1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 20:38:08 +01:00

wmaker: Created a global structure to regroup all global variables

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.
This commit is contained in:
Christophe CURIS
2013-09-29 17:09:55 +02:00
committed by Carlos R. Mafra
parent 70c6494c46
commit 3892f3220a
2 changed files with 23 additions and 12 deletions

View File

@@ -238,22 +238,22 @@ typedef enum {
} wprog_state; } wprog_state;
#define WCHECK_STATE(chk_state) (WProgramState == (chk_state)) #define WCHECK_STATE(chk_state) (w_global.program.state == (chk_state))
#define WCHANGE_STATE(nstate) {\ #define WCHANGE_STATE(nstate) {\
if (WProgramState == WSTATE_NORMAL\ if (w_global.program.state == WSTATE_NORMAL\
|| (nstate) != WSTATE_MODAL)\ || (nstate) != WSTATE_MODAL) \
WProgramState = (nstate); \ w_global.program.state = (nstate); \
if (WProgramSigState != 0)\ if (w_global.program.signal_state != 0)\
WProgramState = WProgramSigState;\ w_global.program.state = w_global.program.signal_state;\
} }
/* only call inside signal handlers, with signals blocked */ /* only call inside signal handlers, with signals blocked */
#define SIG_WCHANGE_STATE(nstate) {\ #define SIG_WCHANGE_STATE(nstate) {\
WProgramSigState = (nstate);\ w_global.program.signal_state = (nstate);\
WProgramState = (nstate);\ w_global.program.state = (nstate);\
} }
@@ -453,9 +453,17 @@ extern struct WPreferences {
/****** Global Variables ******/ /****** Global Variables ******/
extern Display *dpy; 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 unsigned int ValidModMask;
extern wprog_state WProgramState;
extern wprog_state WProgramSigState;
/****** Notifications ******/ /****** Notifications ******/
extern const char WMNManaged[]; extern const char WMNManaged[];

View File

@@ -64,6 +64,7 @@
#endif #endif
/****** Global Variables ******/ /****** Global Variables ******/
struct wmaker_global_variables w_global;
/* general info */ /* general info */
@@ -145,8 +146,6 @@ int wXkbEventBase;
#endif #endif
/* special flags */ /* special flags */
wprog_state WProgramSigState = 0;
wprog_state WProgramState = WSTATE_NORMAL;
char WDelayedActionSet = 0; char WDelayedActionSet = 0;
/* notifications */ /* notifications */
@@ -596,6 +595,10 @@ int main(int argc, char **argv)
int i_am_the_monitor, i, len; int i_am_the_monitor, i, len;
char *str, *alt; 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 */ /* setup common stuff for the monitor and wmaker itself */
WMInitializeApplication("WindowMaker", &argc, argv); WMInitializeApplication("WindowMaker", &argc, argv);