-void initialize_xinerama(xcb_connection_t *connection) {
- virtual_screens = scalloc(sizeof(struct screens_head));
- TAILQ_INIT(virtual_screens);
-
- if (!xcb_get_extension_data(connection, &xcb_xinerama_id)->present) {
- printf("Xinerama extension not found, disabling.\n");
- disable_xinerama(connection);
- return;
- }
-
- if (!xcb_xinerama_is_active_reply(connection, xcb_xinerama_is_active(connection), NULL)->state) {
- printf("Xinerama is not active (in your X-Server), disabling.\n");
- disable_xinerama(connection);
- return;
- }
-
- query_screens(connection, virtual_screens);
-
- 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;
- s->current_workspace = num_screens;
- workspaces[num_screens].screen = s;
- memcpy(&(workspaces[num_screens++].rect), &(s->rect), sizeof(Rect));
- printf("that is virtual screen at %d x %d with %d x %d\n",
- s->rect.x, s->rect.y, s->rect.width, s->rect.height);
- }
-}
-
-/*
- * 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 *connection) {
- /* 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) {
- printf("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(connection, 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)) {
- printf("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;
-
- /* 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) {
- printf("fix: initializing new workspace, setting num to %d\n", c);
- workspaces[c].screen = screen;
- screen->current_workspace = c;
- /* Copy the dimensions from the virtual screen */
- memcpy(&(workspaces[c].rect), &(screen->rect), sizeof(Rect));
- 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)) {
- printf("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 */
- TAILQ_FOREACH(screen, virtual_screens, screens) {
- TAILQ_REMOVE(virtual_screens, screen, screens);
- free(screen);
- }
- free(virtual_screens);
-
- virtual_screens = new_screens;
-
- printf("Current workspace is now: %d\n", first->current_workspace);
-
- render_layout(connection);