xwm: tell the shell the pid of the X clients
authorGiulio Camuffo <giuliocamuffo@gmail.com>
Tue, 27 Jan 2015 17:10:37 +0000 (19:10 +0200)
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>
Mon, 30 Mar 2015 13:04:57 +0000 (16:04 +0300)
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.

[Pekka: fixed trivial merge conflicts.]
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
desktop-shell/shell.c
src/compositor.h
xwayland/window-manager.c

index 83698e9dc88fb58a467aef2916cc7ec56ef2bb9a..f7c928e7873049f39b3cd5f76dffac9f0093acce 100644 (file)
@@ -2251,6 +2251,12 @@ set_title(struct shell_surface *shsurf, const char *title)
        shsurf->surface->timeline.force_refresh = 1;
 }
 
+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)
 {
@@ -6602,6 +6608,7 @@ module_init(struct weston_compositor *ec,
        ec->shell_interface.set_title = set_title;
        ec->shell_interface.set_window_geometry = set_window_geometry;
        ec->shell_interface.set_maximized = shell_interface_set_maximized;
+       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);
index be323123a59ae1a15cb56b2abe90006ec25db4e6..5f49237de8e5b474b65f587477ac2ce43faa6657 100644 (file)
@@ -122,6 +122,7 @@ struct weston_shell_interface {
                                    int32_t x, int32_t y,
                                    int32_t width, int32_t height);
        void (*set_maximized)(struct shell_surface *shsurf);
+       void (*set_pid)(struct shell_surface *shsurf, pid_t pid);
 };
 
 struct weston_animation {
index 59cf39ae324c1818c1586a540bd3337e8421b0c3..145d940e3db886af090542d7fad67f41e3ac7057 100644 (file)
@@ -403,6 +403,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;
@@ -494,10 +495,28 @@ weston_wm_window_read_properties(struct weston_wm_window *window)
                free(reply);
        }
 
+       if (window->pid > 0) {
+               gethostname(name, sizeof(name));
+               for (i = 0; i < sizeof(name); i++) {
+                       if (name[i] == '\0')
+                               break;
+               }
+               if (i == sizeof(name))
+                       name[0] = '\0'; /* ignore stupid hostnames */
+
+               /* 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
@@ -658,17 +677,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);
 }
 
@@ -2430,6 +2442,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;