Skip to content

Commit b6ec8f7

Browse files
soreauammen99
authored andcommitted
Listen for toggle_menu event (#208)
* 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. * wayfire-shell: Bump version for new toggle_menu event
1 parent c9c0e25 commit b6ec8f7

8 files changed

Lines changed: 53 additions & 12 deletions

File tree

proto/wayfire-shell-unstable-v2.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<protocol name="wayfire_shell_unstable_v2">
3-
<interface name="zwf_shell_manager_v2" version="1">
3+
<interface name="zwf_shell_manager_v2" version="2">
44
<description summary="DE integration">
55
This protocol provides additional events and requests for special DE
66
clients like panels, docks, etc.
@@ -21,7 +21,7 @@
2121
</request>
2222
</interface>
2323

24-
<interface name="zwf_output_v2" version="1">
24+
<interface name="zwf_output_v2" version="2">
2525
<description summary="A wrapper for wl_output">
2626
Represents a single output.
2727
Each output is managed independently from the others.
@@ -87,6 +87,15 @@
8787
<arg name="timeout" type="uint" summary="minimum time for the mouse to be in the hotspot"/>
8888
<arg name="id" type="new_id" interface="zwf_hotspot_v2"/>
8989
</request>
90+
91+
<!-- Version 2 additions -->
92+
<event name="toggle_menu" since="2">
93+
<description summary="Toggle menu event">
94+
Tells the menu to toggle open or close.
95+
96+
Emitted using an activator binding.
97+
</description>
98+
</event>
9099
</interface>
91100

92101
<interface name="zwf_hotspot_v2" version="1">

src/panel/panel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class WayfirePanel::impl
162162
{
163163
if (name == "menu")
164164
{
165-
return Widget(new WayfireMenu());
165+
return Widget(new WayfireMenu(output));
166166
}
167167

168168
if (name == "launchers")

src/panel/widgets/menu.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ static void app_info_changed(GAppInfoMonitor *gappinfomonitor, gpointer user_dat
494494

495495
void WayfireMenu::init(Gtk::HBox *container)
496496
{
497+
output->toggle_menu_signal().connect(sigc::mem_fun(this, &WayfireMenu::toggle_menu));
498+
497499
menu_icon.set_callback([=] () { update_icon(); });
498500
menu_size.set_callback([=] () { update_icon(); });
499501
panel_position.set_callback([=] () { update_popover_layout(); });
@@ -537,6 +539,17 @@ void WayfireMenu::init(Gtk::HBox *container)
537539
button->show();
538540
}
539541

542+
void WayfireMenu::toggle_menu()
543+
{
544+
if (button->get_active())
545+
{
546+
button->set_active(false);
547+
} else
548+
{
549+
button->set_active(true);
550+
}
551+
}
552+
540553
void WayfireMenu::hide_menu()
541554
{
542555
button->set_active(false);

src/panel/widgets/menu.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class WayfireLogoutUI
7979

8080
class WayfireMenu : public WayfireWidget
8181
{
82+
WayfireOutput *output;
83+
8284
Gtk::Box flowbox_container;
8385
Gtk::HBox hbox, hbox_bottom;
8486
Gtk::VBox bottom_pad;
@@ -127,8 +129,14 @@ class WayfireMenu : public WayfireWidget
127129

128130
public:
129131
void init(Gtk::HBox *container) override;
132+
void toggle_menu();
130133
void hide_menu();
131134
void refresh();
135+
WayfireMenu(WayfireOutput *output)
136+
{
137+
this->output = output;
138+
}
139+
132140
~WayfireMenu() override
133141
{
134142
g_signal_handler_disconnect(app_info_monitor, app_info_monitor_changed_handler_id);

src/util/wf-autohide-window.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ WayfireAutohidingWindow::WayfireAutohidingWindow(WayfireOutput *output,
5353
std::cerr << "WARNING: Compositor does not support zwf_shell_manager_v2 " << \
5454
"disabling hotspot and autohide features " << \
5555
"(is wayfire-shell plugin enabled?)" << std::endl;
56-
return;
56+
return;
5757
}
5858

5959
static const zwf_output_v2_listener listener = {
@@ -64,7 +64,11 @@ WayfireAutohidingWindow::WayfireAutohidingWindow(WayfireOutput *output,
6464
.leave_fullscreen = [] (void *data, zwf_output_v2*)
6565
{
6666
((WayfireAutohidingWindow*)data)->decrease_autohide();
67-
}
67+
},
68+
.toggle_menu = [] (void *data, zwf_output_v2*)
69+
{
70+
((WayfireAutohidingWindow*)data)->output->toggle_menu_signal().emit();
71+
},
6872
};
6973
zwf_output_v2_add_listener(output->output, &listener, this);
7074
}
@@ -262,7 +266,7 @@ void WayfireAutohidingWindow::setup_hotspot()
262266

263267
void WayfireAutohidingWindow::setup_auto_exclusive_zone()
264268
{
265-
if (!auto_exclusive_zone && auto_exclusive_zone == 0)
269+
if (!auto_exclusive_zone && (auto_exclusive_zone == 0))
266270
{
267271
return;
268272
}
@@ -273,7 +277,7 @@ void WayfireAutohidingWindow::setup_auto_exclusive_zone()
273277
void WayfireAutohidingWindow::update_auto_exclusive_zone()
274278
{
275279
int allocated_height = get_allocated_height();
276-
int new_zone_size = this->auto_exclusive_zone ? allocated_height : 0;
280+
int new_zone_size = this->auto_exclusive_zone ? allocated_height : 0;
277281

278282
if (new_zone_size != this->auto_exclusive_zone_size)
279283
{
@@ -282,7 +286,7 @@ void WayfireAutohidingWindow::update_auto_exclusive_zone()
282286
}
283287
}
284288

285-
void WayfireAutohidingWindow::set_auto_exclusive_zone(bool has_zone)
289+
void WayfireAutohidingWindow::set_auto_exclusive_zone(bool has_zone)
286290
{
287291
if (has_zone && (output->output && autohide_opt))
288292
{
@@ -453,11 +457,11 @@ void WayfireAutohidingWindow::setup_autohide()
453457
this->signal_size_allocate().connect_notify(
454458
[=] (Gtk::Allocation&)
455459
{
456-
//std::cerr << "set_auto_exclusive_zone: " << this->auto_exclusive_zone << std::endl;
460+
// std::cerr << "set_auto_exclusive_zone: " << this->auto_exclusive_zone << std::endl;
457461
this->update_auto_exclusive_zone();
458462

459463
// We have to check here as well, otherwise it enables hotspot when it shouldn't
460-
if (!output->output|| !(output->output && autohide_opt))
464+
if (!output->output || !(output->output && autohide_opt))
461465
{
462466
return;
463467
}

src/util/wf-autohide-window.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class WayfireAutohidingWindow : public Gtk::Window
9393
void setup_autohide();
9494
void update_autohide();
9595

96-
bool auto_exclusive_zone = !autohide_opt;
96+
bool auto_exclusive_zone = !autohide_opt;
9797
int auto_exclusive_zone_size = 0;
9898
void setup_auto_exclusive_zone();
9999
void update_auto_exclusive_zone();

src/util/wf-shell-app.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void registry_add_object(void *data, struct wl_registry *registry,
6666
if (strcmp(interface, zwf_shell_manager_v2_interface.name) == 0)
6767
{
6868
app->wf_shell_manager = (zwf_shell_manager_v2*)wl_registry_bind(registry, name,
69-
&zwf_shell_manager_v2_interface, std::min(version, 1u));
69+
&zwf_shell_manager_v2_interface, std::min(version, 2u));
7070
}
7171
}
7272

@@ -201,3 +201,8 @@ WayfireOutput::~WayfireOutput()
201201
zwf_output_v2_destroy(this->output);
202202
}
203203
}
204+
205+
sigc::signal<void()> WayfireOutput::toggle_menu_signal()
206+
{
207+
return m_toggle_menu_signal;
208+
}

src/util/wf-shell-app.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct WayfireOutput
1919
GMonitor monitor;
2020
wl_output *wo;
2121
zwf_output_v2 *output;
22+
sigc::signal<void()> toggle_menu_signal();
23+
sigc::signal<void()> m_toggle_menu_signal;
2224

2325
WayfireOutput(const GMonitor& monitor, zwf_shell_manager_v2 *zwf_manager);
2426
~WayfireOutput();

0 commit comments

Comments
 (0)