Skip to content

Commit

Permalink
Toggle menu (#2097)
Browse files Browse the repository at this point in the history
* Send wayfire-shell toggle menu event on activator

Update wayfire-shell protocol to include a toggle menu event on the output.
Clients using wayfire-shell protocol can listen for this event and open a
menu in response.
  • Loading branch information
soreau authored Jan 18, 2024
1 parent db8af3e commit 46e8962
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 17 deletions.
2 changes: 1 addition & 1 deletion metadata/expo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="toggle" type="activator">
<_short>Toggle</_short>
<_long>Shows an overview of all workspaces with the specified activator. Pressing again exits.</_long>
<default>&lt;super&gt;</default>
<default>&lt;super&gt; KEY_E</default>
</option>
<option name="background" type="color">
<_short>Background color</_short>
Expand Down
5 changes: 5 additions & 0 deletions metadata/wayfire-shell.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
<_short>Wayfire Shell Protocol</_short>
<_long>An implementation of the wayfire-shell protocol.</_long>
<category>Utility</category>
<option name="toggle_menu" type="activator">
<_short>Toggle Menu</_short>
<_long>Toggles menu with the specified activator.</_long>
<default>&lt;super&gt;</default>
</option>
</plugin>
</wayfire>
7 changes: 0 additions & 7 deletions plugins/ipc/meson.build
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
evdev = dependency('libevdev')
system_json = dependency('nlohmann_json', required: false)

ipc_include_dirs = include_directories('.')

if system_json.found()
json = system_json
else
json = subproject('json').get_variable('nlohmann_json_dep')
endif

ipc = shared_module('ipc',
['ipc.cpp'],
include_directories: [wayfire_api_inc, wayfire_conf_inc, plugins_common_inc],
Expand Down
7 changes: 7 additions & 0 deletions plugins/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
subdir('common')

system_json = dependency('nlohmann_json', required: false)
if system_json.found()
json = system_json
else
json = subproject('json').get_variable('nlohmann_json_dep')
endif

if get_option('debug_ipc')
subdir('ipc')
endif
Expand Down
2 changes: 1 addition & 1 deletion plugins/protocols/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ protocol_plugins = [
]

all_include_dirs = [wayfire_api_inc, wayfire_conf_inc, plugins_common_inc]
all_deps = [wlroots, pixman, wfconfig, wf_protos]
all_deps = [wlroots, pixman, wfconfig, wf_protos, json]

foreach plugin : protocol_plugins
shared_module(plugin, plugin + '.cpp',
Expand Down
41 changes: 36 additions & 5 deletions plugins/protocols/wayfire-shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "wayfire/render-manager.hpp"
#include "wayfire-shell-unstable-v2-protocol.h"
#include "wayfire/signal-definitions.hpp"
#include "plugins/ipc/ipc-activator.hpp"

/* ----------------------------- wfs_hotspot -------------------------------- */
static void handle_hotspot_destroy(wl_resource *resource);
Expand Down Expand Up @@ -190,13 +191,20 @@ static struct zwf_output_v2_interface zwf_output_impl = {
.create_hotspot = handle_zwf_output_create_hotspot,
};

/**
* A signal emitted on the wayfire output where the menu should be toggled.
*/
struct wayfire_shell_toggle_menu_signal
{};

/**
* Represents a zwf_output_v2.
* Lifetime is managed by the wl_resource
*/
class wfs_output
{
uint32_t num_inhibits = 0;
wl_resource *shell_resource;
wl_resource *resource;
wf::output_t *output;

Expand Down Expand Up @@ -228,14 +236,28 @@ class wfs_output
}
};

wf::signal::connection_t<wayfire_shell_toggle_menu_signal> on_toggle_menu = [=] (auto)
{
if (wl_resource_get_version(shell_resource) < ZWF_OUTPUT_V2_TOGGLE_MENU_SINCE_VERSION)
{
return;
}

zwf_output_v2_send_toggle_menu(resource);
};

public:
wfs_output(wf::output_t *output, wl_client *client, int id)
wfs_output(wf::output_t *output, wl_resource *shell_resource, wl_client *client, int id)
{
this->output = output;
this->shell_resource = shell_resource;

resource = wl_resource_create(client, &zwf_output_v2_interface, 1, id);
resource =
wl_resource_create(client, &zwf_output_v2_interface,
std::min(wl_resource_get_version(shell_resource), 2), id);
wl_resource_set_implementation(resource, &zwf_output_impl, this, handle_output_destroy);
output->connect(&on_fullscreen_layer_focused);
output->connect(&on_toggle_menu);
wf::get_core().output_layout->connect(&on_output_removed);
}

Expand Down Expand Up @@ -385,7 +407,7 @@ static void zwf_shell_manager_get_wf_output(wl_client *client,
if (wo)
{
// will be deleted when the resource is destroyed
new wfs_output(wo, client, id);
new wfs_output(wo, resource, client, id);
}
}

Expand All @@ -410,7 +432,7 @@ void bind_zwf_shell_manager(wl_client *client, void *data,
uint32_t version, uint32_t id)
{
auto resource =
wl_resource_create(client, &zwf_shell_manager_v2_interface, 1, id);
wl_resource_create(client, &zwf_shell_manager_v2_interface, version, id);
wl_resource_set_implementation(resource,
&zwf_shell_manager_v2_impl, NULL, NULL);
}
Expand All @@ -425,7 +447,7 @@ wayfire_shell *wayfire_shell_create(wl_display *display)
wayfire_shell *ws = new wayfire_shell;

ws->shell_manager = wl_global_create(display,
&zwf_shell_manager_v2_interface, 1, NULL, bind_zwf_shell_manager);
&zwf_shell_manager_v2_interface, 2, NULL, bind_zwf_shell_manager);

if (ws->shell_manager == NULL)
{
Expand All @@ -440,10 +462,19 @@ wayfire_shell *wayfire_shell_create(wl_display *display)

class wayfire_shell_protocol_impl : public wf::plugin_interface_t
{
wf::ipc_activator_t toggle_menu{"wayfire-shell/toggle_menu"};
wf::ipc_activator_t::handler_t toggle_menu_cb = [=] (wf::output_t *toggle_menu_output, wayfire_view)
{
wayfire_shell_toggle_menu_signal toggle_menu;
toggle_menu_output->emit(&toggle_menu);
return true;
};

public:
void init() override
{
wf_shell = wayfire_shell_create(wf::get_core().display);
toggle_menu.set_handler(toggle_menu_cb);
}

void fini() override
Expand Down
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
6 changes: 5 additions & 1 deletion wayfire.ini
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ activate = <ctrl> <alt> BTN_LEFT

# Show an overview of all workspaces.
[expo]
toggle = <super>
toggle = <super> KEY_E
# Select a workspace.
# Workspaces are arranged into a grid of 3 × 3.
# The numbering is left to right, line by line.
Expand Down Expand Up @@ -309,6 +309,10 @@ next_output_with_win = <super> <shift> KEY_O
[invert]
toggle = <super> KEY_I

# Send toggle menu event.
[wayfire-shell]
toggle_menu = <super>

# Rules ────────────────────────────────────────────────────────────────────────

# Example configuration:
Expand Down

0 comments on commit 46e8962

Please sign in to comment.