]> git.sur5r.net Git - i3/i3/blob - src/floating.c
Merge branch 'master' into next
[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     /* TODO: don’t add them when the user automatically puts new windows into
180      * 1pixel/borderless mode */
181     nc->rect.height += deco_height + 2;
182     nc->rect.width += 4;
183
184     /* Honor the X11 border */
185     nc->rect.height += con->border_width * 2;
186     nc->rect.width += con->border_width * 2;
187
188     /* Some clients (like GIMP’s color picker window) get mapped
189      * to (0, 0), so we push them to a reasonable position
190      * (centered over their leader) */
191     if (nc->rect.x == 0 && nc->rect.y == 0) {
192         Con *leader;
193         if (con->window && con->window->leader != XCB_NONE &&
194             (leader = con_by_window_id(con->window->leader)) != NULL) {
195             DLOG("Centering above leader\n");
196             nc->rect.x = leader->rect.x + (leader->rect.width / 2) - (nc->rect.width / 2);
197             nc->rect.y = leader->rect.y + (leader->rect.height / 2) - (nc->rect.height / 2);
198         } else {
199             /* center the window on workspace as fallback */
200             nc->rect.x = ws->rect.x + (ws->rect.width / 2) - (nc->rect.width / 2);
201             nc->rect.y = ws->rect.y + (ws->rect.height / 2) - (nc->rect.height / 2);
202         }
203     }
204
205     /* Sanity check: Are the coordinates on the appropriate output? If not, we
206      * need to change them */
207     Output *current_output = get_output_containing(nc->rect.x, nc->rect.y);
208     Con *correct_output = con_get_output(ws);
209     if (!current_output || current_output->con != correct_output) {
210         DLOG("This floating window is on the wrong output, fixing coordinates (currently (%d, %d))\n",
211              nc->rect.x, nc->rect.y);
212         /* Take the relative coordinates of the current output, then add them
213          * to the coordinate space of the correct output */
214         uint32_t rel_x = (nc->rect.x - (current_output ? current_output->con->rect.x : 0));
215         uint32_t rel_y = (nc->rect.y - (current_output ? current_output->con->rect.y : 0));
216         nc->rect.x = correct_output->rect.x + rel_x;
217         nc->rect.y = correct_output->rect.y + rel_y;
218     }
219
220     DLOG("Floating rect: (%d, %d) with %d x %d\n", nc->rect.x, nc->rect.y, nc->rect.width, nc->rect.height);
221
222     /* 3: attach the child to the new parent container */
223     con->parent = nc;
224     con->percent = 1.0;
225     con->floating = FLOATING_USER_ON;
226
227     /* 4: set the border style as specified with new_float */
228     if (automatic)
229         con->border_style = config.default_floating_border;
230
231     /* 5: Subtract the deco_height in order to make the floating window appear
232      * at precisely the position it specified in its original geometry (which
233      * is what applications might remember). */
234     deco_height = (con->border_style == BS_NORMAL ? config.font.height + 5 : 0);
235     nc->rect.y -= deco_height;
236
237     DLOG("Corrected y = %d (deco_height = %d)\n", nc->rect.y, deco_height);
238
239     TAILQ_INSERT_TAIL(&(nc->nodes_head), con, nodes);
240     TAILQ_INSERT_TAIL(&(nc->focus_head), con, focused);
241
242     /* render the cons to get initial window_rect correct */
243     render_con(nc, false);
244     render_con(con, false);
245
246     if (set_focus)
247         con_focus(con);
248
249     /* Check if we need to re-assign it to a different workspace because of its
250      * coordinates and exit if that was done successfully. */
251     if (floating_maybe_reassign_ws(nc))
252         return;
253
254     /* Sanitize coordinates: Check if they are on any output */
255     if (get_output_containing(nc->rect.x, nc->rect.y) != NULL)
256         return;
257
258     ELOG("No output found at destination coordinates, centering floating window on current ws\n");
259     nc->rect.x = ws->rect.x + (ws->rect.width / 2) - (nc->rect.width / 2);
260     nc->rect.y = ws->rect.y + (ws->rect.height / 2) - (nc->rect.height / 2);
261 }
262
263 void floating_disable(Con *con, bool automatic) {
264     if (!con_is_floating(con)) {
265         LOG("Container isn't floating, not doing anything.\n");
266         return;
267     }
268
269     Con *ws = con_get_workspace(con);
270
271     /* 1: detach from parent container */
272     TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes);
273     TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
274
275     /* 2: kill parent container */
276     TAILQ_REMOVE(&(con->parent->parent->floating_head), con->parent, floating_windows);
277     TAILQ_REMOVE(&(con->parent->parent->focus_head), con->parent, focused);
278     tree_close(con->parent, DONT_KILL_WINDOW, true, false);
279
280     /* 3: re-attach to the parent of the currently focused con on the workspace
281      * this floating con was on */
282     Con *focused = con_descend_tiling_focused(ws);
283
284     /* if there is no other container on this workspace, focused will be the
285      * workspace itself */
286     if (focused->type == CT_WORKSPACE)
287         con->parent = focused;
288     else con->parent = focused->parent;
289
290     /* con_fix_percent will adjust the percent value */
291     con->percent = 0.0;
292
293     con->floating = FLOATING_USER_OFF;
294
295     con_attach(con, con->parent, false);
296
297     con_fix_percent(con->parent);
298     // TODO: don’t influence focus handling when Con was not focused before.
299     con_focus(con);
300 }
301
302 /*
303  * Toggles floating mode for the given container.
304  *
305  * If the automatic flag is set to true, this was an automatic update by a change of the
306  * window class from the application which can be overwritten by the user.
307  *
308  */
309 void toggle_floating_mode(Con *con, bool automatic) {
310     /* see if the client is already floating */
311     if (con_is_floating(con)) {
312         LOG("already floating, re-setting to tiling\n");
313
314         floating_disable(con, automatic);
315         return;
316     }
317
318     floating_enable(con, automatic);
319 }
320
321 /*
322  * Raises the given container in the list of floating containers
323  *
324  */
325 void floating_raise_con(Con *con) {
326     DLOG("Raising floating con %p / %s\n", con, con->name);
327     TAILQ_REMOVE(&(con->parent->floating_head), con, floating_windows);
328     TAILQ_INSERT_TAIL(&(con->parent->floating_head), con, floating_windows);
329 }
330
331 /*
332  * Checks if con’s coordinates are within its workspace and re-assigns it to
333  * the actual workspace if not.
334  *
335  */
336 bool floating_maybe_reassign_ws(Con *con) {
337     Output *output = get_output_containing(
338         con->rect.x + (con->rect.width / 2),
339         con->rect.y + (con->rect.height / 2));
340
341     if (!output) {
342         ELOG("No output found at destination coordinates?\n");
343         return false;
344     }
345
346     if (con_get_output(con) == output->con) {
347         DLOG("still the same ws\n");
348         return false;
349     }
350
351     DLOG("Need to re-assign!\n");
352
353     Con *content = output_get_content(output->con);
354     Con *ws = TAILQ_FIRST(&(content->focus_head));
355     DLOG("Moving con %p / %s to workspace %p / %s\n", con, con->name, ws, ws->name);
356     con_move_to_workspace(con, ws, false, true);
357     con_focus(con_descend_focused(con));
358     return true;
359 }
360
361 DRAGGING_CB(drag_window_callback) {
362     const struct xcb_button_press_event_t *event = extra;
363
364     /* Reposition the client correctly while moving */
365     con->rect.x = old_rect->x + (new_x - event->root_x);
366     con->rect.y = old_rect->y + (new_y - event->root_y);
367
368     render_con(con, false);
369     x_push_node(con);
370     xcb_flush(conn);
371
372     /* Check if we cross workspace boundaries while moving */
373     if (!floating_maybe_reassign_ws(con))
374         return;
375     tree_render();
376 }
377
378 /*
379  * Called when the user clicked on the titlebar of a floating window.
380  * Calls the drag_pointer function with the drag_window callback
381  *
382  */
383 void floating_drag_window(Con *con, const xcb_button_press_event_t *event) {
384     DLOG("floating_drag_window\n");
385
386     /* Push changes before dragging, so that the window gets raised now and not
387      * after the user releases the mouse button */
388     tree_render();
389
390     /* Drag the window */
391     drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, drag_window_callback, event);
392     tree_render();
393 }
394
395 /*
396  * This is an ugly data structure which we need because there is no standard
397  * way of having nested functions (only available as a gcc extension at the
398  * moment, clang doesn’t support it) or blocks (only available as a clang
399  * extension and only on Mac OS X systems at the moment).
400  *
401  */
402 struct resize_window_callback_params {
403     const border_t corner;
404     const bool proportional;
405     const xcb_button_press_event_t *event;
406 };
407
408 DRAGGING_CB(resize_window_callback) {
409     const struct resize_window_callback_params *params = extra;
410     const xcb_button_press_event_t *event = params->event;
411     border_t corner = params->corner;
412
413     int32_t dest_x = con->rect.x;
414     int32_t dest_y = con->rect.y;
415     uint32_t dest_width;
416     uint32_t dest_height;
417
418     double ratio = (double) old_rect->width / old_rect->height;
419
420     /* First guess: We resize by exactly the amount the mouse moved,
421      * taking into account in which corner the client was grabbed */
422     if (corner & BORDER_LEFT)
423         dest_width = old_rect->width - (new_x - event->root_x);
424     else dest_width = old_rect->width + (new_x - event->root_x);
425
426     if (corner & BORDER_TOP)
427         dest_height = old_rect->height - (new_y - event->root_y);
428     else dest_height = old_rect->height + (new_y - event->root_y);
429
430     /* Obey minimum window size */
431     Rect minimum = con_minimum_size(con);
432     dest_width = max(dest_width, minimum.width);
433     dest_height = max(dest_height, minimum.height);
434
435     /* User wants to keep proportions, so we may have to adjust our values */
436     if (params->proportional) {
437         dest_width = max(dest_width, (int) (dest_height * ratio));
438         dest_height = max(dest_height, (int) (dest_width / ratio));
439     }
440
441     /* If not the lower right corner is grabbed, we must also reposition
442      * the client by exactly the amount we resized it */
443     if (corner & BORDER_LEFT)
444         dest_x = old_rect->x + (old_rect->width - dest_width);
445
446     if (corner & BORDER_TOP)
447         dest_y = old_rect->y + (old_rect->height - dest_height);
448
449     con->rect = (Rect) { dest_x, dest_y, dest_width, dest_height };
450
451     /* TODO: don’t re-render the whole tree just because we change
452      * coordinates of a floating window */
453     tree_render();
454     x_push_changes(croot);
455 }
456
457 /*
458  * Called when the user clicked on a floating window while holding the
459  * floating_modifier and the right mouse button.
460  * Calls the drag_pointer function with the resize_window callback
461  *
462  */
463 void floating_resize_window(Con *con, const bool proportional,
464                             const xcb_button_press_event_t *event) {
465     DLOG("floating_resize_window\n");
466
467     /* corner saves the nearest corner to the original click. It contains
468      * a bitmask of the nearest borders (BORDER_LEFT, BORDER_RIGHT, …) */
469     border_t corner = 0;
470
471     if (event->event_x <= (con->rect.width / 2))
472         corner |= BORDER_LEFT;
473     else corner |= BORDER_RIGHT;
474
475     if (event->event_y <= (con->rect.height / 2))
476         corner |= BORDER_TOP;
477     else corner |= BORDER_BOTTOM;
478
479     struct resize_window_callback_params params = { corner, proportional, event };
480
481     drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, resize_window_callback, &params);
482 }
483
484 /*
485  * This function grabs your pointer and lets you drag stuff around (borders).
486  * Every time you move your mouse, an XCB_MOTION_NOTIFY event will be received
487  * and the given callback will be called with the parameters specified (client,
488  * border on which the click originally was), the original rect of the client,
489  * the event and the new coordinates (x, y).
490  *
491  */
492 void drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_window_t
493                 confine_to, border_t border, callback_t callback, const void *extra)
494 {
495     uint32_t new_x, new_y;
496     Rect old_rect;
497     if (con != NULL)
498         memcpy(&old_rect, &(con->rect), sizeof(Rect));
499
500     /* Grab the pointer */
501     xcb_grab_pointer_cookie_t cookie;
502     xcb_grab_pointer_reply_t *reply;
503     cookie = xcb_grab_pointer(conn,
504         false,               /* get all pointer events specified by the following mask */
505         root,                /* grab the root window */
506         XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION, /* which events to let through */
507         XCB_GRAB_MODE_ASYNC, /* pointer events should continue as normal */
508         XCB_GRAB_MODE_ASYNC, /* keyboard mode */
509         confine_to,          /* confine_to = in which window should the cursor stay */
510         XCB_NONE,            /* don’t display a special cursor */
511         XCB_CURRENT_TIME);
512
513     if ((reply = xcb_grab_pointer_reply(conn, cookie, NULL)) == NULL) {
514         ELOG("Could not grab pointer\n");
515         return;
516     }
517
518     free(reply);
519
520     /* Go into our own event loop */
521     xcb_flush(conn);
522
523     xcb_generic_event_t *inside_event, *last_motion_notify = NULL;
524     bool loop_done = false;
525     /* I’ve always wanted to have my own eventhandler… */
526     while (!loop_done && (inside_event = xcb_wait_for_event(conn))) {
527         /* We now handle all events we can get using xcb_poll_for_event */
528         do {
529             /* skip x11 errors */
530             if (inside_event->response_type == 0) {
531                 free(inside_event);
532                 continue;
533             }
534             /* Strip off the highest bit (set if the event is generated) */
535             int type = (inside_event->response_type & 0x7F);
536
537             switch (type) {
538                 case XCB_BUTTON_RELEASE:
539                     loop_done = true;
540                     break;
541
542                 case XCB_MOTION_NOTIFY:
543                     /* motion_notify events are saved for later */
544                     FREE(last_motion_notify);
545                     last_motion_notify = inside_event;
546                     break;
547
548                 case XCB_UNMAP_NOTIFY:
549                 case XCB_KEY_PRESS:
550                 case XCB_KEY_RELEASE:
551                     DLOG("Unmap-notify, aborting\n");
552                     handle_event(type, inside_event);
553                     loop_done = true;
554                     break;
555
556                 default:
557                     DLOG("Passing to original handler\n");
558                     /* Use original handler */
559                     handle_event(type, inside_event);
560                     break;
561             }
562             if (last_motion_notify != inside_event)
563                 free(inside_event);
564         } while ((inside_event = xcb_poll_for_event(conn)) != NULL);
565
566         if (last_motion_notify == NULL)
567             continue;
568
569         new_x = ((xcb_motion_notify_event_t*)last_motion_notify)->root_x;
570         new_y = ((xcb_motion_notify_event_t*)last_motion_notify)->root_y;
571
572         callback(con, &old_rect, new_x, new_y, extra);
573         FREE(last_motion_notify);
574     }
575
576     xcb_ungrab_pointer(conn, XCB_CURRENT_TIME);
577     xcb_flush(conn);
578 }
579
580 /*
581  * Repositions the CT_FLOATING_CON to have the coordinates specified by
582  * newrect, but only if the coordinates are not out-of-bounds. Also reassigns
583  * the floating con to a different workspace if this move was across different
584  * outputs.
585  *
586  */
587 void floating_reposition(Con *con, Rect newrect) {
588     /* Sanity check: Are the new coordinates on any output? If not, we
589      * ignore that request. */
590     Output *output = get_output_containing(
591         newrect.x + (newrect.width / 2),
592         newrect.y + (newrect.height / 2));
593
594     if (!output) {
595         ELOG("No output found at destination coordinates. Not repositioning.\n");
596         return;
597     }
598
599     con->rect = newrect;
600
601     floating_maybe_reassign_ws(con);
602     tree_render();
603 }
604
605 /*
606  * Fixes the coordinates of the floating window whenever the window gets
607  * reassigned to a different output (or when the output’s rect changes).
608  *
609  */
610 void floating_fix_coordinates(Con *con, Rect *old_rect, Rect *new_rect) {
611     DLOG("Fixing coordinates of floating window %p (rect (%d, %d), %d x %d)\n",
612          con, con->rect.x, con->rect.y, con->rect.width, con->rect.height);
613     DLOG("old_rect = (%d, %d), %d x %d\n",
614          old_rect->x, old_rect->y, old_rect->width, old_rect->height);
615     DLOG("new_rect = (%d, %d), %d x %d\n",
616          new_rect->x, new_rect->y, new_rect->width, new_rect->height);
617     /* First we get the x/y coordinates relative to the x/y coordinates
618      * of the output on which the window is on */
619     int32_t rel_x = (con->rect.x - old_rect->x);
620     int32_t rel_y = (con->rect.y - old_rect->y);
621     /* Then we calculate a fraction, for example 0.63 for a window
622      * which is at y = 1212 of a 1920 px high output */
623     DLOG("rel_x = %d, rel_y = %d, fraction_x = %f, fraction_y = %f, output->w = %d, output->h = %d\n",
624           rel_x, rel_y, (double)rel_x / old_rect->width, (double)rel_y / old_rect->height,
625           old_rect->width, old_rect->height);
626     /* Here we have to multiply at first. Or we will lose precision when not compiled with -msse2 */
627     con->rect.x = (int32_t)new_rect->x + (double)(rel_x * (int32_t)new_rect->width)  / (int32_t)old_rect->width;
628     con->rect.y = (int32_t)new_rect->y + (double)(rel_y * (int32_t)new_rect->height) / (int32_t)old_rect->height;
629     DLOG("Resulting coordinates: x = %d, y = %d\n", con->rect.x, con->rect.y);
630 }
631
632 #if 0
633 /*
634  * Moves the client 10px to the specified direction.
635  *
636  */
637 void floating_move(xcb_connection_t *conn, Client *currently_focused, direction_t direction) {
638         DLOG("floating move\n");
639
640         Rect destination = currently_focused->rect;
641         Rect *screen = &(currently_focused->workspace->output->rect);
642
643         switch (direction) {
644                 case D_LEFT:
645                         destination.x -= 10;
646                         break;
647                 case D_RIGHT:
648                         destination.x += 10;
649                         break;
650                 case D_UP:
651                         destination.y -= 10;
652                         break;
653                 case D_DOWN:
654                         destination.y += 10;
655                         break;
656                 /* to make static analyzers happy */
657                 default:
658                         break;
659         }
660
661         /* Prevent windows from vanishing completely */
662         if ((int32_t)(destination.x + destination.width - 5) <= (int32_t)screen->x ||
663             (int32_t)(destination.x + 5) >= (int32_t)(screen->x + screen->width) ||
664             (int32_t)(destination.y + destination.height - 5) <= (int32_t)screen->y ||
665             (int32_t)(destination.y + 5) >= (int32_t)(screen->y + screen->height)) {
666                 DLOG("boundary check failed, not moving\n");
667                 return;
668         }
669
670         currently_focused->rect = destination;
671         reposition_client(conn, currently_focused);
672
673         /* Because reposition_client does not send a faked configure event (only resize does),
674          * we need to initiate that on our own */
675         fake_absolute_configure_notify(conn, currently_focused);
676         /* fake_absolute_configure_notify flushes */
677 }
678
679 /*
680  * Hides all floating clients (or show them if they are currently hidden) on
681  * the specified workspace.
682  *
683  */
684 void floating_toggle_hide(xcb_connection_t *conn, Workspace *workspace) {
685         Client *client;
686
687         workspace->floating_hidden = !workspace->floating_hidden;
688         DLOG("floating_hidden is now: %d\n", workspace->floating_hidden);
689         TAILQ_FOREACH(client, &(workspace->floating_clients), floating_clients) {
690                 if (workspace->floating_hidden)
691                         client_unmap(conn, client);
692                 else client_map(conn, client);
693         }
694
695         /* If we just unmapped all floating windows we should ensure that the focus
696          * is set correctly, that ist, to the first non-floating client in stack */
697         if (workspace->floating_hidden)
698                 SLIST_FOREACH(client, &(workspace->focus_stack), focus_clients) {
699                         if (client_is_floating(client))
700                                 continue;
701                         set_focus(conn, client, true);
702                         return;
703                 }
704
705         xcb_flush(conn);
706 }
707 #endif