step 4: move wl_handle_x11_events from wl_backend.c to wl_xwayland.c (X11 event bridge)

This commit is contained in:
lkn 2026-06-06 09:43:44 +02:00
parent 3b3ab96597
commit b5aa99542c
2 changed files with 55 additions and 52 deletions

View File

@ -267,58 +267,7 @@ wl_startup_pump_thread(void *arg)
}
#if USE_XWAYLAND
/* Called by the Wayland event loop whenever the X11 connection fd is readable. */
static int
wl_handle_x11_events(int fd, uint32_t mask, void *data)
{
(void)fd; (void)mask; (void)data;
if (!wl_state.x_display)
return 0;
XEvent event;
while (XPending(wl_state.x_display)) {
XNextEvent(wl_state.x_display, &event);
/* Guard: WINGs screen is not initialised until StartUp() completes. */
if (w_global.screen_count > 0) {
/* Translate XEvent → WMEvent at the XWayland boundary.
* _x11_raw carries the original XEvent so WMHandleEvent can
* do X11-specific operations (view lookup, XFilterEvent, etc.) */
WMEvent wev;
memset(&wev, 0, sizeof(wev));
wev._x11_raw = &event;
wev.window = (WNativeWindow)event.xany.window;
switch (event.type) {
case KeyPress: wev.type = WME_KEY_PRESS; break;
case KeyRelease: wev.type = WME_KEY_RELEASE; break;
case ButtonPress: wev.type = WME_BUTTON_PRESS; break;
case ButtonRelease: wev.type = WME_BUTTON_RELEASE; break;
case MotionNotify: wev.type = WME_MOTION; break;
case EnterNotify: wev.type = WME_ENTER; break;
case LeaveNotify: wev.type = WME_LEAVE; break;
case Expose: wev.type = WME_EXPOSE; break;
case ConfigureNotify: wev.type = WME_CONFIGURE; break;
case MapNotify: wev.type = WME_MAP; break;
case UnmapNotify: wev.type = WME_UNMAP; break;
case DestroyNotify: wev.type = WME_DESTROY; break;
case FocusIn: wev.type = WME_FOCUS_IN; break;
case FocusOut: wev.type = WME_FOCUS_OUT; break;
case PropertyNotify: wev.type = WME_PROPERTY; break;
case ClientMessage: wev.type = WME_CLIENT_MESSAGE; break;
case SelectionNotify: wev.type = WME_SELECTION; break;
case SelectionRequest: wev.type = WME_SELECTION_REQUEST; break;
case SelectionClear: wev.type = WME_SELECTION_CLEAR; break;
case MappingNotify: wev.type = WME_MAPPING; break;
case ColormapNotify: wev.type = WME_COLORMAP; break;
case VisibilityNotify: wev.type = WME_VISIBILITY; break;
case ReparentNotify: wev.type = WME_REPARENT; break;
case ConfigureRequest: wev.type = WME_CONFIGURE_REQUEST; break;
case MapRequest: wev.type = WME_MAP_REQUEST; break;
default: wev.type = WME_NONE; break;
}
WMHandleEvent(&wev);
}
}
return 0;
}
extern int wl_handle_x11_events(int fd, uint32_t mask, void *data);
#else
static int
wl_handle_x11_events(int fd, uint32_t mask, void *data)

View File

@ -17,6 +17,9 @@
#include "wl_types.h"
#include <WINGs/WINGsP.h>
#include <wraster.h>
#include <WINGs/WMEvent.h>
#include "../../event.h"
/* Forward declarations */
void view_attach_scene_destroy_listener(struct wl_toplevel_view *view);
@ -427,3 +430,54 @@ RImage *wl_xwayland_capture_snapshot(WScreen *scr, struct wlr_xwayland_surface *
float wl_xwayland_get_window_opacity(WNativeWindow client_win)
{ (void)client_win; return 1.0f; }
#endif
/* Called by the Wayland event loop whenever the X11 connection fd is readable. */
int
wl_handle_x11_events(int fd, uint32_t mask, void *data)
{
(void)fd; (void)mask; (void)data;
if (!wl_state.x_display)
return 0;
XEvent event;
while (XPending(wl_state.x_display)) {
XNextEvent(wl_state.x_display, &event);
/* Guard: WINGs screen is not initialised until StartUp() completes. */
if (w_global.screen_count > 0) {
/* Translate XEvent → WMEvent at the XWayland boundary. */
WMEvent wev;
memset(&wev, 0, sizeof(wev));
wev._x11_raw = &event;
wev.window = (WNativeWindow)event.xany.window;
switch (event.type) {
case KeyPress: wev.type = WME_KEY_PRESS; break;
case KeyRelease: wev.type = WME_KEY_RELEASE; break;
case ButtonPress: wev.type = WME_BUTTON_PRESS; break;
case ButtonRelease: wev.type = WME_BUTTON_RELEASE; break;
case MotionNotify: wev.type = WME_MOTION; break;
case EnterNotify: wev.type = WME_ENTER; break;
case LeaveNotify: wev.type = WME_LEAVE; break;
case Expose: wev.type = WME_EXPOSE; break;
case ConfigureNotify: wev.type = WME_CONFIGURE; break;
case MapNotify: wev.type = WME_MAP; break;
case UnmapNotify: wev.type = WME_UNMAP; break;
case DestroyNotify: wev.type = WME_DESTROY; break;
case FocusIn: wev.type = WME_FOCUS_IN; break;
case FocusOut: wev.type = WME_FOCUS_OUT; break;
case PropertyNotify: wev.type = WME_PROPERTY; break;
case ClientMessage: wev.type = WME_CLIENT_MESSAGE; break;
case SelectionNotify: wev.type = WME_SELECTION; break;
case SelectionRequest: wev.type = WME_SELECTION_REQUEST; break;
case SelectionClear: wev.type = WME_SELECTION_CLEAR; break;
case MappingNotify: wev.type = WME_MAPPING; break;
case ColormapNotify: wev.type = WME_COLORMAP; break;
case VisibilityNotify: wev.type = WME_VISIBILITY; break;
case ReparentNotify: wev.type = WME_REPARENT; break;
case ConfigureRequest: wev.type = WME_CONFIGURE_REQUEST; break;
case MapRequest: wev.type = WME_MAP_REQUEST; break;
default: wev.type = WME_NONE; break;
}
WMHandleEvent(&wev);
}
}
return 0;
}