From 9f8b2453fae8e40f25982ad4333a7e1fcbc68477 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Tue, 3 Mar 2026 07:26:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=84=A6=E7=82=B9=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E5=B1=8F=E5=B9=95=E5=92=8C=E5=85=89=E6=A0=87=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=B7=9F=E9=9A=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 按键操作前自动根据光标位置更新当前屏幕 - 新增 enter_notify 事件处理,鼠标进入窗口时自动获取焦点 - 新增 focus_in 事件处理,窗口获得焦点时更新当前屏幕 - 确保焦点操作与 current_monitor 保持同步 --- src/event.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/event.c b/src/event.c index 04f8d01..2692452 100644 --- a/src/event.c +++ b/src/event.c @@ -11,6 +11,7 @@ #include "action.h" #include "atoms-extern.h" +#include "base.h" #include "client.h" #include "default_config.h" #include "monitor.h" @@ -118,6 +119,11 @@ static void key_press(xcb_key_press_event_t *ev) { for (int i = 0; i < countof(key_list); i++) { keyboard_t key = key_list[i]; if (keysym == key.keysym && ev->state == key.modifiers && key.func) { + /* 查询光标所在屏幕并将其设置为当前屏幕 */ + point_t point = {.x = ev->root_x, .y = ev->root_y}; + monitor_t *monitor = wm_get_monitor_by_point(point); + wm_set_current_monitor(monitor, false); + key.func(&key.arg); return; } @@ -293,6 +299,19 @@ static void expose(xcb_expose_event_t *ev) { xcb_flush(wm.xcb_conn); } +static void enter_notify(xcb_enter_notify_event_t *ev) { + client_t *client = client_get_by_window(ev->event); + if (!client || wm.client_focused == client) return; + + client_focus(client); +} + +static void focus_in(xcb_focus_in_event_t *ev) { + client_t *client = client_get_by_window(ev->event); + if (!client) return; + wm_set_current_monitor(client->monitor, ev->mode != XCB_NOTIFY_MODE_NORMAL); +} + static void handle_xcb_event(xcb_generic_event_t *event) { uint8_t event_type = XCB_EVENT_RESPONSE_TYPE(event); const char *label = xcb_event_get_label(event_type); @@ -316,6 +335,8 @@ static void handle_xcb_event(xcb_generic_event_t *event) { EVENT(XCB_PROPERTY_NOTIFY, property_notify); EVENT(XCB_UNMAP_NOTIFY, unmap_notify); EVENT(XCB_DESTROY_NOTIFY, destroy_notify); + EVENT(XCB_ENTER_NOTIFY, enter_notify); + EVENT(XCB_FOCUS_IN, focus_in); #undef EVENT }