Some analysis on the InitVirtualScreens() function. It is doing too many
things at once.

For instance, it tries to establish if virtual screens should be used at
all - but does this incorrectly (or at least in a very weird way): the
variable userealroot is always True. But it also looks at the atom
WM_VIRTUALROOT but never does anything with it.

Now if the config file has not made a list of virtual screens yet (there
are 2 such lists, one of names, and a corresponding one of data
structures, and the config file makes the names), it makes one. That is,
if it doesn't decide to not do it (which is always the case).

After that, it constructs the list of virtual screen data from the list
of virtual screen names. The names are really the geometry.

(Somewhat aside: that is evil. It should find out the geometry from the
X server. If I had two screens, I don't want their configurations set in
both the X config and the windowmanager config. What if I sit at a
different display every time?).

So, there are at least 2 directives in the config file
(MapWindowCurrentWorkSpace and MapWindowDefaultWorkSpace) that want to
change the virtual screen data list - which doesn't exist yet at all if
InitVirtualScreens() is called after the parsing, and which is default
(i.e. not corresponding to the VirtualScreens directive) if
InitVirtualScreens() is called before the parsing.

The MapWindowCurrentWorkSpace directives set the same data into every
workspacemanagerwindow in every virtual screen, so basically the data is
global and it can just be put in the global ScreenInfo structure.

I propose to move some fields from struct WorkSpaceWindow to struct
WorkSpaceMgr.  I found some more config-time accesses to vScreenList and
I want to move their data too. (I'd even like to set the pointer to some
invalid value, just to catch accesses to it, but you may find that a bit
extreme?)

This operation isn't very complicated but the patch is fairly large.
Something like this before cleanup.
There is still a redundant assignment from Scr->WMgrVertButtonIndent to 
Scr->workSpaceMgr.vspace: it is done while reading the config file and
again later.

# 
# old_revision [4b44cdbf308aa80b3a36017ba4acd4a4ef304b63]
# 
# patch "parse.c"
#  from [4f4ea67447ed1f8c2508e1534da6d7188659469d]
#    to [0691e2a03f62f09fcc19fcae3e9e2117ca36f36f]
# 
# patch "workmgr.c"
#  from [fc4606e28ceb6d9e1773432cf20ddab22b3850da]
#    to [e4451660597155f8c43302bed9b321349266d5ef]
# 
# patch "workmgr.h"
#  from [4dc639cabee882859bcb639fd723c306fea25a08]
#    to [b37e79e38c996c49259ce4bc8869f4e1038c90bd]
# 
============================================================
--- parse.c     4f4ea67447ed1f8c2508e1534da6d7188659469d
+++ parse.c     0691e2a03f62f09fcc19fcae3e9e2117ca36f36f
@@ -1215,10 +1215,7 @@ int do_single_keyword (int keyword)
        return 1;
 
       case kw0_StartInMapState:
-       for (vs = Scr->vScreenList; vs != NULL; vs = vs->next) {
-         vs->wsw->state = MAPSTATE;
-       }
-       Scr->workSpaceMgr.initialstate = MAPSTATE; /* redundant, really */
+       Scr->workSpaceMgr.initialstate = MAPSTATE;
        return 1;
 
       case kw0_NoShowOccupyAll:
