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 #define APPLY_VAL(value, flag, attrib) \
47 if (value) {attr->flag = getBool(attrib, value); \
48 if (mask) mask->flag = 1;}
53 static int getBool(WMPropList
*, WMPropList
*);
54 static char *getString(WMPropList
*, WMPropList
*);
55 static WMPropList
*ANoTitlebar
= NULL
;
56 static WMPropList
*ANoResizebar
;
57 static WMPropList
*ANoMiniaturizeButton
;
58 static WMPropList
*ANoMiniaturizable
;
59 static WMPropList
*ANoCloseButton
;
60 static WMPropList
*ANoBorder
;
61 static WMPropList
*ANoHideOthers
;
62 static WMPropList
*ANoMouseBindings
;
63 static WMPropList
*ANoKeyBindings
;
64 static WMPropList
*ANoAppIcon
; /* app */
65 static WMPropList
*AKeepOnTop
;
66 static WMPropList
*AKeepOnBottom
;
67 static WMPropList
*AOmnipresent
;
68 static WMPropList
*ASkipWindowList
;
69 static WMPropList
*ASkipSwitchPanel
;
70 static WMPropList
*AKeepInsideScreen
;
71 static WMPropList
*AUnfocusable
;
72 static WMPropList
*AAlwaysUserIcon
;
73 static WMPropList
*AStartMiniaturized
;
74 static WMPropList
*AStartMaximized
;
75 static WMPropList
*AStartHidden
; /* app */
76 static WMPropList
*ADontSaveSession
; /* app */
77 static WMPropList
*AEmulateAppIcon
;
78 static WMPropList
*AFocusAcrossWorkspace
;
79 static WMPropList
*AFullMaximize
;
80 static WMPropList
*ASharedAppIcon
; /* app */
81 #ifdef XKB_BUTTON_HINT
82 static WMPropList
*ANoLanguageButton
;
84 static WMPropList
*AStartWorkspace
;
85 static WMPropList
*AIcon
;
86 static WMPropList
*AnyWindow
;
87 static WMPropList
*No
;
89 static void init_wdefaults(void)
91 AIcon
= WMCreatePLString("Icon");
93 ANoTitlebar
= WMCreatePLString("NoTitlebar");
94 ANoResizebar
= WMCreatePLString("NoResizebar");
95 ANoMiniaturizeButton
= WMCreatePLString("NoMiniaturizeButton");
96 ANoMiniaturizable
= WMCreatePLString("NoMiniaturizable");
97 ANoCloseButton
= WMCreatePLString("NoCloseButton");
98 ANoBorder
= WMCreatePLString("NoBorder");
99 ANoHideOthers
= WMCreatePLString("NoHideOthers");
100 ANoMouseBindings
= WMCreatePLString("NoMouseBindings");
101 ANoKeyBindings
= WMCreatePLString("NoKeyBindings");
102 ANoAppIcon
= WMCreatePLString("NoAppIcon");
103 AKeepOnTop
= WMCreatePLString("KeepOnTop");
104 AKeepOnBottom
= WMCreatePLString("KeepOnBottom");
105 AOmnipresent
= WMCreatePLString("Omnipresent");
106 ASkipWindowList
= WMCreatePLString("SkipWindowList");
107 ASkipSwitchPanel
= WMCreatePLString("SkipSwitchPanel");
108 AKeepInsideScreen
= WMCreatePLString("KeepInsideScreen");
109 AUnfocusable
= WMCreatePLString("Unfocusable");
110 AAlwaysUserIcon
= WMCreatePLString("AlwaysUserIcon");
111 AStartMiniaturized
= WMCreatePLString("StartMiniaturized");
112 AStartHidden
= WMCreatePLString("StartHidden");
113 AStartMaximized
= WMCreatePLString("StartMaximized");
114 ADontSaveSession
= WMCreatePLString("DontSaveSession");
115 AEmulateAppIcon
= WMCreatePLString("EmulateAppIcon");
116 AFocusAcrossWorkspace
= WMCreatePLString("FocusAcrossWorkspace");
117 AFullMaximize
= WMCreatePLString("FullMaximize");
118 ASharedAppIcon
= WMCreatePLString("SharedAppIcon");
119 #ifdef XKB_BUTTON_HINT
120 ANoLanguageButton
= WMCreatePLString("NoLanguageButton");
123 AStartWorkspace
= WMCreatePLString("StartWorkspace");
125 AnyWindow
= WMCreatePLString("*");
126 No
= WMCreatePLString("No");
129 /* Returns the correct WMPropList, using instance+class or instance, or class, or default */
130 static WMPropList
*get_value(WMPropList
* dict_win
, WMPropList
* dict_class
, WMPropList
* dict_name
,
131 WMPropList
* dict_any
, WMPropList
* option
, WMPropList
* default_value
,
132 Bool useGlobalDefault
)
137 value
= WMGetFromPLDictionary(dict_win
, option
);
143 value
= WMGetFromPLDictionary(dict_name
, option
);
149 value
= WMGetFromPLDictionary(dict_class
, option
);
154 if (!useGlobalDefault
)
158 value
= WMGetFromPLDictionary(dict_any
, option
);
163 return default_value
;
166 static WMPropList
*get_value_from_instanceclass(const char *value
)
168 WMPropList
*key
, *val
= NULL
;
173 key
= WMCreatePLString(value
);
175 WMPLSetCaseSensitive(True
);
177 if (w_global
.domain
.window_attr
->dictionary
)
178 val
= key
? WMGetFromPLDictionary(w_global
.domain
.window_attr
->dictionary
, key
) : NULL
;
181 WMReleasePropList(key
);
183 WMPLSetCaseSensitive(False
);
189 *----------------------------------------------------------------------
190 * wDefaultFillAttributes--
191 * Retrieves attributes for the specified instance/class and
192 * fills attr with it. Values that are actually defined are also
193 * set in mask. If useGlobalDefault is True, the default for
194 * all windows ("*") will be used for when no values are found
195 * for that instance/class.
197 *----------------------------------------------------------------------
199 void wDefaultFillAttributes(const char *instance
, const char *class,
200 WWindowAttributes
*attr
, WWindowAttributes
*mask
,
201 Bool useGlobalDefault
)
203 WMPropList
*value
, *dw
, *dc
, *dn
, *da
;
206 dw
= dc
= dn
= da
= NULL
;
211 if (class && instance
) {
212 buffer
= StrConcatDot(instance
, class);
213 dw
= get_value_from_instanceclass(buffer
);
217 dn
= get_value_from_instanceclass(instance
);
218 dc
= get_value_from_instanceclass(class);
220 WMPLSetCaseSensitive(True
);
222 if ((w_global
.domain
.window_attr
->dictionary
) && (useGlobalDefault
))
223 da
= WMGetFromPLDictionary(w_global
.domain
.window_attr
->dictionary
, AnyWindow
);
226 value
= get_value(dw
, dc
, dn
, da
, ANoTitlebar
, No
, useGlobalDefault
);
227 APPLY_VAL(value
, no_titlebar
, ANoTitlebar
);
229 value
= get_value(dw
, dc
, dn
, da
, ANoResizebar
, No
, useGlobalDefault
);
230 APPLY_VAL(value
, no_resizebar
, ANoResizebar
);
232 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizeButton
, No
, useGlobalDefault
);
233 APPLY_VAL(value
, no_miniaturize_button
, ANoMiniaturizeButton
);
235 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizable
, No
, useGlobalDefault
);
236 APPLY_VAL(value
, no_miniaturizable
, ANoMiniaturizable
);
238 value
= get_value(dw
, dc
, dn
, da
, ANoCloseButton
, No
, useGlobalDefault
);
239 APPLY_VAL(value
, no_close_button
, ANoCloseButton
);
241 value
= get_value(dw
, dc
, dn
, da
, ANoBorder
, No
, useGlobalDefault
);
242 APPLY_VAL(value
, no_border
, ANoBorder
);
244 value
= get_value(dw
, dc
, dn
, da
, ANoHideOthers
, No
, useGlobalDefault
);
245 APPLY_VAL(value
, no_hide_others
, ANoHideOthers
);
247 value
= get_value(dw
, dc
, dn
, da
, ANoMouseBindings
, No
, useGlobalDefault
);
248 APPLY_VAL(value
, no_bind_mouse
, ANoMouseBindings
);
250 value
= get_value(dw
, dc
, dn
, da
, ANoKeyBindings
, No
, useGlobalDefault
);
251 APPLY_VAL(value
, no_bind_keys
, ANoKeyBindings
);
253 value
= get_value(dw
, dc
, dn
, da
, ANoAppIcon
, No
, useGlobalDefault
);
254 APPLY_VAL(value
, no_appicon
, ANoAppIcon
);
256 value
= get_value(dw
, dc
, dn
, da
, ASharedAppIcon
, No
, useGlobalDefault
);
257 APPLY_VAL(value
, shared_appicon
, ASharedAppIcon
);
259 value
= get_value(dw
, dc
, dn
, da
, AKeepOnTop
, No
, useGlobalDefault
);
260 APPLY_VAL(value
, floating
, AKeepOnTop
);
262 value
= get_value(dw
, dc
, dn
, da
, AKeepOnBottom
, No
, useGlobalDefault
);
263 APPLY_VAL(value
, sunken
, AKeepOnBottom
);
265 value
= get_value(dw
, dc
, dn
, da
, AOmnipresent
, No
, useGlobalDefault
);
266 APPLY_VAL(value
, omnipresent
, AOmnipresent
);
268 value
= get_value(dw
, dc
, dn
, da
, ASkipWindowList
, No
, useGlobalDefault
);
269 APPLY_VAL(value
, skip_window_list
, ASkipWindowList
);
271 value
= get_value(dw
, dc
, dn
, da
, ASkipSwitchPanel
, No
, useGlobalDefault
);
272 APPLY_VAL(value
, skip_switchpanel
, ASkipSwitchPanel
);
274 value
= get_value(dw
, dc
, dn
, da
, AKeepInsideScreen
, No
, useGlobalDefault
);
275 APPLY_VAL(value
, dont_move_off
, AKeepInsideScreen
);
277 value
= get_value(dw
, dc
, dn
, da
, AUnfocusable
, No
, useGlobalDefault
);
278 APPLY_VAL(value
, no_focusable
, AUnfocusable
);
280 value
= get_value(dw
, dc
, dn
, da
, AAlwaysUserIcon
, No
, useGlobalDefault
);
281 APPLY_VAL(value
, always_user_icon
, AAlwaysUserIcon
);
283 value
= get_value(dw
, dc
, dn
, da
, AStartMiniaturized
, No
, useGlobalDefault
);
284 APPLY_VAL(value
, start_miniaturized
, AStartMiniaturized
);
286 value
= get_value(dw
, dc
, dn
, da
, AStartHidden
, No
, useGlobalDefault
);
287 APPLY_VAL(value
, start_hidden
, AStartHidden
);
289 value
= get_value(dw
, dc
, dn
, da
, AStartMaximized
, No
, useGlobalDefault
);
290 APPLY_VAL(value
, start_maximized
, AStartMaximized
);
292 value
= get_value(dw
, dc
, dn
, da
, ADontSaveSession
, No
, useGlobalDefault
);
293 APPLY_VAL(value
, dont_save_session
, ADontSaveSession
);
295 value
= get_value(dw
, dc
, dn
, da
, AEmulateAppIcon
, No
, useGlobalDefault
);
296 APPLY_VAL(value
, emulate_appicon
, AEmulateAppIcon
);
298 value
= get_value(dw
, dc
, dn
, da
, AFocusAcrossWorkspace
, No
, useGlobalDefault
);
299 APPLY_VAL(value
, focus_across_wksp
, AFocusAcrossWorkspace
);
301 value
= get_value(dw
, dc
, dn
, da
, AFullMaximize
, No
, useGlobalDefault
);
302 APPLY_VAL(value
, full_maximize
, AFullMaximize
);
304 #ifdef XKB_BUTTON_HINT
305 value
= get_value(dw
, dc
, dn
, da
, ANoLanguageButton
, No
, useGlobalDefault
);
306 APPLY_VAL(value
, no_language_button
, ANoLanguageButton
);
310 WMPLSetCaseSensitive(False
);
313 static WMPropList
*get_generic_value(const char *instance
, const char *class,
314 WMPropList
*option
, Bool default_icon
)
316 WMPropList
*value
, *key
, *dict
;
320 WMPLSetCaseSensitive(True
);
322 /* Search the icon name using class and instance */
323 if (class && instance
) {
326 buffer
= wmalloc(strlen(class) + strlen(instance
) + 2);
327 sprintf(buffer
, "%s.%s", instance
, class);
328 key
= WMCreatePLString(buffer
);
331 dict
= WMGetFromPLDictionary(w_global
.domain
.window_attr
->dictionary
, key
);
332 WMReleasePropList(key
);
335 value
= WMGetFromPLDictionary(dict
, option
);
338 /* Search the icon name using instance */
339 if (!value
&& instance
) {
340 key
= WMCreatePLString(instance
);
342 dict
= WMGetFromPLDictionary(w_global
.domain
.window_attr
->dictionary
, key
);
343 WMReleasePropList(key
);
346 value
= WMGetFromPLDictionary(dict
, option
);
349 /* Search the icon name using class */
350 if (!value
&& class) {
351 key
= WMCreatePLString(class);
353 dict
= WMGetFromPLDictionary(w_global
.domain
.window_attr
->dictionary
, key
);
354 WMReleasePropList(key
);
357 value
= WMGetFromPLDictionary(dict
, option
);
360 /* Search the default icon name - See default_icon argument! */
361 if (!value
&& default_icon
) {
362 /* AnyWindow is "*" - see wdefaults.c */
363 dict
= WMGetFromPLDictionary(w_global
.domain
.window_attr
->dictionary
, AnyWindow
);
366 value
= WMGetFromPLDictionary(dict
, option
);
369 WMPLSetCaseSensitive(False
);
374 /* Get the file name of the image, using instance and class */
375 char *get_icon_filename(const char *winstance
, const char *wclass
, const char *command
,
381 /* Get the file name of the image, using instance and class */
382 file_name
= wDefaultGetIconFile(winstance
, wclass
, default_icon
);
384 /* Check if the file really exists in the disk */
386 file_path
= FindImage(wPreferences
.icon_path
, file_name
);
390 /* If the specific icon filename is not found, and command is specified,
391 * then include the .app icons and re-do the search. */
392 if (!file_path
&& command
) {
393 wApplicationExtractDirPackIcon(command
, winstance
, wclass
);
394 file_name
= wDefaultGetIconFile(winstance
, wclass
, False
);
397 file_path
= FindImage(wPreferences
.icon_path
, file_name
);
399 wwarning(_("icon \"%s\" doesn't exist, check your config files"), file_name
);
401 /* FIXME: Here, if file_path does not exist then the icon is still in the
402 * "icon database" (w_global.domain.window_attr->dictionary), but the file
403 * for the icon is no more on disk. Therefore, we should remove it from the
404 * database. Is possible to do that using wDefaultChangeIcon() */
409 * Don't wfree(file_name) because it is a direct pointer inside the icon
410 * dictionary (w_global.domain.window_attr->dictionary) and not a result
411 * allocated with wstrdup()
414 if (!file_path
&& default_icon
)
415 file_path
= get_default_image_path();
420 /* This function returns the image picture for the file_name file */
421 RImage
*get_rimage_from_file(WScreen
*scr
, const char *file_name
, int max_size
)
423 RImage
*image
= NULL
;
428 image
= RLoadImage(scr
->rcontext
, file_name
, 0);
430 wwarning(_("error loading image file \"%s\": %s"), file_name
,
431 RMessageForError(RErrorCode
));
433 image
= wIconValidateIconSize(image
, max_size
);
438 /* This function returns the default icon's full path
439 * If the path for an icon is not found, returns NULL */
440 char *get_default_image_path(void)
442 char *path
= NULL
, *file
= NULL
;
444 /* Get the default icon */
445 file
= wDefaultGetIconFile(NULL
, NULL
, True
);
447 path
= FindImage(wPreferences
.icon_path
, file
);
452 /* This function creates the RImage using the default icon */
453 RImage
*get_default_image(WScreen
*scr
)
455 RImage
*image
= NULL
;
458 /* Get the filename full path */
459 path
= get_default_image_path();
463 /* Get the default icon */
464 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
466 wwarning(_("could not find default icon \"%s\""), path
);
468 /* Resize the icon to the wPreferences.icon_size size
469 * usually this function will return early, because size is right */
470 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
475 RImage
*get_icon_image(WScreen
*scr
, const char *winstance
, const char *wclass
, int max_size
)
477 char *file_name
= NULL
;
479 /* Get the file name of the image, using instance and class */
480 file_name
= get_icon_filename(winstance
, wclass
, NULL
, True
);
482 return get_rimage_from_file(scr
, file_name
, max_size
);
485 int wDefaultGetStartWorkspace(WScreen
*scr
, const char *instance
, const char *class)
494 if (!w_global
.domain
.window_attr
->dictionary
)
497 value
= get_generic_value(instance
, class, AStartWorkspace
, True
);
502 tmp
= getString(AStartWorkspace
, value
);
504 if (!tmp
|| strlen(tmp
) == 0)
507 /* Get the workspace number for the workspace name */
508 w
= wGetWorkspaceNumber(scr
, tmp
);
513 /* Get the name of the Icon File. If default_icon is True, then, default value included */
514 char *wDefaultGetIconFile(const char *instance
, const char *class, Bool default_icon
)
522 if (!w_global
.domain
.window_attr
|| !w_global
.domain
.window_attr
->dictionary
)
525 value
= get_generic_value(instance
, class, AIcon
, default_icon
);
530 tmp
= getString(AIcon
, value
);
535 void wDefaultChangeIcon(const char *instance
, const char *class, const char *file
)
537 WDDomain
*db
= w_global
.domain
.window_attr
;
538 WMPropList
*icon_value
= NULL
, *value
, *attr
, *key
, *def_win
, *def_icon
= NULL
;
539 WMPropList
*dict
= db
->dictionary
;
543 dict
= WMCreatePLDictionary(NULL
, NULL
);
545 db
->dictionary
= dict
;
550 WMPLSetCaseSensitive(True
);
552 if (instance
&& class) {
555 buffer
= StrConcatDot(instance
, class);
556 key
= WMCreatePLString(buffer
);
558 } else if (instance
) {
559 key
= WMCreatePLString(instance
);
561 key
= WMCreatePLString(class);
563 key
= WMRetainPropList(AnyWindow
);
567 value
= WMCreatePLString(file
);
568 icon_value
= WMCreatePLDictionary(AIcon
, value
, NULL
);
569 WMReleasePropList(value
);
571 def_win
= WMGetFromPLDictionary(dict
, AnyWindow
);
573 def_icon
= WMGetFromPLDictionary(def_win
, AIcon
);
575 if (def_icon
&& !strcmp(WMGetFromPLString(def_icon
), file
))
579 attr
= WMGetFromPLDictionary(dict
, key
);
581 if (WMIsPLDictionary(attr
)) {
582 if (icon_value
!= NULL
&& !same
)
583 WMMergePLDictionaries(attr
, icon_value
, False
);
585 WMRemoveFromPLDictionary(attr
, AIcon
);
587 } else if (icon_value
!= NULL
&& !same
) {
588 WMPutInPLDictionary(dict
, key
, icon_value
);
591 if (!wPreferences
.flags
.noupdates
)
592 UpdateDomainFile(db
);
594 WMReleasePropList(key
);
596 WMReleasePropList(icon_value
);
598 WMPLSetCaseSensitive(False
);
601 void wDefaultPurgeInfo(const char *instance
, const char *class)
603 WMPropList
*value
, *key
, *dict
;
606 if (!AIcon
) { /* Unnecessary precaution */
610 WMPLSetCaseSensitive(True
);
612 buffer
= wmalloc(strlen(class) + strlen(instance
) + 2);
613 sprintf(buffer
, "%s.%s", instance
, class);
614 key
= WMCreatePLString(buffer
);
616 dict
= WMGetFromPLDictionary(w_global
.domain
.window_attr
->dictionary
, key
);
619 value
= WMGetFromPLDictionary(dict
, AIcon
);
621 WMRemoveFromPLDictionary(dict
, AIcon
);
623 WMRemoveFromPLDictionary(w_global
.domain
.window_attr
->dictionary
, key
);
624 UpdateDomainFile(w_global
.domain
.window_attr
);
628 WMReleasePropList(key
);
629 WMPLSetCaseSensitive(False
);
632 /* --------------------------- Local ----------------------- */
634 static int getBool(WMPropList
* key
, WMPropList
* value
)
638 if (!WMIsPLString(value
)) {
639 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
640 WMGetFromPLString(key
), "Boolean");
643 val
= WMGetFromPLString(value
);
645 if ((val
[1] == '\0' && (val
[0] == 'y' || val
[0] == 'Y' || val
[0] == 'T' || val
[0] == 't' || val
[0] == '1'))
646 || (strcasecmp(val
, "YES") == 0 || strcasecmp(val
, "TRUE") == 0)) {
649 } else if ((val
[1] == '\0'
650 && (val
[0] == 'n' || val
[0] == 'N' || val
[0] == 'F' || val
[0] == 'f' || val
[0] == '0'))
651 || (strcasecmp(val
, "NO") == 0 || strcasecmp(val
, "FALSE") == 0)) {
655 wwarning(_("can't convert \"%s\" to boolean"), val
);
656 /* We return False if we can't convert to BOOLEAN.
657 * This is because all options defaults to False.
658 * -1 is not checked and thus is interpreted as True,
659 * which is not good.*/
664 /* WARNING: Do not free the value returned by this function!! */
665 static char *getString(WMPropList
* key
, WMPropList
* value
)
667 if (!WMIsPLString(value
)) {
668 wwarning(_("Wrong option format for key \"%s\". Should be %s."), WMGetFromPLString(key
), "String");
672 return WMGetFromPLString(value
);