The variable workspace_count, that contains the number of workspaces
is moved to the global workspace properties.

Now the screen is not needed to know the workspace_count.

Signed-off-by: Rodolfo García Peñas (kix) <k...@kix.es>
---
 src/appicon.c    |  7 +++---
 src/dock.c       | 19 ++++++++------
 src/event.c      |  9 ++++---
 src/moveres.c    | 27 +++++++++-----------
 src/screen.h     |  2 --
 src/session.c    | 30 +++++++++++-----------
 src/startup.c    |  3 ++-
 src/window.c     | 21 ++++++++--------
 src/winmenu.c    |  4 +--
 src/winspector.c |  9 ++++---
 src/wmspec.c     | 20 ++++++++-------
 src/workspace.c  | 76 +++++++++++++++++++++++++++-----------------------------
 src/workspace.h  |  1 +
 13 files changed, 116 insertions(+), 112 deletions(-)

diff --git a/src/appicon.c b/src/appicon.c
index e78ea73..ab49aba 100644
--- a/src/appicon.c
+++ b/src/appicon.c
@@ -62,6 +62,7 @@
 
 /**** Global variables ****/
 extern WDDomain *WDWindowAttributes;
+extern WWorkspace_info wks_info;
 
 #define MOD_MASK       wPreferences.modifier_mask
 #define ICON_SIZE      wPreferences.icon_size
