aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-09-10 01:30:59 +0800
committerYuqian Yang <crupest@crupest.life>2025-09-10 01:30:59 +0800
commitfe6e1686ce484cb0dd9a69f130e82f647c30016f (patch)
treef5e020e6a46d9a36a7952d1785cf20467e413159 /include
parent18e330f9f4a673da78e6503c697619ad99b4bdbf (diff)
downloadcru-fe6e1686ce484cb0dd9a69f130e82f647c30016f.tar.gz
cru-fe6e1686ce484cb0dd9a69f130e82f647c30016f.tar.bz2
cru-fe6e1686ce484cb0dd9a69f130e82f647c30016f.zip
xcb window reparent.
Diffstat (limited to 'include')
-rw-r--r--include/cru/platform/Check.h28
-rw-r--r--include/cru/platform/Exception.h2
-rw-r--r--include/cru/platform/Resource.h2
-rw-r--r--include/cru/platform/gui/xcb/Window.h10
4 files changed, 37 insertions, 5 deletions
diff --git a/include/cru/platform/Check.h b/include/cru/platform/Check.h
index 270150e8..202ee86e 100644
--- a/include/cru/platform/Check.h
+++ b/include/cru/platform/Check.h
@@ -35,4 +35,32 @@ std::shared_ptr<TTarget> CheckPlatform(const std::shared_ptr<TSource>& resource,
}
return result;
}
+
+template <typename TTarget>
+TTarget* CheckPlatform(IPlatformResource* resource,
+ std::string target_platform) {
+ if (resource == nullptr) return nullptr;
+ const auto result = dynamic_cast<TTarget*>(resource);
+ if (result == nullptr) {
+ throw PlatformNotMatchException(
+ resource->GetPlatformIdUtf8(), target_platform,
+ "Try to convert resource to target platform failed.");
+ }
+ return result;
+}
+
+template <typename TTarget, typename TSource>
+std::shared_ptr<TTarget> CheckPlatform(const std::shared_ptr<TSource>& resource,
+ std::string target_platform) {
+ if (resource == nullptr) return nullptr;
+ static_assert(std::is_base_of_v<IPlatformResource, TSource>,
+ "TSource must be a subclass of IPlatformResource.");
+ const auto result = std::dynamic_pointer_cast<TTarget>(resource);
+ if (result == nullptr) {
+ throw PlatformNotMatchException(
+ resource->GetPlatformIdUtf8(), target_platform,
+ "Try to convert resource to target platform failed.");
+ }
+ return result;
+}
} // namespace cru::platform
diff --git a/include/cru/platform/Exception.h b/include/cru/platform/Exception.h
index 25017869..f8ed5b0c 100644
--- a/include/cru/platform/Exception.h
+++ b/include/cru/platform/Exception.h
@@ -14,7 +14,7 @@ class CRU_PLATFORM_API PlatformNotMatchException : public PlatformException {
public:
PlatformNotMatchException(
std::string resource_platform, std::string target_platform,
- std::optional<std::string> additional_message = std::nullopt);
+ std::optional<std::string_view> additional_message = std::nullopt);
PlatformNotMatchException(
StringView resource_platform, StringView target_platform,
diff --git a/include/cru/platform/Resource.h b/include/cru/platform/Resource.h
index 69210348..a16a9dbd 100644
--- a/include/cru/platform/Resource.h
+++ b/include/cru/platform/Resource.h
@@ -11,5 +11,7 @@ struct CRU_PLATFORM_API IPlatformResource : virtual Interface {
virtual String GetPlatformId() const = 0;
virtual String GetDebugString() { return String(); }
+
+ virtual std::string GetPlatformIdUtf8() const;
};
} // namespace cru::platform
diff --git a/include/cru/platform/gui/xcb/Window.h b/include/cru/platform/gui/xcb/Window.h
index e09fdbfb..f9fbf735 100644
--- a/include/cru/platform/gui/xcb/Window.h
+++ b/include/cru/platform/gui/xcb/Window.h
@@ -18,10 +18,10 @@ class XcbWindow : public XcbResource, public virtual INativeWindow {
explicit XcbWindow(XcbUiApplication* application);
~XcbWindow() override;
- virtual void Close() = 0;
+ void Close() override;
- virtual INativeWindow* GetParent() = 0;
- virtual void SetParent(INativeWindow* parent) = 0;
+ INativeWindow* GetParent() override;
+ void SetParent(INativeWindow* parent) override;
virtual WindowStyleFlag GetStyleFlag() = 0;
virtual void SetStyleFlag(WindowStyleFlag flag) = 0;
@@ -91,9 +91,11 @@ class XcbWindow : public XcbResource, public virtual INativeWindow {
private:
XcbUiApplication* application_;
std::optional<xcb_window_t> xcb_window_;
- cairo_surface_t *cairo_surface_;
+ cairo_surface_t* cairo_surface_;
Size current_size_;
+ XcbWindow* parent_;
+
Event<std::nullptr_t> create_event_;
Event<std::nullptr_t> destroy_event_;
Event<std::nullptr_t> paint_event_;