2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2010 Michael Stapelberg and contributors (see also: LICENSE)
10 #include <xcb/xcb_atom.h>
11 #include <xcb/randr.h>
13 #include <X11/XKBlib.h>
17 /* After mapping/unmapping windows, a notify event is generated. However, we don’t want it,
18 since it’d trigger an infinite loop of switching between the different windows when
19 changing workspaces */
20 static SLIST_HEAD(ignore_head, Ignore_Event) ignore_events;
22 static void add_ignore_event(const int sequence) {
23 struct Ignore_Event *event = smalloc(sizeof(struct Ignore_Event));
25 event->sequence = sequence;
26 event->added = time(NULL);
28 SLIST_INSERT_HEAD(&ignore_events, event, ignore_events);
32 * Checks if the given sequence is ignored and returns true if so.
35 static bool event_is_ignored(const int sequence) {
36 struct Ignore_Event *event;
37 time_t now = time(NULL);
38 for (event = SLIST_FIRST(&ignore_events); event != SLIST_END(&ignore_events);) {
39 if ((now - event->added) > 5) {
40 struct Ignore_Event *save = event;
41 event = SLIST_NEXT(event, ignore_events);
42 SLIST_REMOVE(&ignore_events, save, Ignore_Event, ignore_events);
44 } else event = SLIST_NEXT(event, ignore_events);
47 SLIST_FOREACH(event, &ignore_events, ignore_events) {
48 if (event->sequence == sequence) {
49 SLIST_REMOVE(&ignore_events, event, Ignore_Event, ignore_events);
59 * There was a key press. We compare this key code with our bindings table and pass
60 * the bound action to parse_command().
63 int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_t *event) {
64 DLOG("Keypress %d, state raw = %d\n", event->detail, event->state);
66 /* Remove the numlock bit, all other bits are modifiers we can bind to */
67 uint16_t state_filtered = event->state & ~(xcb_numlock_mask | XCB_MOD_MASK_LOCK);
68 DLOG("(removed numlock, state = %d)\n", state_filtered);
69 /* Only use the lower 8 bits of the state (modifier masks) so that mouse
70 * button masks are filtered out */
71 state_filtered &= 0xFF;
72 DLOG("(removed upper 8 bits, state = %d)\n", state_filtered);
74 if (xkb_current_group == XkbGroup2Index)
75 state_filtered |= BIND_MODE_SWITCH;
77 DLOG("(checked mode_switch, state %d)\n", state_filtered);
79 /* Find the binding */
80 Binding *bind = get_binding(state_filtered, event->detail);
82 /* No match? Then the user has Mode_switch enabled but does not have a
83 * specific keybinding. Fall back to the default keybindings (without
84 * Mode_switch). Makes it much more convenient for users of a hybrid
85 * layout (like us, ru). */
87 state_filtered &= ~(BIND_MODE_SWITCH);
88 DLOG("no match, new state_filtered = %d\n", state_filtered);
89 if ((bind = get_binding(state_filtered, event->detail)) == NULL) {
90 ELOG("Could not lookup key binding (modifiers %d, keycode %d)\n",
91 state_filtered, event->detail);
96 parse_command(bind->command);
103 * Called with coordinates of an enter_notify event or motion_notify event
104 * to check if the user crossed virtual screen boundaries and adjust the
105 * current workspace, if so.
108 static void check_crossing_screen_boundary(uint32_t x, uint32_t y) {
111 if ((output = get_output_containing(x, y)) == NULL) {
112 ELOG("ERROR: No such screen\n");
115 if (output == c_ws->output)
118 c_ws->current_row = current_row;
119 c_ws->current_col = current_col;
120 c_ws = output->current_workspace;
121 current_row = c_ws->current_row;
122 current_col = c_ws->current_col;
123 DLOG("We're now on output %p\n", output);
125 /* While usually this function is only called when the user switches
126 * to a different output using his mouse (and thus the output is
127 * empty), it may be that the following race condition occurs:
128 * 1) the user actives a new output (say VGA1).
129 * 2) the cursor is sent to the first pixel of the new VGA1, thus
130 * generating an enter_notify for the screen (the enter_notify
131 * is not yet received by i3).
132 * 3) i3 requeries screen configuration and maps a workspace onto the
134 * 4) the enter_notify event arrives and c_ws is set to the new
135 * workspace but the existing windows on the new workspace are not
138 * Therefore, we re-set the focus here to be sure it’s correct. */
139 Client *first_client = SLIST_FIRST(&(c_ws->focus_stack));
140 if (first_client != NULL)
141 set_focus(global_conn, first_client, true);
145 * When the user moves the mouse pointer onto a window, this callback gets called.
148 int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_notify_event_t *event) {
149 DLOG("enter_notify for %08x, mode = %d, detail %d, serial %d\n", event->event, event->mode, event->detail, event->sequence);
150 if (event->mode != XCB_NOTIFY_MODE_NORMAL) {
151 DLOG("This was not a normal notify, ignoring\n");
154 /* Some events are not interesting, because they were not generated actively by the
155 user, but by reconfiguration of windows */
156 if (event_is_ignored(event->sequence))
159 /* This was either a focus for a client’s parent (= titlebar)… */
160 Client *client = table_get(&by_parent, event->event);
161 /* …or the client itself */
163 client = table_get(&by_child, event->event);
165 /* Check for stack windows */
166 if (client == NULL) {
167 struct Stack_Window *stack_win;
168 SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
169 if (stack_win->window == event->event) {
170 client = stack_win->container->currently_focused;
176 /* If not, then the user moved his cursor to the root window. In that case, we adjust c_ws */
177 if (client == NULL) {
178 DLOG("Getting screen at %d x %d\n", event->root_x, event->root_y);
179 check_crossing_screen_boundary(event->root_x, event->root_y);
183 /* Do plausibility checks: This event may be useless for us if it occurs on a window
184 which is in a stacked container but not the focused one */
185 if (client->container != NULL &&
186 client->container->mode == MODE_STACK &&
187 client->container->currently_focused != client) {
188 DLOG("Plausibility check says: no\n");
192 if (client->workspace != c_ws && client->workspace->output == c_ws->output) {
193 /* This can happen when a client gets assigned to a different workspace than
194 * the current one (see src/mainx.c:reparent_window). Shortly after it was created,
195 * an enter_notify will follow. */
196 DLOG("enter_notify for a client on a different workspace but the same screen, ignoring\n");
200 if (!config.disable_focus_follows_mouse)
201 set_focus(conn, client, false);
207 * When the user moves the mouse but does not change the active window
208 * (e.g. when having no windows opened but moving mouse on the root screen
209 * and crossing virtual screen boundaries), this callback gets called.
212 int handle_motion_notify(void *ignored, xcb_connection_t *conn, xcb_motion_notify_event_t *event) {
213 /* Skip events where the pointer was over a child window, we are only
214 * interested in events on the root window. */
215 if (event->child != 0)
218 check_crossing_screen_boundary(event->root_x, event->root_y);
224 * Called when the keyboard mapping changes (for example by using Xmodmap),
225 * we need to update our key bindings then (re-translate symbols).
228 int handle_mapping_notify(void *ignored, xcb_connection_t *conn, xcb_mapping_notify_event_t *event) {
229 if (event->request != XCB_MAPPING_KEYBOARD &&
230 event->request != XCB_MAPPING_MODIFIER)
233 DLOG("Received mapping_notify for keyboard or modifier mapping, re-grabbing keys\n");
234 xcb_refresh_keyboard_mapping(keysyms, event);
236 xcb_get_numlock_mask(conn);
238 ungrab_all_keys(conn);
240 grab_all_keys(conn, false);
246 * A new window appeared on the screen (=was mapped), so let’s manage it.
249 int handle_map_request(void *prophs, xcb_connection_t *conn, xcb_map_request_event_t *event) {
250 xcb_get_window_attributes_cookie_t cookie;
252 cookie = xcb_get_window_attributes_unchecked(conn, event->window);
254 DLOG("window = 0x%08x, serial is %d.\n", event->window, event->sequence);
255 add_ignore_event(event->sequence);
257 manage_window(prophs, conn, event->window, cookie, false);
262 * Configure requests are received when the application wants to resize windows on their own.
264 * We generate a synthethic configure notify event to signalize the client its "new" position.
267 int handle_configure_request(void *prophs, xcb_connection_t *conn, xcb_configure_request_event_t *event) {
268 DLOG("window 0x%08x wants to be at %dx%d with %dx%d\n",
269 event->window, event->x, event->y, event->width, event->height);
271 Client *client = table_get(&by_child, event->window);
272 if (client == NULL) {
276 #define COPY_MASK_MEMBER(mask_member, event_member) do { \
277 if (event->value_mask & mask_member) { \
278 mask |= mask_member; \
279 values[c++] = event->event_member; \
283 COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_X, x);
284 COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_Y, y);
285 COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_WIDTH, width);
286 COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_HEIGHT, height);
287 COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_BORDER_WIDTH, border_width);
288 COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_SIBLING, sibling);
289 COPY_MASK_MEMBER(XCB_CONFIG_WINDOW_STACK_MODE, stack_mode);
291 xcb_configure_window(conn, event->window, mask, values);
297 if (client->fullscreen) {
298 DLOG("Client is in fullscreen mode\n");
300 Rect child_rect = client->workspace->rect;
301 child_rect.x = child_rect.y = 0;
302 fake_configure_notify(conn, child_rect, client->child);
307 /* Floating clients can be reconfigured */
308 if (client_is_floating(client)) {
309 i3Font *font = load_font(conn, config.font);
310 int mode = (client->container != NULL ? client->container->mode : MODE_DEFAULT);
311 /* TODO: refactor this code. we need a function to translate
312 * coordinates of child_rect/rect. */
314 if (event->value_mask & XCB_CONFIG_WINDOW_X) {
315 if (mode == MODE_STACK || mode == MODE_TABBED) {
316 client->rect.x = event->x - 2;
318 if (client->titlebar_position == TITLEBAR_OFF && client->borderless)
319 client->rect.x = event->x;
320 else if (client->titlebar_position == TITLEBAR_OFF && !client->borderless)
321 client->rect.x = event->x - 1;
322 else client->rect.x = event->x - 2;
325 if (event->value_mask & XCB_CONFIG_WINDOW_Y) {
326 if (mode == MODE_STACK || mode == MODE_TABBED) {
327 client->rect.y = event->y - 2;
329 if (client->titlebar_position == TITLEBAR_OFF && client->borderless)
330 client->rect.y = event->y;
331 else if (client->titlebar_position == TITLEBAR_OFF && !client->borderless)
332 client->rect.y = event->y - 1;
333 else client->rect.y = event->y - font->height - 2 - 2;
336 if (event->value_mask & XCB_CONFIG_WINDOW_WIDTH) {
337 if (mode == MODE_STACK || mode == MODE_TABBED) {
338 client->rect.width = event->width + 2 + 2;
340 if (client->titlebar_position == TITLEBAR_OFF && client->borderless)
341 client->rect.width = event->width;
342 else if (client->titlebar_position == TITLEBAR_OFF && !client->borderless)
343 client->rect.width = event->width + (1 + 1);
344 else client->rect.width = event->width + (2 + 2);
347 if (event->value_mask & XCB_CONFIG_WINDOW_HEIGHT) {
348 if (mode == MODE_STACK || mode == MODE_TABBED) {
349 client->rect.height = event->height + 2;
351 if (client->titlebar_position == TITLEBAR_OFF && client->borderless)
352 client->rect.height = event->height;
353 else if (client->titlebar_position == TITLEBAR_OFF && !client->borderless)
354 client->rect.height = event->height + (1 + 1);
355 else client->rect.height = event->height + (font->height + 2 + 2) + 2;
359 DLOG("Accepted new position/size for floating client: (%d, %d) size %d x %d\n",
360 client->rect.x, client->rect.y, client->rect.width, client->rect.height);
362 /* Push the new position/size to X11 */
363 reposition_client(conn, client);
364 resize_client(conn, client);
370 /* Dock clients can be reconfigured in their height */
372 DLOG("Reconfiguring height of this dock client\n");
374 if (!(event->value_mask & XCB_CONFIG_WINDOW_HEIGHT)) {
375 DLOG("Ignoring configure request, no height given\n");
379 client->desired_height = event->height;
380 render_workspace(conn, c_ws->output, c_ws);
386 if (client->fullscreen) {
387 DLOG("Client is in fullscreen mode\n");
389 Rect child_rect = client->container->workspace->rect;
390 child_rect.x = child_rect.y = 0;
391 fake_configure_notify(conn, child_rect, client->child);
396 fake_absolute_configure_notify(conn, client);
402 * Configuration notifies are only handled because we need to set up ignore for
403 * the following enter notify events.
406 int handle_configure_event(void *prophs, xcb_connection_t *conn, xcb_configure_notify_event_t *event) {
407 /* We ignore this sequence twice because events for child and frame should be ignored */
408 add_ignore_event(event->sequence);
409 add_ignore_event(event->sequence);
415 * Gets triggered upon a RandR screen change event, that is when the user
416 * changes the screen configuration in any way (mode, position, …)
419 int handle_screen_change(void *prophs, xcb_connection_t *conn,
420 xcb_generic_event_t *e) {
421 DLOG("RandR screen change\n");
423 randr_query_outputs(conn);
425 ipc_send_event("output", I3_IPC_EVENT_OUTPUT, "{\"change\":\"unspecified\"}");
431 * Our window decorations were unmapped. That means, the window will be killed now,
432 * so we better clean up before.
435 int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_notify_event_t *event) {
436 xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
438 add_ignore_event(event->sequence);
440 Client *client = table_get(&by_child, event->window);
441 /* First, we need to check if the client is awaiting an unmap-request which
442 was generated by us reparenting the window. In that case, we just ignore it. */
443 if (client != NULL && client->awaiting_useless_unmap) {
444 client->awaiting_useless_unmap = false;
448 DLOG("event->window = %08x, event->event = %08x\n", event->window, event->event);
449 DLOG("UnmapNotify for 0x%08x (received from 0x%08x)\n", event->window, event->event);
450 if (client == NULL) {
451 DLOG("not a managed window. Ignoring.\n");
453 /* This was most likely the destroyed frame of a client which is
454 * currently being unmapped, so we add this sequence (again!) to
455 * the ignore list (enter_notify events will get sent for both,
456 * the child and its frame). */
457 add_ignore_event(event->sequence);
462 client = table_remove(&by_child, event->window);
464 /* If this was the fullscreen client, we need to unset it */
465 if (client->fullscreen)
466 client->workspace->fullscreen_client = NULL;
468 /* Clients without a container are either floating or dock windows */
469 if (client->container != NULL) {
470 Container *con = client->container;
472 /* Remove the client from the list of clients */
473 client_remove_from_container(conn, client, con, true);
475 /* Set focus to the last focused client in this container */
476 con->currently_focused = get_last_focused_client(conn, con, NULL);
478 /* Only if this is the active container, we need to really change focus */
479 if ((con->currently_focused != NULL) && ((con == CUR_CELL) || client->fullscreen))
480 set_focus(conn, con->currently_focused, true);
481 } else if (client_is_floating(client)) {
482 DLOG("Removing from floating clients\n");
483 TAILQ_REMOVE(&(client->workspace->floating_clients), client, floating_clients);
484 SLIST_REMOVE(&(client->workspace->focus_stack), client, Client, focus_clients);
488 DLOG("Removing from dock clients\n");
489 SLIST_REMOVE(&(client->workspace->output->dock_clients), client, Client, dock_clients);
492 DLOG("child of 0x%08x.\n", client->frame);
493 xcb_reparent_window(conn, client->child, root, 0, 0);
495 client_unmap(conn, client);
497 xcb_destroy_window(conn, client->frame);
499 table_remove(&by_parent, client->frame);
501 if (client->container != NULL) {
502 Workspace *workspace = client->container->workspace;
503 cleanup_table(conn, workspace);
504 fix_colrowspan(conn, workspace);
507 /* Let’s see how many clients there are left on the workspace to delete it if it’s empty */
508 bool workspace_empty = SLIST_EMPTY(&(client->workspace->focus_stack));
509 bool workspace_focused = (c_ws == client->workspace);
510 Client *to_focus = (!workspace_empty ? SLIST_FIRST(&(client->workspace->focus_stack)) : NULL);
512 /* If this workspace is currently visible, we don’t delete it */
513 if (workspace_is_visible(client->workspace))
514 workspace_empty = false;
516 if (workspace_empty) {
517 client->workspace->output = NULL;
518 ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"empty\"}");
521 /* Remove the urgency flag if set */
522 client->urgent = false;
523 workspace_update_urgent_flag(client->workspace);
525 FREE(client->window_class_instance);
526 FREE(client->window_class_class);
532 /* Ensure the focus is set to the next client in the focus stack or to
533 * the screen itself (if we do not focus the screen, it can happen that
534 * the focus is "nowhere" and thus keypress events will not be received
535 * by i3, thus the user cannot use any hotkeys). */
536 if (workspace_focused) {
537 if (to_focus != NULL)
538 set_focus(conn, to_focus, true);
540 DLOG("Restoring focus to root screen\n");
541 xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, root, XCB_CURRENT_TIME);
550 * A destroy notify event is sent when the window is not unmapped, but
551 * immediately destroyed (for example when starting a window and immediately
552 * killing the program which started it).
554 * We just pass on the event to the unmap notify handler (by copying the
555 * important fields in the event data structure).
558 int handle_destroy_notify_event(void *data, xcb_connection_t *conn, xcb_destroy_notify_event_t *event) {
559 DLOG("destroy notify for 0x%08x, 0x%08x\n", event->event, event->window);
561 xcb_unmap_notify_event_t unmap;
562 unmap.sequence = event->sequence;
563 unmap.event = event->event;
564 unmap.window = event->window;
566 return handle_unmap_notify_event(NULL, conn, &unmap);
570 * Called when a window changes its title
573 int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state,
574 xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
576 if ((con = con_by_window_id(window)) == NULL || con->window == NULL)
579 window_update_name(con->window, prop);
581 x_push_changes(croot);
587 * Handles legacy window name updates (WM_NAME), see also src/window.c,
588 * window_update_name_legacy().
591 int handle_windowname_change_legacy(void *data, xcb_connection_t *conn, uint8_t state,
592 xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
594 if ((con = con_by_window_id(window)) == NULL || con->window == NULL)
597 window_update_name_legacy(con->window, prop);
599 x_push_changes(croot);
605 * Updates the client’s WM_CLASS property
608 int handle_windowclass_change(void *data, xcb_connection_t *conn, uint8_t state,
609 xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
611 if ((con = con_by_window_id(window)) == NULL || con->window == NULL)
614 window_update_class(con->window, prop);
621 * Expose event means we should redraw our windows (= title bar)
624 int handle_expose_event(void *data, xcb_connection_t *conn, xcb_expose_event_t *event) {
625 /* event->count is the number of minimum remaining expose events for this window, so we
626 skip all events but the last one */
627 if (event->count != 0)
629 DLOG("window = %08x\n", event->window);
631 Client *client = table_get(&by_parent, event->window);
632 if (client == NULL) {
633 /* There was no client in the table, so this is probably an expose event for
634 one of our stack_windows. */
635 struct Stack_Window *stack_win;
636 SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
637 if (stack_win->window == event->window) {
638 render_container(conn, stack_win->container);
642 /* …or one of the bars? */
644 TAILQ_FOREACH(output, &outputs, outputs)
645 if (output->bar == event->window)
653 if (container_mode(client->container, true) == MODE_DEFAULT)
654 decorate_window(conn, client, client->frame, client->titlegc, 0, 0);
656 uint32_t background_color;
658 background_color = config.client.urgent.background;
659 /* Distinguish if the window is currently focused… */
660 else if (CUR_CELL != NULL && CUR_CELL->currently_focused == client)
661 background_color = config.client.focused.background;
662 /* …or if it is the focused window in a not focused container */
663 else background_color = config.client.focused_inactive.background;
665 /* Set foreground color to current focused color, line width to 2 */
666 uint32_t values[] = {background_color, 2};
667 xcb_change_gc(conn, client->titlegc, XCB_GC_FOREGROUND | XCB_GC_LINE_WIDTH, values);
669 /* Draw the border, the ±1 is for line width = 2 */
670 xcb_point_t points[] = {{1, 0}, /* left upper edge */
671 {1, client->rect.height-1}, /* left bottom edge */
672 {client->rect.width-1, client->rect.height-1}, /* right bottom edge */
673 {client->rect.width-1, 0}}; /* right upper edge */
674 xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, client->frame, client->titlegc, 4, points);
676 /* Draw a black background */
677 xcb_change_gc_single(conn, client->titlegc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
678 if (client->titlebar_position == TITLEBAR_OFF && !client->borderless) {
679 xcb_rectangle_t crect = {1, 0, client->rect.width - (1 + 1), client->rect.height - 1};
680 xcb_poly_fill_rectangle(conn, client->frame, client->titlegc, 1, &crect);
682 xcb_rectangle_t crect = {2, 0, client->rect.width - (2 + 2), client->rect.height - 2};
683 xcb_poly_fill_rectangle(conn, client->frame, client->titlegc, 1, &crect);
691 * Handle client messages (EWMH)
694 int handle_client_message(void *data, xcb_connection_t *conn, xcb_client_message_event_t *event) {
695 if (event->type == atoms[_NET_WM_STATE]) {
696 if (event->format != 32 || event->data.data32[1] != atoms[_NET_WM_STATE_FULLSCREEN])
699 Client *client = table_get(&by_child, event->window);
703 /* Check if the fullscreen state should be toggled */
704 if ((client->fullscreen &&
705 (event->data.data32[0] == _NET_WM_STATE_REMOVE ||
706 event->data.data32[0] == _NET_WM_STATE_TOGGLE)) ||
707 (!client->fullscreen &&
708 (event->data.data32[0] == _NET_WM_STATE_ADD ||
709 event->data.data32[0] == _NET_WM_STATE_TOGGLE)))
710 client_toggle_fullscreen(conn, client);
712 ELOG("unhandled clientmessage\n");
719 int handle_window_type(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
720 xcb_atom_t atom, xcb_get_property_reply_t *property) {
721 /* TODO: Implement this one. To do this, implement a little test program which sleep(1)s
722 before changing this property. */
723 ELOG("_NET_WM_WINDOW_TYPE changed, this is not yet implemented.\n");
728 * Handles the size hints set by a window, but currently only the part necessary for displaying
729 * clients proportionally inside their frames (mplayer for example)
731 * See ICCCM 4.1.2.3 for more details
734 int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
735 xcb_atom_t name, xcb_get_property_reply_t *reply) {
736 Client *client = table_get(&by_child, window);
737 if (client == NULL) {
738 DLOG("Received WM_SIZE_HINTS for unknown client\n");
741 xcb_size_hints_t size_hints;
745 /* If the hints were already in this event, use them, if not, request them */
747 xcb_get_wm_size_hints_from_reply(&size_hints, reply);
749 xcb_get_wm_normal_hints_reply(conn, xcb_get_wm_normal_hints_unchecked(conn, client->child), &size_hints, NULL);
751 if ((size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)) {
752 // TODO: Minimum size is not yet implemented
753 DLOG("Minimum size: %d (width) x %d (height)\n", size_hints.min_width, size_hints.min_height);
756 bool changed = false;
757 if ((size_hints.flags & XCB_SIZE_HINT_P_RESIZE_INC)) {
758 if (size_hints.width_inc > 0 && size_hints.width_inc < 0xFFFF)
759 if (client->width_increment != size_hints.width_inc) {
760 client->width_increment = size_hints.width_inc;
763 if (size_hints.height_inc > 0 && size_hints.height_inc < 0xFFFF)
764 if (client->height_increment != size_hints.height_inc) {
765 client->height_increment = size_hints.height_inc;
770 DLOG("resize increments changed\n");
773 int base_width = 0, base_height = 0;
775 /* base_width/height are the desired size of the window.
776 We check if either the program-specified size or the program-specified
777 min-size is available */
778 if (size_hints.flags & XCB_SIZE_HINT_BASE_SIZE) {
779 base_width = size_hints.base_width;
780 base_height = size_hints.base_height;
781 } else if (size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE) {
782 /* TODO: is this right? icccm says not */
783 base_width = size_hints.min_width;
784 base_height = size_hints.min_height;
787 if (base_width != client->base_width ||
788 base_height != client->base_height) {
789 client->base_width = base_width;
790 client->base_height = base_height;
791 DLOG("client's base_height changed to %d\n", base_height);
792 DLOG("client's base_width changed to %d\n", base_width);
797 if (client->fullscreen)
798 DLOG("Not resizing client, it is in fullscreen mode\n");
800 resize_client(conn, client);
805 /* If no aspect ratio was set or if it was invalid, we ignore the hints */
806 if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) ||
807 (size_hints.min_aspect_num <= 0) ||
808 (size_hints.min_aspect_den <= 0)) {
812 double width = client->rect.width - base_width;
813 double height = client->rect.height - base_height;
814 /* Convert numerator/denominator to a double */
815 double min_aspect = (double)size_hints.min_aspect_num / size_hints.min_aspect_den;
816 double max_aspect = (double)size_hints.max_aspect_num / size_hints.min_aspect_den;
818 DLOG("Aspect ratio set: minimum %f, maximum %f\n", min_aspect, max_aspect);
819 DLOG("width = %f, height = %f\n", width, height);
821 /* Sanity checks, this is user-input, in a way */
822 if (max_aspect <= 0 || min_aspect <= 0 || height == 0 || (width / height) <= 0)
825 /* Check if we need to set proportional_* variables using the correct ratio */
826 if ((width / height) < min_aspect) {
827 client->proportional_width = width;
828 client->proportional_height = width / min_aspect;
829 } else if ((width / height) > max_aspect) {
830 client->proportional_width = width;
831 client->proportional_height = width / max_aspect;
834 client->force_reconfigure = true;
836 if (client->container != NULL) {
837 render_container(conn, client->container);
845 * Handles the WM_HINTS property for extracting the urgency state of the window.
848 int handle_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
849 xcb_atom_t name, xcb_get_property_reply_t *reply) {
850 Client *client = table_get(&by_child, window);
851 if (client == NULL) {
852 DLOG("Received WM_HINTS for unknown client\n");
855 xcb_wm_hints_t hints;
858 if (!xcb_get_wm_hints_from_reply(&hints, reply))
861 if (!xcb_get_wm_hints_reply(conn, xcb_get_wm_hints_unchecked(conn, client->child), &hints, NULL))
865 Client *last_focused = SLIST_FIRST(&(c_ws->focus_stack));
866 if (!client->urgent && client == last_focused) {
867 DLOG("Ignoring urgency flag for current client\n");
871 /* Update the flag on the client directly */
872 client->urgent = (xcb_wm_hints_get_urgency(&hints) != 0);
874 LOG("Urgency flag changed to %d\n", client->urgent);
876 workspace_update_urgent_flag(client->workspace);
877 redecorate_window(conn, client);
879 /* If the workspace this client is on is not visible, we need to redraw
880 * the workspace bar */
881 if (!workspace_is_visible(client->workspace)) {
882 Output *output = client->workspace->output;
883 render_workspace(conn, output, output->current_workspace);
891 * Handles the transient for hints set by a window, signalizing that this window is a popup window
892 * for some other window.
894 * See ICCCM 4.1.2.6 for more details
897 int handle_transient_for(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
898 xcb_atom_t name, xcb_get_property_reply_t *reply) {
899 Client *client = table_get(&by_child, window);
900 if (client == NULL) {
901 DLOG("No such client\n");
905 xcb_window_t transient_for;
908 if (!xcb_get_wm_transient_for_from_reply(&transient_for, reply))
911 if (!xcb_get_wm_transient_for_reply(conn, xcb_get_wm_transient_for_unchecked(conn, window),
912 &transient_for, NULL))
916 if (client->floating == FLOATING_AUTO_OFF) {
917 DLOG("This is a popup window, putting into floating\n");
918 toggle_floating_mode(conn, client, true);
925 * Handles changes of the WM_CLIENT_LEADER atom which specifies if this is a
926 * toolwindow (or similar) and to which window it belongs (logical parent).
929 int handle_clientleader_change(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
930 xcb_atom_t name, xcb_get_property_reply_t *prop) {
932 prop = xcb_get_property_reply(conn, xcb_get_property_unchecked(conn,
933 false, window, WM_CLIENT_LEADER, WINDOW, 0, 32), NULL);
938 Client *client = table_get(&by_child, window);
942 xcb_window_t *leader = xcb_get_property_value(prop);
946 DLOG("Client leader changed to %08x\n", *leader);
948 client->leader = *leader;