4 * i3 - an improved dynamic tiling window manager
6 * © 2009 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
18 #include <xcb/xcb_atom.h>
19 #include <xcb/xcb_icccm.h>
21 #include <X11/XKBlib.h>
36 /* After mapping/unmapping windows, a notify event is generated. However, we don’t want it,
37 since it’d trigger an infinite loop of switching between the different windows when
38 changing workspaces */
39 static SLIST_HEAD(ignore_head, Ignore_Event) ignore_events;
41 static void add_ignore_event(const int sequence) {
42 struct Ignore_Event *event = smalloc(sizeof(struct Ignore_Event));
44 event->sequence = sequence;
45 event->added = time(NULL);
47 LOG("Adding sequence %d to ignorelist\n", sequence);
49 SLIST_INSERT_HEAD(&ignore_events, event, ignore_events);
53 * Checks if the given sequence is ignored and returns true if so.
56 static bool event_is_ignored(const int sequence) {
57 struct Ignore_Event *event;
58 time_t now = time(NULL);
59 for (event = SLIST_FIRST(&ignore_events); event != SLIST_END(&ignore_events);) {
60 if ((now - event->added) > 5) {
61 struct Ignore_Event *save = event;
62 event = SLIST_NEXT(event, ignore_events);
63 SLIST_REMOVE(&ignore_events, save, Ignore_Event, ignore_events);
65 } else event = SLIST_NEXT(event, ignore_events);
68 SLIST_FOREACH(event, &ignore_events, ignore_events) {
69 if (event->sequence == sequence) {
70 LOG("Ignoring event (sequence %d)\n", sequence);
71 SLIST_REMOVE(&ignore_events, event, Ignore_Event, ignore_events);
81 * Due to bindings like Mode_switch + <a>, we need to bind some keys in XCB_GRAB_MODE_SYNC.
82 * Therefore, we just replay all key presses.
85 int handle_key_release(void *ignored, xcb_connection_t *conn, xcb_key_release_event_t *event) {
86 LOG("got key release, just passing\n");
87 xcb_allow_events(conn, XCB_ALLOW_REPLAY_KEYBOARD, event->time);
93 * There was a key press. We compare this key code with our bindings table and pass
94 * the bound action to parse_command().
97 int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_t *event) {
98 LOG("Keypress %d\n", event->detail);
100 /* We need to get the keysym group (There are group 1 to group 4, each holding
101 two keysyms (without shift and with shift) using Xkb because X fails to
102 provide them reliably (it works in Xephyr, it does not in real X) */
104 if (XkbGetState(xkbdpy, XkbUseCoreKbd, &state) == Success && (state.group+1) == 2)
107 LOG("state %d\n", event->state);
109 /* Remove the numlock bit, all other bits are modifiers we can bind to */
110 uint16_t state_filtered = event->state & ~(xcb_numlock_mask | XCB_MOD_MASK_LOCK);
112 /* Find the binding */
114 TAILQ_FOREACH(bind, &bindings, bindings)
115 if (bind->keycode == event->detail && bind->mods == state_filtered)
118 /* No match? Then it was an actively grabbed key, that is with Mode_switch, and
119 the user did not press Mode_switch, so just pass it… */
120 if (bind == TAILQ_END(&bindings)) {
121 xcb_allow_events(conn, ReplayKeyboard, event->time);
126 parse_command(conn, bind->command);
127 if (event->state & 0x2) {
128 LOG("Mode_switch -> allow_events(SyncKeyboard)\n");
129 xcb_allow_events(conn, SyncKeyboard, event->time);
137 * When the user moves the mouse pointer onto a window, this callback gets called.
140 int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_notify_event_t *event) {
141 LOG("enter_notify for %08x, mode = %d, detail %d, serial %d\n", event->event, event->mode, event->detail, event->sequence);
142 if (event->mode != XCB_NOTIFY_MODE_NORMAL) {
143 LOG("This was not a normal notify, ignoring\n");
146 /* Some events are not interesting, because they were not generated actively by the
147 user, but be reconfiguration of windows */
148 if (event_is_ignored(event->sequence))
151 /* This was either a focus for a client’s parent (= titlebar)… */
152 Client *client = table_get(&by_parent, event->event);
153 /* …or the client itself */
155 client = table_get(&by_child, event->event);
157 /* Check for stack windows */
158 if (client == NULL) {
159 struct Stack_Window *stack_win;
160 SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
161 if (stack_win->window == event->event) {
162 client = stack_win->container->currently_focused;
168 /* If not, then the user moved his cursor to the root window. In that case, we adjust c_ws */
169 if (client == NULL) {
170 LOG("Getting screen at %d x %d\n", event->root_x, event->root_y);
171 i3Screen *screen = get_screen_containing(event->root_x, event->root_y);
172 if (screen == NULL) {
173 LOG("ERROR: No such screen\n");
176 c_ws->current_row = current_row;
177 c_ws->current_col = current_col;
178 c_ws = &workspaces[screen->current_workspace];
179 current_row = c_ws->current_row;
180 current_col = c_ws->current_col;
181 LOG("We're now on virtual screen number %d\n", screen->num);
185 /* Do plausibility checks: This event may be useless for us if it occurs on a window
186 which is in a stacked container but not the focused one */
187 if (client->container != NULL &&
188 client->container->mode == MODE_STACK &&
189 client->container->currently_focused != client) {
190 LOG("Plausibility check says: no\n");
194 set_focus(conn, client, false);
200 * Checks if the button press was on a stack window, handles focus setting and returns true
201 * if so, or false otherwise.
204 static bool button_press_stackwin(xcb_connection_t *conn, xcb_button_press_event_t *event) {
205 struct Stack_Window *stack_win;
206 SLIST_FOREACH(stack_win, &stack_wins, stack_windows) {
207 if (stack_win->window != event->event)
210 /* A stack window was clicked, we check if it was button4 or button5
211 which are scroll up / scroll down. */
212 if (event->detail == XCB_BUTTON_INDEX_4 || event->detail == XCB_BUTTON_INDEX_5) {
213 direction_t direction = (event->detail == XCB_BUTTON_INDEX_4 ? D_UP : D_DOWN);
214 focus_window_in_container(conn, CUR_CELL, direction);
218 /* It was no scrolling, so we calculate the destination client by
219 dividing the Y position of the event through the height of a window
220 decoration and then set the focus to this client. */
221 i3Font *font = load_font(conn, config.font);
222 int decoration_height = (font->height + 2 + 2);
223 int destination = (event->event_y / decoration_height),
227 LOG("Click on stack_win for client %d\n", destination);
228 CIRCLEQ_FOREACH(client, &(stack_win->container->clients), clients)
229 if (c++ == destination) {
230 set_focus(conn, client, true);
241 * Checks if the button press was on a bar, switches to the workspace and returns true
242 * if so, or false otherwise.
245 static bool button_press_bar(xcb_connection_t *conn, xcb_button_press_event_t *event) {
247 TAILQ_FOREACH(screen, virtual_screens, screens) {
248 if (screen->bar != event->event)
251 LOG("Click on a bar\n");
253 /* Check if the button was one of button4 or button5 (scroll up / scroll down) */
254 if (event->detail == XCB_BUTTON_INDEX_4 || event->detail == XCB_BUTTON_INDEX_5) {
255 int add = (event->detail == XCB_BUTTON_INDEX_4 ? -1 : 1);
256 for (int i = c_ws->num + add; (i >= 0) && (i < 10); i += add)
257 if (workspaces[i].screen == screen) {
258 show_workspace(conn, i+1);
263 i3Font *font = load_font(conn, config.font);
264 int workspace = event->event_x / (font->height + 6),
266 /* Because workspaces can be on different screens, we need to loop
267 through all of them and decide to count it based on its ->screen */
268 for (int i = 0; i < 10; i++)
269 if ((workspaces[i].screen == screen) && (c++ == workspace)) {
270 show_workspace(conn, i+1);
279 int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_event_t *event) {
280 LOG("button press!\n");
281 /* This was either a focus for a client’s parent (= titlebar)… */
282 Client *client = table_get(&by_child, event->event);
283 bool border_click = false;
284 if (client == NULL) {
285 client = table_get(&by_parent, event->event);
288 if (client == NULL) {
289 /* The client was neither on a client’s titlebar nor on a client itself, maybe on a stack_window? */
290 if (button_press_stackwin(conn, event))
294 if (button_press_bar(conn, event))
297 LOG("Could not handle this button press\n");
301 /* Set focus in any case */
302 set_focus(conn, client, true);
304 /* Let’s see if this was on the borders (= resize). If not, we’re done */
305 LOG("press button on x=%d, y=%d\n", event->event_x, event->event_y);
306 resize_orientation_t orientation = O_VERTICAL;
307 Container *con = client->container,
312 LOG("dock. done.\n");
313 xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time);
318 LOG("event->event_x = %d, client->rect.width = %d\n", event->event_x, client->rect.width);
321 LOG("client. done.\n");
322 xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time);
327 /* Don’t handle events inside the titlebar, only borders are interesting */
328 i3Font *font = load_font(conn, config.font);
329 if (event->event_y >= 2 && event->event_y <= (font->height + 2 + 2)) {
330 LOG("click on titlebar\n");
334 if (event->event_y < 2) {
335 /* This was a press on the top border */
338 first = con->workspace->table[con->col][con->row-1];
340 orientation = O_HORIZONTAL;
341 } else if (event->event_y >= (client->rect.height - 2)) {
343 if (con->row == (con->workspace->rows-1))
346 second = con->workspace->table[con->col][con->row+1];
347 orientation = O_HORIZONTAL;
348 } else if (event->event_x <= 2) {
352 first = con->workspace->table[con->col-1][con->row];
354 } else if (event->event_x > 2) {
356 if (con->col == (con->workspace->cols-1))
359 second = con->workspace->table[con->col+1][con->row];
362 return resize_graphical_handler(conn, first, second, orientation, event);
366 * A new window appeared on the screen (=was mapped), so let’s manage it.
369 int handle_map_request(void *prophs, xcb_connection_t *conn, xcb_map_request_event_t *event) {
370 xcb_get_window_attributes_cookie_t cookie;
371 xcb_get_window_attributes_reply_t *reply;
373 cookie = xcb_get_window_attributes_unchecked(conn, event->window);
375 if ((reply = xcb_get_window_attributes_reply(conn, cookie, NULL)) == NULL) {
376 LOG("Could not get window attributes\n");
380 window_attributes_t wa = { TAG_VALUE };
381 LOG("override_redirect = %d\n", reply->override_redirect);
382 wa.u.override_redirect = reply->override_redirect;
383 LOG("window = 0x%08x, serial is %d.\n", event->window, event->sequence);
384 add_ignore_event(event->sequence);
386 manage_window(prophs, conn, event->window, wa);
391 * Configure requests are received when the application wants to resize windows on their own.
393 * We generate a synthethic configure notify event to signalize the client its "new" position.
396 int handle_configure_request(void *prophs, xcb_connection_t *conn, xcb_configure_request_event_t *event) {
397 LOG("configure-request, serial %d\n", event->sequence);
398 LOG("event->window = %08x\n", event->window);
399 LOG("application wants to be at %dx%d with %dx%d\n", event->x, event->y, event->width, event->height);
401 Client *client = table_get(&by_child, event->window);
402 if (client == NULL) {
403 LOG("This client is not mapped, so we don't care and just tell the client that he will get its size\n");
404 Rect rect = {event->x, event->y, event->width, event->height};
405 fake_configure_notify(conn, rect, event->window);
409 if (client->fullscreen) {
410 LOG("Client is in fullscreen mode\n");
412 Rect child_rect = client->container->workspace->rect;
413 child_rect.x = child_rect.y = 0;
414 fake_configure_notify(conn, child_rect, client->child);
419 fake_absolute_configure_notify(conn, client);
425 * Configuration notifies are only handled because we need to set up ignore for the following
426 * enter notify events
429 int handle_configure_event(void *prophs, xcb_connection_t *conn, xcb_configure_notify_event_t *event) {
430 xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
432 LOG("handle_configure_event for window %08x\n", event->window);
433 LOG("event->type = %d, \n", event->response_type);
434 LOG("event->x = %d, ->y = %d, ->width = %d, ->height = %d\n", event->x, event->y, event->width, event->height);
436 /* We ignore this sequence twice because events for child and frame should be ignored */
437 add_ignore_event(event->sequence);
438 add_ignore_event(event->sequence);
440 if (event->event == root) {
441 LOG("reconfigure of the root window, need to xinerama\n");
442 /* FIXME: Somehow, this is occuring too often. Therefore, we check for 0/0,
443 but is there a better way? */
444 if (event->x == 0 && event->y == 0)
445 xinerama_requery_screens(conn);
453 * Our window decorations were unmapped. That means, the window will be killed now,
454 * so we better clean up before.
457 int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_notify_event_t *event) {
458 xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
460 add_ignore_event(event->sequence);
462 Client *client = table_get(&by_child, event->window);
463 /* First, we need to check if the client is awaiting an unmap-request which
464 was generated by us reparenting the window. In that case, we just ignore it. */
465 if (client != NULL && client->awaiting_useless_unmap) {
466 LOG("Dropping this unmap request, it was generated by reparenting\n");
467 client->awaiting_useless_unmap = false;
471 LOG("event->window = %08x, event->event = %08x\n", event->window, event->event);
472 LOG("UnmapNotify for 0x%08x (received from 0x%08x)\n", event->window, event->event);
473 if (client == NULL) {
474 LOG("not a managed window. Ignoring.\n");
476 /* This was most likely the destroyed frame of a client which is
477 * currently being unmapped, so we add this sequence (again!) to
478 * the ignore list (enter_notify events will get sent for both,
479 * the child and its frame). */
480 add_ignore_event(event->sequence);
485 client = table_remove(&by_child, event->window);
487 if (client->name != NULL)
490 if (client->container != NULL) {
491 Container *con = client->container;
493 /* If this was the fullscreen client, we need to unset it */
494 if (client->fullscreen)
495 con->workspace->fullscreen_client = NULL;
497 /* Remove the client from the list of clients */
498 remove_client_from_container(conn, client, con);
500 /* Set focus to the last focused client in this container */
501 con->currently_focused = get_last_focused_client(conn, con, NULL);
503 /* Only if this is the active container, we need to really change focus */
504 if ((con->currently_focused != NULL) && ((con == CUR_CELL) || client->fullscreen))
505 set_focus(conn, con->currently_focused, true);
509 LOG("Removing from dock clients\n");
510 SLIST_REMOVE(&(client->workspace->screen->dock_clients), client, Client, dock_clients);
513 LOG("child of 0x%08x.\n", client->frame);
514 xcb_reparent_window(conn, client->child, root, 0, 0);
515 xcb_destroy_window(conn, client->frame);
517 table_remove(&by_parent, client->frame);
519 if (client->container != NULL) {
520 cleanup_table(conn, client->container->workspace);
521 fix_colrowspan(conn, client->container->workspace);
524 /* Let’s see how many clients there are left on the workspace to delete it if it’s empty */
525 bool workspace_empty = true;
526 FOR_TABLE(client->workspace)
527 if (!CIRCLEQ_EMPTY(&(client->workspace->table[cols][rows]->clients))) {
528 workspace_empty = false;
533 TAILQ_FOREACH(screen, virtual_screens, screens)
534 if (screen->current_workspace == client->workspace->num) {
535 workspace_empty = false;
540 client->workspace->screen = NULL;
550 * Called when a window changes its title
553 int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state,
554 xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
555 LOG("window's name changed.\n");
556 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
557 LOG("_NET_WM_NAME not specified, not changing\n");
560 Client *client = table_get(&by_child, window);
564 /* Save the old pointer to make the update atomic */
567 asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop));
568 /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
569 char *ucs2_name = convert_utf8_to_ucs2(new_name, &new_len);
570 LOG("Name should change to \"%s\"\n", new_name);
573 /* Check if they are the same and don’t update if so.
574 Note the use of new_len * 2 to check all bytes as each glyph takes 2 bytes.
575 Also note the use of memcmp() instead of strncmp() because the latter stops on nullbytes,
576 but UCS-2 uses nullbytes to fill up glyphs which only use one byte. */
577 if ((new_len == client->name_len) &&
578 (client->name != NULL) &&
579 (memcmp(client->name, ucs2_name, new_len * 2) == 0)) {
580 LOG("Name did not change, not updating\n");
585 char *old_name = client->name;
586 client->name = ucs2_name;
587 client->name_len = new_len;
588 client->uses_net_wm_name = true;
590 if (old_name != NULL)
593 /* If the client is a dock window, we don’t need to render anything */
597 if (client->container->mode == MODE_STACK)
598 render_container(conn, client->container);
599 else decorate_window(conn, client, client->frame, client->titlegc, 0);
606 * We handle legacy window names (titles) which are in COMPOUND_TEXT encoding. However, we
607 * just pass them along, so when containing non-ASCII characters, those will be rendering
608 * incorrectly. In order to correctly render unicode window titles in i3, an application
609 * has to set _NET_WM_NAME, which is in UTF-8 encoding.
611 * On every update, a message is put out to the user, so he may improve the situation and
612 * update applications which display filenames in their title to correctly use
613 * _NET_WM_NAME and therefore support unicode.
616 int handle_windowname_change_legacy(void *data, xcb_connection_t *conn, uint8_t state,
617 xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
618 LOG("window's name changed (legacy).\n");
619 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
620 LOG("prop == NULL\n");
623 Client *client = table_get(&by_child, window);
627 if (client->uses_net_wm_name) {
628 LOG("This client is capable of _NET_WM_NAME, ignoring legacy name\n");
632 /* Save the old pointer to make the update atomic */
634 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop)) == -1) {
635 perror("Could not get old name");
636 LOG("Could not get old name\n");
639 /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
640 LOG("Name should change to \"%s\"\n", new_name);
642 /* Check if they are the same and don’t update if so. */
643 if (client->name != NULL &&
644 strlen(new_name) == strlen(client->name) &&
645 strcmp(client->name, new_name) == 0) {
646 LOG("Name did not change, not updating\n");
651 LOG("Using legacy window title. Note that in order to get Unicode window titles in i3,"
652 "the application has to set _NET_WM_NAME which is in UTF-8 encoding.\n");
654 char *old_name = client->name;
655 client->name = new_name;
656 client->name_len = -1;
658 if (old_name != NULL)
661 /* If the client is a dock window, we don’t need to render anything */
665 if (client->container->mode == MODE_STACK)
666 render_container(conn, client->container);
667 else decorate_window(conn, client, client->frame, client->titlegc, 0);
674 * Expose event means we should redraw our windows (= title bar)
677 int handle_expose_event(void *data, xcb_connection_t *conn, xcb_expose_event_t *event) {
678 /* event->count is the number of minimum remaining expose events for this window, so we
679 skip all events but the last one */
680 if (event->count != 0)
682 LOG("window = %08x\n", event->window);
684 Client *client = table_get(&by_parent, event->window);
685 if (client == NULL) {
686 /* There was no client in the table, so this is probably an expose event for
687 one of our stack_windows. */
688 struct Stack_Window *stack_win;
689 SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
690 if (stack_win->window == event->window) {
691 render_container(conn, stack_win->container);
695 /* …or one of the bars? */
697 TAILQ_FOREACH(screen, virtual_screens, screens)
698 if (screen->bar == event->window)
703 LOG("got client %s\n", client->name);
705 LOG("this is a dock\n");
709 if (client->container->mode != MODE_STACK)
710 decorate_window(conn, client, client->frame, client->titlegc, 0);
712 uint32_t background_color;
713 /* Distinguish if the window is currently focused… */
714 if (CUR_CELL->currently_focused == client)
715 background_color = get_colorpixel(conn, "#285577");
716 /* …or if it is the focused window in a not focused container */
717 else background_color = get_colorpixel(conn, "#555555");
719 /* Set foreground color to current focused color, line width to 2 */
720 uint32_t values[] = {background_color, 2};
721 xcb_change_gc(conn, client->titlegc, XCB_GC_FOREGROUND | XCB_GC_LINE_WIDTH, values);
723 /* Draw the border, the ±1 is for line width = 2 */
724 xcb_point_t points[] = {{1, 0}, /* left upper edge */
725 {1, client->rect.height-1}, /* left bottom edge */
726 {client->rect.width-1, client->rect.height-1}, /* right bottom edge */
727 {client->rect.width-1, 0}}; /* right upper edge */
728 xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, client->frame, client->titlegc, 4, points);
730 /* Draw a black background */
731 xcb_change_gc_single(conn, client->titlegc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
732 xcb_rectangle_t crect = {2, 0, client->rect.width - (2 + 2), client->rect.height - 2};
733 xcb_poly_fill_rectangle(conn, client->frame, client->titlegc, 1, &crect);
740 * Handle client messages (EWMH)
743 int handle_client_message(void *data, xcb_connection_t *conn, xcb_client_message_event_t *event) {
744 LOG("client_message\n");
746 if (event->type == atoms[_NET_WM_STATE]) {
747 if (event->format != 32 || event->data.data32[1] != atoms[_NET_WM_STATE_FULLSCREEN])
752 Client *client = table_get(&by_child, event->window);
756 /* Check if the fullscreen state should be toggled */
757 if ((client->fullscreen &&
758 (event->data.data32[0] == _NET_WM_STATE_REMOVE ||
759 event->data.data32[0] == _NET_WM_STATE_TOGGLE)) ||
760 (!client->fullscreen &&
761 (event->data.data32[0] == _NET_WM_STATE_ADD ||
762 event->data.data32[0] == _NET_WM_STATE_TOGGLE)))
763 toggle_fullscreen(conn, client);
765 LOG("unhandled clientmessage\n");
772 int handle_window_type(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
773 xcb_atom_t atom, xcb_get_property_reply_t *property) {
774 /* TODO: Implement this one. To do this, implement a little test program which sleep(1)s
775 before changing this property. */
776 LOG("_NET_WM_WINDOW_TYPE changed, this is not yet implemented.\n");
781 * Handles the size hints set by a window, but currently only the part necessary for displaying
782 * clients proportionally inside their frames (mplayer for example)
784 * See ICCCM 4.1.2.3 for more details
787 int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
788 xcb_atom_t name, xcb_get_property_reply_t *reply) {
789 LOG("handle_normal_hints\n");
790 Client *client = table_get(&by_child, window);
791 if (client == NULL) {
792 LOG("No such client\n");
795 xcb_size_hints_t size_hints;
797 /* If the hints were already in this event, use them, if not, request them */
799 xcb_get_wm_size_hints_from_reply(&size_hints, reply);
801 xcb_get_wm_normal_hints_reply(conn, xcb_get_wm_normal_hints_unchecked(conn, client->child), &size_hints, NULL);
803 /* If no aspect ratio was set or if it was invalid, we ignore the hints */
804 if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) ||
805 (size_hints.min_aspect_num <= 0) ||
806 (size_hints.min_aspect_den <= 0)) {
807 LOG("No aspect ratio set, ignoring\n");
811 LOG("window is %08x / %s\n", client->child, client->name);
813 int base_width = 0, base_height = 0,
814 min_width = 0, min_height = 0;
816 /* base_width/height are the desired size of the window.
817 We check if either the program-specified size or the program-specified
818 min-size is available */
819 if (size_hints.flags & XCB_SIZE_HINT_P_SIZE) {
820 base_width = size_hints.base_width;
821 base_height = size_hints.base_height;
822 } else if (size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE) {
823 base_width = size_hints.min_width;
824 base_height = size_hints.min_height;
827 if (size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE) {
828 min_width = size_hints.min_width;
829 min_height = size_hints.min_height;
830 } else if (size_hints.flags & XCB_SIZE_HINT_P_SIZE) {
831 min_width = size_hints.base_width;
832 min_height = size_hints.base_height;
835 double width = client->rect.width - base_width;
836 double height = client->rect.height - base_height;
837 /* Convert numerator/denominator to a double */
838 double min_aspect = (double)size_hints.min_aspect_num / size_hints.min_aspect_den;
839 double max_aspect = (double)size_hints.max_aspect_num / size_hints.min_aspect_den;
841 LOG("min_aspect = %f, max_aspect = %f\n", min_aspect, max_aspect);
842 LOG("width = %f, height = %f\n", width, height);
844 /* Sanity checks, this is user-input, in a way */
845 if (max_aspect <= 0 || min_aspect <= 0 || height == 0 || (width / height) <= 0)
848 /* Check if we need to set proportional_* variables using the correct ratio */
849 if ((width / height) < min_aspect) {
850 client->proportional_width = width;
851 client->proportional_height = width / min_aspect;
852 } else if ((width / height) > max_aspect) {
853 client->proportional_width = width;
854 client->proportional_height = width / max_aspect;
857 client->force_reconfigure = true;
859 if (client->container != NULL) {
860 render_container(conn, client->container);