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