aboutsummaryrefslogtreecommitdiff
path: root/src/platform/gui/xcb/Cursor.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-09-23 22:37:42 +0800
committerYuqian Yang <crupest@crupest.life>2025-09-23 22:37:42 +0800
commit9c7d93cdb85ccc89f0804b4f280eac099c4476c6 (patch)
tree7ce2dd98c2c61e4da09a6bf750b5f8fd56f929fe /src/platform/gui/xcb/Cursor.cpp
parent9737b7966c0b061ee80235d1c7c460efc0610894 (diff)
downloadcru-9c7d93cdb85ccc89f0804b4f280eac099c4476c6.tar.gz
cru-9c7d93cdb85ccc89f0804b4f280eac099c4476c6.tar.bz2
cru-9c7d93cdb85ccc89f0804b4f280eac099c4476c6.zip
Impl xcb cursor manager.
Diffstat (limited to 'src/platform/gui/xcb/Cursor.cpp')
-rw-r--r--src/platform/gui/xcb/Cursor.cpp38
1 files changed, 35 insertions, 3 deletions
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 <xcb/xcb.h>
+#include <xcb/xcb_cursor.h>
+#include <memory>
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<XcbCursor>(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<ICursor> XcbCursorManager::GetSystemCursor(
+ SystemCursorType type) {
+ return cursors_[type];
+}
+
+std::shared_ptr<XcbCursor> XcbCursorManager::LoadXCursor(
+ std::string_view name) {
+ return std::make_shared<XcbCursor>(
+ application_, xcb_cursor_load_cursor(xcb_cursor_context_, name.data()),
+ true);
+}
+
} // namespace cru::platform::gui::xcb