Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listen for toggle_menu event #208

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions proto/wayfire-shell-unstable-v2.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="wayfire_shell_unstable_v2">
<interface name="zwf_shell_manager_v2" version="1">
<interface name="zwf_shell_manager_v2" version="2">
<description summary="DE integration">
This protocol provides additional events and requests for special DE
clients like panels, docks, etc.
Expand All @@ -21,7 +21,7 @@
</request>
</interface>

<interface name="zwf_output_v2" version="1">
<interface name="zwf_output_v2" version="2">
<description summary="A wrapper for wl_output">
Represents a single output.
Each output is managed independently from the others.
Expand Down Expand Up @@ -87,6 +87,15 @@
<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>

<!-- Version 2 additions -->
<event name="toggle_menu" since="2">
<description summary="Toggle menu event">
Tells the menu to toggle open or close.

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
13 changes: 13 additions & 0 deletions src/panel/widgets/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 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 @@ -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);
Expand Down
18 changes: 11 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,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);
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
{
Expand All @@ -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))
{
Expand Down Expand Up @@ -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;
}
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
7 changes: 6 additions & 1 deletion src/util/wf-shell-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -201,3 +201,8 @@ WayfireOutput::~WayfireOutput()
zwf_output_v2_destroy(this->output);
}
}

sigc::signal<void()> WayfireOutput::toggle_menu_signal()
{
return m_toggle_menu_signal;
}
2 changes: 2 additions & 0 deletions src/util/wf-shell-app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ struct WayfireOutput
GMonitor monitor;
wl_output *wo;
zwf_output_v2 *output;
sigc::signal<void()> toggle_menu_signal();
sigc::signal<void()> m_toggle_menu_signal;

WayfireOutput(const GMonitor& monitor, zwf_shell_manager_v2 *zwf_manager);
~WayfireOutput();
Expand Down
Loading