2 #define I3__FILE__ "window.c"
4 * vim:ts=4:sw=4:expandtab
6 * i3 - an improved dynamic tiling window manager
7 * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
9 * window.c: Updates window attributes (X11 hints/properties).
15 * Updates the WM_CLASS (consisting of the class and instance) for the
19 void window_update_class(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
20 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
21 DLOG("WM_CLASS not set.\n");
26 /* We cannot use asprintf here since this property contains two
27 * null-terminated strings (for compatibility reasons). Instead, we
28 * use strdup() on both strings */
29 char *new_class = xcb_get_property_value(prop);
31 FREE(win->class_instance);
32 FREE(win->class_class);
34 win->class_instance = sstrdup(new_class);
35 if ((strlen(new_class) + 1) < xcb_get_property_value_length(prop))
36 win->class_class = sstrdup(new_class + strlen(new_class) + 1);
37 else win->class_class = NULL;
38 LOG("WM_CLASS changed to %s (instance), %s (class)\n",
39 win->class_instance, win->class_class);
52 * Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given
53 * window. Further updates using window_update_name_legacy will be ignored.
56 void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
57 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
58 DLOG("_NET_WM_NAME not specified, not changing\n");
63 i3string_free(win->name);
64 win->name = i3string_from_utf8_with_length(xcb_get_property_value(prop),
65 xcb_get_property_value_length(prop));
66 win->name_x_changed = true;
67 LOG("_NET_WM_NAME changed to \"%s\"\n", i3string_as_utf8(win->name));
69 win->uses_net_wm_name = true;
82 * Updates the name by using WM_NAME (encoded in COMPOUND_TEXT). We do not
83 * touch what the client sends us but pass it to xcb_image_text_8. To get
84 * proper unicode rendering, the application has to use _NET_WM_NAME (see
85 * window_update_name()).
88 void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
89 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
90 DLOG("WM_NAME not set (_NET_WM_NAME is what you want anyways).\n");
95 /* ignore update when the window is known to already have a UTF-8 name */
96 if (win->uses_net_wm_name) {
101 i3string_free(win->name);
102 win->name = i3string_from_utf8_with_length(xcb_get_property_value(prop),
103 xcb_get_property_value_length(prop));
105 LOG("WM_NAME changed to \"%s\"\n", i3string_as_utf8(win->name));
106 LOG("Using legacy window title. Note that in order to get Unicode window "
107 "titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");
109 win->name_x_changed = true;
116 run_assignments(win);
122 * Updates the CLIENT_LEADER (logical parent window).
125 void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop) {
126 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
127 DLOG("CLIENT_LEADER not set.\n");
132 xcb_window_t *leader = xcb_get_property_value(prop);
133 if (leader == NULL) {
138 DLOG("Client leader changed to %08x\n", *leader);
140 win->leader = *leader;
146 * Updates the TRANSIENT_FOR (logical parent window).
149 void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop) {
150 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
151 DLOG("TRANSIENT_FOR not set.\n");
156 xcb_window_t transient_for;
157 if (!xcb_icccm_get_wm_transient_for_from_reply(&transient_for, prop)) {
162 DLOG("Transient for changed to %08x\n", transient_for);
164 win->transient_for = transient_for;
170 * Updates the _NET_WM_STRUT_PARTIAL (reserved pixels at the screen edges)
173 void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop) {
174 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
175 DLOG("_NET_WM_STRUT_PARTIAL not set.\n");
181 if (!(strut = xcb_get_property_value(prop))) {
186 DLOG("Reserved pixels changed to: left = %d, right = %d, top = %d, bottom = %d\n",
187 strut[0], strut[1], strut[2], strut[3]);
189 win->reserved = (struct reservedpx){ strut[0], strut[1], strut[2], strut[3] };
195 * Updates the WM_WINDOW_ROLE
198 void window_update_role(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
199 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
200 DLOG("WM_WINDOW_ROLE not set.\n");
206 if (asprintf(&new_role, "%.*s", xcb_get_property_value_length(prop),
207 (char*)xcb_get_property_value(prop)) == -1) {
208 perror("asprintf()");
209 DLOG("Could not get WM_WINDOW_ROLE\n");
214 win->role = new_role;
215 LOG("WM_WINDOW_ROLE changed to \"%s\"\n", win->role);
222 run_assignments(win);
228 * Updates the WM_HINTS (we only care about the input focus handling part).
231 void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop, bool *urgency_hint) {
232 if (urgency_hint != NULL)
233 *urgency_hint = false;
235 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
236 DLOG("WM_HINTS not set.\n");
241 xcb_icccm_wm_hints_t hints;
243 if (!xcb_icccm_get_wm_hints_from_reply(&hints, prop)) {
244 DLOG("Could not get WM_HINTS\n");
249 win->doesnt_accept_focus = !hints.input;
250 LOG("WM_HINTS.input changed to \"%d\"\n", hints.input);
252 if (urgency_hint != NULL)
253 *urgency_hint = (xcb_icccm_wm_hints_get_urgency(&hints) != 0);