libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.72k stars 1.8k forks source link

Can't receive any events if create SDL_Window from AvaloniaUI NativeControlHost on x11. #9503

Closed sandsc closed 2 months ago

sandsc commented 6 months ago

Create a sdl window by Avalonia NativeControlHost's platform handle shows black window on x11, it seems underlying window can't gets resized, when I resize underlying window manually, it shows, however it detached from Avalonia window, can't embedded in main window. It works no problem on windows platform, I don't know if this is a SDL bug, or an Avalonia bug? Avalonia x11 bug

madebr commented 6 months ago

Can you please provide a (small) reproducer? That way triage will go a lot faster.

sandsc commented 6 months ago

using code SDL_SetNumberProperty(sdlPid, SDL_PROP_WINDOW_CREATE_X11_WINDOW_NUMBER, reinterpret_cast<Sint64>(handle)); instead of SDL_Setroperty(sdlPid, SDL_PROP_WINDOW_CREATE_X11_WINDOW_NUMBER, handle); now NativeControlHost's can embedded in Avalonia window, I guess that x11 window handle should be passed as number value, or a toplevel window created, but a new issue has arisen, I can't receive any input events if it is a embedded child window.
I will provide a small app to reproduce the bugs later, thanks for any helps.

sandsc commented 6 months ago

Here is small app to reproduce issue, prebuilt libraries are included for both windows x64 and Linux x64 platform.

sandsc commented 6 months ago

Here is screenshot on Linux x11, only SDL_EVENT_WINDOW_SHOWN and SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED events received when app started. but all input and window events can be received on Windows platform.

2024-04-10

Also found that the red line is not rendered on Linux either.

sandsc commented 6 months ago

In SDL_x11window When creating window for external window, add some code for set event mask for external window, then events can be received, I'm not very familiar with x11 programming and don't know if this's the right way to fix.

 if (w) {
        window->flags |= SDL_WINDOW_EXTERNAL;
        if (SetupWindowData(_this, window, w) < 0) {
            return -1;
        }
        unsigned int keyboard_events = KeyPressMask | KeyReleaseMask;
        unsigned int pointer_events = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ButtonMotionMask;
        X11_Xinput2SelectMouseAndKeyboard(_this, window);

        SDL_WindowData *wd = window->driverdata;
        /* If XInput2 can handle pointer and keyboard events, we don't track them here */
        if (wd->xinput2_keyboard_enabled) {
            keyboard_events = 0;
        }
        if (wd->xinput2_mouse_enabled) {
            pointer_events = 0;
        }
        Display *display = _this->driverdata->display;
        X11_XSelectInput(display, w,
                         (FocusChangeMask | EnterWindowMask | LeaveWindowMask | StructureNotifyMask |
                          keyboard_events | pointer_events));
        return 0;
    }
slouken commented 2 months ago

Fixed, thanks!