Client_DrawFrame(Client *c, int active) {
int quarter = (border + titleHeight()) / 4;
- if (c->parent == c->screen->root || c->parent == 0 || c->framed == False)
+ if (c->parent == root || c->parent == 0 || c->framed == False)
return;
- XSetWindowBackground(dpy, c->parent,
- active ? c->screen->black : c->screen->gray);
+ XSetWindowBackground(dpy, c->parent, active ? black : gray);
XClearWindow(dpy, c->parent);
/* Draw window title. */
if (c->name != 0) {
Xutf8DrawString(dpy, c->parent, font_set,
- c->screen->gc, border + 2 + (3 * quarter),
+ gc, border + 2 + (3 * quarter),
2 + ascent(font_set_ext),
c->name, c->namelen);
}
for (c = clients; c; c = c->next) {
if (c->framed != True) continue;
- attr.cursor = c->screen->root_cursor;
- XChangeWindowAttributes(dpy, c->parent,
- CWCursor, &attr);
+ attr.cursor = root_cursor;
+ XChangeWindowAttributes(dpy, c->parent, CWCursor, &attr);
c->cursor = ENone;
}
}
int font_char;
};
-static CursorMapping cursor_map[] = {
+static CursorMapping cursor_mappings[] = {
{ETopLeft, XC_top_left_corner},
{ETop, XC_top_side},
{ETopRight, XC_top_right_corner},
XAllocNamedColor(dpy, cmp, "red", &red, &exact);
XAllocNamedColor(dpy, cmp, "white", &white, &exact);
- screens[screen].root_cursor = XCreateFontCursor(dpy, XC_left_ptr);
- XRecolorCursor(dpy, screens[screen].root_cursor, &red, &white);
+ root_cursor = XCreateFontCursor(dpy, XC_left_ptr);
+ XRecolorCursor(dpy, root_cursor, &red, &white);
- screens[screen].box_cursor = XCreateFontCursor(dpy, XC_draped_box);
- XRecolorCursor(dpy, screens[screen].box_cursor, &red, &white);
+ box_cursor = XCreateFontCursor(dpy, XC_draped_box);
+ XRecolorCursor(dpy, box_cursor, &red, &white);
- for (i = 0; cursor_map[i].font_char != 0; i++) {
- Edge e = cursor_map[i].edge;
- screens[screen].cursor_map[e] =
- XCreateFontCursor(dpy, cursor_map[i].font_char);
- XRecolorCursor(dpy, screens[screen].cursor_map[e],
- &red, &white);
+ for (i = 0; cursor_mappings[i].font_char != 0; i++) {
+ Edge e = cursor_mappings[i].edge;
+ cursor_map[e] = XCreateFontCursor(dpy, cursor_mappings[i].font_char);
+ XRecolorCursor(dpy, cursor_map[e], &red, &white);
}
}
extern Cursor
getEdgeCursor(Edge edge) {
- return screens[0].cursor_map[edge];
+ return cursor_map[edge];
}
return;
}
- if (c->parent != c->screen->root) {
+ if (c->parent != root) {
XUnmapWindow(dpy, c->parent);
- XReparentWindow(dpy, c->parent, c->screen->root, c->size.x, c->size.y);
+ XReparentWindow(dpy, c->parent, root, c->size.x, c->size.y);
}
XRemoveFromSaveSet(dpy, c->window);
if (c->framed == True) {
XSetWindowAttributes attr;
- attr.cursor = c->screen->root_cursor;
+ attr.cursor = root_cursor;
XChangeWindowAttributes(dpy, c->parent,
CWCursor, &attr);
c->cursor = ENone;
XSetWindowAttributes attr;
if (edge == ENone) {
- attr.cursor = c->screen->root_cursor;
+ attr.cursor = root_cursor;
} else {
- attr.cursor = c->screen->cursor_map[edge];
+ attr.cursor = cursor_map[edge];
}
- XChangeWindowAttributes(dpy, c->parent,
- CWCursor, &attr);
+ XChangeWindowAttributes(dpy, c->parent, CWCursor, &attr);
c->cursor = edge;
}
}
int start_y; /* The Y position where the mode changed. */
Display * dpy; /* The connection to the X server. */
+Window root;
+int display_width; /* The width of the screen. */
+int display_height; /* The height of the screen. */
+GC gc; /* The default GC. */
+unsigned long black; /* Black pixel value. */
+unsigned long white; /* White pixel value. */
+unsigned long gray; /* Gray pixel value. */
+Cursor root_cursor;
+Cursor box_cursor;
+Cursor cursor_map[E_LAST];
+
int screen_count; /* The number of screens. */
ScreenInfo * screens; /* Information about these screens. */
ScreenInfo * current_screen;
/* Internalize useful atoms. */
wm_state = XInternAtom(dpy, "WM_STATE", False);
- wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False);
wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False);
wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
wm_take_focus = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
Window * wins;
XWindowAttributes attr;
- XQueryTree(dpy, screens[screen].root, &dw1, &dw2, &wins, &nwins);
+ XQueryTree(dpy, root, &dw1, &dw2, &wins, &nwins);
for (i = 0; i < nwins; i++) {
XGetWindowAttributes(dpy, wins[i], &attr);
if (attr.override_redirect)
continue;
- c = Client_Add(wins[i], screens[screen].root);
+ c = Client_Add(wins[i], root);
if (c != 0 && c->window == wins[i]) {
c->screen = &screens[screen];
c->size.x = attr.x;
XSetWindowAttributes attr;
XColor colour, exact;
int len;
- char * display_string = DisplayString(dpy);
- char * colon = strrchr(display_string, ':');
- char * dot = NULL;
-
- /* Set the DISPLAY specification. */
- if (colon) {
- dot = strrchr(colon, '.');
- len = 9 + strlen(display_string) + ((dot == 0) ? 2 : 0) + 10;
- screens[screen].display_spec = (char *) malloc(len);
- sprintf(screens[screen].display_spec, "DISPLAY=%s", display_string);
- if (dot == 0) dot = screens[screen].display_spec + len - 3;
- else dot = strrchr(screens[screen].display_spec, '.');
- sprintf(dot, ".%i", screen);
- } else {
- screens[screen].display_spec = 0;
- }
/* Find the root window. */
- screens[screen].root = RootWindow(dpy, screen);
- screens[screen].display_width = DisplayWidth(dpy, screen);
- screens[screen].display_height = DisplayHeight(dpy, screen);
+ root = RootWindow(dpy, screen);
+ display_width = DisplayWidth(dpy, screen);
+ display_height = DisplayHeight(dpy, screen);
/* Get the pixel values of the only two colours we use. */
- screens[screen].black = BlackPixel(dpy, screen);
- screens[screen].white = WhitePixel(dpy, screen);
+ black = BlackPixel(dpy, screen);
+ white = WhitePixel(dpy, screen);
XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "DimGray", &colour, &exact);
- screens[screen].gray = colour.pixel;
+ gray = colour.pixel;
/* Set up root (frame) GC's. */
- gv.foreground = screens[screen].black ^ screens[screen].white;
- gv.background = screens[screen].white;
+ gv.foreground = black ^ white;
+ gv.background = white;
gv.function = GXxor;
gv.line_width = 1;
gv.subwindow_mode = IncludeInferiors;
gv.line_width = 2;
- screens[screen].gc = XCreateGC(dpy, screens[screen].root,
+ gc = XCreateGC(dpy, root,
GCForeground | GCBackground | GCFunction |
GCLineWidth | GCSubwindowMode, &gv);
/* Announce our interest in the root window. */
- attr.cursor = screens[screen].root_cursor;
+ attr.cursor = root_cursor;
attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask |
ColormapChangeMask | ButtonPressMask | PropertyChangeMask |
EnterWindowMask;
- XChangeWindowAttributes(dpy, screens[screen].root, CWCursor |
- CWEventMask, &attr);
+ XChangeWindowAttributes(dpy, root, CWCursor | CWEventMask, &attr);
/* Make sure all our communication to the server got through. */
XSync(dpy, False);
Find the screen for which root is the root window.
*/
ScreenInfo *
-getScreenFromRoot(Window root) {
+getScreenFromRoot(Window wroot) {
int screen;
for (screen = 0; screen < screen_count; screen++)
- if (screens[screen].root == root)
+ if (root == wroot)
return &screens[screen];
return 0;
*/
typedef struct ScreenInfo ScreenInfo;
struct ScreenInfo {
- Window root;
- int display_width; /* The width of the screen. */
- int display_height; /* The height of the screen. */
- GC gc; /* The default GC. */
- unsigned long black; /* Black pixel value. */
- unsigned long white; /* White pixel value. */
- unsigned long gray; /* Gray pixel value. */
- Cursor root_cursor;
- Cursor box_cursor;
- Cursor cursor_map[E_LAST];
- Bool ewmh_set_client_list; /* hack to prevent recursion */
- char * display_spec;
};
/* Client flags for EWMH protocols and window behavior */
extern Mode mode;
extern int start_x;
extern int start_y;
+
extern Display * dpy;
+extern Window root;
+extern int display_width; /* The width of the screen. */
+extern int display_height; /* The height of the screen. */
+extern GC gc; /* The default GC. */
+extern unsigned long black; /* Black pixel value. */
+extern unsigned long white; /* White pixel value. */
+extern unsigned long gray; /* Gray pixel value. */
+extern Cursor root_cursor;
+extern Cursor box_cursor;
+extern Cursor cursor_map[E_LAST];
+
extern int screen_count;
extern ScreenInfo * screens;
extern ScreenInfo * current_screen;
*/
if (c->framed == True) {
- c->parent = XCreateSimpleWindow(dpy, c->screen->root,
+ c->parent = XCreateSimpleWindow(dpy, root,
c->size.x, c->size.y - titleHeight(),
c->size.width, c->size.height + titleHeight(),
- 1, c->screen->black, c->screen->white);
+ 1, black, white);
attr.event_mask = ExposureMask | EnterWindowMask | ButtonMask |
SubstructureRedirectMask | SubstructureNotifyMask |
void
getMousePosition(int * x, int * y) {
- Window root, child;
+ Window wroot, child;
int t1, t2;
unsigned int b;
/* It doesn't matter which root window we give this call. */
- XQueryPointer(dpy, screens[0].root, &root, &child, x, y, &t1, &t2, &b);
- current_screen = getScreenFromRoot(root);
+ XQueryPointer(dpy, root, &wroot, &child, x, y, &t1, &t2, &b);
}