-void initialize_xinerama(xcb_connection_t *conn) {
- virtual_screens = scalloc(sizeof(struct screens_head));
- TAILQ_INIT(virtual_screens);
-
- if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
- DLOG("Xinerama extension not found, disabling.\n");
- disable_xinerama(conn);
- } else {
- xcb_xinerama_is_active_reply_t *reply;
- reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
-
- if (reply == NULL || !reply->state) {
- DLOG("Xinerama is not active (in your X-Server), disabling.\n");
- disable_xinerama(conn);
- } else
- query_screens(conn, virtual_screens);
-
- FREE(reply);
- }
-
- i3Screen *screen;
- num_screens = 0;
- /* Just go through each workspace and associate as many screens as we can. */
- TAILQ_FOREACH(screen, virtual_screens, screens) {
- screen->num = num_screens;
- num_screens++;
- Workspace *ws = get_first_workspace_for_screen(virtual_screens, screen);
- initialize_screen(conn, screen, ws);
- }
-}
-
-/*
- * 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) {
- DLOG("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,
- *old_screen;
- int screen_count = 0;
- /* Mark each workspace which currently is assigned to a screen, so we
- * can garbage-collect afterwards */
- Workspace *ws;
- TAILQ_FOREACH(ws, workspaces, workspaces)
- ws->reassigned = (ws->screen == NULL);
-
- TAILQ_FOREACH(screen, new_screens, screens) {
- screen->num = screen_count;
- screen->current_workspace = NULL;
-
- TAILQ_FOREACH(old_screen, virtual_screens, screens) {
- if (old_screen->num != screen_count)
- continue;
-
- DLOG("Found a matching screen\n");
- /* Use the same workspace */
- screen->current_workspace = old_screen->current_workspace;
-
- /* Re-use the old bar window */
- screen->bar = old_screen->bar;
- screen->bargc = old_screen->bargc;
- DLOG("old_screen->bar = %p\n", old_screen->bar);
-
- Rect bar_rect = {screen->rect.x,
- screen->rect.y + screen->rect.height - (font->height + 6),
- screen->rect.width,
- font->height + 6};
-
- DLOG("configuring bar to be at %d x %d with %d x %d\n",
- bar_rect.x, bar_rect.y, bar_rect.height, bar_rect.width);
- 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 = old_screen->dock_clients;
- SLIST_INIT(&(old_screen->dock_clients));
-
- /* Update the dimensions */
- Workspace *ws;
- TAILQ_FOREACH(ws, workspaces, workspaces) {
- if (ws->screen != old_screen)
- continue;
-
- DLOG("re-assigning ws %d\n", ws->num);
- memcpy(&(ws->rect), &(screen->rect), sizeof(Rect));
- ws->screen = screen;
- ws->reassigned = true;
- }
-
- break;
- }
- if (screen->current_workspace == NULL) {
- /* Find the first unused workspace, preferring the ones
- * which are assigned to this screen and initialize
- * the screen with it. */
- DLOG("getting first ws for screen %p\n", screen);
- Workspace *ws = get_first_workspace_for_screen(new_screens, screen);
- initialize_screen(conn, screen, ws);
- ws->reassigned = true;
-
- /* As this workspace just got visible (we got a new screen
- * without workspace), we need to map its clients */
- workspace_map_clients(conn, ws);
- }
- screen_count++;
- }
-
- /* check for dock_clients which are out of bounds */
- TAILQ_FOREACH(old_screen, virtual_screens, screens) {
- if (SLIST_EMPTY(&(old_screen->dock_clients)))
- continue;
-
- DLOG("dock_clients out of bounds at screen %p, reassigning\n", old_screen);
- if (SLIST_EMPTY(&(first->dock_clients))) {
- first->dock_clients = old_screen->dock_clients;
- continue;
- }
-
- /* We need to merge the lists */
- Client *dock_client;
-
- while (!SLIST_EMPTY(&(old_screen->dock_clients))) {
- dock_client = SLIST_FIRST(&(old_screen->dock_clients));
- SLIST_INSERT_HEAD(&(first->dock_clients), dock_client, dock_clients);
- SLIST_REMOVE_HEAD(&(old_screen->dock_clients), dock_clients);
- }
- }
-
- /* Check for workspaces which are out of bounds */
- TAILQ_FOREACH(ws, workspaces, workspaces) {
- if (ws->reassigned)
- continue;
-
- DLOG("Closing bar window (%p)\n", ws->screen->bar);
- xcb_destroy_window(conn, ws->screen->bar);
-
- DLOG("Workspace %d's screen out of bounds, assigning to first screen\n", ws->num + 1);
- workspace_assign_to(ws, first);
- }
-
- 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;
-
- /* Check for workspaces which need to be assigned to specific screens
- * which may now be available */
- TAILQ_FOREACH(ws, workspaces, workspaces) {
- if (ws->preferred_screen == NULL)
- continue;
-
- workspace_initialize(ws, ws->screen, true);
- }
-
- DLOG("Current workspace is now: %d\n", first->current_workspace);
-
- render_layout(conn);