2 #define I3__FILE__ "floating.c"
14 extern xcb_connection_t *
conn;
23 Rect outputs_dimensions = {0, 0, 0, 0};
28 return outputs_dimensions;
39 const int floating_sane_min_height = 50;
40 const int floating_sane_min_width = 75;
41 Rect floating_sane_max_dimensions;
106 bool set_focus = (con ==
focused);
109 LOG(
"Container is a dock window, not enabling floating mode.\n");
114 LOG(
"Container is already in floating mode, not doing anything.\n");
122 if (con->
type == CT_WORKSPACE) {
123 LOG(
"This is a workspace, creating new container around content\n");
125 LOG(
"Workspace is empty, aborting\n");
135 memcpy(&(new->rect), &(con->
rect),
sizeof(
Rect));
138 if (old_focused ==
TAILQ_END(&(con->focus_head)))
142 DLOG(
"Moving cons\n");
151 DLOG(
"Attaching new split to ws\n");
176 nc->
type = CT_FLOATING_CON;
187 DLOG(
"Old container empty after setting this child to floating, closing\n");
192 sasprintf(&name,
"[i3 con] floatingcon around %p", con);
201 Rect zero = { 0, 0, 0, 0 };
205 if (memcmp(&(nc->
rect), &zero,
sizeof(
Rect)) == 0) {
206 DLOG(
"Geometry not set, combining children\n");
248 DLOG(
"Centering above leader\n");
264 if (!current_output || current_output->
con != correct_output) {
265 DLOG(
"This floating window is on the wrong output, fixing coordinates (currently (%d, %d))\n",
284 nc->
rect.
y -= deco_height;
286 DLOG(
"Corrected y = %d (deco_height = %d)\n", nc->
rect.
y, deco_height);
307 ELOG(
"No output found at destination coordinates, centering floating window on current ws\n");
314 LOG(
"Container isn't floating, not doing anything.\n");
318 const bool set_focus = (con ==
focused);
337 if (focused->
type == CT_WORKSPACE)
364 LOG(
"already floating, re-setting to tiling\n");
378 DLOG(
"Raising floating con %p / %s\n", con, con->
name);
394 ELOG(
"No output found at destination coordinates?\n");
399 DLOG(
"still the same ws\n");
403 DLOG(
"Need to re-assign!\n");
407 DLOG(
"Moving con %p / %s to workspace %p / %s\n", con, con->
name, ws, ws->
name);
414 const struct xcb_button_press_event_t *
event = extra;
417 con->rect.x = old_rect->x + (new_x -
event->root_x);
418 con->rect.y = old_rect->y + (new_y -
event->root_y);
438 DLOG(
"floating_drag_window\n");
464 const xcb_button_press_event_t *
event;
469 const xcb_button_press_event_t *
event = params->
event;
472 int32_t dest_x = con->rect.x;
473 int32_t dest_y = con->rect.y;
475 uint32_t dest_height;
477 double ratio = (double) old_rect->width / old_rect->height;
482 dest_width = old_rect->width - (new_x -
event->root_x);
483 else dest_width = old_rect->width + (new_x -
event->root_x);
486 dest_height = old_rect->height - (new_y -
event->root_y);
487 else dest_height = old_rect->height + (new_y -
event->root_y);
491 dest_width =
max(dest_width, (
int) (dest_height * ratio));
492 dest_height =
max(dest_height, (
int) (dest_width / ratio));
495 con->rect = (
Rect) { dest_x, dest_y, dest_width, dest_height };
502 if (corner & BORDER_LEFT)
503 dest_x = old_rect->x + (old_rect->width - con->rect.width);
505 if (corner & BORDER_TOP)
506 dest_y = old_rect->y + (old_rect->height - con->rect.height);
508 con->rect.x = dest_x;
509 con->rect.y = dest_y;
524 const xcb_button_press_event_t *
event) {
525 DLOG(
"floating_resize_window\n");
531 if (event->event_x <= (con->
rect.
width / 2))
536 if (event->event_y <= (con->
rect.
height / 2)) {
567 uint32_t new_x, new_y;
568 Rect old_rect = { 0, 0, 0, 0 };
570 memcpy(&old_rect, &(con->
rect),
sizeof(
Rect));
576 xcb_grab_pointer_cookie_t cookie;
577 xcb_grab_pointer_reply_t *reply;
578 cookie = xcb_grab_pointer(
conn,
581 XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION,
588 if ((reply = xcb_grab_pointer_reply(
conn, cookie, NULL)) == NULL) {
589 ELOG(
"Could not grab pointer\n");
598 xcb_generic_event_t *inside_event, *last_motion_notify = NULL;
599 bool loop_done =
false;
601 while (!loop_done && (inside_event = xcb_wait_for_event(
conn))) {
605 if (inside_event->response_type == 0) {
610 int type = (inside_event->response_type & 0x7F);
613 case XCB_BUTTON_RELEASE:
617 case XCB_MOTION_NOTIFY:
619 FREE(last_motion_notify);
620 last_motion_notify = inside_event;
623 case XCB_UNMAP_NOTIFY:
625 case XCB_KEY_RELEASE:
626 DLOG(
"Unmap-notify, aborting\n");
632 DLOG(
"Passing to original handler\n");
637 if (last_motion_notify != inside_event)
639 }
while ((inside_event = xcb_poll_for_event(
conn)) != NULL);
641 if (last_motion_notify == NULL || loop_done)
644 new_x = ((xcb_motion_notify_event_t*)last_motion_notify)->root_x;
645 new_y = ((xcb_motion_notify_event_t*)last_motion_notify)->root_y;
647 callback(con, &old_rect, new_x, new_y, extra);
648 FREE(last_motion_notify);
651 xcb_ungrab_pointer(
conn, XCB_CURRENT_TIME);
666 ELOG(
"No output found at destination coordinates. Not repositioning.\n");
687 DLOG(
"Fixing coordinates of floating window %p (rect (%d, %d), %d x %d)\n",
689 DLOG(
"old_rect = (%d, %d), %d x %d\n",
690 old_rect->
x, old_rect->
y, old_rect->
width, old_rect->
height);
691 DLOG(
"new_rect = (%d, %d), %d x %d\n",
692 new_rect->
x, new_rect->
y, new_rect->
width, new_rect->
height);
695 int32_t rel_x = con->
rect.
x - old_rect->
x + (int32_t)(con->
rect.
width / 2);
696 int32_t rel_y = con->
rect.
y - old_rect->
y + (int32_t)(con->
rect.
height / 2);
699 DLOG(
"rel_x = %d, rel_y = %d, fraction_x = %f, fraction_y = %f, output->w = %d, output->h = %d\n",
700 rel_x, rel_y, (
double)rel_x / old_rect->
width, (
double)rel_y / old_rect->
height,
703 con->
rect.
x = (int32_t)new_rect->
x + (
double)(rel_x * (int32_t)new_rect->
width)
705 con->
rect.
y = (int32_t)new_rect->
y + (
double)(rel_y * (int32_t)new_rect->
height)
707 DLOG(
"Resulting coordinates: x = %d, y = %d\n", con->
rect.
x, con->
rect.
y);
715 void floating_move(xcb_connection_t *
conn, Client *currently_focused,
direction_t direction) {
716 DLOG(
"floating move\n");
718 Rect destination = currently_focused->rect;
719 Rect *screen = &(currently_focused->workspace->output->rect);
740 if ((int32_t)(destination.
x + destination.
width - 5) <= (int32_t)screen->
x ||
741 (int32_t)(destination.
x + 5) >= (int32_t)(screen->
x + screen->
width) ||
742 (int32_t)(destination.
y + destination.
height - 5) <= (int32_t)screen->
y ||
743 (int32_t)(destination.
y + 5) >= (int32_t)(screen->
y + screen->
height)) {
744 DLOG(
"boundary check failed, not moving\n");
748 currently_focused->rect = destination;
749 reposition_client(conn, currently_focused);
762 void floating_toggle_hide(xcb_connection_t *conn, Workspace *workspace) {
765 workspace->floating_hidden = !workspace->floating_hidden;
766 DLOG(
"floating_hidden is now: %d\n", workspace->floating_hidden);
767 TAILQ_FOREACH(client, &(workspace->floating_clients), floating_clients) {
768 if (workspace->floating_hidden)
769 client_unmap(conn, client);
770 else client_map(conn, client);
775 if (workspace->floating_hidden)
776 SLIST_FOREACH(client, &(workspace->focus_stack), focus_clients) {
777 if (client_is_floating(client))
779 set_focus(conn, client,
true);
void floating_fix_coordinates(Con *con, Rect *old_rect, Rect *new_rect)
Fixes the coordinates of the floating window whenever the window gets reassigned to a different outpu...
A 'Con' represents everything from the X11 root window down to a single X11 window.
int render_deco_height(void)
void x_push_changes(Con *con)
Pushes all changes (state of each node, see x_push_node() and the window stack) to X11...
#define TAILQ_INSERT_TAIL(head, elm, field)
void(* callback_t)(Con *, Rect *, uint32_t, uint32_t, const void *)
Callback for dragging.
Stores a rectangle, for example the size of a window, the child window etc.
border_style_t border_style
void floating_drag_window(Con *con, const xcb_button_press_event_t *event)
Called when the user clicked on the titlebar of a floating window.
#define DRAGGING_CB(name)
Macro to create a callback function for dragging.
int32_t floating_maximum_width
Maximum and minimum dimensions of a floating window.
void render_con(Con *con, bool render_fullscreen)
"Renders" the given container (and its children), meaning that all rects are updated correctly...
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool dont_warp)
Moves the given container to the currently focused container on the given workspace.
Rect con_border_style_rect(Con *con)
Returns a "relative" Rect which contains the amount of pixels that need to be added to the original R...
#define TAILQ_EMPTY(head)
int con_num_children(Con *con)
Returns the number of children of this container.
Cursor xcursor_get_cursor(enum xcursor_cursor_t c)
void toggle_floating_mode(Con *con, bool automatic)
Calls floating_enable() for tiling containers and floating_disable() for floating containers...
void floating_disable(Con *con, bool automatic)
Disables floating mode for the given container by re-attaching the container to its old parent...
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
enum Con::@20 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
#define TAILQ_REMOVE(head, elm, field)
Con * con_descend_tiling_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
void floating_reposition(Con *con, Rect newrect)
Repositions the CT_FLOATING_CON to have the coordinates specified by newrect, but only if the coordin...
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
const xcb_button_press_event_t * event
struct Rect geometry
the geometry this window requested when getting mapped
void fake_absolute_configure_notify(Con *con)
Generates a configure_notify_event with absolute coordinates (relative to the X root window...
Con * con_by_window_id(xcb_window_t window)
Returns the container with the given client window ID or NULL if no such container exists...
void floating_raise_con(Con *con)
Raises the given container in the list of floating containers.
struct outputs_head outputs
border_t
On which border was the dragging initiated?
Rect rect
x, y, width, height
xcb_window_t leader
Holds the xcb_window_t (just an ID) for the leader window (logical parent for toolwindows and similar...
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
border_style_t default_floating_border
The default border style for new floating windows.
bool tree_close(Con *con, kill_window_t kill_window, bool dont_kill_parent, bool force_set_focus)
Closes the given container including all children.
void drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_window_t confine_to, border_t border, int cursor, callback_t callback, const void *extra)
This function grabs your pointer and lets you drag stuff around (borders).
int32_t floating_minimum_width
void con_focus(Con *con)
Sets input focus to the given container.
int32_t floating_maximum_height
#define TAILQ_FIRST(head)
void x_push_node(Con *con)
This function pushes the properties of each node of the layout tree to X11 if they have changed (like...
static Rect total_outputs_dimensions(void)
An Output is a physical output on your graphics driver.
Output * get_output_containing(int x, int y)
Returns the active (!) output which contains the coordinates x, y or NULL if there is no output which...
#define SLIST_FOREACH(var, head, field)
#define TAILQ_FOREACH(var, head, field)
Con * con_new(Con *parent, i3Window *window)
void con_detach(Con *con)
Detaches the given container from its current parent.
void handle_event(int type, xcb_generic_event_t *event)
Takes an xcb_generic_event_t and calls the appropriate handler, based on the event type...
void floating_resize_window(Con *con, const bool proportional, const xcb_button_press_event_t *event)
Called when the user clicked on a floating window while holding the floating_modifier and the right m...
Con * output_get_content(Con *output)
Returns the output container below the given output container.
int32_t floating_minimum_height
void x_set_name(Con *con, const char *name)
Sets the WM_NAME property (so, no UTF8, but used only for debugging anyways) of the given name...
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on...
bool contained_by_output(Rect rect)
void floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
void floating_check_size(Con *floating_con)
Called when a floating window is created or resized.
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
Con * con
Pointer to the Con which represents this output.
enum Con::@21 scratchpad_state
bool con_is_floating(Con *con)
Returns true if the node is floating.
bool floating_maybe_reassign_ws(Con *con)
Checks if con’s coordinates are within its workspace and re-assigns it to the actual workspace if not...
int con_border_style(Con *con)
Use this function to get a container’s border style.