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 i3Screens stores the virtual screens, used for handling overlapping screens
26 * (xrandr --same-as) */
27 struct screens_head virtual_screens = TAILQ_HEAD_INITIALIZER(virtual_screens);
30 * Looks in virtual_screens for the i3Screen whose start coordinates are x, y
33 i3Screen *get_screen_at(int x, int y) {
35 TAILQ_FOREACH(screen, &virtual_screens, screens)
36 if (screen->rect.x == x && screen->rect.y == y)
43 * Looks in virtual_screens for the i3Screen which contains coordinates x, y
46 i3Screen *get_screen_containing(int x, int y) {
48 TAILQ_FOREACH(screen, &virtual_screens, screens)
49 if (x > screen->rect.x && x < (screen->rect.x + screen->rect.width) &&
50 y > screen->rect.y && y < (screen->rect.y + screen->rect.height))
57 * Fills virtual_screens with exactly one screen with width/height of the whole X server.
60 static void disable_xinerama(xcb_connection_t *connection) {
61 xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;
63 i3Screen *s = calloc(sizeof(i3Screen), 1);
67 s->rect.width = root_screen->width_in_pixels;
68 s->rect.height = root_screen->height_in_pixels;
70 TAILQ_INSERT_TAIL(&virtual_screens, s, screens);
74 * We have just established a connection to the X server and need the initial Xinerama
75 * information to setup workspaces for each screen.
78 void initialize_xinerama(xcb_connection_t *conn) {
79 xcb_xinerama_query_screens_reply_t *reply;
80 xcb_xinerama_screen_info_t *screen_info;
82 if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
83 printf("Xinerama extension not found, disabling.\n");
84 disable_xinerama(conn);
88 if (!xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL)->state) {
89 printf("Xinerama is not active (in your X-Server), disabling.\n");
90 disable_xinerama(conn);
94 reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
96 printf("Couldn’t get active Xinerama screens\n");
99 screen_info = xcb_xinerama_query_screens_screen_info(reply);
100 num_screens = xcb_xinerama_query_screens_screen_info_length(reply);
102 /* Just go through each workspace and associate as many screens as we can. */
103 for (int screen = 0; screen < num_screens; screen++) {
104 i3Screen *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
106 /* This screen already exists. We use the littlest screen so that the user
107 can always see the complete workspace */
108 s->rect.width = min(s->rect.width, screen_info[screen].width);
109 s->rect.height = min(s->rect.height, screen_info[screen].height);
111 s = calloc(sizeof(i3Screen), 1);
112 s->rect.x = screen_info[screen].x_org;
113 s->rect.y = screen_info[screen].y_org;
114 s->rect.width = screen_info[screen].width;
115 s->rect.height = screen_info[screen].height;
116 TAILQ_INSERT_TAIL(&virtual_screens, s, screens);
119 printf("found Xinerama screen: %d x %d at %d x %d\n",
120 screen_info[screen].width, screen_info[screen].height,
121 screen_info[screen].x_org, screen_info[screen].y_org);
126 TAILQ_FOREACH(s, &virtual_screens, screens) {
127 s->num = num_screens;
128 s->current_workspace = num_screens;
129 workspaces[num_screens].screen = s;
130 memcpy(&(workspaces[num_screens++].rect), &(s->rect), sizeof(Rect));
131 printf("that is virtual screen at %d x %d with %d x %d\n",
132 s->rect.x, s->rect.y, s->rect.width, s->rect.height);