i3
|
00001 /* 00002 * vim:ts=4:sw=4:expandtab 00003 * 00004 * i3 - an improved dynamic tiling window manager 00005 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE) 00006 * 00007 * floating.c: Floating windows. 00008 * 00009 */ 00010 #include "all.h" 00011 00012 extern xcb_connection_t *conn; 00013 00014 void floating_enable(Con *con, bool automatic) { 00015 bool set_focus = (con == focused); 00016 00017 if (con->parent && con->parent->type == CT_DOCKAREA) { 00018 LOG("Container is a dock window, not enabling floating mode.\n"); 00019 return; 00020 } 00021 00022 if (con_is_floating(con)) { 00023 LOG("Container is already in floating mode, not doing anything.\n"); 00024 return; 00025 } 00026 00027 /* 1: If the container is a workspace container, we need to create a new 00028 * split-container with the same orientation and make that one floating. We 00029 * cannot touch the workspace container itself because floating containers 00030 * are children of the workspace. */ 00031 if (con->type == CT_WORKSPACE) { 00032 LOG("This is a workspace, creating new container around content\n"); 00033 if (con_num_children(con) == 0) { 00034 LOG("Workspace is empty, aborting\n"); 00035 return; 00036 } 00037 /* TODO: refactor this with src/con.c:con_set_layout */ 00038 Con *new = con_new(NULL, NULL); 00039 new->parent = con; 00040 new->orientation = con->orientation; 00041 00042 /* since the new container will be set into floating mode directly 00043 * afterwards, we need to copy the workspace rect. */ 00044 memcpy(&(new->rect), &(con->rect), sizeof(Rect)); 00045 00046 Con *old_focused = TAILQ_FIRST(&(con->focus_head)); 00047 if (old_focused == TAILQ_END(&(con->focus_head))) 00048 old_focused = NULL; 00049 00050 /* 4: move the existing cons of this workspace below the new con */ 00051 DLOG("Moving cons\n"); 00052 Con *child; 00053 while (!TAILQ_EMPTY(&(con->nodes_head))) { 00054 child = TAILQ_FIRST(&(con->nodes_head)); 00055 con_detach(child); 00056 con_attach(child, new, true); 00057 } 00058 00059 /* 4: attach the new split container to the workspace */ 00060 DLOG("Attaching new split to ws\n"); 00061 con_attach(new, con, false); 00062 00063 if (old_focused) 00064 con_focus(old_focused); 00065 00066 con = new; 00067 set_focus = false; 00068 } 00069 00070 /* 1: detach the container from its parent */ 00071 /* TODO: refactor this with tree_close() */ 00072 TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes); 00073 TAILQ_REMOVE(&(con->parent->focus_head), con, focused); 00074 00075 con_fix_percent(con->parent); 00076 00077 /* 2: create a new container to render the decoration on, add 00078 * it as a floating window to the workspace */ 00079 Con *nc = con_new(NULL, NULL); 00080 /* we need to set the parent afterwards instead of passing it as an 00081 * argument to con_new() because nc would be inserted into the tiling layer 00082 * otherwise. */ 00083 Con *ws = con_get_workspace(con); 00084 nc->parent = ws; 00085 nc->orientation = NO_ORIENTATION; 00086 nc->type = CT_FLOATING_CON; 00087 /* We insert nc already, even though its rect is not yet calculated. This 00088 * is necessary because otherwise the workspace might be empty (and get 00089 * closed in tree_close()) even though it’s not. */ 00090 TAILQ_INSERT_TAIL(&(ws->floating_head), nc, floating_windows); 00091 TAILQ_INSERT_TAIL(&(ws->focus_head), nc, focused); 00092 00093 /* check if the parent container is empty and close it if so */ 00094 if ((con->parent->type == CT_CON || con->parent->type == CT_FLOATING_CON) && 00095 con_num_children(con->parent) == 0) { 00096 DLOG("Old container empty after setting this child to floating, closing\n"); 00097 tree_close(con->parent, DONT_KILL_WINDOW, false, false); 00098 } 00099 00100 char *name; 00101 sasprintf(&name, "[i3 con] floatingcon around %p", con); 00102 x_set_name(nc, name); 00103 free(name); 00104 00105 /* find the height for the decorations */ 00106 int deco_height = config.font.height + 5; 00107 00108 DLOG("Original rect: (%d, %d) with %d x %d\n", con->rect.x, con->rect.y, con->rect.width, con->rect.height); 00109 DLOG("Geometry = (%d, %d) with %d x %d\n", con->geometry.x, con->geometry.y, con->geometry.width, con->geometry.height); 00110 Rect zero = { 0, 0, 0, 0 }; 00111 nc->rect = con->geometry; 00112 /* If the geometry was not set (split containers), we need to determine a 00113 * sensible one by combining the geometry of all children */ 00114 if (memcmp(&(nc->rect), &zero, sizeof(Rect)) == 0) { 00115 DLOG("Geometry not set, combining children\n"); 00116 Con *child; 00117 TAILQ_FOREACH(child, &(con->nodes_head), nodes) { 00118 DLOG("child geometry: %d x %d\n", child->geometry.width, child->geometry.height); 00119 nc->rect.width += child->geometry.width; 00120 nc->rect.height = max(nc->rect.height, child->geometry.height); 00121 } 00122 } 00123 /* Raise the width/height to at least 75x50 (minimum size for windows) */ 00124 nc->rect.width = max(nc->rect.width, 75); 00125 nc->rect.height = max(nc->rect.height, 50); 00126 /* add pixels for the decoration */ 00127 /* TODO: don’t add them when the user automatically puts new windows into 00128 * 1pixel/borderless mode */ 00129 nc->rect.height += deco_height + 2; 00130 nc->rect.width += 4; 00131 00132 /* Honor the X11 border */ 00133 nc->rect.height += con->border_width * 2; 00134 nc->rect.width += con->border_width * 2; 00135 00136 /* Some clients (like GIMP’s color picker window) get mapped 00137 * to (0, 0), so we push them to a reasonable position 00138 * (centered over their leader) */ 00139 if (nc->rect.x == 0 && nc->rect.y == 0) { 00140 Con *leader; 00141 if (con->window && con->window->leader != XCB_NONE && 00142 (leader = con_by_window_id(con->window->leader)) != NULL) { 00143 DLOG("Centering above leader\n"); 00144 nc->rect.x = leader->rect.x + (leader->rect.width / 2) - (nc->rect.width / 2); 00145 nc->rect.y = leader->rect.y + (leader->rect.height / 2) - (nc->rect.height / 2); 00146 } else { 00147 /* center the window on workspace as fallback */ 00148 nc->rect.x = ws->rect.x + (ws->rect.width / 2) - (nc->rect.width / 2); 00149 nc->rect.y = ws->rect.y + (ws->rect.height / 2) - (nc->rect.height / 2); 00150 } 00151 } 00152 00153 /* Sanity check: Are the coordinates on the appropriate output? If not, we 00154 * need to change them */ 00155 Output *current_output = get_output_containing(nc->rect.x, nc->rect.y); 00156 Con *correct_output = con_get_output(ws); 00157 if (!current_output || current_output->con != correct_output) { 00158 DLOG("This floating window is on the wrong output, fixing coordinates (currently (%d, %d))\n", 00159 nc->rect.x, nc->rect.y); 00160 /* Take the relative coordinates of the current output, then add them 00161 * to the coordinate space of the correct output */ 00162 uint32_t rel_x = (nc->rect.x - (current_output ? current_output->con->rect.x : 0)); 00163 uint32_t rel_y = (nc->rect.y - (current_output ? current_output->con->rect.y : 0)); 00164 nc->rect.x = correct_output->rect.x + rel_x; 00165 nc->rect.y = correct_output->rect.y + rel_y; 00166 } 00167 00168 DLOG("Floating rect: (%d, %d) with %d x %d\n", nc->rect.x, nc->rect.y, nc->rect.width, nc->rect.height); 00169 00170 /* 3: attach the child to the new parent container */ 00171 con->parent = nc; 00172 con->percent = 1.0; 00173 con->floating = FLOATING_USER_ON; 00174 00175 /* 4: set the border style as specified with new_float */ 00176 if (automatic) 00177 con->border_style = config.default_floating_border; 00178 00179 /* 5: Subtract the deco_height in order to make the floating window appear 00180 * at precisely the position it specified in its original geometry (which 00181 * is what applications might remember). */ 00182 deco_height = (con->border_style == BS_NORMAL ? config.font.height + 5 : 0); 00183 nc->rect.y -= deco_height; 00184 00185 DLOG("Corrected y = %d (deco_height = %d)\n", nc->rect.y, deco_height); 00186 00187 TAILQ_INSERT_TAIL(&(nc->nodes_head), con, nodes); 00188 TAILQ_INSERT_TAIL(&(nc->focus_head), con, focused); 00189 00190 /* render the cons to get initial window_rect correct */ 00191 render_con(nc, false); 00192 render_con(con, false); 00193 00194 if (set_focus) 00195 con_focus(con); 00196 00197 /* Check if we need to re-assign it to a different workspace because of its 00198 * coordinates and exit if that was done successfully. */ 00199 if (floating_maybe_reassign_ws(nc)) 00200 return; 00201 00202 /* Sanitize coordinates: Check if they are on any output */ 00203 if (get_output_containing(nc->rect.x, nc->rect.y) != NULL) 00204 return; 00205 00206 ELOG("No output found at destination coordinates, centering floating window on current ws\n"); 00207 nc->rect.x = ws->rect.x + (ws->rect.width / 2) - (nc->rect.width / 2); 00208 nc->rect.y = ws->rect.y + (ws->rect.height / 2) - (nc->rect.height / 2); 00209 } 00210 00211 void floating_disable(Con *con, bool automatic) { 00212 if (!con_is_floating(con)) { 00213 LOG("Container isn't floating, not doing anything.\n"); 00214 return; 00215 } 00216 00217 Con *ws = con_get_workspace(con); 00218 00219 /* 1: detach from parent container */ 00220 TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes); 00221 TAILQ_REMOVE(&(con->parent->focus_head), con, focused); 00222 00223 /* 2: kill parent container */ 00224 TAILQ_REMOVE(&(con->parent->parent->floating_head), con->parent, floating_windows); 00225 TAILQ_REMOVE(&(con->parent->parent->focus_head), con->parent, focused); 00226 tree_close(con->parent, DONT_KILL_WINDOW, false, false); 00227 00228 /* 3: re-attach to the parent of the currently focused con on the workspace 00229 * this floating con was on */ 00230 Con *focused = con_descend_tiling_focused(ws); 00231 00232 /* if there is no other container on this workspace, focused will be the 00233 * workspace itself */ 00234 if (focused->type == CT_WORKSPACE) 00235 con->parent = focused; 00236 else con->parent = focused->parent; 00237 00238 /* con_fix_percent will adjust the percent value */ 00239 con->percent = 0.0; 00240 00241 TAILQ_INSERT_TAIL(&(con->parent->nodes_head), con, nodes); 00242 TAILQ_INSERT_TAIL(&(con->parent->focus_head), con, focused); 00243 00244 con->floating = FLOATING_USER_OFF; 00245 00246 con_fix_percent(con->parent); 00247 // TODO: don’t influence focus handling when Con was not focused before. 00248 con_focus(con); 00249 } 00250 00251 /* 00252 * Toggles floating mode for the given container. 00253 * 00254 * If the automatic flag is set to true, this was an automatic update by a change of the 00255 * window class from the application which can be overwritten by the user. 00256 * 00257 */ 00258 void toggle_floating_mode(Con *con, bool automatic) { 00259 /* see if the client is already floating */ 00260 if (con_is_floating(con)) { 00261 LOG("already floating, re-setting to tiling\n"); 00262 00263 floating_disable(con, automatic); 00264 return; 00265 } 00266 00267 floating_enable(con, automatic); 00268 } 00269 00270 /* 00271 * Raises the given container in the list of floating containers 00272 * 00273 */ 00274 void floating_raise_con(Con *con) { 00275 DLOG("Raising floating con %p / %s\n", con, con->name); 00276 TAILQ_REMOVE(&(con->parent->floating_head), con, floating_windows); 00277 TAILQ_INSERT_TAIL(&(con->parent->floating_head), con, floating_windows); 00278 } 00279 00280 /* 00281 * Checks if con’s coordinates are within its workspace and re-assigns it to 00282 * the actual workspace if not. 00283 * 00284 */ 00285 bool floating_maybe_reassign_ws(Con *con) { 00286 Output *output = get_output_containing( 00287 con->rect.x + (con->rect.width / 2), 00288 con->rect.y + (con->rect.height / 2)); 00289 00290 if (!output) { 00291 ELOG("No output found at destination coordinates?\n"); 00292 return false; 00293 } 00294 00295 if (con_get_output(con) == output->con) { 00296 DLOG("still the same ws\n"); 00297 return false; 00298 } 00299 00300 DLOG("Need to re-assign!\n"); 00301 00302 Con *content = output_get_content(output->con); 00303 Con *ws = TAILQ_FIRST(&(content->focus_head)); 00304 DLOG("Moving con %p / %s to workspace %p / %s\n", con, con->name, ws, ws->name); 00305 con_move_to_workspace(con, ws, false, true); 00306 con_focus(con_descend_focused(con)); 00307 return true; 00308 } 00309 00310 DRAGGING_CB(drag_window_callback) { 00311 const struct xcb_button_press_event_t *event = extra; 00312 00313 /* Reposition the client correctly while moving */ 00314 con->rect.x = old_rect->x + (new_x - event->root_x); 00315 con->rect.y = old_rect->y + (new_y - event->root_y); 00316 00317 render_con(con, false); 00318 x_push_node(con); 00319 xcb_flush(conn); 00320 00321 /* Check if we cross workspace boundaries while moving */ 00322 if (!floating_maybe_reassign_ws(con)) 00323 return; 00324 tree_render(); 00325 } 00326 00327 /* 00328 * Called when the user clicked on the titlebar of a floating window. 00329 * Calls the drag_pointer function with the drag_window callback 00330 * 00331 */ 00332 void floating_drag_window(Con *con, const xcb_button_press_event_t *event) { 00333 DLOG("floating_drag_window\n"); 00334 00335 /* Push changes before dragging, so that the window gets raised now and not 00336 * after the user releases the mouse button */ 00337 tree_render(); 00338 00339 /* Drag the window */ 00340 drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, drag_window_callback, event); 00341 tree_render(); 00342 } 00343 00344 /* 00345 * This is an ugly data structure which we need because there is no standard 00346 * way of having nested functions (only available as a gcc extension at the 00347 * moment, clang doesn’t support it) or blocks (only available as a clang 00348 * extension and only on Mac OS X systems at the moment). 00349 * 00350 */ 00351 struct resize_window_callback_params { 00352 const border_t corner; 00353 const bool proportional; 00354 const xcb_button_press_event_t *event; 00355 }; 00356 00357 DRAGGING_CB(resize_window_callback) { 00358 const struct resize_window_callback_params *params = extra; 00359 const xcb_button_press_event_t *event = params->event; 00360 border_t corner = params->corner; 00361 00362 int32_t dest_x = con->rect.x; 00363 int32_t dest_y = con->rect.y; 00364 uint32_t dest_width; 00365 uint32_t dest_height; 00366 00367 double ratio = (double) old_rect->width / old_rect->height; 00368 00369 /* First guess: We resize by exactly the amount the mouse moved, 00370 * taking into account in which corner the client was grabbed */ 00371 if (corner & BORDER_LEFT) 00372 dest_width = old_rect->width - (new_x - event->root_x); 00373 else dest_width = old_rect->width + (new_x - event->root_x); 00374 00375 if (corner & BORDER_TOP) 00376 dest_height = old_rect->height - (new_y - event->root_y); 00377 else dest_height = old_rect->height + (new_y - event->root_y); 00378 00379 /* Obey minimum window size */ 00380 Rect minimum = con_minimum_size(con); 00381 dest_width = max(dest_width, minimum.width); 00382 dest_height = max(dest_height, minimum.height); 00383 00384 /* User wants to keep proportions, so we may have to adjust our values */ 00385 if (params->proportional) { 00386 dest_width = max(dest_width, (int) (dest_height * ratio)); 00387 dest_height = max(dest_height, (int) (dest_width / ratio)); 00388 } 00389 00390 /* If not the lower right corner is grabbed, we must also reposition 00391 * the client by exactly the amount we resized it */ 00392 if (corner & BORDER_LEFT) 00393 dest_x = old_rect->x + (old_rect->width - dest_width); 00394 00395 if (corner & BORDER_TOP) 00396 dest_y = old_rect->y + (old_rect->height - dest_height); 00397 00398 con->rect = (Rect) { dest_x, dest_y, dest_width, dest_height }; 00399 00400 /* TODO: don’t re-render the whole tree just because we change 00401 * coordinates of a floating window */ 00402 tree_render(); 00403 x_push_changes(croot); 00404 } 00405 00406 /* 00407 * Called when the user clicked on a floating window while holding the 00408 * floating_modifier and the right mouse button. 00409 * Calls the drag_pointer function with the resize_window callback 00410 * 00411 */ 00412 void floating_resize_window(Con *con, const bool proportional, 00413 const xcb_button_press_event_t *event) { 00414 DLOG("floating_resize_window\n"); 00415 00416 /* corner saves the nearest corner to the original click. It contains 00417 * a bitmask of the nearest borders (BORDER_LEFT, BORDER_RIGHT, …) */ 00418 border_t corner = 0; 00419 00420 if (event->event_x <= (con->rect.width / 2)) 00421 corner |= BORDER_LEFT; 00422 else corner |= BORDER_RIGHT; 00423 00424 if (event->event_y <= (con->rect.height / 2)) 00425 corner |= BORDER_TOP; 00426 else corner |= BORDER_BOTTOM; 00427 00428 struct resize_window_callback_params params = { corner, proportional, event }; 00429 00430 drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, resize_window_callback, ¶ms); 00431 } 00432 00433 /* 00434 * This function grabs your pointer and lets you drag stuff around (borders). 00435 * Every time you move your mouse, an XCB_MOTION_NOTIFY event will be received 00436 * and the given callback will be called with the parameters specified (client, 00437 * border on which the click originally was), the original rect of the client, 00438 * the event and the new coordinates (x, y). 00439 * 00440 */ 00441 void drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_window_t 00442 confine_to, border_t border, callback_t callback, const void *extra) 00443 { 00444 uint32_t new_x, new_y; 00445 Rect old_rect; 00446 if (con != NULL) 00447 memcpy(&old_rect, &(con->rect), sizeof(Rect)); 00448 00449 /* Grab the pointer */ 00450 xcb_grab_pointer_cookie_t cookie; 00451 xcb_grab_pointer_reply_t *reply; 00452 cookie = xcb_grab_pointer(conn, 00453 false, /* get all pointer events specified by the following mask */ 00454 root, /* grab the root window */ 00455 XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION, /* which events to let through */ 00456 XCB_GRAB_MODE_ASYNC, /* pointer events should continue as normal */ 00457 XCB_GRAB_MODE_ASYNC, /* keyboard mode */ 00458 confine_to, /* confine_to = in which window should the cursor stay */ 00459 XCB_NONE, /* don’t display a special cursor */ 00460 XCB_CURRENT_TIME); 00461 00462 if ((reply = xcb_grab_pointer_reply(conn, cookie, NULL)) == NULL) { 00463 ELOG("Could not grab pointer\n"); 00464 return; 00465 } 00466 00467 free(reply); 00468 00469 /* Go into our own event loop */ 00470 xcb_flush(conn); 00471 00472 xcb_generic_event_t *inside_event, *last_motion_notify = NULL; 00473 bool loop_done = false; 00474 /* I’ve always wanted to have my own eventhandler… */ 00475 while (!loop_done && (inside_event = xcb_wait_for_event(conn))) { 00476 /* We now handle all events we can get using xcb_poll_for_event */ 00477 do { 00478 /* skip x11 errors */ 00479 if (inside_event->response_type == 0) { 00480 free(inside_event); 00481 continue; 00482 } 00483 /* Strip off the highest bit (set if the event is generated) */ 00484 int type = (inside_event->response_type & 0x7F); 00485 00486 switch (type) { 00487 case XCB_BUTTON_RELEASE: 00488 loop_done = true; 00489 break; 00490 00491 case XCB_MOTION_NOTIFY: 00492 /* motion_notify events are saved for later */ 00493 FREE(last_motion_notify); 00494 last_motion_notify = inside_event; 00495 break; 00496 00497 case XCB_UNMAP_NOTIFY: 00498 case XCB_KEY_PRESS: 00499 case XCB_KEY_RELEASE: 00500 DLOG("Unmap-notify, aborting\n"); 00501 handle_event(type, inside_event); 00502 loop_done = true; 00503 break; 00504 00505 default: 00506 DLOG("Passing to original handler\n"); 00507 /* Use original handler */ 00508 handle_event(type, inside_event); 00509 break; 00510 } 00511 if (last_motion_notify != inside_event) 00512 free(inside_event); 00513 } while ((inside_event = xcb_poll_for_event(conn)) != NULL); 00514 00515 if (last_motion_notify == NULL) 00516 continue; 00517 00518 new_x = ((xcb_motion_notify_event_t*)last_motion_notify)->root_x; 00519 new_y = ((xcb_motion_notify_event_t*)last_motion_notify)->root_y; 00520 00521 callback(con, &old_rect, new_x, new_y, extra); 00522 FREE(last_motion_notify); 00523 } 00524 00525 xcb_ungrab_pointer(conn, XCB_CURRENT_TIME); 00526 xcb_flush(conn); 00527 } 00528 00529 /* 00530 * Repositions the CT_FLOATING_CON to have the coordinates specified by 00531 * newrect, but only if the coordinates are not out-of-bounds. Also reassigns 00532 * the floating con to a different workspace if this move was across different 00533 * outputs. 00534 * 00535 */ 00536 void floating_reposition(Con *con, Rect newrect) { 00537 /* Sanity check: Are the new coordinates on any output? If not, we 00538 * ignore that request. */ 00539 Output *output = get_output_containing( 00540 newrect.x + (newrect.width / 2), 00541 newrect.y + (newrect.height / 2)); 00542 00543 if (!output) { 00544 ELOG("No output found at destination coordinates. Not repositioning.\n"); 00545 return; 00546 } 00547 00548 con->rect = newrect; 00549 00550 floating_maybe_reassign_ws(con); 00551 tree_render(); 00552 } 00553 00554 /* 00555 * Fixes the coordinates of the floating window whenever the window gets 00556 * reassigned to a different output (or when the output’s rect changes). 00557 * 00558 */ 00559 void floating_fix_coordinates(Con *con, Rect *old_rect, Rect *new_rect) { 00560 DLOG("Fixing coordinates of floating window %p\n", con); 00561 /* First we get the x/y coordinates relative to the x/y coordinates 00562 * of the output on which the window is on */ 00563 uint32_t rel_x = (con->rect.x - old_rect->x); 00564 uint32_t rel_y = (con->rect.y - old_rect->y); 00565 /* Then we calculate a fraction, for example 0.63 for a window 00566 * which is at y = 1212 of a 1920 px high output */ 00567 double fraction_x = ((double)rel_x / old_rect->width); 00568 double fraction_y = ((double)rel_y / old_rect->height); 00569 DLOG("rel_x = %d, rel_y = %d, fraction_x = %f, fraction_y = %f, output->w = %d, output->h = %d\n", 00570 rel_x, rel_y, fraction_x, fraction_y, old_rect->width, old_rect->height); 00571 con->rect.x = new_rect->x + (fraction_x * new_rect->width); 00572 con->rect.y = new_rect->y + (fraction_y * new_rect->height); 00573 DLOG("Resulting coordinates: x = %d, y = %d\n", con->rect.x, con->rect.y); 00574 } 00575 00576 #if 0 00577 /* 00578 * Moves the client 10px to the specified direction. 00579 * 00580 */ 00581 void floating_move(xcb_connection_t *conn, Client *currently_focused, direction_t direction) { 00582 DLOG("floating move\n"); 00583 00584 Rect destination = currently_focused->rect; 00585 Rect *screen = &(currently_focused->workspace->output->rect); 00586 00587 switch (direction) { 00588 case D_LEFT: 00589 destination.x -= 10; 00590 break; 00591 case D_RIGHT: 00592 destination.x += 10; 00593 break; 00594 case D_UP: 00595 destination.y -= 10; 00596 break; 00597 case D_DOWN: 00598 destination.y += 10; 00599 break; 00600 /* to make static analyzers happy */ 00601 default: 00602 break; 00603 } 00604 00605 /* Prevent windows from vanishing completely */ 00606 if ((int32_t)(destination.x + destination.width - 5) <= (int32_t)screen->x || 00607 (int32_t)(destination.x + 5) >= (int32_t)(screen->x + screen->width) || 00608 (int32_t)(destination.y + destination.height - 5) <= (int32_t)screen->y || 00609 (int32_t)(destination.y + 5) >= (int32_t)(screen->y + screen->height)) { 00610 DLOG("boundary check failed, not moving\n"); 00611 return; 00612 } 00613 00614 currently_focused->rect = destination; 00615 reposition_client(conn, currently_focused); 00616 00617 /* Because reposition_client does not send a faked configure event (only resize does), 00618 * we need to initiate that on our own */ 00619 fake_absolute_configure_notify(conn, currently_focused); 00620 /* fake_absolute_configure_notify flushes */ 00621 } 00622 00623 /* 00624 * Hides all floating clients (or show them if they are currently hidden) on 00625 * the specified workspace. 00626 * 00627 */ 00628 void floating_toggle_hide(xcb_connection_t *conn, Workspace *workspace) { 00629 Client *client; 00630 00631 workspace->floating_hidden = !workspace->floating_hidden; 00632 DLOG("floating_hidden is now: %d\n", workspace->floating_hidden); 00633 TAILQ_FOREACH(client, &(workspace->floating_clients), floating_clients) { 00634 if (workspace->floating_hidden) 00635 client_unmap(conn, client); 00636 else client_map(conn, client); 00637 } 00638 00639 /* If we just unmapped all floating windows we should ensure that the focus 00640 * is set correctly, that ist, to the first non-floating client in stack */ 00641 if (workspace->floating_hidden) 00642 SLIST_FOREACH(client, &(workspace->focus_stack), focus_clients) { 00643 if (client_is_floating(client)) 00644 continue; 00645 set_focus(conn, client, true); 00646 return; 00647 } 00648 00649 xcb_flush(conn); 00650 } 00651 #endif