From 9c7d93cdb85ccc89f0804b4f280eac099c4476c6 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Tue, 23 Sep 2025 22:37:42 +0800 Subject: Impl xcb cursor manager. --- src/platform/gui/xcb/Cursor.cpp | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'src/platform/gui/xcb/Cursor.cpp') diff --git a/src/platform/gui/xcb/Cursor.cpp b/src/platform/gui/xcb/Cursor.cpp index 7bc73f6d..5582c6a6 100644 --- a/src/platform/gui/xcb/Cursor.cpp +++ b/src/platform/gui/xcb/Cursor.cpp @@ -1,12 +1,13 @@ #include "cru/platform/gui/xcb/Cursor.h" -#include "cru/base/Base.h" +#include "cru/base/Exception.h" +#include "cru/platform/gui/Cursor.h" #include "cru/platform/gui/xcb/UiApplication.h" #include +#include +#include namespace cru::platform::gui::xcb { -XcbCursor* XcbCursor::LoadXCursor(io::Stream* stream) { NotImplemented(); } - XcbCursor::XcbCursor(XcbUiApplication* application, xcb_cursor_t cursor, bool auto_free) : application_(application), cursor_(cursor), auto_free_(auto_free) {} @@ -19,4 +20,35 @@ XcbCursor::~XcbCursor() { xcb_cursor_t XcbCursor::GetXcbCursor() { return cursor_; } +XcbCursorManager::XcbCursorManager(XcbUiApplication* application) + : application_(application) { + auto code = xcb_cursor_context_new(application->GetXcbConnection(), + application->GetFirstXcbScreen(), + &xcb_cursor_context_); + if (code != 0) { + throw PlatformException("Failed to call xcb_cursor_context_new."); + } + + cursors_[SystemCursorType::Arrow] = + std::make_shared(application_, XCB_CURSOR_NONE, false); + cursors_[SystemCursorType::Hand] = LoadXCursor("pointer"); + cursors_[SystemCursorType::IBeam] = LoadXCursor("ibeam"); +} + +XcbCursorManager::~XcbCursorManager() { + xcb_cursor_context_free(xcb_cursor_context_); +} + +std::shared_ptr XcbCursorManager::GetSystemCursor( + SystemCursorType type) { + return cursors_[type]; +} + +std::shared_ptr XcbCursorManager::LoadXCursor( + std::string_view name) { + return std::make_shared( + application_, xcb_cursor_load_cursor(xcb_cursor_context_, name.data()), + true); +} + } // namespace cru::platform::gui::xcb -- cgit v1.2.3