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;
83 if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
84 printf("Xinerama extension not found, disabling.\n");
85 disable_xinerama(conn);
89 if (!xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL)->state) {
90 printf("Xinerama is not active (in your X-Server), disabling.\n");
91 disable_xinerama(conn);
95 reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
97 printf("Couldn’t get active Xinerama screens\n");
100 screen_info = xcb_xinerama_query_screens_screen_info(reply);
101 num_screens = xcb_xinerama_query_screens_screen_info_length(reply);
103 /* Just go through each workspace and associate as many screens as we can. */
104 for (screen = 0; screen < num_screens; screen++) {
105 i3Screen *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
107 /* This screen already exists. We use the littlest screen so that the user
108 can always see the complete workspace */
109 s->rect.width = min(s->rect.width, screen_info[screen].width);
110 s->rect.height = min(s->rect.height, screen_info[screen].height);
112 s = calloc(sizeof(i3Screen), 1);
113 s->rect.x = screen_info[screen].x_org;
114 s->rect.y = screen_info[screen].y_org;
115 s->rect.width = screen_info[screen].width;
116 s->rect.height = screen_info[screen].height;
117 TAILQ_INSERT_TAIL(&virtual_screens, s, screens);
120 printf("found Xinerama screen: %d x %d at %d x %d\n",
121 screen_info[screen].width, screen_info[screen].height,
122 screen_info[screen].x_org, screen_info[screen].y_org);
127 TAILQ_FOREACH(s, &virtual_screens, screens) {
128 s->num = num_screens;
129 s->current_workspace = num_screens;
130 workspaces[num_screens].screen = s;
131 memcpy(&(workspaces[num_screens++].rect), &(s->rect), sizeof(Rect));
132 printf("that is virtual screen at %d x %d with %d x %d\n",
133 s->rect.x, s->rect.y, s->rect.width, s->rect.height);