Skip to content

Commit 078a2c3

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

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class MPD final : public ALabel {
4747
std::string getOptionIcon(std::string optionName, bool activated) const;
4848

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

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ extern "C" {
1616

1717
namespace waybar::modules::mpris {
1818

19-
class Mpris : public ALabel {
19+
class Mpris final : public ALabel {
2020
public:
2121
Mpris(const std::string&, const Json::Value&);
2222
virtual ~Mpris();
2323
auto update() -> void override;
24-
bool handleToggle(GdkEventButton* const&) override;
24+
void handleToggle(int n_press, double dx, double dy) override;
2525

2626
private:
2727
static auto onPlayerNameAppeared(PlayerctlPlayerManager*, PlayerctlPlayerName*, gpointer) -> void;

Diff for: meson.build

+10-2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ libpulse = dependency('libpulse', required: get_option('pulseaudio'))
8787
libmpdclient = dependency('libmpdclient', required: get_option('mpd'))
8888
libjack = dependency('jack', required: get_option('jack'))
8989
upower_glib = dependency('upower-glib', required: get_option('upower_glib'))
90+
playerctl = dependency('playerctl', version : ['>=2.0.0'], required: get_option('mpris'))
9091

9192
libsndio = compiler.find_library('sndio', required: get_option('sndio'))
9293
if libsndio.found()
@@ -209,7 +210,7 @@ if libevdev.found() and (is_linux or libepoll.found()) and libinput.found() and
209210
man_files += files('man/waybar-keyboard-state.5.scd')
210211
endif
211212

212-
#if libmpdclient.found()
213+
if libmpdclient.found()
213214
add_project_arguments('-DHAVE_LIBMPDCLIENT', language: 'cpp')
214215
src_files += files(
215216
'src/modules/mpd/mpd.cpp',
@@ -218,7 +219,7 @@ endif
218219
man_files += files(
219220
'man/waybar-mpd.5.scd',
220221
)
221-
#endif
222+
endif
222223

223224
if libsndio.found()
224225
add_project_arguments('-DHAVE_LIBSNDIO', language: 'cpp')
@@ -333,6 +334,12 @@ if (upower_glib.found() and not get_option('logind').disabled())
333334
man_files += files('man/waybar-upower.5.scd')
334335
endif
335336

337+
if playerctl.found()
338+
add_project_arguments('-DHAVE_MPRIS', language: 'cpp')
339+
src_files += files('src/modules/mpris/mpris.cpp')
340+
man_files += files('man/waybar-mpris.5.scd')
341+
endif
342+
336343
if libpulse.found()
337344
add_project_arguments('-DHAVE_LIBPULSE', language: 'cpp')
338345
src_files += files(
@@ -376,6 +383,7 @@ executable(
376383
libinput,
377384
libnl,
378385
libnlgen,
386+
playerctl,
379387
libpulse,
380388
libmpdclient,
381389
libjack,

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ void waybar::modules::MPD::fetchState() {
326326
checkErrors(conn);
327327
}
328328
329-
bool waybar::modules::MPD::handlePlayPause(int n_press, double dx, double dy) {
329+
void waybar::modules::MPD::handlePlayPause(int n_press, double dx, double dy) {
330330
if (n_press != 1 || connection_ = nullptr)
331-
return false;
331+
return;
332332
333333
auto button{controllClick_->get_current_button()};
334334
@@ -340,6 +340,4 @@ bool waybar::modules::MPD::handlePlayPause(int n_press, double dx, double dy) {
340340
} else if (button == 3u) {
341341
context_.stop();
342342
}
343-
344-
return true;
345343
}

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

+12-14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern "C" {
1414

1515
#include <glib.h>
1616
#include <spdlog/spdlog.h>
17+
#include <glibmm/markup.h>
1718

1819
namespace waybar::modules::mpris {
1920

@@ -462,7 +463,7 @@ auto Mpris::onPlayerStop(PlayerctlPlayer* player, gpointer data) -> void {
462463
spdlog::debug("mpris: player-stop callback");
463464

464465
// hide widget
465-
mpris->event_box_.set_visible(false);
466+
mpris->label_.set_visible(false);
466467
// update widget
467468
mpris->dp.emit();
468469
}
@@ -586,7 +587,7 @@ auto Mpris::getPlayerInfo() -> std::optional<PlayerInfo> {
586587
return std::nullopt;
587588
}
588589

589-
bool Mpris::handleToggle(GdkEventButton* const& e) {
590+
void Mpris::handleToggle(int n_press, double dx, double dy) {
590591
GError* error = nullptr;
591592
waybar::util::ScopeGuard error_deleter([error]() {
592593
if (error) {
@@ -595,36 +596,33 @@ bool Mpris::handleToggle(GdkEventButton* const& e) {
595596
});
596597

597598
auto info = getPlayerInfo();
598-
if (!info) return false;
599+
if (!info) return;
599600

600-
if (e->type == GdkEventType::GDK_BUTTON_PRESS) {
601-
switch (e->button) {
601+
if (n_press == 1) {
602+
switch (controllClick_->get_current_button()) {
602603
case 1: // left-click
603604
if (config_["on-click"].isString()) {
604-
return ALabel::handleToggle(e);
605+
return ALabel::handleToggle(n_press, dx, dy);
605606
}
606607
playerctl_player_play_pause(player, &error);
607608
break;
608609
case 2: // middle-click
609610
if (config_["on-click-middle"].isString()) {
610-
return ALabel::handleToggle(e);
611+
return ALabel::handleToggle(n_press, dx, dy);
611612
}
612613
playerctl_player_previous(player, &error);
613614
break;
614615
case 3: // right-click
615616
if (config_["on-click-right"].isString()) {
616-
return ALabel::handleToggle(e);
617+
return ALabel::handleToggle(n_press, dx, dy);
617618
}
618619
playerctl_player_next(player, &error);
619620
break;
620621
}
621622
}
622-
if (error) {
623+
if (error)
623624
spdlog::error("mpris[{}]: error running builtin on-click action: {}", (*info).name,
624625
error->message);
625-
return false;
626-
}
627-
return true;
628626
}
629627

630628
auto Mpris::update() -> void {
@@ -634,7 +632,7 @@ auto Mpris::update() -> void {
634632

635633
auto opt = getPlayerInfo();
636634
if (!opt) {
637-
event_box_.set_visible(false);
635+
label_.set_visible(false);
638636
ALabel::update();
639637
return;
640638
}
@@ -732,7 +730,7 @@ auto Mpris::update() -> void {
732730
}
733731
}
734732

735-
event_box_.set_visible(true);
733+
label_.set_visible(true);
736734
// call parent update
737735
ALabel::update();
738736
}

0 commit comments

Comments
 (0)