]> git.sur5r.net Git - i3/i3/blob - src/floating.c
Bugfix: Add deco_height only when in "normal" border mode.
[i3/i3] / src / floating.c
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * floating.c: Floating windows.
8  *
9  */
10 #include "all.h"
11
12 extern xcb_connection_t *conn;
13
14 /*
15  * Calculates sum of heights and sum of widths of all currently active outputs
16  *
17  */
18 static Rect total_outputs_dimensions(void) {
19     Output *output;
20     /* Use Rect to encapsulate dimensions, ignoring x/y */
21     Rect outputs_dimensions = {0, 0, 0, 0};
22     TAILQ_FOREACH(output, &outputs, outputs) {
23         outputs_dimensions.height += output->rect.height;
24         outputs_dimensions.width += output->rect.width;
25     }
26     return outputs_dimensions;
27 }
28
29 void floating_enable(Con *con, bool automatic) {
30     bool set_focus = (con == focused);
31
32     if (con->parent && con->parent->type == CT_DOCKAREA) {
33         LOG("Container is a dock window, not enabling floating mode.\n");
34         return;
35     }
36
37     if (con_is_floating(con)) {
38         LOG("Container is already in floating mode, not doing anything.\n");
39         return;
40     }
41
42     /* 1: If the container is a workspace container, we need to create a new
43      * split-container with the same layout and make that one floating. We
44      * cannot touch the workspace container itself because floating containers
45      * are children of the workspace. */
46     if (con->type == CT_WORKSPACE) {
47         LOG("This is a workspace, creating new container around content\n");
48         if (con_num_children(con) == 0) {
49             LOG("Workspace is empty, aborting\n");
50             return;
51         }
52         /* TODO: refactor this with src/con.c:con_set_layout */
53         Con *new = con_new(NULL, NULL);
54         new->parent = con;
55         new->layout = con->layout;
56
57         /* since the new container will be set into floating mode directly
58          * afterwards, we need to copy the workspace rect. */
59         memcpy(&(new->rect), &(con->rect), sizeof(Rect));
60
61         Con *old_focused = TAILQ_FIRST(&(con->focus_head));
62         if (old_focused == TAILQ_END(&(con->focus_head)))
63             old_focused = NULL;
64
65         /* 4: move the existing cons of this workspace below the new con */
66         DLOG("Moving cons\n");
67         Con *child;
68         while (!TAILQ_EMPTY(&(con->nodes_head))) {
69             child = TAILQ_FIRST(&(con->nodes_head));
70             con_detach(child);
71             con_attach(child, new, true);
72         }
73
74         /* 4: attach the new split container to the workspace */
75         DLOG("Attaching new split to ws\n");
76         con_attach(new, con, false);
77
78         if (old_focused)
79             con_focus(old_focused);
80
81         con = new;
82         set_focus = false;
83     }
84
85     /* 1: detach the container from its parent */
86     /* TODO: refactor this with tree_close() */
87     TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes);
88     TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
89
90     con_fix_percent(con->parent);
91
92     /* 2: create a new container to render the decoration on, add
93      * it as a floating window to the workspace */
94     Con *nc = con_new(NULL, NULL);
95     /* we need to set the parent afterwards instead of passing it as an
96      * argument to con_new() because nc would be inserted into the tiling layer
97      * otherwise. */
98     Con *ws = con_get_workspace(con);
99     nc->parent = ws;
100     nc->split = true;
101     nc->type = CT_FLOATING_CON;
102     nc->layout = L_SPLITH;
103     /* We insert nc already, even though its rect is not yet calculated. This
104      * is necessary because otherwise the workspace might be empty (and get
105      * closed in tree_close()) even though it’s not. */
106     TAILQ_INSERT_TAIL(&(ws->floating_head), nc, floating_windows);
107     TAILQ_INSERT_TAIL(&(ws->focus_head), nc, focused);
108
109     /* check if the parent container is empty and close it if so */
110     if ((con->parent->type == CT_CON || con->parent->type == CT_FLOATING_CON) &&
111         con_num_children(con->parent) == 0) {
112         DLOG("Old container empty after setting this child to floating, closing\n");
113         tree_close(con->parent, DONT_KILL_WINDOW, false, false);
114     }
115
116     char *name;
117     sasprintf(&name, "[i3 con] floatingcon around %p", con);
118     x_set_name(nc, name);
119     free(name);
120
121     /* find the height for the decorations */
122     int deco_height = config.font.height + 5;
123
124     DLOG("Original rect: (%d, %d) with %d x %d\n", con->rect.x, con->rect.y, con->rect.width, con->rect.height);
125     DLOG("Geometry = (%d, %d) with %d x %d\n", con->geometry.x, con->geometry.y, con->geometry.width, con->geometry.height);
126     Rect zero = { 0, 0, 0, 0 };
127     nc->rect = con->geometry;
128     /* If the geometry was not set (split containers), we need to determine a
129      * sensible one by combining the geometry of all children */
130     if (memcmp(&(nc->rect), &zero, sizeof(Rect)) == 0) {
131         DLOG("Geometry not set, combining children\n");
132         Con *child;
133         TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
134             DLOG("child geometry: %d x %d\n", child->geometry.width, child->geometry.height);
135             nc->rect.width += child->geometry.width;
136             nc->rect.height = max(nc->rect.height, child->geometry.height);
137         }
138     }
139
140     /* Define reasonable minimal and maximal sizes for floating windows */
141     const int floating_sane_min_height = 50;
142     const int floating_sane_min_width = 75;
143
144     Rect floating_sane_max_dimensions;
145     floating_sane_max_dimensions = total_outputs_dimensions();
146
147     /* Unless user requests otherwise (-1), ensure width/height do not exceed
148      * configured maxima or, if unconfigured, limit to combined width of all
149      * outputs */
150     if (config.floating_maximum_height != -1) {
151         if (config.floating_maximum_height == 0)
152             nc->rect.height = min(nc->rect.height, floating_sane_max_dimensions.height);
153         else
154             nc->rect.height = min(nc->rect.height, config.floating_maximum_height);
155     }
156     if (config.floating_maximum_width != -1) {
157         if (config.floating_maximum_width == 0)
158             nc->rect.width = min(nc->rect.width, floating_sane_max_dimensions.width);
159         else
160             nc->rect.width = min(nc->rect.width, config.floating_maximum_width);
161     }
162
163     /* Unless user requests otherwise (-1), raise the width/height to
164      * reasonable minimum dimensions */
165     if (config.floating_minimum_height != -1) {
166         if (config.floating_minimum_height == 0)
167             nc->rect.height = max(nc->rect.height, floating_sane_min_height);
168         else
169             nc->rect.height = max(nc->rect.height, config.floating_minimum_height);
170     }
171     if (config.floating_minimum_width != -1) {
172         if (config.floating_minimum_width == 0)
173             nc->rect.width = max(nc->rect.width, floating_sane_min_width);
174         else
175             nc->rect.width = max(nc->rect.width, config.floating_minimum_width);
176     }
177
178     /* Add pixels for the decoration. */
179     Rect border_style_rect = con_border_style_rect(con);
180
181     nc->rect.height -= border_style_rect.height;
182     nc->rect.width -= border_style_rect.width;
183
184     /* Add some more pixels for the title bar */
185     if(con_border_style(con) == BS_NORMAL)
186         nc->rect.height += deco_height;
187
188     /* Honor the X11 border */
189     nc->rect.height += con->border_width * 2;
190     nc->rect.width += con->border_width * 2;
191
192     /* Some clients (like GIMP’s color picker window) get mapped
193      * to (0, 0), so we push them to a reasonable position
194      * (centered over their leader) */
195     if (nc->rect.x == 0 && nc->rect.y == 0) {
196         Con *leader;
197         if (con->window && con->window->leader != XCB_NONE &&
198             (leader = con_by_window_id(con->window->leader)) != NULL) {
199             DLOG("Centering above leader\n");
200             nc->rect.x = leader->rect.x + (leader->rect.width / 2) - (nc->rect.width / 2);
201             nc->rect.y = leader->rect.y + (leader->rect.height / 2) - (nc->rect.height / 2);
202         } else {
203             /* center the window on workspace as fallback */
204             nc->rect.x = ws->rect.x + (ws->rect.width / 2) - (nc->rect.width / 2);
205             nc->rect.y = ws->rect.y + (ws->rect.height / 2) - (nc->rect.height / 2);
206         }
207     }
208
209     /* Sanity check: Are the coordinates on the appropriate output? If not, we
210      * need to change them */
211     Output *current_output = get_output_containing(nc->rect.x, nc->rect.y);
212     Con *correct_output = con_get_output(ws);
213     if (!current_output || current_output->con != correct_output) {
214         DLOG("This floating window is on the wrong output, fixing coordinates (currently (%d, %d))\n",
215              nc->rect.x, nc->rect.y);
216         /* Take the relative coordinates of the current output, then add them
217          * to the coordinate space of the correct output */
218         uint32_t rel_x = (nc->rect.x - (current_output ? current_output->con->rect.x : 0));
219         uint32_t rel_y = (nc->rect.y - (current_output ? current_output->con->rect.y : 0));
220         nc->rect.x = correct_output->rect.x + rel_x;
221         nc->rect.y = correct_output->rect.y + rel_y;
222     }
223
224     DLOG("Floating rect: (%d, %d) with %d x %d\n", nc->rect.x, nc->rect.y, nc->rect.width, nc->rect.height);
225
226     /* 3: attach the child to the new parent container */
227     con->parent = nc;
228     con->percent = 1.0;
229     con->floating = FLOATING_USER_ON;
230
231     /* 4: set the border style as specified with new_float */
232     if (automatic)
233         con->border_style = config.default_floating_border;
234
235     /* 5: Subtract the deco_height in order to make the floating window appear
236      * at precisely the position it specified in its original geometry (which
237      * is what applications might remember). */
238     deco_height = (con->border_style == BS_NORMAL ? config.font.height + 5 : 0);
239     nc->rect.y -= deco_height;
240
241     DLOG("Corrected y = %d (deco_height = %d)\n", nc->rect.y, deco_height);
242
243     TAILQ_INSERT_TAIL(&(nc->nodes_head), con, nodes);
244     TAILQ_INSERT_TAIL(&(nc->focus_head), con, focused);
245
246     /* render the cons to get initial window_rect correct */
247     render_con(nc, false);
248     render_con(con, false);
249
250     if (set_focus)
251         con_focus(con);
252
253     /* Check if we need to re-assign it to a different workspace because of its
254      * coordinates and exit if that was done successfully. */
255     if (floating_maybe_reassign_ws(nc))
256         return;
257
258     /* Sanitize coordinates: Check if they are on any output */
259     if (get_output_containing(nc->rect.x, nc->rect.y) != NULL)
260         return;
261
262     ELOG("No output found at destination coordinates, centering floating window on current ws\n");
263     nc->rect.x = ws->rect.x + (ws->rect.width / 2) - (nc->rect.width / 2);
264     nc->rect.y = ws->rect.y + (ws->rect.height / 2) - (nc->rect.height / 2);
265 }
266
267 void floating_disable(Con *con, bool automatic) {
268     if (!con_is_floating(con)) {
269         LOG("Container isn't floating, not doing anything.\n");
270         return;
271     }
272
273     Con *ws = con_get_workspace(con);
274
275     /* 1: detach from parent container */
276     TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes);
277     TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
278
279     /* 2: kill parent container */
280     TAILQ_REMOVE(&(con->parent->parent->floating_head), con->parent, floating_windows);
281     TAILQ_REMOVE(&(con->parent->parent->focus_head), con->parent, focused);
282     tree_close(con->parent, DONT_KILL_WINDOW, true, false);
283
284     /* 3: re-attach to the parent of the currently focused con on the workspace
285      * this floating con was on */
286     Con *focused = con_descend_tiling_focused(ws);
287
288     /* if there is no other container on this workspace, focused will be the
289      * workspace itself */
290     if (focused->type == CT_WORKSPACE)
291         con->parent = focused;
292     else con->parent = focused->parent;
293
294     /* con_fix_percent will adjust the percent value */
295     con->percent = 0.0;
296
297     con->floating = FLOATING_USER_OFF;
298
299     con_attach(con, con->parent, false);
300
301     con_fix_percent(con->parent);
302     // TODO: don’t influence focus handling when Con was not focused before.
303     con_focus(con);
304 }
305
306 /*
307  * Toggles floating mode for the given container.
308  *
309  * If the automatic flag is set to true, this was an automatic update by a change of the
310  * window class from the application which can be overwritten by the user.
311  *
312  */
313 void toggle_floating_mode(Con *con, bool automatic) {
314     /* see if the client is already floating */
315     if (con_is_floating(con)) {
316         LOG("already floating, re-setting to tiling\n");
317
318         floating_disable(con, automatic);
319         return;
320     }
321
322     floating_enable(con, automatic);
323 }
324
325 /*
326  * Raises the given container in the list of floating containers
327  *
328  */
329 void floating_raise_con(Con *con) {
330     DLOG("Raising floating con %p / %s\n", con, con->name);
331     TAILQ_REMOVE(&(con->parent->floating_head), con, floating_windows);
332     TAILQ_INSERT_TAIL(&(con->parent->floating_head), con, floating_windows);
333 }
334
335 /*
336  * Checks if con’s coordinates are within its workspace and re-assigns it to
337  * the actual workspace if not.
338  *
339  */
340 bool floating_maybe_reassign_ws(Con *con) {
341     Output *output = get_output_containing(
342         con->rect.x + (con->rect.width / 2),
343         con->rect.y + (con->rect.height / 2));
344
345     if (!output) {
346         ELOG("No output found at destination coordinates?\n");
347         return false;
348     }
349
350     if (con_get_output(con) == output->con) {
351         DLOG("still the same ws\n");
352         return false;
353     }
354
355     DLOG("Need to re-assign!\n");
356
357     Con *content = output_get_content(output->con);
358     Con *ws = TAILQ_FIRST(&(content->focus_head));
359     DLOG("Moving con %p / %s to workspace %p / %s\n", con, con->name, ws, ws->name);
360     con_move_to_workspace(con, ws, false, true);
361     con_focus(con_descend_focused(con));
362     return true;
363 }
364
365 DRAGGING_CB(drag_window_callback) {
366     const struct xcb_button_press_event_t *event = extra;
367
368     /* Reposition the client correctly while moving */
369     con->rect.x = old_rect->x + (new_x - event->root_x);
370     con->rect.y = old_rect->y + (new_y - event->root_y);
371
372     render_con(con, false);
373     x_push_node(con);
374     xcb_flush(conn);
375
376     /* Check if we cross workspace boundaries while moving */
377     if (!floating_maybe_reassign_ws(con))
378         return;
379     tree_render();
380 }
381
382 /*
383  * Called when the user clicked on the titlebar of a floating window.
384  * Calls the drag_pointer function with the drag_window callback
385  *
386  */
387 void floating_drag_window(Con *con, const xcb_button_press_event_t *event) {
388     DLOG("floating_drag_window\n");
389
390     /* Push changes before dragging, so that the window gets raised now and not
391      * after the user releases the mouse button */
392     tree_render();
393
394     /* Drag the window */
395     drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, drag_window_callback, event);
396     tree_render();
397 }
398
399 /*
400  * This is an ugly data structure which we need because there is no standard
401  * way of having nested functions (only available as a gcc extension at the
402  * moment, clang doesn’t support it) or blocks (only available as a clang
403  * extension and only on Mac OS X systems at the moment).
404  *
405  */
406 struct resize_window_callback_params {
407     const border_t corner;
408     const bool proportional;
409     const xcb_button_press_event_t *event;
410 };
411
412 DRAGGING_CB(resize_window_callback) {
413     const struct resize_window_callback_params *params = extra;
414     const xcb_button_press_event_t *event = params->event;
415     border_t corner = params->corner;
416
417     int32_t dest_x = con->rect.x;
418     int32_t dest_y = con->rect.y;
419     uint32_t dest_width;
420     uint32_t dest_height;
421
422     double ratio = (double) old_rect->width / old_rect->height;
423
424     /* First guess: We resize by exactly the amount the mouse moved,
425      * taking into account in which corner the client was grabbed */
426     if (corner & BORDER_LEFT)
427         dest_width = old_rect->width - (new_x - event->root_x);
428     else dest_width = old_rect->width + (new_x - event->root_x);
429
430     if (corner & BORDER_TOP)
431         dest_height = old_rect->height - (new_y - event->root_y);
432     else dest_height = old_rect->height + (new_y - event->root_y);
433
434     /* Obey minimum window size */
435     Rect minimum = con_minimum_size(con);
436     dest_width = max(dest_width, minimum.width);
437     dest_height = max(dest_height, minimum.height);
438
439     /* User wants to keep proportions, so we may have to adjust our values */
440     if (params->proportional) {
441         dest_width = max(dest_width, (int) (dest_height * ratio));
442         dest_height = max(dest_height, (int) (dest_width / ratio));
443     }
444
445     /* If not the lower right corner is grabbed, we must also reposition
446      * the client by exactly the amount we resized it */
447     if (corner & BORDER_LEFT)
448         dest_x = old_rect->x + (old_rect->width - dest_width);
449
450     if (corner & BORDER_TOP)
451         dest_y = old_rect->y + (old_rect->height - dest_height);
452
453     con->rect = (Rect) { dest_x, dest_y, dest_width, dest_height };
454
455     /* TODO: don’t re-render the whole tree just because we change
456      * coordinates of a floating window */
457     tree_render();
458     x_push_changes(croot);
459 }
460
461 /*
462  * Called when the user clicked on a floating window while holding the
463  * floating_modifier and the right mouse button.
464  * Calls the drag_pointer function with the resize_window callback
465  *
466  */
467 void floating_resize_window(Con *con, const bool proportional,
468                             const xcb_button_press_event_t *event) {
469     DLOG("floating_resize_window\n");
470
471     /* corner saves the nearest corner to the original click. It contains
472      * a bitmask of the nearest borders (BORDER_LEFT, BORDER_RIGHT, …) */
473     border_t corner = 0;
474
475     if (event->event_x <= (con->rect.width / 2))
476         corner |= BORDER_LEFT;
477     else corner |= BORDER_RIGHT;
478
479     if (event->event_y <= (con->rect.height / 2))
480         corner |= BORDER_TOP;
481     else corner |= BORDER_BOTTOM;
482
483     struct resize_window_callback_params params = { corner, proportional, event };
484
485     drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, resize_window_callback, &params);
486 }
487
488 /*
489  * This function grabs your pointer and lets you drag stuff around (borders).
490  * Every time you move your mouse, an XCB_MOTION_NOTIFY event will be received
491  * and the given callback will be called with the parameters specified (client,
492  * border on which the click originally was), the original rect of the client,
493  * the event and the new coordinates (x, y).
494  *
495  */
496 void drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_window_t
497                 confine_to, border_t border, callback_t callback, const void *extra)
498 {
499     uint32_t new_x, new_y;
500     Rect old_rect = { 0, 0, 0, 0 };
501     if (con != NULL)
502         memcpy(&old_rect, &(con->rect), sizeof(Rect));
503
504     /* Grab the pointer */
505     xcb_grab_pointer_cookie_t cookie;
506     xcb_grab_pointer_reply_t *reply;
507     cookie = xcb_grab_pointer(conn,
508         false,               /* get all pointer events specified by the following mask */
509         root,                /* grab the root window */
510         XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION, /* which events to let through */
511         XCB_GRAB_MODE_ASYNC, /* pointer events should continue as normal */
512         XCB_GRAB_MODE_ASYNC, /* keyboard mode */
513         confine_to,          /* confine_to = in which window should the cursor stay */
514         XCB_NONE,            /* don’t display a special cursor */
515         XCB_CURRENT_TIME);
516
517     if ((reply = xcb_grab_pointer_reply(conn, cookie, NULL)) == NULL) {
518         ELOG("Could not grab pointer\n");
519         return;
520     }
521
522     free(reply);
523
524     /* Go into our own event loop */
525     xcb_flush(conn);
526
527     xcb_generic_event_t *inside_event, *last_motion_notify = NULL;
528     bool loop_done = false;
529     /* I’ve always wanted to have my own eventhandler… */
530     while (!loop_done && (inside_event = xcb_wait_for_event(conn))) {
531         /* We now handle all events we can get using xcb_poll_for_event */
532         do {
533             /* skip x11 errors */
534             if (inside_event->response_type == 0) {
535                 free(inside_event);
536                 continue;
537             }
538             /* Strip off the highest bit (set if the event is generated) */
539             int type = (inside_event->response_type & 0x7F);
540
541             switch (type) {
542                 case XCB_BUTTON_RELEASE:
543                     loop_done = true;
544                     break;
545
546                 case XCB_MOTION_NOTIFY:
547                     /* motion_notify events are saved for later */
548                     FREE(last_motion_notify);
549                     last_motion_notify = inside_event;
550                     break;
551
552                 case XCB_UNMAP_NOTIFY:
553                 case XCB_KEY_PRESS:
554                 case XCB_KEY_RELEASE:
555                     DLOG("Unmap-notify, aborting\n");
556                     handle_event(type, inside_event);
557                     loop_done = true;
558                     break;
559
560                 default:
561                     DLOG("Passing to original handler\n");
562                     /* Use original handler */
563                     handle_event(type, inside_event);
564                     break;
565             }
566             if (last_motion_notify != inside_event)
567                 free(inside_event);
568         } while ((inside_event = xcb_poll_for_event(conn)) != NULL);
569
570         if (last_motion_notify == NULL)
571             continue;
572
573         new_x = ((xcb_motion_notify_event_t*)last_motion_notify)->root_x;
574         new_y = ((xcb_motion_notify_event_t*)last_motion_notify)->root_y;
575
576         callback(con, &old_rect, new_x, new_y, extra);
577         FREE(last_motion_notify);
578     }
579
580     xcb_ungrab_pointer(conn, XCB_CURRENT_TIME);
581     xcb_flush(conn);
582 }
583
584 /*
585  * Repositions the CT_FLOATING_CON to have the coordinates specified by
586  * newrect, but only if the coordinates are not out-of-bounds. Also reassigns
587  * the floating con to a different workspace if this move was across different
588  * outputs.
589  *
590  */
591 void floating_reposition(Con *con, Rect newrect) {
592     /* Sanity check: Are the new coordinates on any output? If not, we
593      * ignore that request. */
594     Output *output = get_output_containing(
595         newrect.x + (newrect.width / 2),
596         newrect.y + (newrect.height / 2));
597
598     if (!output) {
599         ELOG("No output found at destination coordinates. Not repositioning.\n");
600         return;
601     }
602
603     con->rect = newrect;
604
605     floating_maybe_reassign_ws(con);
606     tree_render();
607 }
608
609 /*
610  * Fixes the coordinates of the floating window whenever the window gets
611  * reassigned to a different output (or when the output’s rect changes).
612  *
613  */
614 void floating_fix_coordinates(Con *con, Rect *old_rect, Rect *new_rect) {
615     DLOG("Fixing coordinates of floating window %p (rect (%d, %d), %d x %d)\n",
616          con, con->rect.x, con->rect.y, con->rect.width, con->rect.height);
617     DLOG("old_rect = (%d, %d), %d x %d\n",
618          old_rect->x, old_rect->y, old_rect->width, old_rect->height);
619     DLOG("new_rect = (%d, %d), %d x %d\n",
620          new_rect->x, new_rect->y, new_rect->width, new_rect->height);
621     /* First we get the x/y coordinates relative to the x/y coordinates
622      * of the output on which the window is on */
623     int32_t rel_x = (con->rect.x - old_rect->x);
624     int32_t rel_y = (con->rect.y - old_rect->y);
625     /* Then we calculate a fraction, for example 0.63 for a window
626      * which is at y = 1212 of a 1920 px high output */
627     DLOG("rel_x = %d, rel_y = %d, fraction_x = %f, fraction_y = %f, output->w = %d, output->h = %d\n",
628           rel_x, rel_y, (double)rel_x / old_rect->width, (double)rel_y / old_rect->height,
629           old_rect->width, old_rect->height);
630     /* Here we have to multiply at first. Or we will lose precision when not compiled with -msse2 */
631     con->rect.x = (int32_t)new_rect->x + (double)(rel_x * (int32_t)new_rect->width)  / (int32_t)old_rect->width;
632     con->rect.y = (int32_t)new_rect->y + (double)(rel_y * (int32_t)new_rect->height) / (int32_t)old_rect->height;
633     DLOG("Resulting coordinates: x = %d, y = %d\n", con->rect.x, con->rect.y);
634 }
635
636 #if 0
637 /*
638  * Moves the client 10px to the specified direction.
639  *
640  */
641 void floating_move(xcb_connection_t *conn, Client *currently_focused, direction_t direction) {
642         DLOG("floating move\n");
643
644         Rect destination = currently_focused->rect;
645         Rect *screen = &(currently_focused->workspace->output->rect);
646
647         switch (direction) {
648                 case D_LEFT:
649                         destination.x -= 10;
650                         break;
651                 case D_RIGHT:
652                         destination.x += 10;
653                         break;
654                 case D_UP:
655                         destination.y -= 10;
656                         break;
657                 case D_DOWN:
658                         destination.y += 10;
659                         break;
660                 /* to make static analyzers happy */
661                 default:
662                         break;
663         }
664
665         /* Prevent windows from vanishing completely */
666         if ((int32_t)(destination.x + destination.width - 5) <= (int32_t)screen->x ||
667             (int32_t)(destination.x + 5) >= (int32_t)(screen->x + screen->width) ||
668             (int32_t)(destination.y + destination.height - 5) <= (int32_t)screen->y ||
669             (int32_t)(destination.y + 5) >= (int32_t)(screen->y + screen->height)) {
670                 DLOG("boundary check failed, not moving\n");
671                 return;
672         }
673
674         currently_focused->rect = destination;
675         reposition_client(conn, currently_focused);
676
677         /* Because reposition_client does not send a faked configure event (only resize does),
678          * we need to initiate that on our own */
679         fake_absolute_configure_notify(conn, currently_focused);
680         /* fake_absolute_configure_notify flushes */
681 }
682
683 /*
684  * Hides all floating clients (or show them if they are currently hidden) on
685  * the specified workspace.
686  *
687  */
688 void floating_toggle_hide(xcb_connection_t *conn, Workspace *workspace) {
689         Client *client;
690
691         workspace->floating_hidden = !workspace->floating_hidden;
692         DLOG("floating_hidden is now: %d\n", workspace->floating_hidden);
693         TAILQ_FOREACH(client, &(workspace->floating_clients), floating_clients) {
694                 if (workspace->floating_hidden)
695                         client_unmap(conn, client);
696                 else client_map(conn, client);
697         }
698
699         /* If we just unmapped all floating windows we should ensure that the focus
700          * is set correctly, that ist, to the first non-floating client in stack */
701         if (workspace->floating_hidden)
702                 SLIST_FOREACH(client, &(workspace->focus_stack), focus_clients) {
703                         if (client_is_floating(client))
704                                 continue;
705                         set_focus(conn, client, true);
706                         return;
707                 }
708
709         xcb_flush(conn);
710 }
711 #endif