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",
107 DLOG(
"current = %s, best = %s\n", current->
name, best->
name);
124 other = &(output->
rect);
126 if ((direction ==
D_RIGHT && other->x > cur->
x) ||
127 (direction ==
D_LEFT && other->x < cur->
x)) {
130 if ((other->y + other->height) <= cur->
y ||
131 (cur->
y + cur->
height) <= other->y)
133 }
else if ((direction ==
D_DOWN && other->y > cur->
y) ||
134 (direction ==
D_UP && other->y < cur->
y)) {
137 if ((other->x + other->width) <= cur->
x ||
138 (cur->
x + cur->
width) <= other->x)
152 if ((direction ==
D_RIGHT && other->x < best->
rect.
x) ||
153 (direction ==
D_LEFT && other->x > best->
rect.
x) ||
154 (direction ==
D_DOWN && other->y < best->
rect.
y) ||
155 (direction ==
D_UP && other->y > best->
rect.
y)) {
162 if ((direction ==
D_RIGHT && other->x > best->
rect.
x) ||
163 (direction ==
D_LEFT && other->x < best->
rect.
x) ||
164 (direction ==
D_DOWN && other->y > best->
rect.
y) ||
165 (direction ==
D_UP && other->y < best->
rect.
y)) {
172 DLOG(
"current = %s, best = %s\n", current->
name, (best ? best->
name :
"NULL"));
182 DLOG(
"RandR extension unusable, disabling.\n");
206 Con *con = NULL, *current;
209 DLOG(
"init_con for output %s\n", output->
name);
214 if (strcmp(current->name, output->
name) != 0)
219 DLOG(
"Using existing con %p / %s\n", con, con->
name);
227 con->
type = CT_OUTPUT;
240 DLOG(
"Not adding workspace, this was a reused con\n");
244 DLOG(
"Changing layout, adding top/bottom dockarea\n");
246 topdock->
type = CT_DOCKAREA;
247 topdock->
layout = L_DOCKAREA;
251 match->
dock = M_DOCK_TOP;
266 DLOG(
"adding main content container\n");
268 content->
type = CT_CON;
269 content->
layout = L_SPLITH;
280 bottomdock->
type = CT_DOCKAREA;
281 bottomdock->
layout = L_DOCKAREA;
285 match->
dock = M_DOCK_BOTTOM;
313 if (strcmp(assignment->
output, output->
name) != 0)
317 Con *workspace = NULL, *out;
320 !strcasecmp(child->name, assignment->
name));
321 if (workspace == NULL)
327 if (workspace_out == output->
con) {
328 LOG(
"Workspace \"%s\" assigned to output \"%s\", but it is already "
329 "there. Do you have two assignment directives for the same "
330 "workspace in your configuration file?\n",
336 LOG(
"Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
343 Con *previous = NULL;
345 LOG(
"Switching to previously used workspace \"%s\" on output \"%s\"\n",
346 previous->
name, workspace_out->
name);
358 TAILQ_FOREACH(floating_con, &(workspace->floating_head), floating_windows)
369 if (visible && previous == NULL) {
370 LOG(
"There is no workspace left on \"%s\", re-initializing\n",
371 workspace_out->
name);
374 DLOG(
"Done re-initializing, continuing with \"%s\"\n", output->
name);
394 if (strcmp(assignment->
output, output->
name) != 0)
397 LOG(
"Initializing first assigned workspace \"%s\" for output \"%s\"\n",
405 DLOG(
"Now adding a workspace\n");
424 DLOG(
"Output mode changed, updating rect\n");
425 assert(output->
con != NULL);
428 Con *content, *workspace, *child;
436 TAILQ_FOREACH(child, &(workspace->floating_head), floating_windows) {
452 DLOG(
"Setting workspace [%d,%s]'s layout to %d.\n", workspace->
num, workspace->
name, workspace->
layout);
453 if ((child =
TAILQ_FIRST(&(workspace->nodes_head)))) {
454 if (child->
layout == L_SPLITV || child->
layout == L_SPLITH)
456 DLOG(
"Setting child [%d,%s]'s layout to %d.\n", child->
num, child->
name, child->
layout);
471 xcb_randr_get_output_info_reply_t *
output,
477 bool existing = (
new != NULL);
484 xcb_randr_get_output_info_name_length(output),
485 xcb_randr_get_output_info_name(output));
487 DLOG(
"found output with name %s\n", new->name);
492 if (output->crtc == XCB_NONE) {
497 }
else if (new->active)
498 new->to_be_disabled =
true;
502 xcb_randr_get_crtc_info_cookie_t icookie;
503 icookie = xcb_randr_get_crtc_info(conn, output->crtc, cts);
504 if ((crtc = xcb_randr_get_crtc_info_reply(conn, icookie, NULL)) == NULL) {
505 DLOG(
"Skipping output %s: could not get CRTC (%p)\n",
516 new->active = (
new->rect.width != 0 &&
new->rect.height != 0);
518 DLOG(
"width/height 0/0, disabling output\n");
522 DLOG(
"mode: %dx%d+%d+%d\n", new->rect.width, new->rect.height,
523 new->rect.x, new->rect.y);
528 if (!updated || !existing) {
546 xcb_randr_get_output_primary_cookie_t pcookie;
547 xcb_randr_get_screen_resources_current_cookie_t rcookie;
555 xcb_randr_output_t *randr_outputs;
561 rcookie = xcb_randr_get_screen_resources_current(
conn,
root);
562 pcookie = xcb_randr_get_output_primary(
conn,
root);
564 if ((
primary = xcb_randr_get_output_primary_reply(
conn, pcookie, NULL)) == NULL)
565 ELOG(
"Could not get RandR primary output\n");
566 else DLOG(
"primary output is %08x\n",
primary->output);
567 if ((res = xcb_randr_get_screen_resources_current_reply(
conn, rcookie, NULL)) == NULL) {
571 cts = res->config_timestamp;
573 int len = xcb_randr_get_screen_resources_current_outputs_length(res);
574 randr_outputs = xcb_randr_get_screen_resources_current_outputs(res);
577 xcb_randr_get_output_info_cookie_t ocookie[len];
578 for (
int i = 0; i < len; i++)
579 ocookie[i] = xcb_randr_get_output_info(
conn, randr_outputs[i], cts);
582 for (
int i = 0; i < len; i++) {
583 xcb_randr_get_output_info_reply_t *
output;
585 if ((output = xcb_randr_get_output_info_reply(
conn, ocookie[i], NULL)) == NULL)
597 DLOG(
"output %p / %s, position (%d, %d), checking for clones\n",
610 DLOG(
"output %p has the same position, his mode = %d x %d\n",
622 DLOG(
"disabling output %p (%s)\n", other, other->
name);
625 DLOG(
"new output mode %d x %d, other mode %d x %d\n",
636 if (output->
active && output->
con == NULL) {
637 DLOG(
"Need to initialize a Con for output %s\n", output->
name);
648 DLOG(
"Output %s disabled, re-assigning workspaces/docks\n", output->
name);
657 if (output->
con != NULL) {
662 DLOG(
"This output (%p) was focused! Getting next\n", output->
con);
664 DLOG(
"next = %p\n", next);
673 if (current != next &&
TAILQ_EMPTY(&(current->focus_head))) {
675 DLOG(
"Getting rid of current = %p / %s (empty, unfocused)\n", current, current->
name);
679 DLOG(
"Detaching current = %p / %s\n", current, current->
name);
681 DLOG(
"Re-attaching current = %p / %s\n", current, current->
name);
683 DLOG(
"Fixing the coordinates of floating containers\n");
685 TAILQ_FOREACH(floating_con, &(current->floating_head), floating_windows)
687 DLOG(
"Done, next\n");
689 DLOG(
"re-attached all workspaces\n");
692 DLOG(
"now focusing next = %p\n", next);
700 if (child->
type != CT_DOCKAREA)
702 DLOG(
"Handling dock con %p\n", child);
709 DLOG(
"Moving dock client %p to nc %p\n", dock, nc);
711 DLOG(
"Re-attaching\n");
717 DLOG(
"destroying disappearing con %p\n", output->
con);
719 DLOG(
"Done. Should be fine now\n");
734 ELOG(
"No outputs found via RandR, disabling\n");
748 DLOG(
"Should add ws for output %s\n", output->
name);
757 DLOG(
"Focusing primary output %s\n", output->
name);
774 const xcb_query_extension_reply_t *extreply;
776 extreply = xcb_get_extension_data(
conn, &xcb_randr_id);
777 if (!extreply->present) {
782 if (event_base != NULL)
783 *event_base = extreply->first_event;
786 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE |
787 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE |
788 XCB_RANDR_NOTIFY_MASK_CRTC_CHANGE |
789 XCB_RANDR_NOTIFY_MASK_OUTPUT_PROPERTY);