aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/platform/gui/xcb/Window.h3
-rw-r--r--src/platform/gui/xcb/Window.cpp29
2 files changed, 27 insertions, 5 deletions
diff --git a/include/cru/platform/gui/xcb/Window.h b/include/cru/platform/gui/xcb/Window.h
index 9c6b4f43..3f21131c 100644
--- a/include/cru/platform/gui/xcb/Window.h
+++ b/include/cru/platform/gui/xcb/Window.h
@@ -67,7 +67,7 @@ class XcbWindow : public XcbResource, public virtual INativeWindow {
virtual IEvent<WindowVisibilityType>* VisibilityChangeEvent() = 0;
virtual IEvent<Size>* ResizeEvent() = 0;
- virtual IEvent<FocusChangeType>* FocusEvent() = 0;
+ IEvent<FocusChangeType>* FocusEvent() override;
IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() override;
IEvent<Point>* MouseMoveEvent() override;
@@ -91,6 +91,7 @@ class XcbWindow : public XcbResource, public virtual INativeWindow {
XcbUiApplication* application_;
std::optional<xcb_window_t> xcb_window_;
+ Event<FocusChangeType> focus_event_;
Event<MouseEnterLeaveType> mouse_enter_leave_event_;
Event<Point> mouse_move_event_;
Event<NativeMouseButtonEventArgs> mouse_down_event_;
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<FocusChangeType> *XcbWindow::FocusEvent() { return &focus_event_; }
+
IEvent<MouseEnterLeaveType> *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<xcb_window_t> 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;