15 #include <xcb/randr.h> 23 xcb_randr_get_output_primary_reply_t *
primary;
54 strcasecmp(output->
name, name) == 0)
71 die(
"No usable outputs available.\n");
99 DLOG(
"comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
119 DLOG(
"comparing x=%d y=%d %dx%d with x=%d and y=%d %dx%d\n",
140 int lx = rect.
x, uy = rect.
y;
145 DLOG(
"comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
171 else if (direction ==
D_LEFT)
173 else if (direction ==
D_DOWN)
181 DLOG(
"current = %s, best = %s\n", current->
name, best->
name);
205 other = &(output->
rect);
207 if ((direction ==
D_RIGHT && other->x > cur->
x) ||
208 (direction ==
D_LEFT && other->x < cur->
x)) {
211 if ((other->y + other->height) <= cur->
y ||
212 (cur->
y + cur->
height) <= other->y)
214 }
else if ((direction ==
D_DOWN && other->y > cur->
y) ||
215 (direction ==
D_UP && other->y < cur->
y)) {
218 if ((other->x + other->width) <= cur->
x ||
219 (cur->
x + cur->
width) <= other->x)
233 if ((direction ==
D_RIGHT && other->x < best->
rect.
x) ||
234 (direction ==
D_LEFT && other->x > best->
rect.
x) ||
235 (direction ==
D_DOWN && other->y < best->
rect.
y) ||
236 (direction ==
D_UP && other->y > best->
rect.
y)) {
243 if ((direction ==
D_RIGHT && other->x > best->
rect.
x) ||
244 (direction ==
D_LEFT && other->x < best->
rect.
x) ||
245 (direction ==
D_DOWN && other->y > best->
rect.
y) ||
246 (direction ==
D_UP && other->y < best->
rect.
y)) {
253 DLOG(
"current = %s, best = %s\n", current->
name, (best ? best->
name :
"NULL"));
280 Con *con = NULL, *current;
283 DLOG(
"init_con for output %s\n", output->
name);
288 if (strcmp(current->name, output->
name) != 0)
293 DLOG(
"Using existing con %p / %s\n", con, con->
name);
301 con->
type = CT_OUTPUT;
314 DLOG(
"Not adding workspace, this was a reused con\n");
318 DLOG(
"Changing layout, adding top/bottom dockarea\n");
320 topdock->
type = CT_DOCKAREA;
325 match->
dock = M_DOCK_TOP;
340 DLOG(
"adding main content container\n");
342 content->
type = CT_CON;
354 bottomdock->
type = CT_DOCKAREA;
359 match->
dock = M_DOCK_BOTTOM;
387 if (strcmp(assignment->
output, output->
name) != 0)
391 Con *workspace = NULL, *out;
394 !strcasecmp(child->name, assignment->
name));
395 if (workspace == NULL)
401 if (workspace_out == output->
con) {
402 LOG(
"Workspace \"%s\" assigned to output \"%s\", but it is already " 403 "there. Do you have two assignment directives for the same " 404 "workspace in your configuration file?\n",
410 LOG(
"Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
417 Con *previous = NULL;
419 LOG(
"Switching to previously used workspace \"%s\" on output \"%s\"\n",
420 previous->
name, workspace_out->
name);
432 TAILQ_FOREACH(floating_con, &(workspace->floating_head), floating_windows)
443 if (visible && previous == NULL) {
444 LOG(
"There is no workspace left on \"%s\", re-initializing\n",
445 workspace_out->
name);
448 DLOG(
"Done re-initializing, continuing with \"%s\"\n", output->
name);
468 if (strcmp(assignment->
output, output->
name) != 0)
471 LOG(
"Initializing first assigned workspace \"%s\" for output \"%s\"\n",
479 DLOG(
"Now adding a workspace\n");
498 DLOG(
"Output mode changed, updating rect\n");
499 assert(output->
con != NULL);
502 Con *content, *workspace, *child;
510 TAILQ_FOREACH(child, &(workspace->floating_head), floating_windows) {
526 DLOG(
"Setting workspace [%d,%s]'s layout to %d.\n", workspace->
num, workspace->
name, workspace->
layout);
527 if ((child =
TAILQ_FIRST(&(workspace->nodes_head)))) {
530 DLOG(
"Setting child [%d,%s]'s layout to %d.\n", child->
num, child->
name, child->
layout);
545 xcb_randr_get_output_info_reply_t *
output,
551 bool existing = (
new != NULL);
558 xcb_randr_get_output_info_name_length(output),
559 xcb_randr_get_output_info_name(output));
561 DLOG(
"found output with name %s\n", new->name);
566 if (output->crtc == XCB_NONE) {
572 }
else if (new->active)
573 new->to_be_disabled =
true;
577 xcb_randr_get_crtc_info_cookie_t icookie;
578 icookie = xcb_randr_get_crtc_info(conn, output->crtc, cts);
579 if ((crtc = xcb_randr_get_crtc_info_reply(conn, icookie, NULL)) == NULL) {
580 DLOG(
"Skipping output %s: could not get CRTC (%p)\n",
591 new->active = (
new->rect.width != 0 &&
new->rect.height != 0);
593 DLOG(
"width/height 0/0, disabling output\n");
597 DLOG(
"mode: %dx%d+%d+%d\n", new->rect.width, new->rect.height,
598 new->rect.x, new->rect.y);
603 if (!updated || !existing) {
624 xcb_randr_get_output_primary_cookie_t pcookie;
625 xcb_randr_get_screen_resources_current_cookie_t rcookie;
632 xcb_randr_output_t *randr_outputs;
635 rcookie = xcb_randr_get_screen_resources_current(
conn,
root);
636 pcookie = xcb_randr_get_output_primary(
conn,
root);
638 if ((
primary = xcb_randr_get_output_primary_reply(
conn, pcookie, NULL)) == NULL)
639 ELOG(
"Could not get RandR primary output\n");
645 ELOG(
"Could not query screen resources.\n");
647 cts = res->config_timestamp;
649 int len = xcb_randr_get_screen_resources_current_outputs_length(res);
650 randr_outputs = xcb_randr_get_screen_resources_current_outputs(res);
653 xcb_randr_get_output_info_cookie_t ocookie[len];
654 for (
int i = 0; i < len; i++)
655 ocookie[i] = xcb_randr_get_output_info(
conn, randr_outputs[i], cts);
658 for (
int i = 0; i < len; i++) {
659 xcb_randr_get_output_info_reply_t *
output;
661 if ((output = xcb_randr_get_output_info_reply(
conn, ocookie[i], NULL)) == NULL)
671 DLOG(
"Active RandR output found. Disabling root output.\n");
675 DLOG(
"No active RandR output found. Enabling root output.\n");
676 root_output->
active =
true;
684 DLOG(
"output %p / %s, position (%d, %d), checking for clones\n",
697 DLOG(
"output %p has the same position, his mode = %d x %d\n",
709 DLOG(
"disabling output %p (%s)\n", other, other->
name);
712 DLOG(
"new output mode %d x %d, other mode %d x %d\n",
723 if (output->
active && output->
con == NULL) {
724 DLOG(
"Need to initialize a Con for output %s\n", output->
name);
750 DLOG(
"Should add ws for output %s\n", output->
name);
759 DLOG(
"Focusing primary output %s\n", output->
name);
778 DLOG(
"Output %s disabled, re-assigning workspaces/docks\n", output->
name);
787 if (output->
con != NULL) {
792 DLOG(
"This output (%p) was focused! Getting next\n", output->
con);
794 DLOG(
"next = %p\n", next);
803 if (current != next &&
TAILQ_EMPTY(&(current->focus_head))) {
805 DLOG(
"Getting rid of current = %p / %s (empty, unfocused)\n", current, current->
name);
809 DLOG(
"Detaching current = %p / %s\n", current, current->
name);
811 DLOG(
"Re-attaching current = %p / %s\n", current, current->
name);
813 DLOG(
"Fixing the coordinates of floating containers\n");
815 TAILQ_FOREACH(floating_con, &(current->floating_head), floating_windows) {
818 DLOG(
"Done, next\n");
820 DLOG(
"re-attached all workspaces\n");
823 DLOG(
"now focusing next = %p\n", next);
831 if (child->
type != CT_DOCKAREA)
833 DLOG(
"Handling dock con %p\n", child);
840 DLOG(
"Moving dock client %p to nc %p\n", dock, nc);
842 DLOG(
"Re-attaching\n");
848 DLOG(
"destroying disappearing con %p\n", output->
con);
853 DLOG(
"Done. Should be fine now\n");
866 const xcb_query_extension_reply_t *extreply;
871 extreply = xcb_get_extension_data(
conn, &xcb_randr_id);
872 if (!extreply->present) {
873 DLOG(
"RandR is not present, activating root output.\n");
874 root_output->
active =
true;
883 if (event_base != NULL)
884 *event_base = extreply->first_event;
887 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE |
888 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE |
889 XCB_RANDR_NOTIFY_MASK_CRTC_CHANGE |
890 XCB_RANDR_NOTIFY_MASK_OUTPUT_PROPERTY);
Output * get_output_by_name(const char *name)
Returns the output with the given name if it is active (!) or NULL.
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given 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...
void con_detach(Con *con)
Detaches the given container from its current parent.
Stores which workspace (by name or number) goes to which output.
static Output * get_output_by_id(xcb_randr_output_t id)
void randr_query_outputs(void)
Initializes the specified output, assigning the specified workspace to it.
xcb_randr_get_crtc_info_reply_t crtc_info
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.
xcb_screen_t * root_screen
struct outputs_head outputs
void workspace_show(Con *workspace)
Switches to the given workspace.
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...
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
static void output_change_mode(xcb_connection_t *conn, Output *output)
static bool any_randr_output_active(void)
#define TAILQ_NEXT(elm, field)
xcb_randr_get_screen_resources_current_reply_t resources_reply
Output * get_first_output(void)
Returns the first output which is active.
xcb_randr_get_output_primary_reply_t * primary
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)
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
fullscreen_mode_t fullscreen_mode
void con_focus(Con *con)
Sets input focus to the given container.
An Output is a physical output on your graphics driver.
void randr_disable_output(Output *output)
Disables the output and moves its content.
Con * output_get_content(Con *output)
Returns the output container below the given output container.
void render_con(Con *con, bool render_fullscreen)
"Renders" the given container (and its children), meaning that all rects are updated correctly...
enum Match::@17 insert_where
Stores a rectangle, for example the size of a window, the child window etc.
#define TAILQ_INSERT_TAIL(head, elm, field)
static Output * root_output
struct ws_assignments_head ws_assignments
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
Rect rect
x, y, width, height
xcb_connection_t * conn
XCB connection and root screen.
#define TAILQ_HEAD_INITIALIZER(head)
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
#define TAILQ_FOREACH(var, head, field)
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...
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on...
int con_num_children(Con *con)
Returns the number of children of this container.
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...
bool changed
Internal flags, necessary for querying RandR screens (happens in two stages)
bool contained_by_output(Rect rect)
#define TAILQ_FIRST(head)
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
bool active
Whether the output is currently active (has a CRTC attached with a valid mode)
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...
A "match" is a data structure which acts like a mask or expression to match certain windows or not...
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.
void randr_init(int *event_base)
We have just established a connection to the X server and need the initial XRandR information to setu...
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 output_init_con(Output *output)
Initializes a CT_OUTPUT Con (searches existing ones from inplace restart before) to use for the given...
void match_init(Match *match)
int default_orientation
Default orientation for new containers.
Output * create_root_output(xcb_connection_t *conn)
Con * con
Pointer to the Con which represents this output.
Output * get_output_with_dimensions(Rect rect)
Returns the active output which spans exactly the area specified by rect or NULL if there is no outpu...
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.
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
xcb_randr_output_t id
Output id, so that we can requery the output directly later.
Con * con_new(Con *parent, i3Window *window)
A 'Con' represents everything from the X11 root window down to a single X11 window.
#define GREP_FIRST(dest, head, condition)
Con * create_workspace_on_output(Output *output, Con *content)
Returns a pointer to a new workspace in the given output.
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...
char * name
Name of the output.
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
#define TAILQ_EMPTY(head)
#define TAILQ_INSERT_HEAD(head, elm, field)
Output * get_output_next_wrap(direction_t direction, Output *current)
Like get_output_next with close_far == CLOSEST_OUTPUT, but wraps.