@@ -859,7 +860,7 @@ Bool wHandleAppIconMove(WAppIcon *aicon, XEvent *event)
 
                        if (omnipresent && !showed_all_clips) {
                                int i;
-                               for (i = 0; i < scr->workspace_count; i++) {
+                               for (i = 0; i < wks_info.workspace_count; i++) {
                                        if (i == scr->current_workspace)
                                                continue;
                                        
wDockShowIcons(scr->workspaces[i]->clip);
@@ -1064,7 +1065,7 @@ Bool wHandleAppIconMove(WAppIcon *aicon, XEvent *event)
                        }
                        if (showed_all_clips) {
                                int i;
-                               for (i = 0; i < scr->workspace_count; i++) {
+                               for (i = 0; i < wks_info.workspace_count; i++) {
                                        if (i == scr->current_workspace)
                                                continue;
                                        
wDockHideIcons(scr->workspaces[i]->clip);
@@ -1146,7 +1147,7 @@ static void create_appicon_from_dock(WWindow *wwin, 
WApplication *wapp, Window m
        /* check clips */
        if (!wapp->app_icon) {
                int i;
-               for (i = 0; i < scr->workspace_count; i++) {
+               for (i = 0; i < wks_info.workspace_count; i++) {
                        WDock *dock = scr->workspaces[i]->clip;
                        if (dock)
                                wapp->app_icon = findDockIconFor(dock, 
main_window);
diff --git a/src/dock.c b/src/dock.c
index f1ee032..07ab823 100644
--- a/src/dock.c
+++ b/src/dock.c
@@ -65,6 +65,9 @@
 #define CLIP_IDLE         0
 #define CLIP_FORWARD      2
 
+/**** Global variables ****/
+extern WWorkspace_info wks_info;
+
 #define MOD_MASK wPreferences.modifier_mask
 #define ICON_SIZE wPreferences.icon_size
 
@@ -594,7 +597,7 @@ static void toggleAutoAttractCallback(WMenu *menu, 
WMenuEntry *entry)
        } else if (dock->type == WM_DRAWER) {
                /* check if at least one clip already auto attracts icons */
                int i, ask_for_confirmation = False;
-               for (i = 0; i < scr->workspace_count; i++) {
+               for (i = 0; i < wks_info.workspace_count; i++) {
                        if (scr->workspaces[ i ]->clip->attract_icons) {
                                ask_for_confirmation = True;
                                break;
@@ -620,10 +623,10 @@ static void toggleAutoAttractCallback(WMenu *menu, 
WMenuEntry *entry)
                        /* The newly auto-attracting dock is a drawer: disable 
any clip and 
                         * previously attracting drawer */
                        int i;
-                       for (i = 0; i < scr->workspace_count; i++) {
+                       for (i = 0; i < wks_info.workspace_count; i++)
                                scr->workspaces[ i ]->clip->attract_icons = 
False;
                                /* dock menu will be updated later, when opened 
*/
-                       }
+
                        if (scr->attracting_drawer != NULL)
                                scr->attracting_drawer->attract_icons = False;
                        scr->attracting_drawer = dock;
@@ -941,7 +944,7 @@ static void updateWorkspaceMenu(WMenu *menu, WAppIcon *icon)
        if (!menu || !icon)
                return;
 
-       for (i = 0; i < scr->workspace_count; i++) {
+       for (i = 0; i < wks_info.workspace_count; i++) {
                if (i < menu->entry_no) {
                        if (strcmp(menu->entries[i]->text, 
scr->workspaces[i]->name) != 0) {
                                wfree(menu->entries[i]->text);
@@ -2576,7 +2579,7 @@ Bool wDockSnapIcon(WDock *dock, WAppIcon *icon, int 
req_x, int req_y, int *ret_x
                int start, stop, k;
 
                start = icon->omnipresent ? 0 : scr->current_workspace;
-               stop = icon->omnipresent ? scr->workspace_count : start + 1;
+               stop = icon->omnipresent ? wks_info.workspace_count : start + 1;
 
                aicon = NULL;
                for (k = start; k < stop; k++) {
@@ -3895,7 +3898,7 @@ static void handleClipChangeWorkspace(WScreen *scr, 
XEvent *event)
        new_ws = wPreferences.ws_advance || (event->xbutton.state & 
ControlMask);
 
        if (direction == CLIP_FORWARD) {
-               if (scr->current_workspace < scr->workspace_count - 1)
+               if (scr->current_workspace < wks_info.workspace_count - 1)
                        wWorkspaceChange(scr, scr->current_workspace + 1);
                else if (new_ws && scr->current_workspace < MAX_WORKSPACES - 1)
                        wWorkspaceChange(scr, scr->current_workspace + 1);
@@ -3905,7 +3908,7 @@ static void handleClipChangeWorkspace(WScreen *scr, 
XEvent *event)
                if (scr->current_workspace > 0)
                        wWorkspaceChange(scr, scr->current_workspace - 1);
                else if (scr->current_workspace == 0 && wPreferences.ws_cycle)
-                       wWorkspaceChange(scr, scr->workspace_count - 1);
+                       wWorkspaceChange(scr, wks_info.workspace_count - 1);
        }
 
        wClipIconPaint(scr->clip_icon);
@@ -4148,7 +4151,7 @@ static Bool iconCanBeOmnipresent(WAppIcon *aicon)
        WAppIcon *btn;
        int i, j;
 
-       for (i = 0; i < scr->workspace_count; i++) {
+       for (i = 0; i < wks_info.workspace_count; i++) {
                clip = scr->workspaces[i]->clip;
 
                if (clip == aicon->dock)
diff --git a/src/event.c b/src/event.c
index b11df23..f98546d 100644
--- a/src/event.c
+++ b/src/event.c
@@ -79,6 +79,7 @@
 /******** Global Variables **********/
 extern WShortKey wKeyBindings[WKBD_LAST];
 extern int wScreenCount;
+extern WWorkspace_info wks_info;
 
 #define MOD_MASK wPreferences.modifier_mask
 
@@ -1567,7 +1568,7 @@ static void handleKeyPress(XEvent * event)
        case WKBD_WORKSPACE1 ... WKBD_WORKSPACE10:
                widx = command - WKBD_WORKSPACE1;
                i = (scr->current_workspace / 10) * 10 + widx;
-               if (wPreferences.ws_advance || i < scr->workspace_count)
+               if (wPreferences.ws_advance || i < wks_info.workspace_count)
                        wWorkspaceChange(scr, i);
                break;
 
@@ -1584,7 +1585,7 @@ static void handleKeyPress(XEvent * event)
        case WKBD_MOVE_WORKSPACE1 ... WKBD_MOVE_WORKSPACE10:
                widx = command - WKBD_MOVE_WORKSPACE1;
                i = (scr->current_workspace / 10) * 10 + widx;
-               if (wwin && (wPreferences.ws_advance || i < 
scr->workspace_count))
+               if (wwin && (wPreferences.ws_advance || i < 
wks_info.workspace_count))
                        wWindowChangeWorkspace(wwin, i);
                break;
 
@@ -1611,7 +1612,7 @@ static void handleKeyPress(XEvent * event)
                                column = scr->current_workspace % 10;
 
                                if (command == WKBD_MOVE_NEXTWSLAYER) {
-                                       if ((row + 1) * 10 < 
scr->workspace_count)
+                                       if ((row + 1) * 10 < 
wks_info.workspace_count)
                                                wWindowChangeWorkspace(wwin, 
column + (row + 1) * 10);
                                } else {
                                        if (row > 0)
@@ -1731,7 +1732,7 @@ static void handleKeyPress(XEvent * event)
                        column = scr->current_workspace % 10;
 
                        if (command == WKBD_NEXTWSLAYER) {
-                               if ((row + 1) * 10 < scr->workspace_count)
+                               if ((row + 1) * 10 < wks_info.workspace_count)
                                        wWorkspaceChange(scr, column + (row + 
1) * 10);
                        } else {
                                if (row > 0)
diff --git a/src/moveres.c b/src/moveres.c
index 86cb88e..2008171 100644
--- a/src/moveres.c
+++ b/src/moveres.c
@@ -60,6 +60,8 @@
  */
 #define HAS_BORDER_WITH_SELECT(w) ((w)->flags.selected || HAS_BORDER(w))
 
+/****** Global Variables ******/
+extern WWorkspace_info wks_info;
 
 /*
  *----------------------------------------------------------------------
@@ -838,23 +840,17 @@ static Bool checkWorkspaceChange(WWindow * wwin, MoveData 
* data, Bool opaqueMov
 
        if (data->mouseX <= 1) {
                if (scr->current_workspace > 0) {
-
                        crossWorkspace(scr, wwin, opaqueMove, 
scr->current_workspace - 1, True);
                        changed = True;
                        data->rubCount = 0;
-
                } else if (scr->current_workspace == 0 && 
wPreferences.ws_cycle) {
-
-                       crossWorkspace(scr, wwin, opaqueMove, 
scr->workspace_count - 1, True);
+                       crossWorkspace(scr, wwin, opaqueMove, 
wks_info.workspace_count - 1, True);
                        changed = True;
                        data->rubCount = 0;
                }
        } else if (data->mouseX >= scr->scr_width - 2) {
-
-               if (scr->current_workspace == scr->workspace_count - 1) {
-
-                       if (wPreferences.ws_cycle || scr->workspace_count == 
MAX_WORKSPACES) {
-
+               if (scr->current_workspace == wks_info.workspace_count - 1) {
+                       if (wPreferences.ws_cycle || wks_info.workspace_count 
== MAX_WORKSPACES) {
                                crossWorkspace(scr, wwin, opaqueMove, 0, False);
                                changed = True;
                                data->rubCount = 0;
@@ -882,8 +878,7 @@ static Bool checkWorkspaceChange(WWindow * wwin, MoveData * 
data, Bool opaqueMov
                                changed = True;
                                data->rubCount = 0;
                        }
-               } else if (scr->current_workspace < scr->workspace_count) {
-
+               } else if (scr->current_workspace < wks_info.workspace_count) {
                        /* go to next workspace */
                        crossWorkspace(scr, wwin, opaqueMove, 
scr->current_workspace + 1, False);
                        changed = True;
@@ -1395,15 +1390,17 @@ int wKeyboardMoveResizeWindow(WWindow * wwin)
                                if (wPreferences.ws_cycle) {
                                        if (src_x + off_x + ww < 20) {
                                                if (!scr->current_workspace) {
-                                                       wWorkspaceChange(scr, 
scr->workspace_count - 1);
-                                               } else
+                                                       wWorkspaceChange(scr, 
wks_info.workspace_count - 1);
+                                               } else {
                                                        wWorkspaceChange(scr, 
scr->current_workspace - 1);
+                                               }
                                                off_x += scr_width;
                                        } else if (src_x + off_x + 20 > 
scr_width) {
-                                               if (scr->current_workspace == 
scr->workspace_count - 1) {
+                                               if (scr->current_workspace == 
wks_info.workspace_count - 1) {
                                                        wWorkspaceChange(scr, 
0);
-                                               } else
+                                               } else {
                                                        wWorkspaceChange(scr, 
scr->current_workspace + 1);
+                                               }
                                                off_x -= scr_width;
                                        }
                                } else {
diff --git a/src/screen.h b/src/screen.h
index 02694ec..4ac9a96 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -121,8 +121,6 @@ typedef struct _WScreen {
 
     int window_count;                 /* number of windows in window_list */
 
-    int workspace_count;              /* number of workspaces */
-
     struct WWorkspace **workspaces;    /* workspace array */
 
     int current_workspace;            /* current workspace number */
diff --git a/src/session.c b/src/session.c
index 6b5696d..183a4d3 100644
--- a/src/session.c
+++ b/src/session.c
@@ -85,6 +85,8 @@
 
 #include <WINGs/WUtil.h>
 
+/** Global **/
+extern WWorkspace_info wks_info;
 
 static WMPropList *sApplications = NULL;
 static WMPropList *sCommand;
@@ -233,15 +235,15 @@ static WMPropList *makeWindowState(WWindow * wwin, 
WApplication * wapp)
                if (wapp && wapp->app_icon && wapp->app_icon->dock) {
                        int i;
                        char *name = NULL;
-                       if (wapp->app_icon->dock == scr->dock) {
+                       if (wapp->app_icon->dock == scr->dock)
                                name = "Dock";
-                       }
-                       if (name == NULL) // Try the clips
-                       {
-                               for (i = 0; i < scr->workspace_count; i++)
+
+                       /* Try the clips */
+                       if (name == NULL) {
+                               for (i = 0; i < wks_info.workspace_count; i++)
                                        if (scr->workspaces[i]->clip == 
wapp->app_icon->dock)
                                                break;
-                               if (i < scr->workspace_count)
+                               if (i < wks_info.workspace_count)
                                        name = scr->workspaces[i]->name;
                        }
                        if (name == NULL) // Try the drawers
@@ -384,7 +386,7 @@ static WSavedState *getWindowState(WScreen * scr, 
WMPropList * win_state)
                tmp = WMGetFromPLString(value);
                if (sscanf(tmp, "%i", &state->workspace) != 1) {
                        state->workspace = -1;
-                       for (i = 0; i < scr->workspace_count; i++) {
+                       for (i = 0; i < wks_info.workspace_count; i++) {
                                if (strcmp(scr->workspaces[i]->name, tmp) == 0) 
{
                                        state->workspace = i;
                                        break;
@@ -468,12 +470,12 @@ void wSessionRestoreState(WScreen *scr)
                value = WMGetFromPLDictionary(win_info, sDock);
                if (value && WMIsPLString(value) && (tmp = 
WMGetFromPLString(value)) != NULL) {
                        if (sscanf(tmp, "%i", &n) != 1) {
-                               if (!strcasecmp(tmp, "DOCK")) {
+                               if (!strcasecmp(tmp, "DOCK"))
                                        dock = scr->dock;
-                               }
-                               if (dock == NULL) // Try the clips
-                               {
-                                       for (j = 0; j < scr->workspace_count; 
j++) {
+
+                               /* Try the clips */
+                               if (dock == NULL) {
+                                       for (j = 0; j < 
wks_info.workspace_count; j++) {
                                                if 
(strcmp(scr->workspaces[j]->name, tmp) == 0) {
                                                        dock = 
scr->workspaces[j]->clip;
                                                        break;
@@ -495,7 +497,7 @@ void wSessionRestoreState(WScreen *scr)
                        } else {
                                if (n == 0) {
                                        dock = scr->dock;
-                               } else if (n > 0 && n <= scr->workspace_count) {
+                               } else if (n > 0 && n <= 
wks_info.workspace_count) {
                                        dock = scr->workspaces[n - 1]->clip;
                                }
                        }
@@ -558,6 +560,6 @@ void wSessionRestoreLastWorkspace(WScreen * scr)
        /* Get the workspace number for the workspace name */
        w = wGetWorkspaceNumber(scr, value);
 
-       if (w != scr->current_workspace && w < scr->workspace_count)
+       if (w != scr->current_workspace && w < wks_info.workspace_count)
                wWorkspaceChange(scr, w);
 }
diff --git a/src/startup.c b/src/startup.c
index 712d3f7..c3a5f45 100644
--- a/src/startup.c
+++ b/src/startup.c
@@ -90,6 +90,7 @@ extern WDDomain *WDRootMenu;
 extern WDDomain *WDWindowAttributes;
 extern WShortKey wKeyBindings[WKBD_LAST];
 extern int wScreenCount;
+extern WWorkspace_info wks_info;
 
 #ifdef SHAPE
 extern Bool wShapeSupported;
@@ -719,7 +720,7 @@ void StartUp(Bool defaultScreenOnly)
                        /* auto-launch apps in clip */
                        if (!wPreferences.flags.noclip) {
                                int i;
-                               for (i = 0; i < wScreen[j]->workspace_count; 
i++) {
+                               for (i = 0; i < wks_info.workspace_count; i++) {
                                        if (wScreen[j]->workspaces[i]->clip) {
                                                wScreen[j]->last_dock = 
wScreen[j]->workspaces[i]->clip;
                                                
wDockDoAutoLaunch(wScreen[j]->workspaces[i]->clip, i);
diff --git a/src/window.c b/src/window.c
index 2063a5c..c0dd3d6 100644
--- a/src/window.c
+++ b/src/window.c
@@ -74,6 +74,7 @@
 
 /****** Global Variables ******/
 extern WShortKey wKeyBindings[WKBD_LAST];
+extern WWorkspace_info wks_info;
 
 #ifdef SHAPE
 extern Bool wShapeSupported;
@@ -379,7 +380,7 @@ void wWindowSetupInitialAttributes(WWindow *wwin, int 
*level, int *workspace)
                }
 
                if (tmp_workspace >= 0)
-                       *workspace = tmp_workspace % scr->workspace_count;
+                       *workspace = tmp_workspace % wks_info.workspace_count;
        }
 
        /*
@@ -841,9 +842,9 @@ WWindow *wManageWindow(WScreen *scr, Window window)
                if (!IS_OMNIPRESENT(wwin)) {
                        int w = wDefaultGetStartWorkspace(scr, 
wwin->wm_instance,
                                                          wwin->wm_class);
-                       if (w < 0 || w >= scr->workspace_count) {
+                       if (w < 0 || w >= wks_info.workspace_count) {
                                workspace = win_state->state->workspace;
-                               if (workspace >= scr->workspace_count)
+                               if (workspace >= wks_info.workspace_count)
                                        workspace = scr->current_workspace;
                        } else {
                                workspace = w;
@@ -912,14 +913,14 @@ WWindow *wManageWindow(WScreen *scr, Window window)
 
        /* set workspace on which the window starts */
        if (workspace >= 0) {
-               if (workspace > scr->workspace_count - 1)
-                       workspace = workspace % scr->workspace_count;
+               if (workspace > wks_info.workspace_count - 1)
+                       workspace = workspace % wks_info.workspace_count;
        } else {
                int w;
 
                w = wDefaultGetStartWorkspace(scr, wwin->wm_instance, 
wwin->wm_class);
 
-               if (w >= 0 && w < scr->workspace_count && 
!(IS_OMNIPRESENT(wwin))) {
+               if (w >= 0 && w < wks_info.workspace_count && 
!(IS_OMNIPRESENT(wwin))) {
                        workspace = w;
                } else {
                        if (wPreferences.open_transients_with_parent && 
transientOwner)
@@ -1866,7 +1867,7 @@ void wWindowChangeWorkspace(WWindow *wwin, int workspace)
        WApplication *wapp;
        int unmap = 0;
 
-       if (workspace >= scr->workspace_count || workspace < 0 || workspace == 
wwin->frame->workspace)
+       if (workspace >= wks_info.workspace_count || workspace < 0 || workspace 
== wwin->frame->workspace)
                return;
 
        if (workspace != scr->current_workspace) {
@@ -1919,17 +1920,17 @@ void wWindowChangeWorkspaceRelative(WWindow *wwin, int 
amount)
                if (w >= 0) {
                        wWindowChangeWorkspace(wwin, w);
                } else if (wPreferences.ws_cycle) {
-                       wWindowChangeWorkspace(wwin, scr->workspace_count + w);
+                       wWindowChangeWorkspace(wwin, wks_info.workspace_count + 
w);
                }
        } else if (amount > 0) {
-               if (w < scr->workspace_count) {
+               if (w < wks_info.workspace_count) {
                        wWindowChangeWorkspace(wwin, w);
                } else if (wPreferences.ws_advance) {
                        int workspace = WMIN(w, MAX_WORKSPACES - 1);
                        wWorkspaceMake(scr, workspace);
                        wWindowChangeWorkspace(wwin, workspace);
                } else if (wPreferences.ws_cycle) {
-                       wWindowChangeWorkspace(wwin, w % scr->workspace_count);
+                       wWindowChangeWorkspace(wwin, w % 
wks_info.workspace_count);
                }
        }
 }
diff --git a/src/winmenu.c b/src/winmenu.c
index d853f30..be4603b 100644
--- a/src/winmenu.c
+++ b/src/winmenu.c
@@ -70,7 +70,7 @@
 
 /**** Global data ***/
 extern WShortKey wKeyBindings[WKBD_LAST];
-
+extern WWorkspace_info wks_info;
 
 static void updateOptionsMenu(WMenu * menu, WWindow * wwin);
 
@@ -221,7 +221,7 @@ static void updateWorkspaceMenu(WMenu * menu)
        WMenuEntry *entry;
        int i;
 
-       for (i = 0; i < scr->workspace_count; i++) {
+       for (i = 0; i < wks_info.workspace_count; i++) {
                if (i < menu->entry_no) {
 
                        entry = menu->entries[i];
diff --git a/src/winspector.c b/src/winspector.c
index 0ee08d6..0f22ad5 100644
--- a/src/winspector.c
+++ b/src/winspector.c
@@ -115,6 +115,7 @@ typedef struct InspectorPanel {
 } InspectorPanel;
 
 extern WDDomain *WDWindowAttributes;
+extern WWorkspace_info wks_info;
 
 static InspectorPanel *panelList = NULL;
 static WMPropList *ANoTitlebar = NULL;
@@ -494,7 +495,7 @@ static void saveSettings(WMButton *button, InspectorPanel 
*panel)
        }
 
        i = WMGetPopUpButtonSelectedItem(panel->wsP) - 1;
-       if (i >= 0 && i < panel->frame->screen_ptr->workspace_count) {
+       if (i >= 0 && i < wks_info.workspace_count) {
                value = 
WMCreatePLString(panel->frame->screen_ptr->workspaces[i]->name);
                different |= insertAttribute(dict, winDic, AStartWorkspace, 
value, flags);
                WMReleasePropList(value);
@@ -932,7 +933,7 @@ static void revertSettings(WMButton *button, InspectorPanel 
*panel)
 
        n = wDefaultGetStartWorkspace(wwin->screen_ptr, wm_instance, wm_class);
 
-       if (n >= 0 && n < wwin->screen_ptr->workspace_count)
+       if (n >= 0 && n < wks_info.workspace_count)
                WMSetPopUpButtonSelectedItem(panel->wsP, n + 1);
        else
                WMSetPopUpButtonSelectedItem(panel->wsP, 0);
@@ -1529,11 +1530,11 @@ static void create_tab_icon_workspace(WWindow *wwin, 
InspectorPanel *panel, int
        WMResizeWidget(panel->wsP, PWIDTH - (2 * 15) - (2 * 20), 20);
        WMAddPopUpButtonItem(panel->wsP, _("Nowhere in particular"));
 
-       for (i = 0; i < wwin->screen_ptr->workspace_count; i++)
+       for (i = 0; i < wks_info.workspace_count; i++)
                WMAddPopUpButtonItem(panel->wsP, scr->workspaces[i]->name);
 
        i = wDefaultGetStartWorkspace(wwin->screen_ptr, wwin->wm_instance, 
wwin->wm_class);
-       if (i >= 0 && i <= wwin->screen_ptr->workspace_count)
+       if (i >= 0 && i <= wks_info.workspace_count)
                WMSetPopUpButtonSelectedItem(panel->wsP, i + 1);
        else
                WMSetPopUpButtonSelectedItem(panel->wsP, 0);
diff --git a/src/wmspec.c b/src/wmspec.c
index 553ffba..79fa90e 100644
--- a/src/wmspec.c
+++ b/src/wmspec.c
@@ -50,6 +50,8 @@
 #include "xinerama.h"
 #include "properties.h"
 
+/* Global variables */
+extern WWorkspace_info wks_info;
 
 /* Root Window Properties */
 static Atom net_supported;
@@ -315,16 +317,16 @@ void wNETWMUpdateDesktop(WScreen *scr)
        long *views, sizes[2];
        int count, i;
 
-       if (scr->workspace_count == 0)
+       if (wks_info.workspace_count == 0)
                return;
 
-       count = scr->workspace_count * 2;
+       count = wks_info.workspace_count * 2;
        views = wmalloc(sizeof(long) * count);
        /*memset(views, 0, sizeof(long) * count); */
        sizes[0] = scr->scr_width;
        sizes[1] = scr->scr_height;
 
-       for (i = 0; i < scr->workspace_count; i++) {
+       for (i = 0; i < wks_info.workspace_count; i++) {
                views[2 * i + 0] = 0;
                views[2 * i + 1] = 0;
        }
@@ -736,7 +738,7 @@ static void updateWorkspaceCount(WScreen *scr)
 {                              /* changeable */
        long count;
 
-       count = scr->workspace_count;
+       count = wks_info.workspace_count;
 
        XChangeProperty(dpy, scr->root_win, net_number_of_desktops, XA_CARDINAL,
                        32, PropModeReplace, (unsigned char *)&count, 1);
@@ -759,7 +761,7 @@ static void updateWorkspaceNames(WScreen *scr)
 
        pos = buf;
        len = 0;
-       for (i = 0; i < scr->workspace_count; i++) {
+       for (i = 0; i < wks_info.workspace_count; i++) {
                curr_size = strlen(scr->workspaces[i]->name);
                strcpy(pos, scr->workspaces[i]->name);
                pos += (curr_size + 1);
@@ -1352,13 +1354,13 @@ Bool wNETWMProcessClientMessage(XClientMessageEvent 
*event)
                        long value;
 
                        value = event->data.l[0];
-                       if (value > scr->workspace_count) {
-                               wWorkspaceMake(scr, value - 
scr->workspace_count);
-                       } else if (value < scr->workspace_count) {
+                       if (value > wks_info.workspace_count) {
+                               wWorkspaceMake(scr, value - 
wks_info.workspace_count);
+                       } else if (value < wks_info.workspace_count) {
                                int i;
                                Bool rebuild = False;
 
-                               for (i = scr->workspace_count - 1; i >= value; 
i--) {
+                               for (i = wks_info.workspace_count - 1; i >= 
value; i--) {
                                        if (!wWorkspaceDelete(scr, i)) {
                                                rebuild = True;
                                                break;
diff --git a/src/workspace.c b/src/workspace.c
index ace7d3c..0b4527f 100644
--- a/src/workspace.c
+++ b/src/workspace.c
@@ -89,8 +89,8 @@ int wWorkspaceNew(WScreen *scr)
        WWorkspace *wspace, **list;
        int i;
 
-       if (scr->workspace_count < MAX_WORKSPACES) {
-               scr->workspace_count++;
+       if (wks_info.workspace_count < MAX_WORKSPACES) {
+               wks_info.workspace_count++;
 
                wspace = wmalloc(sizeof(WWorkspace));
                wspace->name = NULL;
@@ -98,15 +98,15 @@ int wWorkspaceNew(WScreen *scr)
 
                if (!wspace->name) {
                        wspace->name = wmalloc(strlen(_("Workspace %i")) + 8);
-                       sprintf(wspace->name, _("Workspace %i"), 
scr->workspace_count);
+                       sprintf(wspace->name, _("Workspace %i"), 
wks_info.workspace_count);
                }
 
                if (!wPreferences.flags.noclip)
                        wspace->clip = wDockCreate(scr, WM_CLIP, NULL);
 
-               list = wmalloc(sizeof(WWorkspace *) * scr->workspace_count);
+               list = wmalloc(sizeof(WWorkspace *) * wks_info.workspace_count);
 
-               for (i = 0; i < scr->workspace_count - 1; i++)
+               for (i = 0; i < wks_info.workspace_count - 1; i++)
                        list[i] = scr->workspaces[i];
 
                list[i] = wspace;
@@ -118,10 +118,10 @@ int wWorkspaceNew(WScreen *scr)
                wWorkspaceMenuUpdate(scr, scr->workspace_menu);
                wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
                wNETWMUpdateDesktop(scr);
-               WMPostNotificationName(WMNWorkspaceCreated, scr, (void 
*)(uintptr_t) (scr->workspace_count - 1));
+               WMPostNotificationName(WMNWorkspaceCreated, scr, (void 
*)(uintptr_t) (wks_info.workspace_count - 1));
                XFlush(dpy);
 
-               return scr->workspace_count - 1;
+               return wks_info.workspace_count - 1;
        }
 
        return -1;
@@ -149,9 +149,9 @@ Bool wWorkspaceDelete(WScreen * scr, int workspace)
                scr->workspaces[workspace]->clip = NULL;
        }
 
-       list = wmalloc(sizeof(WWorkspace *) * (scr->workspace_count - 1));
+       list = wmalloc(sizeof(WWorkspace *) * (wks_info.workspace_count - 1));
        j = 0;
-       for (i = 0; i < scr->workspace_count; i++) {
+       for (i = 0; i < wks_info.workspace_count; i++) {
                if (i != workspace) {
                        list[j++] = scr->workspaces[i];
                } else {
@@ -163,7 +163,7 @@ Bool wWorkspaceDelete(WScreen * scr, int workspace)
        wfree(scr->workspaces);
        scr->workspaces = list;
 
-       scr->workspace_count--;
+       wks_info.workspace_count--;
 
        /* update menu */
        wWorkspaceMenuUpdate(scr, scr->workspace_menu);
@@ -175,7 +175,7 @@ Bool wWorkspaceDelete(WScreen * scr, int workspace)
                WMenu *menu = scr->workspace_submenu;
 
                i = menu->entry_no;
-               while (i > scr->workspace_count)
+               while (i > wks_info.workspace_count)
                        wMenuRemoveItem(menu, --i);
                wMenuRealize(menu);
        }
@@ -184,16 +184,16 @@ Bool wWorkspaceDelete(WScreen * scr, int workspace)
                WMenu *menu = scr->clip_submenu;
 
                i = menu->entry_no;
-               while (i > scr->workspace_count)
+               while (i > wks_info.workspace_count)
                        wMenuRemoveItem(menu, --i);
                wMenuRealize(menu);
        }
        wNETWMUpdateDesktop(scr);
-       WMPostNotificationName(WMNWorkspaceDestroyed, scr, (void *)(uintptr_t) 
(scr->workspace_count - 1));
+       WMPostNotificationName(WMNWorkspaceDestroyed, scr, (void *)(uintptr_t) 
(wks_info.workspace_count - 1));
 
-       if (scr->current_workspace >= scr->workspace_count)
-               wWorkspaceChange(scr, scr->workspace_count - 1);
-       if (scr->last_workspace >= scr->workspace_count)
+       if (scr->current_workspace >= wks_info.workspace_count)
+               wWorkspaceChange(scr, wks_info.workspace_count - 1);
+       if (scr->last_workspace >= wks_info.workspace_count)
                scr->last_workspace = 0;
 
        return True;
@@ -260,9 +260,8 @@ static void showWorkspaceName(WScreen * scr, int workspace)
        int xx, yy;
 #endif
 
-       if (wPreferences.workspace_name_display_position == WD_NONE || 
scr->workspace_count < 2) {
+       if (wPreferences.workspace_name_display_position == WD_NONE || 
wks_info.workspace_count < 2)
                return;
-       }
 
        if (scr->workspace_name_timer) {
                WMDeleteTimerHandler(scr->workspace_name_timer);
@@ -452,15 +451,15 @@ void wWorkspaceRelativeChange(WScreen * scr, int amount)
                if (w >= 0) {
                        wWorkspaceChange(scr, w);
                } else if (wPreferences.ws_cycle) {
-                       wWorkspaceChange(scr, scr->workspace_count + w);
+                       wWorkspaceChange(scr, wks_info.workspace_count + w);
                }
        } else if (amount > 0) {
-               if (w < scr->workspace_count) {
+               if (w < wks_info.workspace_count) {
                        wWorkspaceChange(scr, w);
                } else if (wPreferences.ws_advance) {
                        wWorkspaceChange(scr, WMIN(w, MAX_WORKSPACES - 1));
                } else if (wPreferences.ws_cycle) {
-                       wWorkspaceChange(scr, w % scr->workspace_count);
+                       wWorkspaceChange(scr, w % wks_info.workspace_count);
                }
        }
 }
@@ -476,9 +475,8 @@ void wWorkspaceForceChange(WScreen * scr, int workspace)
 
        SendHelperMessage(scr, 'C', workspace + 1, NULL);
 
-       if (workspace > scr->workspace_count - 1) {
-               wWorkspaceMake(scr, workspace - scr->workspace_count + 1);
-       }
+       if (workspace > wks_info.workspace_count - 1)
+               wWorkspaceMake(scr, workspace - wks_info.workspace_count + 1);
 
        wClipUpdateForWorkspaceChange(scr, workspace);
 
@@ -648,9 +646,9 @@ static void lastWSCommand(WMenu * menu, WMenuEntry * entry)
        wWorkspaceChange(menu->frame->screen_ptr, 
menu->frame->screen_ptr->last_workspace);
 }
 
-static void deleteWSCommand(WMenu * menu, WMenuEntry * entry)
+static void deleteWSCommand(WMenu *menu, WMenuEntry *entry)
 {
-       wWorkspaceDelete(menu->frame->screen_ptr, 
menu->frame->screen_ptr->workspace_count - 1);
+       wWorkspaceDelete(menu->frame->screen_ptr, wks_info.workspace_count - 1);
 }
 
 static void newWSCommand(WMenu *menu, WMenuEntry *foo)
@@ -669,7 +667,7 @@ void wWorkspaceRename(WScreen *scr, int workspace, const 
char *name)
        char buf[MAX_WORKSPACENAME_WIDTH + 1];
        char *tmp;
 
-       if (workspace >= scr->workspace_count)
+       if (workspace >= wks_info.workspace_count)
                return;
 
        /* trim white spaces */
@@ -751,9 +749,9 @@ void wWorkspaceMenuUpdate(WScreen * scr, WMenu * menu)
        if (!menu)
                return;
 
-       if (menu->entry_no < scr->workspace_count + MC_WORKSPACE1) {
+       if (menu->entry_no < wks_info.workspace_count + MC_WORKSPACE1) {
                /* new workspace(s) added */
-               i = scr->workspace_count - (menu->entry_no - MC_WORKSPACE1);
+               i = wks_info.workspace_count - (menu->entry_no - MC_WORKSPACE1);
                ws = menu->entry_no - MC_WORKSPACE1;
                while (i > 0) {
                        wstrlcpy(title, scr->workspaces[ws]->name, 
MAX_WORKSPACENAME_WIDTH);
@@ -765,14 +763,13 @@ void wWorkspaceMenuUpdate(WScreen * scr, WMenu * menu)
                        i--;
                        ws++;
                }
-       } else if (menu->entry_no > scr->workspace_count + MC_WORKSPACE1) {
+       } else if (menu->entry_no > wks_info.workspace_count + MC_WORKSPACE1) {
                /* removed workspace(s) */
-               for (i = menu->entry_no - 1; i >= scr->workspace_count + 
MC_WORKSPACE1; i--) {
+               for (i = menu->entry_no - 1; i >= wks_info.workspace_count + 
MC_WORKSPACE1; i--)
                        wMenuRemoveItem(menu, i);
-               }
        }
 
-       for (i = 0; i < scr->workspace_count; i++) {
+       for (i = 0; i < wks_info.workspace_count; i++) {
                /* workspace shortcut labels */
                if (i / 10 == scr->current_workspace / 10)
                        menu->entries[i + MC_WORKSPACE1]->rtext = 
GetShortcutKey(wKeyBindings[WKBD_WORKSPACE1 + (i % 10)]);
@@ -785,14 +782,13 @@ void wWorkspaceMenuUpdate(WScreen * scr, WMenu * menu)
        wMenuRealize(menu);
 
        /* don't let user destroy current workspace */
-       if (scr->current_workspace == scr->workspace_count - 1) {
+       if (scr->current_workspace == wks_info.workspace_count - 1)
                wMenuSetEnabled(menu, MC_DESTROY_LAST, False);
-       } else {
+       else
                wMenuSetEnabled(menu, MC_DESTROY_LAST, True);
-       }
 
        /* back to last workspace */
-       if (scr->workspace_count && scr->last_workspace != 
scr->current_workspace)
+       if (wks_info.workspace_count && scr->last_workspace != 
scr->current_workspace)
                wMenuSetEnabled(menu, MC_LAST_USED, True);
        else
                wMenuSetEnabled(menu, MC_LAST_USED, False);
@@ -814,7 +810,7 @@ void wWorkspaceSaveState(WScreen * scr, WMPropList * 
old_state)
 
        old_wks_state = WMGetFromPLDictionary(old_state, dWorkspaces);
        parr = WMCreatePLArray(NULL);
-       for (i = 0; i < scr->workspace_count; i++) {
+       for (i = 0; i < wks_info.workspace_count; i++) {
                pstr = WMCreatePLString(scr->workspaces[i]->name);
                wks_state = WMCreatePLDictionary(dName, pstr, NULL);
                WMReleasePropList(pstr);
@@ -858,7 +854,7 @@ void wWorkspaceRestoreState(WScreen *scr)
                else
                        pstr = wks_state;
 
-               if (i >= scr->workspace_count)
+               if (i >= wks_info.workspace_count)
                        wWorkspaceNew(scr);
 
                if (scr->workspace_menu) {
@@ -926,7 +922,7 @@ int wGetWorkspaceNumber(WScreen *scr, const char *value)
 
        if (sscanf(value, "%i", &w) != 1) {
                w = -1;
-               for (i = 0; i < scr->workspace_count; i++) {
+               for (i = 0; i < wks_info.workspace_count; i++) {
                        if (strcmp(scr->workspaces[i]->name, value) == 0) {
                                w = i;
                                break;
diff --git a/src/workspace.h b/src/workspace.h
index 68cd275..48d05e9 100644
--- a/src/workspace.h
+++ b/src/workspace.h
@@ -30,6 +30,7 @@ typedef struct WWorkspace {
 
 typedef struct WWorkspace_info {
        /* Workspace stuff */
+       int workspace_count;            /* number of workspaces */
        WMFont *workspace_name_font;
 } WWorkspace_info;
 
-- 
1.8.4.rc3


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to