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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
32 #include <X11/Xutil.h>
33 #include <X11/keysym.h>
37 #include "WindowMaker.h"
41 #include "workspace.h"
47 extern WPreferences wPreferences
;
49 extern WMPropList
*wAttributeDomainName
;
51 extern WDDomain
*WDWindowAttributes
;
56 static int getBool(WMPropList
*, WMPropList
*);
58 static char *getString(WMPropList
*, WMPropList
*);
60 static WMPropList
*ANoTitlebar
= NULL
;
61 static WMPropList
*ANoResizebar
;
62 static WMPropList
*ANoMiniaturizeButton
;
63 static WMPropList
*ANoCloseButton
;
64 static WMPropList
*ANoBorder
;
65 static WMPropList
*ANoHideOthers
;
66 static WMPropList
*ANoMouseBindings
;
67 static WMPropList
*ANoKeyBindings
;
68 static WMPropList
*ANoAppIcon
; /* app */
69 static WMPropList
*AKeepOnTop
;
70 static WMPropList
*AKeepOnBottom
;
71 static WMPropList
*AOmnipresent
;
72 static WMPropList
*ASkipWindowList
;
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
*AFullMaximize
;
82 static WMPropList
*ASharedAppIcon
; /* app */
83 #ifdef XKB_BUTTON_HINT
84 static WMPropList
*ANoLanguageButton
;
87 static WMPropList
*AStartWorkspace
;
89 static WMPropList
*AIcon
;
91 static WMPropList
*AnyWindow
;
92 static WMPropList
*No
;
94 static void init_wdefaults(WScreen
* scr
)
96 AIcon
= WMCreatePLString("Icon");
98 ANoTitlebar
= WMCreatePLString("NoTitlebar");
99 ANoResizebar
= WMCreatePLString("NoResizebar");
100 ANoMiniaturizeButton
= WMCreatePLString("NoMiniaturizeButton");
101 ANoCloseButton
= WMCreatePLString("NoCloseButton");
102 ANoBorder
= WMCreatePLString("NoBorder");
103 ANoHideOthers
= WMCreatePLString("NoHideOthers");
104 ANoMouseBindings
= WMCreatePLString("NoMouseBindings");
105 ANoKeyBindings
= WMCreatePLString("NoKeyBindings");
106 ANoAppIcon
= WMCreatePLString("NoAppIcon");
107 AKeepOnTop
= WMCreatePLString("KeepOnTop");
108 AKeepOnBottom
= WMCreatePLString("KeepOnBottom");
109 AOmnipresent
= WMCreatePLString("Omnipresent");
110 ASkipWindowList
= WMCreatePLString("SkipWindowList");
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 AFullMaximize
= WMCreatePLString("FullMaximize");
120 ASharedAppIcon
= WMCreatePLString("SharedAppIcon");
121 #ifdef XKB_BUTTON_HINT
122 ANoLanguageButton
= WMCreatePLString("NoLanguageButton");
125 AStartWorkspace
= WMCreatePLString("StartWorkspace");
127 AnyWindow
= WMCreatePLString("*");
128 No
= WMCreatePLString("No");
130 if (!scr->wattribs) {
131 scr->wattribs = PLGetDomain(wAttributeDomainName);
135 static WMPropList
*get_value(WMPropList
* dict_win
, WMPropList
* dict_class
, WMPropList
* dict_name
,
136 WMPropList
* dict_any
, WMPropList
* option
, WMPropList
* default_value
,
137 Bool useGlobalDefault
)
142 value
= WMGetFromPLDictionary(dict_win
, option
);
148 value
= WMGetFromPLDictionary(dict_name
, option
);
154 value
= WMGetFromPLDictionary(dict_class
, option
);
159 if (!useGlobalDefault
)
163 value
= WMGetFromPLDictionary(dict_any
, option
);
168 return default_value
;
172 *----------------------------------------------------------------------
173 * wDefaultFillAttributes--
174 * Retrieves attributes for the specified instance/class and
175 * fills attr with it. Values that are actually defined are also
176 * set in mask. If useGlobalDefault is True, the default for
177 * all windows ("*") will be used for when no values are found
178 * for that instance/class.
180 *----------------------------------------------------------------------
183 wDefaultFillAttributes(WScreen
* scr
, char *instance
, char *class,
184 WWindowAttributes
* attr
, WWindowAttributes
* mask
, Bool useGlobalDefault
)
186 WMPropList
*value
, *key1
, *key2
, *key3
, *dw
, *dc
, *dn
, *da
;
188 if (class && instance
) {
191 buffer
= wmalloc(strlen(class) + strlen(instance
) + 2);
192 sprintf(buffer
, "%s.%s", instance
, class);
193 key1
= WMCreatePLString(buffer
);
200 key2
= WMCreatePLString(instance
);
205 key3
= WMCreatePLString(class);
213 WMPLSetCaseSensitive(True
);
215 if (WDWindowAttributes
->dictionary
) {
216 dw
= key1
? WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key1
) : NULL
;
217 dn
= key2
? WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key2
) : NULL
;
218 dc
= key3
? WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key3
) : NULL
;
219 if (useGlobalDefault
)
220 da
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, AnyWindow
);
230 WMReleasePropList(key1
);
232 WMReleasePropList(key2
);
234 WMReleasePropList(key3
);
236 #define APPLY_VAL(value, flag, attrib) \
237 if (value) {attr->flag = getBool(attrib, value); \
238 if (mask) mask->flag = 1;}
241 value
= get_value(dw
, dc
, dn
, da
, ANoTitlebar
, No
, useGlobalDefault
);
242 APPLY_VAL(value
, no_titlebar
, ANoTitlebar
);
244 value
= get_value(dw
, dc
, dn
, da
, ANoResizebar
, No
, useGlobalDefault
);
245 APPLY_VAL(value
, no_resizebar
, ANoResizebar
);
247 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizeButton
, No
, useGlobalDefault
);
248 APPLY_VAL(value
, no_miniaturize_button
, ANoMiniaturizeButton
);
250 value
= get_value(dw
, dc
, dn
, da
, ANoCloseButton
, No
, useGlobalDefault
);
251 APPLY_VAL(value
, no_close_button
, ANoCloseButton
);
253 value
= get_value(dw
, dc
, dn
, da
, ANoBorder
, No
, useGlobalDefault
);
254 APPLY_VAL(value
, no_border
, ANoBorder
);
256 value
= get_value(dw
, dc
, dn
, da
, ANoHideOthers
, No
, useGlobalDefault
);
257 APPLY_VAL(value
, no_hide_others
, ANoHideOthers
);
259 value
= get_value(dw
, dc
, dn
, da
, ANoMouseBindings
, No
, useGlobalDefault
);
260 APPLY_VAL(value
, no_bind_mouse
, ANoMouseBindings
);
262 value
= get_value(dw
, dc
, dn
, da
, ANoKeyBindings
, No
, useGlobalDefault
);
263 APPLY_VAL(value
, no_bind_keys
, ANoKeyBindings
);
265 value
= get_value(dw
, dc
, dn
, da
, ANoAppIcon
, No
, useGlobalDefault
);
266 APPLY_VAL(value
, no_appicon
, ANoAppIcon
);
268 value
= get_value(dw
, dc
, dn
, da
, ASharedAppIcon
, No
, useGlobalDefault
);
269 APPLY_VAL(value
, shared_appicon
, ASharedAppIcon
);
271 value
= get_value(dw
, dc
, dn
, da
, AKeepOnTop
, No
, useGlobalDefault
);
272 APPLY_VAL(value
, floating
, AKeepOnTop
);
274 value
= get_value(dw
, dc
, dn
, da
, AKeepOnBottom
, No
, useGlobalDefault
);
275 APPLY_VAL(value
, sunken
, AKeepOnBottom
);
277 value
= get_value(dw
, dc
, dn
, da
, AOmnipresent
, No
, useGlobalDefault
);
278 APPLY_VAL(value
, omnipresent
, AOmnipresent
);
280 value
= get_value(dw
, dc
, dn
, da
, ASkipWindowList
, No
, useGlobalDefault
);
281 APPLY_VAL(value
, skip_window_list
, ASkipWindowList
);
283 value
= get_value(dw
, dc
, dn
, da
, AKeepInsideScreen
, No
, useGlobalDefault
);
284 APPLY_VAL(value
, dont_move_off
, AKeepInsideScreen
);
286 value
= get_value(dw
, dc
, dn
, da
, AUnfocusable
, No
, useGlobalDefault
);
287 APPLY_VAL(value
, no_focusable
, AUnfocusable
);
289 value
= get_value(dw
, dc
, dn
, da
, AAlwaysUserIcon
, No
, useGlobalDefault
);
290 APPLY_VAL(value
, always_user_icon
, AAlwaysUserIcon
);
292 value
= get_value(dw
, dc
, dn
, da
, AStartMiniaturized
, No
, useGlobalDefault
);
293 APPLY_VAL(value
, start_miniaturized
, AStartMiniaturized
);
295 value
= get_value(dw
, dc
, dn
, da
, AStartHidden
, No
, useGlobalDefault
);
296 APPLY_VAL(value
, start_hidden
, AStartHidden
);
298 value
= get_value(dw
, dc
, dn
, da
, AStartMaximized
, No
, useGlobalDefault
);
299 APPLY_VAL(value
, start_maximized
, AStartMaximized
);
301 value
= get_value(dw
, dc
, dn
, da
, ADontSaveSession
, No
, useGlobalDefault
);
302 APPLY_VAL(value
, dont_save_session
, ADontSaveSession
);
304 value
= get_value(dw
, dc
, dn
, da
, AEmulateAppIcon
, No
, useGlobalDefault
);
305 APPLY_VAL(value
, emulate_appicon
, AEmulateAppIcon
);
307 value
= get_value(dw
, dc
, dn
, da
, AFullMaximize
, No
, useGlobalDefault
);
308 APPLY_VAL(value
, full_maximize
, AFullMaximize
);
310 #ifdef XKB_BUTTON_HINT
311 value
= get_value(dw
, dc
, dn
, da
, ANoLanguageButton
, No
, useGlobalDefault
);
312 APPLY_VAL(value
, no_language_button
, ANoLanguageButton
);
316 WMPLSetCaseSensitive(False
);
319 WMPropList
*get_generic_value(WScreen
* scr
, char *instance
, char *class, WMPropList
* option
, Bool noDefault
)
321 WMPropList
*value
, *key
, *dict
;
325 WMPLSetCaseSensitive(True
);
327 if (class && instance
) {
330 buffer
= wmalloc(strlen(class) + strlen(instance
) + 2);
331 sprintf(buffer
, "%s.%s", instance
, class);
332 key
= WMCreatePLString(buffer
);
335 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
336 WMReleasePropList(key
);
339 value
= WMGetFromPLDictionary(dict
, option
);
343 if (!value
&& instance
) {
344 key
= WMCreatePLString(instance
);
346 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
347 WMReleasePropList(key
);
349 value
= WMGetFromPLDictionary(dict
, option
);
353 if (!value
&& class) {
354 key
= WMCreatePLString(class);
356 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
357 WMReleasePropList(key
);
360 value
= WMGetFromPLDictionary(dict
, option
);
364 if (!value
&& !noDefault
) {
365 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, AnyWindow
);
368 value
= WMGetFromPLDictionary(dict
, option
);
372 WMPLSetCaseSensitive(False
);
377 char *wDefaultGetIconFile(WScreen
* scr
, char *instance
, char *class, Bool noDefault
)
386 if (!WDWindowAttributes
->dictionary
)
389 value
= get_generic_value(scr
, instance
, class, AIcon
, noDefault
);
394 tmp
= getString(AIcon
, value
);
399 RImage
*wDefaultGetImage(WScreen
* scr
, char *winstance
, char *wclass
)
405 file_name
= wDefaultGetIconFile(scr
, winstance
, wclass
, False
);
409 path
= FindImage(wPreferences
.icon_path
, file_name
);
412 wwarning(_("could not find icon file \"%s\""), file_name
);
416 image
= RLoadImage(scr
->rcontext
, path
, 0);
418 wwarning(_("error loading image file \"%s\""), path
, RMessageForError(RErrorCode
));
422 image
= wIconValidateIconSize(scr
, image
);
427 int wDefaultGetStartWorkspace(WScreen
* scr
, char *instance
, char *class)
437 if (!WDWindowAttributes
->dictionary
)
440 value
= get_generic_value(scr
, instance
, class, AStartWorkspace
, False
);
445 tmp
= getString(AStartWorkspace
, value
);
447 if (!tmp
|| strlen(tmp
) == 0)
450 if (sscanf(tmp
, "%i", &w
) != 1) {
452 for (i
= 0; i
< scr
->workspace_count
; i
++) {
453 if (strcmp(scr
->workspaces
[i
]->name
, tmp
) == 0) {
465 void wDefaultChangeIcon(WScreen
* scr
, char *instance
, char *class, char *file
)
467 WDDomain
*db
= WDWindowAttributes
;
468 WMPropList
*icon_value
= NULL
, *value
, *attr
, *key
, *def_win
, *def_icon
= NULL
;
469 WMPropList
*dict
= db
->dictionary
;
473 dict
= WMCreatePLDictionary(NULL
, NULL
);
475 db
->dictionary
= dict
;
481 WMPLSetCaseSensitive(True
);
483 if (instance
&& class) {
485 buffer
= wmalloc(strlen(instance
) + strlen(class) + 2);
486 sprintf(buffer
, "%s.%s", instance
, class);
487 key
= WMCreatePLString(buffer
);
489 } else if (instance
) {
490 key
= WMCreatePLString(instance
);
492 key
= WMCreatePLString(class);
494 key
= WMRetainPropList(AnyWindow
);
498 value
= WMCreatePLString(file
);
499 icon_value
= WMCreatePLDictionary(AIcon
, value
, NULL
);
500 WMReleasePropList(value
);
502 if ((def_win
= WMGetFromPLDictionary(dict
, AnyWindow
)) != NULL
) {
503 def_icon
= WMGetFromPLDictionary(def_win
, AIcon
);
506 if (def_icon
&& !strcmp(WMGetFromPLString(def_icon
), file
))
510 if ((attr
= WMGetFromPLDictionary(dict
, key
)) != NULL
) {
511 if (WMIsPLDictionary(attr
)) {
512 if (icon_value
!= NULL
&& !same
)
513 WMMergePLDictionaries(attr
, icon_value
, False
);
515 WMRemoveFromPLDictionary(attr
, AIcon
);
517 } else if (icon_value
!= NULL
&& !same
) {
518 WMPutInPLDictionary(dict
, key
, icon_value
);
520 if (!wPreferences
.flags
.noupdates
) {
521 UpdateDomainFile(db
);
524 WMReleasePropList(key
);
526 WMReleasePropList(icon_value
);
528 WMPLSetCaseSensitive(False
);
531 /* --------------------------- Local ----------------------- */
533 static int getBool(WMPropList
* key
, WMPropList
* value
)
537 if (!WMIsPLString(value
)) {
538 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
539 WMGetFromPLString(key
), "Boolean");
542 val
= WMGetFromPLString(value
);
544 if ((val
[1] == '\0' && (val
[0] == 'y' || val
[0] == 'Y' || val
[0] == 'T' || val
[0] == 't' || val
[0] == '1'))
545 || (strcasecmp(val
, "YES") == 0 || strcasecmp(val
, "TRUE") == 0)) {
548 } else if ((val
[1] == '\0'
549 && (val
[0] == 'n' || val
[0] == 'N' || val
[0] == 'F' || val
[0] == 'f' || val
[0] == '0'))
550 || (strcasecmp(val
, "NO") == 0 || strcasecmp(val
, "FALSE") == 0)) {
554 wwarning(_("can't convert \"%s\" to boolean"), val
);
555 /* We return False if we can't convert to BOOLEAN.
556 * This is because all options defaults to False.
557 * -1 is not checked and thus is interpreted as True,
558 * which is not good.*/
563 /* WARNING: Do not free the value returned by this function!! */
564 static char *getString(WMPropList
* key
, WMPropList
* value
)
566 if (!WMIsPLString(value
)) {
567 wwarning(_("Wrong option format for key \"%s\". Should be %s."), WMGetFromPLString(key
), "String");
571 return WMGetFromPLString(value
);