2009-02-15 01:58:09 +01:00
|
|
|
|
/*
|
|
|
|
|
* vim:ts=8:expandtab
|
|
|
|
|
*
|
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
|
|
|
|
*
|
2009-02-15 03:07:29 +01:00
|
|
|
|
* © 2009 Michael Stapelberg and contributors
|
2009-02-15 01:58:09 +01:00
|
|
|
|
*
|
|
|
|
|
* See file LICENSE for license information.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2009-03-03 23:51:02 +01:00
|
|
|
|
#include <stdbool.h>
|
2009-03-09 07:39:19 +01:00
|
|
|
|
#include <assert.h>
|
2009-07-21 15:59:11 +02:00
|
|
|
|
#include <time.h>
|
2009-12-08 20:55:17 +01:00
|
|
|
|
#include <unistd.h>
|
2009-02-15 01:58:09 +01:00
|
|
|
|
|
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
|
#include <xcb/xinerama.h>
|
|
|
|
|
|
|
|
|
|
#include "queue.h"
|
|
|
|
|
#include "i3.h"
|
|
|
|
|
#include "data.h"
|
|
|
|
|
#include "table.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "xinerama.h"
|
2009-03-03 23:51:02 +01:00
|
|
|
|
#include "layout.h"
|
2009-03-04 12:09:43 +01:00
|
|
|
|
#include "xcb.h"
|
|
|
|
|
#include "config.h"
|
2009-08-08 19:51:51 +02:00
|
|
|
|
#include "workspace.h"
|
2009-12-19 22:39:00 +01:00
|
|
|
|
#include "log.h"
|
2009-02-15 01:58:09 +01:00
|
|
|
|
|
2009-02-15 02:12:14 +01:00
|
|
|
|
/* This TAILQ of i3Screens stores the virtual screens, used for handling overlapping screens
|
2009-02-15 01:58:09 +01:00
|
|
|
|
* (xrandr --same-as) */
|
2009-03-03 23:51:02 +01:00
|
|
|
|
struct screens_head *virtual_screens;
|
|
|
|
|
|
|
|
|
|
static bool xinerama_enabled = true;
|
2009-02-15 01:58:09 +01:00
|
|
|
|
|
2009-08-08 19:51:51 +02:00
|
|
|
|
/*
|
|
|
|
|
* Returns true if both screen objects describe the same screen (checks their
|
|
|
|
|
* size and position).
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
bool screens_are_equal(i3Screen *screen1, i3Screen *screen2) {
|
|
|
|
|
/* If one of both objects (or both) are NULL, we cannot compare them */
|
|
|
|
|
if (screen1 == NULL || screen2 == NULL)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* If the pointers are equal, take the short-circuit */
|
|
|
|
|
if (screen1 == screen2)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
/* Compare their size - other properties are not relevant to determine
|
|
|
|
|
* if a screen is equal to another one */
|
|
|
|
|
return (memcmp(&(screen1->rect), &(screen2->rect), sizeof(Rect)) == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-15 02:12:14 +01:00
|
|
|
|
/*
|
|
|
|
|
* Looks in virtual_screens for the i3Screen whose start coordinates are x, y
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-03 23:51:02 +01:00
|
|
|
|
i3Screen *get_screen_at(int x, int y, struct screens_head *screenlist) {
|
2009-02-15 01:58:09 +01:00
|
|
|
|
i3Screen *screen;
|
2009-03-03 23:51:02 +01:00
|
|
|
|
TAILQ_FOREACH(screen, screenlist, screens)
|
2009-02-15 01:58:09 +01:00
|
|
|
|
if (screen->rect.x == x && screen->rect.y == y)
|
|
|
|
|
return screen;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-15 02:12:14 +01:00
|
|
|
|
/*
|
|
|
|
|
* Looks in virtual_screens for the i3Screen which contains coordinates x, y
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-02-15 01:58:09 +01:00
|
|
|
|
i3Screen *get_screen_containing(int x, int y) {
|
|
|
|
|
i3Screen *screen;
|
2009-03-03 23:51:02 +01:00
|
|
|
|
TAILQ_FOREACH(screen, virtual_screens, screens) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
|
2009-03-03 23:51:02 +01:00
|
|
|
|
x, y, screen->rect.x, screen->rect.y, screen->rect.width, screen->rect.height);
|
|
|
|
|
if (x >= screen->rect.x && x < (screen->rect.x + screen->rect.width) &&
|
|
|
|
|
y >= screen->rect.y && y < (screen->rect.y + screen->rect.height))
|
2009-02-15 01:58:09 +01:00
|
|
|
|
return screen;
|
2009-03-03 23:51:02 +01:00
|
|
|
|
}
|
2009-02-15 01:58:09 +01:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-09 07:39:19 +01:00
|
|
|
|
/*
|
|
|
|
|
* Gets the screen which is the last one in the given direction, for example the screen
|
|
|
|
|
* on the most bottom when direction == D_DOWN, the screen most right when direction == D_RIGHT
|
|
|
|
|
* and so on.
|
|
|
|
|
*
|
|
|
|
|
* This function always returns a screen.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-08-11 15:02:30 +02:00
|
|
|
|
i3Screen *get_screen_most(direction_t direction, i3Screen *current) {
|
2009-03-09 07:39:19 +01:00
|
|
|
|
i3Screen *screen, *candidate = NULL;
|
|
|
|
|
int position = 0;
|
|
|
|
|
TAILQ_FOREACH(screen, virtual_screens, screens) {
|
|
|
|
|
/* Repeated calls of WIN determine the winner of the comparison */
|
|
|
|
|
#define WIN(variable, condition) \
|
|
|
|
|
if (variable condition) { \
|
|
|
|
|
candidate = screen; \
|
|
|
|
|
position = variable; \
|
|
|
|
|
} \
|
|
|
|
|
break;
|
|
|
|
|
|
2009-08-11 15:02:30 +02:00
|
|
|
|
if (((direction == D_UP) || (direction == D_DOWN)) &&
|
|
|
|
|
(current->rect.x != screen->rect.x))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (((direction == D_LEFT) || (direction == D_RIGHT)) &&
|
|
|
|
|
(current->rect.y != screen->rect.y))
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-03-09 07:39:19 +01:00
|
|
|
|
switch (direction) {
|
|
|
|
|
case D_UP:
|
|
|
|
|
WIN(screen->rect.y, <= position);
|
|
|
|
|
case D_DOWN:
|
|
|
|
|
WIN(screen->rect.y, >= position);
|
|
|
|
|
case D_LEFT:
|
|
|
|
|
WIN(screen->rect.x, <= position);
|
|
|
|
|
case D_RIGHT:
|
|
|
|
|
WIN(screen->rect.x, >= position);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(candidate != NULL);
|
|
|
|
|
|
|
|
|
|
return candidate;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-24 23:50:04 +02:00
|
|
|
|
static void initialize_screen(xcb_connection_t *conn, i3Screen *screen, Workspace *workspace) {
|
|
|
|
|
i3Font *font = load_font(conn, config.font);
|
|
|
|
|
|
|
|
|
|
workspace->screen = screen;
|
2009-09-29 19:45:41 +02:00
|
|
|
|
screen->current_workspace = workspace;
|
2009-06-24 23:50:04 +02:00
|
|
|
|
|
|
|
|
|
/* Create a bar for each screen */
|
|
|
|
|
Rect bar_rect = {screen->rect.x,
|
2009-10-07 20:52:53 +02:00
|
|
|
|
screen->rect.y + screen->rect.height - (font->height + 6),
|
2009-06-24 23:50:04 +02:00
|
|
|
|
screen->rect.x + screen->rect.width,
|
|
|
|
|
font->height + 6};
|
|
|
|
|
uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
|
|
|
|
|
uint32_t values[] = {1, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS};
|
2009-07-25 22:29:28 +02:00
|
|
|
|
screen->bar = create_window(conn, bar_rect, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_CURSOR_LEFT_PTR, true, mask, values);
|
2009-06-24 23:50:04 +02:00
|
|
|
|
screen->bargc = xcb_generate_id(conn);
|
|
|
|
|
xcb_create_gc(conn, screen->bargc, screen->bar, 0, 0);
|
|
|
|
|
|
|
|
|
|
SLIST_INIT(&(screen->dock_clients));
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("that is virtual screen at %d x %d with %d x %d\n",
|
2009-06-24 23:50:04 +02:00
|
|
|
|
screen->rect.x, screen->rect.y, screen->rect.width, screen->rect.height);
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-15 02:12:14 +01:00
|
|
|
|
/*
|
|
|
|
|
* Fills virtual_screens with exactly one screen with width/height of the whole X server.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-04 15:45:12 +01:00
|
|
|
|
static void disable_xinerama(xcb_connection_t *conn) {
|
|
|
|
|
xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
|
2009-02-15 02:12:14 +01:00
|
|
|
|
|
|
|
|
|
i3Screen *s = calloc(sizeof(i3Screen), 1);
|
|
|
|
|
|
|
|
|
|
s->rect.x = 0;
|
|
|
|
|
s->rect.y = 0;
|
|
|
|
|
s->rect.width = root_screen->width_in_pixels;
|
|
|
|
|
s->rect.height = root_screen->height_in_pixels;
|
|
|
|
|
|
2009-06-24 23:50:04 +02:00
|
|
|
|
num_screens = 1;
|
|
|
|
|
s->num = 0;
|
|
|
|
|
|
2009-03-03 23:51:02 +01:00
|
|
|
|
TAILQ_INSERT_TAIL(virtual_screens, s, screens);
|
|
|
|
|
|
|
|
|
|
xinerama_enabled = false;
|
2009-02-15 02:12:14 +01:00
|
|
|
|
}
|
2009-02-15 01:58:09 +01:00
|
|
|
|
|
|
|
|
|
/*
|
2009-03-03 23:51:02 +01:00
|
|
|
|
* Gets the Xinerama screens and converts them to virtual i3Screens (only one screen for two
|
|
|
|
|
* Xinerama screen which are configured in clone mode) in the given screenlist
|
2009-02-15 01:58:09 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-04 15:45:12 +01:00
|
|
|
|
static void query_screens(xcb_connection_t *conn, struct screens_head *screenlist) {
|
2009-02-15 01:58:09 +01:00
|
|
|
|
xcb_xinerama_query_screens_reply_t *reply;
|
|
|
|
|
xcb_xinerama_screen_info_t *screen_info;
|
2009-07-21 15:59:11 +02:00
|
|
|
|
time_t before_trying = time(NULL);
|
|
|
|
|
|
|
|
|
|
/* Try repeatedly to find screens (there might be short timeframes in
|
|
|
|
|
* which the X server does not return any screens, such as when rotating
|
|
|
|
|
* screens), but not longer than 5 seconds (strictly speaking, only four
|
|
|
|
|
* seconds of trying are guaranteed due to the 1-second-resolution) */
|
2009-12-07 16:31:49 +01:00
|
|
|
|
while ((time(NULL) - before_trying) < 10) {
|
2009-07-21 15:59:11 +02:00
|
|
|
|
reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
|
|
|
|
|
if (!reply) {
|
2009-12-21 20:41:02 +01:00
|
|
|
|
ELOG("Couldn't get Xinerama screens\n");
|
2009-07-21 15:59:11 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
screen_info = xcb_xinerama_query_screens_screen_info(reply);
|
|
|
|
|
int screens = xcb_xinerama_query_screens_screen_info_length(reply);
|
|
|
|
|
num_screens = 0;
|
|
|
|
|
|
|
|
|
|
for (int screen = 0; screen < screens; screen++) {
|
|
|
|
|
i3Screen *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org, screenlist);
|
2009-08-08 19:51:51 +02:00
|
|
|
|
if (s != NULL) {
|
2009-12-21 22:30:08 +01:00
|
|
|
|
DLOG("Re-used old Xinerama screen %p\n", s);
|
2009-07-21 15:59:11 +02:00
|
|
|
|
/* This screen already exists. We use the littlest screen so that the user
|
|
|
|
|
can always see the complete workspace */
|
|
|
|
|
s->rect.width = min(s->rect.width, screen_info[screen].width);
|
|
|
|
|
s->rect.height = min(s->rect.height, screen_info[screen].height);
|
|
|
|
|
} else {
|
|
|
|
|
s = calloc(sizeof(i3Screen), 1);
|
2009-12-21 22:30:08 +01:00
|
|
|
|
DLOG("Created new Xinerama screen %p\n", s);
|
2009-07-21 15:59:11 +02:00
|
|
|
|
s->rect.x = screen_info[screen].x_org;
|
|
|
|
|
s->rect.y = screen_info[screen].y_org;
|
|
|
|
|
s->rect.width = screen_info[screen].width;
|
|
|
|
|
s->rect.height = screen_info[screen].height;
|
|
|
|
|
/* We always treat the screen at 0x0 as the primary screen */
|
|
|
|
|
if (s->rect.x == 0 && s->rect.y == 0)
|
|
|
|
|
TAILQ_INSERT_HEAD(screenlist, s, screens);
|
|
|
|
|
else TAILQ_INSERT_TAIL(screenlist, s, screens);
|
|
|
|
|
num_screens++;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("found Xinerama screen: %d x %d at %d x %d\n",
|
2009-07-21 15:59:11 +02:00
|
|
|
|
screen_info[screen].width, screen_info[screen].height,
|
|
|
|
|
screen_info[screen].x_org, screen_info[screen].y_org);
|
2009-02-15 01:58:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-21 15:59:11 +02:00
|
|
|
|
free(reply);
|
2009-02-15 01:58:09 +01:00
|
|
|
|
|
2009-07-21 15:59:11 +02:00
|
|
|
|
if (num_screens == 0) {
|
2009-12-21 20:41:02 +01:00
|
|
|
|
ELOG("No screens found. This is weird. Trying again...\n");
|
2009-12-07 16:31:49 +01:00
|
|
|
|
/* Give the scheduler a chance to do something else
|
|
|
|
|
* and don’t hog the CPU */
|
|
|
|
|
usleep(250);
|
2009-07-21 15:59:11 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-05-03 22:59:50 +02:00
|
|
|
|
|
2009-07-21 15:59:11 +02:00
|
|
|
|
break;
|
2009-05-03 22:59:50 +02:00
|
|
|
|
}
|
2009-12-07 16:31:49 +01:00
|
|
|
|
|
|
|
|
|
if (num_screens == 0) {
|
2009-12-21 20:41:02 +01:00
|
|
|
|
ELOG("No screens found for 10 seconds. Please fix your setup. i3 will exit now.\n");
|
2009-12-07 16:31:49 +01:00
|
|
|
|
exit(0);
|
|
|
|
|
}
|
2009-03-03 23:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We have just established a connection to the X server and need the initial Xinerama
|
|
|
|
|
* information to setup workspaces for each screen.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-04 15:45:12 +01:00
|
|
|
|
void initialize_xinerama(xcb_connection_t *conn) {
|
2009-03-03 23:51:02 +01:00
|
|
|
|
virtual_screens = scalloc(sizeof(struct screens_head));
|
|
|
|
|
TAILQ_INIT(virtual_screens);
|
|
|
|
|
|
2009-03-04 15:45:12 +01:00
|
|
|
|
if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Xinerama extension not found, disabling.\n");
|
2009-03-04 15:45:12 +01:00
|
|
|
|
disable_xinerama(conn);
|
2009-09-05 19:17:59 +02:00
|
|
|
|
} else {
|
|
|
|
|
xcb_xinerama_is_active_reply_t *reply;
|
|
|
|
|
reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
|
2009-03-05 01:48:30 +01:00
|
|
|
|
|
2009-09-05 19:17:59 +02:00
|
|
|
|
if (reply == NULL || !reply->state) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Xinerama is not active (in your X-Server), disabling.\n");
|
2009-09-05 19:17:59 +02:00
|
|
|
|
disable_xinerama(conn);
|
|
|
|
|
} else
|
|
|
|
|
query_screens(conn, virtual_screens);
|
2009-03-03 23:51:02 +01:00
|
|
|
|
|
2009-09-05 19:17:59 +02:00
|
|
|
|
FREE(reply);
|
|
|
|
|
}
|
2009-03-05 01:48:30 +01:00
|
|
|
|
|
2009-08-08 19:51:51 +02:00
|
|
|
|
i3Screen *screen;
|
2009-02-15 01:58:09 +01:00
|
|
|
|
num_screens = 0;
|
2009-03-03 23:51:02 +01:00
|
|
|
|
/* Just go through each workspace and associate as many screens as we can. */
|
2009-08-08 19:51:51 +02:00
|
|
|
|
TAILQ_FOREACH(screen, virtual_screens, screens) {
|
|
|
|
|
screen->num = num_screens;
|
2009-03-04 12:09:43 +01:00
|
|
|
|
num_screens++;
|
2009-08-08 19:51:51 +02:00
|
|
|
|
Workspace *ws = get_first_workspace_for_screen(virtual_screens, screen);
|
|
|
|
|
initialize_screen(conn, screen, ws);
|
2009-02-15 01:58:09 +01:00
|
|
|
|
}
|
2009-03-03 23:51:02 +01:00
|
|
|
|
}
|
2009-02-15 01:58:09 +01:00
|
|
|
|
|
2009-03-03 23:51:02 +01:00
|
|
|
|
/*
|
|
|
|
|
* This is called when the rootwindow receives a configure_notify event and therefore the
|
|
|
|
|
* number/position of the Xinerama screens could have changed.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-04 15:45:12 +01:00
|
|
|
|
void xinerama_requery_screens(xcb_connection_t *conn) {
|
2009-05-03 22:59:50 +02:00
|
|
|
|
i3Font *font = load_font(conn, config.font);
|
|
|
|
|
|
2009-03-03 23:51:02 +01:00
|
|
|
|
/* 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) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Xinerama is disabled\n");
|
2009-03-03 23:51:02 +01:00
|
|
|
|
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);
|
|
|
|
|
|
2009-03-04 15:45:12 +01:00
|
|
|
|
query_screens(conn, new_screens);
|
2009-03-03 23:51:02 +01:00
|
|
|
|
|
|
|
|
|
i3Screen *first = TAILQ_FIRST(new_screens),
|
2009-08-08 19:51:51 +02:00
|
|
|
|
*screen,
|
|
|
|
|
*old_screen;
|
2009-03-03 23:51:02 +01:00
|
|
|
|
int screen_count = 0;
|
2009-08-08 19:51:51 +02:00
|
|
|
|
/* Mark each workspace which currently is assigned to a screen, so we
|
|
|
|
|
* can garbage-collect afterwards */
|
2009-09-29 19:45:41 +02:00
|
|
|
|
Workspace *ws;
|
|
|
|
|
TAILQ_FOREACH(ws, workspaces, workspaces)
|
|
|
|
|
ws->reassigned = (ws->screen == NULL);
|
2009-08-08 19:51:51 +02:00
|
|
|
|
|
2009-03-03 23:51:02 +01:00
|
|
|
|
TAILQ_FOREACH(screen, new_screens, screens) {
|
|
|
|
|
screen->num = screen_count;
|
2009-09-29 19:45:41 +02:00
|
|
|
|
screen->current_workspace = NULL;
|
2009-08-08 19:51:51 +02:00
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(old_screen, virtual_screens, screens) {
|
|
|
|
|
if (old_screen->num != screen_count)
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Found a matching screen\n");
|
2009-08-08 19:51:51 +02:00
|
|
|
|
/* 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;
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("old_screen->bar = %p\n", old_screen->bar);
|
2009-08-08 19:51:51 +02:00
|
|
|
|
|
|
|
|
|
Rect bar_rect = {screen->rect.x,
|
2009-10-11 14:30:57 +02:00
|
|
|
|
screen->rect.y + screen->rect.height - (font->height + 6),
|
2009-12-21 22:30:08 +01:00
|
|
|
|
screen->rect.width,
|
2009-08-08 19:51:51 +02:00
|
|
|
|
font->height + 6};
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("configuring bar to be at %d x %d with %d x %d\n",
|
2009-08-08 19:51:51 +02:00
|
|
|
|
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;
|
2009-10-28 15:37:34 +01:00
|
|
|
|
SLIST_INIT(&(old_screen->dock_clients));
|
2009-08-08 19:51:51 +02:00
|
|
|
|
|
|
|
|
|
/* Update the dimensions */
|
2009-09-29 19:45:41 +02:00
|
|
|
|
Workspace *ws;
|
|
|
|
|
TAILQ_FOREACH(ws, workspaces, workspaces) {
|
2009-08-08 19:51:51 +02:00
|
|
|
|
if (ws->screen != old_screen)
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("re-assigning ws %d\n", ws->num);
|
2009-08-08 19:51:51 +02:00
|
|
|
|
memcpy(&(ws->rect), &(screen->rect), sizeof(Rect));
|
|
|
|
|
ws->screen = screen;
|
|
|
|
|
ws->reassigned = true;
|
2009-03-03 23:51:02 +01:00
|
|
|
|
}
|
2009-08-08 19:51:51 +02:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-09-29 19:45:41 +02:00
|
|
|
|
if (screen->current_workspace == NULL) {
|
2009-08-08 19:51:51 +02:00
|
|
|
|
/* Find the first unused workspace, preferring the ones
|
|
|
|
|
* which are assigned to this screen and initialize
|
|
|
|
|
* the screen with it. */
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("getting first ws for screen %p\n", screen);
|
2009-08-08 19:51:51 +02:00
|
|
|
|
Workspace *ws = get_first_workspace_for_screen(new_screens, screen);
|
|
|
|
|
initialize_screen(conn, screen, ws);
|
2009-09-28 18:02:11 +02:00
|
|
|
|
ws->reassigned = true;
|
2009-08-08 19:51:51 +02:00
|
|
|
|
|
|
|
|
|
/* As this workspace just got visible (we got a new screen
|
|
|
|
|
* without workspace), we need to map its clients */
|
|
|
|
|
workspace_map_clients(conn, ws);
|
2009-03-03 23:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
screen_count++;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-28 15:37:34 +01:00
|
|
|
|
/* check for dock_clients which are out of bounds */
|
|
|
|
|
TAILQ_FOREACH(old_screen, virtual_screens, screens) {
|
|
|
|
|
if (SLIST_EMPTY(&(old_screen->dock_clients)))
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("dock_clients out of bounds at screen %p, reassigning\n", old_screen);
|
2009-10-28 15:37:34 +01:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-03 23:51:02 +01:00
|
|
|
|
/* Check for workspaces which are out of bounds */
|
2009-09-29 19:45:41 +02:00
|
|
|
|
TAILQ_FOREACH(ws, workspaces, workspaces) {
|
|
|
|
|
if (ws->reassigned)
|
2009-05-09 13:01:23 +02:00
|
|
|
|
continue;
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Closing bar window (%p)\n", ws->screen->bar);
|
2009-09-29 19:45:41 +02:00
|
|
|
|
xcb_destroy_window(conn, ws->screen->bar);
|
2009-05-09 13:01:23 +02:00
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Workspace %d's screen out of bounds, assigning to first screen\n", ws->num + 1);
|
2009-12-21 22:30:08 +01:00
|
|
|
|
workspace_assign_to(ws, first);
|
2009-05-09 13:01:23 +02:00
|
|
|
|
}
|
2009-12-21 22:30:08 +01:00
|
|
|
|
|
2009-05-09 13:01:23 +02:00
|
|
|
|
xcb_flush(conn);
|
2009-03-03 23:51:02 +01:00
|
|
|
|
|
|
|
|
|
/* Free the old list */
|
2009-03-05 01:48:30 +01:00
|
|
|
|
while (!TAILQ_EMPTY(virtual_screens)) {
|
|
|
|
|
screen = TAILQ_FIRST(virtual_screens);
|
2009-03-03 23:51:02 +01:00
|
|
|
|
TAILQ_REMOVE(virtual_screens, screen, screens);
|
|
|
|
|
free(screen);
|
|
|
|
|
}
|
|
|
|
|
free(virtual_screens);
|
|
|
|
|
|
|
|
|
|
virtual_screens = new_screens;
|
|
|
|
|
|
2009-12-21 22:30:08 +01:00
|
|
|
|
/* Check for workspaces which need to be assigned to specific screens
|
|
|
|
|
* which may now be available */
|
|
|
|
|
TAILQ_FOREACH(ws, workspaces, workspaces) {
|
2009-12-23 00:39:03 +01:00
|
|
|
|
if (ws->preferred_screen == NULL || ws->screen == NULL)
|
2009-12-21 22:30:08 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
workspace_initialize(ws, ws->screen, true);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Current workspace is now: %d\n", first->current_workspace);
|
2009-03-03 23:51:02 +01:00
|
|
|
|
|
2009-03-04 15:45:12 +01:00
|
|
|
|
render_layout(conn);
|
2009-02-15 01:58:09 +01:00
|
|
|
|
}
|