Gtk4: Migration dwl/tags

Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
pull/2956/head
Viktar Lukashonak 2024-03-17 12:34:31 +03:00
parent b4a28042d8
commit 7e61e5f5d5
No known key found for this signature in database
GPG Key ID: 08A413AA87200A6F
10 changed files with 36 additions and 39 deletions

View File

@ -7,7 +7,7 @@
namespace waybar::modules { namespace waybar::modules {
class Bluetooth : public ALabel { class Bluetooth final : public ALabel {
struct ControllerInfo { struct ControllerInfo {
std::string path; std::string path;
std::string address; std::string address;

View File

@ -5,7 +5,7 @@
namespace waybar::modules { namespace waybar::modules {
class Cpu : public ALabel { class Cpu final : public ALabel {
public: public:
Cpu(const std::string&, const Json::Value&); Cpu(const std::string&, const Json::Value&);
virtual ~Cpu() = default; virtual ~Cpu() = default;

View File

@ -7,7 +7,7 @@
namespace waybar::modules { namespace waybar::modules {
class Custom : public ALabel { class Custom final : public ALabel {
public: public:
Custom(const std::string&, const std::string&, const Json::Value&, const std::string&); Custom(const std::string&, const std::string&, const Json::Value&, const std::string&);
virtual ~Custom(); virtual ~Custom();

View File

@ -5,7 +5,7 @@
namespace waybar::modules { namespace waybar::modules {
class Disk : public ALabel { class Disk final : public ALabel {
public: public:
Disk(const std::string&, const Json::Value&); Disk(const std::string&, const Json::Value&);
virtual ~Disk() = default; virtual ~Disk() = default;

View File

@ -1,34 +1,32 @@
#pragma once #pragma once
#include <gtkmm/button.h> #include <gtkmm/button.h>
#include <wayland-client.h>
#include "AModule.hpp" #include "AModule.hpp"
#include "bar.hpp" #include "bar.hpp"
#include "dwl-ipc-unstable-v2-client-protocol.h" #include "dwl-ipc-unstable-v2-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"
namespace waybar::modules::dwl { namespace waybar::modules::dwl {
class Tags : public waybar::AModule { class Tags final : public waybar::AModule {
public: public:
Tags(const std::string &, const waybar::Bar &, const Json::Value &); Tags(const std::string &, const waybar::Bar &, const Json::Value &);
virtual ~Tags(); virtual ~Tags();
// Handlers for wayland events // Handlers for wayland events
void handle_view_tags(uint32_t tag, uint32_t state, uint32_t clients, uint32_t focused); 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 zdwl_ipc_manager_v2 *status_manager_;
struct wl_seat *seat_; struct wl_seat *seat_;
private: private:
const waybar::Bar &bar_; const waybar::Bar &bar_;
Gtk::Box box_; Gtk::Box box_;
std::vector<Gtk::Button> buttons_; std::vector<Gtk::Button> buttons_;
std::vector<Glib::RefPtr<Gtk::GestureClick>> clickControls_;
struct zdwl_ipc_output_v2 *output_status_; 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<Gtk::GestureClick> controlClick);
}; };
} /* namespace waybar::modules::dwl */ } /* namespace waybar::modules::dwl */

View File

@ -7,7 +7,7 @@
namespace waybar::modules { namespace waybar::modules {
class Memory : public ALabel { class Memory final : public ALabel {
public: public:
Memory(const std::string&, const Json::Value&); Memory(const std::string&, const Json::Value&);
virtual ~Memory() = default; virtual ~Memory() = default;

View File

@ -5,7 +5,7 @@
namespace waybar::modules { namespace waybar::modules {
class Temperature : public ALabel { class Temperature final : public ALabel {
public: public:
Temperature(const std::string&, const Json::Value&); Temperature(const std::string&, const Json::Value&);
virtual ~Temperature() = default; virtual ~Temperature() = default;

View File

@ -229,6 +229,10 @@ elif is_dragonfly or is_freebsd or is_netbsd or is_openbsd
endif endif
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') subdir('protocol')
executable( executable(

View File

@ -182,12 +182,12 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
if (ref == "river/layout") { if (ref == "river/layout") {
return new waybar::modules::river::Layout(id, bar_, config_[name]); return new waybar::modules::river::Layout(id, bar_, config_[name]);
} }
#endif #endif*/
#ifdef HAVE_DWL #ifdef HAVE_DWL
if (ref == "dwl/tags") { if (ref == "dwl/tags") {
return new waybar::modules::dwl::Tags(id, bar_, config_[name]); return new waybar::modules::dwl::Tags(id, bar_, config_[name]);
} }
#endif #endif/*
#ifdef HAVE_HYPRLAND #ifdef HAVE_HYPRLAND
if (ref == "hyprland/window") { if (ref == "hyprland/window") {
return new waybar::modules::hyprland::Window(id, bar_, config_[name]); return new waybar::modules::hyprland::Window(id, bar_, config_[name]);

View File

@ -1,14 +1,7 @@
#include "modules/dwl/tags.hpp" #include "modules/dwl/tags.hpp"
#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <spdlog/spdlog.h>
#include <wayland-client.h>
#include <algorithm>
#include "client.hpp" #include "client.hpp"
#include "dwl-ipc-unstable-v2-client-protocol.h"
#include <spdlog/spdlog.h>
#define TAG_INACTIVE 0 #define TAG_INACTIVE 0
#define TAG_ACTIVE 1 #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(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS); box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_);
// Default to 9 tags, cap at 32 // Default to 9 tags, cap at 32
const uint32_t num_tags = 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; uint32_t i = 1;
for (const auto &tag_label : tag_labels) { for (const auto &tag_label : tag_labels) {
Gtk::Button &button = buttons_.emplace_back(tag_label); Gtk::Button &button{buttons_.emplace_back(tag_label)};
button.set_relief(Gtk::RELIEF_NONE); auto controlClick{clickControls_.emplace_back(Gtk::GestureClick::create())};
box_.pack_start(button, false, false, 0); 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()) { if (!config_["disable-click"].asBool()) {
button.signal_clicked().connect( controlClick->signal_pressed().connect(sigc::bind(sigc::mem_fun(*this,
sigc::bind(sigc::mem_fun(*this, &Tags::handle_primary_clicked), i)); &Tags::handle_button_press), i, controlClick));
button.signal_button_press_event().connect( controlClick->signal_released().connect(sigc::bind(sigc::mem_fun(*this,
sigc::bind(sigc::mem_fun(*this, &Tags::handle_button_press), i)); &Tags::handle_primary_clicked), i));
} }
button.show(); button.show();
i <<= 1; 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; if (!output_status_) return;
zdwl_ipc_output_v2_set_tags(output_status_, tag, 1); zdwl_ipc_output_v2_set_tags(output_status_, tag, 1);
} }
bool Tags::handle_button_press(GdkEventButton *event_button, uint32_t tag) { void Tags::handle_button_press(int n_press, double dx, double dy, uint32_t tag,
if (event_button->type == GDK_BUTTON_PRESS && event_button->button == 3) { Glib::RefPtr<Gtk::GestureClick> controlClick) {
if (!output_status_) return true; if (controlClick->get_current_button() == 3) {
if (!output_status_) return;
zdwl_ipc_output_v2_set_tags(output_status_, num_tags ^ tag, 0); 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) { void Tags::handle_view_tags(uint32_t tag, uint32_t state, uint32_t clients, uint32_t focused) {