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 fd06c6f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions plugins/single_plugins/ipc-rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

0 comments on commit fd06c6f

Please sign in to comment.