15 #include <xcb/randr.h>
23 xcb_randr_get_output_primary_reply_t *
primary;
53 strcasecmp(output->
name, name) == 0)
83 DLOG(
"comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
102 Output *output, *candidate = NULL;
109 #define WIN(variable, condition) \
110 if (variable condition) { \
111 candidate = output; \
112 position = variable; \
116 if (((direction ==
D_UP) || (direction ==
D_DOWN)) &&
136 assert(candidate != NULL);
146 Output *output, *candidate = NULL;
152 if (((direction ==
D_UP) || (direction ==
D_DOWN)) &&
163 (!candidate || output->
rect.
y < candidate->
rect.
y))
168 (!candidate || output->
rect.
y > candidate->
rect.
y))
173 (!candidate || output->
rect.
x > candidate->
rect.
x))
178 (!candidate || output->
rect.
x < candidate->
rect.
x))
193 DLOG(
"RandR extension unusable, disabling.\n");
217 Con *con = NULL, *current;
220 DLOG(
"init_con for output %s\n", output->
name);
225 if (strcmp(current->name, output->
name) != 0)
230 DLOG(
"Using existing con %p / %s\n", con, con->
name);
238 con->
type = CT_OUTPUT;
251 DLOG(
"Not adding workspace, this was a reused con\n");
255 DLOG(
"Changing layout, adding top/bottom dockarea\n");
257 topdock->
type = CT_DOCKAREA;
258 topdock->
layout = L_DOCKAREA;
263 match->
dock = M_DOCK_TOP;
278 DLOG(
"adding main content container\n");
280 content->
type = CT_CON;
291 bottomdock->
type = CT_DOCKAREA;
292 bottomdock->
layout = L_DOCKAREA;
297 match->
dock = M_DOCK_BOTTOM;
325 if (strcmp(assignment->
output, output->
name) != 0)
329 Con *workspace = NULL, *out;
332 !strcasecmp(child->name, assignment->
name));
333 if (workspace == NULL)
339 if (workspace_out == output->
con) {
340 LOG(
"Workspace \"%s\" assigned to output \"%s\", but it is already "
341 "there. Do you have two assignment directives for the same "
342 "workspace in your configuration file?\n",
348 LOG(
"Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
355 Con *previous = NULL;
357 LOG(
"Switching to previously used workspace \"%s\" on output \"%s\"\n",
358 previous->
name, workspace_out->
name);
368 if (visible && previous == NULL) {
369 LOG(
"There is no workspace left on \"%s\", re-initializing\n",
370 workspace_out->
name);
373 DLOG(
"Done re-initializing, continuing with \"%s\"\n", output->
name);
393 if (strcmp(assignment->
output, output->
name) != 0)
396 LOG(
"Initializing first assigned workspace \"%s\" for output \"%s\"\n",
404 DLOG(
"Now adding a workspace\n");
423 DLOG(
"Output mode changed, updating rect\n");
424 assert(output->
con != NULL);
427 Con *content, *workspace, *child;
435 TAILQ_FOREACH(child, &(workspace->floating_head), floating_windows) {
451 DLOG(
"Setting workspace [%d,%s]'s orientation to %d.\n", workspace->
num, workspace->
name, workspace->
orientation);
452 if ((child =
TAILQ_FIRST(&(workspace->nodes_head)))) {
469 xcb_randr_get_output_info_reply_t *
output,
475 bool existing = (
new != NULL);
482 xcb_randr_get_output_info_name_length(output),
483 xcb_randr_get_output_info_name(output));
485 DLOG(
"found output with name %s\n", new->name);
490 if (output->crtc == XCB_NONE) {
495 }
else if (new->active)
496 new->to_be_disabled =
true;
500 xcb_randr_get_crtc_info_cookie_t icookie;
501 icookie = xcb_randr_get_crtc_info(conn, output->crtc, cts);
502 if ((crtc = xcb_randr_get_crtc_info_reply(conn, icookie, NULL)) == NULL) {
503 DLOG(
"Skipping output %s: could not get CRTC (%p)\n",
514 new->active = (
new->rect.width != 0 &&
new->rect.height != 0);
516 DLOG(
"width/height 0/0, disabling output\n");
520 DLOG(
"mode: %dx%d+%d+%d\n", new->rect.width, new->rect.height,
521 new->rect.x, new->rect.y);
526 if (!updated || !existing) {
544 xcb_randr_get_output_primary_cookie_t pcookie;
545 xcb_randr_get_screen_resources_current_cookie_t rcookie;
553 xcb_randr_output_t *randr_outputs;
559 rcookie = xcb_randr_get_screen_resources_current(
conn,
root);
560 pcookie = xcb_randr_get_output_primary(
conn,
root);
562 if ((
primary = xcb_randr_get_output_primary_reply(
conn, pcookie, NULL)) == NULL)
563 ELOG(
"Could not get RandR primary output\n");
564 else DLOG(
"primary output is %08x\n",
primary->output);
565 if ((res = xcb_randr_get_screen_resources_current_reply(
conn, rcookie, NULL)) == NULL) {
569 cts = res->config_timestamp;
571 int len = xcb_randr_get_screen_resources_current_outputs_length(res);
572 randr_outputs = xcb_randr_get_screen_resources_current_outputs(res);
575 xcb_randr_get_output_info_cookie_t ocookie[len];
576 for (
int i = 0; i < len; i++)
577 ocookie[i] = xcb_randr_get_output_info(
conn, randr_outputs[i], cts);
580 for (
int i = 0; i < len; i++) {
581 xcb_randr_get_output_info_reply_t *
output;
583 if ((output = xcb_randr_get_output_info_reply(
conn, ocookie[i], NULL)) == NULL)
595 DLOG(
"output %p / %s, position (%d, %d), checking for clones\n",
608 DLOG(
"output %p has the same position, his mode = %d x %d\n",
620 DLOG(
"disabling output %p (%s)\n", other, other->
name);
623 DLOG(
"new output mode %d x %d, other mode %d x %d\n",
634 if (output->
active && output->
con == NULL) {
635 DLOG(
"Need to initialize a Con for output %s\n", output->
name);
646 DLOG(
"Output %s disabled, re-assigning workspaces/docks\n", output->
name);
649 die(
"No usable outputs available\n");
656 if (output->
con != NULL) {
661 DLOG(
"This output (%p) was focused! Getting next\n", output->
con);
663 DLOG(
"next = %p\n", next);
672 if (current != next &&
TAILQ_EMPTY(&(current->focus_head))) {
674 DLOG(
"Getting rid of current = %p / %s (empty, unfocused)\n", current, current->
name);
678 DLOG(
"Detaching current = %p / %s\n", current, current->
name);
680 DLOG(
"Re-attaching current = %p / %s\n", current, current->
name);
682 DLOG(
"Fixing the coordinates of floating containers\n");
684 TAILQ_FOREACH(floating_con, &(current->floating_head), floating_windows)
686 DLOG(
"Done, next\n");
688 DLOG(
"re-attached all workspaces\n");
691 DLOG(
"now focusing next = %p\n", next);
699 if (child->
type != CT_DOCKAREA)
701 DLOG(
"Handling dock con %p\n", child);
708 DLOG(
"Moving dock client %p to nc %p\n", dock, nc);
710 DLOG(
"Re-attaching\n");
716 DLOG(
"destroying disappearing con %p\n", output->
con);
718 DLOG(
"Done. Should be fine now\n");
733 ELOG(
"No outputs found via RandR, disabling\n");
744 DLOG(
"Should add ws for output %s\n", output->
name);
753 DLOG(
"Focusing primary output %s\n", output->
name);
770 const xcb_query_extension_reply_t *extreply;
772 extreply = xcb_get_extension_data(
conn, &xcb_randr_id);
773 if (!extreply->present) {
778 if (event_base != NULL)
779 *event_base = extreply->first_event;
782 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE |
783 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE |
784 XCB_RANDR_NOTIFY_MASK_CRTC_CHANGE |
785 XCB_RANDR_NOTIFY_MASK_OUTPUT_PROPERTY);