[PATCH weston v4] xwm: tell the shell the pid of the X clients

Giulio Camuffo giuliocamuffo at gmail.com
Mon Jan 12 09:04:06 PST 2015


All the surfaces from all the X clients share the same wl_client so
wl_client_get_credentials can't be used to get the pid of the X
clients.
The shell may need to know the pid to be able to associate a surface
with e.g. a DBus service.
---

 desktop-shell/shell.c     |  7 +++++++
 src/compositor.h          |  1 +
 xwayland/window-manager.c | 21 +++++++++++++--------
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index c9c61b1..1925cd5 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -2248,6 +2248,12 @@ set_title(struct shell_surface *shsurf, const char *title)
 }
 
 static void
+set_pid(struct shell_surface *shsurf, pid_t pid)
+{
+	/* We have no use for it */
+}
+
+static void
 set_type(struct shell_surface *shsurf, enum shell_surface_type t)
 {
 	shsurf->type = t;
@@ -6626,6 +6632,7 @@ module_init(struct weston_compositor *ec,
 	ec->shell_interface.resize = surface_resize;
 	ec->shell_interface.set_title = set_title;
 	ec->shell_interface.set_window_geometry = set_window_geometry;
+	ec->shell_interface.set_pid = set_pid;
 
 	weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
 	weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
diff --git a/src/compositor.h b/src/compositor.h
index 900d2a5..3b1e490 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -121,6 +121,7 @@ struct weston_shell_interface {
 	void (*set_window_geometry)(struct shell_surface *shsurf,
 				    int32_t x, int32_t y,
 				    int32_t width, int32_t height);
+	void (*set_pid)(struct shell_surface *shsurf, pid_t pid);
 };
 
 struct weston_animation {
diff --git a/xwayland/window-manager.c b/xwayland/window-manager.c
index f362eac..748c896 100644
--- a/xwayland/window-manager.c
+++ b/xwayland/window-manager.c
@@ -401,6 +401,7 @@ weston_wm_window_read_properties(struct weston_wm_window *window)
 	uint32_t *xid;
 	xcb_atom_t *atom;
 	uint32_t i;
+	char name[1024];
 
 	if (!window->properties_dirty)
 		return;
@@ -487,10 +488,19 @@ weston_wm_window_read_properties(struct weston_wm_window *window)
 		free(reply);
 	}
 
+	gethostname(name, 1024);
+	/* this is only one heuristic to guess the PID of a client is valid,
+	 * assuming it's compliant with icccm and ewmh. Non-compliants and
+	 * remote applications of course fail. */
+	if (!window->machine || strcmp(window->machine, name))
+		window->pid = 0;
+
 	if (window->shsurf && window->name)
 		shell_interface->set_title(window->shsurf, window->name);
 	if (window->frame && window->name)
 		frame_set_title(window->frame, window->name);
+	if (window->shsurf && window->pid > 0)
+		shell_interface->set_pid(window->shsurf, window->pid);
 }
 
 static void
@@ -651,17 +661,10 @@ weston_wm_kill_client(struct wl_listener *listener, void *data)
 {
 	struct weston_surface *surface = data;
 	struct weston_wm_window *window = get_wm_window(surface);
-	char name[1024];
-
 	if (!window)
 		return;
 
-	gethostname(name, 1024);
-
-	/* this is only one heuristic to guess the PID of a client is valid,
-	 * assuming it's compliant with icccm and ewmh. Non-compliants and
-	 * remote applications of course fail. */
-	if (!strcmp(window->machine, name) && window->pid != 0)
+	if (window->pid > 0)
 		kill(window->pid, SIGKILL);
 }
 
@@ -2350,6 +2353,8 @@ xserver_map_shell_surface(struct weston_wm_window *window,
 
 	if (window->name)
 		shell_interface->set_title(window->shsurf, window->name);
+	if (window->pid > 0)
+		shell_interface->set_pid(window->shsurf, window->pid);
 
 	if (window->fullscreen) {
 		window->saved_width = window->width;
-- 
2.2.1



More information about the wayland-devel mailing list