4 * i3 - an improved dynamic tiling window manager
6 * (c) 2009 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
16 #include <xcb/xinerama.h>
25 /* This TAILQ of Rects stores the virtual screens, used for handling overlapping screens
26 * (xrandr --same-as) */
27 struct screens_head virtual_screens;
29 i3Screen *get_screen_at(int x, int y) {
31 TAILQ_FOREACH(screen, &virtual_screens, screens)
32 if (screen->rect.x == x && screen->rect.y == y)
38 i3Screen *get_screen_containing(int x, int y) {
40 TAILQ_FOREACH(screen, &virtual_screens, screens)
41 if (x > screen->rect.x && x < (screen->rect.x + screen->rect.width) &&
42 y > screen->rect.y && y < (screen->rect.y + screen->rect.height))
50 * We have just established a connection to the X server and need the initial Xinerama
51 * information to setup workspaces for each screen.
54 void initialize_xinerama(xcb_connection_t *conn) {
55 xcb_xinerama_query_screens_reply_t *reply;
56 xcb_xinerama_screen_info_t *screen_info;
59 if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
60 printf("Xinerama extension not found, disabling.\n");
64 if (!xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL)->state) {
65 printf("Xinerama is not active (in your X-Server), disabling.\n");
69 reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
71 printf("Couldn’t get active Xinerama screens\n");
74 screen_info = xcb_xinerama_query_screens_screen_info(reply);
75 num_screens = xcb_xinerama_query_screens_screen_info_length(reply);
77 TAILQ_INIT(&virtual_screens);
79 /* Just go through each workspace and associate as many screens as we can. */
80 for (screen = 0; screen < num_screens; screen++) {
81 i3Screen *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
83 /* This screen already exists. We use the littlest screen so that the user
84 can always see the complete workspace */
85 s->rect.width = min(s->rect.width, screen_info[screen].width);
86 s->rect.height = min(s->rect.height, screen_info[screen].height);
88 s = calloc(sizeof(Screen), 1);
89 s->rect.x = screen_info[screen].x_org;
90 s->rect.y = screen_info[screen].y_org;
91 s->rect.width = screen_info[screen].width;
92 s->rect.height = screen_info[screen].height;
93 TAILQ_INSERT_TAIL(&virtual_screens, s, screens);
96 printf("found Xinerama screen: %d x %d at %d x %d\n",
97 screen_info[screen].width, screen_info[screen].height,
98 screen_info[screen].x_org, screen_info[screen].y_org);
103 TAILQ_FOREACH(s, &virtual_screens, screens) {
104 s->num = num_screens;
105 s->current_workspace = num_screens;
106 workspaces[num_screens].screen = s;
107 memcpy(&(workspaces[num_screens++].rect), &(s->rect), sizeof(Rect));
108 printf("that is virtual screen at %d x %d with %d x %d\n",
109 s->rect.x, s->rect.y, s->rect.width, s->rect.height);