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.
32 #include <X11/Xutil.h>
33 #include <X11/keysym.h>
37 #include "WindowMaker.h"
41 #include "workspace.h"
46 extern WPreferences wPreferences
;
47 extern WDDomain
*WDWindowAttributes
;
52 static int getBool(WMPropList
*, WMPropList
*);
53 static char *getString(WMPropList
*, WMPropList
*);
54 static WMPropList
*ANoTitlebar
= NULL
;
55 static WMPropList
*ANoResizebar
;
56 static WMPropList
*ANoMiniaturizeButton
;
57 static WMPropList
*ANoMiniaturizable
;
58 static WMPropList
*ANoCloseButton
;
59 static WMPropList
*ANoBorder
;
60 static WMPropList
*ANoHideOthers
;
61 static WMPropList
*ANoMouseBindings
;
62 static WMPropList
*ANoKeyBindings
;
63 static WMPropList
*ANoAppIcon
; /* app */
64 static WMPropList
*AKeepOnTop
;
65 static WMPropList
*AKeepOnBottom
;
66 static WMPropList
*AOmnipresent
;
67 static WMPropList
*ASkipWindowList
;
68 static WMPropList
*ASkipSwitchPanel
;
69 static WMPropList
*AKeepInsideScreen
;
70 static WMPropList
*AUnfocusable
;
71 static WMPropList
*AAlwaysUserIcon
;
72 static WMPropList
*AStartMiniaturized
;
73 static WMPropList
*AStartMaximized
;
74 static WMPropList
*AStartHidden
; /* app */
75 static WMPropList
*ADontSaveSession
; /* app */
76 static WMPropList
*AEmulateAppIcon
;
77 static WMPropList
*AFocusAcrossWorkspace
;
78 static WMPropList
*AFullMaximize
;
79 static WMPropList
*ASharedAppIcon
; /* app */
80 #ifdef XKB_BUTTON_HINT
81 static WMPropList
*ANoLanguageButton
;
83 static WMPropList
*AStartWorkspace
;
84 static WMPropList
*AIcon
;
85 static WMPropList
*AnyWindow
;
86 static WMPropList
*No
;
88 static void init_wdefaults(WScreen
* scr
)
90 AIcon
= WMCreatePLString("Icon");
92 ANoTitlebar
= WMCreatePLString("NoTitlebar");
93 ANoResizebar
= WMCreatePLString("NoResizebar");
94 ANoMiniaturizeButton
= WMCreatePLString("NoMiniaturizeButton");
95 ANoMiniaturizable
= WMCreatePLString("NoMiniaturizable");
96 ANoCloseButton
= WMCreatePLString("NoCloseButton");
97 ANoBorder
= WMCreatePLString("NoBorder");
98 ANoHideOthers
= WMCreatePLString("NoHideOthers");
99 ANoMouseBindings
= WMCreatePLString("NoMouseBindings");
100 ANoKeyBindings
= WMCreatePLString("NoKeyBindings");
101 ANoAppIcon
= WMCreatePLString("NoAppIcon");
102 AKeepOnTop
= WMCreatePLString("KeepOnTop");
103 AKeepOnBottom
= WMCreatePLString("KeepOnBottom");
104 AOmnipresent
= WMCreatePLString("Omnipresent");
105 ASkipWindowList
= WMCreatePLString("SkipWindowList");
106 ASkipSwitchPanel
= WMCreatePLString("SkipSwitchPanel");
107 AKeepInsideScreen
= WMCreatePLString("KeepInsideScreen");
108 AUnfocusable
= WMCreatePLString("Unfocusable");
109 AAlwaysUserIcon
= WMCreatePLString("AlwaysUserIcon");
110 AStartMiniaturized
= WMCreatePLString("StartMiniaturized");
111 AStartHidden
= WMCreatePLString("StartHidden");
112 AStartMaximized
= WMCreatePLString("StartMaximized");
113 ADontSaveSession
= WMCreatePLString("DontSaveSession");
114 AEmulateAppIcon
= WMCreatePLString("EmulateAppIcon");
115 AFocusAcrossWorkspace
= WMCreatePLString("FocusAcrossWorkspace");
116 AFullMaximize
= WMCreatePLString("FullMaximize");
117 ASharedAppIcon
= WMCreatePLString("SharedAppIcon");
118 #ifdef XKB_BUTTON_HINT
119 ANoLanguageButton
= WMCreatePLString("NoLanguageButton");
122 AStartWorkspace
= WMCreatePLString("StartWorkspace");
124 AnyWindow
= WMCreatePLString("*");
125 No
= WMCreatePLString("No");
128 static WMPropList
*get_value(WMPropList
* dict_win
, WMPropList
* dict_class
, WMPropList
* dict_name
,
129 WMPropList
* dict_any
, WMPropList
* option
, WMPropList
* default_value
,
130 Bool useGlobalDefault
)
135 value
= WMGetFromPLDictionary(dict_win
, option
);
141 value
= WMGetFromPLDictionary(dict_name
, option
);
147 value
= WMGetFromPLDictionary(dict_class
, option
);
152 if (!useGlobalDefault
)
156 value
= WMGetFromPLDictionary(dict_any
, option
);
161 return default_value
;
165 *----------------------------------------------------------------------
166 * wDefaultFillAttributes--
167 * Retrieves attributes for the specified instance/class and
168 * fills attr with it. Values that are actually defined are also
169 * set in mask. If useGlobalDefault is True, the default for
170 * all windows ("*") will be used for when no values are found
171 * for that instance/class.
173 *----------------------------------------------------------------------
176 wDefaultFillAttributes(WScreen
* scr
, char *instance
, char *class,
177 WWindowAttributes
* attr
, WWindowAttributes
* mask
, Bool useGlobalDefault
)
179 WMPropList
*value
, *key1
, *key2
, *key3
, *dw
, *dc
, *dn
, *da
;
181 if (class && instance
) {
184 buffer
= wmalloc(strlen(class) + strlen(instance
) + 2);
185 sprintf(buffer
, "%s.%s", instance
, class);
186 key1
= WMCreatePLString(buffer
);
193 key2
= WMCreatePLString(instance
);
198 key3
= WMCreatePLString(class);
205 WMPLSetCaseSensitive(True
);
207 if (WDWindowAttributes
->dictionary
) {
208 dw
= key1
? WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key1
) : NULL
;
209 dn
= key2
? WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key2
) : NULL
;
210 dc
= key3
? WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key3
) : NULL
;
211 if (useGlobalDefault
)
212 da
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, AnyWindow
);
222 WMReleasePropList(key1
);
224 WMReleasePropList(key2
);
226 WMReleasePropList(key3
);
228 #define APPLY_VAL(value, flag, attrib) \
229 if (value) {attr->flag = getBool(attrib, value); \
230 if (mask) mask->flag = 1;}
233 value
= get_value(dw
, dc
, dn
, da
, ANoTitlebar
, No
, useGlobalDefault
);
234 APPLY_VAL(value
, no_titlebar
, ANoTitlebar
);
236 value
= get_value(dw
, dc
, dn
, da
, ANoResizebar
, No
, useGlobalDefault
);
237 APPLY_VAL(value
, no_resizebar
, ANoResizebar
);
239 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizeButton
, No
, useGlobalDefault
);
240 APPLY_VAL(value
, no_miniaturize_button
, ANoMiniaturizeButton
);
242 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizable
, No
, useGlobalDefault
);
243 APPLY_VAL(value
, no_miniaturizable
, ANoMiniaturizable
);
245 value
= get_value(dw
, dc
, dn
, da
, ANoCloseButton
, No
, useGlobalDefault
);
246 APPLY_VAL(value
, no_close_button
, ANoCloseButton
);
248 value
= get_value(dw
, dc
, dn
, da
, ANoBorder
, No
, useGlobalDefault
);
249 APPLY_VAL(value
, no_border
, ANoBorder
);
251 value
= get_value(dw
, dc
, dn
, da
, ANoHideOthers
, No
, useGlobalDefault
);
252 APPLY_VAL(value
, no_hide_others
, ANoHideOthers
);
254 value
= get_value(dw
, dc
, dn
, da
, ANoMouseBindings
, No
, useGlobalDefault
);
255 APPLY_VAL(value
, no_bind_mouse
, ANoMouseBindings
);
257 value
= get_value(dw
, dc
, dn
, da
, ANoKeyBindings
, No
, useGlobalDefault
);
258 APPLY_VAL(value
, no_bind_keys
, ANoKeyBindings
);
260 value
= get_value(dw
, dc
, dn
, da
, ANoAppIcon
, No
, useGlobalDefault
);
261 APPLY_VAL(value
, no_appicon
, ANoAppIcon
);
263 value
= get_value(dw
, dc
, dn
, da
, ASharedAppIcon
, No
, useGlobalDefault
);
264 APPLY_VAL(value
, shared_appicon
, ASharedAppIcon
);
266 value
= get_value(dw
, dc
, dn
, da
, AKeepOnTop
, No
, useGlobalDefault
);
267 APPLY_VAL(value
, floating
, AKeepOnTop
);
269 value
= get_value(dw
, dc
, dn
, da
, AKeepOnBottom
, No
, useGlobalDefault
);
270 APPLY_VAL(value
, sunken
, AKeepOnBottom
);
272 value
= get_value(dw
, dc
, dn
, da
, AOmnipresent
, No
, useGlobalDefault
);
273 APPLY_VAL(value
, omnipresent
, AOmnipresent
);
275 value
= get_value(dw
, dc
, dn
, da
, ASkipWindowList
, No
, useGlobalDefault
);
276 APPLY_VAL(value
, skip_window_list
, ASkipWindowList
);
278 value
= get_value(dw
, dc
, dn
, da
, ASkipSwitchPanel
, No
, useGlobalDefault
);
279 APPLY_VAL(value
, skip_switchpanel
, ASkipSwitchPanel
);
281 value
= get_value(dw
, dc
, dn
, da
, AKeepInsideScreen
, No
, useGlobalDefault
);
282 APPLY_VAL(value
, dont_move_off
, AKeepInsideScreen
);
284 value
= get_value(dw
, dc
, dn
, da
, AUnfocusable
, No
, useGlobalDefault
);
285 APPLY_VAL(value
, no_focusable
, AUnfocusable
);
287 value
= get_value(dw
, dc
, dn
, da
, AAlwaysUserIcon
, No
, useGlobalDefault
);
288 APPLY_VAL(value
, always_user_icon
, AAlwaysUserIcon
);
290 value
= get_value(dw
, dc
, dn
, da
, AStartMiniaturized
, No
, useGlobalDefault
);
291 APPLY_VAL(value
, start_miniaturized
, AStartMiniaturized
);
293 value
= get_value(dw
, dc
, dn
, da
, AStartHidden
, No
, useGlobalDefault
);
294 APPLY_VAL(value
, start_hidden
, AStartHidden
);
296 value
= get_value(dw
, dc
, dn
, da
, AStartMaximized
, No
, useGlobalDefault
);
297 APPLY_VAL(value
, start_maximized
, AStartMaximized
);
299 value
= get_value(dw
, dc
, dn
, da
, ADontSaveSession
, No
, useGlobalDefault
);
300 APPLY_VAL(value
, dont_save_session
, ADontSaveSession
);
302 value
= get_value(dw
, dc
, dn
, da
, AEmulateAppIcon
, No
, useGlobalDefault
);
303 APPLY_VAL(value
, emulate_appicon
, AEmulateAppIcon
);
305 value
= get_value(dw
, dc
, dn
, da
, AFocusAcrossWorkspace
, No
, useGlobalDefault
);
306 APPLY_VAL(value
, focus_across_wksp
, AFocusAcrossWorkspace
);
308 value
= get_value(dw
, dc
, dn
, da
, AFullMaximize
, No
, useGlobalDefault
);
309 APPLY_VAL(value
, full_maximize
, AFullMaximize
);
311 #ifdef XKB_BUTTON_HINT
312 value
= get_value(dw
, dc
, dn
, da
, ANoLanguageButton
, No
, useGlobalDefault
);
313 APPLY_VAL(value
, no_language_button
, ANoLanguageButton
);
317 WMPLSetCaseSensitive(False
);
320 static WMPropList
*get_generic_value(WScreen
*scr
, char *instance
, char *class,
321 WMPropList
*option
, Bool noDefault
)
323 WMPropList
*value
, *key
, *dict
;
327 WMPLSetCaseSensitive(True
);
329 /* Search the icon name using class and instance */
330 if (class && instance
) {
333 buffer
= wmalloc(strlen(class) + strlen(instance
) + 2);
334 sprintf(buffer
, "%s.%s", instance
, class);
335 key
= WMCreatePLString(buffer
);
338 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
339 WMReleasePropList(key
);
342 value
= WMGetFromPLDictionary(dict
, option
);
345 /* Search the icon name using instance */
346 if (!value
&& instance
) {
347 key
= WMCreatePLString(instance
);
349 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
350 WMReleasePropList(key
);
353 value
= WMGetFromPLDictionary(dict
, option
);
356 /* Search the icon name using class */
357 if (!value
&& class) {
358 key
= WMCreatePLString(class);
360 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
361 WMReleasePropList(key
);
364 value
= WMGetFromPLDictionary(dict
, option
);
367 /* Search the default icon name - See noDefault argument! */
368 if (!value
&& !noDefault
) {
369 /* AnyWindow is "*" - see wdefaults.c */
370 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, AnyWindow
);
373 value
= WMGetFromPLDictionary(dict
, option
);
376 WMPLSetCaseSensitive(False
);
381 /* Get the name of the Icon File. If noDefault is False, then, default value included */
382 char *wDefaultGetIconFile(WScreen
* scr
, char *instance
, char *class, Bool noDefault
)
390 if (!WDWindowAttributes
->dictionary
)
393 value
= get_generic_value(scr
, instance
, class, AIcon
, noDefault
);
398 tmp
= getString(AIcon
, value
);
403 RImage
*wDefaultGetImage(WScreen
* scr
, char *winstance
, char *wclass
, int max_size
)
409 /* Get the file name of the image, using instance and class */
410 file_name
= wDefaultGetIconFile(scr
, winstance
, wclass
, False
);
414 /* Search the file image in the icon paths */
415 path
= FindImage(wPreferences
.icon_path
, file_name
);
418 wwarning(_("could not find icon file \"%s\""), file_name
);
422 image
= RLoadImage(scr
->rcontext
, path
, 0);
424 wwarning(_("error loading image file \"%s\": %s"), path
, RMessageForError(RErrorCode
));
428 image
= wIconValidateIconSize(scr
, image
, max_size
);
433 int wDefaultGetStartWorkspace(WScreen
* scr
, char *instance
, char *class)
442 if (!WDWindowAttributes
->dictionary
)
445 value
= get_generic_value(scr
, instance
, class, AStartWorkspace
, False
);
450 tmp
= getString(AStartWorkspace
, value
);
452 if (!tmp
|| strlen(tmp
) == 0)
455 /* Get the workspace number for the workspace name */
456 w
= wGetWorkspaceNumber(scr
, tmp
);
463 void wDefaultChangeIcon(WScreen
* scr
, char *instance
, char *class, char *file
)
465 WDDomain
*db
= WDWindowAttributes
;
466 WMPropList
*icon_value
= NULL
, *value
, *attr
, *key
, *def_win
, *def_icon
= NULL
;
467 WMPropList
*dict
= db
->dictionary
;
471 dict
= WMCreatePLDictionary(NULL
, NULL
);
473 db
->dictionary
= dict
;
478 WMPLSetCaseSensitive(True
);
480 if (instance
&& class) {
482 buffer
= wmalloc(strlen(instance
) + strlen(class) + 2);
483 sprintf(buffer
, "%s.%s", instance
, class);
484 key
= WMCreatePLString(buffer
);
486 } else if (instance
) {
487 key
= WMCreatePLString(instance
);
489 key
= WMCreatePLString(class);
491 key
= WMRetainPropList(AnyWindow
);
495 value
= WMCreatePLString(file
);
496 icon_value
= WMCreatePLDictionary(AIcon
, value
, NULL
);
497 WMReleasePropList(value
);
499 if ((def_win
= WMGetFromPLDictionary(dict
, AnyWindow
)) != NULL
)
500 def_icon
= WMGetFromPLDictionary(def_win
, AIcon
);
502 if (def_icon
&& !strcmp(WMGetFromPLString(def_icon
), file
))
506 if ((attr
= WMGetFromPLDictionary(dict
, key
)) != NULL
) {
507 if (WMIsPLDictionary(attr
)) {
508 if (icon_value
!= NULL
&& !same
)
509 WMMergePLDictionaries(attr
, icon_value
, False
);
511 WMRemoveFromPLDictionary(attr
, AIcon
);
513 } else if (icon_value
!= NULL
&& !same
) {
514 WMPutInPLDictionary(dict
, key
, icon_value
);
517 if (!wPreferences
.flags
.noupdates
)
518 UpdateDomainFile(db
);
520 WMReleasePropList(key
);
522 WMReleasePropList(icon_value
);
524 WMPLSetCaseSensitive(False
);
527 /* --------------------------- Local ----------------------- */
529 static int getBool(WMPropList
* key
, WMPropList
* value
)
533 if (!WMIsPLString(value
)) {
534 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
535 WMGetFromPLString(key
), "Boolean");
538 val
= WMGetFromPLString(value
);
540 if ((val
[1] == '\0' && (val
[0] == 'y' || val
[0] == 'Y' || val
[0] == 'T' || val
[0] == 't' || val
[0] == '1'))
541 || (strcasecmp(val
, "YES") == 0 || strcasecmp(val
, "TRUE") == 0)) {
544 } else if ((val
[1] == '\0'
545 && (val
[0] == 'n' || val
[0] == 'N' || val
[0] == 'F' || val
[0] == 'f' || val
[0] == '0'))
546 || (strcasecmp(val
, "NO") == 0 || strcasecmp(val
, "FALSE") == 0)) {
550 wwarning(_("can't convert \"%s\" to boolean"), val
);
551 /* We return False if we can't convert to BOOLEAN.
552 * This is because all options defaults to False.
553 * -1 is not checked and thus is interpreted as True,
554 * which is not good.*/
559 /* WARNING: Do not free the value returned by this function!! */
560 static char *getString(WMPropList
* key
, WMPropList
* value
)
562 if (!WMIsPLString(value
)) {
563 wwarning(_("Wrong option format for key \"%s\". Should be %s."), WMGetFromPLString(key
), "String");
567 return WMGetFromPLString(value
);