From fd06c6fa18f89aafc48bac6a8295c207c7c6dcee Mon Sep 17 00:00:00 2001 From: Scott Moreau Date: Fri, 9 Feb 2024 17:28:24 -0700 Subject: [PATCH 1/3] ipc-rules: Add get-view-pid to get the active view pid --- plugins/single_plugins/ipc-rules.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugins/single_plugins/ipc-rules.cpp b/plugins/single_plugins/ipc-rules.cpp index adf642c5b..ec03cb3d9 100644 --- a/plugins/single_plugins/ipc-rules.cpp +++ b/plugins/single_plugins/ipc-rules.cpp @@ -445,6 +445,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker nlohmann::json description; description["id"] = view->get_id(); + description["pid"] = get_view_pid(view); description["app-id"] = view->get_app_id(); description["title"] = view->get_title(); auto toplevel = wf::toplevel_cast(view); @@ -494,6 +495,29 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker return wf::ipc::json_error("Unknown input device!"); }; + + pid_t get_view_pid(wayfire_view view) + { + pid_t pid = -1; + if (!view) + { + return pid; + } + +#if WF_HAS_XWAYLAND + wlr_surface *wlr_surface = view->get_wlr_surface(); + if (wlr_surface && wlr_xwayland_surface_try_from_wlr_surface(wlr_surface)) + { + pid = wlr_xwayland_surface_try_from_wlr_surface(wlr_surface)->pid; + } else +#endif + if (view && view->get_client()) + { + wl_client_get_credentials(view->get_client(), &pid, 0, 0); + } + + return pid; + } }; DECLARE_WAYFIRE_PLUGIN(ipc_rules_t); From 72a68863bc939d83cfedd95b7aaf848af17c576d Mon Sep 17 00:00:00 2001 From: Scott Moreau Date: Sat, 10 Feb 2024 09:47:15 -0700 Subject: [PATCH 2/3] ipc-rules: Merge list_views() and view_to_json() properties --- plugins/single_plugins/ipc-rules.cpp | 48 +++++++++------------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/plugins/single_plugins/ipc-rules.cpp b/plugins/single_plugins/ipc-rules.cpp index ec03cb3d9..ba9e8c52f 100644 --- a/plugins/single_plugins/ipc-rules.cpp +++ b/plugins/single_plugins/ipc-rules.cpp @@ -171,42 +171,13 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker // no-op } - wf::ipc::method_callback list_views = [] (nlohmann::json) + wf::ipc::method_callback list_views = [=] (nlohmann::json) { auto response = nlohmann::json::array(); for (auto& view : wf::get_core().get_all_views()) { - nlohmann::json v; - auto output = view->get_output(); - v["id"] = view->get_id(); - v["title"] = view->get_title(); - v["app-id"] = view->get_app_id(); - v["base-geometry"] = wf::ipc::geometry_to_json(get_view_base_geometry(view)); - v["bbox"] = wf::ipc::geometry_to_json(view->get_bounding_box()); - v["output"] = output ? output->to_string() : "null"; - v["output-id"] = output ? output->get_id() : -1; - v["last-focus-timestamp"] = wf::get_focus_timestamp(view); - v["role"] = role_to_string(view->role); - - v["state"] = {}; - v["state"]["mapped"] = view->is_mapped(); - v["state"]["focusable"] = view->is_focusable(); - - if (auto toplevel = toplevel_cast(view)) - { - v["parent"] = toplevel->parent ? (int)toplevel->parent->get_id() : -1; - v["geometry"] = wf::ipc::geometry_to_json(toplevel->get_geometry()); - v["state"]["tiled"] = toplevel->pending_tiled_edges(); - v["state"]["fullscreen"] = toplevel->pending_fullscreen(); - v["state"]["minimized"] = toplevel->minimized; - v["state"]["activated"] = toplevel->activated; - } else - { - v["geometry"] = wf::ipc::geometry_to_json(view->get_bounding_box()); - } - - v["layer"] = layer_to_string(get_view_layer(view)); + nlohmann::json v = view_to_json(view); response.push_back(v); } @@ -443,20 +414,31 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker return nullptr; } + auto output = view->get_output(); nlohmann::json description; description["id"] = view->get_id(); description["pid"] = get_view_pid(view); - description["app-id"] = view->get_app_id(); description["title"] = view->get_title(); + description["app-id"] = view->get_app_id(); + description["base-geometry"] = wf::ipc::geometry_to_json(get_view_base_geometry(view)); auto toplevel = wf::toplevel_cast(view); + description["parent"] = toplevel && toplevel->parent ? (int)toplevel->parent->get_id() : -1; description["geometry"] = wf::ipc::geometry_to_json(toplevel ? toplevel->get_pending_geometry() : view->get_bounding_box()); - description["output"] = view->get_output() ? view->get_output()->get_id() : -1; + description["bbox"] = wf::ipc::geometry_to_json(view->get_bounding_box()); + description["output-id"] = view->get_output() ? view->get_output()->get_id() : -1; + description["output-name"] = output ? output->to_string() : "null"; + description["last-focus-timestamp"] = wf::get_focus_timestamp(view); + description["role"] = role_to_string(view->role); + description["mapped"] = view->is_mapped(); + description["layer"] = layer_to_string(get_view_layer(view)); description["tiled-edges"] = toplevel ? toplevel->pending_tiled_edges() : 0; description["fullscreen"] = toplevel ? toplevel->pending_fullscreen() : false; description["minimized"] = toplevel ? toplevel->minimized : false; + description["activated"] = toplevel ? toplevel->activated : false; description["focusable"] = view->is_focusable(); description["type"] = get_view_type(view); + return description; } From 33c08d4574f35050f1f546dd7793877d59e6a1d1 Mon Sep 17 00:00:00 2001 From: Scott Moreau Date: Sat, 10 Feb 2024 15:26:19 -0700 Subject: [PATCH 3/3] ipc-rules: Send view-unmapped signal --- plugins/single_plugins/ipc-rules.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/single_plugins/ipc-rules.cpp b/plugins/single_plugins/ipc-rules.cpp index ba9e8c52f..b59e65756 100644 --- a/plugins/single_plugins/ipc-rules.cpp +++ b/plugins/single_plugins/ipc-rules.cpp @@ -140,6 +140,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker method_repository->register_method("window-rules/get-focused-view", get_focused_view); method_repository->connect(&on_client_disconnected); wf::get_core().connect(&on_view_mapped); + wf::get_core().connect(&on_view_unmapped); wf::get_core().connect(&on_kbfocus_changed); init_output_tracking(); } @@ -347,6 +348,11 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker send_view_to_subscribes(ev->view, "view-mapped"); }; + wf::signal::connection_t on_view_unmapped = [=] (wf::view_unmapped_signal *ev) + { + send_view_to_subscribes(ev->view, "view-unmapped"); + }; + wf::signal::connection_t on_kbfocus_changed = [=] (wf::keyboard_focus_changed_signal *ev) {