koekeishiya / yabai

A tiling window manager for macOS based on binary space partitioning
MIT License
23.12k stars 639 forks source link

Yabai incompatability with SDL3 #2385

Closed cheyao closed 3 days ago

cheyao commented 1 month ago

When using SDL3 and showing a message box, normally the mouse is released. But when yabai is activated, the mouse doesn't get released.

SDL example: https://gist.github.com/cheyao/52df7535b1585d8d9e5d6c397bfd1104 (The SDL_ShowSimpleMessageBox must be in SDL_AppInit)

Here is a small video showcasing the problem: https://imgur.com/a/D2X4P5Y

koekeishiya commented 1 month ago

I'm unable to reproduce this using SDL2 and yabai v7.1.1.

sdl

If you run yabai --verbose in a secondary terminal instead of running through --start-service you will get a dump of events that are processed. Although I don't see how this matters, I guess you could post your yabai config as well.

cheyao commented 1 month ago

Thanks for the quick response!

SDL2 works perfectly with yabai, but the problem is with the new SDL3 and it's new event based system. The SDL dev team recently changed how they captured the mouse, so I guess that is the problem. It works fine without yabai so the SDL devs redirected me here.

Here is a video: https://imgur.com/a/Q2HyeEP

Here are the logs:

EVENT_HANDLER_WINDOW_FOCUSED: kitty 13392
EVENT_HANDLER_MOUSE_DOWN: 893.68, 996.22
EVENT_HANDLER_MOUSE_DOWN: 903.97, 715.35
EVENT_HANDLER_MOUSE_UP: 903.97, 715.35
EVENT_HANDLER_WINDOW_TITLE_CHANGED: kitty 13392
EVENT_HANDLER_APPLICATION_LAUNCHED: SDL3 (67615) is not finished launching, subscribing to finishedLaunching changes
-[workspace_context observeValueForKeyPath:ofObject:change:context:]: SDL3 (67615) finished launching
EVENT_HANDLER_APPLICATION_LAUNCHED: SDL3 (67615)
window_manager_create_and_add_window:13438 SDL3 -  (AXWindow:AXDialog:1)
window_manager_create_and_add_window:13437 SDL3 - Window (AXWindow:AXStandardWindow:1)
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: SDL3 (67615)
EVENT_HANDLER_WINDOW_RESIZED: kitty 13392
EVENT_HANDLER_WINDOW_RESIZED: SDL3 13437
EVENT_HANDLER_WINDOW_MOVED:DEBOUNCED SDL3 13437
EVENT_HANDLER_WINDOW_FOCUSED: SDL3 13437
EVENT_HANDLER_MOUSE_DOWN: 1257.00, 806.00
EVENT_HANDLER_MOUSE_UP: 1257.00, 806.00
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: kitty (61532)
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: kitty has windows that are not yet resolved
EVENT_HANDLER_APPLICATION_TERMINATED: FirefoxCP Isolated Web Content (93666) (not observed)
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: SDL3 (67615)
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: kitty (61532)
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: kitty has windows that are not yet resolved
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: SDL3 (67615)
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: kitty (61532)
EVENT_HANDLER_APPLICATION_FRONT_SWITCHED: kitty has windows that are not yet resolved
EVENT_HANDLER_WINDOW_FOCUSED: kitty 11667
EVENT_HANDLER_SPACE_CHANGED: 4
space_manager_refresh_application_windows: kitty has windows that are not yet resolved
space_manager_refresh_application_windows: Vesktop has windows that are not yet resolved
space_manager_refresh_application_windows: Firefox has windows that are not yet resolved
EVENT_HANDLER_MOUSE_DOWN: 858.75, 1033.77
EVENT_HANDLER_MOUSE_DOWN: 869.69, 990.64
EVENT_HANDLER_MOUSE_DOWN: 853.90, 1034.47
EVENT_HANDLER_MOUSE_DOWN: 878.92, 982.18
EVENT_HANDLER_APPLICATION_TERMINATED: SDL3 (67615)
EVENT_HANDLER_WINDOW_TITLE_CHANGED: kitty 13392
EVENT_HANDLER_WINDOW_TITLE_CHANGED: kitty 13392
EVENT_HANDLER_WINDOW_FOCUSED: kitty 13055
EVENT_HANDLER_SPACE_CHANGED: 5
space_manager_refresh_application_windows: kitty has windows that are not yet resolved
space_manager_refresh_application_windows: Vesktop has windows that are not yet resolved
space_manager_refresh_application_windows: Firefox has windows that are not yet resolved
EVENT_HANDLER_WINDOW_RESIZED: kitty 13392
EVENT_HANDLER_WINDOW_FOCUSED: kitty 13392
EVENT_HANDLER_MOUSE_DOWN: 1004.19, 451.90
EVENT_HANDLER_MOUSE_UP: 1004.19, 451.90
EVENT_HANDLER_APPLICATION_LAUNCHED: FirefoxCP (68196) is not finished launching, subscribing to finishedLaunching changes
EVENT_HANDLER_WINDOW_FOCUSED: kitty 13055
EVENT_HANDLER_MOUSE_DOWN: 645.63, 648.63
EVENT_HANDLER_MOUSE_UP: 645.63, 648.63

Here is my .yabairc:

yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"
sudo yabai --load-sa
yabai -m config layout bsp
yabai -m config focus_follows_mouse autoraise
yabai -m config window_shadow float

yabai -m config top_padding    10
yabai -m config bottom_padding 10
yabai -m config left_padding   10
yabai -m config right_padding  10
yabai -m config window_gap     10
yabai -m config menubar_opacity 0.0

yabai -m config mouse_modifier cmd

yabai -m config external_bar all:30:00

yabai -m rule --add app="^System Preferences$" manage=off
yabai -m rule --add app="^OpenGL$" manage=off

Just to be sure:

$ yabai -v             
yabai-v7.1.1
koekeishiya commented 1 month ago

Hm I'm not really sure what the problem could be. yabai uses the official Quartz Event Services API to get notified about mouse events from macOS. We then observe the events, cache and post some information to our own event loop, and let macOS continue processing the event (except for cases where we should override that event -- which is iff mouse_modifier from the config is held down while the mouse event takes place).

The code is basically: https://github.com/koekeishiya/yabai/blob/master/src/mouse_handler.c#L29

register for events:

CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, mask, mouse_handler, mouse_state);

event handler

    case kCGEventLeftMouseDown:
    case kCGEventRightMouseDown: {
        uint8_t mod = mouse_mod_from_cgflags(CGEventGetFlags(event));
        event_loop_post(&g_event_loop, MOUSE_DOWN, (void *) CFRetain(event), mod);

        if (mod == mouse_state->modifier) {
            mouse_state->consume_mouse_click = true;
            mouse_state->consumed_event = (CGEventRef) CFRetain(event);
            return NULL;
        }
    } break;
    case kCGEventLeftMouseUp:
    case kCGEventRightMouseUp: {
        event_loop_post(&g_event_loop, MOUSE_UP, (void *) CFRetain(event), 0);

        if (mouse_state->consume_mouse_click) {
            if (!mouse_state->drag_detected) {
                CGEventTapPostEvent(proxy, mouse_state->consumed_event);
                CGEventTapPostEvent(proxy, event);
            }

            mouse_state->drag_detected = false;
            mouse_state->consume_mouse_click = false;
            CFRelease(mouse_state->consumed_event);
            return NULL;
        }
    } break;

    return event;
cheyao commented 3 days ago

I've just upgraded to the latest SDL3, and the issue is gone :D