From: Christophe CURIS <[email protected]>

Having all the global variables at the same place will provide
better visibility on the code; grouping them in a structure
reduces the risk for name clash; it also offer the possibility
to organise them.

Another BIG benefit is that, when reading the code, an access to
a global variable will now be clearly visible, and distinguished
from a local variable use.
---
 src/WindowMaker.h | 26 +++++++++++++++++---------
 src/main.c        |  7 +++++--
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/WindowMaker.h b/src/WindowMaker.h
index a200c85..8456fe7 100644
--- a/src/WindowMaker.h
+++ b/src/WindowMaker.h
@@ -242,18 +242,18 @@ typedef enum {
 
 
 #define WCHANGE_STATE(nstate) {\
-    if (WProgramState == WSTATE_NORMAL\
-        || (nstate) != WSTATE_MODAL)\
-        WProgramState = (nstate); \
-    if (WProgramSigState != 0)\
-        WProgramState = WProgramSigState;\
+    if (w_global.program.state == WSTATE_NORMAL\
+        || (nstate) != WSTATE_MODAL)                     \
+        w_global.program.state = (nstate); \
+    if (w_global.program.signal_state != 0)\
+        w_global.program.state = w_global.program.signal_state;\
 }
 
 
 /* only call inside signal handlers, with signals blocked */
 #define SIG_WCHANGE_STATE(nstate) {\
-    WProgramSigState = (nstate);\
-    WProgramState = (nstate);\
+    w_global.program.signal_state = (nstate);\
+    w_global.program.state = (nstate);\
 }
 
 
@@ -453,9 +453,17 @@ extern struct WPreferences {
 
 /****** Global Variables  ******/
 extern Display *dpy;
+
+extern struct wmaker_global_variables {
+       /* Tracking of the state of the program */
+       struct {
+               wprog_state state;
+               wprog_state signal_state;
+       } program;
+
+} w_global;
+
 extern unsigned int ValidModMask;
-extern wprog_state WProgramState;
-extern wprog_state WProgramSigState;
 
 /****** Notifications ******/
 extern const char WMNManaged[];
diff --git a/src/main.c b/src/main.c
index faed4fe..b4e768f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -64,6 +64,7 @@
 #endif
 
 /****** Global Variables ******/
+struct wmaker_global_variables w_global;
 
 /* general info */
 
@@ -145,8 +146,6 @@ int wXkbEventBase;
 #endif
 
 /* special flags */
-wprog_state WProgramSigState = 0;
-wprog_state WProgramState = WSTATE_NORMAL;
 char WDelayedActionSet = 0;
 
 /* notifications */
@@ -596,6 +595,10 @@ int main(int argc, char **argv)
        int i_am_the_monitor, i, len;
        char *str, *alt;
 
+       memset(&w_global, 0, sizeof(w_global));
+       w_global.program.state = WSTATE_NORMAL;
+       w_global.program.signal_state = WSTATE_NORMAL;
+
        /* setup common stuff for the monitor and wmaker itself */
        WMInitializeApplication("WindowMaker", &argc, argv);
 
-- 
1.8.4.rc3


-- 
To unsubscribe, send mail to [email protected].

Reply via email to