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);