commit be9e90f
shrub
·
2026-01-10 00:20:19 +0000 UTC
parent 5ad54d7
swc_window_get_pid add api to query a window's client pid
2 files changed,
+33,
-0
+8,
-0
1@@ -26,6 +26,7 @@
2
3 #include <stdbool.h>
4 #include <stdint.h>
5+#include <sys/types.h>
6
7 #ifdef __cplusplus
8 extern "C" {
9@@ -320,6 +321,13 @@ void swc_window_set_geometry(struct swc_window *window, const struct swc_rectang
10 */
11 bool swc_window_get_geometry(const struct swc_window *window, struct swc_rectangle *geometry);
12
13+/**
14+ * Get the pid of the client that owns this window
15+ *
16+ * returns pid, or 0 if unavailable
17+ */
18+pid_t swc_window_get_pid(struct swc_window *window);
19+
20 /**
21 * Set the window's border color and width.
22 *
+25,
-0
1@@ -27,12 +27,14 @@
2 #include "internal.h"
3 #include "keyboard.h"
4 #include "seat.h"
5+#include "surface.h"
6 #include "swc.h"
7 #include "util.h"
8 #include "view.h"
9
10 #include <stdlib.h>
11 #include <string.h>
12+#include <sys/types.h>
13
14 #define INTERNAL(w) ((struct window *)(w))
15
16@@ -519,3 +521,26 @@ window_begin_resize(struct window *window, uint32_t edges, struct button *button
17 window->resize.offset.y = geometry->y - py + ((edges & SWC_WINDOW_EDGE_BOTTOM) ? geometry->height : 0);
18 window->resize.edges = edges;
19 }
20+
21+EXPORT pid_t
22+swc_window_get_pid(struct swc_window *base)
23+{
24+ struct window *window = INTERNAL(base);
25+ struct surface *surface;
26+ struct wl_client *client;
27+ pid_t pid;
28+ uid_t uid;
29+ gid_t gid;
30+
31+ if (!window || !window->view || !window->view->surface)
32+ return 0;
33+
34+ surface = window->view->surface;
35+ if (!surface->resource)
36+ return 0;
37+
38+ client = wl_resource_get_client(surface->resource);
39+ wl_client_get_credentials(client, &pid, &uid, &gid);
40+
41+ return pid;
42+}