Skip to content
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
5 changes: 5 additions & 0 deletions metadata/gtk-shell.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
<_short>GTK Shell Protocol</_short>
<_long>An implementation of the gtk-shell protocol.</_long>
<category>Utility</category>
<option name="global_menu_bar" type="bool">
<_short>Advertise global menu bar support</_short>
<_long>This will cause compatible GTK3 apps to export their menus via DBus. You need a compatible global menu client program to display the menus.</_long>
<default>false</default>
</option>
</plugin>
</wayfire>
8 changes: 8 additions & 0 deletions metadata/kde-appmenu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<wayfire>
<plugin name="kde-appmenu">
<_short>KDE Appmenu support</_short>
<_long>An implementation of the KDE Appmenu protocol for global menus.</_long>
<category>Utility</category>
</plugin>
</wayfire>
1 change: 1 addition & 0 deletions metadata/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ install_data('input-method-v1.xml', install_dir: conf_data.get('PLUGIN_XML_DIR')
install_data('invert.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('ipc.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('ipc-rules.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('kde-appmenu.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('move.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('oswitch.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('output.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
Expand Down
51 changes: 51 additions & 0 deletions plugins/protocols/gtk-shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,54 @@ static void handle_gtk_surface_set_dbus_properties(wl_client *client,
{
wf::get_core().get_data_safe<wf_gtk_shell>()->surface_app_id[surface->wl_surface] = application_id;
}

wayfire_view view = wf::wl_surface_to_wayfire_view(surface->wl_surface);
if (!view)
{
LOGE("Could not get view");
return;
} else
{
if (app_menu_path && *app_menu_path)
{
view->set_property<std::string>("gtk-shell-app-menu-path", app_menu_path);
} else
{
view->erase_property("gtk-shell-app-menu-path");
}

if (application_object_path && *application_object_path)
{
view->set_property<std::string>("gtk-shell-application-object-path", application_object_path);
} else
{
view->erase_property("gtk-shell-application-object-path");
}

if (menubar_path && *menubar_path)
{
view->set_property<std::string>("gtk-shell-menubar-path", menubar_path);
} else
{
view->erase_property("gtk-shell-menubar-path");
}

if (unique_bus_name && *unique_bus_name)
{
view->set_property<std::string>("gtk-shell-unique-bus-name", unique_bus_name);
} else
{
view->erase_property("gtk-shell-unique-bus-name");
}

if (window_object_path && *window_object_path)
{
view->set_property<std::string>("gtk-shell-window-object-path", window_object_path);
} else
{
view->erase_property("gtk-shell-window-object-path");
}
}
}

/**
Expand Down Expand Up @@ -331,6 +379,9 @@ void bind_gtk_shell1(wl_client *client, void *data, uint32_t version, uint32_t i
{
auto resource = wl_resource_create(client, &gtk_shell1_interface, GTK_SHELL_VERSION, id);
wl_resource_set_implementation(resource, &gtk_shell1_impl, data, handle_gtk_shell1_destroy);
wf::option_wrapper_t<bool> global_menu_bar{"gtk-shell/global_menu_bar"};
// Note: we also have the "global_app_menu" capability, but it does not seem to have any effect
gtk_shell1_send_capabilities(resource, global_menu_bar ? GTK_SHELL1_CAPABILITY_GLOBAL_MENU_BAR : 0);
}

class wayfire_gtk_shell_impl : public wf::plugin_interface_t
Expand Down
114 changes: 114 additions & 0 deletions plugins/protocols/kde-appmenu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include "kde-appmenu-protocol.h"
#include "wayfire/core.hpp"
#include "wayfire/object.hpp"
#include <wayfire/plugin.hpp>
#include <wayfire/view.hpp>
#include <wayfire/toplevel-view.hpp>

#define KDE_APPMENU_VERSION 2

struct wf_kde_appmenu_surface
{
wl_resource *resource;
wl_resource *wl_surface;
};

static void handle_kde_appmenu_set_address(wl_client *client,
wl_resource *resource, const char *service_name,
const char *object_path)
{
auto surface = static_cast<wf_kde_appmenu_surface*>(wl_resource_get_user_data(resource));
wayfire_view view = wf::wl_surface_to_wayfire_view(surface->wl_surface);
if (!view)
{
LOGE("Could not get view");
return;
} else
{
if (service_name && *service_name)
{
view->set_property<std::string>("kde-appmenu-service-name", service_name);
} else
{
view->erase_property("kde-appmenu-service-name");
}

if (object_path && *object_path)
{
view->set_property<std::string>("kde-appmenu-object-path", object_path);
} else
{
view->erase_property("kde-appmenu-object-path");
}
}
}

static void handle_kde_appmenu_release(wl_client*, wl_resource*)
{
/* no-op */
}

static void handle_kde_appmenu_destroy(wl_resource *resource)
{
auto surface = static_cast<wf_kde_appmenu_surface*>(wl_resource_get_user_data(resource));
delete surface;
}

const struct org_kde_kwin_appmenu_interface kde_appmenu_impl = {
.set_address = handle_kde_appmenu_set_address,
.release = handle_kde_appmenu_release
};


static void handle_kde_appmenu_manager_create(wl_client *client,
wl_resource *resource, uint32_t id, wl_resource *surface)
{
wf_kde_appmenu_surface *kde_appmenu_surface = new wf_kde_appmenu_surface;
kde_appmenu_surface->resource = wl_resource_create(client,
&org_kde_kwin_appmenu_interface, wl_resource_get_version(resource), id);
kde_appmenu_surface->wl_surface = surface;
wl_resource_set_implementation(kde_appmenu_surface->resource, &kde_appmenu_impl,
kde_appmenu_surface, handle_kde_appmenu_destroy);
}

static void handle_kde_appmenu_manager_release(wl_client*, wl_resource*)
{
/* no-op */
}

static void handle_kde_appmenu_manager_destroy(wl_resource*)
{
/* no-op */
}

static const struct org_kde_kwin_appmenu_manager_interface kde_appmenu_manager_impl = {
.create = handle_kde_appmenu_manager_create,
.release = handle_kde_appmenu_manager_release
};


static void bind_kde_appmenu(wl_client *client, void *data, uint32_t version, uint32_t id)
{
auto resource = wl_resource_create(client, &org_kde_kwin_appmenu_manager_interface,
KDE_APPMENU_VERSION, id);
wl_resource_set_implementation(resource, &kde_appmenu_manager_impl,
data, handle_kde_appmenu_manager_destroy);
}

class wayfire_kde_appmenu_impl : public wf::plugin_interface_t
{
public:
void init() override
{
auto display = wf::get_core().display;
wl_global_create(display, &org_kde_kwin_appmenu_manager_interface,
KDE_APPMENU_VERSION, NULL, bind_kde_appmenu);
}

bool is_unloadable() override
{
return false;
}
};

DECLARE_WAYFIRE_PLUGIN(wayfire_kde_appmenu_impl);
2 changes: 1 addition & 1 deletion plugins/protocols/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
protocol_plugins = [
'ext-toplevel', 'foreign-toplevel', 'gtk-shell', 'wayfire-shell', 'xdg-activation', 'shortcuts-inhibit',
'input-method-v1', 'session-lock', 'security-context-v1',
'input-method-v1', 'session-lock', 'security-context-v1', 'kde-appmenu',
]

all_include_dirs = [wayfire_api_inc, wayfire_conf_inc, plugins_common_inc, ipc_include_dirs]
Expand Down
40 changes: 40 additions & 0 deletions proto/kde-appmenu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="appmenu">
<copyright><![CDATA[
SPDX-FileCopyrightText: 2017 David Edmundson

SPDX-License-Identifier: LGPL-2.1-or-later
]]></copyright>
<interface name="org_kde_kwin_appmenu_manager" version="2">
<description summary="appmenu dbus address interface">
This interface allows a client to link a window (or wl_surface) to an com.canonical.dbusmenu
interface registered on DBus.
</description>
<request name="create">
<arg name="id" type="new_id" interface="org_kde_kwin_appmenu"/>
<arg name="surface" type="object" interface="wl_surface"/>
</request>
<!-- version 2 additions-->
<request name="release" type="destructor" since="2">
<description summary="destroy the org_kde_kwin_appmenu_manager object" />
</request>
</interface>
<interface name="org_kde_kwin_appmenu" version="2">
<description summary="appmenu dbus address interface">
The DBus service name and object path where the appmenu interface is present
The object should be registered on the session bus before sending this request.
If not applicable, clients should remove this object.
</description>
<request name="set_address">
<description summary="initialise or update the location of the AppMenu interface">
Set or update the service name and object path.
Strings should be formatted in Latin-1 matching the relevant DBus specifications.
</description>
<arg name="service_name" type="string" />
<arg name="object_path" type="string" />
</request>
<request name="release" type="destructor">
<description summary="release the appmenu object"/>
</request>
</interface>
</protocol>
3 changes: 2 additions & 1 deletion proto/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ server_protocols = [
'wayfire-shell-unstable-v2.xml',
'gtk-shell.xml',
'wlr-layer-shell-unstable-v1.xml',
'wlr-output-power-management-unstable-v1.xml'
'wlr-output-power-management-unstable-v1.xml',
'kde-appmenu.xml'
]

wl_protos_src = []
Expand Down
5 changes: 5 additions & 0 deletions src/api/wayfire/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ class object_base_t
return true;
}

void erase_property(std::string name)
{
erase_data(name);
}

object_base_t(const object_base_t &) = delete;
object_base_t(object_base_t &&) = delete;
object_base_t& operator =(const object_base_t&) = delete;
Expand Down
2 changes: 1 addition & 1 deletion src/api/wayfire/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ using wayfire_plugin_load_func = wf::plugin_interface_t * (*)();
/**
* The version is defined as macro as well, to allow conditional compilation.
*/
#define WAYFIRE_API_ABI_VERSION_MACRO 2025'12'26
#define WAYFIRE_API_ABI_VERSION_MACRO 2026'01'22

/**
* The version of Wayfire's API/ABI
Expand Down