Handle transient hint and window class dialog to mark clients as floating

This commit is contained in:
Michael Stapelberg 2009-06-12 22:59:23 +02:00
parent cb12e205d9
commit 052190ad05
6 changed files with 91 additions and 14 deletions

View File

@ -124,4 +124,14 @@ int handle_window_type(void *data, xcb_connection_t *conn, uint8_t state, xcb_wi
int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window, int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
xcb_atom_t name, xcb_get_property_reply_t *reply); xcb_atom_t name, xcb_get_property_reply_t *reply);
/**
* Handles the transient for hints set by a window, signalizing that this window is a popup window
* for some other window.
*
* See ICCCM 4.1.2.6 for more details
*
*/
int handle_transient_for(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
xcb_atom_t name, xcb_get_property_reply_t *reply);
#endif #endif

View File

@ -20,7 +20,7 @@
#ifndef _I3_H #ifndef _I3_H
#define _I3_H #define _I3_H
#define NUM_ATOMS 13 #define NUM_ATOMS 14
extern char **start_argv; extern char **start_argv;
extern Display *xkbdpy; extern Display *xkbdpy;

View File

@ -49,6 +49,7 @@ enum { _NET_SUPPORTED = 0,
_NET_WM_STATE, _NET_WM_STATE,
_NET_WM_WINDOW_TYPE, _NET_WM_WINDOW_TYPE,
_NET_WM_WINDOW_TYPE_DOCK, _NET_WM_WINDOW_TYPE_DOCK,
_NET_WM_WINDOW_TYPE_DIALOG,
_NET_WM_DESKTOP, _NET_WM_DESKTOP,
_NET_WM_STRUT_PARTIAL, _NET_WM_STRUT_PARTIAL,
WM_PROTOCOLS, WM_PROTOCOLS,

View File

@ -761,8 +761,8 @@ int handle_windowclass_change(void *data, xcb_connection_t *conn, uint8_t state,
return 1; return 1;
} }
if (strcmp(new_class, "tools") == 0) { if (strcmp(new_class, "tools") == 0 || strcmp(new_class, "Dialog") == 0) {
LOG("tool window, should we put it floating?\n"); LOG("tool/dialog window, should we put it floating?\n");
if (client->floating == FLOATING_AUTO_OFF) if (client->floating == FLOATING_AUTO_OFF)
toggle_floating_mode(conn, client, true); toggle_floating_mode(conn, client, true);
} }
@ -901,6 +901,11 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w
else else
xcb_get_wm_normal_hints_reply(conn, xcb_get_wm_normal_hints_unchecked(conn, client->child), &size_hints, NULL); xcb_get_wm_normal_hints_reply(conn, xcb_get_wm_normal_hints_unchecked(conn, client->child), &size_hints, NULL);
if ((size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)) {
LOG("min size set\n");
LOG("gots min_width = %d, min_height = %d\n", size_hints.min_width, size_hints.min_height);
}
/* If no aspect ratio was set or if it was invalid, we ignore the hints */ /* If no aspect ratio was set or if it was invalid, we ignore the hints */
if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) || if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) ||
(size_hints.min_aspect_num <= 0) || (size_hints.min_aspect_num <= 0) ||
@ -955,3 +960,42 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w
return 1; return 1;
} }
/*
* Handles the transient for hints set by a window, signalizing that this window is a popup window
* for some other window.
*
* See ICCCM 4.1.2.6 for more details
*
*/
int handle_transient_for(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
xcb_atom_t name, xcb_get_property_reply_t *reply) {
LOG("Transient hint!\n");
Client *client = table_get(&by_child, window);
if (client == NULL) {
LOG("No such client\n");
return 1;
}
xcb_window_t transient_for;
if (reply != NULL) {
if (!xcb_get_wm_transient_for_from_reply(&transient_for, reply)) {
LOG("Not transient for any window\n");
return 1;
}
} else {
if (!xcb_get_wm_transient_for_reply(conn, xcb_get_wm_transient_for_unchecked(conn, window),
&transient_for, NULL)) {
LOG("Not transient for any window\n");
return 1;
}
}
if (client->floating == FLOATING_AUTO_OFF) {
LOG("This is a popup window, putting into floating\n");
toggle_floating_mode(conn, client, true);
}
return 1;
}

View File

