decompose wl_backend.c: extract wl_grabstate.c

This commit is contained in:
Window Maker 2026-06-02 14:26:30 +02:00
parent 9f69f7930d
commit 7b02d32a02
3 changed files with 80 additions and 66 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -0,0 +1,78 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <wayland-server-core.h>
#include <wlr/types/wlr_seat.h>
#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;
}