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",
112 else if (direction ==
D_LEFT)
114 else if (direction ==
D_DOWN)
122 DLOG(
"current = %s, best = %s\n", current->
name, best->
name);
146 other = &(output->
rect);
148 if ((direction ==
D_RIGHT && other->x > cur->
x) ||
149 (direction ==
D_LEFT && other->x < cur->
x)) {
152 if ((other->y + other->height) <= cur->
y ||
153 (cur->
y + cur->
height) <= other->y)
155 }
else if ((direction ==
D_DOWN && other->y > cur->
y) ||
156 (direction ==
D_UP && other->y < cur->
y)) {
159 if ((other->x + other->width) <= cur->
x ||
160 (cur->
x + cur->
width) <= other->x)
174 if ((direction ==
D_RIGHT && other->x < best->
rect.
x) ||
175 (direction ==
D_LEFT && other->x > best->
rect.
x) ||
176 (direction ==
D_DOWN && other->y < best->
rect.
y) ||
177 (direction ==
D_UP && other->y > best->
rect.
y)) {
184 if ((direction ==
D_RIGHT && other->x > best->
rect.
x) ||
185 (direction ==
D_LEFT && other->x < best->
rect.
x) ||
186 (direction ==
D_DOWN && other->y > best->
rect.
y) ||
187 (direction ==
D_UP && other->y < best->
rect.
y)) {
194 DLOG(
"current = %s, best = %s\n", current->
name, (best ? best->
name :
"NULL"));
204 DLOG(
"RandR extension unusable, disabling.\n");
228 Con *con = NULL, *current;
231 DLOG(
"init_con for output %s\n", output->
name);
236 if (strcmp(current->name, output->
name) != 0)
241 DLOG(
"Using existing con %p / %s\n", con, con->
name);
249 con->
type = CT_OUTPUT;
262 DLOG(
"Not adding workspace, this was a reused con\n");
266 DLOG(
"Changing layout, adding top/bottom dockarea\n");
268 topdock->
type = CT_DOCKAREA;
269 topdock->
layout = L_DOCKAREA;
273 match->
dock = M_DOCK_TOP;
288 DLOG(
"adding main content container\n");
290 content->
type = CT_CON;
291 content->
layout = L_SPLITH;
302 bottomdock->
type = CT_DOCKAREA;
303 bottomdock->
layout = L_DOCKAREA;
307 match->
dock = M_DOCK_BOTTOM;
335 if (strcmp(assignment->
output, output->
name) != 0)
339 Con *workspace = NULL, *out;
342 !strcasecmp(child->name, assignment->
name));
343 if (workspace == NULL)
349 if (workspace_out == output->
con) {
350 LOG(
"Workspace \"%s\" assigned to output \"%s\", but it is already "
351 "there. Do you have two assignment directives for the same "
352 "workspace in your configuration file?\n",
358 LOG(
"Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
365 Con *previous = NULL;
367 LOG(
"Switching to previously used workspace \"%s\" on output \"%s\"\n",
368 previous->
name, workspace_out->
name);
380 TAILQ_FOREACH(floating_con, &(workspace->floating_head), floating_windows)
391 if (visible && previous == NULL) {
392 LOG(
"There is no workspace left on \"%s\", re-initializing\n",
393 workspace_out->
name);
396 DLOG(
"Done re-initializing, continuing with \"%s\"\n", output->
name);
416 if (strcmp(assignment->
output, output->
name) != 0)
419 LOG(
"Initializing first assigned workspace \"%s\" for output \"%s\"\n",
427 DLOG(
"Now adding a workspace\n");
446 DLOG(
"Output mode changed, updating rect\n");
447 assert(output->
con != NULL);
450 Con *content, *workspace, *child;
458 TAILQ_FOREACH(child, &(workspace->floating_head), floating_windows) {
474 DLOG(
"Setting workspace [%d,%s]'s layout to %d.\n", workspace->
num, workspace->
name, workspace->
layout);
475 if ((child =
TAILQ_FIRST(&(workspace->nodes_head)))) {
476 if (child->
layout == L_SPLITV || child->
layout == L_SPLITH)
478 DLOG(
"Setting child [%d,%s]'s layout to %d.\n", child->
num, child->
name, child->
layout);
493 xcb_randr_get_output_info_reply_t *
output,
499 bool existing = (
new != NULL);
506 xcb_randr_get_output_info_name_length(output),
507 xcb_randr_get_output_info_name(output));
509 DLOG(
"found output with name %s\n", new->name);
514 if (output->crtc == XCB_NONE) {
519 }
else if (new->active)
520 new->to_be_disabled =
true;
524 xcb_randr_get_crtc_info_cookie_t icookie;
525 icookie = xcb_randr_get_crtc_info(conn, output->crtc, cts);
526 if ((crtc = xcb_randr_get_crtc_info_reply(conn, icookie, NULL)) == NULL) {
527 DLOG(
"Skipping output %s: could not get CRTC (%p)\n",
538 new->active = (
new->rect.width != 0 &&
new->rect.height != 0);
540 DLOG(
"width/height 0/0, disabling output\n");
544 DLOG(
"mode: %dx%d+%d+%d\n", new->rect.width, new->rect.height,
545 new->rect.x, new->rect.y);
550 if (!updated || !existing) {
568 xcb_randr_get_output_primary_cookie_t pcookie;
569 xcb_randr_get_screen_resources_current_cookie_t rcookie;
577 xcb_randr_output_t *randr_outputs;
583 rcookie = xcb_randr_get_screen_resources_current(
conn,
root);
584 pcookie = xcb_randr_get_output_primary(
conn,
root);
586 if ((
primary = xcb_randr_get_output_primary_reply(
conn, pcookie, NULL)) == NULL)
587 ELOG(
"Could not get RandR primary output\n");
588 else DLOG(
"primary output is %08x\n",
primary->output);
589 if ((res = xcb_randr_get_screen_resources_current_reply(
conn, rcookie, NULL)) == NULL) {
593 cts = res->config_timestamp;
595 int len = xcb_randr_get_screen_resources_current_outputs_length(res);
596 randr_outputs = xcb_randr_get_screen_resources_current_outputs(res);
599 xcb_randr_get_output_info_cookie_t ocookie[len];
600 for (
int i = 0; i < len; i++)
601 ocookie[i] = xcb_randr_get_output_info(
conn, randr_outputs[i], cts);
604 for (
int i = 0; i < len; i++) {
605 xcb_randr_get_output_info_reply_t *
output;
607 if ((output = xcb_randr_get_output_info_reply(
conn, ocookie[i], NULL)) == NULL)
619 DLOG(
"output %p / %s, position (%d, %d), checking for clones\n",
632 DLOG(
"output %p has the same position, his mode = %d x %d\n",
644 DLOG(
"disabling output %p (%s)\n", other, other->
name);
647 DLOG(
"new output mode %d x %d, other mode %d x %d\n",
658 if (output->
active && output->
con == NULL) {
659 DLOG(
"Need to initialize a Con for output %s\n", output->
name);
670 DLOG(
"Output %s disabled, re-assigning workspaces/docks\n", output->
name);
679 if (output->
con != NULL) {
684 DLOG(
"This output (%p) was focused! Getting next\n", output->
con);
686 DLOG(
"next = %p\n", next);
695 if (current != next &&
TAILQ_EMPTY(&(current->focus_head))) {
697 DLOG(
"Getting rid of current = %p / %s (empty, unfocused)\n", current, current->
name);
701 DLOG(
"Detaching current = %p / %s\n", current, current->
name);
703 DLOG(
"Re-attaching current = %p / %s\n", current, current->
name);
705 DLOG(
"Fixing the coordinates of floating containers\n");
707 TAILQ_FOREACH(floating_con, &(current->floating_head), floating_windows)
709 DLOG(
"Done, next\n");
711 DLOG(
"re-attached all workspaces\n");
714 DLOG(
"now focusing next = %p\n", next);
722 if (child->
type != CT_DOCKAREA)
724 DLOG(
"Handling dock con %p\n", child);
731 DLOG(
"Moving dock client %p to nc %p\n", dock, nc);
733 DLOG(
"Re-attaching\n");
739 DLOG(
"destroying disappearing con %p\n", output->
con);
741 DLOG(
"Done. Should be fine now\n");
756 ELOG(
"No outputs found via RandR, disabling\n");
770 DLOG(
"Should add ws for output %s\n", output->
name);
779 DLOG(
"Focusing primary output %s\n", output->
name);
796 const xcb_query_extension_reply_t *extreply;
798 extreply = xcb_get_extension_data(
conn, &xcb_randr_id);
799 if (!extreply->present) {
804 if (event_base != NULL)
805 *event_base = extreply->first_event;
808 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE |
809 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE |
810 XCB_RANDR_NOTIFY_MASK_CRTC_CHANGE |
811 XCB_RANDR_NOTIFY_MASK_OUTPUT_PROPERTY);