Go to the documentation of this file.
13 #define MAX(x, y) ((x) > (y) ? (x) : (y))
26 Rect outputs_dimensions = {0, 0, 0, 0};
31 return outputs_dimensions;
53 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE, con->
window->
id,
54 A_I3_FLOATING_WINDOW, XCB_ATOM_CARDINAL, 32, 1, &val);
56 xcb_delete_property(
conn, con->
window->
id, A_I3_FLOATING_WINDOW);
75 const int floating_sane_min_height = 50;
76 const int floating_sane_min_width = 75;
77 Rect floating_sane_max_dimensions;
142 const double ar = (double)width / (
double)height;
144 if (min_ar > 0 && ar < min_ar) {
146 }
else if (max_ar > 0 && ar > max_ar) {
151 width = round(height * new_ar);
152 height = round(width / new_ar);
154 height = round(width / new_ar);
155 width = round(height * new_ar);
225 bool set_focus = (con ==
focused);
228 LOG(
"Container is a dock window, not enabling floating mode.\n");
233 LOG(
"Container is already in floating mode, not doing anything.\n");
237 if (con->
type == CT_WORKSPACE) {
238 LOG(
"Container is a workspace, not enabling floating mode.\n");
242 Con *focus_head_placeholder = NULL;
243 bool focus_before_parent =
true;
248 while (ancestor->
parent->
type != CT_WORKSPACE) {
250 ancestor = ancestor->
parent;
262 if (focus_before_parent) {
282 nc->
type = CT_FLOATING_CON;
290 if (focus_before_parent) {
291 if (focus_head_placeholder) {
297 if (focus_head_placeholder) {
308 DLOG(
"Old container empty after setting this child to floating, closing\n");
316 sasprintf(&name,
"[i3 con] floatingcon around %p", con);
329 DLOG(
"Geometry not set, combining children\n");
376 DLOG(
"Centering above leader\n");
388 if (!current_output || current_output->
con != correct_output) {
389 DLOG(
"This floating window is on the wrong output, fixing coordinates (currently (%d, %d))\n",
394 if (current_output) {
399 if (!current_output || current_output->
con != correct_output) {
410 nc->
rect.
y -= deco_height;
412 DLOG(
"Corrected y = %d (deco_height = %d)\n", nc->
rect.
y, deco_height);
426 LOG(
"Container isn't floating, not doing anything.\n");
432 LOG(
"Can't disable floating for container in internal workspace.\n");
437 if (tiling_focused->
type == CT_WORKSPACE) {
463 if (con->
type == CT_FLOATING_CON) {
464 ELOG(
"Cannot toggle floating mode on con = %p because it is of type CT_FLOATING_CON.\n", con);
470 LOG(
"already floating, re-setting to tiling\n");
484 DLOG(
"Raising floating con %p / %s\n", con, con->
name);
496 DLOG(
"Con in an internal workspace\n");
503 ELOG(
"No output found at destination coordinates?\n");
508 DLOG(
"still the same ws\n");
512 DLOG(
"Need to re-assign!\n");
516 DLOG(
"Moving con %p / %s to workspace %p / %s\n", con, con->
name, ws, ws->
name);
543 assert(con->
type == CT_FLOATING_CON);
545 xcb_query_pointer_reply_t *reply = xcb_query_pointer_reply(
conn, xcb_query_pointer(
conn,
root), NULL);
547 ELOG(
"could not query pointer position, not moving this container\n");
552 if (output == NULL) {
553 ELOG(
"The pointer is not on any output, cannot move the container here.\n");
558 int32_t x = reply->root_x - con->
rect.
width / 2;
563 x =
MAX(x, (int32_t)output->
rect.
x);
576 con->rect.x = old_rect->x + (new_x -
event->root_x);
577 con->rect.y = old_rect->y + (new_y -
event->root_y);
597 DLOG(
"floating_drag_window\n");
610 DLOG(
"The container has been closed in the meantime.\n");
643 int32_t dest_x = con->rect.x;
644 int32_t dest_y = con->rect.y;
646 uint32_t dest_height;
648 double ratio = (double)old_rect->width / old_rect->height;
653 dest_width = old_rect->width - (new_x -
event->root_x);
655 dest_width = old_rect->width + (new_x -
event->root_x);
658 dest_height = old_rect->height - (new_y -
event->root_y);
660 dest_height = old_rect->height + (new_y -
event->root_y);
664 dest_width =
max(dest_width, (
int)(dest_height * ratio));
665 dest_height =
max(dest_height, (
int)(dest_width / ratio));
668 con->rect = (
Rect){dest_x, dest_y, dest_width, dest_height};
676 dest_x = old_rect->x + (old_rect->width - con->rect.width);
679 dest_y = old_rect->y + (old_rect->height - con->rect.height);
681 con->rect.x = dest_x;
682 con->rect.y = dest_y;
695 const xcb_button_press_event_t *event) {
696 DLOG(
"floating_resize_window\n");
702 if (event->event_x <= (int16_t)(con->
rect.
width / 2))
708 if (event->event_y <= (int16_t)(con->
rect.
height / 2)) {
724 DLOG(
"The container has been closed in the meantime.\n");
748 ELOG(
"No output found at destination coordinates. Not repositioning.\n");
772 DLOG(
"floating resize to %dx%d px\n", x,
y);
775 if (focused_con->
window == NULL) {
776 DLOG(
"No window is focused. Not resizing.\n");
781 bool prefer_height = (rect->
width == x);
802 DLOG(
"Fixing coordinates of floating window %p (rect (%d, %d), %d x %d)\n",
804 DLOG(
"old_rect = (%d, %d), %d x %d\n",
805 old_rect->
x, old_rect->
y, old_rect->
width, old_rect->
height);
806 DLOG(
"new_rect = (%d, %d), %d x %d\n",
807 new_rect->
x, new_rect->
y, new_rect->
width, new_rect->
height);
810 int32_t rel_x = con->
rect.
x - old_rect->
x + (int32_t)(con->
rect.
width / 2);
811 int32_t rel_y = con->
rect.
y - old_rect->
y + (int32_t)(con->
rect.
height / 2);
814 DLOG(
"rel_x = %d, rel_y = %d, fraction_x = %f, fraction_y = %f, output->w = %d, output->h = %d\n",
815 rel_x, rel_y, (
double)rel_x / old_rect->
width, (
double)rel_y / old_rect->
height,
818 con->
rect.
x = (int32_t)new_rect->
x + (
double)(rel_x * (int32_t)new_rect->
width) / (int32_t)old_rect->
width - (int32_t)(con->
rect.
width / 2);
819 con->
rect.
y = (int32_t)new_rect->
y + (
double)(rel_y * (int32_t)new_rect->
height) / (int32_t)old_rect->
height - (int32_t)(con->
rect.
height / 2);
820 DLOG(
"Resulting coordinates: x = %d, y = %d\n", con->
rect.
x, con->
rect.
y);
void workspace_show(Con *workspace)
Switches to the given workspace.
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 tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
bool con_inside_focused(Con *con)
Checks if the given container is inside a focused container.
void ipc_send_window_event(const char *property, Con *con)
For the window events we send, along the usual "change" field, also the window container,...
Con * con_new(Con *parent, i3Window *window)
A wrapper for con_new_skeleton, to retain the old con_new behaviour.
#define TAILQ_INSERT_AFTER(head, listelm, elm, field)
Con * con_descend_tiling_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
@ XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER
enum Con::@22 scratchpad_state
Rect rect
x, y, width, height
void floating_resize(Con *floating_con, uint32_t x, uint32_t y)
Sets size of the CT_FLOATING_CON to specified dimensions.
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
Output * get_output_from_rect(Rect rect)
Returns the active output which contains the midpoint of the given rect.
DRAGGING_CB(drag_window_callback)
bool con_is_floating(Con *con)
Returns true if the node is floating.
Output * get_output_containing(unsigned int x, unsigned int y)
Returns the active (!) output which contains the coordinates x, y or NULL if there is no output which...
int render_deco_height(void)
Returns the height for the decorations.
bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_parent)
Closes the given container including all children.
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
void floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
int con_border_style(Con *con)
Use this function to get a container’s border style.
#define TAILQ_EMPTY(head)
int32_t floating_maximum_width
Maximum and minimum dimensions of a floating window.
int32_t floating_minimum_height
void floating_raise_con(Con *con)
Raises the given container in the list of floating containers.
void con_detach(Con *con)
Detaches the given container from its current parent.
void floating_disable(Con *con)
Disables floating mode for the given container by re-attaching the container to its old parent.
void insert_con_into(Con *con, Con *target, position_t position)
This function detaches 'con' from its parent and inserts it either before or after 'target'.
Output * output_containing_rect(Rect rect)
In output_containing_rect, we check if any active output contains part of the container.
drag_result_t drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_window_t confine_to, int cursor, bool use_threshold, callback_t callback, const void *extra)
This function grabs your pointer and keyboard and lets you drag stuff around (borders).
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
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...
void floating_center(Con *con, Rect rect)
Centers a floating con above the specified rect.
#define TAILQ_INSERT_HEAD(head, elm, field)
#define TAILQ_FIRST(head)
bool floating_reposition(Con *con, Rect newrect)
Repositions the CT_FLOATING_CON to have the coordinates specified by newrect, but only if the coordin...
enum Con::@21 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
#define TAILQ_NEXT(elm, field)
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...
int32_t floating_maximum_height
fullscreen_mode_t fullscreen_mode
void floating_check_size(Con *floating_con, bool prefer_height)
Called when a floating window is created or resized.
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...
An Output is a physical output on your graphics driver.
@ XCURSOR_CURSOR_TOP_LEFT_CORNER
#define TAILQ_INSERT_BEFORE(listelm, elm, field)
int con_num_children(Con *con)
Returns the number of children of this container.
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on.
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
#define TAILQ_PREV(elm, headname, field)
void toggle_floating_mode(Con *con, bool automatic)
Calls floating_enable() for tiling containers and floating_disable() for floating containers.
border_style_t default_floating_border
The default border style for new floating windows.
@ XCURSOR_CURSOR_TOP_RIGHT_CORNER
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...
bool rect_equals(Rect a, Rect b)
xcb_screen_t * root_screen
Con * con
Pointer to the Con which represents this output.
struct outputs_head outputs
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
int32_t floating_minimum_width
static Rect total_outputs_dimensions(void)
#define TAILQ_FOREACH(var, head, field)
void x_push_changes(Con *con)
Pushes all changes (state of each node, see x_push_node() and the window stack) to X11.
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
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...
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.
void floating_move_to_pointer(Con *con)
Moves the given floating con to the current pointer position.
border_style_t border_style
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...
#define TAILQ_REMOVE(head, elm, field)
struct Rect geometry
the geometry this window requested when getting mapped
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
A 'Con' represents everything from the X11 root window down to a single X11 window.
void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool dont_warp, bool ignore_focus)
Moves the given container to the currently focused container on the given workspace.
border_t
On which border was the dragging initiated?
bool con_exists(Con *con)
Returns true if the given container (still) exists.
void render_con(Con *con, bool already_inset)
"Renders" the given container (and its children), meaning that all rects are updated correctly.
xcb_window_t leader
Holds the xcb_window_t (just an ID) for the leader window (logical parent for toolwindows and similar...
static void floating_set_hint_atom(Con *con, bool floating)
#define TAILQ_INSERT_TAIL(head, elm, field)
drag_result_t
This is the return value of a drag operation like drag_pointer.
xcb_connection_t * conn
XCB connection and root screen.
void floating_drag_window(Con *con, const xcb_button_press_event_t *event, bool use_threshold)
Called when the user clicked on the titlebar of a floating window.
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Con * output_get_content(Con *output)
Returns the output container below the given output container.
@ XCURSOR_CURSOR_BOTTOM_LEFT_CORNER
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
bool con_is_docked(Con *con)
Returns true if the container is a docked container.
Stores a rectangle, for example the size of a window, the child window etc.