@@ -1670,18 +1667,14 @@ int do_number_keyword (int keyword, int 
       case kwn_WMgrVertButtonIndent:
        if (Scr->FirstTime) Scr->WMgrVertButtonIndent = num;
        if (Scr->WMgrVertButtonIndent < 0) Scr->WMgrVertButtonIndent = 0;
-       for (vs = Scr->vScreenList; vs != NULL; vs = vs->next) {
-         vs->wsw->vspace          = Scr->WMgrVertButtonIndent;
-       }
+       Scr->workSpaceMgr.vspace = Scr->WMgrVertButtonIndent;
        Scr->workSpaceMgr.occupyWindow->vspace = Scr->WMgrVertButtonIndent;
        return 1;
 
       case kwn_WMgrHorizButtonIndent:
        if (Scr->FirstTime) Scr->WMgrHorizButtonIndent = num;
        if (Scr->WMgrHorizButtonIndent < 0) Scr->WMgrHorizButtonIndent = 0;
-       for (vs = Scr->vScreenList; vs != NULL; vs = vs->next) {
-         vs->wsw->hspace          = Scr->WMgrHorizButtonIndent;
-       }
+       Scr->workSpaceMgr.hspace = Scr->WMgrVertButtonIndent;
        Scr->workSpaceMgr.occupyWindow->hspace = Scr->WMgrHorizButtonIndent;
        return 1;
 
============================================================
--- workmgr.c   fc4606e28ceb6d9e1773432cf20ddab22b3850da
+++ workmgr.c   e4451660597155f8c43302bed9b321349266d5ef
@@ -141,6 +141,16 @@ void InitWorkSpaceManager (void)
     Scr->workSpaceMgr.occupyWindow->columns   = 0;
     Scr->workSpaceMgr.occupyWindow->twm_win   = (TwmWindow*) 0;
 
+    Scr->workSpaceMgr.curColors.back  = Scr->Black;
+    Scr->workSpaceMgr.curColors.fore  = Scr->White;
+    Scr->workSpaceMgr.defColors.back  = Scr->White;
+    Scr->workSpaceMgr.defColors.fore  = Scr->Black;    
+    Scr->workSpaceMgr.curImage        = None;
+    Scr->workSpaceMgr.curPaint        = False;
+    Scr->workSpaceMgr.defImage        = None;
+    Scr->workSpaceMgr.vspace          = Scr->WMgrVertButtonIndent;
+    Scr->workSpaceMgr.hspace          = Scr->WMgrHorizButtonIndent;
+
 #ifdef I18N
     Scr->workSpaceMgr.windowFont.basename =
       "-adobe-courier-medium-r-normal--10-100-75-75-m-60-iso8859-1";
@@ -157,22 +167,14 @@ void ConfigureWorkSpaceManager (void) {
 
 void ConfigureWorkSpaceManager (void) {
     virtualScreen *vs;
+
     for (vs = Scr->vScreenList; vs != NULL; vs = vs->next) {
        WorkSpaceWindow *wsw = (WorkSpaceWindow*) malloc (sizeof 
(WorkSpaceWindow));
        wsw->name            = "WorkSpaceManager";
        wsw->icon_name       = "WorkSpaceManager Icon";
        wsw->twm_win         = (TwmWindow*) 0;
+       wsw->state = Scr->workSpaceMgr.initialstate; /* BUTTONSSTATE */
        vs->wsw = wsw;
-       vs->wsw->curColors.back  = Scr->Black;
-       vs->wsw->curColors.fore  = Scr->White;
-       vs->wsw->defColors.back  = Scr->White;
-       vs->wsw->defColors.fore  = Scr->Black;  
-       vs->wsw->curImage        = None;
-       vs->wsw->curPaint        = False;
-       vs->wsw->defImage        = None;
-       vs->wsw->state = Scr->workSpaceMgr.initialstate; /* BUTTONSSTATE */
-       vs->wsw->vspace          = Scr->WMgrVertButtonIndent;
-       vs->wsw->hspace          = Scr->WMgrHorizButtonIndent;
     }
 }
 
@@ -244,14 +246,17 @@ void CreateWorkSpaceManager (void)
       WorkSpaceWindow *wsw = vs->wsw;
       WorkSpace *ws2 = wsw->currentwspc;
       MapSubwindow *msw = wsw->mswl [ws2->number];
-      if (wsw->curImage == None) {
-       if (wsw->curPaint) {
-         XSetWindowBackground (dpy, msw->w, wsw->curColors.back);
+      if (Scr->workSpaceMgr.curImage == None) {
+         printf("CreateWorkSpaceManager: curPaint = %d, curColors.back = 
%lx\n", 
+                 Scr->workSpaceMgr.curPaint,
+                 Scr->workSpaceMgr.curColors.back);
+       if (Scr->workSpaceMgr.curPaint) {
+         XSetWindowBackground (dpy, msw->w, Scr->workSpaceMgr.curColors.back);
        }
       } else {
-       XSetWindowBackgroundPixmap (dpy, msw->w, wsw->curImage->pixmap);
+       XSetWindowBackgroundPixmap (dpy, msw->w, 
Scr->workSpaceMgr.curImage->pixmap);
       }
-      XSetWindowBorder (dpy, msw->w, wsw->curBorderColor);
+      XSetWindowBorder (dpy, msw->w, Scr->workSpaceMgr.curBorderColor);
       XClearWindow (dpy, msw->w);
 
       if (useBackgroundInfo && ! Scr->DontPaintRootWindow) {
@@ -445,6 +450,7 @@ void GotoWorkSpace (virtualScreen *vs, W
     TwmWindow           *last_twmWin = NULL;
     virtualScreen       *tmpvs;
 
+    printf("GotoWorkSpace\n");
     if (! Scr->workSpaceManagerActive) return;
     for (tmpvs = Scr->vScreenList; tmpvs != NULL; tmpvs = tmpvs->next) {
       if (ws == tmpvs->wsw->currentwspc) {
@@ -561,21 +567,24 @@ void GotoWorkSpace (virtualScreen *vs, W
            XSetWindowBackgroundPixmap (dpy, oldw, oldws->image->pixmap);
     }
     else {
-       if (vs->wsw->defImage == None || Scr->NoImagesInWorkSpaceManager)
-           XSetWindowBackground       (dpy, oldw, vs->wsw->defColors.back);
+       if (Scr->workSpaceMgr.defImage == None || 
Scr->NoImagesInWorkSpaceManager)
+           XSetWindowBackground       (dpy, oldw, 
Scr->workSpaceMgr.defColors.back);
        else
-           XSetWindowBackgroundPixmap (dpy, oldw, vs->wsw->defImage->pixmap);
+           XSetWindowBackgroundPixmap (dpy, oldw, 
Scr->workSpaceMgr.defImage->pixmap);
     }
-    attr.border_pixel = vs->wsw->defBorderColor;
+    attr.border_pixel = Scr->workSpaceMgr.defBorderColor;
+    printf("set defBorderColor %lx\n", attr.border_pixel);
     XChangeWindowAttributes (dpy, oldw, CWBorderPixel, &attr);
 
-    if (vs->wsw->curImage == None) {
-       if (vs->wsw->curPaint) XSetWindowBackground (dpy, neww, 
vs->wsw->curColors.back);
+    if (Scr->workSpaceMgr.curImage == None) {
+       printf("set curColors.back %lx\n", Scr->workSpaceMgr.curColors.back);
+       if (Scr->workSpaceMgr.curPaint) XSetWindowBackground (dpy, neww, 
Scr->workSpaceMgr.curColors.back);
     }
     else {
-       XSetWindowBackgroundPixmap (dpy, neww, vs->wsw->curImage->pixmap);
+       XSetWindowBackgroundPixmap (dpy, neww, 
Scr->workSpaceMgr.curImage->pixmap);
     }
-    attr.border_pixel = vs->wsw->curBorderColor;
+    attr.border_pixel =  Scr->workSpaceMgr.curBorderColor;
+    printf("set curBorderColor %lx\n", attr.border_pixel);
     XChangeWindowAttributes (dpy, neww, CWBorderPixel, &attr);
 
     XClearWindow (dpy, oldw);
@@ -846,7 +855,7 @@ void SetupOccupation (TwmWindow *twm_win
            state = twm_win->wmhints->initial_state;
     }
     if (visible (twm_win)) {
-       if (state == InactiveState) SetMapStateProp (twm_win,   NormalState);
+       if (state == InactiveState) SetMapStateProp (twm_win, NormalState);
     } else {
        if (state ==   NormalState) SetMapStateProp (twm_win, InactiveState);
     }
@@ -1587,11 +1596,11 @@ static void CreateWorkSpaceManagerWindow
     icon_name = vs->wsw->icon_name;
     geometry  = Scr->workSpaceMgr.geometry;
     columns   = Scr->workSpaceMgr.columns;
-    vspace    = vs->wsw->vspace;
-    hspace    = vs->wsw->hspace;
+    vspace    = Scr->workSpaceMgr.vspace;
+    hspace    = Scr->workSpaceMgr.hspace;
     font      = Scr->workSpaceMgr.buttonFont;
     cp        = Scr->workSpaceMgr.cp;
-    border    = vs->wsw->defBorderColor;
+    border    = Scr->workSpaceMgr.defBorderColor;
 
     count = 0;
     for (ws = Scr->workSpaceMgr.workSpaceList; ws != NULL; ws = ws->next) 
count++;
@@ -1702,10 +1711,10 @@ static void CreateWorkSpaceManagerWindow
                XSetWindowBackgroundPixmap (dpy, mapsw, ws->image->pixmap);
        }
        else {
-           if (vs->wsw->defImage == None || Scr->NoImagesInWorkSpaceManager)
-               XSetWindowBackground       (dpy, mapsw, 
vs->wsw->defColors.back);
+           if (Scr->workSpaceMgr.defImage == None || 
Scr->NoImagesInWorkSpaceManager)
+               XSetWindowBackground       (dpy, mapsw, 
Scr->workSpaceMgr.defColors.back);
            else
-               XSetWindowBackgroundPixmap (dpy, mapsw, 
vs->wsw->defImage->pixmap);
+               XSetWindowBackgroundPixmap (dpy, mapsw, 
Scr->workSpaceMgr.defImage->pixmap);
        }
        XClearWindow (dpy, butsw);
        i++;
@@ -3162,8 +3171,8 @@ static void ResizeWorkSpaceManager (virt
     if ((neww == oldw) && (newh == oldh)) return;
     oldw = neww; oldh = newh;
 
-    hspace  = vs->wsw->hspace;
-    vspace  = vs->wsw->vspace;
+    hspace  = Scr->workSpaceMgr.hspace;
+    vspace  = Scr->workSpaceMgr.vspace;
     lines   = Scr->workSpaceMgr.lines;
     columns = Scr->workSpaceMgr.columns;
     bwidth  = (neww - (columns * hspace)) / columns;
@@ -3261,56 +3270,62 @@ void WMapCreateCurrentBackGround (char *
                                  char *background, char *foreground,
                                  char *pixmap)
 {
-    virtualScreen *vs;
     Image *image;
+    WorkSpaceMgr *ws = &Scr->workSpaceMgr;
 
-    for (vs = Scr->vScreenList; vs; vs = vs->next) {
-      vs->wsw->curBorderColor = Scr->Black;
-      vs->wsw->curColors.back = Scr->White;
-      vs->wsw->curColors.fore = Scr->Black;
-      vs->wsw->curImage       = None;
+    ws->curBorderColor = Scr->Black;
+    ws->curColors.back = Scr->White;
+    ws->curColors.fore = Scr->Black;
+    ws->curImage       = None;
 
-      if (border == NULL) continue;
-      GetColor (Scr->Monochrome, &(vs->wsw->curBorderColor), border);
-      if (background == NULL) continue;
-      vs->wsw->curPaint = True;
-      GetColor (Scr->Monochrome, &(vs->wsw->curColors.back), background);
-      if (foreground == NULL) continue;
-      GetColor (Scr->Monochrome, &(vs->wsw->curColors.fore), foreground);
+    if (border == NULL)
+       return;
+    GetColor (Scr->Monochrome, &ws->curBorderColor, border);
+    if (background == NULL)
+       return;
+    ws->curPaint = True;
+    GetColor (Scr->Monochrome, &ws->curColors.back, background);
+    printf("WMapCreateCurrentBackGround: background %s -> %lx\n",
+           background, ws->curColors.back);
+    if (foreground == NULL)
+       return;
+    GetColor (Scr->Monochrome, &ws->curColors.fore, foreground);
 
-      if (pixmap == NULL) continue;
-      if ((image = GetImage (pixmap, vs->wsw->curColors)) == None) {
+    if (pixmap == NULL)
+       return;
+    if ((image = GetImage (pixmap, ws->curColors)) == None) {
        fprintf (stderr, "Can't find pixmap %s\n", pixmap);
-       continue;
-      }
-      vs->wsw->curImage = image;
+       return;
     }
+    ws->curImage = image;
 }
 
 void WMapCreateDefaultBackGround (char *border,
                                  char *background, char *foreground,
                                  char *pixmap)
 {
-    virtualScreen *vs;
     Image *image;
+    WorkSpaceMgr *ws = &Scr->workSpaceMgr;
 
-    for (vs = Scr->vScreenList; vs; vs = vs->next) {
-      vs->wsw->defBorderColor = Scr->Black;
-      vs->wsw->defColors.back = Scr->White;
-      vs->wsw->defColors.fore = Scr->Black;
-      vs->wsw->defImage       = None;
+    ws->defBorderColor = Scr->Black;
+    ws->defColors.back = Scr->White;
+    ws->defColors.fore = Scr->Black;
+    ws->defImage       = None;
 
-      if (border == NULL) continue;
-      GetColor (Scr->Monochrome, &(vs->wsw->defBorderColor), border);
-      if (background == NULL) continue;
-      GetColor (Scr->Monochrome, &(vs->wsw->defColors.back), background);
-      if (foreground == NULL) continue;
-      GetColor (Scr->Monochrome, &(vs->wsw->defColors.fore), foreground);
-
-      if (pixmap == NULL) continue;
-      if ((image = GetImage (pixmap, vs->wsw->defColors)) == None) continue;
-      vs->wsw->defImage = image;
-    }
+    if (border == NULL)
+       return;
+    GetColor (Scr->Monochrome, &ws->defBorderColor, border);
+    if (background == NULL)
+       return;
+    GetColor (Scr->Monochrome, &ws->defColors.back, background);
+    if (foreground == NULL)
+       return;
+    GetColor (Scr->Monochrome, &ws->defColors.fore, foreground);
+    if (pixmap == NULL)
+       return;
+    if ((image = GetImage (pixmap, ws->defColors)) == None)
+       return;
+    ws->defImage = image;
 }
 
 Bool AnimateRoot (void)
============================================================
--- workmgr.h   4dc639cabee882859bcb639fd723c306fea25a08
+++ workmgr.h   b37e79e38c996c49259ce4bc8869f4e1038c90bd
@@ -70,6 +70,15 @@ struct WorkSpaceMgr {
     short                  buttonStyle;
     name_list      *windowBackgroundL;
     name_list      *windowForegroundL;
+    ColorPair          curColors;
+    Image              *curImage;
+    unsigned long      curBorderColor;
+    Bool               curPaint;
+
+    ColorPair          defColors;
+    Image             *defImage;
+    unsigned long      defBorderColor;
+    int                        hspace, vspace;
 };
 
 struct WorkSpace {
@@ -111,17 +120,8 @@ struct WorkSpaceWindow {
 
   int          width, height;
   int          bwidth, bheight;
-  int          hspace, vspace;
   int          wwidth, wheight;
   
-  ColorPair            curColors;
-  Image                *curImage;
-  unsigned long        curBorderColor;
-  Bool         curPaint;
-
-  ColorPair            defColors;
-  Image                *defImage;
-  unsigned long        defBorderColor;
   struct WorkSpaceWindow *next;
 };
 


Reply via email to