1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 04:48:06 +01:00

Function wDefaultFillAttributes() rewritten

The function wDefaultFillAttributes can be changed a lot:

1. Initialitation to NULL: If the pointers are initialized to NULL
   then, the "if's" don't need the else block:

   WMPropList *value, *dw, *dc, *dn, *da;
   dw = dc = dn = da = NULL;

   if's:

   = if (instance)
   =     key2 = WMCreatePLString(instance);
   - else
   -     key2 = NULL;

2. Added StrConcatDot in the class + instance block:

   = if (class && instance) {
   +     buffer = StrConcatDot(instance, class);
   -     buffer = wmalloc(strlen(class) + strlen(instance) + 2);
   -     sprintf(buffer, "%s.%s", instance, class);

3. init_wdefaults(scr); moved above. This function is used only
   to load the default value "AnyWindow" (value "*"), to search
   the default value. Can be moved above without problems.

4. Preprocessor code of APPLY_VAL moved to the top of the file.

5. New function get_value_from_instanceclass() to do the rest of
   the (repetitive) code. This function is called to create the
   proplist, search the value, and return the proplist.

EXTRA:

1. Added StrConcatDot (like dot 2) in wDefaultChangeIcon()
2. Added a comment in get_value()
This commit is contained in:
Rodolfo García Peñas (kix)
2012-06-06 07:50:05 +02:00
committed by Carlos R. Mafra
parent 32fe186c54
commit c61e5bfeb8

View File

@@ -42,6 +42,10 @@
#include "defaults.h"
#include "icon.h"
#define APPLY_VAL(value, flag, attrib) \
if (value) {attr->flag = getBool(attrib, value); \
if (mask) mask->flag = 1;}
/* Global stuff */
extern WPreferences wPreferences;
extern WDDomain *WDWindowAttributes;
@@ -125,6 +129,7 @@ static void init_wdefaults(WScreen * scr)
No = WMCreatePLString("No");
}
/* Returns the correct WMPropList, using instance+class or instance, or class, or default */
static WMPropList *get_value(WMPropList * dict_win, WMPropList * dict_class, WMPropList * dict_name,
WMPropList * dict_any, WMPropList * option, WMPropList * default_value,
Bool useGlobalDefault)
@@ -161,6 +166,28 @@ static WMPropList *get_value(WMPropList * dict_win, WMPropList * dict_class, WMP
return default_value;
}
static WMPropList *get_value_from_instanceclass(char *value)
{
WMPropList *key, *val = NULL;
if (!value)
return NULL;
key = WMCreatePLString(value);
WMPLSetCaseSensitive(True);
if (WDWindowAttributes->dictionary)
val = key ? WMGetFromPLDictionary(WDWindowAttributes->dictionary, key) : NULL;
if (key)
WMReleasePropList(key);
WMPLSetCaseSensitive(False);
return val;
}
/*
*----------------------------------------------------------------------
* wDefaultFillAttributes--
@@ -176,58 +203,27 @@ void
wDefaultFillAttributes(WScreen * scr, char *instance, char *class,
WWindowAttributes * attr, WWindowAttributes * mask, Bool useGlobalDefault)
{
WMPropList *value, *key1, *key2, *key3, *dw, *dc, *dn, *da;
WMPropList *value, *dw, *dc, *dn, *da;
char *buffer;
if (class && instance) {
char *buffer;
buffer = wmalloc(strlen(class) + strlen(instance) + 2);
sprintf(buffer, "%s.%s", instance, class);
key1 = WMCreatePLString(buffer);
wfree(buffer);
} else {
key1 = NULL;
}
if (instance)
key2 = WMCreatePLString(instance);
else
key2 = NULL;
if (class)
key3 = WMCreatePLString(class);
else
key3 = NULL;
dw = dc = dn = da = NULL;
if (!ANoTitlebar)
init_wdefaults(scr);
if (class && instance) {
buffer = StrConcatDot(instance, class);
dw = get_value_from_instanceclass(buffer);
wfree(buffer);
}
dn = get_value_from_instanceclass(instance);
dc = get_value_from_instanceclass(class);
WMPLSetCaseSensitive(True);
if (WDWindowAttributes->dictionary) {
dw = key1 ? WMGetFromPLDictionary(WDWindowAttributes->dictionary, key1) : NULL;
dn = key2 ? WMGetFromPLDictionary(WDWindowAttributes->dictionary, key2) : NULL;
dc = key3 ? WMGetFromPLDictionary(WDWindowAttributes->dictionary, key3) : NULL;
if (useGlobalDefault)
da = WMGetFromPLDictionary(WDWindowAttributes->dictionary, AnyWindow);
else
da = NULL;
} else {
dw = NULL;
dn = NULL;
dc = NULL;
da = NULL;
}
if (key1)
WMReleasePropList(key1);
if (key2)
WMReleasePropList(key2);
if (key3)
WMReleasePropList(key3);
#define APPLY_VAL(value, flag, attrib) \
if (value) {attr->flag = getBool(attrib, value); \
if (mask) mask->flag = 1;}
if ((WDWindowAttributes->dictionary) && (useGlobalDefault))
da = WMGetFromPLDictionary(WDWindowAttributes->dictionary, AnyWindow);
/* get the data */
value = get_value(dw, dc, dn, da, ANoTitlebar, No, useGlobalDefault);
@@ -477,8 +473,8 @@ void wDefaultChangeIcon(WScreen * scr, char *instance, char *class, char *file)
if (instance && class) {
char *buffer;
buffer = wmalloc(strlen(instance) + strlen(class) + 2);
sprintf(buffer, "%s.%s", instance, class);
buffer = StrConcatDot(instance, class);
key = WMCreatePLString(buffer);
wfree(buffer);
} else if (instance) {