Skip to content

Commit

Permalink
Listen for toggle_menu event
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
soreau committed Jan 14, 2024
1 parent a750421 commit abc34a5
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 9 deletions.
8 changes: 8 additions & 0 deletions proto/wayfire-shell-unstable-v2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
<arg name="timeout" type="uint" summary="minimum time for the mouse to be in the hotspot"/>
<arg name="id" type="new_id" interface="zwf_hotspot_v2"/>
</request>

<event name="toggle_menu">
<description summary="Toggle menu event">
Tells the menu to open.

Emitted using an activator binding.
</description>
</event>
</interface>

<interface name="zwf_hotspot_v2" version="1">
Expand Down
2 changes: 1 addition & 1 deletion src/panel/panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class WayfirePanel::impl
{
if (name == "menu")
{
return Widget(new WayfireMenu());
return Widget(new WayfireMenu(output));
}

if (name == "launchers")
Expand Down
64 changes: 64 additions & 0 deletions src/panel/widgets/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,61 @@ static void app_info_changed(GAppInfoMonitor *gappinfomonitor, gpointer user_dat
menu->refresh();
}

static void registry_add_object(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version)
{
auto menu = static_cast<WayfireMenu*>(data);
if (strcmp(interface, zwf_shell_manager_v2_interface.name) == 0)
{
menu->wf_shell_manager = (zwf_shell_manager_v2*)wl_registry_bind(registry, name,
&zwf_shell_manager_v2_interface, std::min(version, 1u));
}
}

static void registry_remove_object(void *data, struct wl_registry *registry,
uint32_t name)
{}

static struct wl_registry_listener registry_listener =
{
&registry_add_object,
&registry_remove_object
};

void WayfireMenu::init(Gtk::HBox *container)
{
auto gdk_display = gdk_display_get_default();
auto display = gdk_wayland_display_get_wl_display(gdk_display);

wl_registry *registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener, this);
wl_display_roundtrip(display);

static const zwf_output_v2_listener listener = {
.enter_fullscreen = [] (void *data, zwf_output_v2*)
{},
.leave_fullscreen = [] (void *data, zwf_output_v2*)
{},
.toggle_menu = [] (void *data, zwf_output_v2 *output)
{
WayfireMenu *menu = (WayfireMenu*)data;
menu->toggle_menu();
},
};

if (!this->wf_shell_manager)
{
std::cerr << "WARNING: Compositor does not support zwf_shell_manager_v2. " << \
"Menu activators will not work. " << \
"(is wayfire-shell plugin enabled?)" << std::endl;
} else
{
this->output_manager = zwf_shell_manager_v2_get_wf_output(this->wf_shell_manager, this->output->wo);
zwf_output_v2_add_listener(this->output_manager, &listener, this);
}

wl_registry_destroy(registry);

menu_icon.set_callback([=] () { update_icon(); });
menu_size.set_callback([=] () { update_icon(); });
panel_position.set_callback([=] () { update_popover_layout(); });
Expand Down Expand Up @@ -537,6 +590,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);
Expand Down
10 changes: 10 additions & 0 deletions src/panel/widgets/menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,9 +128,17 @@ class WayfireMenu : public WayfireWidget
void on_logout_click();

public:
zwf_output_v2 *output_manager = NULL;
zwf_shell_manager_v2 *wf_shell_manager = NULL;
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);
Expand Down
16 changes: 9 additions & 7 deletions src/util/wf-autohide-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -64,7 +64,9 @@ WayfireAutohidingWindow::WayfireAutohidingWindow(WayfireOutput *output,
.leave_fullscreen = [] (void *data, zwf_output_v2*)
{
((WayfireAutohidingWindow*)data)->decrease_autohide();
}
},
.toggle_menu = [] (void *data, zwf_output_v2*)
{},
};
zwf_output_v2_add_listener(output->output, &listener, this);
}
Expand Down Expand Up @@ -262,7 +264,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;
}
Expand All @@ -273,7 +275,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)
{
Expand All @@ -282,7 +284,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))
{
Expand Down Expand Up @@ -453,11 +455,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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/wf-autohide-window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit abc34a5

Please sign in to comment.