xwm: set the shell_surface's title
authorGiulio Camuffo <giuliocamuffo@gmail.com>
Wed, 11 Sep 2013 16:20:47 +0000 (18:20 +0200)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 11 Sep 2013 20:50:54 +0000 (13:50 -0700)
add a new function pointer to the weston_shell_interface struct that
shells will set accordingly.

src/compositor.h
src/shell.c
src/xwayland/window-manager.c

index 50e96ff..a523c83 100644 (file)
@@ -107,6 +107,8 @@ struct weston_shell_interface {
        int (*move)(struct shell_surface *shsurf, struct weston_seat *ws);
        int (*resize)(struct shell_surface *shsurf,
                      struct weston_seat *ws, uint32_t edges);
+       void (*set_title)(struct shell_surface *shsurf,
+                         const char *title);
 
 };
 
index 89153e3..c1e0109 100644 (file)
@@ -1592,13 +1592,19 @@ shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
 }
 
 static void
+set_title(struct shell_surface *shsurf, const char *title)
+{
+       free(shsurf->title);
+       shsurf->title = strdup(title);
+}
+
+static void
 shell_surface_set_title(struct wl_client *client,
                        struct wl_resource *resource, const char *title)
 {
        struct shell_surface *shsurf = wl_resource_get_user_data(resource);
 
-       free(shsurf->title);
-       shsurf->title = strdup(title);
+       set_title(shsurf, title);
 }
 
 static void
@@ -4580,6 +4586,7 @@ module_init(struct weston_compositor *ec,
        ec->shell_interface.set_xwayland = set_xwayland;
        ec->shell_interface.move = surface_move;
        ec->shell_interface.resize = surface_resize;
+       ec->shell_interface.set_title = set_title;
 
        wl_list_init(&shell->input_panel.surfaces);
 
index f775734..b4f64d3 100644 (file)
@@ -363,6 +363,8 @@ static void
 weston_wm_window_read_properties(struct weston_wm_window *window)
 {
        struct weston_wm *wm = window->wm;
+       struct weston_shell_interface *shell_interface =
+               &wm->server->compositor->shell_interface;
 
 #define F(field) offsetof(struct weston_wm_window, field)
        const struct {
@@ -468,6 +470,9 @@ weston_wm_window_read_properties(struct weston_wm_window *window)
                }
                free(reply);
        }
+
+       if (window->shsurf && window->name)
+               shell_interface->set_title(window->shsurf, window->name);
 }
 
 static void
@@ -1875,6 +1880,9 @@ surface_destroy(struct wl_listener *listener, void *data)
 
        wm_log("surface for xid %d destroyed\n", window->id);
 
+       /* This should have been freed by the shell.
+       Don't try to use it later. */
+       window->shsurf = NULL;
        window->surface = NULL;
 }
 
@@ -2029,6 +2037,9 @@ xserver_map_shell_surface(struct weston_wm *wm,
                                                      window->surface,
                                                      &shell_client);
 
+       if (window->name)
+               shell_interface->set_title(window->shsurf, window->name);
+
        if (window->fullscreen) {
                window->saved_width = window->width;
                window->saved_height = window->height;