15#define MAX(x, y) ((x) > (y) ? (x) : (y))
29 Rect outputs_dimensions = {0, 0, 0, 0};
34 return outputs_dimensions;
56 xcb_change_property(
conn, XCB_PROP_MODE_REPLACE, con->
window->
id,
57 A_I3_FLOATING_WINDOW, XCB_ATOM_CARDINAL, 32, 1, &val);
59 xcb_delete_property(
conn, con->
window->
id, A_I3_FLOATING_WINDOW);
78 const int floating_sane_min_height = 50;
79 const int floating_sane_min_width = 75;
80 Rect floating_sane_max_dimensions;
94 DLOG(
"floating_check_size, want min width %d, min height %d, border extra: w=%d, h=%d\n",
95 floating_sane_min_width,
96 floating_sane_min_height,
101 if (window != NULL) {
151 const double ar = (double)width / (
double)height;
153 if (min_ar > 0 && ar < min_ar) {
155 }
else if (max_ar > 0 && ar > max_ar) {
160 width = round(height * new_ar);
161 height = round(width / new_ar);
163 height = round(width / new_ar);
164 width = round(height * new_ar);
234 bool set_focus = (con ==
focused);
237 LOG(
"Container is a dock window, not enabling floating mode.\n");
242 LOG(
"Container is already in floating mode, not doing anything.\n");
246 if (con->
type == CT_WORKSPACE) {
247 LOG(
"Container is a workspace, not enabling floating mode.\n");
251 Con *focus_head_placeholder = NULL;
252 bool focus_before_parent =
true;
257 while (ancestor->
parent->
type != CT_WORKSPACE) {
259 ancestor = ancestor->
parent;
271 if (focus_before_parent) {
291 nc->
type = CT_FLOATING_CON;
298 struct focus_head *fh = &(ws->focus_head);
299 if (focus_before_parent) {
300 if (focus_head_placeholder) {
306 if (focus_head_placeholder) {
317 DLOG(
"Old container empty after setting this child to floating, closing\n");
325 sasprintf(&name,
"[i3 con] floatingcon around %p", con);
335 DLOG(
"Geometry not set, combining children\n");
378 DLOG(
"Centering above leader\n");
390 if (!current_output || current_output->
con != correct_output) {
391 DLOG(
"This floating window is on the wrong output, fixing coordinates (currently (%d, %d))\n",
396 if (current_output) {
401 if (!current_output || current_output->
con != correct_output) {
422 LOG(
"Container isn't floating, not doing anything.\n");
428 LOG(
"Can't disable floating for container in internal workspace.\n");
433 if (tiling_focused->
type == CT_WORKSPACE) {
459 if (con->
type == CT_FLOATING_CON) {
460 ELOG(
"Cannot toggle floating mode on con = %p because it is of type CT_FLOATING_CON.\n", con);
466 LOG(
"already floating, re-setting to tiling\n");
480 DLOG(
"Raising floating con %p / %s\n", con, con->
name);
492 DLOG(
"Con in an internal workspace\n");
499 ELOG(
"No output found at destination coordinates?\n");
504 DLOG(
"still the same ws\n");
508 DLOG(
"Need to re-assign!\n");
512 DLOG(
"Moving con %p / %s to workspace %p / %s\n", con, con->
name, ws, ws->
name);
539 assert(con->
type == CT_FLOATING_CON);
541 xcb_query_pointer_reply_t *reply = xcb_query_pointer_reply(
conn, xcb_query_pointer(
conn,
root), NULL);
543 ELOG(
"could not query pointer position, not moving this container\n");
548 if (output == NULL) {
549 ELOG(
"The pointer is not on any output, cannot move the container here.\n");
554 int32_t x = reply->root_x - con->
rect.
width / 2;
559 x =
MAX(x, (int32_t)output->
rect.
x);
574 con->rect.x = old_rect->x + (new_x -
event->root_x);
575 con->rect.y = old_rect->y + (new_y -
event->root_y);
596 DLOG(
"floating_drag_window\n");
609 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);
659 dest_height = old_rect->height - (new_y -
event->root_y);
661 dest_height = old_rect->height + (new_y -
event->root_y);
666 dest_width =
max(dest_width, (
int)(dest_height * ratio));
667 dest_height =
max(dest_height, (
int)(dest_width / ratio));
670 con->rect = (
Rect){dest_x, dest_y, dest_width, dest_height};
678 dest_x = old_rect->x + (old_rect->width - con->rect.width);
682 dest_y = old_rect->y + (old_rect->height - con->rect.height);
685 con->rect.x = dest_x;
686 con->rect.y = dest_y;
699 const xcb_button_press_event_t *event) {
700 DLOG(
"floating_resize_window\n");
710 if (event->event_x <= (int16_t)(con->
rect.
width / 2)) {
717 if (event->event_y <= (int16_t)(con->
rect.
height / 2)) {
733 DLOG(
"The container has been closed in the meantime.\n");
759 ELOG(
"No output found at destination coordinates. Not repositioning.\n");
784 DLOG(
"floating resize to %dx%d px\n", x,
y);
787 if (focused_con->
window == NULL) {
788 DLOG(
"No window is focused. Not resizing.\n");
793 bool prefer_height = (rect->
width == x);
817 DLOG(
"Fixing coordinates of floating window %p (rect (%d, %d), %d x %d)\n",
819 DLOG(
"old_rect = (%d, %d), %d x %d\n",
820 old_rect->
x, old_rect->
y, old_rect->
width, old_rect->
height);
821 DLOG(
"new_rect = (%d, %d), %d x %d\n",
822 new_rect->
x, new_rect->
y, new_rect->
width, new_rect->
height);
825 int32_t rel_x = con->
rect.
x - old_rect->
x + (int32_t)(con->
rect.
width / 2);
826 int32_t rel_y = con->
rect.
y - old_rect->
y + (int32_t)(con->
rect.
height / 2);
829 DLOG(
"rel_x = %d, rel_y = %d, fraction_x = %f, fraction_y = %f, output->w = %d, output->h = %d\n",
830 rel_x, rel_y, (
double)rel_x / old_rect->
width, (
double)rel_y / old_rect->
height,
833 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);
834 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);
835 DLOG(
"Resulting coordinates: x = %d, y = %d\n", con->
rect.
x, con->
rect.
y);
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.
bool con_is_floating(Con *con)
Returns true if the node is floating.
Con * con_new(Con *parent, i3Window *window)
A wrapper for con_new_skeleton, to retain the old con_new behaviour.
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Con * con_descend_tiling_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
bool con_is_docked(Con *con)
Returns true if the container is a docked container.
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.
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...
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
bool con_exists(Con *con)
Returns true if the given container (still) exists.
void con_detach(Con *con)
Detaches the given container from its current parent.
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
bool con_inside_focused(Con *con)
Checks if the given container is inside a focused container.
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
int con_num_children(Con *con)
Returns the number of children of this container.
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on.
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
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 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 floating_check_size(Con *floating_con, bool prefer_height)
Called when a floating window is created or resized.
void floating_disable(Con *con)
Disables floating mode for the given container by re-attaching the container to its old parent.
void floating_center(Con *con, Rect rect)
Centers a floating con above the specified rect.
static Rect total_outputs_dimensions(void)
static void floating_set_hint_atom(Con *con, bool floating)
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.
void floating_raise_con(Con *con)
Raises the given container in the list of floating containers.
void toggle_floating_mode(Con *con, bool automatic)
Calls floating_enable() for tiling containers and floating_disable() for floating containers.
void floating_resize(Con *floating_con, uint32_t x, uint32_t y)
Sets size of the CT_FLOATING_CON to specified dimensions.
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_move_to_pointer(Con *con)
Moves the given floating con to the current pointer position.
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...
bool floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
bool floating_reposition(Con *con, Rect newrect)
Repositions the CT_FLOATING_CON to have the coordinates specified by newrect, but only if the coordin...
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'.
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Output * get_output_from_rect(Rect rect)
Returns the active output which contains the midpoint of the given rect.
Output * output_containing_rect(Rect rect)
In output_containing_rect, we check if any active output contains part of the container.
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...
struct outputs_head outputs
void render_con(Con *con)
"Renders" the given container (and its children), meaning that all rects are updated correctly.
bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_parent)
Closes the given container including all children.
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
bool rect_equals(Rect a, Rect b)
void workspace_show(Con *workspace)
Switches to the given workspace.
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
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 x_push_node(Con *con)
This function pushes the properties of each node of the layout tree to X11 if they have changed (like...
void x_push_changes(Con *con)
Pushes all changes (state of each node, see x_push_node() and the window stack) to X11.
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,...
xcb_connection_t * conn
XCB connection and root screen.
xcb_screen_t * root_screen
#define DRAGGING_CB(name)
Macro to create a callback function for dragging.
drag_result_t
This is the return value of a drag operation like drag_pointer.
border_t
On which border was the dragging initiated?
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...
#define TAILQ_FOREACH(var, head, field)
#define TAILQ_INSERT_TAIL(head, elm, field)
#define TAILQ_PREV(elm, headname, field)
#define TAILQ_FIRST(head)
#define TAILQ_REMOVE(head, elm, field)
#define TAILQ_NEXT(elm, field)
#define TAILQ_EMPTY(head)
#define TAILQ_INSERT_BEFORE(listelm, elm, field)
#define TAILQ_INSERT_HEAD(head, elm, field)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field)
@ XCURSOR_CURSOR_TOP_LEFT_CORNER
@ XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER
@ XCURSOR_CURSOR_TOP_RIGHT_CORNER
@ XCURSOR_CURSOR_BOTTOM_LEFT_CORNER
int32_t floating_minimum_width
int32_t floating_minimum_height
int32_t floating_maximum_width
Maximum and minimum dimensions of a floating window.
int32_t floating_maximum_height
border_style_t default_floating_border
The default border style for new floating windows.
Stores a rectangle, for example the size of a window, the child window etc.
An Output is a physical output on your graphics driver.
Con * con
Pointer to the Con which represents this output.
Rect rect
x, y, width, height
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
xcb_window_t leader
Holds the xcb_window_t (just an ID) for the leader window (logical parent for toolwindows and similar...
A 'Con' represents everything from the X11 root window down to a single X11 window.
enum Con::@20 scratchpad_state
border_style_t max_user_border_style
border_style_t border_style
struct Rect geometry
the geometry this window requested when getting mapped
enum Con::@19 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
fullscreen_mode_t fullscreen_mode