2 #define I3__FILE__ "randr.c"
17 #include <xcb/randr.h>
25 xcb_randr_get_output_primary_reply_t *
primary;
56 strcasecmp(output->
name, name) == 0)
73 die(
"No usable outputs available.\n");
101 DLOG(
"comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
121 int lx = rect.
x, uy = rect.
y;
126 DLOG(
"comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
152 else if (direction ==
D_LEFT)
154 else if (direction ==
D_DOWN)
162 DLOG(
"current = %s, best = %s\n", current->
name, best->
name);
186 other = &(output->
rect);
188 if ((direction ==
D_RIGHT && other->x > cur->
x) ||
189 (direction ==
D_LEFT && other->x < cur->
x)) {
192 if ((other->y + other->height) <= cur->
y ||
193 (cur->
y + cur->
height) <= other->y)
195 }
else if ((direction ==
D_DOWN && other->y > cur->
y) ||
196 (direction ==
D_UP && other->y < cur->
y)) {
199 if ((other->x + other->width) <= cur->
x ||
200 (cur->
x + cur->
width) <= other->x)
214 if ((direction ==
D_RIGHT && other->x < best->
rect.
x) ||
215 (direction ==
D_LEFT && other->x > best->
rect.
x) ||
216 (direction ==
D_DOWN && other->y < best->
rect.
y) ||
217 (direction ==
D_UP && other->y > best->
rect.
y)) {
224 if ((direction ==
D_RIGHT && other->x > best->
rect.
x) ||
225 (direction ==
D_LEFT && other->x < best->
rect.
x) ||
226 (direction ==
D_DOWN && other->y > best->
rect.
y) ||
227 (direction ==
D_UP && other->y < best->
rect.
y)) {
234 DLOG(
"current = %s, best = %s\n", current->
name, (best ? best->
name :
"NULL"));
261 Con *con = NULL, *current;
264 DLOG(
"init_con for output %s\n", output->
name);
269 if (strcmp(current->name, output->
name) != 0)
274 DLOG(
"Using existing con %p / %s\n", con, con->
name);
282 con->
type = CT_OUTPUT;
295 DLOG(
"Not adding workspace, this was a reused con\n");
299 DLOG(
"Changing layout, adding top/bottom dockarea\n");
301 topdock->
type = CT_DOCKAREA;
306 match->
dock = M_DOCK_TOP;
321 DLOG(
"adding main content container\n");
323 content->
type = CT_CON;
335 bottomdock->
type = CT_DOCKAREA;
340 match->
dock = M_DOCK_BOTTOM;
368 if (strcmp(assignment->
output, output->
name) != 0)
372 Con *workspace = NULL, *out;
375 !strcasecmp(child->name, assignment->
name));
376 if (workspace == NULL)
382 if (workspace_out == output->
con) {
383 LOG(
"Workspace \"%s\" assigned to output \"%s\", but it is already "
384 "there. Do you have two assignment directives for the same "
385 "workspace in your configuration file?\n",
391 LOG(
"Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
398 Con *previous = NULL;
400 LOG(
"Switching to previously used workspace \"%s\" on output \"%s\"\n",
401 previous->
name, workspace_out->
name);
413 TAILQ_FOREACH(floating_con, &(workspace->floating_head), floating_windows)
424 if (visible && previous == NULL) {
425 LOG(
"There is no workspace left on \"%s\", re-initializing\n",
426 workspace_out->
name);
429 DLOG(
"Done re-initializing, continuing with \"%s\"\n", output->
name);
449 if (strcmp(assignment->
output, output->
name) != 0)
452 LOG(
"Initializing first assigned workspace \"%s\" for output \"%s\"\n",
460 DLOG(
"Now adding a workspace\n");
479 DLOG(
"Output mode changed, updating rect\n");
480 assert(output->
con != NULL);
483 Con *content, *workspace, *child;
491 TAILQ_FOREACH(child, &(workspace->floating_head), floating_windows) {
507 DLOG(
"Setting workspace [%d,%s]'s layout to %d.\n", workspace->
num, workspace->
name, workspace->
layout);
508 if ((child =
TAILQ_FIRST(&(workspace->nodes_head)))) {
511 DLOG(
"Setting child [%d,%s]'s layout to %d.\n", child->
num, child->
name, child->
layout);
526 xcb_randr_get_output_info_reply_t *
output,
532 bool existing = (
new != NULL);
539 xcb_randr_get_output_info_name_length(output),
540 xcb_randr_get_output_info_name(output));
542 DLOG(
"found output with name %s\n", new->name);
547 if (output->crtc == XCB_NONE) {
553 }
else if (new->active)
554 new->to_be_disabled =
true;
558 xcb_randr_get_crtc_info_cookie_t icookie;
559 icookie = xcb_randr_get_crtc_info(conn, output->crtc, cts);
560 if ((crtc = xcb_randr_get_crtc_info_reply(conn, icookie, NULL)) == NULL) {
561 DLOG(
"Skipping output %s: could not get CRTC (%p)\n",
572 new->active = (
new->rect.width != 0 &&
new->rect.height != 0);
574 DLOG(
"width/height 0/0, disabling output\n");
578 DLOG(
"mode: %dx%d+%d+%d\n", new->rect.width, new->rect.height,
579 new->rect.x, new->rect.y);
584 if (!updated || !existing) {
605 xcb_randr_get_output_primary_cookie_t pcookie;
606 xcb_randr_get_screen_resources_current_cookie_t rcookie;
613 xcb_randr_output_t *randr_outputs;
616 rcookie = xcb_randr_get_screen_resources_current(
conn,
root);
617 pcookie = xcb_randr_get_output_primary(
conn,
root);
619 if ((
primary = xcb_randr_get_output_primary_reply(
conn, pcookie, NULL)) == NULL)
620 ELOG(
"Could not get RandR primary output\n");
626 ELOG(
"Could not query screen resources.\n");
628 cts = res->config_timestamp;
630 int len = xcb_randr_get_screen_resources_current_outputs_length(res);
631 randr_outputs = xcb_randr_get_screen_resources_current_outputs(res);
634 xcb_randr_get_output_info_cookie_t ocookie[len];
635 for (
int i = 0; i < len; i++)
636 ocookie[i] = xcb_randr_get_output_info(
conn, randr_outputs[i], cts);
639 for (
int i = 0; i < len; i++) {
640 xcb_randr_get_output_info_reply_t *
output;
642 if ((output = xcb_randr_get_output_info_reply(
conn, ocookie[i], NULL)) == NULL)
652 DLOG(
"Active RandR output found. Disabling root output.\n");
656 DLOG(
"No active RandR output found. Enabling root output.\n");
657 root_output->
active =
true;
665 DLOG(
"output %p / %s, position (%d, %d), checking for clones\n",
678 DLOG(
"output %p has the same position, his mode = %d x %d\n",
690 DLOG(
"disabling output %p (%s)\n", other, other->
name);
693 DLOG(
"new output mode %d x %d, other mode %d x %d\n",
704 if (output->
active && output->
con == NULL) {
705 DLOG(
"Need to initialize a Con for output %s\n", output->
name);
716 DLOG(
"Output %s disabled, re-assigning workspaces/docks\n", output->
name);
725 if (output->
con != NULL) {
730 DLOG(
"This output (%p) was focused! Getting next\n", output->
con);
732 DLOG(
"next = %p\n", next);
741 if (current != next &&
TAILQ_EMPTY(&(current->focus_head))) {
743 DLOG(
"Getting rid of current = %p / %s (empty, unfocused)\n", current, current->
name);
747 DLOG(
"Detaching current = %p / %s\n", current, current->
name);
749 DLOG(
"Re-attaching current = %p / %s\n", current, current->
name);
751 DLOG(
"Fixing the coordinates of floating containers\n");
753 TAILQ_FOREACH(floating_con, &(current->floating_head), floating_windows)
755 DLOG(
"Done, next\n");
757 DLOG(
"re-attached all workspaces\n");
760 DLOG(
"now focusing next = %p\n", next);
768 if (child->
type != CT_DOCKAREA)
770 DLOG(
"Handling dock con %p\n", child);
777 DLOG(
"Moving dock client %p to nc %p\n", dock, nc);
779 DLOG(
"Re-attaching\n");
785 DLOG(
"destroying disappearing con %p\n", output->
con);
787 DLOG(
"Done. Should be fine now\n");
808 DLOG(
"Should add ws for output %s\n", output->
name);
817 DLOG(
"Focusing primary output %s\n", output->
name);
834 const xcb_query_extension_reply_t *extreply;
839 extreply = xcb_get_extension_data(
conn, &xcb_randr_id);
840 if (!extreply->present) {
841 DLOG(
"RandR is not present, activating root output.\n");
842 root_output->
active =
true;
851 if (event_base != NULL)
852 *event_base = extreply->first_event;
855 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE |
856 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE |
857 XCB_RANDR_NOTIFY_MASK_CRTC_CHANGE |
858 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.
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
void con_focus(Con *con)
Sets input focus to the given container.
#define TAILQ_EMPTY(head)
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Output * get_output_next_wrap(direction_t direction, Output *current)
Like get_output_next with close_far == CLOSEST_OUTPUT, but wraps.
Con * create_workspace_on_output(Output *output, Con *content)
Returns a pointer to a new workspace in the given output.
void match_init(Match *match)
Stores which workspace (by name or number) goes to which output.
#define TAILQ_FOREACH(var, head, field)
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_parent, bool force_set_focus)
Closes the given container including all children.
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
xcb_connection_t * conn
XCB connection and root screen.
fullscreen_mode_t fullscreen_mode
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.
#define TAILQ_NEXT(elm, field)
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on...
xcb_randr_output_t id
Output id, so that we can requery the output directly later.
void con_detach(Con *con)
Detaches the given container from its current parent.
bool contained_by_output(Rect rect)
void workspace_show(Con *workspace)
Switches to the given workspace.
bool changed
Internal flags, necessary for querying RandR screens (happens in two stages)
#define GREP_FIRST(dest, head, condition)
Con * con
Pointer to the Con which represents this output.
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)
static bool any_randr_output_active(void)
static Output * get_output_by_id(xcb_randr_output_t id)
struct ws_assignments_head ws_assignments
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...
xcb_randr_get_output_primary_reply_t * primary
#define TAILQ_INSERT_HEAD(head, elm, field)
int default_orientation
Default orientation for new containers.
Stores a rectangle, for example the size of a window, the child window etc.
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...
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
void randr_query_outputs(void)
Initializes the specified output, assigning the specified workspace to it.
enum Match::@17 insert_where
A 'Con' represents everything from the X11 root window down to a single X11 window.
bool active
Whether the output is currently active (has a CRTC attached with a valid mode)
struct outputs_head outputs
#define TAILQ_FIRST(head)
static Output * root_output
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...
static void output_change_mode(xcb_connection_t *conn, Output *output)
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
xcb_randr_get_screen_resources_current_reply_t resources_reply
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
#define TAILQ_INSERT_TAIL(head, elm, field)
xcb_screen_t * root_screen
int con_num_children(Con *con)
Returns the number of children of this container.
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...
Output * get_first_output(void)
Returns the first output which is active.
Rect rect
x, y, width, height
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...
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
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...
Output * get_output_by_name(const char *name)
Returns the output with the given name if it is active (!) or NULL.
A "match" is a data structure which acts like a mask or expression to match certain windows or not...
An Output is a physical output on your graphics driver.
Con * con_new(Con *parent, i3Window *window)
Output * create_root_output(xcb_connection_t *conn)
char * name
Name of the output.
xcb_randr_get_crtc_info_reply_t crtc_info
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...
#define TAILQ_HEAD_INITIALIZER(head)