diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-09-22 14:58:02 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-09-22 20:23:27 +0800 |
commit | 70e9404912e0047f14861abc8d4e3982c23685fd (patch) | |
tree | ed2d7bb13a5973687b8a2c640810b7583773bba0 | |
parent | 444e628d22db67742181ae14ae2ed0a9c2b6cd67 (diff) | |
download | cru-70e9404912e0047f14861abc8d4e3982c23685fd.tar.gz cru-70e9404912e0047f14861abc8d4e3982c23685fd.tar.bz2 cru-70e9404912e0047f14861abc8d4e3982c23685fd.zip |
Impl RequestFocus of xcb window.
-rw-r--r-- | include/cru/platform/gui/Window.h | 2 | ||||
-rw-r--r-- | include/cru/platform/gui/xcb/Window.h | 2 | ||||
-rw-r--r-- | src/platform/gui/xcb/Window.cpp | 7 |
3 files changed, 10 insertions, 1 deletions
diff --git a/include/cru/platform/gui/Window.h b/include/cru/platform/gui/Window.h index 742ef798..f877545e 100644 --- a/include/cru/platform/gui/Window.h +++ b/include/cru/platform/gui/Window.h @@ -72,6 +72,8 @@ struct INativeWindow : virtual IPlatformResource { // The lefttop of the rect is relative to screen lefttop. virtual void SetWindowRect(const Rect& rect) = 0; + // Return true if window gained the focus. But the return value should be + // ignored, since it does not guarantee anything. virtual bool RequestFocus() = 0; // Relative to client lefttop. diff --git a/include/cru/platform/gui/xcb/Window.h b/include/cru/platform/gui/xcb/Window.h index ba4798a5..346cbd55 100644 --- a/include/cru/platform/gui/xcb/Window.h +++ b/include/cru/platform/gui/xcb/Window.h @@ -42,7 +42,7 @@ class XcbWindow : public XcbResource, public virtual INativeWindow { Rect GetWindowRect() override; void SetWindowRect(const Rect& rect) override; - virtual bool RequestFocus() = 0; + bool RequestFocus() override; // Relative to client lefttop. virtual Point GetMousePosition() = 0; diff --git a/src/platform/gui/xcb/Window.cpp b/src/platform/gui/xcb/Window.cpp index 9f2448d1..3e5c7f7b 100644 --- a/src/platform/gui/xcb/Window.cpp +++ b/src/platform/gui/xcb/Window.cpp @@ -231,6 +231,13 @@ void XcbWindow::SetWindowRect(const Rect &rect) { SetClientRect(real_rect); } +bool XcbWindow::RequestFocus() { + if (!xcb_window_) return false; + xcb_set_input_focus(application_->GetXcbConnection(), XCB_NONE, *xcb_window_, + XCB_CURRENT_TIME); + return true; +} + std::unique_ptr<graphics::IPainter> XcbWindow::BeginPaint() { assert(cairo_surface_); |