]> git.sur5r.net Git - i3/i3/commitdiff
Implement handling of window titles
authorMichael Stapelberg <michael+git@stapelberg.de>
Wed, 11 Feb 2009 17:54:20 +0000 (18:54 +0100)
committerMichael Stapelberg <michael+git@stapelberg.de>
Wed, 11 Feb 2009 17:54:20 +0000 (18:54 +0100)
data.h
mainx.c

diff --git a/data.h b/data.h
index 4a53dd1943ed4d128d53ae8d0cfc0c7694914a9f..cefc92b7c11a7274809ba2b1ef89203afdc4e25f 100644 (file)
--- a/data.h
+++ b/data.h
@@ -87,6 +87,10 @@ struct Client {
        int x, y;
        int width, height;
 
+       /* Name */
+       char *name;
+       int name_len;
+
        /* XCB contexts */
        xcb_window_t frame; /* Our window: The frame around the client */
        xcb_gcontext_t titlegc; /* The titlebar’s graphic context inside the frame */
diff --git a/mainx.c b/mainx.c
index 8d29b4288b9132474b3c4146188ce233587e45c1..15fd3cc64047e40b2ca1dffcc8e566ae7a01718e 100644 (file)
--- a/mainx.c
+++ b/mainx.c
@@ -403,7 +403,7 @@ void decorate_window(xcb_connection_t *conn, Client *client) {
 
        /* TODO: utf8? */
        char *label;
-       asprintf(&label, "gots win %08x", client->frame);
+       asprintf(&label, "(%08x) %.*s", client->frame, client->name_len, client->name);
         xcb_void_cookie_t text_cookie = xcb_image_text_8_checked(conn, strlen(label), client->frame,
                                        client->titlegc, 3 /* X */, font->height /* Y = baseline of font */, label);
        free(label);
@@ -1113,7 +1113,25 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *c, xcb_unmap_notify_
        return 1;
 }
 
+/*
+ * Called when a window changes its title
+ *
+ */
+static int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state,
+                               xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
+       printf("window's name changed.\n");
+       Client *client = table_get(byChild, window);
+
+       client->name_len = xcb_get_property_value_length(prop);
+       client->name = malloc(client->name_len);
+       strncpy(client->name, xcb_get_property_value(prop), client->name_len);
+       printf("rename to \"%.*s\".\n", client->name_len, client->name);
+
+       decorate_window(conn, client);
+       xcb_flush(conn);
 
+       return 1;
+}
 
 static int handleExposeEvent(void *data, xcb_connection_t *c, xcb_expose_event_t *e) {
 printf("exposeevent\n");
@@ -1235,6 +1253,8 @@ int main(int argc, char *argv[], char *env[]) {
        xcb_property_handlers_init(&prophs, &evenths);
        xcb_event_set_map_notify_handler(&evenths, handle_map_notify_event, &prophs);
 
+       xcb_watch_wm_name(&prophs, 128, handle_windowname_change, 0);
+
        root = xcb_aux_get_screen(c, screens)->root;
        root_win = root;