@ -275,6 +275,9 @@ int main(int argc, char *argv[], char *env[]) {
/* Watch _NET_WM_NAME (= title of the window in UTF-8) property */ /* Watch _NET_WM_NAME (= title of the window in UTF-8) property */
xcb_property_set_handler(&prophs, atoms[_NET_WM_NAME], 128, handle_windowname_change, NULL); xcb_property_set_handler(&prophs, atoms[_NET_WM_NAME], 128, handle_windowname_change, NULL);
/* Watch WM_TRANSIENT_FOR property (to which client this popup window belongs) */
xcb_property_set_handler(&prophs, WM_TRANSIENT_FOR, UINT_MAX, handle_transient_for, NULL);
/* Watch WM_NAME (= title of the window in compound text) property for legacy applications */ /* Watch WM_NAME (= title of the window in compound text) property for legacy applications */
xcb_watch_wm_name(&prophs, 128, handle_windowname_change_legacy, NULL); xcb_watch_wm_name(&prophs, 128, handle_windowname_change_legacy, NULL);

View File

@ -113,6 +113,7 @@ void manage_window(xcb_property_handlers_t *prophs, xcb_connection_t *conn, xcb_
xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_CLASS); xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_CLASS);
xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_NAME); xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_NAME);
xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_NORMAL_HINTS); xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_NORMAL_HINTS);
xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_TRANSIENT_FOR);
xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, atoms[_NET_WM_NAME]); xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, atoms[_NET_WM_NAME]);
free(geom); free(geom);
@ -169,6 +170,10 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
new->container = CUR_CELL; new->container = CUR_CELL;
new->workspace = new->container->workspace; new->workspace = new->container->workspace;
/* Minimum useful size for managed windows is 75x50 (primarily affects floating) */
width = max(width, 75);
height = max(height, 50);
new->frame = xcb_generate_id(conn); new->frame = xcb_generate_id(conn);
new->child = child; new->child = child;
new->rect.width = width; new->rect.width = width;
@ -243,16 +248,19 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
xcb_atom_t *atom; xcb_atom_t *atom;
xcb_get_property_reply_t *preply = xcb_get_property_reply(conn, wm_type_cookie, NULL); xcb_get_property_reply_t *preply = xcb_get_property_reply(conn, wm_type_cookie, NULL);
if (preply != NULL && preply->value_len > 0 && (atom = xcb_get_property_value(preply))) { if (preply != NULL && preply->value_len > 0 && (atom = xcb_get_property_value(preply))) {
for (int i = 0; i < xcb_get_property_value_length(preply); i++) { for (int i = 0; i < xcb_get_property_value_length(preply); i++)
if (atom[i] != atoms[_NET_WM_WINDOW_TYPE_DOCK]) if (atom[i] == atoms[_NET_WM_WINDOW_TYPE_DOCK]) {
continue; LOG("Window is a dock.\n");
LOG("Window is a dock.\n"); new->dock = true;
new->dock = true; new->titlebar_position = TITLEBAR_OFF;
new->titlebar_position = TITLEBAR_OFF; new->force_reconfigure = true;
new->force_reconfigure = true; new->container = NULL;
new->container = NULL; SLIST_INSERT_HEAD(&(c_ws->screen->dock_clients), new, dock_clients);
SLIST_INSERT_HEAD(&(c_ws->screen->dock_clients), new, dock_clients); } else if (atom[i] == atoms[_NET_WM_WINDOW_TYPE_DIALOG]) {
} /* Set the dialog window to automatically floating, will be used below */
new->floating = FLOATING_AUTO_ON;
LOG("dialog window, automatically floating\n");
}
} }
if (new->dock) { if (new->dock) {
@ -336,7 +344,7 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
} }
/* Insert into the currently active container, if its not a dock window */ /* Insert into the currently active container, if its not a dock window */
if (!new->dock) { if (!new->dock && new->floating <= FLOATING_USER_OFF) {
/* Insert after the old active client, if existing. If it does not exist, the /* Insert after the old active client, if existing. If it does not exist, the
container is empty and it does not matter, where we insert it */ container is empty and it does not matter, where we insert it */
if (old_focused != NULL && !old_focused->dock) if (old_focused != NULL && !old_focused->dock)
@ -358,6 +366,17 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
} }
} }
if (new->floating >= FLOATING_AUTO_ON) {
new->floating_rect.x = new->rect.x;
new->floating_rect.y = new->rect.y;
LOG("copying size from tiling (%d, %d) size (%d, %d)\n",
new->floating_rect.x, new->floating_rect.y,
new->floating_rect.width, new->floating_rect.height);
/* Make sure it is on top of the other windows */
xcb_raise_window(conn, new->frame);
}
new->initialized = true; new->initialized = true;
/* Check if the window already got the fullscreen hint set */ /* Check if the window already got the fullscreen hint set */