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_wm.h>
19 #include <xcb/xcb_icccm.h>
21 #include <X11/XKBlib.h>
35 /* After mapping/unmapping windows, a notify event is generated. However, we don’t want it,
36 since it’d trigger an infinite loop of switching between the different windows when
37 changing workspaces */
38 SLIST_HEAD(ignore_head, Ignore_Event) ignore_events;
40 static void add_ignore_event(const int sequence) {
41 struct Ignore_Event *event = smalloc(sizeof(struct Ignore_Event));
43 event->sequence = sequence;
44 event->added = time(NULL);
46 LOG("Adding sequence %d to ignorelist\n", sequence);
48 SLIST_INSERT_HEAD(&ignore_events, event, ignore_events);
52 * Checks if the given sequence is ignored and returns true if so.
55 static bool event_is_ignored(const int sequence) {
56 struct Ignore_Event *event;
57 /* TODO: cleanup this list */
58 SLIST_FOREACH(event, &ignore_events, ignore_events) {
59 if (event->sequence == sequence) {
60 LOG("Ignoring event (sequence %d)\n", sequence);
61 SLIST_REMOVE(&ignore_events, event, Ignore_Event, ignore_events);
70 * Due to bindings like Mode_switch + <a>, we need to bind some keys in XCB_GRAB_MODE_SYNC.
71 * Therefore, we just replay all key presses.
74 int handle_key_release(void *ignored, xcb_connection_t *conn, xcb_key_release_event_t *event) {
75 LOG("got key release, just passing\n");
76 xcb_allow_events(conn, XCB_ALLOW_REPLAY_KEYBOARD, event->time);
82 * There was a key press. We compare this key code with our bindings table and pass
83 * the bound action to parse_command().
86 int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_t *event) {
87 LOG("Keypress %d\n", event->detail);
89 /* We need to get the keysym group (There are group 1 to group 4, each holding
90 two keysyms (without shift and with shift) using Xkb because X fails to
91 provide them reliably (it works in Xephyr, it does not in real X) */
93 if (XkbGetState(xkbdpy, XkbUseCoreKbd, &state) == Success && (state.group+1) == 2)
96 LOG("state %d\n", event->state);
98 /* Remove the numlock bit, all other bits are modifiers we can bind to */
99 uint16_t state_filtered = event->state & ~XCB_MOD_MASK_LOCK;
101 /* Find the binding */
103 TAILQ_FOREACH(bind, &bindings, bindings)
104 if (bind->keycode == event->detail && bind->mods == state_filtered)
107 /* No match? Then it was an actively grabbed key, that is with Mode_switch, and
108 the user did not press Mode_switch, so just pass it… */
109 if (bind == TAILQ_END(&bindings)) {
110 xcb_allow_events(conn, ReplayKeyboard, event->time);
115 parse_command(conn, bind->command);
116 if (event->state & 0x2) {
117 LOG("Mode_switch -> allow_events(SyncKeyboard)\n");
118 xcb_allow_events(conn, SyncKeyboard, event->time);
126 * When the user moves the mouse pointer onto a window, this callback gets called.
129 int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_notify_event_t *event) {
130 LOG("enter_notify for %08x, mode = %d, detail %d, serial %d\n", event->event, event->mode, event->detail, event->sequence);
131 if (event->mode != XCB_NOTIFY_MODE_NORMAL) {
132 LOG("This was not a normal notify, ignoring\n");
135 /* Some events are not interesting, because they were not generated actively by the
136 user, but be reconfiguration of windows */
137 if (event_is_ignored(event->sequence))
140 /* This was either a focus for a client’s parent (= titlebar)… */
141 Client *client = table_get(byParent, event->event);
142 /* …or the client itself */
144 client = table_get(byChild, event->event);
146 /* If not, then the user moved his cursor to the root window. In that case, we adjust c_ws */
147 if (client == NULL) {
148 LOG("Getting screen at %d x %d\n", event->root_x, event->root_y);
149 i3Screen *screen = get_screen_containing(event->root_x, event->root_y);
150 if (screen == NULL) {
151 LOG("ERROR: No such screen\n");
154 c_ws = &workspaces[screen->current_workspace];
155 LOG("We're now on virtual screen number %d\n", screen->num);
159 /* Do plausibility checks: This event may be useless for us if it occurs on a window
160 which is in a stacked container but not the focused one */
161 if (client->container != NULL &&
162 client->container->mode == MODE_STACK &&
163 client->container->currently_focused != client) {
164 LOG("Plausibility check says: no\n");
168 set_focus(conn, client);
173 int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_event_t *event) {
174 LOG("button press!\n");
175 /* This was either a focus for a client’s parent (= titlebar)… */
176 Client *client = table_get(byChild, event->event);
177 bool border_click = false;
178 if (client == NULL) {
179 client = table_get(byParent, event->event);
182 if (client == NULL) {
183 /* The client was neither on a client’s titlebar nor on a client itself, maybe on a stack_window? */
184 struct Stack_Window *stack_win;
185 SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
186 if (stack_win->window == event->event) {
187 /* A stack window was clicked. We calculate the destination client by
188 dividing the Y position of the event through the height of a window
189 decoration and then set the focus to this client. */
190 i3Font *font = load_font(conn, config.font);
191 int decoration_height = (font->height + 2 + 2);
192 int destination = (event->event_y / decoration_height),
196 LOG("Click on stack_win for client %d\n", destination);
197 CIRCLEQ_FOREACH(client, &(stack_win->container->clients), clients)
198 if (c++ == destination) {
199 set_focus(conn, client);
209 xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
210 xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
212 /* Set focus in any case */
213 set_focus(conn, client);
215 /* Let’s see if this was on the borders (= resize). If not, we’re done */
216 LOG("press button on x=%d, y=%d\n", event->event_x, event->event_y);
218 Container *con = client->container,
221 enum { O_HORIZONTAL, O_VERTICAL } orientation = O_VERTICAL;
225 LOG("dock. done.\n");
226 xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time);
231 LOG("event->event_x = %d, client->rect.width = %d\n", event->event_x, client->rect.width);
234 LOG("client. done.\n");
235 xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time);
240 if (event->event_y < 2) {
241 /* This was a press on the top border */
244 first = con->workspace->table[con->col][con->row-1];
246 orientation = O_HORIZONTAL;
247 } else if (event->event_y >= (client->rect.height - 2)) {
249 if (con->row == (con->workspace->rows-1))
252 second = con->workspace->table[con->col][con->row+1];
253 orientation = O_HORIZONTAL;
254 } else if (event->event_x <= 2) {
258 first = con->workspace->table[con->col-1][con->row];
260 } else if (event->event_x > 2) {
262 if (con->col == (con->workspace->cols-1))
265 second = con->workspace->table[con->col+1][con->row];
271 mask = XCB_CW_OVERRIDE_REDIRECT;
274 /* Open a new window, the resizebar. Grab the pointer and move the window around
275 as the user moves the pointer. */
276 Rect grabrect = {0, 0, root_screen->width_in_pixels, root_screen->height_in_pixels};
277 xcb_window_t grabwin = create_window(conn, grabrect, XCB_WINDOW_CLASS_INPUT_ONLY, -1, mask, values);
280 if (orientation == O_VERTICAL) {
281 helprect.x = event->root_x;
284 helprect.height = root_screen->height_in_pixels; /* this has to be the cell’s height */
285 new_position = event->root_x;
288 helprect.y = event->root_y;
289 helprect.width = root_screen->width_in_pixels; /* this has to be the cell’s width */
291 new_position = event->root_y;
294 mask = XCB_CW_BACK_PIXEL;
295 values[0] = get_colorpixel(conn, "#4c7899");
297 mask |= XCB_CW_OVERRIDE_REDIRECT;
300 xcb_window_t helpwin = create_window(conn, helprect, XCB_WINDOW_CLASS_INPUT_OUTPUT,
301 (orientation == O_VERTICAL ?
302 XCB_CURSOR_SB_V_DOUBLE_ARROW :
303 XCB_CURSOR_SB_H_DOUBLE_ARROW), mask, values);
305 xcb_circulate_window(conn, XCB_CIRCULATE_RAISE_LOWEST, helpwin);
307 xcb_grab_pointer(conn, false, root, XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION,
308 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, grabwin, XCB_NONE, XCB_CURRENT_TIME);
312 xcb_generic_event_t *inside_event;
313 /* I’ve always wanted to have my own eventhandler… */
314 while ((inside_event = xcb_wait_for_event(conn))) {
315 /* Same as get_event_handler in xcb */
316 int nr = inside_event->response_type;
318 /* An error occured */
319 handle_event(NULL, conn, inside_event);
324 nr &= XCB_EVENT_RESPONSE_TYPE_MASK;
327 /* Check if we need to escape this loop */
328 if (nr == XCB_BUTTON_RELEASE)
332 case XCB_MOTION_NOTIFY:
333 if (orientation == O_VERTICAL) {
334 values[0] = new_position = ((xcb_motion_notify_event_t*)inside_event)->root_x;
335 xcb_configure_window(conn, helpwin, XCB_CONFIG_WINDOW_X, values);
337 values[0] = new_position = ((xcb_motion_notify_event_t*)inside_event)->root_y;
338 xcb_configure_window(conn, helpwin, XCB_CONFIG_WINDOW_Y, values);
344 LOG("Passing to original handler\n");
345 /* Use original handler */
346 xcb_event_handle(&evenths, inside_event);
352 xcb_ungrab_pointer(conn, XCB_CURRENT_TIME);
353 xcb_destroy_window(conn, helpwin);
354 xcb_destroy_window(conn, grabwin);
357 Workspace *ws = con->workspace;
358 if (orientation == O_VERTICAL) {
359 LOG("Resize was from X = %d to X = %d\n", event->root_x, new_position);
360 if (event->root_x == new_position) {
361 LOG("Nothing changed, not updating anything\n");
365 /* Convert 0 (for default width_factor) to actual numbers */
366 if (first->width_factor == 0)
367 first->width_factor = ((float)ws->rect.width / ws->cols) / ws->rect.width;
368 if (second->width_factor == 0)
369 second->width_factor = ((float)ws->rect.width / ws->cols) / ws->rect.width;
371 first->width_factor *= (float)(first->width + (new_position - event->root_x)) / first->width;
372 second->width_factor *= (float)(second->width - (new_position - event->root_x)) / second->width;
374 LOG("Resize was from Y = %d to Y = %d\n", event->root_y, new_position);
375 if (event->root_y == new_position) {
376 LOG("Nothing changed, not updating anything\n");
380 /* Convert 0 (for default height_factor) to actual numbers */
381 if (first->height_factor == 0)
382 first->height_factor = ((float)ws->rect.height / ws->rows) / ws->rect.height;
383 if (second->height_factor == 0)
384 second->height_factor = ((float)ws->rect.height / ws->rows) / ws->rect.height;
386 first->height_factor *= (float)(first->height + (new_position - event->root_y)) / first->height;
387 second->height_factor *= (float)(second->height - (new_position - event->root_y)) / second->height;
396 * A new window appeared on the screen (=was mapped), so let’s manage it.
399 int handle_map_request(void *prophs, xcb_connection_t *conn, xcb_map_request_event_t *event) {
400 xcb_get_window_attributes_cookie_t cookie;
401 xcb_get_window_attributes_reply_t *reply;
403 cookie = xcb_get_window_attributes_unchecked(conn, event->window);
405 if ((reply = xcb_get_window_attributes_reply(conn, cookie, NULL)) == NULL) {
406 LOG("Could not get window attributes\n");
410 window_attributes_t wa = { TAG_VALUE };
411 LOG("override_redirect = %d\n", reply->override_redirect);
412 wa.u.override_redirect = reply->override_redirect;
413 LOG("window = 0x%08x, serial is %d.\n", event->window, event->sequence);
414 add_ignore_event(event->sequence);
416 manage_window(prophs, conn, event->window, wa);
421 * Configure requests are received when the application wants to resize windows on their own.
423 * We generate a synthethic configure notify event to signalize the client its "new" position.
426 int handle_configure_request(void *prophs, xcb_connection_t *conn, xcb_configure_request_event_t *event) {
427 LOG("configure-request, serial %d\n", event->sequence);
428 LOG("event->window = %08x\n", event->window);
429 LOG("application wants to be at %dx%d with %dx%d\n", event->x, event->y, event->width, event->height);
431 Client *client = table_get(byChild, event->window);
432 if (client == NULL) {
433 LOG("No such client\n");
437 xcb_configure_notify_event_t generated_event;
439 generated_event.event = client->child;
440 generated_event.window = client->child;
441 generated_event.response_type = XCB_CONFIGURE_NOTIFY;
443 generated_event.x = client->child_rect.x;
444 generated_event.y = client->child_rect.y;
445 generated_event.width = client->child_rect.width;
446 generated_event.height = client->child_rect.height;
448 generated_event.border_width = 0;
449 generated_event.above_sibling = XCB_NONE;
450 generated_event.override_redirect = false;
452 xcb_send_event(conn, false, client->child, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char*)&generated_event);
455 LOG("Told the client to stay at %dx%d with size %dx%d\n",
456 client->child_rect.x, client->child_rect.y, client->child_rect.width, client->child_rect.height);
462 * Configuration notifies are only handled because we need to set up ignore for the following
463 * enter notify events
466 int handle_configure_event(void *prophs, xcb_connection_t *conn, xcb_configure_notify_event_t *event) {
467 xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
469 LOG("handle_configure_event for window %08x\n", event->window);
470 LOG("event->type = %d, \n", event->response_type);
471 LOG("event->x = %d, ->y = %d, ->width = %d, ->height = %d\n", event->x, event->y, event->width, event->height);
472 add_ignore_event(event->sequence);
474 if (event->event == root) {
475 LOG("reconfigure of the root window, need to xinerama\n");
476 /* FIXME: Somehow, this is occuring too often. Therefore, we check for 0/0,
477 but is there a better way? */
478 if (event->x == 0 && event->y == 0)
479 xinerama_requery_screens(conn);
487 * Our window decorations were unmapped. That means, the window will be killed now,
488 * so we better clean up before.
491 int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_notify_event_t *event) {
492 xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
494 add_ignore_event(event->sequence);
496 Client *client = table_get(byChild, event->window);
497 /* First, we need to check if the client is awaiting an unmap-request which
498 was generated by us reparenting the window. In that case, we just ignore it. */
499 if (client != NULL && client->awaiting_useless_unmap) {
500 LOG("Dropping this unmap request, it was generated by reparenting\n");
501 client->awaiting_useless_unmap = false;
505 LOG("event->window = %08x, event->event = %08x\n", event->window, event->event);
506 LOG("UnmapNotify for 0x%08x (received from 0x%08x)\n", event->window, event->event);
507 if (client == NULL) {
508 LOG("not a managed window. Ignoring.\n");
512 client = table_remove(byChild, event->window);
514 if (client->name != NULL)
517 if (client->container != NULL) {
518 Container *con = client->container;
520 /* If this was the fullscreen client, we need to unset it */
521 if (client->fullscreen)
522 con->workspace->fullscreen_client = NULL;
524 /* Remove the client from the list of clients */
525 remove_client_from_container(conn, client, con);
527 /* Remove from the focus stack */
528 LOG("Removing from focus stack\n");
529 SLIST_REMOVE(&(con->workspace->focus_stack), client, Client, focus_clients);
531 /* Set focus to the last focused client in this container */
532 con->currently_focused = NULL;
533 Client *focus_client;
534 SLIST_FOREACH(focus_client, &(con->workspace->focus_stack), focus_clients)
535 if (focus_client->container == con) {
536 con->currently_focused = focus_client;
537 set_focus(conn, focus_client);
543 LOG("Removing from dock clients\n");
544 SLIST_REMOVE(&(client->workspace->dock_clients), client, Client, dock_clients);
547 LOG("child of 0x%08x.\n", client->frame);
548 xcb_reparent_window(conn, client->child, root, 0, 0);
549 xcb_destroy_window(conn, client->frame);
551 table_remove(byParent, client->frame);
553 if (client->container != NULL)
554 cleanup_table(conn, client->container->workspace);
564 * Called when a window changes its title
567 int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state,
568 xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
569 LOG("window's name changed.\n");
571 LOG("prop == NULL\n");
574 Client *client = table_get(byChild, window);
578 /* Save the old pointer to make the update atomic */
581 asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop));
582 /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
583 char *ucs2_name = convert_utf8_to_ucs2(new_name, &new_len);
584 LOG("Name should change to \"%s\"\n", new_name);
587 /* Check if they are the same and don’t update if so.
588 Note the use of new_len * 2 to check all bytes as each glyph takes 2 bytes.
589 Also note the use of memcmp() instead of strncmp() because the latter stops on nullbytes,
590 but UCS-2 uses nullbytes to fill up glyphs which only use one byte. */
591 if ((new_len == client->name_len) &&
592 (client->name != NULL) &&
593 (memcmp(client->name, ucs2_name, new_len * 2) == 0)) {
594 LOG("Name did not change, not updating\n");
599 char *old_name = client->name;
600 client->name = ucs2_name;
601 client->name_len = new_len;
603 if (old_name != NULL)
606 /* If the client is a dock window, we don’t need to render anything */
610 if (client->container->mode == MODE_STACK)
611 render_container(conn, client->container);
612 else decorate_window(conn, client, client->frame, client->titlegc, 0);
619 * Expose event means we should redraw our windows (= title bar)
622 int handle_expose_event(void *data, xcb_connection_t *conn, xcb_expose_event_t *event) {
623 /* event->count is the number of minimum remaining expose events for this window, so we
624 skip all events but the last one */
625 if (event->count != 0)
627 LOG("window = %08x\n", event->window);
629 Client *client = table_get(byParent, event->window);
630 if (client == NULL) {
631 /* There was no client in the table, so this is probably an expose event for
632 one of our stack_windows. */
633 struct Stack_Window *stack_win;
634 SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
635 if (stack_win->window == event->window) {
636 render_container(conn, stack_win->container);
640 /* …or one of the bars? */
642 TAILQ_FOREACH(screen, virtual_screens, screens) {
643 if (screen->bar == event->window) {
650 LOG("got client %s\n", client->name);
652 LOG("this is a dock\n");
656 if (client->container->mode != MODE_STACK)
657 decorate_window(conn, client, client->frame, client->titlegc, 0);
659 uint32_t background_color;
660 /* Distinguish if the window is currently focused… */
661 if (CUR_CELL->currently_focused == client)
662 background_color = get_colorpixel(conn, "#285577");
663 /* …or if it is the focused window in a not focused container */
664 else background_color = get_colorpixel(conn, "#555555");
666 /* Set foreground color to current focused color, line width to 2 */
667 uint32_t values[] = {background_color, 2};
668 xcb_change_gc(conn, client->titlegc, XCB_GC_FOREGROUND | XCB_GC_LINE_WIDTH, values);
670 /* Draw the border, the ±1 is for line width = 2 */
671 xcb_point_t points[] = {{1, 0}, /* left upper edge */
672 {1, client->rect.height-1}, /* left bottom edge */
673 {client->rect.width-1, client->rect.height-1}, /* right bottom edge */
674 {client->rect.width-1, 0}}; /* right upper edge */
675 xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, client->frame, client->titlegc, 4, points);
677 /* Draw a black background */
678 xcb_change_gc_single(conn, client->titlegc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
679 xcb_rectangle_t crect = {2, 0, client->rect.width - (2 + 2), client->rect.height - 2};
680 xcb_poly_fill_rectangle(conn, client->frame, client->titlegc, 1, &crect);
687 * Handle client messages (EWMH)
690 int handle_client_message(void *data, xcb_connection_t *conn, xcb_client_message_event_t *event) {
691 LOG("client_message\n");
693 if (event->type == atoms[_NET_WM_STATE]) {
694 if (event->format != 32 || event->data.data32[1] != atoms[_NET_WM_STATE_FULLSCREEN])
699 Client *client = table_get(byChild, 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 toggle_fullscreen(conn, client);
712 LOG("unhandled clientmessage\n");
719 int window_type_handler(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 LOG("_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 LOG("handle_normal_hints\n");
737 Client *client = table_get(byChild, window);
738 if (client == NULL) {
739 LOG("No such client\n");
742 xcb_size_hints_t size_hints;
744 /* If the hints were already in this event, use them, if not, request them */
746 xcb_get_wm_size_hints_from_reply(&size_hints, reply);
748 xcb_get_wm_normal_hints_reply(conn, xcb_get_wm_normal_hints_unchecked(conn, client->child), &size_hints, NULL);
750 /* If no aspect ratio was set or if it was invalid, we ignore the hints */
751 if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) ||
752 (size_hints.min_aspect_num <= 0) ||
753 (size_hints.min_aspect_den <= 0)) {
754 LOG("No aspect ratio set, ignoring\n");
758 LOG("window is %08x / %s\n", client->child, client->name);
760 int base_width = 0, base_height = 0,
761 min_width = 0, min_height = 0;
763 /* base_width/height are the desired size of the window.
764 We check if either the program-specified size or the program-specified
765 min-size is available */
766 if (size_hints.flags & XCB_SIZE_HINT_P_SIZE) {
767 base_width = size_hints.base_width;
768 base_height = size_hints.base_height;
769 } else if (size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE) {
770 base_width = size_hints.min_width;
771 base_height = size_hints.min_height;
774 if (size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE) {
775 min_width = size_hints.min_width;
776 min_height = size_hints.min_height;
777 } else if (size_hints.flags & XCB_SIZE_HINT_P_SIZE) {
778 min_width = size_hints.base_width;
779 min_height = size_hints.base_height;
782 double width = client->rect.width - base_width;
783 double height = client->rect.height - base_height;
784 /* Convert numerator/denominator to a double */
785 double min_aspect = (double)size_hints.min_aspect_num / size_hints.min_aspect_den;
786 double max_aspect = (double)size_hints.max_aspect_num / size_hints.min_aspect_den;
788 LOG("min_aspect = %f, max_aspect = %f\n", min_aspect, max_aspect);
789 LOG("width = %f, height = %f\n", width, height);
791 /* Sanity checks, this is user-input, in a way */
792 if (max_aspect <= 0 || min_aspect <= 0 || height == 0 || (width / height) <= 0)
795 /* Check if we need to set proportional_* variables using the correct ratio */
796 if ((width / height) < min_aspect) {
797 client->proportional_width = width;
798 client->proportional_height = width / min_aspect;
799 } else if ((width / height) > max_aspect) {
800 client->proportional_width = width;
801 client->proportional_height = width / max_aspect;
804 client->force_reconfigure = true;
806 if (client->container != NULL) {
807 render_container(conn, client->container);