From c13f17bcff04f32f35afbf9c8f2a453978529105 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 9 Mar 2020 14:51:49 -0400 Subject: [PATCH] started dissecting screen info since all my machines have a single screen and that's it. --- client.c | 12 +++++------- cursor.c | 22 ++++++++++----------- disp.c | 13 ++++++------- lwm.c | 59 +++++++++++++++++++++++++------------------------------- lwm.h | 24 +++++++++++------------ manage.c | 4 ++-- mouse.c | 5 ++--- 7 files changed, 63 insertions(+), 76 deletions(-) diff --git a/client.c b/client.c index 61bf15e..6ecace5 100644 --- a/client.c +++ b/client.c @@ -82,17 +82,16 @@ void 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); } @@ -355,9 +354,8 @@ Client_ResetAllCursors(void) { 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; } } diff --git a/cursor.c b/cursor.c index a689f95..4839b01 100644 --- a/cursor.c +++ b/cursor.c @@ -32,7 +32,7 @@ struct CursorMapping { 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}, @@ -56,22 +56,20 @@ initialiseCursors(int screen) { 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]; } diff --git a/disp.c b/disp.c index 7d06329..6136e63 100644 --- a/disp.c +++ b/disp.c @@ -272,9 +272,9 @@ unmap(XEvent *ev) { 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); @@ -478,7 +478,7 @@ enter(XEvent *ev) { 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; @@ -548,12 +548,11 @@ motionnotify(XEvent *ev) { 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; } } diff --git a/lwm.c b/lwm.c index 7cb2b5a..644da6d 100644 --- a/lwm.c +++ b/lwm.c @@ -43,6 +43,17 @@ int start_x; /* The X position where the mode changed. */ 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; @@ -78,7 +89,6 @@ main(int argc, char *argv[]) { /* 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); @@ -147,12 +157,12 @@ scanWindowTree(int screen) { 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; @@ -219,53 +229,36 @@ initScreen(int screen) { 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); @@ -275,11 +268,11 @@ initScreen(int screen) { 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; diff --git a/lwm.h b/lwm.h index ceb9949..004643d 100644 --- a/lwm.h +++ b/lwm.h @@ -64,18 +64,6 @@ typedef enum { */ 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 */ @@ -116,7 +104,19 @@ extern int border; 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; diff --git a/manage.c b/manage.c index 283ad37..a40764d 100644 --- a/manage.c +++ b/manage.c @@ -172,10 +172,10 @@ manage(Client * c, int mapped) */ 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 | diff --git a/mouse.c b/mouse.c index 6ab33b3..f86ac19 100644 --- a/mouse.c +++ b/mouse.c @@ -30,12 +30,11 @@ 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); } -- 2.54.0