feat: 添加 MOD4 + 鼠标左键移动窗口功能

This commit is contained in:
2026-06-21 16:30:59 +08:00
parent b8cd40df9f
commit 4e7ab45864
9 changed files with 167 additions and 1 deletions

View File

@@ -538,6 +538,17 @@ static void backend_grab_button(
}
}
static void backend_start_move_window(backend_t *backend, xcb_window_t window) {
auto conn = backend->conn;
auto root = backend->screen->root;
auto mask = XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
XCB_EVENT_MASK_POINTER_MOTION;
auto mode = XCB_GRAB_MODE_ASYNC;
auto cursor = cursor_get_xcb_cursor(backend, ZDWM_CURSOR_MOVE);
auto time = XCB_TIME_CURRENT_TIME;
xcb_grab_pointer(conn, false, root, mask, mode, mode, root, cursor, time);
}
static void backend_merge_effects(
backend_t *backend,
const effect_t *effects,
@@ -566,6 +577,9 @@ static void backend_merge_effects(
XCB_ICCCM_WM_STATE_WITHDRAWN
);
break;
case ZDWM_EFFECT_START_MOVE_WINDOW:
backend_start_move_window(backend, e->as.move.window);
break;
case ZDWM_EFFECT_MINIMIZE_WINDOW: {
auto window = e->as.minimize.window;
xcb_icccm_wm_state_t state = XCB_ICCCM_WM_STATE_NORMAL;
@@ -619,6 +633,10 @@ static void backend_merge_effects(
break;
case ZDWM_EFFECT_GRAB_BUTTON:
backend_grab_button(backend, &e->as.grab_button);
break;
case ZDWM_EFFECT_UNGRAB_POINTER:
xcb_ungrab_pointer(backend->conn, XCB_CURRENT_TIME);
break;
}
}
}

View File

@@ -271,7 +271,8 @@ static bool handle_button_press(
event_t *event,
const xcb_button_press_event_t *xcb_event
) {
auto handled = fill_button_event(xcb_event, &event->as.pointer_button_press);
auto press = &event->as.pointer_button_press;
auto handled = fill_button_event(xcb_event, press);
if (handled) event->type = ZDWM_EVENT_POINTER_BUTTON_PRESS;
return handled;