Merge pull request #5133 from J0hannes101/master

feat(cursor): use cursor-shape-v1 cursor names instead of Gdk::CursorType
This commit is contained in:
Alexis Rouillard
2026-07-04 00:30:33 +02:00
committed by GitHub
4 changed files with 18 additions and 21 deletions
+1 -1
View File
@@ -45,7 +45,7 @@ class AModule : public IModule {
const Json::Value& config_; const Json::Value& config_;
Gtk::EventBox event_box_; Gtk::EventBox event_box_;
virtual void setCursor(Gdk::CursorType const& c); virtual void setCursor(std::string const& c);
virtual bool handleToggle(GdkEventButton* const& ev); virtual bool handleToggle(GdkEventButton* const& ev);
virtual bool handleMouseEnter(GdkEventCrossing* const& ev); virtual bool handleMouseEnter(GdkEventCrossing* const& ev);
+9 -11
View File
@@ -57,18 +57,17 @@ You can apply special styling to any module for when the cursor hovers it.
Most, if not all, module types support setting the `cursor` option. This is Most, if not all, module types support setting the `cursor` option. This is
configured in your `config.jsonc`. If set to `false`, when hovering the module a configured in your `config.jsonc`. If set to `false`, when hovering the module a
"pointer"(as commonly known from web CSS styling `cursor: pointer`) style cursor "pointer" (as commonly known from web CSS styling `cursor: pointer`) style cursor
will not be shown. Default behavior is to indicate an interaction event is will not be shown. Default behavior is to indicate an interaction event is
available. available.
There are more cursor types to choose from by setting the `cursor` option to If set to a string value, it must be a valid cursor name
a number, see Gdk3 official docs for all possible cursor types: (e.g. `"pointer"`, `"default"`, `"grab"`, `"text"`, `"crosshair"`, etc.),
https://docs.gtk.org/gdk3/enum.CursorType.html. see the cursor-shape-v1 protocol for all possible cursor types:
However, note that not all cursor options listed may be available on https://wayland.app/protocols/cursor-shape-v1#wp_cursor_shape_device_v1:enum:shape.
your system. If you attempt to use a cursor which is not available, the Depending on the compositor and cursor theme used, cursors not listed in the protocol may also work.
application will crash.
Example of disabling pointer(`Gdk::Hand2`) cursor type on a custom module: Example of disabling the cursor on a custom module:
``` ```
"custom/my-custom-module": { "custom/my-custom-module": {
@@ -77,13 +76,12 @@ Example of disabling pointer(`Gdk::Hand2`) cursor type on a custom module:
} }
``` ```
Example of setting cursor type to `Gdk::Boat`(according to Example of setting the cursor type to `"grab"`:
https://docs.gtk.org/gdk3/enum.CursorType.html#boat):
``` ```
"custom/my-custom-module": { "custom/my-custom-module": {
... ...
"cursor": 8, "cursor": "grab",
} }
``` ```
+8 -8
View File
@@ -78,12 +78,12 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std::
if (config_.isMember("cursor")) { if (config_.isMember("cursor")) {
if (config_["cursor"].isBool()) { if (config_["cursor"].isBool()) {
if (config_["cursor"].asBool()) { if (config_["cursor"].asBool()) {
setCursor(Gdk::HAND2); setCursor("pointer");
} else { } else {
setCursor(Gdk::ARROW); setCursor("default");
} }
} else if (config_["cursor"].isInt()) { } else if (config_["cursor"].isString()) {
setCursor(Gdk::CursorType(config_["cursor"].asInt())); setCursor(config_["cursor"].asString());
} else { } else {
spdlog::warn("unknown cursor option configured on module {}", name_); spdlog::warn("unknown cursor option configured on module {}", name_);
} }
@@ -121,10 +121,10 @@ auto AModule::doAction(const std::string& name) -> void {
} }
} }
void AModule::setCursor(Gdk::CursorType const& c) { void AModule::setCursor(std::string const& c) {
auto gdk_window = event_box_.get_window(); auto gdk_window = event_box_.get_window();
if (gdk_window) { if (gdk_window) {
auto cursor = Gdk::Cursor::create(c); auto cursor = Gdk::Cursor::create(gdk_window->get_display(), c);
gdk_window->set_cursor(cursor); gdk_window->set_cursor(cursor);
} else { } else {
// window may not be accessible yet, in this case, // window may not be accessible yet, in this case,
@@ -145,7 +145,7 @@ bool AModule::handleMouseEnter(GdkEventCrossing* const& e) {
// Default behavior indicating event availability // Default behavior indicating event availability
if (hasUserEvents_ && !config_.isMember("cursor")) { if (hasUserEvents_ && !config_.isMember("cursor")) {
setCursor(Gdk::HAND2); setCursor("pointer");
} }
return false; return false;
@@ -158,7 +158,7 @@ bool AModule::handleMouseLeave(GdkEventCrossing* const& e) {
// Default behavior indicating event availability // Default behavior indicating event availability
if (hasUserEvents_ && !config_.isMember("cursor")) { if (hasUserEvents_ && !config_.isMember("cursor")) {
setCursor(Gdk::ARROW); setCursor("default");
} }
return false; return false;
-1
View File
@@ -7,7 +7,6 @@
#include <algorithm> #include <algorithm>
#include <chrono> #include <chrono>
#include "gdkmm/cursor.h"
#include "gdkmm/event.h" #include "gdkmm/event.h"
#include "gdkmm/types.h" #include "gdkmm/types.h"
#include "glibmm/fileutils.h" #include "glibmm/fileutils.h"