From 7b02d32a0274bcbf131bd0171218c1d8b71314ed Mon Sep 17 00:00:00 2001 From: Window Maker Date: Tue, 2 Jun 2026 14:26:30 +0200 Subject: [PATCH] decompose wl_backend.c: extract wl_grabstate.c --- src/Makefile.am | 3 +- src/backend/wayland/wl_backend.c | 65 ------------------------- src/backend/wayland/wl_grabstate.c | 78 ++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 66 deletions(-) create mode 100644 src/backend/wayland/wl_grabstate.c diff --git a/src/Makefile.am b/src/Makefile.am index b999081..88c0987 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -182,7 +182,8 @@ wmaker_SOURCES += \ backend/wayland/wl_stubs.c \ backend/wayland/wl_clipboard.c \ backend/wayland/wl_dnd.c \ - backend/wayland/wl_grabs.c + backend/wayland/wl_grabs.c \ + backend/wayland/wl_grabstate.c endif if USE_NESTED_FUNC diff --git a/src/backend/wayland/wl_backend.c b/src/backend/wayland/wl_backend.c index b8b57bd..4410cd5 100644 --- a/src/backend/wayland/wl_backend.c +++ b/src/backend/wayland/wl_backend.c @@ -4529,56 +4529,6 @@ handle_pointer_frame(struct wl_listener *listener, void *data) wlr_seat_pointer_notify_frame(wl_state.seat); } -/* ------------------------------------------------------------------ */ -/* Pointer grabs */ -/* ------------------------------------------------------------------ */ - - int -wl_pointer_grab(WNativeWindow grab_win, WNativeWindow confine_to, - unsigned int event_mask, int cursor_id, - int owner_events, unsigned long timestamp) -{ - (void)confine_to; (void)event_mask; - (void)timestamp; (void)grab_win; - wwarning("wl_pointer_grab: win=0x%lx owner_events=%d cursor_id=%d grab_type_before=%d", - grab_win, owner_events, cursor_id, wl_state.grab_type); - /* Only set up a WM policy grab (type 3) for actual drags (owner_events=True). - * Brief protective grabs (e.g., during icon creation) don't need to suppress - * pointer focus — they just need to return success. */ - if (owner_events) { - wl_state.grab_type = 3; - wl_state.grab_view = NULL; - if (wl_state.seat) - wlr_seat_pointer_clear_focus(wl_state.seat); - } - if (cursor_id > 0) { - /* Map WCUR_* cursor IDs to xcursor names (same as pointer_change_grab) */ - switch (cursor_id) { - case WCUR_MOVE: wl_set_cursor_image("fleur"); break; - case WCUR_WAIT: wl_set_cursor_image("watch"); break; - case WCUR_TOPLEFTRESIZE: wl_set_cursor_image("nw-resize"); break; - case WCUR_TOPRIGHTRESIZE: wl_set_cursor_image("ne-resize"); break; - case WCUR_BOTTOMLEFTRESIZE: wl_set_cursor_image("sw-resize"); break; - case WCUR_BOTTOMRIGHTRESIZE: wl_set_cursor_image("se-resize"); break; - case WCUR_VERTICALRESIZE: wl_set_cursor_image("n-resize"); break; - case WCUR_HORIZONRESIZE: wl_set_cursor_image("e-resize"); break; - default: wl_set_cursor_image("left_ptr"); break; - } - } - return 1; /* success */ -} - - void wl_pointer_ungrab(unsigned long timestamp) -{ - (void)timestamp; - wwarning("wl_pointer_ungrab: grab_type=%d", wl_state.grab_type); - if (wl_state.grab_type == 3) { - wl_state.grab_type = 0; - wl_state.grab_view = NULL; - /* Reset cursor to default arrow when WM policy grab ends. */ - wl_set_cursor_image("left_ptr"); - } -} /* ------------------------------------------------------------------ */ /* Phase 13: pointer focus delivery to Wayland surfaces */ @@ -4828,21 +4778,6 @@ wl_pointer_change_grab(unsigned int event_mask, int cursor_id, /* ------------------------------------------------------------------ */ /* Keyboard grabs */ -/* ------------------------------------------------------------------ */ - - int -wl_keyboard_grab(WNativeWindow win) -{ - (void)win; - wl_state.keyboard_grabbed = true; - return 0; -} - - void -wl_keyboard_ungrab(void) -{ - wl_state.keyboard_grabbed = false; -} diff --git a/src/backend/wayland/wl_grabstate.c b/src/backend/wayland/wl_grabstate.c new file mode 100644 index 0000000..7188225 --- /dev/null +++ b/src/backend/wayland/wl_grabstate.c @@ -0,0 +1,78 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include "../../WindowMaker.h" +#include "../../screen.h" +#include "wl_types.h" + +/* Forward declarations */ +void wl_set_cursor_image(const char *name); + + +/* ------------------------------------------------------------------ */ +/* Pointer grabs */ +/* ------------------------------------------------------------------ */ + + int +wl_pointer_grab(WNativeWindow grab_win, WNativeWindow confine_to, + unsigned int event_mask, int cursor_id, + int owner_events, unsigned long timestamp) +{ + (void)confine_to; (void)event_mask; + (void)timestamp; (void)grab_win; + wwarning("wl_pointer_grab: win=0x%lx owner_events=%d cursor_id=%d grab_type_before=%d", + grab_win, owner_events, cursor_id, wl_state.grab_type); + /* Only set up a WM policy grab (type 3) for actual drags (owner_events=True). + * Brief protective grabs (e.g., during icon creation) don't need to suppress + * pointer focus — they just need to return success. */ + if (owner_events) { + wl_state.grab_type = 3; + wl_state.grab_view = NULL; + if (wl_state.seat) + wlr_seat_pointer_clear_focus(wl_state.seat); + } + if (cursor_id > 0) { + /* Map WCUR_* cursor IDs to xcursor names (same as pointer_change_grab) */ + switch (cursor_id) { + case WCUR_MOVE: wl_set_cursor_image("fleur"); break; + case WCUR_WAIT: wl_set_cursor_image("watch"); break; + case WCUR_TOPLEFTRESIZE: wl_set_cursor_image("nw-resize"); break; + case WCUR_TOPRIGHTRESIZE: wl_set_cursor_image("ne-resize"); break; + case WCUR_BOTTOMLEFTRESIZE: wl_set_cursor_image("sw-resize"); break; + case WCUR_BOTTOMRIGHTRESIZE: wl_set_cursor_image("se-resize"); break; + case WCUR_VERTICALRESIZE: wl_set_cursor_image("n-resize"); break; + case WCUR_HORIZONRESIZE: wl_set_cursor_image("e-resize"); break; + default: wl_set_cursor_image("left_ptr"); break; + } + } + return 1; /* success */ +} + + void wl_pointer_ungrab(unsigned long timestamp) +{ + (void)timestamp; + wwarning("wl_pointer_ungrab: grab_type=%d", wl_state.grab_type); + if (wl_state.grab_type == 3) { + wl_state.grab_type = 0; + wl_state.grab_view = NULL; + /* Reset cursor to default arrow when WM policy grab ends. */ + wl_set_cursor_image("left_ptr"); + } +} +/* ------------------------------------------------------------------ */ + + int +wl_keyboard_grab(WNativeWindow win) +{ + (void)win; + wl_state.keyboard_grabbed = true; + return 0; +} + + void +wl_keyboard_ungrab(void) +{ + wl_state.keyboard_grabbed = false; +}