From 7e61e5f5d5562a37885df31b1042b936da97d209 Mon Sep 17 00:00:00 2001 From: Viktar Lukashonak Date: Sun, 17 Mar 2024 12:34:31 +0300 Subject: [PATCH] Gtk4: Migration dwl/tags Signed-off-by: Viktar Lukashonak --- include/modules/bluetooth.hpp | 2 +- include/modules/cpu.hpp | 2 +- include/modules/custom.hpp | 2 +- include/modules/disk.hpp | 2 +- include/modules/dwl/tags.hpp | 14 +++++------ include/modules/memory.hpp | 2 +- include/modules/temperature.hpp | 2 +- meson.build | 4 ++++ src/factory.cpp | 4 ++-- src/modules/dwl/tags.cpp | 41 +++++++++++++++------------------ 10 files changed, 36 insertions(+), 39 deletions(-) diff --git a/include/modules/bluetooth.hpp b/include/modules/bluetooth.hpp index 056e7211..ead18561 100644 --- a/include/modules/bluetooth.hpp +++ b/include/modules/bluetooth.hpp @@ -7,7 +7,7 @@ namespace waybar::modules { -class Bluetooth : public ALabel { +class Bluetooth final : public ALabel { struct ControllerInfo { std::string path; std::string address; diff --git a/include/modules/cpu.hpp b/include/modules/cpu.hpp index d8790364..085c6566 100644 --- a/include/modules/cpu.hpp +++ b/include/modules/cpu.hpp @@ -5,7 +5,7 @@ namespace waybar::modules { -class Cpu : public ALabel { +class Cpu final : public ALabel { public: Cpu(const std::string&, const Json::Value&); virtual ~Cpu() = default; diff --git a/include/modules/custom.hpp b/include/modules/custom.hpp index 72190ab5..427632eb 100644 --- a/include/modules/custom.hpp +++ b/include/modules/custom.hpp @@ -7,7 +7,7 @@ namespace waybar::modules { -class Custom : public ALabel { +class Custom final : public ALabel { public: Custom(const std::string&, const std::string&, const Json::Value&, const std::string&); virtual ~Custom(); diff --git a/include/modules/disk.hpp b/include/modules/disk.hpp index 45c4ce04..d0f31c5f 100644 --- a/include/modules/disk.hpp +++ b/include/modules/disk.hpp @@ -5,7 +5,7 @@ namespace waybar::modules { -class Disk : public ALabel { +class Disk final : public ALabel { public: Disk(const std::string&, const Json::Value&); virtual ~Disk() = default; diff --git a/include/modules/dwl/tags.hpp b/include/modules/dwl/tags.hpp index 53dff989..566151c2 100644 --- a/include/modules/dwl/tags.hpp +++ b/include/modules/dwl/tags.hpp @@ -1,34 +1,32 @@ #pragma once #include -#include #include "AModule.hpp" #include "bar.hpp" #include "dwl-ipc-unstable-v2-client-protocol.h" -#include "xdg-output-unstable-v1-client-protocol.h" namespace waybar::modules::dwl { -class Tags : public waybar::AModule { +class Tags final : public waybar::AModule { public: Tags(const std::string &, const waybar::Bar &, const Json::Value &); virtual ~Tags(); - // Handlers for wayland events void handle_view_tags(uint32_t tag, uint32_t state, uint32_t clients, uint32_t focused); - void handle_primary_clicked(uint32_t tag); - bool handle_button_press(GdkEventButton *event_button, uint32_t tag); - struct zdwl_ipc_manager_v2 *status_manager_; struct wl_seat *seat_; - private: const waybar::Bar &bar_; Gtk::Box box_; std::vector buttons_; + std::vector> clickControls_; struct zdwl_ipc_output_v2 *output_status_; + + void handle_primary_clicked(int n_press, double dx, double dy, uint32_t tag); + void handle_button_press(int n_press, double dx, double dy, uint32_t tag, + Glib::RefPtr controlClick); }; } /* namespace waybar::modules::dwl */ diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp index b03a6349..628a8b3a 100644 --- a/include/modules/memory.hpp +++ b/include/modules/memory.hpp @@ -7,7 +7,7 @@ namespace waybar::modules { -class Memory : public ALabel { +class Memory final : public ALabel { public: Memory(const std::string&, const Json::Value&); virtual ~Memory() = default; diff --git a/include/modules/temperature.hpp b/include/modules/temperature.hpp index 13c32647..6a34d9b0 100644 --- a/include/modules/temperature.hpp +++ b/include/modules/temperature.hpp @@ -5,7 +5,7 @@ namespace waybar::modules { -class Temperature : public ALabel { +class Temperature final : public ALabel { public: Temperature(const std::string&, const Json::Value&); virtual ~Temperature() = default; diff --git a/meson.build b/meson.build index 7975fee5..21a35bcb 100644 --- a/meson.build +++ b/meson.build @@ -229,6 +229,10 @@ elif is_dragonfly or is_freebsd or is_netbsd or is_openbsd endif endif +add_project_arguments('-DHAVE_DWL', language: 'cpp') +src_files += files('src/modules/dwl/tags.cpp') +man_files += files('man/waybar-dwl-tags.5.scd') + subdir('protocol') executable( diff --git a/src/factory.cpp b/src/factory.cpp index 149f4a31..d136f33d 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -182,12 +182,12 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name, if (ref == "river/layout") { return new waybar::modules::river::Layout(id, bar_, config_[name]); } -#endif +#endif*/ #ifdef HAVE_DWL if (ref == "dwl/tags") { return new waybar::modules::dwl::Tags(id, bar_, config_[name]); } -#endif +#endif/* #ifdef HAVE_HYPRLAND if (ref == "hyprland/window") { return new waybar::modules::hyprland::Window(id, bar_, config_[name]); diff --git a/src/modules/dwl/tags.cpp b/src/modules/dwl/tags.cpp index f36ece1d..189e3c6d 100644 --- a/src/modules/dwl/tags.cpp +++ b/src/modules/dwl/tags.cpp @@ -1,14 +1,7 @@ #include "modules/dwl/tags.hpp" - -#include -#include -#include -#include - -#include - #include "client.hpp" -#include "dwl-ipc-unstable-v2-client-protocol.h" + +#include #define TAG_INACTIVE 0 #define TAG_ACTIVE 1 @@ -114,7 +107,6 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con box_.get_style_context()->add_class(id); } box_.get_style_context()->add_class(MODULE_CLASS); - event_box_.add(box_); // Default to 9 tags, cap at 32 const uint32_t num_tags = @@ -133,14 +125,18 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con uint32_t i = 1; for (const auto &tag_label : tag_labels) { - Gtk::Button &button = buttons_.emplace_back(tag_label); - button.set_relief(Gtk::RELIEF_NONE); - box_.pack_start(button, false, false, 0); + Gtk::Button &button{buttons_.emplace_back(tag_label)}; + auto controlClick{clickControls_.emplace_back(Gtk::GestureClick::create())}; + controlClick->set_propagation_phase(Gtk::PropagationPhase::TARGET); + controlClick->set_button(0); + button.add_controller(controlClick); + button.set_has_frame(false); + box_.prepend(button); if (!config_["disable-click"].asBool()) { - button.signal_clicked().connect( - sigc::bind(sigc::mem_fun(*this, &Tags::handle_primary_clicked), i)); - button.signal_button_press_event().connect( - sigc::bind(sigc::mem_fun(*this, &Tags::handle_button_press), i)); + controlClick->signal_pressed().connect(sigc::bind(sigc::mem_fun(*this, + &Tags::handle_button_press), i, controlClick)); + controlClick->signal_released().connect(sigc::bind(sigc::mem_fun(*this, + &Tags::handle_primary_clicked), i)); } button.show(); i <<= 1; @@ -160,18 +156,17 @@ Tags::~Tags() { } } -void Tags::handle_primary_clicked(uint32_t tag) { +void Tags::handle_primary_clicked(int n_press, double dx, double dy, uint32_t tag) { if (!output_status_) return; - zdwl_ipc_output_v2_set_tags(output_status_, tag, 1); } -bool Tags::handle_button_press(GdkEventButton *event_button, uint32_t tag) { - if (event_button->type == GDK_BUTTON_PRESS && event_button->button == 3) { - if (!output_status_) return true; +void Tags::handle_button_press(int n_press, double dx, double dy, uint32_t tag, + Glib::RefPtr controlClick) { + if (controlClick->get_current_button() == 3) { + if (!output_status_) return; zdwl_ipc_output_v2_set_tags(output_status_, num_tags ^ tag, 0); } - return true; } void Tags::handle_view_tags(uint32_t tag, uint32_t state, uint32_t clients, uint32_t focused) {