From ee13d7c861bcd8be48ca85964e94a9c768d2fb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kondor=20D=C3=A1niel?= Date: Thu, 13 Feb 2025 21:45:17 +0100 Subject: [PATCH] foreign-toplevel: send KDE AppMenu info as well --- plugins/protocols/foreign-toplevel.cpp | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/plugins/protocols/foreign-toplevel.cpp b/plugins/protocols/foreign-toplevel.cpp index 22cae7d58..817aab1dc 100644 --- a/plugins/protocols/foreign-toplevel.cpp +++ b/plugins/protocols/foreign-toplevel.cpp @@ -8,6 +8,7 @@ #include #include #include "gtk-shell.hpp" +#include "kde-appmenu.hpp" #include "config.h" class wayfire_foreign_toplevel; @@ -22,6 +23,12 @@ class toplevel_gtk_shell1_dbus_properties_t : public wf::custom_data_t { std::optional unique_bus_name; }; +class toplevel_kde_appmenu_path_t : public wf::custom_data_t { + public: + std::optional service_name; + std::optional object_path; +}; + class wayfire_foreign_toplevel { wayfire_toplevel_view view; @@ -88,6 +95,11 @@ class wayfire_foreign_toplevel unique_bus_name); } + void toplevel_send_kde_appmenu_path(const char *service_name, const char *object_path) + { + wlr_foreign_toplevel_handle_v1_set_kde_appmenu_path(handle, service_name, object_path); + } + private: void toplevel_send_title() { @@ -284,6 +296,7 @@ class wayfire_foreign_toplevel_protocol_impl : public wf::plugin_interface_t wf::get_core().connect(&on_view_mapped); wf::get_core().connect(&on_view_unmapped); wf::get_core().connect(&on_view_dbus_properties_changed); + wf::get_core().connect(&on_view_kde_appmenu_changed); } void fini() override @@ -313,6 +326,13 @@ class wayfire_foreign_toplevel_protocol_impl : public wf::plugin_interface_t props->application_object_path ? props->application_object_path->c_str() : nullptr, props->unique_bus_name ? props->unique_bus_name->c_str() : nullptr); } + + if (auto props = toplevel->get_data()) + { + handle_for_view[toplevel]->toplevel_send_kde_appmenu_path( + props->service_name ? props->service_name->c_str() : nullptr, + props->object_path ? props->object_path->c_str() : nullptr); + } } }; @@ -358,6 +378,31 @@ class wayfire_foreign_toplevel_protocol_impl : public wf::plugin_interface_t } }; + wf::signal::connection_t on_view_kde_appmenu_changed = + [=] (kde_appmenu_dbus_address_signal *ev) + { + if (auto toplevel = wf::toplevel_cast(ev->view)) + { + auto it = handle_for_view.find(toplevel); + if (it != handle_for_view.end()) + { + it->second->toplevel_send_kde_appmenu_path( + ev->service_name, + ev->object_path); + } + /* Store the values with the view. This is necessary to cover + * the cases when either: + * (1) the view has not been mapped yet; or + * (2) the view is later unmapped and remapped + */ + auto props = toplevel->get_data_safe(); + if (ev->service_name) props->service_name = ev->service_name; + else props->service_name.reset(); + if (ev->object_path) props->object_path = ev->object_path; + else props->object_path.reset(); + } + }; + wlr_foreign_toplevel_manager_v1 *toplevel_manager; std::map> handle_for_view; };