Skip to content

Commit aa8853e

Browse files
committed
GTK4: Migration MPD
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
1 parent a7ef5cc commit aa8853e

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

Diff for: include/modules/mpd/mpd.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace waybar::modules {
1414

15-
class MPD : public ALabel {
15+
class MPD final : public ALabel {
1616
friend class detail::Context;
1717

1818
// State machine
@@ -47,7 +47,7 @@ class MPD : public ALabel {
4747
std::string getOptionIcon(std::string optionName, bool activated) const;
4848

4949
// GUI-side methods
50-
bool handlePlayPause(GdkEventButton* const&);
50+
bool handlePlayPause(int n_press, double dx, double dy);
5151
void emit() { dp.emit(); }
5252

5353
// MPD-side, Non-GUI methods.

Diff for: meson.build

+13
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ xkbregistry = dependency('xkbregistry')
8484
libnl = dependency('libnl-3.0', required: get_option('libnl'))
8585
libnlgen = dependency('libnl-genl-3.0', required: get_option('libnl'))
8686
libpulse = dependency('libpulse', required: get_option('pulseaudio'))
87+
libmpdclient = dependency('libmpdclient', required: get_option('mpd'))
8788
libjack = dependency('jack', required: get_option('jack'))
8889
upower_glib = dependency('upower-glib', required: get_option('upower_glib'))
8990

@@ -208,6 +209,17 @@ if libevdev.found() and (is_linux or libepoll.found()) and libinput.found() and
208209
man_files += files('man/waybar-keyboard-state.5.scd')
209210
endif
210211

212+
#if libmpdclient.found()
213+
add_project_arguments('-DHAVE_LIBMPDCLIENT', language: 'cpp')
214+
src_files += files(
215+
'src/modules/mpd/mpd.cpp',
216+
'src/modules/mpd/state.cpp',
217+
)
218+
man_files += files(
219+
'man/waybar-mpd.5.scd',
220+
)
221+
#endif
222+
211223
if libsndio.found()
212224
add_project_arguments('-DHAVE_LIBSNDIO', language: 'cpp')
213225
src_files += files('src/modules/sndio.cpp')
@@ -365,6 +377,7 @@ executable(
365377
libnl,
366378
libnlgen,
367379
libpulse,
380+
libmpdclient,
368381
libjack,
369382
libsndio,
370383
upower_glib

Diff for: src/modules/mpd/mpd.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
3939
server_ = config["server"].asCString();
4040
}
4141
42-
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
43-
event_box_.signal_button_press_event().connect(sigc::mem_fun(*this, &MPD::handlePlayPause));
42+
controllClick_->signal_pressed().connect(sigc::mem_fun(*this, &MPD::handlePlayPause), false);
4443
}
4544
4645
auto waybar::modules::MPD::update() -> void {
@@ -327,17 +326,18 @@ void waybar::modules::MPD::fetchState() {
327326
checkErrors(conn);
328327
}
329328
330-
bool waybar::modules::MPD::handlePlayPause(GdkEventButton* const& e) {
331-
if (e->type == GDK_2BUTTON_PRESS || e->type == GDK_3BUTTON_PRESS || connection_ == nullptr) {
329+
bool waybar::modules::MPD::handlePlayPause(int n_press, double dx, double dy) {
330+
if (n_press != 1 || connection_ = nullptr)
332331
return false;
333-
}
334332
335-
if (e->button == 1) {
333+
auto button{controllClick_->get_current_button()};
334+
335+
if (button == 1u) {
336336
if (state_ == MPD_STATE_PLAY)
337337
context_.pause();
338338
else
339339
context_.play();
340-
} else if (e->button == 3) {
340+
} else if (button == 3u) {
341341
context_.stop();
342342
}
343343

Diff for: src/modules/mpd/state.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ void Idle::entry() noexcept {
6666
spdlog::error("mpd: Idle: failed to register for IDLE events");
6767
} else {
6868
spdlog::debug("mpd: Idle: watching FD");
69-
sigc::slot<bool, Glib::IOCondition const&> idle_slot = sigc::mem_fun(*this, &Idle::on_io);
69+
sigc::slot<bool(Glib::IOCondition const&)> idle_slot = sigc::mem_fun(*this, &Idle::on_io);
7070
idle_connection_ =
7171
Glib::signal_io().connect(idle_slot, mpd_connection_get_fd(conn),
72-
Glib::IO_IN | Glib::IO_PRI | Glib::IO_ERR | Glib::IO_HUP);
72+
Glib::IOCondition::IO_IN | Glib::IOCondition::IO_PRI | Glib::IOCondition::IO_ERR | Glib::IOCondition::IO_HUP);
7373
}
7474
}
7575

@@ -118,7 +118,7 @@ bool Idle::on_io(Glib::IOCondition const&) {
118118
}
119119

120120
void Playing::entry() noexcept {
121-
sigc::slot<bool> timer_slot = sigc::mem_fun(*this, &Playing::on_timer);
121+
sigc::slot<bool()> timer_slot = sigc::mem_fun(*this, &Playing::on_timer);
122122
timer_connection_ = Glib::signal_timeout().connect(timer_slot, /* milliseconds */ 1'000);
123123
spdlog::debug("mpd: Playing: enabled 1 second periodic timer.");
124124
}
@@ -186,7 +186,7 @@ void Playing::pause() {
186186
void Playing::update() noexcept { ctx_->do_update(); }
187187

188188
void Paused::entry() noexcept {
189-
sigc::slot<bool> timer_slot = sigc::mem_fun(*this, &Paused::on_timer);
189+
sigc::slot<bool()> timer_slot = sigc::mem_fun(*this, &Paused::on_timer);
190190
timer_connection_ = Glib::signal_timeout().connect(timer_slot, /* milliseconds */ 200);
191191
spdlog::debug("mpd: Paused: enabled 200 ms periodic timer.");
192192
}
@@ -257,7 +257,7 @@ void Paused::stop() {
257257
void Paused::update() noexcept { ctx_->do_update(); }
258258

259259
void Stopped::entry() noexcept {
260-
sigc::slot<bool> timer_slot = sigc::mem_fun(*this, &Stopped::on_timer);
260+
sigc::slot<bool()> timer_slot = sigc::mem_fun(*this, &Stopped::on_timer);
261261
timer_connection_ = Glib::signal_timeout().connect(timer_slot, /* milliseconds */ 200);
262262
spdlog::debug("mpd: Stopped: enabled 200 ms periodic timer.");
263263
}
@@ -332,7 +332,7 @@ void Disconnected::arm_timer(int interval) noexcept {
332332
disarm_timer();
333333

334334
// register timer
335-
sigc::slot<bool> timer_slot = sigc::mem_fun(*this, &Disconnected::on_timer);
335+
sigc::slot<bool()> timer_slot = sigc::mem_fun(*this, &Disconnected::on_timer);
336336
timer_connection_ = Glib::signal_timeout().connect(timer_slot, interval);
337337
spdlog::debug("mpd: Disconnected: enabled interval timer.");
338338
}

0 commit comments

Comments
 (0)