commit a76e501

Michael Forney  ·  2014-04-24 01:59:08 +0000 UTC
parent 9df1eb0
xwm: Claim WM_S0 selection, as specified by ICCCM
2 files changed,  +53, -1
+2, -0
1@@ -69,6 +69,8 @@
2     ((type *) ((uintptr_t) __mptr - OFFSET_OF(type, member)));              \
3 })
4 
5+#define ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0])
6+
7 struct wl_resource;
8 
9 void swc_remove_resource(struct wl_resource * resource);
+51, -1
 1@@ -47,14 +47,30 @@ struct xwl_window
 2     };
 3 };
 4 
 5+enum atom
 6+{
 7+    ATOM_WM_S0,
 8+};
 9+
10 static struct
11 {
12     xcb_connection_t * connection;
13     xcb_ewmh_connection_t ewmh;
14     xcb_screen_t * screen;
15+    xcb_window_t window;
16     struct wl_event_source * source;
17     struct wl_list windows, unpaired_windows;
18-} xwm;
19+    union
20+    {
21+        const char * name;
22+        xcb_intern_atom_cookie_t cookie;
23+        xcb_atom_t value;
24+    } atoms[1];
25+} xwm = {
26+    .atoms = {
27+        [ATOM_WM_S0] = "WM_S0",
28+    }
29+};
30 
31 static void update_name(struct xwl_window * xwl_window)
32 {
33@@ -179,6 +195,9 @@ bool xwm_initialize(int fd)
34     xcb_void_cookie_t change_attributes_cookie, redirect_subwindows_cookie;
35     xcb_generic_error_t * error;
36     xcb_intern_atom_cookie_t * ewmh_cookies;
37+    xcb_intern_atom_reply_t * atom_reply;
38+    unsigned index;
39+    const char * name;
40     const xcb_query_extension_reply_t * composite_extension;
41 
42     xwm.connection = xcb_connect_to_fd(fd, NULL);
43@@ -198,6 +217,13 @@ bool xwm_initialize(int fd)
44         goto error1;
45     }
46 
47+    for (index = 0; index < ARRAY_LENGTH(xwm.atoms); ++index)
48+    {
49+        name = xwm.atoms[index].name;
50+        xwm.atoms[index].cookie = xcb_intern_atom(xwm.connection, 0,
51+                                                  strlen(name), name);
52+    }
53+
54     setup = xcb_get_setup(xwm.connection);
55     screen_iterator = xcb_setup_roots_iterator(setup);
56     xwm.screen = screen_iterator.data;
57@@ -245,12 +271,36 @@ bool xwm_initialize(int fd)
58         goto error3;
59     }
60 
61+    xwm.window = xcb_generate_id(xwm.connection);
62+    xcb_create_window(xwm.connection, 0, xwm.window, xwm.screen->root,
63+                      0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY,
64+                      XCB_COPY_FROM_PARENT, 0, NULL);
65+
66     if (!xcb_ewmh_init_atoms_replies(&xwm.ewmh, ewmh_cookies, NULL))
67     {
68         ERROR("xwm: Failed to get EWMH atom replies\n");
69         goto error3;
70     }
71 
72+    for (index = 0; index < ARRAY_LENGTH(xwm.atoms); ++index)
73+    {
74+        atom_reply = xcb_intern_atom_reply(xwm.connection,
75+                                           xwm.atoms[index].cookie, &error);
76+
77+        if (error)
78+        {
79+            ERROR("xwm: Failed to get atom reply: %u\n", error->error_code);
80+            return false;
81+        }
82+
83+        xwm.atoms[index].value = atom_reply->atom;
84+        free(atom_reply);
85+    }
86+
87+    xcb_set_selection_owner(xwm.connection, xwm.window,
88+                            xwm.atoms[ATOM_WM_S0].value, XCB_CURRENT_TIME);
89+    xcb_flush(xwm.connection);
90+
91     return true;
92 
93   error3: