Skip to content

Commit

Permalink
ipc-rules: Add get-view-pid to get the active view pid
Browse files Browse the repository at this point in the history
  • Loading branch information
soreau committed Feb 10, 2024
1 parent 3b42051 commit 6180b27
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions plugins/single_plugins/ipc-rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
method_repository->register_method("window-rules/configure-view", configure_view);
method_repository->register_method("window-rules/focus-view", focus_view);
method_repository->register_method("window-rules/get-focused-view", get_focused_view);
method_repository->register_method("window-rules/get-view-pid", get_view_pid);
method_repository->connect(&on_client_disconnected);
wf::get_core().connect(&on_view_mapped);
wf::get_core().connect(&on_kbfocus_changed);
Expand All @@ -156,6 +157,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
method_repository->unregister_method("window-rules/configure-view");
method_repository->unregister_method("window-rules/focus-view");
method_repository->unregister_method("window-rules/get-focused-view");
method_repository->unregister_method("window-rules/get-view-pid");
fini_output_tracking();
}

Expand Down Expand Up @@ -494,6 +496,35 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker

return wf::ipc::json_error("Unknown input device!");
};

wf::ipc::method_callback get_view_pid = [=] (nlohmann::json)
{
auto response = wf::ipc::json_ok();
auto view = wf::get_core().seat->get_active_view();
pid_t pid = -1;
if (!view)
{
response["pid"] = pid;
return response;
}

wlr_surface *wlr_surface = view->get_wlr_surface();
int is_xwayland_surface = 0;
#if WF_HAS_XWAYLAND
is_xwayland_surface = wlr_surface && wlr_xwayland_surface_try_from_wlr_surface(wlr_surface);
if (is_xwayland_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);
}

response["pid"] = pid;
return response;
};
};

DECLARE_WAYFIRE_PLUGIN(ipc_rules_t);

0 comments on commit 6180b27

Please sign in to comment.