From f78f29ee66f5d67579791380098759768e3682e8 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Tue, 2 Jul 2024 18:13:53 -0500 Subject: [PATCH] AModule: retain existing default behavior when unconfigured --- man/waybar-styles.5.scd.in | 10 ++++++---- src/AModule.cpp | 13 +++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/man/waybar-styles.5.scd.in b/man/waybar-styles.5.scd.in index c1bc25e3..b11e15bd 100644 --- a/man/waybar-styles.5.scd.in +++ b/man/waybar-styles.5.scd.in @@ -42,9 +42,11 @@ You can apply special styling to any module for when the cursor hovers it. ## Setting cursor style Most, if not all, module types support setting the `cursor` option. This is -configured in your `config.jsonc`. If set to `true`, 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 -will be shown. +will not be shown. Default behavior is to indicate an interaction event is +available. + There are more cursor types to choose from by setting the `cursor` option to a number, see Gdk3 official docs for all possible cursor types: https://docs.gtk.org/gdk3/enum.CursorType.html. @@ -52,12 +54,12 @@ However, note that not all cursor options listed may be available on your system. If you attempt to use a cursor which is not available, the application will crash. -Example of enabling pointer(`Gdk::Hand2`) cursor type on a custom module: +Example of disabling pointer(`Gdk::Hand2`) cursor type on a custom module: ``` "custom/my-custom-module": { ... - "cursor": true, + "cursor": false, } ``` diff --git a/src/AModule.cpp b/src/AModule.cpp index 887b0de0..c180b480 100644 --- a/src/AModule.cpp +++ b/src/AModule.cpp @@ -69,6 +69,7 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std:: event_box_.signal_scroll_event().connect(sigc::mem_fun(*this, &AModule::handleScroll)); } + // Respect user configuration of cursor if (config_.isMember("cursor")) { if (config_["cursor"].isBool() && config_["cursor"].asBool()) { setCursor(Gdk::HAND2); @@ -125,6 +126,12 @@ bool AModule::handleMouseEnter(GdkEventCrossing* const& e) { if (auto* module = event_box_.get_child(); module != nullptr) { module->set_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT); } + + // Default behavior indicating event availability + if (hasUserEvents_ && !config_.isMember("cursor")) { + setCursor(Gdk::HAND2); + } + return false; } @@ -132,6 +139,12 @@ bool AModule::handleMouseLeave(GdkEventCrossing* const& e) { if (auto* module = event_box_.get_child(); module != nullptr) { module->unset_state_flags(Gtk::StateFlags::STATE_FLAG_PRELIGHT); } + + // Default behavior indicating event availability + if (hasUserEvents_ && !config_.isMember("cursor")) { + setCursor(Gdk::ARROW); + } + return false; }