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