12 extern xcb_connection_t *
conn;
21 Rect outputs_dimensions = {0, 0, 0, 0};
26 return outputs_dimensions;
30 bool set_focus = (con ==
focused);
33 LOG(
"Container is a dock window, not enabling floating mode.\n");
38 LOG(
"Container is already in floating mode, not doing anything.\n");
46 if (con->
type == CT_WORKSPACE) {
47 LOG(
"This is a workspace, creating new container around content\n");
49 LOG(
"Workspace is empty, aborting\n");
59 memcpy(&(new->rect), &(con->
rect),
sizeof(
Rect));
62 if (old_focused ==
TAILQ_END(&(con->focus_head)))
66 DLOG(
"Moving cons\n");
75 DLOG(
"Attaching new split to ws\n");
101 nc->
type = CT_FLOATING_CON;
111 DLOG(
"Old container empty after setting this child to floating, closing\n");
116 sasprintf(&name,
"[i3 con] floatingcon around %p", con);
125 Rect zero = { 0, 0, 0, 0 };
129 if (memcmp(&(nc->
rect), &zero,
sizeof(
Rect)) == 0) {
130 DLOG(
"Geometry not set, combining children\n");
140 const int floating_sane_min_height = 50;
141 const int floating_sane_min_width = 75;
143 Rect floating_sane_max_dimensions;
194 DLOG(
"Centering above leader\n");
208 if (!current_output || current_output->
con != correct_output) {
209 DLOG(
"This floating window is on the wrong output, fixing coordinates (currently (%d, %d))\n",
213 uint32_t rel_x = (nc->
rect.
x - (current_output ? current_output->
con->
rect.
x : 0));
214 uint32_t rel_y = (nc->
rect.
y - (current_output ? current_output->
con->
rect.
y : 0));
234 nc->
rect.
y -= deco_height;
236 DLOG(
"Corrected y = %d (deco_height = %d)\n", nc->
rect.
y, deco_height);
257 ELOG(
"No output found at destination coordinates, centering floating window on current ws\n");
264 LOG(
"Container isn't floating, not doing anything.\n");
285 if (focused->
type == CT_WORKSPACE)
311 LOG(
"already floating, re-setting to tiling\n");
325 DLOG(
"Raising floating con %p / %s\n", con, con->
name);
341 ELOG(
"No output found at destination coordinates?\n");
346 DLOG(
"still the same ws\n");
350 DLOG(
"Need to re-assign!\n");
354 DLOG(
"Moving con %p / %s to workspace %p / %s\n", con, con->
name, ws, ws->
name);
361 const struct xcb_button_press_event_t *
event = extra;
364 con->rect.x = old_rect->x + (new_x -
event->root_x);
365 con->rect.y = old_rect->y + (new_y -
event->root_y);
383 DLOG(
"floating_drag_window\n");
404 const xcb_button_press_event_t *
event;
409 const xcb_button_press_event_t *
event = params->
event;
412 int32_t dest_x = con->rect.x;
413 int32_t dest_y = con->rect.y;
415 uint32_t dest_height;
417 double ratio = (double) old_rect->width / old_rect->height;
422 dest_width = old_rect->width - (new_x -
event->root_x);
423 else dest_width = old_rect->width + (new_x -
event->root_x);
426 dest_height = old_rect->height - (new_y -
event->root_y);
427 else dest_height = old_rect->height + (new_y -
event->root_y);
431 dest_width =
max(dest_width, minimum.
width);
432 dest_height =
max(dest_height, minimum.
height);
436 dest_width =
max(dest_width, (
int) (dest_height * ratio));
437 dest_height =
max(dest_height, (
int) (dest_width / ratio));
442 if (corner & BORDER_LEFT)
443 dest_x = old_rect->x + (old_rect->width - dest_width);
445 if (corner & BORDER_TOP)
446 dest_y = old_rect->y + (old_rect->height - dest_height);
448 con->rect = (
Rect) { dest_x, dest_y, dest_width, dest_height };
463 const xcb_button_press_event_t *
event) {
464 DLOG(
"floating_resize_window\n");
470 if (event->event_x <= (con->
rect.
width / 2))
494 uint32_t new_x, new_y;
497 memcpy(&old_rect, &(con->
rect),
sizeof(
Rect));
500 xcb_grab_pointer_cookie_t cookie;
501 xcb_grab_pointer_reply_t *reply;
502 cookie = xcb_grab_pointer(
conn,
505 XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION,
512 if ((reply = xcb_grab_pointer_reply(
conn, cookie, NULL)) == NULL) {
513 ELOG(
"Could not grab pointer\n");
522 xcb_generic_event_t *inside_event, *last_motion_notify = NULL;
523 bool loop_done =
false;
525 while (!loop_done && (inside_event = xcb_wait_for_event(
conn))) {
529 if (inside_event->response_type == 0) {
534 int type = (inside_event->response_type & 0x7F);
537 case XCB_BUTTON_RELEASE:
541 case XCB_MOTION_NOTIFY:
543 FREE(last_motion_notify);
544 last_motion_notify = inside_event;
547 case XCB_UNMAP_NOTIFY:
549 case XCB_KEY_RELEASE:
550 DLOG(
"Unmap-notify, aborting\n");
556 DLOG(
"Passing to original handler\n");
561 if (last_motion_notify != inside_event)
563 }
while ((inside_event = xcb_poll_for_event(
conn)) != NULL);
565 if (last_motion_notify == NULL)
568 new_x = ((xcb_motion_notify_event_t*)last_motion_notify)->root_x;
569 new_y = ((xcb_motion_notify_event_t*)last_motion_notify)->root_y;
571 callback(con, &old_rect, new_x, new_y, extra);
572 FREE(last_motion_notify);
575 xcb_ungrab_pointer(
conn, XCB_CURRENT_TIME);
590 newrect.
x + (newrect.
width / 2),
591 newrect.
y + (newrect.
height / 2));
594 ELOG(
"No output found at destination coordinates. Not repositioning.\n");
610 DLOG(
"Fixing coordinates of floating window %p\n", con);
613 uint32_t rel_x = (con->
rect.
x - old_rect->
x);
614 uint32_t rel_y = (con->
rect.
y - old_rect->
y);
617 double fraction_x = ((double)rel_x / old_rect->
width);
618 double fraction_y = ((double)rel_y / old_rect->
height);
619 DLOG(
"rel_x = %d, rel_y = %d, fraction_x = %f, fraction_y = %f, output->w = %d, output->h = %d\n",
620 rel_x, rel_y, fraction_x, fraction_y, old_rect->
width, old_rect->
height);
621 con->
rect.
x = new_rect->
x + (fraction_x * new_rect->
width);
622 con->
rect.
y = new_rect->
y + (fraction_y * new_rect->
height);
623 DLOG(
"Resulting coordinates: x = %d, y = %d\n", con->
rect.
x, con->
rect.
y);
631 void floating_move(xcb_connection_t *
conn, Client *currently_focused,
direction_t direction) {
632 DLOG(
"floating move\n");
634 Rect destination = currently_focused->rect;
635 Rect *screen = &(currently_focused->workspace->output->rect);
656 if ((int32_t)(destination.
x + destination.
width - 5) <= (int32_t)screen->
x ||
657 (int32_t)(destination.
x + 5) >= (int32_t)(screen->
x + screen->
width) ||
658 (int32_t)(destination.
y + destination.
height - 5) <= (int32_t)screen->
y ||
659 (int32_t)(destination.
y + 5) >= (int32_t)(screen->
y + screen->
height)) {
660 DLOG(
"boundary check failed, not moving\n");
664 currently_focused->rect = destination;
665 reposition_client(conn, currently_focused);
678 void floating_toggle_hide(xcb_connection_t *conn, Workspace *workspace) {
681 workspace->floating_hidden = !workspace->floating_hidden;
682 DLOG(
"floating_hidden is now: %d\n", workspace->floating_hidden);
683 TAILQ_FOREACH(client, &(workspace->floating_clients), floating_clients) {
684 if (workspace->floating_hidden)
685 client_unmap(conn, client);
686 else client_map(conn, client);
691 if (workspace->floating_hidden)
692 SLIST_FOREACH(client, &(workspace->focus_stack), focus_clients) {
693 if (client_is_floating(client))
695 set_focus(conn, client,
true);