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"
45 #define APPLY_VAL(value, flag, attrib) \
46 if (value) {attr->flag = getBool(attrib, value); \
47 if (mask) mask->flag = 1;}
50 extern WPreferences wPreferences
;
51 extern WDDomain
*WDWindowAttributes
;
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
;
87 static WMPropList
*AStartWorkspace
;
88 static WMPropList
*AIcon
;
89 static WMPropList
*AnyWindow
;
90 static WMPropList
*No
;
92 static void init_wdefaults(WScreen
* scr
)
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");
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
)
140 value
= WMGetFromPLDictionary(dict_win
, option
);
146 value
= WMGetFromPLDictionary(dict_name
, option
);
152 value
= WMGetFromPLDictionary(dict_class
, option
);
157 if (!useGlobalDefault
)
161 value
= WMGetFromPLDictionary(dict_any
, option
);
166 return default_value
;
169 static WMPropList
*get_value_from_instanceclass(char *value
)
171 WMPropList
*key
, *val
= NULL
;
176 key
= WMCreatePLString(value
);
178 WMPLSetCaseSensitive(True
);
180 if (WDWindowAttributes
->dictionary
)
181 val
= key
? WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
) : NULL
;
184 WMReleasePropList(key
);
186 WMPLSetCaseSensitive(False
);
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 *----------------------------------------------------------------------
203 wDefaultFillAttributes(WScreen
* scr
, char *instance
, char *class,
204 WWindowAttributes
* attr
, WWindowAttributes
* mask
, Bool useGlobalDefault
)
206 WMPropList
*value
, *dw
, *dc
, *dn
, *da
;
209 dw
= dc
= dn
= da
= NULL
;
214 if (class && instance
) {
215 buffer
= StrConcatDot(instance
, class);
216 dw
= get_value_from_instanceclass(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
);
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
);
313 WMPLSetCaseSensitive(False
);
316 static WMPropList
*get_generic_value(char *instance
, char *class,
317 WMPropList
*option
, Bool noDefault
)
319 WMPropList
*value
, *key
, *dict
;
323 WMPLSetCaseSensitive(True
);
325 /* Search the icon name using class and instance */
326 if (class && instance
) {
329 buffer
= wmalloc(strlen(class) + strlen(instance
) + 2);
330 sprintf(buffer
, "%s.%s", instance
, class);
331 key
= WMCreatePLString(buffer
);
334 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
335 WMReleasePropList(key
);
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
);
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
);
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
);
369 value
= WMGetFromPLDictionary(dict
, option
);
372 WMPLSetCaseSensitive(False
);
377 RImage
*wDefaultGetImage(WScreen
* scr
, char *winstance
, char *wclass
, int max_size
)
383 /* Get the file name of the image, using instance and class */
384 file_name
= wDefaultGetIconFile(scr
, winstance
, wclass
, False
);
388 /* Search the file image in the icon paths */
389 path
= FindImage(wPreferences
.icon_path
, file_name
);
392 wwarning(_("could not find icon file \"%s\""), file_name
);
396 image
= RLoadImage(scr
->rcontext
, path
, 0);
398 wwarning(_("error loading image file \"%s\": %s"), path
, RMessageForError(RErrorCode
));
402 image
= wIconValidateIconSize(scr
, image
, max_size
);
407 int wDefaultGetStartWorkspace(WScreen
* scr
, char *instance
, char *class)
416 if (!WDWindowAttributes
->dictionary
)
419 value
= get_generic_value(instance
, class, AStartWorkspace
, False
);
424 tmp
= getString(AStartWorkspace
, value
);
426 if (!tmp
|| strlen(tmp
) == 0)
429 /* Get the workspace number for the workspace name */
430 w
= wGetWorkspaceNumber(scr
, tmp
);
435 /* Get the name of the Icon File. If noDefault is False, then, default value included */
436 char *wDefaultGetIconFile(WScreen
*scr
, char *instance
, char *class, Bool noDefault
)
444 if (!WDWindowAttributes
->dictionary
)
447 value
= get_generic_value(instance
, class, AIcon
, noDefault
);
452 tmp
= getString(AIcon
, value
);
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
;
465 dict
= WMCreatePLDictionary(NULL
, NULL
);
467 db
->dictionary
= dict
;
472 WMPLSetCaseSensitive(True
);
474 if (instance
&& class) {
477 buffer
= StrConcatDot(instance
, class);
478 key
= WMCreatePLString(buffer
);
480 } else if (instance
) {
481 key
= WMCreatePLString(instance
);
483 key
= WMCreatePLString(class);
485 key
= WMRetainPropList(AnyWindow
);
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
))
500 if ((attr
= WMGetFromPLDictionary(dict
, key
)) != NULL
) {
501 if (WMIsPLDictionary(attr
)) {
502 if (icon_value
!= NULL
&& !same
)
503 WMMergePLDictionaries(attr
, icon_value
, False
);
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
);
516 WMReleasePropList(icon_value
);
518 WMPLSetCaseSensitive(False
);
521 /* --------------------------- Local ----------------------- */
523 static int getBool(WMPropList
* key
, WMPropList
* value
)
527 if (!WMIsPLString(value
)) {
528 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
529 WMGetFromPLString(key
), "Boolean");
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)) {
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)) {
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.*/
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");
561 return WMGetFromPLString(value
);