From fd7166b7b32225cdd3a9ba9d248fd1d6de8bf62f Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Tue, 9 Sep 2025 23:24:52 +0800 Subject: xcb window focus event. --- src/platform/gui/xcb/Window.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/platform/gui') diff --git a/src/platform/gui/xcb/Window.cpp b/src/platform/gui/xcb/Window.cpp index 7cbbce47..7e4f698e 100644 --- a/src/platform/gui/xcb/Window.cpp +++ b/src/platform/gui/xcb/Window.cpp @@ -73,6 +73,8 @@ XcbWindow::XcbWindow(XcbUiApplication *application) XcbWindow::~XcbWindow() { application_->UnregisterWindow(this); } +IEvent *XcbWindow::FocusEvent() { return &focus_event_; } + IEvent *XcbWindow::MouseEnterLeaveEvent() { return &mouse_enter_leave_event_; } @@ -107,10 +109,11 @@ xcb_window_t XcbWindow::DoCreateWindow() { uint32_t mask = XCB_CW_EVENT_MASK; uint32_t values[1] = { - XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | - XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION | - XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | - XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE}; + XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_FOCUS_CHANGE | + XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | + XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_ENTER_WINDOW | + XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_KEY_PRESS | + XCB_EVENT_MASK_KEY_RELEASE}; xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 100, 100, 400, 200, 10, XCB_WINDOW_CLASS_INPUT_OUTPUT, @@ -131,6 +134,16 @@ void XcbWindow::HandleEvent(xcb_generic_event_t *event) { expose->height); break; } + case XCB_FOCUS_IN: { + xcb_focus_in_event_t *fi = (xcb_focus_in_event_t *)event; + focus_event_.Raise(FocusChangeType::Gain); + break; + } + case XCB_FOCUS_OUT: { + xcb_focus_out_event_t *fo = (xcb_focus_out_event_t *)event; + focus_event_.Raise(FocusChangeType::Lose); + break; + } case XCB_BUTTON_PRESS: { xcb_button_press_event_t *bp = (xcb_button_press_event_t *)event; @@ -210,6 +223,14 @@ std::optional XcbWindow::GetEventWindow( xcb_expose_event_t *expose = (xcb_expose_event_t *)event; return expose->window; } + case XCB_FOCUS_IN: { + xcb_focus_in_event_t *fi = (xcb_focus_in_event_t *)event; + return fi->event; + } + case XCB_FOCUS_OUT: { + xcb_focus_out_event_t *fo = (xcb_focus_out_event_t *)event; + return fo->event; + } case XCB_BUTTON_PRESS: { xcb_button_press_event_t *bp = (xcb_button_press_event_t *)event; return bp->event; -- cgit v1.2.3