-
- i3Screen *s;
- num_screens = 0;
- /* Just go through each workspace and associate as many screens as we can. */
- TAILQ_FOREACH(s, virtual_screens, screens) {
- s->num = num_screens;
- initialize_screen(conn, s, &(workspaces[num_screens]));
- num_screens++;
- }
-}
-
-/*
- * This is called when the rootwindow receives a configure_notify event and therefore the
- * number/position of the Xinerama screens could have changed.
- *
- */
-void xinerama_requery_screens(xcb_connection_t *conn) {
- /* POSSIBLE PROBLEM: Is the order of the Xinerama screens always constant? That is, can
- it change when I move the --right-of video projector to --left-of? */
-
- if (!xinerama_enabled) {
- LOG("Xinerama is disabled\n");
- return;
- }
-
- /* We use a separate copy to diff with the previous set of screens */
- struct screens_head *new_screens = scalloc(sizeof(struct screens_head));
- TAILQ_INIT(new_screens);
-
- query_screens(conn, new_screens);
-
- i3Screen *first = TAILQ_FIRST(new_screens),
- *screen;
- int screen_count = 0;
- TAILQ_FOREACH(screen, new_screens, screens) {
- screen->num = screen_count;
- screen->current_workspace = -1;
- for (int c = 0; c < 10; c++)
- if ((workspaces[c].screen != NULL) &&
- (workspaces[c].screen->num == screen_count)) {
- LOG("Found a matching screen\n");
- /* Try to use the same workspace, if it’s available */
- if (workspaces[c].screen->current_workspace)
- screen->current_workspace = workspaces[c].screen->current_workspace;
-
- if (screen->current_workspace == -1)
- screen->current_workspace = c;
-
- /* Re-use the old bar window */
- screen->bar = workspaces[c].screen->bar;
- screen->bargc = workspaces[c].screen->bargc;
-
- /* Copy the list head for the dock clients */
- screen->dock_clients = workspaces[c].screen->dock_clients;
-
- /* Update the dimensions */
- memcpy(&(workspaces[c].rect), &(screen->rect), sizeof(Rect));
- workspaces[c].screen = screen;
- }
- if (screen->current_workspace == -1) {
- /* Create a new workspace for this screen, it’s new */
- for (int c = 0; c < 10; c++)
- if (workspaces[c].screen == NULL) {
- LOG("fix: initializing new workspace, setting num to %d\n", c);
- initialize_screen(conn, screen, &(workspaces[c]));
- break;
- }
- }
- screen_count++;
- }
-
- /* Check for workspaces which are out of bounds */
- for (int c = 0; c < 10; c++)
- if ((workspaces[c].screen != NULL) &&
- (workspaces[c].screen->num >= num_screens)) {
- LOG("Closing bar window\n");
- xcb_destroy_window(conn, workspaces[c].screen->bar);
-
- LOG("Workspace %d's screen out of bounds, assigning to first screen\n", c+1);
- workspaces[c].screen = first;
- memcpy(&(workspaces[c].rect), &(first->rect), sizeof(Rect));
- }
-
- /* Free the old list */
- while (!TAILQ_EMPTY(virtual_screens)) {
- screen = TAILQ_FIRST(virtual_screens);
- TAILQ_REMOVE(virtual_screens, screen, screens);
- free(screen);
- }
- free(virtual_screens);
-
- virtual_screens = new_screens;
-
- LOG("Current workspace is now: %d\n", first->current_workspace);
-
- render_layout(conn);