2 #define I3__FILE__ "randr.c"
17 #include <xcb/randr.h>
25 xcb_randr_get_output_primary_reply_t *
primary;
55 strcasecmp(output->
name, name) == 0)
72 die(
"No usable outputs available.\n");
85 DLOG(
"comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
105 int lx = rect.
x, uy = rect.
y;
110 DLOG(
"comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
137 else if (direction ==
D_LEFT)
139 else if (direction ==
D_DOWN)
147 DLOG(
"current = %s, best = %s\n", current->
name, best->
name);
171 other = &(output->
rect);
173 if ((direction ==
D_RIGHT && other->x > cur->
x) ||
174 (direction ==
D_LEFT && other->x < cur->
x)) {
177 if ((other->y + other->height) <= cur->
y ||
178 (cur->
y + cur->
height) <= other->y)
180 }
else if ((direction ==
D_DOWN && other->y > cur->
y) ||
181 (direction ==
D_UP && other->y < cur->
y)) {
184 if ((other->x + other->width) <= cur->
x ||
185 (cur->
x + cur->
width) <= other->x)
199 if ((direction ==
D_RIGHT && other->x < best->
rect.
x) ||
200 (direction ==
D_LEFT && other->x > best->
rect.
x) ||
201 (direction ==
D_DOWN && other->y < best->
rect.
y) ||
202 (direction ==
D_UP && other->y > best->
rect.
y)) {
209 if ((direction ==
D_RIGHT && other->x > best->
rect.
x) ||
210 (direction ==
D_LEFT && other->x < best->
rect.
x) ||
211 (direction ==
D_DOWN && other->y > best->
rect.
y) ||
212 (direction ==
D_UP && other->y < best->
rect.
y)) {
219 DLOG(
"current = %s, best = %s\n", current->
name, (best ? best->
name :
"NULL"));
229 DLOG(
"RandR extension unusable, disabling.\n");
253 Con *con = NULL, *current;
256 DLOG(
"init_con for output %s\n", output->
name);
261 if (strcmp(current->name, output->
name) != 0)
266 DLOG(
"Using existing con %p / %s\n", con, con->
name);
274 con->
type = CT_OUTPUT;
287 DLOG(
"Not adding workspace, this was a reused con\n");
291 DLOG(
"Changing layout, adding top/bottom dockarea\n");
293 topdock->
type = CT_DOCKAREA;
298 match->
dock = M_DOCK_TOP;
313 DLOG(
"adding main content container\n");
315 content->
type = CT_CON;
327 bottomdock->
type = CT_DOCKAREA;
332 match->
dock = M_DOCK_BOTTOM;
360 if (strcmp(assignment->
output, output->
name) != 0)
364 Con *workspace = NULL, *out;
367 !strcasecmp(child->name, assignment->
name));
368 if (workspace == NULL)
374 if (workspace_out == output->
con) {
375 LOG(
"Workspace \"%s\" assigned to output \"%s\", but it is already "
376 "there. Do you have two assignment directives for the same "
377 "workspace in your configuration file?\n",
383 LOG(
"Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
390 Con *previous = NULL;
392 LOG(
"Switching to previously used workspace \"%s\" on output \"%s\"\n",
393 previous->
name, workspace_out->
name);
405 TAILQ_FOREACH(floating_con, &(workspace->floating_head), floating_windows)
416 if (visible && previous == NULL) {
417 LOG(
"There is no workspace left on \"%s\", re-initializing\n",
418 workspace_out->
name);
421 DLOG(
"Done re-initializing, continuing with \"%s\"\n", output->
name);
441 if (strcmp(assignment->
output, output->
name) != 0)
444 LOG(
"Initializing first assigned workspace \"%s\" for output \"%s\"\n",
452 DLOG(
"Now adding a workspace\n");
471 DLOG(
"Output mode changed, updating rect\n");
472 assert(output->
con != NULL);
475 Con *content, *workspace, *child;
483 TAILQ_FOREACH(child, &(workspace->floating_head), floating_windows) {
499 DLOG(
"Setting workspace [%d,%s]'s layout to %d.\n", workspace->
num, workspace->
name, workspace->
layout);
500 if ((child =
TAILQ_FIRST(&(workspace->nodes_head)))) {
503 DLOG(
"Setting child [%d,%s]'s layout to %d.\n", child->
num, child->
name, child->
layout);
518 xcb_randr_get_output_info_reply_t *
output,
524 bool existing = (
new != NULL);
531 xcb_randr_get_output_info_name_length(output),
532 xcb_randr_get_output_info_name(output));
534 DLOG(
"found output with name %s\n", new->name);
539 if (output->crtc == XCB_NONE) {
544 }
else if (new->active)
545 new->to_be_disabled =
true;
549 xcb_randr_get_crtc_info_cookie_t icookie;
550 icookie = xcb_randr_get_crtc_info(conn, output->crtc, cts);
551 if ((crtc = xcb_randr_get_crtc_info_reply(conn, icookie, NULL)) == NULL) {
552 DLOG(
"Skipping output %s: could not get CRTC (%p)\n",
563 new->active = (
new->rect.width != 0 &&
new->rect.height != 0);
565 DLOG(
"width/height 0/0, disabling output\n");
569 DLOG(
"mode: %dx%d+%d+%d\n", new->rect.width, new->rect.height,
570 new->rect.x, new->rect.y);
575 if (!updated || !existing) {
593 xcb_randr_get_output_primary_cookie_t pcookie;
594 xcb_randr_get_screen_resources_current_cookie_t rcookie;
602 xcb_randr_output_t *randr_outputs;
608 rcookie = xcb_randr_get_screen_resources_current(
conn,
root);
609 pcookie = xcb_randr_get_output_primary(
conn,
root);
611 if ((
primary = xcb_randr_get_output_primary_reply(
conn, pcookie, NULL)) == NULL)
612 ELOG(
"Could not get RandR primary output\n");
613 else DLOG(
"primary output is %08x\n",
primary->output);
614 if ((res = xcb_randr_get_screen_resources_current_reply(
conn, rcookie, NULL)) == NULL) {
618 cts = res->config_timestamp;
620 int len = xcb_randr_get_screen_resources_current_outputs_length(res);
621 randr_outputs = xcb_randr_get_screen_resources_current_outputs(res);
624 xcb_randr_get_output_info_cookie_t ocookie[len];
625 for (
int i = 0; i < len; i++)
626 ocookie[i] = xcb_randr_get_output_info(
conn, randr_outputs[i], cts);
629 for (
int i = 0; i < len; i++) {
630 xcb_randr_get_output_info_reply_t *
output;
632 if ((output = xcb_randr_get_output_info_reply(
conn, ocookie[i], NULL)) == NULL)
644 DLOG(
"output %p / %s, position (%d, %d), checking for clones\n",
657 DLOG(
"output %p has the same position, his mode = %d x %d\n",
669 DLOG(
"disabling output %p (%s)\n", other, other->
name);
672 DLOG(
"new output mode %d x %d, other mode %d x %d\n",
683 if (output->
active && output->
con == NULL) {
684 DLOG(
"Need to initialize a Con for output %s\n", output->
name);
695 DLOG(
"Output %s disabled, re-assigning workspaces/docks\n", output->
name);
704 if (output->
con != NULL) {
709 DLOG(
"This output (%p) was focused! Getting next\n", output->
con);
711 DLOG(
"next = %p\n", next);
720 if (current != next &&
TAILQ_EMPTY(&(current->focus_head))) {
722 DLOG(
"Getting rid of current = %p / %s (empty, unfocused)\n", current, current->
name);
726 DLOG(
"Detaching current = %p / %s\n", current, current->
name);
728 DLOG(
"Re-attaching current = %p / %s\n", current, current->
name);
730 DLOG(
"Fixing the coordinates of floating containers\n");
732 TAILQ_FOREACH(floating_con, &(current->floating_head), floating_windows)
734 DLOG(
"Done, next\n");
736 DLOG(
"re-attached all workspaces\n");
739 DLOG(
"now focusing next = %p\n", next);
747 if (child->
type != CT_DOCKAREA)
749 DLOG(
"Handling dock con %p\n", child);
756 DLOG(
"Moving dock client %p to nc %p\n", dock, nc);
758 DLOG(
"Re-attaching\n");
764 DLOG(
"destroying disappearing con %p\n", output->
con);
766 DLOG(
"Done. Should be fine now\n");
781 ELOG(
"No outputs found via RandR, disabling\n");
795 DLOG(
"Should add ws for output %s\n", output->
name);
804 DLOG(
"Focusing primary output %s\n", output->
name);
821 const xcb_query_extension_reply_t *extreply;
823 extreply = xcb_get_extension_data(
conn, &xcb_randr_id);
824 if (!extreply->present) {
829 if (event_base != NULL)
830 *event_base = extreply->first_event;
833 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE |
834 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE |
835 XCB_RANDR_NOTIFY_MASK_CRTC_CHANGE |
836 XCB_RANDR_NOTIFY_MASK_OUTPUT_PROPERTY);
Con * con_for_window(Con *con, i3Window *window, Match **store_match)
Returns the first container below 'con' which wants to swallow this window TODO: priority.
bool update_if_necessary(uint32_t *destination, const uint32_t new_value)
Updates *destination with new_value and returns true if it was changed or false if it was the same...
char * name
Name of the output.
#define GREP_FIRST(dest, head, condition)
void randr_init(int *event_base)
We have just established a connection to the X server and need the initial XRandR information to setu...
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.
void workspace_show(Con *workspace)
Switches to the given workspace.
Stores which workspace (by name) goes to which output.
#define TAILQ_INSERT_TAIL(head, elm, field)
static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id, xcb_randr_get_output_info_reply_t *output, xcb_timestamp_t cts, resources_reply *res)
Stores a rectangle, for example the size of a window, the child window etc.
xcb_randr_get_screen_resources_current_reply_t resources_reply
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
void output_init_con(Output *output)
Initializes a CT_OUTPUT Con (searches existing ones from inplace restart before) to use for the given...
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.
static bool randr_disabled
void randr_query_outputs(void)
Initializes the specified output, assigning the specified workspace to it.
#define TAILQ_EMPTY(head)
int con_num_children(Con *con)
Returns the number of children of this container.
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
A "match" is a data structure which acts like a mask or expression to match certain windows or not...
#define TAILQ_INSERT_HEAD(head, elm, field)
Output * get_output_by_name(const char *name)
Returns the output with the given name if it is active (!) or NULL.
void * scalloc(size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
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.
Output * get_output_next(direction_t direction, Output *current, output_close_far_t close_far)
Gets the output which is the next one in the given direction.
xcb_randr_output_t id
Output id, so that we can requery the output directly later.
xcb_randr_get_output_primary_reply_t * primary
Output * get_first_output(void)
Returns the first output which is active.
void match_init(Match *match)
int default_orientation
Default orientation for new containers.
struct ws_assignments_head ws_assignments
#define TAILQ_HEAD_INITIALIZER(head)
struct outputs_head outputs
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
Rect rect
x, y, width, height
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...
Output * get_output_next_wrap(direction_t direction, Output *current)
Like get_output_next with close_far == CLOSEST_OUTPUT, but wraps.
xcb_screen_t * root_screen
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.
enum Match::@15 insert_where
#define TAILQ_NEXT(elm, field)
void con_focus(Con *con)
Sets input focus to the given container.
#define TAILQ_FIRST(head)
bool active
Whether the output is currently active (has a CRTC attached with a valid mode)
An Output is a physical output on your graphics driver.
bool changed
Internal flags, necessary for querying RandR screens (happens in two stages)
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 TAILQ_FOREACH(var, head, field)
Con * con_new(Con *parent, i3Window *window)
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
void con_detach(Con *con)
Detaches the given container from its current parent.
Con * output_get_content(Con *output)
Returns the output container below the given output container.
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 init_ws_for_output(Output *output, Con *content)
Initializes at least one workspace for this output, trying the following steps until there is at leas...
void disable_randr(xcb_connection_t *conn)
Disables RandR support by creating exactly one output with the size of the X11 screen.
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.
Con * create_workspace_on_output(Output *output, Con *content)
xcb_randr_get_crtc_info_reply_t crtc_info
static Output * get_output_by_id(xcb_randr_output_t id)
static void output_change_mode(xcb_connection_t *conn, Output *output)
enum Con::@19 fullscreen_mode