From c61e5bfeb8a036191e1a2517b694d05b7c871900 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Wed, 6 Jun 2012 07:50:05 +0200 Subject: [PATCH] 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() --- src/wdefaults.c | 88 +++++++++++++++++++++++++++------------------------------ 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/src/wdefaults.c b/src/wdefaults.c index e627dd45..8d1ef543 100644 --- a/src/wdefaults.c +++ b/src/wdefaults.c @@ -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; + dw = dc = dn = da = NULL; - buffer = wmalloc(strlen(class) + strlen(instance) + 2); - sprintf(buffer, "%s.%s", instance, class); - key1 = WMCreatePLString(buffer); + if (!ANoTitlebar) + init_wdefaults(scr); + + if (class && instance) { + buffer = StrConcatDot(instance, class); + dw = get_value_from_instanceclass(buffer); wfree(buffer); - } else { - key1 = NULL; } - if (instance) - key2 = WMCreatePLString(instance); - else - key2 = NULL; - - if (class) - key3 = WMCreatePLString(class); - else - key3 = NULL; - - if (!ANoTitlebar) - init_wdefaults(scr); + 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) { -- 2.11.4.GIT