1
1
#include " AModule.hpp"
2
2
3
3
#include < fmt/format.h>
4
+ #include < spdlog/spdlog.h>
4
5
5
6
#include < util/command.hpp>
6
7
8
+ #include " gdk/gdk.h"
9
+ #include " gdkmm/cursor.h"
10
+
7
11
namespace waybar {
8
12
9
13
AModule::AModule (const Json::Value& config, const std::string& name, const std::string& id,
@@ -64,6 +68,17 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std::
64
68
event_box_.add_events (Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
65
69
event_box_.signal_scroll_event ().connect (sigc::mem_fun (*this , &AModule::handleScroll));
66
70
}
71
+
72
+ // Respect user configuration of cursor
73
+ if (config_.isMember (" cursor" )) {
74
+ if (config_[" cursor" ].isBool () && config_[" cursor" ].asBool ()) {
75
+ setCursor (Gdk::HAND2);
76
+ } else if (config_[" cursor" ].isInt ()) {
77
+ setCursor (Gdk::CursorType (config_[" cursor" ].asInt ()));
78
+ } else {
79
+ spdlog::warn (" unknown cursor option configured on module {}" , name_);
80
+ }
81
+ }
67
82
}
68
83
69
84
AModule::~AModule () {
@@ -91,19 +106,32 @@ auto AModule::doAction(const std::string& name) -> void {
91
106
}
92
107
93
108
void AModule::setCursor (Gdk::CursorType const & c) {
94
- auto cursor = Gdk::Cursor::create (c);
95
109
auto gdk_window = event_box_.get_window ();
96
- gdk_window->set_cursor (cursor);
110
+ if (gdk_window) {
111
+ auto cursor = Gdk::Cursor::create (c);
112
+ gdk_window->set_cursor (cursor);
113
+ } else {
114
+ // window may not be accessible yet, in this case,
115
+ // schedule another call for setting the cursor in 1 sec
116
+ Glib::signal_timeout ().connect_seconds (
117
+ [this , c]() {
118
+ setCursor (c);
119
+ return false ;
120
+ },
121
+ 1 );
122
+ }
97
123
}
98
124
99
125
bool AModule::handleMouseEnter (GdkEventCrossing* const & e) {
100
126
if (auto * module = event_box_.get_child (); module != nullptr ) {
101
127
module->set_state_flags (Gtk::StateFlags::STATE_FLAG_PRELIGHT);
102
128
}
103
129
104
- if (hasUserEvents_) {
130
+ // Default behavior indicating event availability
131
+ if (hasUserEvents_ && !config_.isMember (" cursor" )) {
105
132
setCursor (Gdk::HAND2);
106
133
}
134
+
107
135
return false ;
108
136
}
109
137
@@ -112,9 +140,11 @@ bool AModule::handleMouseLeave(GdkEventCrossing* const& e) {
112
140
module->unset_state_flags (Gtk::StateFlags::STATE_FLAG_PRELIGHT);
113
141
}
114
142
115
- if (hasUserEvents_) {
143
+ // Default behavior indicating event availability
144
+ if (hasUserEvents_ && !config_.isMember (" cursor" )) {
116
145
setCursor (Gdk::ARROW);
117
146
}
147
+
118
148
return false ;
119
149
}
120
150
0 commit comments