]> git.mdlowis.com Git - proto/lwm.git/commitdiff
started dissecting screen info since all my machines have a single screen and that...
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 9 Mar 2020 18:51:49 +0000 (14:51 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 9 Mar 2020 18:51:49 +0000 (14:51 -0400)
client.c
cursor.c
disp.c
lwm.c
lwm.h
manage.c
mouse.c

index 61bf15ea56bc3ee28f4edffecc8706d4c7c76334..6ecace5a2d69534113fbe4bd0eaf2c03291c7959 100644 (file)
--- 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;
     }
 }
index a689f956b690352f3a1a9a964e616ab20c83ddb8..4839b01d9e0e39b1ca920e3df330958072621f09 100644 (file)
--- 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 7d06329309c7c804e8941ab23842730024b51752..6136e632df2c1d985e4e935287b712771d080381 100644 (file)
--- 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 7cb2b5a3d5301b02ae795f2ac7f0f3109ffc7b67..644da6db5458fb450d74d6d1468e1751f592241f 100644 (file)
--- 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 ceb9949a4264fea4e4597011a4a8d48fd141fcc7..004643da6097bbdad19f5135a40e79bc694f4055 100644 (file)
--- 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;
index 283ad37c30273c3d64ef0c20ff4c613641581d8a..a40764dce95f7b571fad07d019bf39089f6d8dd9 100644 (file)
--- 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 6ab33b35ff49618393455b0beede71b07201dba4..f86ac191834d3e7dacc4ab36433f494b1cebdee5 100644 (file)
--- a/mouse.c
+++ b/mouse.c
 
 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);
 }