diff --git a/Makefile.base.mk b/Makefile.base.mk index 016777d7..c4b0e05c 100644 --- a/Makefile.base.mk +++ b/Makefile.base.mk @@ -304,8 +304,7 @@ ifeq ($(HAVE_X11),true) DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11) -DHAVE_X11 DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11) ifeq ($(HAVE_XCURSOR),true) -# TODO -DHAVE_XCURSOR -DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor) +DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor) -DHAVE_XCURSOR DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xcursor) endif ifeq ($(HAVE_XEXT),true) diff --git a/dgl/Base.hpp b/dgl/Base.hpp index 0288cb06..bb0538c9 100644 --- a/dgl/Base.hpp +++ b/dgl/Base.hpp @@ -130,6 +130,23 @@ enum CrossingMode { kCrossingUngrab ///< Crossing due to a grab release }; +/** + A mouse cursor type. + + This is a portable subset of mouse cursors that exist on X11, MacOS, and Windows. +*/ +enum MouseCursor { + kMouseCursorArrow, ///< Default pointing arrow + kMouseCursorCaret, ///< Caret (I-Beam) for text entry + kMouseCursorCrosshair, ///< Cross-hair + kMouseCursorHand, ///< Hand with a pointing finger + kMouseCursorNotAllowed, ///< Operation not allowed + kMouseCursorLeftRight, ///< Left/right arrow for horizontal resize + kMouseCursorUpDown, ///< Up/down arrow for vertical resize + kMouseCursorDiagonal, ///< Top-left to bottom-right arrow for diagonal resize + kMouseCursorAntiDiagonal ///< Bottom-left to top-right arrow for diagonal resize +}; + /** Scroll direction. diff --git a/dgl/TopLevelWidget.hpp b/dgl/TopLevelWidget.hpp index dfdcf750..522dfaf8 100644 --- a/dgl/TopLevelWidget.hpp +++ b/dgl/TopLevelWidget.hpp @@ -103,6 +103,7 @@ public: // TODO group stuff after here, convenience functions present in Window class bool setClipboard(const char* mimeType, const void* data, size_t dataSize); const void* getClipboard(const char*& mimeType, size_t& dataSize); + bool setCursor(MouseCursor cursor); bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs = 0); bool removeIdleCallback(IdleCallback* callback); double getScaleFactor() const noexcept; diff --git a/dgl/Window.hpp b/dgl/Window.hpp index d884f54f..f91bb41e 100644 --- a/dgl/Window.hpp +++ b/dgl/Window.hpp @@ -284,6 +284,15 @@ public: */ const void* getClipboard(const char*& mimeType, size_t& dataSize); + /** + Set the mouse cursor. + + This changes the system cursor that is displayed when the pointer is inside the window. + May fail if setting the cursor is not supported on this system, + for example if compiled on X11 without Xcursor support. + */ + bool setCursor(MouseCursor cursor); + /** Add a callback function to be triggered on every idle cycle or on a specific timer frequency. You can add more than one, and remove them at anytime with removeIdleCallback(). diff --git a/dgl/src/TopLevelWidget.cpp b/dgl/src/TopLevelWidget.cpp index 4c0257b6..9a6b5c26 100644 --- a/dgl/src/TopLevelWidget.cpp +++ b/dgl/src/TopLevelWidget.cpp @@ -70,6 +70,11 @@ const void* TopLevelWidget::getClipboard(const char*& mimeType, size_t& dataSize return pData->window.getClipboard(mimeType, dataSize); } +bool TopLevelWidget::setCursor(const MouseCursor cursor) +{ + return pData->window.setCursor(cursor); +} + bool TopLevelWidget::addIdleCallback(IdleCallback* const callback, const uint timerFrequencyInMs) { return pData->window.addIdleCallback(callback, timerFrequencyInMs); diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index 6fa5f3a6..1e2f3a12 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -271,6 +271,11 @@ const void* Window::getClipboard(const char*& mimeType, size_t& dataSize) return clipboard; } +bool Window::setCursor(const MouseCursor cursor) +{ + return puglSetCursor(pData->view, static_cast(cursor)) == PUGL_SUCCESS; +} + bool Window::addIdleCallback(IdleCallback* const callback, const uint timerFrequencyInMs) { DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr, false) diff --git a/dgl/src/pugl-upstream b/dgl/src/pugl-upstream index f69d953d..d6c17abe 160000 --- a/dgl/src/pugl-upstream +++ b/dgl/src/pugl-upstream @@ -1 +1 @@ -Subproject commit f69d953d95dae70e32d37e522076fd41cec31a22 +Subproject commit d6c17abe22399acefc00fd0b78b99ea38ce27f41