Respect Motif hint for window decorations
Patch status: superseded
Patch by Tony Crisci
Long description:
When the _MOTIF_WM_HINTS property of a window specifies it should have no title bar, or no decorations at all, respond by setting the border style of that container to BS_PIXEL or BS_NONE respectively. This comes from the old Motif window manager. It was originally intended to specify exactly what sort of decorations a window should have, and exactly what sort of user input it should respond to. The EWMH spec intended to replace Motif hints with _NET_WM_WINDOW_TYPE, but it is still in use by popular widget toolkits such as GTK+ and Java AWT. i3's implementation simply mirrors Gnome's Metacity. Official documentation of this hint is nowhere to be found. For more information see: https://people.gnome.org/~tthurman/docs/metacity/xprops_8h-source.html http://stackoverflow.com/questions/13787553/detect-if-a-x11-window-has-decorations
To apply this patch, use:
curl http://cr.i3wm.org/patch/361/raw.patch | git am
b/include/atoms.xmacro
| 32 |
@@ -31,3 +31,4 @@ xmacro(I3_SHMLOG_PATH) |
| 33 |
xmacro(I3_PID) |
| 34 |
xmacro(_NET_REQUEST_FRAME_EXTENTS) |
| 35 |
xmacro(_NET_FRAME_EXTENTS) |
| 36 |
+xmacro(_MOTIF_WM_HINTS) |
b/include/window.h
| 41 |
@@ -61,3 +61,10 @@ void window_update_role(i3Window *win, xcb_get_property_reply_t *prop, bool befo |
| 42 |
* |
| 43 |
*/ |
| 44 |
void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop, bool *urgency_hint); |
| 45 |
+ |
| 46 |
+/** |
| 47 |
+ * Updates the MOTIF_WM_HINTS. The container's border style should be set to |
| 48 |
+ * `motif_border_style' and set to floating if border style is not BS_NORMAL. |
| 49 |
+ * |
| 50 |
+ */ |
| 51 |
+void window_update_motif_hints(i3Window *win, xcb_get_property_reply_t *prop, border_style_t *motif_border_style); |
b/src/manage.c
| 56 |
@@ -118,7 +118,8 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki |
| 57 |
xcb_get_property_cookie_t wm_type_cookie, strut_cookie, state_cookie, |
| 58 |
utf8_title_cookie, title_cookie, |
| 59 |
class_cookie, leader_cookie, transient_cookie, |
| 60 |
- role_cookie, startup_id_cookie, wm_hints_cookie; |
| 61 |
+ role_cookie, startup_id_cookie, wm_hints_cookie, |
| 62 |
+ motif_wm_hints_cookie; |
| 63 |
|
| 64 |
|
| 65 |
geomc = xcb_get_geometry(conn, d); |
| 66 |
@@ -188,6 +189,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki |
| 67 |
role_cookie = GET_PROPERTY(A_WM_WINDOW_ROLE, 128); |
| 68 |
startup_id_cookie = GET_PROPERTY(A__NET_STARTUP_ID, 512); |
| 69 |
wm_hints_cookie = xcb_icccm_get_wm_hints(conn, window); |
| 70 |
+ motif_wm_hints_cookie = GET_PROPERTY(A__MOTIF_WM_HINTS, 5 * sizeof(long)); |
| 71 |
/* TODO: also get wm_normal_hints here. implement after we got rid of xcb-event */ |
| 72 |
|
| 73 |
DLOG("Managing window 0x%08x\n", window);
|
| 74 |
@@ -222,6 +224,8 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki |
| 75 |
window_update_role(cwindow, xcb_get_property_reply(conn, role_cookie, NULL), true); |
| 76 |
bool urgency_hint; |
| 77 |
window_update_hints(cwindow, xcb_get_property_reply(conn, wm_hints_cookie, NULL), &urgency_hint); |
| 78 |
+ border_style_t motif_border_style = BS_NORMAL; |
| 79 |
+ window_update_motif_hints(cwindow, xcb_get_property_reply(conn, motif_wm_hints_cookie, NULL), &motif_border_style); |
| 80 |
|
| 81 |
xcb_get_property_reply_t *startup_id_reply; |
| 82 |
startup_id_reply = xcb_get_property_reply(conn, startup_id_cookie, NULL); |
| 83 |
@@ -444,6 +448,12 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki |
| 84 |
floating_enable(nc, true); |
| 85 |
} |
| 86 |
|
| 87 |
+ if (motif_border_style != BS_NORMAL) {
|
| 88 |
+ DLOG("MOTIF_WM_HINTS specifies decorations (border_style = %d)\n", motif_border_style);
|
| 89 |
+ floating_enable(nc, false); |
| 90 |
+ con_set_border_style(nc, motif_border_style, config.default_border_width); |
| 91 |
+ } |
| 92 |
+ |
| 93 |
/* to avoid getting an UnmapNotify event due to reparenting, we temporarily |
| 94 |
* declare no interest in any state change event of this window */ |
| 95 |
values[0] = XCB_NONE; |
b/src/window.c
| 100 |
@@ -11,6 +11,12 @@ |
| 101 |
*/ |
| 102 |
#include "all.h" |
| 103 |
|
| 104 |
+#define MWM_HINTS_DECORATIONS (1L << 1) |
| 105 |
+ |
| 106 |
+#define MWM_DECOR_ALL (1L << 0) |
| 107 |
+#define MWM_DECOR_BORDER (1L << 1) |
| 108 |
+#define MWM_DECOR_TITLE (1L << 3) |
| 109 |
+ |
| 110 |
/* |
| 111 |
* Updates the WM_CLASS (consisting of the class and instance) for the |
| 112 |
* given window. |
| 113 |
@@ -254,3 +260,53 @@ void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop, bool *ur |
| 114 |
|
| 115 |
free(prop); |
| 116 |
} |
| 117 |
+ |
| 118 |
+/** |
| 119 |
+ * Updates the MOTIF_WM_HINTS. The container's border style should be set to |
| 120 |
+ * `motif_border_style' and set to floating if border style is not BS_NORMAL. |
| 121 |
+ * |
| 122 |
+ * i3 only uses this hint when it specifies a window should have no |
| 123 |
+ * title bar, or no decorations at all, which is how most window managers |
| 124 |
+ * handle it. |
| 125 |
+ * |
| 126 |
+ * This comes from the old Motif window manager. It was originally intended to |
| 127 |
+ * specify exactly what sort of decorations a window should have, and exactly |
| 128 |
+ * what sort of user input it should respond to. The EWMH spec intended to |
| 129 |
+ * replace Motif hints with _NET_WM_WINDOW_TYPE, but it is still in use by |
| 130 |
+ * popular widget toolkits such as GTK+ and Java AWT. |
| 131 |
+ * |
| 132 |
+ */ |
| 133 |
+void window_update_motif_hints(i3Window *win, xcb_get_property_reply_t *prop, border_style_t *motif_border_style) {
|
| 134 |
+ /* This implementation simply mirrors Gnome's Metacity. Official |
| 135 |
+ * documentation of this hint is nowhere to be found. |
| 136 |
+ * For more information see: |
| 137 |
+ * https://people.gnome.org/~tthurman/docs/metacity/xprops_8h-source.html |
| 138 |
+ * http://stackoverflow.com/questions/13787553/detect-if-a-x11-window-has-decorations |
| 139 |
+ */ |
| 140 |
+ |
| 141 |
+ if (motif_border_style != NULL) |
| 142 |
+ *motif_border_style = BS_NORMAL; |
| 143 |
+ |
| 144 |
+ if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
|
| 145 |
+ FREE(prop); |
| 146 |
+ return; |
| 147 |
+ } |
| 148 |
+ |
| 149 |
+ /* The property consists of an array of 5 `long's. The first value is a bit |
| 150 |
+ * mask of what properties the hint will specify. We are only interested in |
| 151 |
+ * MWM_HINTS_DECORATIONS because it indicates that the second value of the |
| 152 |
+ * array tells us which decorations the window should have, each flag being |
| 153 |
+ * a particular decoration. */ |
| 154 |
+ long *motif_hints = (long *)xcb_get_property_value(prop); |
| 155 |
+ |
| 156 |
+ if (motif_border_style != NULL && motif_hints[0] & MWM_HINTS_DECORATIONS) {
|
| 157 |
+ if (motif_hints[1] & MWM_DECOR_ALL || motif_hints[1] & MWM_DECOR_TITLE) |
| 158 |
+ *motif_border_style = BS_NORMAL; |
| 159 |
+ else if (motif_hints[1] & MWM_DECOR_BORDER) |
| 160 |
+ *motif_border_style = BS_PIXEL; |
| 161 |
+ else |
| 162 |
+ *motif_border_style = BS_NONE; |
| 163 |
+ } |
| 164 |
+ |
| 165 |
+ FREE(prop); |
| 166 |
+} |