aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-09-22 14:58:02 +0800
committerYuqian Yang <crupest@crupest.life>2025-09-22 16:39:33 +0800
commit444e628d22db67742181ae14ae2ed0a9c2b6cd67 (patch)
treefa2f6249ba90d1e7e618e59c7eb3cdf00fbe9971 /include
parent8bde78e1a008ba5ba95ea54ff03717baf53d4170 (diff)
downloadcru-444e628d22db67742181ae14ae2ed0a9c2b6cd67.tar.gz
cru-444e628d22db67742181ae14ae2ed0a9c2b6cd67.tar.bz2
cru-444e628d22db67742181ae14ae2ed0a9c2b6cd67.zip
Impl window rect of xcb window.
Diffstat (limited to 'include')
-rw-r--r--include/cru/platform/GraphicsBase.h16
-rw-r--r--include/cru/platform/gui/xcb/UiApplication.h1
-rw-r--r--include/cru/platform/gui/xcb/Window.h15
3 files changed, 23 insertions, 9 deletions
diff --git a/include/cru/platform/GraphicsBase.h b/include/cru/platform/GraphicsBase.h
index b0f653ef..d5936476 100644
--- a/include/cru/platform/GraphicsBase.h
+++ b/include/cru/platform/GraphicsBase.h
@@ -206,10 +206,22 @@ struct Rect final {
height + thickness.GetVerticalTotal());
}
- constexpr Rect Shrink(const Thickness& thickness) const {
- return Rect(left + thickness.left, top + thickness.top,
+ constexpr Rect Shrink(const Thickness& thickness,
+ bool normalize = false) const {
+ Rect result(left + thickness.left, top + thickness.top,
width - thickness.GetHorizontalTotal(),
height - thickness.GetVerticalTotal());
+
+ if (normalize) {
+ if (result.width < 0) {
+ result.width = 0;
+ }
+ if (result.height < 0) {
+ result.height = 0;
+ }
+ }
+
+ return result;
}
constexpr bool IsPointInside(const Point& point) const {
diff --git a/include/cru/platform/gui/xcb/UiApplication.h b/include/cru/platform/gui/xcb/UiApplication.h
index 6063a8ab..591ac33f 100644
--- a/include/cru/platform/gui/xcb/UiApplication.h
+++ b/include/cru/platform/gui/xcb/UiApplication.h
@@ -41,6 +41,7 @@ class XcbUiApplication : public XcbResource, public virtual IUiApplication {
CRU_XCB_UI_APPLICATION_DEFINE_XCB_ATOM(_NET_WM_WINDOW_TYPE)
CRU_XCB_UI_APPLICATION_DEFINE_XCB_ATOM(_NET_WM_WINDOW_TYPE_NORMAL)
CRU_XCB_UI_APPLICATION_DEFINE_XCB_ATOM(_NET_WM_WINDOW_TYPE_UTILITY)
+ CRU_XCB_UI_APPLICATION_DEFINE_XCB_ATOM(_NET_FRAME_EXTENTS)
#undef CRU_XCB_UI_APPLICATION_DEFINE_XCB_ATOM
diff --git a/include/cru/platform/gui/xcb/Window.h b/include/cru/platform/gui/xcb/Window.h
index 927c3db9..ba4798a5 100644
--- a/include/cru/platform/gui/xcb/Window.h
+++ b/include/cru/platform/gui/xcb/Window.h
@@ -1,5 +1,6 @@
#pragma once
+#include "../../GraphicsBase.h"
#include "../Window.h"
#include "Base.h"
@@ -38,13 +39,8 @@ class XcbWindow : public XcbResource, public virtual INativeWindow {
Rect GetClientRect() override;
void SetClientRect(const Rect& rect) override;
- // Get the rect of the window containing frame.
- // The lefttop of the rect is relative to screen lefttop.
- virtual Rect GetWindowRect() = 0;
-
- // Set the rect of the window containing frame.
- // The lefttop of the rect is relative to screen lefttop.
- virtual void SetWindowRect(const Rect& rect) = 0;
+ Rect GetWindowRect() override;
+ void SetWindowRect(const Rect& rect) override;
virtual bool RequestFocus() = 0;
@@ -98,6 +94,11 @@ class XcbWindow : public XcbResource, public virtual INativeWindow {
std::uint32_t length,
std::uint32_t* out_length = nullptr);
+ // Relative to screen lefttop.
+ Point GetXcbWindowPosition(xcb_window_t window);
+
+ std::optional<Thickness> Get_NET_FRAME_EXTENTS(xcb_window_t window);
+
private:
XcbUiApplication* application_;
std::optional<xcb_window_t> xcb_window_;