-
- 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) {
- i3Font *font = load_font(conn, config.font);
-
- /* 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;
-
- Rect bar_rect = {screen->rect.x,
- screen->rect.height - (font->height + 6),
- screen->rect.x + screen->rect.width,
- font->height + 6};
-
- xcb_configure_window(conn, screen->bar, XCB_CONFIG_WINDOW_X |
- XCB_CONFIG_WINDOW_Y |
- XCB_CONFIG_WINDOW_WIDTH |
- XCB_CONFIG_WINDOW_HEIGHT, &(bar_rect.x));
-
- /* 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))
- continue;
-
- /* f_ws is a shortcut to the workspace to fix */
- Workspace *f_ws = &(workspaces[c]);
- Client *client;
-
- LOG("Closing bar window\n");
- xcb_destroy_window(conn, f_ws->screen->bar);
-
- LOG("Workspace %d's screen out of bounds, assigning to first screen\n", c+1);
- f_ws->screen = first;
- memcpy(&(f_ws->rect), &(first->rect), sizeof(Rect));
-
- /* Force reconfiguration for each client on that workspace */
- FOR_TABLE(f_ws)
- CIRCLEQ_FOREACH(client, &(f_ws->table[cols][rows]->clients), clients)
- client->force_reconfigure = true;
-
- /* Render the workspace to reconfigure the clients. However, they will be visible now, so… */
- render_workspace(conn, first, f_ws);
-
- /* …unless we want to see them at the moment, we should hide that workspace */
- if (first->current_workspace == c)
- continue;
-
- unmap_workspace(conn, f_ws);
- }
- xcb_flush(conn);
-
- /* 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);