From aa4b59d594a962f34a7737a015703f0878c73b35 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Wed, 10 Sep 2025 00:28:49 +0800 Subject: xcb window resize event. --- include/cru/platform/gui/xcb/Window.h | 4 +++- src/platform/gui/xcb/Window.cpp | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/cru/platform/gui/xcb/Window.h b/include/cru/platform/gui/xcb/Window.h index 475f2527..4c9e3f4d 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* PaintEvent() = 0; virtual IEvent* VisibilityChangeEvent() = 0; - virtual IEvent* ResizeEvent() = 0; + IEvent* ResizeEvent() override; IEvent* FocusEvent() override; IEvent* MouseEnterLeaveEvent() override; @@ -91,10 +91,12 @@ class XcbWindow : public XcbResource, public virtual INativeWindow { private: XcbUiApplication* application_; std::optional xcb_window_; + Size current_size_; Event create_event_; Event destroy_event_; + Event resize_event_; Event focus_event_; Event mouse_enter_leave_event_; Event mouse_move_event_; diff --git a/src/platform/gui/xcb/Window.cpp b/src/platform/gui/xcb/Window.cpp index 179e13af..67568dce 100644 --- a/src/platform/gui/xcb/Window.cpp +++ b/src/platform/gui/xcb/Window.cpp @@ -59,6 +59,8 @@ IEvent *XcbWindow::CreateEvent() { return &create_event_; } IEvent *XcbWindow::DestroyEvent() { return &destroy_event_; } +IEvent *XcbWindow::ResizeEvent() { return &resize_event_; } + IEvent *XcbWindow::FocusEvent() { return &focus_event_; } IEvent *XcbWindow::MouseEnterLeaveEvent() { @@ -104,6 +106,7 @@ xcb_window_t XcbWindow::DoCreateWindow() { xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 100, 100, 400, 200, 10, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values); + current_size_ = {400, 200}; create_event_.Raise(nullptr); @@ -125,6 +128,17 @@ void XcbWindow::HandleEvent(xcb_generic_event_t *event) { case XCB_DESTROY_NOTIFY: { destroy_event_.Raise(nullptr); xcb_window_ = std::nullopt; + break; + } + case XCB_CONFIGURE_NOTIFY: { + xcb_configure_notify_event_t *configure = + (xcb_configure_notify_event_t *)event; + if (configure->width != current_size_.width || + configure->height != current_size_.height) { + current_size_ = Size(configure->width, configure->height); + resize_event_.Raise(current_size_); + } + break; } case XCB_FOCUS_IN: { focus_event_.Raise(FocusChangeType::Gain); @@ -217,6 +231,11 @@ std::optional XcbWindow::GetEventWindow( xcb_destroy_notify_event_t *destroy = (xcb_destroy_notify_event_t *)event; return destroy->event; } + case XCB_CONFIGURE_NOTIFY: { + xcb_configure_notify_event_t *configure = + (xcb_configure_notify_event_t *)event; + return configure->event; + } case XCB_FOCUS_IN: { xcb_focus_in_event_t *fi = (xcb_focus_in_event_t *)event; return fi->event; -- cgit v1.2.3