From 73260ade6316c45ba454913d8b1811ba9f8bc88a Mon Sep 17 00:00:00 2001 From: Scott Moreau Date: Sun, 14 Jan 2024 11:32:54 -0700 Subject: [PATCH 1/2] Listen for toggle_menu event Update wayfire-shell protocol and listen for the toggle_menu event. Fixes #11 because ipc plugin can be used to allow calling toggle_menu from a script. --- proto/wayfire-shell-unstable-v2.xml | 8 ++++++++ src/panel/panel.cpp | 2 +- src/panel/widgets/menu.cpp | 13 +++++++++++++ src/panel/widgets/menu.hpp | 8 ++++++++ src/util/wf-autohide-window.cpp | 18 +++++++++++------- src/util/wf-autohide-window.hpp | 2 +- src/util/wf-shell-app.cpp | 5 +++++ src/util/wf-shell-app.hpp | 2 ++ 8 files changed, 49 insertions(+), 9 deletions(-) diff --git a/proto/wayfire-shell-unstable-v2.xml b/proto/wayfire-shell-unstable-v2.xml index 6932d5cf..247ab4cb 100644 --- a/proto/wayfire-shell-unstable-v2.xml +++ b/proto/wayfire-shell-unstable-v2.xml @@ -87,6 +87,14 @@ + + + + Tells the menu to open. + + Emitted using an activator binding. + + diff --git a/src/panel/panel.cpp b/src/panel/panel.cpp index 44636788..109112f4 100644 --- a/src/panel/panel.cpp +++ b/src/panel/panel.cpp @@ -162,7 +162,7 @@ class WayfirePanel::impl { if (name == "menu") { - return Widget(new WayfireMenu()); + return Widget(new WayfireMenu(output)); } if (name == "launchers") diff --git a/src/panel/widgets/menu.cpp b/src/panel/widgets/menu.cpp index 42114285..d2402471 100644 --- a/src/panel/widgets/menu.cpp +++ b/src/panel/widgets/menu.cpp @@ -494,6 +494,8 @@ static void app_info_changed(GAppInfoMonitor *gappinfomonitor, gpointer user_dat void WayfireMenu::init(Gtk::HBox *container) { + output->toggle_menu_signal().connect(sigc::mem_fun(this, &WayfireMenu::toggle_menu)); + menu_icon.set_callback([=] () { update_icon(); }); menu_size.set_callback([=] () { update_icon(); }); panel_position.set_callback([=] () { update_popover_layout(); }); @@ -537,6 +539,17 @@ void WayfireMenu::init(Gtk::HBox *container) button->show(); } +void WayfireMenu::toggle_menu() +{ + if (button->get_active()) + { + button->set_active(false); + } else + { + button->set_active(true); + } +} + void WayfireMenu::hide_menu() { button->set_active(false); diff --git a/src/panel/widgets/menu.hpp b/src/panel/widgets/menu.hpp index 2ee50ee2..c881e6fa 100644 --- a/src/panel/widgets/menu.hpp +++ b/src/panel/widgets/menu.hpp @@ -79,6 +79,8 @@ class WayfireLogoutUI class WayfireMenu : public WayfireWidget { + WayfireOutput *output; + Gtk::Box flowbox_container; Gtk::HBox hbox, hbox_bottom; Gtk::VBox bottom_pad; @@ -127,8 +129,14 @@ class WayfireMenu : public WayfireWidget public: void init(Gtk::HBox *container) override; + void toggle_menu(); void hide_menu(); void refresh(); + WayfireMenu(WayfireOutput *output) + { + this->output = output; + } + ~WayfireMenu() override { g_signal_handler_disconnect(app_info_monitor, app_info_monitor_changed_handler_id); diff --git a/src/util/wf-autohide-window.cpp b/src/util/wf-autohide-window.cpp index b076c7d7..6e785ee1 100644 --- a/src/util/wf-autohide-window.cpp +++ b/src/util/wf-autohide-window.cpp @@ -53,7 +53,7 @@ WayfireAutohidingWindow::WayfireAutohidingWindow(WayfireOutput *output, std::cerr << "WARNING: Compositor does not support zwf_shell_manager_v2 " << \ "disabling hotspot and autohide features " << \ "(is wayfire-shell plugin enabled?)" << std::endl; - return; + return; } static const zwf_output_v2_listener listener = { @@ -64,7 +64,11 @@ WayfireAutohidingWindow::WayfireAutohidingWindow(WayfireOutput *output, .leave_fullscreen = [] (void *data, zwf_output_v2*) { ((WayfireAutohidingWindow*)data)->decrease_autohide(); - } + }, + .toggle_menu = [] (void *data, zwf_output_v2*) + { + ((WayfireAutohidingWindow*)data)->output->toggle_menu_signal().emit(); + }, }; zwf_output_v2_add_listener(output->output, &listener, this); } @@ -262,7 +266,7 @@ void WayfireAutohidingWindow::setup_hotspot() void WayfireAutohidingWindow::setup_auto_exclusive_zone() { - if (!auto_exclusive_zone && auto_exclusive_zone == 0) + if (!auto_exclusive_zone && (auto_exclusive_zone == 0)) { return; } @@ -273,7 +277,7 @@ void WayfireAutohidingWindow::setup_auto_exclusive_zone() void WayfireAutohidingWindow::update_auto_exclusive_zone() { int allocated_height = get_allocated_height(); - int new_zone_size = this->auto_exclusive_zone ? allocated_height : 0; + int new_zone_size = this->auto_exclusive_zone ? allocated_height : 0; if (new_zone_size != this->auto_exclusive_zone_size) { @@ -282,7 +286,7 @@ void WayfireAutohidingWindow::update_auto_exclusive_zone() } } -void WayfireAutohidingWindow::set_auto_exclusive_zone(bool has_zone) +void WayfireAutohidingWindow::set_auto_exclusive_zone(bool has_zone) { if (has_zone && (output->output && autohide_opt)) { @@ -453,11 +457,11 @@ void WayfireAutohidingWindow::setup_autohide() this->signal_size_allocate().connect_notify( [=] (Gtk::Allocation&) { - //std::cerr << "set_auto_exclusive_zone: " << this->auto_exclusive_zone << std::endl; + // std::cerr << "set_auto_exclusive_zone: " << this->auto_exclusive_zone << std::endl; this->update_auto_exclusive_zone(); // We have to check here as well, otherwise it enables hotspot when it shouldn't - if (!output->output|| !(output->output && autohide_opt)) + if (!output->output || !(output->output && autohide_opt)) { return; } diff --git a/src/util/wf-autohide-window.hpp b/src/util/wf-autohide-window.hpp index b8fcc034..b96d14ae 100644 --- a/src/util/wf-autohide-window.hpp +++ b/src/util/wf-autohide-window.hpp @@ -93,7 +93,7 @@ class WayfireAutohidingWindow : public Gtk::Window void setup_autohide(); void update_autohide(); - bool auto_exclusive_zone = !autohide_opt; + bool auto_exclusive_zone = !autohide_opt; int auto_exclusive_zone_size = 0; void setup_auto_exclusive_zone(); void update_auto_exclusive_zone(); diff --git a/src/util/wf-shell-app.cpp b/src/util/wf-shell-app.cpp index 2c05cd36..c45a8d3e 100644 --- a/src/util/wf-shell-app.cpp +++ b/src/util/wf-shell-app.cpp @@ -201,3 +201,8 @@ WayfireOutput::~WayfireOutput() zwf_output_v2_destroy(this->output); } } + +sigc::signal WayfireOutput::toggle_menu_signal() +{ + return m_toggle_menu_signal; +} diff --git a/src/util/wf-shell-app.hpp b/src/util/wf-shell-app.hpp index 2d54505f..89e531c1 100644 --- a/src/util/wf-shell-app.hpp +++ b/src/util/wf-shell-app.hpp @@ -19,6 +19,8 @@ struct WayfireOutput GMonitor monitor; wl_output *wo; zwf_output_v2 *output; + sigc::signal toggle_menu_signal(); + sigc::signal m_toggle_menu_signal; WayfireOutput(const GMonitor& monitor, zwf_shell_manager_v2 *zwf_manager); ~WayfireOutput(); From 0a080d7377033a99908e1e440712217c97eb115d Mon Sep 17 00:00:00 2001 From: Scott Moreau Date: Tue, 16 Jan 2024 00:15:15 -0700 Subject: [PATCH 2/2] wayfire-shell: Bump version for new toggle_menu event --- proto/wayfire-shell-unstable-v2.xml | 9 +++++---- src/util/wf-shell-app.cpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/proto/wayfire-shell-unstable-v2.xml b/proto/wayfire-shell-unstable-v2.xml index 247ab4cb..a6d1d9d9 100644 --- a/proto/wayfire-shell-unstable-v2.xml +++ b/proto/wayfire-shell-unstable-v2.xml @@ -1,6 +1,6 @@ - + This protocol provides additional events and requests for special DE clients like panels, docks, etc. @@ -21,7 +21,7 @@ - + Represents a single output. Each output is managed independently from the others. @@ -88,9 +88,10 @@ - + + - Tells the menu to open. + Tells the menu to toggle open or close. Emitted using an activator binding. diff --git a/src/util/wf-shell-app.cpp b/src/util/wf-shell-app.cpp index c45a8d3e..09f09a5b 100644 --- a/src/util/wf-shell-app.cpp +++ b/src/util/wf-shell-app.cpp @@ -66,7 +66,7 @@ static void registry_add_object(void *data, struct wl_registry *registry, if (strcmp(interface, zwf_shell_manager_v2_interface.name) == 0) { app->wf_shell_manager = (zwf_shell_manager_v2*)wl_registry_bind(registry, name, - &zwf_shell_manager_v2_interface, std::min(version, 1u)); + &zwf_shell_manager_v2_interface, std::min(version, 2u)); } }