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 /* Some events are not interesting, because they were not generated actively by the
132 user, but be reconfiguration of windows */
133 if (event_is_ignored(event->sequence))
136 /* This was either a focus for a client’s parent (= titlebar)… */
137 Client *client = table_get(byParent, event->event);
138 /* …or the client itself */
140 client = table_get(byChild, event->event);
142 /* If not, then the user moved his cursor to the root window. In that case, we adjust c_ws */
143 if (client == NULL) {
144 LOG("Getting screen at %d x %d\n", event->root_x, event->root_y);
145 i3Screen *screen = get_screen_containing(event->root_x, event->root_y);
146 if (screen == NULL) {
147 LOG("ERROR: No such screen\n");
150 c_ws = &workspaces[screen->current_workspace];
151 LOG("We're now on virtual screen number %d\n", screen->num);
155 /* Do plausibility checks: This event may be useless for us if it occurs on a window
156 which is in a stacked container but not the focused one */
157 if (client->container->mode == MODE_STACK && client->container->currently_focused != client) {
158 LOG("Plausibility check says: no\n");
162 set_focus(conn, client);
167 int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_event_t *event) {
168 LOG("button press!\n");
169 /* This was either a focus for a client’s parent (= titlebar)… */
170 Client *client = table_get(byChild, event->event);
171 bool border_click = false;
172 if (client == NULL) {
173 client = table_get(byParent, event->event);
176 if (client == NULL) {
177 /* The client was neither on a client’s titlebar nor on a client itself, maybe on a stack_window? */
178 struct Stack_Window *stack_win;
179 SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
180 if (stack_win->window == event->event) {
181 /* A stack window was clicked. We calculate the destination client by
182 dividing the Y position of the event through the height of a window
183 decoration and then set the focus to this client. */
184 i3Font *font = load_font(conn, config.font);
185 int decoration_height = (font->height + 2 + 2);
186 int destination = (event->event_y / decoration_height),
190 LOG("Click on stack_win for client %d\n", destination);
191 CIRCLEQ_FOREACH(client, &(stack_win->container->clients), clients)
192 if (c++ == destination) {
193 set_focus(conn, client);
203 xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
204 xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
206 /* Set focus in any case */
207 set_focus(conn, client);
209 /* Let’s see if this was on the borders (= resize). If not, we’re done */
210 LOG("press button on x=%d, y=%d\n", event->event_x, event->event_y);
212 Container *con = client->container,
215 enum { O_HORIZONTAL, O_VERTICAL } orientation = O_VERTICAL;
219 LOG("dock. done.\n");
220 xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time);
225 LOG("event->event_x = %d, client->rect.width = %d\n", event->event_x, client->rect.width);
228 LOG("client. done.\n");
229 xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time);
234 if (event->event_y < 2) {
235 /* This was a press on the top border */
238 first = con->workspace->table[con->col][con->row-1];
240 orientation = O_HORIZONTAL;
241 } else if (event->event_y >= (client->rect.height - 2)) {
243 if (con->row == (con->workspace->rows-1))
246 second = con->workspace->table[con->col][con->row+1];
247 orientation = O_HORIZONTAL;
248 } else if (event->event_x <= 2) {
252 first = con->workspace->table[con->col-1][con->row];
254 } else if (event->event_x > 2) {
256 if (con->col == (con->workspace->cols-1))
259 second = con->workspace->table[con->col+1][con->row];
265 mask = XCB_CW_OVERRIDE_REDIRECT;
268 /* Open a new window, the resizebar. Grab the pointer and move the window around
269 as the user moves the pointer. */
270 Rect grabrect = {0, 0, root_screen->width_in_pixels, root_screen->height_in_pixels};
271 xcb_window_t grabwin = create_window(conn, grabrect, XCB_WINDOW_CLASS_INPUT_ONLY, -1, mask, values);
274 if (orientation == O_VERTICAL) {
275 helprect.x = event->root_x;
278 helprect.height = root_screen->height_in_pixels; /* this has to be the cell’s height */
279 new_position = event->root_x;
282 helprect.y = event->root_y;
283 helprect.width = root_screen->width_in_pixels; /* this has to be the cell’s width */
285 new_position = event->root_y;
288 mask = XCB_CW_BACK_PIXEL;
289 values[0] = get_colorpixel(conn, "#4c7899");
291 mask |= XCB_CW_OVERRIDE_REDIRECT;
294 xcb_window_t helpwin = create_window(conn, helprect, XCB_WINDOW_CLASS_INPUT_OUTPUT,
295 (orientation == O_VERTICAL ?
296 XCB_CURSOR_SB_V_DOUBLE_ARROW :
297 XCB_CURSOR_SB_H_DOUBLE_ARROW), mask, values);
299 xcb_circulate_window(conn, XCB_CIRCULATE_RAISE_LOWEST, helpwin);
301 xcb_grab_pointer(conn, false, root, XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION,
302 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, grabwin, XCB_NONE, XCB_CURRENT_TIME);
306 xcb_generic_event_t *inside_event;
307 /* I’ve always wanted to have my own eventhandler… */
308 while ((inside_event = xcb_wait_for_event(conn))) {
309 /* Same as get_event_handler in xcb */
310 int nr = inside_event->response_type;
312 /* An error occured */
313 handle_event(NULL, conn, inside_event);
318 nr &= XCB_EVENT_RESPONSE_TYPE_MASK;
321 /* Check if we need to escape this loop */
322 if (nr == XCB_BUTTON_RELEASE)
326 case XCB_MOTION_NOTIFY:
327 if (orientation == O_VERTICAL) {
328 values[0] = new_position = ((xcb_motion_notify_event_t*)inside_event)->root_x;
329 xcb_configure_window(conn, helpwin, XCB_CONFIG_WINDOW_X, values);
331 values[0] = new_position = ((xcb_motion_notify_event_t*)inside_event)->root_y;
332 xcb_configure_window(conn, helpwin, XCB_CONFIG_WINDOW_Y, values);
338 LOG("Passing to original handler\n");
339 /* Use original handler */
340 xcb_event_handle(&evenths, inside_event);
346 xcb_ungrab_pointer(conn, XCB_CURRENT_TIME);
347 xcb_destroy_window(conn, helpwin);
348 xcb_destroy_window(conn, grabwin);
351 Workspace *ws = con->workspace;
352 if (orientation == O_VERTICAL) {
353 LOG("Resize was from X = %d to X = %d\n", event->root_x, new_position);
354 if (event->root_x == new_position) {
355 LOG("Nothing changed, not updating anything\n");
359 /* Convert 0 (for default width_factor) to actual numbers */
360 if (first->width_factor == 0)
361 first->width_factor = ((float)ws->rect.width / ws->cols) / ws->rect.width;
362 if (second->width_factor == 0)
363 second->width_factor = ((float)ws->rect.width / ws->cols) / ws->rect.width;
365 first->width_factor *= (float)(first->width + (new_position - event->root_x)) / first->width;
366 second->width_factor *= (float)(second->width - (new_position - event->root_x)) / second->width;
368 LOG("Resize was from Y = %d to Y = %d\n", event->root_y, new_position);
369 if (event->root_y == new_position) {
370 LOG("Nothing changed, not updating anything\n");
374 /* Convert 0 (for default height_factor) to actual numbers */
375 if (first->height_factor == 0)
376 first->height_factor = ((float)ws->rect.height / ws->rows) / ws->rect.height;
377 if (second->height_factor == 0)
378 second->height_factor = ((float)ws->rect.height / ws->rows) / ws->rect.height;
380 first->height_factor *= (float)(first->height + (new_position - event->root_y)) / first->height;
381 second->height_factor *= (float)(second->height - (new_position - event->root_y)) / second->height;
390 * A new window appeared on the screen (=was mapped), so let’s manage it.
393 int handle_map_request(void *prophs, xcb_connection_t *conn, xcb_map_request_event_t *event) {
394 xcb_get_window_attributes_cookie_t cookie;
395 xcb_get_window_attributes_reply_t *reply;
397 cookie = xcb_get_window_attributes_unchecked(conn, event->window);
399 if ((reply = xcb_get_window_attributes_reply(conn, cookie, NULL)) == NULL) {
400 LOG("Could not get window attributes\n");
404 window_attributes_t wa = { TAG_VALUE };
405 LOG("override_redirect = %d\n", reply->override_redirect);
406 wa.u.override_redirect = reply->override_redirect;
407 LOG("window = 0x%08x, serial is %d.\n", event->window, event->sequence);
408 add_ignore_event(event->sequence);
409 manage_window(prophs, conn, event->window, wa);
414 * Configure requests are received when the application wants to resize windows on their own.
416 * We generate a synthethic configure notify event to signalize the client its "new" position.
419 int handle_configure_request(void *prophs, xcb_connection_t *conn, xcb_configure_request_event_t *event) {
420 LOG("configure-request, serial %d\n", event->sequence);
421 LOG("event->window = %08x\n", event->window);
422 LOG("application wants to be at %dx%d with %dx%d\n", event->x, event->y, event->width, event->height);
424 Client *client = table_get(byChild, event->window);
425 if (client == NULL) {
426 LOG("No such client\n");
430 xcb_configure_notify_event_t generated_event;
432 generated_event.event = client->child;
433 generated_event.window = client->child;
434 generated_event.response_type = XCB_CONFIGURE_NOTIFY;
436 generated_event.x = client->child_rect.x;
437 generated_event.y = client->child_rect.y;
438 generated_event.width = client->child_rect.width;
439 generated_event.height = client->child_rect.height;
441 generated_event.border_width = 0;
442 generated_event.above_sibling = XCB_NONE;
443 generated_event.override_redirect = false;
445 xcb_send_event(conn, false, client->child, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char*)&generated_event);
448 LOG("Told the client to stay at %dx%d with size %dx%d\n",
449 client->child_rect.x, client->child_rect.y, client->child_rect.width, client->child_rect.height);
455 * Configuration notifies are only handled because we need to set up ignore for the following
456 * enter notify events
459 int handle_configure_event(void *prophs, xcb_connection_t *conn, xcb_configure_notify_event_t *event) {
460 xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
462 LOG("handle_configure_event for window %08x\n", event->window);
463 LOG("event->type = %d, \n", event->response_type);
464 LOG("event->x = %d, ->y = %d, ->width = %d, ->height = %d\n", event->x, event->y, event->width, event->height);
465 add_ignore_event(event->sequence);
467 if (event->event == root) {
468 LOG("reconfigure of the root window, need to xinerama\n");
469 /* FIXME: Somehow, this is occuring too often. Therefore, we check for 0/0,
470 but is there a better way? */
471 if (event->x == 0 && event->y == 0)
472 xinerama_requery_screens(conn);
480 * Our window decorations were unmapped. That means, the window will be killed now,
481 * so we better clean up before.
484 int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_notify_event_t *event) {
485 xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
487 add_ignore_event(event->sequence);
489 Client *client = table_get(byChild, event->window);
490 /* First, we need to check if the client is awaiting an unmap-request which
491 was generated by us reparenting the window. In that case, we just ignore it. */
492 if (client != NULL && client->awaiting_useless_unmap) {
493 LOG("Dropping this unmap request, it was generated by reparenting\n");
494 client->awaiting_useless_unmap = false;
498 LOG("event->window = %08x, event->event = %08x\n", event->window, event->event);
499 LOG("UnmapNotify for 0x%08x (received from 0x%08x)\n", event->window, event->event);
500 if (client == NULL) {
501 LOG("not a managed window. Ignoring.\n");
505 client = table_remove(byChild, event->window);
507 if (client->name != NULL)
510 if (client->container != NULL) {
511 Container *con = client->container;
513 /* If this was the fullscreen client, we need to unset it */
514 if (client->fullscreen)
515 con->workspace->fullscreen_client = NULL;
517 /* Remove the client from the list of clients */
518 remove_client_from_container(conn, client, con);
520 /* Remove from the focus stack */
521 LOG("Removing from focus stack\n");
522 SLIST_REMOVE(&(con->workspace->focus_stack), client, Client, focus_clients);
524 /* Set focus to the last focused client in this container */
525 con->currently_focused = NULL;
526 Client *focus_client;
527 SLIST_FOREACH(focus_client, &(con->workspace->focus_stack), focus_clients)
528 if (focus_client->container == con) {
529 con->currently_focused = focus_client;
530 set_focus(conn, focus_client);
535 LOG("child of 0x%08x.\n", client->frame);
536 xcb_reparent_window(conn, client->child, root, 0, 0);
537 xcb_destroy_window(conn, client->frame);
539 table_remove(byParent, client->frame);
541 cleanup_table(conn, client->container->workspace);
551 * This handler makes sure that windows are closed correctly as we drop the first unmap event we
552 * get because they are sometimes generated by remapping.
554 * FIXME: Rather than providing this event, I’d rather know why some applications need to have
555 * unmap events ignored (like VLC’s open dialog, just open it two times) while others don’t (GIMP).
556 * For now, just make it work.
559 int handle_destroy_notify_event(void *data, xcb_connection_t *conn, xcb_destroy_notify_event_t *event) {
560 LOG("Destroynotify, faking unmapnotify\n");
561 return handle_unmap_notify_event(data, conn, event);
565 * Called when a window changes its title
568 int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state,
569 xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
570 LOG("window's name changed.\n");
572 LOG("prop == NULL\n");
575 Client *client = table_get(byChild, window);
579 /* Save the old pointer to make the update atomic */
582 asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop));
583 /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
584 char *ucs2_name = convert_utf8_to_ucs2(new_name, &new_len);
585 LOG("Name should change to \"%s\"\n", new_name);
588 /* Check if they are the same and don’t update if so.
589 Note the use of new_len * 2 to check all bytes as each glyph takes 2 bytes.
590 Also note the use of memcmp() instead of strncmp() because the latter stops on nullbytes,
591 but UCS-2 uses nullbytes to fill up glyphs which only use one byte. */
592 if ((new_len == client->name_len) &&
593 (client->name != NULL) &&
594 (memcmp(client->name, ucs2_name, new_len * 2) == 0)) {
595 LOG("Name did not change, not updating\n");
600 char *old_name = client->name;
601 client->name = ucs2_name;
602 client->name_len = new_len;
604 if (old_name != NULL)
607 if (client->container->mode == MODE_STACK)
608 render_container(conn, client->container);
609 else decorate_window(conn, client, client->frame, client->titlegc, 0);
616 * Expose event means we should redraw our windows (= title bar)
619 int handle_expose_event(void *data, xcb_connection_t *conn, xcb_expose_event_t *event) {
620 /* event->count is the number of minimum remaining expose events for this window, so we
621 skip all events but the last one */
622 if (event->count != 0)
624 LOG("window = %08x\n", event->window);
626 Client *client = table_get(byParent, event->window);
627 if (client == NULL) {
628 /* There was no client in the table, so this is probably an expose event for
629 one of our stack_windows. */
630 struct Stack_Window *stack_win;
631 SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
632 if (stack_win->window == event->window) {
633 render_container(conn, stack_win->container);
637 /* …or one of the bars? */
639 TAILQ_FOREACH(screen, virtual_screens, screens) {
640 if (screen->bar == event->window) {
647 LOG("got client %s\n", client->name);
648 if (client->container->mode != MODE_STACK)
649 decorate_window(conn, client, client->frame, client->titlegc, 0);
651 uint32_t background_color;
652 /* Distinguish if the window is currently focused… */
653 if (CUR_CELL->currently_focused == client)
654 background_color = get_colorpixel(conn, "#285577");
655 /* …or if it is the focused window in a not focused container */
656 else background_color = get_colorpixel(conn, "#555555");
658 /* Set foreground color to current focused color, line width to 2 */
659 uint32_t values[] = {background_color, 2};
660 xcb_change_gc(conn, client->titlegc, XCB_GC_FOREGROUND | XCB_GC_LINE_WIDTH, values);
662 /* Draw the border, the ±1 is for line width = 2 */
663 xcb_point_t points[] = {{1, 0}, /* left upper edge */
664 {1, client->rect.height-1}, /* left bottom edge */
665 {client->rect.width-1, client->rect.height-1}, /* right bottom edge */
666 {client->rect.width-1, 0}}; /* right upper edge */
667 xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, client->frame, client->titlegc, 4, points);
669 /* Draw a black background */
670 xcb_change_gc_single(conn, client->titlegc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
671 xcb_rectangle_t crect = {2, 0, client->rect.width - (2 + 2), client->rect.height - 2};
672 xcb_poly_fill_rectangle(conn, client->frame, client->titlegc, 1, &crect);
679 * Handle client messages (EWMH)
682 int handle_client_message(void *data, xcb_connection_t *conn, xcb_client_message_event_t *event) {
683 LOG("client_message\n");
685 if (event->type == atoms[_NET_WM_STATE]) {
686 if (event->format != 32 || event->data.data32[1] != atoms[_NET_WM_STATE_FULLSCREEN])
691 Client *client = table_get(byChild, event->window);
695 /* Check if the fullscreen state should be toggled */
696 if ((client->fullscreen &&
697 (event->data.data32[0] == _NET_WM_STATE_REMOVE ||
698 event->data.data32[0] == _NET_WM_STATE_TOGGLE)) ||
699 (!client->fullscreen &&
700 (event->data.data32[0] == _NET_WM_STATE_ADD ||
701 event->data.data32[0] == _NET_WM_STATE_TOGGLE)))
702 toggle_fullscreen(conn, client);
704 LOG("unhandled clientmessage\n");
711 int window_type_handler(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
712 xcb_atom_t atom, xcb_get_property_reply_t *property) {
713 /* TODO: Implement this one. To do this, implement a little test program which sleep(1)s
714 before changing this property. */
715 LOG("_NET_WM_WINDOW_TYPE changed, this is not yet implemented.\n");
720 * Handles the size hints set by a window, but currently only the part necessary for displaying
721 * clients proportionally inside their frames (mplayer for example)
723 * See ICCCM 4.1.2.3 for more details
726 int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
727 xcb_atom_t name, xcb_get_property_reply_t *reply) {
728 LOG("handle_normal_hints\n");
729 Client *client = table_get(byChild, window);
730 if (client == NULL) {
731 LOG("No such client\n");
734 xcb_size_hints_t size_hints;
736 /* If the hints were already in this event, use them, if not, request them */
738 xcb_get_wm_size_hints_from_reply(&size_hints, reply);
740 xcb_get_wm_normal_hints_reply(conn, xcb_get_wm_normal_hints_unchecked(conn, client->child), &size_hints, NULL);
742 /* If no aspect ratio was set or if it was invalid, we ignore the hints */
743 if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) ||
744 (size_hints.min_aspect_num <= 0) ||
745 (size_hints.min_aspect_den <= 0)) {
746 LOG("No aspect ratio set, ignoring\n");
750 LOG("window is %08x / %s\n", client->child, client->name);
752 int base_width = 0, base_height = 0,
753 min_width = 0, min_height = 0;
755 /* base_width/height are the desired size of the window.
756 We check if either the program-specified size or the program-specified
757 min-size is available */
758 if (size_hints.flags & XCB_SIZE_HINT_P_SIZE) {
759 base_width = size_hints.base_width;
760 base_height = size_hints.base_height;
761 } else if (size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE) {
762 base_width = size_hints.min_width;
763 base_height = size_hints.min_height;
766 if (size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE) {
767 min_width = size_hints.min_width;
768 min_height = size_hints.min_height;
769 } else if (size_hints.flags & XCB_SIZE_HINT_P_SIZE) {
770 min_width = size_hints.base_width;
771 min_height = size_hints.base_height;
774 double width = client->rect.width - base_width;
775 double height = client->rect.height - base_height;
776 /* Convert numerator/denominator to a double */
777 double min_aspect = (double)size_hints.min_aspect_num / size_hints.min_aspect_den;
778 double max_aspect = (double)size_hints.max_aspect_num / size_hints.min_aspect_den;
780 LOG("min_aspect = %f, max_aspect = %f\n", min_aspect, max_aspect);
781 LOG("width = %f, height = %f\n", width, height);
783 /* Sanity checks, this is user-input, in a way */
784 if (max_aspect <= 0 || min_aspect <= 0 || height == 0 || (width / height) <= 0)
787 /* Check if we need to set proportional_* variables using the correct ratio */
788 if ((width / height) < min_aspect) {
789 client->proportional_width = width;
790 client->proportional_height = width / min_aspect;
791 } else if ((width / height) > max_aspect) {
792 client->proportional_width = width;
793 client->proportional_height = width / max_aspect;
796 client->force_reconfigure = true;
798 if (client->container != NULL) {
799 render_container(conn, client->container);