Remove unused argument from wDefaultFillAttributes()
[wmaker-crm.git] / src / wdefaults.c
bloba34d86ecafc6ab596593be959e5191c63d7525c8
1 /* wdefaults.c - window specific defaults
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "wconfig.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <string.h>
28 #include <strings.h>
29 #include <ctype.h>
31 #include <X11/Xlib.h>
32 #include <X11/Xutil.h>
33 #include <X11/keysym.h>
35 #include <wraster.h>
37 #include "WindowMaker.h"
38 #include "window.h"
39 #include "screen.h"
40 #include "funcs.h"
41 #include "workspace.h"
42 #include "defaults.h"
43 #include "icon.h"
45 #define APPLY_VAL(value, flag, attrib) \
46 if (value) {attr->flag = getBool(attrib, value); \
47 if (mask) mask->flag = 1;}
49 /* Global stuff */
50 extern WPreferences wPreferences;
51 extern WDDomain *WDWindowAttributes;
53 /* Local stuff */
55 /* type converters */
56 static int getBool(WMPropList *, WMPropList *);
57 static char *getString(WMPropList *, WMPropList *);
58 static WMPropList *ANoTitlebar = NULL;
59 static WMPropList *ANoResizebar;
60 static WMPropList *ANoMiniaturizeButton;
61 static WMPropList *ANoMiniaturizable;
62 static WMPropList *ANoCloseButton;
63 static WMPropList *ANoBorder;
64 static WMPropList *ANoHideOthers;
65 static WMPropList *ANoMouseBindings;
66 static WMPropList *ANoKeyBindings;
67 static WMPropList *ANoAppIcon; /* app */
68 static WMPropList *AKeepOnTop;
69 static WMPropList *AKeepOnBottom;
70 static WMPropList *AOmnipresent;
71 static WMPropList *ASkipWindowList;
72 static WMPropList *ASkipSwitchPanel;
73 static WMPropList *AKeepInsideScreen;
74 static WMPropList *AUnfocusable;
75 static WMPropList *AAlwaysUserIcon;
76 static WMPropList *AStartMiniaturized;
77 static WMPropList *AStartMaximized;
78 static WMPropList *AStartHidden; /* app */
79 static WMPropList *ADontSaveSession; /* app */
80 static WMPropList *AEmulateAppIcon;
81 static WMPropList *AFocusAcrossWorkspace;
82 static WMPropList *AFullMaximize;
83 static WMPropList *ASharedAppIcon; /* app */
84 #ifdef XKB_BUTTON_HINT
85 static WMPropList *ANoLanguageButton;
86 #endif
87 static WMPropList *AStartWorkspace;
88 static WMPropList *AIcon;
89 static WMPropList *AnyWindow;
90 static WMPropList *No;
92 static void init_wdefaults(void)
94 AIcon = WMCreatePLString("Icon");
96 ANoTitlebar = WMCreatePLString("NoTitlebar");
97 ANoResizebar = WMCreatePLString("NoResizebar");
98 ANoMiniaturizeButton = WMCreatePLString("NoMiniaturizeButton");
99 ANoMiniaturizable = WMCreatePLString("NoMiniaturizable");
100 ANoCloseButton = WMCreatePLString("NoCloseButton");
101 ANoBorder = WMCreatePLString("NoBorder");
102 ANoHideOthers = WMCreatePLString("NoHideOthers");
103 ANoMouseBindings = WMCreatePLString("NoMouseBindings");
104 ANoKeyBindings = WMCreatePLString("NoKeyBindings");
105 ANoAppIcon = WMCreatePLString("NoAppIcon");
106 AKeepOnTop = WMCreatePLString("KeepOnTop");
107 AKeepOnBottom = WMCreatePLString("KeepOnBottom");
108 AOmnipresent = WMCreatePLString("Omnipresent");
109 ASkipWindowList = WMCreatePLString("SkipWindowList");
110 ASkipSwitchPanel = WMCreatePLString("SkipSwitchPanel");
111 AKeepInsideScreen = WMCreatePLString("KeepInsideScreen");
112 AUnfocusable = WMCreatePLString("Unfocusable");
113 AAlwaysUserIcon = WMCreatePLString("AlwaysUserIcon");
114 AStartMiniaturized = WMCreatePLString("StartMiniaturized");
115 AStartHidden = WMCreatePLString("StartHidden");
116 AStartMaximized = WMCreatePLString("StartMaximized");
117 ADontSaveSession = WMCreatePLString("DontSaveSession");
118 AEmulateAppIcon = WMCreatePLString("EmulateAppIcon");
119 AFocusAcrossWorkspace = WMCreatePLString("FocusAcrossWorkspace");
120 AFullMaximize = WMCreatePLString("FullMaximize");
121 ASharedAppIcon = WMCreatePLString("SharedAppIcon");
122 #ifdef XKB_BUTTON_HINT
123 ANoLanguageButton = WMCreatePLString("NoLanguageButton");
124 #endif
126 AStartWorkspace = WMCreatePLString("StartWorkspace");
128 AnyWindow = WMCreatePLString("*");
129 No = WMCreatePLString("No");
132 /* Returns the correct WMPropList, using instance+class or instance, or class, or default */
133 static WMPropList *get_value(WMPropList * dict_win, WMPropList * dict_class, WMPropList * dict_name,
134 WMPropList * dict_any, WMPropList * option, WMPropList * default_value,
135 Bool useGlobalDefault)
137 WMPropList *value;
139 if (dict_win) {
140 value = WMGetFromPLDictionary(dict_win, option);
141 if (value)
142 return value;
145 if (dict_name) {
146 value = WMGetFromPLDictionary(dict_name, option);
147 if (value)
148 return value;
151 if (dict_class) {
152 value = WMGetFromPLDictionary(dict_class, option);
153 if (value)
154 return value;
157 if (!useGlobalDefault)
158 return NULL;
160 if (dict_any) {
161 value = WMGetFromPLDictionary(dict_any, option);
162 if (value)
163 return value;
166 return default_value;
169 static WMPropList *get_value_from_instanceclass(char *value)
171 WMPropList *key, *val = NULL;
173 if (!value)
174 return NULL;
176 key = WMCreatePLString(value);
178 WMPLSetCaseSensitive(True);
180 if (WDWindowAttributes->dictionary)
181 val = key ? WMGetFromPLDictionary(WDWindowAttributes->dictionary, key) : NULL;
183 if (key)
184 WMReleasePropList(key);
186 WMPLSetCaseSensitive(False);
188 return val;
192 *----------------------------------------------------------------------
193 * wDefaultFillAttributes--
194 * Retrieves attributes for the specified instance/class and
195 * fills attr with it. Values that are actually defined are also
196 * set in mask. If useGlobalDefault is True, the default for
197 * all windows ("*") will be used for when no values are found
198 * for that instance/class.
200 *----------------------------------------------------------------------
202 void wDefaultFillAttributes(char *instance, char *class,
203 WWindowAttributes *attr, WWindowAttributes *mask,
204 Bool useGlobalDefault)
206 WMPropList *value, *dw, *dc, *dn, *da;
207 char *buffer;
209 dw = dc = dn = da = NULL;
211 if (!ANoTitlebar)
212 init_wdefaults();
214 if (class && instance) {
215 buffer = StrConcatDot(instance, class);
216 dw = get_value_from_instanceclass(buffer);
217 wfree(buffer);
220 dn = get_value_from_instanceclass(instance);
221 dc = get_value_from_instanceclass(class);
223 WMPLSetCaseSensitive(True);
225 if ((WDWindowAttributes->dictionary) && (useGlobalDefault))
226 da = WMGetFromPLDictionary(WDWindowAttributes->dictionary, AnyWindow);
228 /* get the data */
229 value = get_value(dw, dc, dn, da, ANoTitlebar, No, useGlobalDefault);
230 APPLY_VAL(value, no_titlebar, ANoTitlebar);
232 value = get_value(dw, dc, dn, da, ANoResizebar, No, useGlobalDefault);
233 APPLY_VAL(value, no_resizebar, ANoResizebar);
235 value = get_value(dw, dc, dn, da, ANoMiniaturizeButton, No, useGlobalDefault);
236 APPLY_VAL(value, no_miniaturize_button, ANoMiniaturizeButton);
238 value = get_value(dw, dc, dn, da, ANoMiniaturizable, No, useGlobalDefault);
239 APPLY_VAL(value, no_miniaturizable, ANoMiniaturizable);
241 value = get_value(dw, dc, dn, da, ANoCloseButton, No, useGlobalDefault);
242 APPLY_VAL(value, no_close_button, ANoCloseButton);
244 value = get_value(dw, dc, dn, da, ANoBorder, No, useGlobalDefault);
245 APPLY_VAL(value, no_border, ANoBorder);
247 value = get_value(dw, dc, dn, da, ANoHideOthers, No, useGlobalDefault);
248 APPLY_VAL(value, no_hide_others, ANoHideOthers);
250 value = get_value(dw, dc, dn, da, ANoMouseBindings, No, useGlobalDefault);
251 APPLY_VAL(value, no_bind_mouse, ANoMouseBindings);
253 value = get_value(dw, dc, dn, da, ANoKeyBindings, No, useGlobalDefault);
254 APPLY_VAL(value, no_bind_keys, ANoKeyBindings);
256 value = get_value(dw, dc, dn, da, ANoAppIcon, No, useGlobalDefault);
257 APPLY_VAL(value, no_appicon, ANoAppIcon);
259 value = get_value(dw, dc, dn, da, ASharedAppIcon, No, useGlobalDefault);
260 APPLY_VAL(value, shared_appicon, ASharedAppIcon);
262 value = get_value(dw, dc, dn, da, AKeepOnTop, No, useGlobalDefault);
263 APPLY_VAL(value, floating, AKeepOnTop);
265 value = get_value(dw, dc, dn, da, AKeepOnBottom, No, useGlobalDefault);
266 APPLY_VAL(value, sunken, AKeepOnBottom);
268 value = get_value(dw, dc, dn, da, AOmnipresent, No, useGlobalDefault);
269 APPLY_VAL(value, omnipresent, AOmnipresent);
271 value = get_value(dw, dc, dn, da, ASkipWindowList, No, useGlobalDefault);
272 APPLY_VAL(value, skip_window_list, ASkipWindowList);
274 value = get_value(dw, dc, dn, da, ASkipSwitchPanel, No, useGlobalDefault);
275 APPLY_VAL(value, skip_switchpanel, ASkipSwitchPanel);
277 value = get_value(dw, dc, dn, da, AKeepInsideScreen, No, useGlobalDefault);
278 APPLY_VAL(value, dont_move_off, AKeepInsideScreen);
280 value = get_value(dw, dc, dn, da, AUnfocusable, No, useGlobalDefault);
281 APPLY_VAL(value, no_focusable, AUnfocusable);
283 value = get_value(dw, dc, dn, da, AAlwaysUserIcon, No, useGlobalDefault);
284 APPLY_VAL(value, always_user_icon, AAlwaysUserIcon);
286 value = get_value(dw, dc, dn, da, AStartMiniaturized, No, useGlobalDefault);
287 APPLY_VAL(value, start_miniaturized, AStartMiniaturized);
289 value = get_value(dw, dc, dn, da, AStartHidden, No, useGlobalDefault);
290 APPLY_VAL(value, start_hidden, AStartHidden);
292 value = get_value(dw, dc, dn, da, AStartMaximized, No, useGlobalDefault);
293 APPLY_VAL(value, start_maximized, AStartMaximized);
295 value = get_value(dw, dc, dn, da, ADontSaveSession, No, useGlobalDefault);
296 APPLY_VAL(value, dont_save_session, ADontSaveSession);
298 value = get_value(dw, dc, dn, da, AEmulateAppIcon, No, useGlobalDefault);
299 APPLY_VAL(value, emulate_appicon, AEmulateAppIcon);
301 value = get_value(dw, dc, dn, da, AFocusAcrossWorkspace, No, useGlobalDefault);
302 APPLY_VAL(value, focus_across_wksp, AFocusAcrossWorkspace);
304 value = get_value(dw, dc, dn, da, AFullMaximize, No, useGlobalDefault);
305 APPLY_VAL(value, full_maximize, AFullMaximize);
307 #ifdef XKB_BUTTON_HINT
308 value = get_value(dw, dc, dn, da, ANoLanguageButton, No, useGlobalDefault);
309 APPLY_VAL(value, no_language_button, ANoLanguageButton);
310 #endif
312 /* clean up */
313 WMPLSetCaseSensitive(False);
316 static WMPropList *get_generic_value(char *instance, char *class,
317 WMPropList *option, Bool noDefault)
319 WMPropList *value, *key, *dict;
321 value = NULL;
323 WMPLSetCaseSensitive(True);
325 /* Search the icon name using class and instance */
326 if (class && instance) {
327 char *buffer;
329 buffer = wmalloc(strlen(class) + strlen(instance) + 2);
330 sprintf(buffer, "%s.%s", instance, class);
331 key = WMCreatePLString(buffer);
332 wfree(buffer);
334 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
335 WMReleasePropList(key);
337 if (dict)
338 value = WMGetFromPLDictionary(dict, option);
341 /* Search the icon name using instance */
342 if (!value && instance) {
343 key = WMCreatePLString(instance);
345 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
346 WMReleasePropList(key);
348 if (dict)
349 value = WMGetFromPLDictionary(dict, option);
352 /* Search the icon name using class */
353 if (!value && class) {
354 key = WMCreatePLString(class);
356 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
357 WMReleasePropList(key);
359 if (dict)
360 value = WMGetFromPLDictionary(dict, option);
363 /* Search the default icon name - See noDefault argument! */
364 if (!value && !noDefault) {
365 /* AnyWindow is "*" - see wdefaults.c */
366 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, AnyWindow);
368 if (dict)
369 value = WMGetFromPLDictionary(dict, option);
372 WMPLSetCaseSensitive(False);
374 return value;
377 RImage *wDefaultGetImage(WScreen * scr, char *winstance, char *wclass, int max_size)
379 char *file_name;
380 char *path;
381 RImage *image;
383 /* Get the file name of the image, using instance and class */
384 file_name = wDefaultGetIconFile(winstance, wclass, False);
385 if (!file_name)
386 return NULL;
388 /* Search the file image in the icon paths */
389 path = FindImage(wPreferences.icon_path, file_name);
391 if (!path) {
392 wwarning(_("could not find icon file \"%s\""), file_name);
393 return NULL;
396 image = RLoadImage(scr->rcontext, path, 0);
397 if (!image)
398 wwarning(_("error loading image file \"%s\": %s"), path, RMessageForError(RErrorCode));
400 wfree(path);
402 image = wIconValidateIconSize(scr, image, max_size);
404 return image;
407 int wDefaultGetStartWorkspace(WScreen * scr, char *instance, char *class)
409 WMPropList *value;
410 int w;
411 char *tmp;
413 if (!ANoTitlebar)
414 init_wdefaults();
416 if (!WDWindowAttributes->dictionary)
417 return -1;
419 value = get_generic_value(instance, class, AStartWorkspace, False);
421 if (!value)
422 return -1;
424 tmp = getString(AStartWorkspace, value);
426 if (!tmp || strlen(tmp) == 0)
427 return -1;
429 /* Get the workspace number for the workspace name */
430 w = wGetWorkspaceNumber(scr, tmp);
432 return w;
435 /* Get the name of the Icon File. If noDefault is False, then, default value included */
436 char *wDefaultGetIconFile(char *instance, char *class, Bool noDefault)
438 WMPropList *value;
439 char *tmp;
441 if (!ANoTitlebar)
442 init_wdefaults();
444 if (!WDWindowAttributes->dictionary)
445 return NULL;
447 value = get_generic_value(instance, class, AIcon, noDefault);
449 if (!value)
450 return NULL;
452 tmp = getString(AIcon, value);
454 return tmp;
457 void wDefaultChangeIcon(WScreen * scr, char *instance, char *class, char *file)
459 WDDomain *db = WDWindowAttributes;
460 WMPropList *icon_value = NULL, *value, *attr, *key, *def_win, *def_icon = NULL;
461 WMPropList *dict = db->dictionary;
462 int same = 0;
464 if (!dict) {
465 dict = WMCreatePLDictionary(NULL, NULL);
466 if (dict)
467 db->dictionary = dict;
468 else
469 return;
472 WMPLSetCaseSensitive(True);
474 if (instance && class) {
475 char *buffer;
477 buffer = StrConcatDot(instance, class);
478 key = WMCreatePLString(buffer);
479 wfree(buffer);
480 } else if (instance) {
481 key = WMCreatePLString(instance);
482 } else if (class) {
483 key = WMCreatePLString(class);
484 } else {
485 key = WMRetainPropList(AnyWindow);
488 if (file) {
489 value = WMCreatePLString(file);
490 icon_value = WMCreatePLDictionary(AIcon, value, NULL);
491 WMReleasePropList(value);
493 if ((def_win = WMGetFromPLDictionary(dict, AnyWindow)) != NULL)
494 def_icon = WMGetFromPLDictionary(def_win, AIcon);
496 if (def_icon && !strcmp(WMGetFromPLString(def_icon), file))
497 same = 1;
500 if ((attr = WMGetFromPLDictionary(dict, key)) != NULL) {
501 if (WMIsPLDictionary(attr)) {
502 if (icon_value != NULL && !same)
503 WMMergePLDictionaries(attr, icon_value, False);
504 else
505 WMRemoveFromPLDictionary(attr, AIcon);
507 } else if (icon_value != NULL && !same) {
508 WMPutInPLDictionary(dict, key, icon_value);
511 if (!wPreferences.flags.noupdates)
512 UpdateDomainFile(db);
514 WMReleasePropList(key);
515 if (icon_value)
516 WMReleasePropList(icon_value);
518 WMPLSetCaseSensitive(False);
521 /* --------------------------- Local ----------------------- */
523 static int getBool(WMPropList * key, WMPropList * value)
525 char *val;
527 if (!WMIsPLString(value)) {
528 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
529 WMGetFromPLString(key), "Boolean");
530 return 0;
532 val = WMGetFromPLString(value);
534 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y' || val[0] == 'T' || val[0] == 't' || val[0] == '1'))
535 || (strcasecmp(val, "YES") == 0 || strcasecmp(val, "TRUE") == 0)) {
537 return 1;
538 } else if ((val[1] == '\0'
539 && (val[0] == 'n' || val[0] == 'N' || val[0] == 'F' || val[0] == 'f' || val[0] == '0'))
540 || (strcasecmp(val, "NO") == 0 || strcasecmp(val, "FALSE") == 0)) {
542 return 0;
543 } else {
544 wwarning(_("can't convert \"%s\" to boolean"), val);
545 /* We return False if we can't convert to BOOLEAN.
546 * This is because all options defaults to False.
547 * -1 is not checked and thus is interpreted as True,
548 * which is not good.*/
549 return 0;
553 /* WARNING: Do not free the value returned by this function!! */
554 static char *getString(WMPropList * key, WMPropList * value)
556 if (!WMIsPLString(value)) {
557 wwarning(_("Wrong option format for key \"%s\". Should be %s."), WMGetFromPLString(key), "String");
558 return NULL;
561 return WMGetFromPLString(value);