From: Christophe CURIS <[email protected]>
The default domains were originally defined in different global
variables in C files; This patches groups them in a single
structure placed in global namespace.
---
src/WindowMaker.h | 8 ++++++++
src/appicon.c | 7 ++-----
src/defaults.c | 51 ++++++++++++++++++++++++---------------------------
src/dialog.c | 2 --
src/main.c | 5 -----
src/rootmenu.c | 11 +++++------
src/screen.c | 7 +------
src/startup.c | 19 ++++++++-----------
src/wdefaults.c | 35 ++++++++++++++++-------------------
src/winspector.c | 4 +---
10 files changed, 65 insertions(+), 84 deletions(-)
diff --git a/src/WindowMaker.h b/src/WindowMaker.h
index 46ba189..f4fa5b8 100644
--- a/src/WindowMaker.h
+++ b/src/WindowMaker.h
@@ -481,6 +481,14 @@ extern struct wmaker_global_variables {
} timestamp;
+ /* Global Domains, for storing dictionaries */
+ struct {
+ /* Note: you must #include <defaults.h> if you want to use them
*/
+ struct WDDomain *wmaker;
+ struct WDDomain *window_attr;
+ struct WDDomain *root_menu;
+ } domain;
+
/* Screens related */
int screen_count;
diff --git a/src/appicon.c b/src/appicon.c
index 4ccd3a4..ee6aed6 100644
--- a/src/appicon.c
+++ b/src/appicon.c
@@ -60,9 +60,6 @@
* using the classname/instancename
*/
-/**** Global variables ****/
-extern WDDomain *WDWindowAttributes;
-
#define MOD_MASK wPreferences.modifier_mask
#define ICON_SIZE wPreferences.icon_size
@@ -1084,7 +1081,7 @@ Bool wHandleAppIconMove(WAppIcon *aicon, XEvent *event)
/* This function save the application icon and store the path in the
Dictionary */
static void wApplicationSaveIconPathFor(const char *iconPath, const char
*wm_instance, const char *wm_class)
{
- WMPropList *dict = WDWindowAttributes->dictionary;
+ WMPropList *dict = w_global.domain.window_attr->dictionary;
WMPropList *adict, *key, *iconk;
WMPropList *val;
char *tmp;
@@ -1118,7 +1115,7 @@ static void wApplicationSaveIconPathFor(const char
*iconPath, const char *wm_ins
WMReleasePropList(iconk);
if (val && !wPreferences.flags.noupdates)
- UpdateDomainFile(WDWindowAttributes);
+ UpdateDomainFile(w_global.domain.window_attr);
}
static WAppIcon *findDockIconFor(WDock *dock, Window main_window)
diff --git a/src/defaults.c b/src/defaults.c
index 705142d..1eaa3cf 100644
--- a/src/defaults.c
+++ b/src/defaults.c
@@ -72,9 +72,6 @@
#endif
/***** Global *****/
-extern WDDomain *WDWindowMaker;
-extern WDDomain *WDWindowAttributes;
-extern WDDomain *WDRootMenu;
extern WShortKey wKeyBindings[WKBD_LAST];
typedef struct _WDefaultEntry WDefaultEntry;
@@ -971,21 +968,21 @@ void wDefaultsCheckDomains(void* arg)
WMPropList *dict;
int i;
- if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp
< stbuf.st_mtime) {
- WDWindowMaker->timestamp = stbuf.st_mtime;
+ if (stat(w_global.domain.wmaker->path, &stbuf) >= 0 &&
w_global.domain.wmaker->timestamp < stbuf.st_mtime) {
+ w_global.domain.wmaker->timestamp = stbuf.st_mtime;
/* Global dictionary */
shared_dict = readGlobalDomain("WindowMaker", True);
/* User dictionary */
- dict = WMReadPropListFromFile(WDWindowMaker->path);
+ dict = WMReadPropListFromFile(w_global.domain.wmaker->path);
if (dict) {
if (!WMIsPLDictionary(dict)) {
WMReleasePropList(dict);
dict = NULL;
wwarning(_("Domain %s (%s) of defaults database
is corrupted!"),
- "WindowMaker", WDWindowMaker->path);
+ "WindowMaker",
w_global.domain.wmaker->path);
} else {
if (shared_dict) {
WMMergePLDictionaries(shared_dict,
dict, True);
@@ -1000,10 +997,10 @@ void wDefaultsCheckDomains(void* arg)
wReadDefaults(scr, dict);
}
- if (WDWindowMaker->dictionary)
-
WMReleasePropList(WDWindowMaker->dictionary);
+ if (w_global.domain.wmaker->dictionary)
+
WMReleasePropList(w_global.domain.wmaker->dictionary);
- WDWindowMaker->dictionary = dict;
+ w_global.domain.wmaker->dictionary = dict;
}
} else {
wwarning(_("could not load domain %s from user defaults
database"), "WindowMaker");
@@ -1014,17 +1011,17 @@ void wDefaultsCheckDomains(void* arg)
}
- if (stat(WDWindowAttributes->path, &stbuf) >= 0 &&
WDWindowAttributes->timestamp < stbuf.st_mtime) {
+ if (stat(w_global.domain.window_attr->path, &stbuf) >= 0 &&
w_global.domain.window_attr->timestamp < stbuf.st_mtime) {
/* global dictionary */
shared_dict = readGlobalDomain("WMWindowAttributes", True);
/* user dictionary */
- dict = WMReadPropListFromFile(WDWindowAttributes->path);
+ dict =
WMReadPropListFromFile(w_global.domain.window_attr->path);
if (dict) {
if (!WMIsPLDictionary(dict)) {
WMReleasePropList(dict);
dict = NULL;
wwarning(_("Domain %s (%s) of defaults database
is corrupted!"),
- "WMWindowAttributes",
WDWindowAttributes->path);
+ "WMWindowAttributes",
w_global.domain.window_attr->path);
} else {
if (shared_dict) {
WMMergePLDictionaries(shared_dict,
dict, True);
@@ -1033,10 +1030,10 @@ void wDefaultsCheckDomains(void* arg)
shared_dict = NULL;
}
- if (WDWindowAttributes->dictionary)
-
WMReleasePropList(WDWindowAttributes->dictionary);
+ if (w_global.domain.window_attr->dictionary)
+
WMReleasePropList(w_global.domain.window_attr->dictionary);
- WDWindowAttributes->dictionary = dict;
+ w_global.domain.window_attr->dictionary = dict;
for (i = 0; i < w_global.screen_count; i++) {
scr = wScreenWithNumber(i);
if (scr) {
@@ -1053,30 +1050,30 @@ void wDefaultsCheckDomains(void* arg)
wwarning(_("could not load domain %s from user defaults
database"), "WMWindowAttributes");
}
- WDWindowAttributes->timestamp = stbuf.st_mtime;
+ w_global.domain.window_attr->timestamp = stbuf.st_mtime;
if (shared_dict)
WMReleasePropList(shared_dict);
}
- if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp <
stbuf.st_mtime) {
- dict = WMReadPropListFromFile(WDRootMenu->path);
+ if (stat(w_global.domain.root_menu->path, &stbuf) >= 0 &&
w_global.domain.root_menu->timestamp < stbuf.st_mtime) {
+ dict = WMReadPropListFromFile(w_global.domain.root_menu->path);
if (dict) {
if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
WMReleasePropList(dict);
dict = NULL;
wwarning(_("Domain %s (%s) of defaults database
is corrupted!"),
- "WMRootMenu", WDRootMenu->path);
+ "WMRootMenu",
w_global.domain.root_menu->path);
} else {
- if (WDRootMenu->dictionary)
-
WMReleasePropList(WDRootMenu->dictionary);
+ if (w_global.domain.root_menu->dictionary)
+
WMReleasePropList(w_global.domain.root_menu->dictionary);
- WDRootMenu->dictionary = dict;
- wDefaultsMergeGlobalMenus(WDRootMenu);
+ w_global.domain.root_menu->dictionary = dict;
+
wDefaultsMergeGlobalMenus(w_global.domain.root_menu);
}
} else {
wwarning(_("could not load domain %s from user defaults
database"), "WMRootMenu");
}
- WDRootMenu->timestamp = stbuf.st_mtime;
+ w_global.domain.root_menu->timestamp = stbuf.st_mtime;
}
#ifndef HAVE_INOTIFY
if (!arg)
@@ -1092,7 +1089,7 @@ void wReadDefaults(WScreen * scr, WMPropList * new_dict)
int update_workspace_back = 0; /* kluge :/ */
unsigned int needs_refresh;
void *tdata;
- WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ?
WDWindowMaker->dictionary : NULL);
+ WMPropList *old_dict = (w_global.domain.wmaker->dictionary != new_dict
? w_global.domain.wmaker->dictionary : NULL);
needs_refresh = 0;
@@ -1995,7 +1992,7 @@ getWSSpecificBackground(WScreen * scr, WDefaultEntry *
entry, WMPropList * value
if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
WMPropList *key = WMCreatePLString("WorkspaceBack");
- WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
+ WMRemoveFromPLDictionary(w_global.domain.wmaker->dictionary,
key);
WMReleasePropList(key);
}
diff --git a/src/dialog.c b/src/dialog.c
index 992078a..a00de06 100644
--- a/src/dialog.c
+++ b/src/dialog.c
@@ -1454,8 +1454,6 @@ void wShowLegalPanel(WScreen * scr)
***********************************************************************
*/
-extern WDDomain *WDWindowAttributes;
-
typedef struct _CrashPanel {
WMWindow *win; /* main window */
diff --git a/src/main.c b/src/main.c
index da6d0b6..dac5fdf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -76,11 +76,6 @@ struct WPreferences wPreferences;
WShortKey wKeyBindings[WKBD_LAST];
-/* defaults domains */
-WDDomain *WDWindowMaker = NULL;
-WDDomain *WDWindowAttributes = NULL;
-WDDomain *WDRootMenu = NULL;
-
/* notifications */
const char WMNManaged[] = "WMNManaged";
const char WMNUnmanaged[] = "WMNUnmanaged";
diff --git a/src/rootmenu.c b/src/rootmenu.c
index 72ae878..10e2397 100644
--- a/src/rootmenu.c
+++ b/src/rootmenu.c
@@ -60,7 +60,6 @@
#define MAX_SHORTCUT_LENGTH 32
-extern WDDomain *WDRootMenu;
static WMenu *readMenuPipe(WScreen * scr, char **file_name);
static WMenu *readPLMenuPipe(WScreen * scr, char **file_name);
@@ -1462,7 +1461,7 @@ static WMenu *configureMenu(WScreen * scr, WMPropList *
definition, Bool include
if (!scr->root_menu || stat_buf.st_mtime >
scr->root_menu->timestamp
/* if the pointer in WMRootMenu has changed */
- || WDRootMenu->timestamp > scr->root_menu->timestamp) {
+ || w_global.domain.root_menu->timestamp >
scr->root_menu->timestamp) {
if (menu_is_default) {
wwarning(_
@@ -1472,7 +1471,7 @@ static WMenu *configureMenu(WScreen * scr, WMPropList *
definition, Bool include
menu = readMenuFile(scr, path);
if (menu)
- menu->timestamp = WMAX(stat_buf.st_mtime,
WDRootMenu->timestamp);
+ menu->timestamp = WMAX(stat_buf.st_mtime,
w_global.domain.root_menu->timestamp);
} else {
menu = NULL;
}
@@ -1617,17 +1616,17 @@ void OpenRootMenu(WScreen * scr, int x, int y, int
keyboard)
return;
}
- definition = WDRootMenu->dictionary;
+ definition = w_global.domain.root_menu->dictionary;
/*
definition = PLGetDomain(domain);
*/
if (definition) {
if (WMIsPLArray(definition)) {
- if (!scr->root_menu || WDRootMenu->timestamp >
scr->root_menu->timestamp) {
+ if (!scr->root_menu ||
w_global.domain.root_menu->timestamp > scr->root_menu->timestamp) {
menu = configureMenu(scr, definition, True);
if (menu)
- menu->timestamp = WDRootMenu->timestamp;
+ menu->timestamp =
w_global.domain.root_menu->timestamp;
} else
menu = NULL;
diff --git a/src/screen.c b/src/screen.c
index 32620af..c1fa714 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -69,11 +69,6 @@
|SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
|KeyPressMask|KeyReleaseMask)
-/**** Global variables ****/
-
-extern WDDomain *WDWindowMaker;
-
-/**** Local ****/
#define STIPPLE_WIDTH 2
#define STIPPLE_HEIGHT 2
static char STIPPLE_DATA[] = { 0x02, 0x01 };
@@ -619,7 +614,7 @@ WScreen *wScreenInit(int screen_number)
scr->info_window = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 10,
10, 0, 0, 0);
/* read defaults for this screen */
- wReadDefaults(scr, WDWindowMaker->dictionary);
+ wReadDefaults(scr, w_global.domain.wmaker->dictionary);
{
XColor xcol;
diff --git a/src/startup.c b/src/startup.c
index c6438ea..915e065 100644
--- a/src/startup.c
+++ b/src/startup.c
@@ -85,9 +85,6 @@
#endif
/****** Global Variables ******/
-extern WDDomain *WDWindowMaker;
-extern WDDomain *WDRootMenu;
-extern WDDomain *WDWindowAttributes;
extern WShortKey wKeyBindings[WKBD_LAST];
/***** Local *****/
@@ -560,13 +557,13 @@ void StartUp(Bool defaultScreenOnly)
WMHookEventHandler(DispatchEvent);
/* initialize defaults stuff */
- WDWindowMaker = wDefaultsInitDomain("WindowMaker", True);
- if (!WDWindowMaker->dictionary)
+ w_global.domain.wmaker = wDefaultsInitDomain("WindowMaker", True);
+ if (!w_global.domain.wmaker->dictionary)
wwarning(_("could not read domain \"%s\" from defaults
database"), "WindowMaker");
/* read defaults that don't change until a restart and are
* screen independent */
- wReadStaticDefaults(WDWindowMaker ? WDWindowMaker->dictionary : NULL);
+ wReadStaticDefaults(w_global.domain.wmaker ?
w_global.domain.wmaker->dictionary : NULL);
/* check sanity of some values */
if (wPreferences.icon_size < 16) {
@@ -576,14 +573,14 @@ void StartUp(Bool defaultScreenOnly)
}
/* init other domains */
- WDRootMenu = wDefaultsInitDomain("WMRootMenu", False);
- if (!WDRootMenu->dictionary)
+ w_global.domain.root_menu = wDefaultsInitDomain("WMRootMenu", False);
+ if (!w_global.domain.root_menu->dictionary)
wwarning(_("could not read domain \"%s\" from defaults
database"), "WMRootMenu");
- wDefaultsMergeGlobalMenus(WDRootMenu);
+ wDefaultsMergeGlobalMenus(w_global.domain.root_menu);
- WDWindowAttributes = wDefaultsInitDomain("WMWindowAttributes", True);
- if (!WDWindowAttributes->dictionary)
+ w_global.domain.window_attr = wDefaultsInitDomain("WMWindowAttributes",
True);
+ if (!w_global.domain.window_attr->dictionary)
wwarning(_("could not read domain \"%s\" from defaults
database"), "WMWindowAttributes");
XSetErrorHandler((XErrorHandler) catchXError);
diff --git a/src/wdefaults.c b/src/wdefaults.c
index 3378790..a181832 100644
--- a/src/wdefaults.c
+++ b/src/wdefaults.c
@@ -47,9 +47,6 @@
if (value) {attr->flag = getBool(attrib, value); \
if (mask) mask->flag = 1;}
-/* Global stuff */
-extern WDDomain *WDWindowAttributes;
-
/* Local stuff */
/* type converters */
@@ -177,8 +174,8 @@ static WMPropList *get_value_from_instanceclass(const char
*value)
WMPLSetCaseSensitive(True);
- if (WDWindowAttributes->dictionary)
- val = key ?
WMGetFromPLDictionary(WDWindowAttributes->dictionary, key) : NULL;
+ if (w_global.domain.window_attr->dictionary)
+ val = key ?
WMGetFromPLDictionary(w_global.domain.window_attr->dictionary, key) : NULL;
if (key)
WMReleasePropList(key);
@@ -222,8 +219,8 @@ void wDefaultFillAttributes(const char *instance, const
char *class,
WMPLSetCaseSensitive(True);
- if ((WDWindowAttributes->dictionary) && (useGlobalDefault))
- da = WMGetFromPLDictionary(WDWindowAttributes->dictionary,
AnyWindow);
+ if ((w_global.domain.window_attr->dictionary) && (useGlobalDefault))
+ da =
WMGetFromPLDictionary(w_global.domain.window_attr->dictionary, AnyWindow);
/* get the data */
value = get_value(dw, dc, dn, da, ANoTitlebar, No, useGlobalDefault);
@@ -331,7 +328,7 @@ static WMPropList *get_generic_value(const char *instance,
const char *class,
key = WMCreatePLString(buffer);
wfree(buffer);
- dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary,
key);
+ dict =
WMGetFromPLDictionary(w_global.domain.window_attr->dictionary, key);
WMReleasePropList(key);
if (dict)
@@ -342,7 +339,7 @@ static WMPropList *get_generic_value(const char *instance,
const char *class,
if (!value && instance) {
key = WMCreatePLString(instance);
- dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary,
key);
+ dict =
WMGetFromPLDictionary(w_global.domain.window_attr->dictionary, key);
WMReleasePropList(key);
if (dict)
@@ -353,7 +350,7 @@ static WMPropList *get_generic_value(const char *instance,
const char *class,
if (!value && class) {
key = WMCreatePLString(class);
- dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary,
key);
+ dict =
WMGetFromPLDictionary(w_global.domain.window_attr->dictionary, key);
WMReleasePropList(key);
if (dict)
@@ -363,7 +360,7 @@ static WMPropList *get_generic_value(const char *instance,
const char *class,
/* Search the default icon name - See default_icon argument! */
if (!value && default_icon) {
/* AnyWindow is "*" - see wdefaults.c */
- dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary,
AnyWindow);
+ dict =
WMGetFromPLDictionary(w_global.domain.window_attr->dictionary, AnyWindow);
if (dict)
value = WMGetFromPLDictionary(dict, option);
@@ -403,12 +400,12 @@ char *get_icon_filename(const char *winstance, const char
*wclass, const char *c
wwarning(_("icon \"%s\" doesn't exist, check your
config files"), file_name);
/* FIXME: Here, if file_path don't exists, then the icon is in
the
- * "icon database" (WDWindowAttributes->dictionary), but the
icon
+ * "icon database" (w_global.domain.window_attr->dictionary),
but the icon
* is not en disk. Therefore, we should remove it from the icon
* database. Is possible to do that using wDefaultChangeIcon()
*/
/* Don't wfree(file_name) here, because is a pointer to the icon
- * dictionary (WDWindowAttributes->dictionary) value. */
+ * dictionary (w_global.domain.window_attr->dictionary) value.
*/
}
if (!file_path && default_icon)
@@ -491,7 +488,7 @@ int wDefaultGetStartWorkspace(WScreen *scr, const char
*instance, const char *cl
if (!ANoTitlebar)
init_wdefaults();
- if (!WDWindowAttributes->dictionary)
+ if (!w_global.domain.window_attr->dictionary)
return -1;
value = get_generic_value(instance, class, AStartWorkspace, True);
@@ -519,7 +516,7 @@ char *wDefaultGetIconFile(const char *instance, const char
*class, Bool default_
if (!ANoTitlebar)
init_wdefaults();
- if (!WDWindowAttributes || !WDWindowAttributes->dictionary)
+ if (!w_global.domain.window_attr ||
!w_global.domain.window_attr->dictionary)
return NULL;
value = get_generic_value(instance, class, AIcon, default_icon);
@@ -534,7 +531,7 @@ char *wDefaultGetIconFile(const char *instance, const char
*class, Bool default_
void wDefaultChangeIcon(WScreen *scr, const char *instance, const char *class,
const char *file)
{
- WDDomain *db = WDWindowAttributes;
+ WDDomain *db = w_global.domain.window_attr;
WMPropList *icon_value = NULL, *value, *attr, *key, *def_win, *def_icon
= NULL;
WMPropList *dict = db->dictionary;
int same = 0;
@@ -611,15 +608,15 @@ void wDefaultPurgeInfo(WScreen *scr, const char
*instance, const char *class)
sprintf(buffer, "%s.%s", instance, class);
key = WMCreatePLString(buffer);
- dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
+ dict = WMGetFromPLDictionary(w_global.domain.window_attr->dictionary,
key);
if (dict) {
value = WMGetFromPLDictionary(dict, AIcon);
if (value) {
WMRemoveFromPLDictionary(dict, AIcon);
}
- WMRemoveFromPLDictionary(WDWindowAttributes->dictionary, key);
- UpdateDomainFile(WDWindowAttributes);
+
WMRemoveFromPLDictionary(w_global.domain.window_attr->dictionary, key);
+ UpdateDomainFile(w_global.domain.window_attr);
}
wfree(buffer);
diff --git a/src/winspector.c b/src/winspector.c
index 3be4434..fd2a1ba 100644
--- a/src/winspector.c
+++ b/src/winspector.c
@@ -114,8 +114,6 @@ typedef struct InspectorPanel {
unsigned int choosingIcon:1;
} InspectorPanel;
-extern WDDomain *WDWindowAttributes;
-
static InspectorPanel *panelList = NULL;
static WMPropList *ANoTitlebar = NULL;
static WMPropList *ANoResizebar;
@@ -430,7 +428,7 @@ insertAttribute(WMPropList *dict, WMPropList *window,
WMPropList *attr, WMPropLi
static void saveSettings(WMButton *button, InspectorPanel *panel)
{
WWindow *wwin = panel->inspected;
- WDDomain *db = WDWindowAttributes;
+ WDDomain *db = w_global.domain.window_attr;
WMPropList *dict = NULL;
WMPropList *winDic, *appDic, *value, *value1, *key = NULL, *key2;
char *icon_file, *buf1, *buf2;
--
1.8.4.rc3
--
To unsubscribe, send mail to [email protected].