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;}
51 extern WPreferences wPreferences
;
52 extern WDDomain
*WDWindowAttributes
;
57 static int getBool(WMPropList
*, WMPropList
*);
58 static char *getString(WMPropList
*, WMPropList
*);
59 static WMPropList
*ANoTitlebar
= NULL
;
60 static WMPropList
*ANoResizebar
;
61 static WMPropList
*ANoMiniaturizeButton
;
62 static WMPropList
*ANoMiniaturizable
;
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
*ASkipSwitchPanel
;
74 static WMPropList
*AKeepInsideScreen
;
75 static WMPropList
*AUnfocusable
;
76 static WMPropList
*AAlwaysUserIcon
;
77 static WMPropList
*AStartMiniaturized
;
78 static WMPropList
*AStartMaximized
;
79 static WMPropList
*AStartHidden
; /* app */
80 static WMPropList
*ADontSaveSession
; /* app */
81 static WMPropList
*AEmulateAppIcon
;
82 static WMPropList
*AFocusAcrossWorkspace
;
83 static WMPropList
*AFullMaximize
;
84 static WMPropList
*ASharedAppIcon
; /* app */
85 #ifdef XKB_BUTTON_HINT
86 static WMPropList
*ANoLanguageButton
;
88 static WMPropList
*AStartWorkspace
;
89 static WMPropList
*AIcon
;
90 static WMPropList
*AnyWindow
;
91 static WMPropList
*No
;
93 static void init_wdefaults(void)
95 AIcon
= WMCreatePLString("Icon");
97 ANoTitlebar
= WMCreatePLString("NoTitlebar");
98 ANoResizebar
= WMCreatePLString("NoResizebar");
99 ANoMiniaturizeButton
= WMCreatePLString("NoMiniaturizeButton");
100 ANoMiniaturizable
= WMCreatePLString("NoMiniaturizable");
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 ASkipSwitchPanel
= WMCreatePLString("SkipSwitchPanel");
112 AKeepInsideScreen
= WMCreatePLString("KeepInsideScreen");
113 AUnfocusable
= WMCreatePLString("Unfocusable");
114 AAlwaysUserIcon
= WMCreatePLString("AlwaysUserIcon");
115 AStartMiniaturized
= WMCreatePLString("StartMiniaturized");
116 AStartHidden
= WMCreatePLString("StartHidden");
117 AStartMaximized
= WMCreatePLString("StartMaximized");
118 ADontSaveSession
= WMCreatePLString("DontSaveSession");
119 AEmulateAppIcon
= WMCreatePLString("EmulateAppIcon");
120 AFocusAcrossWorkspace
= WMCreatePLString("FocusAcrossWorkspace");
121 AFullMaximize
= WMCreatePLString("FullMaximize");
122 ASharedAppIcon
= WMCreatePLString("SharedAppIcon");
123 #ifdef XKB_BUTTON_HINT
124 ANoLanguageButton
= WMCreatePLString("NoLanguageButton");
127 AStartWorkspace
= WMCreatePLString("StartWorkspace");
129 AnyWindow
= WMCreatePLString("*");
130 No
= WMCreatePLString("No");
133 /* Returns the correct WMPropList, using instance+class or instance, or class, or default */
134 static WMPropList
*get_value(WMPropList
* dict_win
, WMPropList
* dict_class
, WMPropList
* dict_name
,
135 WMPropList
* dict_any
, WMPropList
* option
, WMPropList
* default_value
,
136 Bool useGlobalDefault
)
141 value
= WMGetFromPLDictionary(dict_win
, option
);
147 value
= WMGetFromPLDictionary(dict_name
, option
);
153 value
= WMGetFromPLDictionary(dict_class
, option
);
158 if (!useGlobalDefault
)
162 value
= WMGetFromPLDictionary(dict_any
, option
);
167 return default_value
;
170 static WMPropList
*get_value_from_instanceclass(char *value
)
172 WMPropList
*key
, *val
= NULL
;
177 key
= WMCreatePLString(value
);
179 WMPLSetCaseSensitive(True
);
181 if (WDWindowAttributes
->dictionary
)
182 val
= key
? WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
) : NULL
;
185 WMReleasePropList(key
);
187 WMPLSetCaseSensitive(False
);
193 *----------------------------------------------------------------------
194 * wDefaultFillAttributes--
195 * Retrieves attributes for the specified instance/class and
196 * fills attr with it. Values that are actually defined are also
197 * set in mask. If useGlobalDefault is True, the default for
198 * all windows ("*") will be used for when no values are found
199 * for that instance/class.
201 *----------------------------------------------------------------------
203 void wDefaultFillAttributes(char *instance
, char *class,
204 WWindowAttributes
*attr
, WWindowAttributes
*mask
,
205 Bool useGlobalDefault
)
207 WMPropList
*value
, *dw
, *dc
, *dn
, *da
;
210 dw
= dc
= dn
= da
= NULL
;
215 if (class && instance
) {
216 buffer
= StrConcatDot(instance
, class);
217 dw
= get_value_from_instanceclass(buffer
);
221 dn
= get_value_from_instanceclass(instance
);
222 dc
= get_value_from_instanceclass(class);
224 WMPLSetCaseSensitive(True
);
226 if ((WDWindowAttributes
->dictionary
) && (useGlobalDefault
))
227 da
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, AnyWindow
);
230 value
= get_value(dw
, dc
, dn
, da
, ANoTitlebar
, No
, useGlobalDefault
);
231 APPLY_VAL(value
, no_titlebar
, ANoTitlebar
);
233 value
= get_value(dw
, dc
, dn
, da
, ANoResizebar
, No
, useGlobalDefault
);
234 APPLY_VAL(value
, no_resizebar
, ANoResizebar
);
236 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizeButton
, No
, useGlobalDefault
);
237 APPLY_VAL(value
, no_miniaturize_button
, ANoMiniaturizeButton
);
239 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizable
, No
, useGlobalDefault
);
240 APPLY_VAL(value
, no_miniaturizable
, ANoMiniaturizable
);
242 value
= get_value(dw
, dc
, dn
, da
, ANoCloseButton
, No
, useGlobalDefault
);
243 APPLY_VAL(value
, no_close_button
, ANoCloseButton
);
245 value
= get_value(dw
, dc
, dn
, da
, ANoBorder
, No
, useGlobalDefault
);
246 APPLY_VAL(value
, no_border
, ANoBorder
);
248 value
= get_value(dw
, dc
, dn
, da
, ANoHideOthers
, No
, useGlobalDefault
);
249 APPLY_VAL(value
, no_hide_others
, ANoHideOthers
);
251 value
= get_value(dw
, dc
, dn
, da
, ANoMouseBindings
, No
, useGlobalDefault
);
252 APPLY_VAL(value
, no_bind_mouse
, ANoMouseBindings
);
254 value
= get_value(dw
, dc
, dn
, da
, ANoKeyBindings
, No
, useGlobalDefault
);
255 APPLY_VAL(value
, no_bind_keys
, ANoKeyBindings
);
257 value
= get_value(dw
, dc
, dn
, da
, ANoAppIcon
, No
, useGlobalDefault
);
258 APPLY_VAL(value
, no_appicon
, ANoAppIcon
);
260 value
= get_value(dw
, dc
, dn
, da
, ASharedAppIcon
, No
, useGlobalDefault
);
261 APPLY_VAL(value
, shared_appicon
, ASharedAppIcon
);
263 value
= get_value(dw
, dc
, dn
, da
, AKeepOnTop
, No
, useGlobalDefault
);
264 APPLY_VAL(value
, floating
, AKeepOnTop
);
266 value
= get_value(dw
, dc
, dn
, da
, AKeepOnBottom
, No
, useGlobalDefault
);
267 APPLY_VAL(value
, sunken
, AKeepOnBottom
);
269 value
= get_value(dw
, dc
, dn
, da
, AOmnipresent
, No
, useGlobalDefault
);
270 APPLY_VAL(value
, omnipresent
, AOmnipresent
);
272 value
= get_value(dw
, dc
, dn
, da
, ASkipWindowList
, No
, useGlobalDefault
);
273 APPLY_VAL(value
, skip_window_list
, ASkipWindowList
);
275 value
= get_value(dw
, dc
, dn
, da
, ASkipSwitchPanel
, No
, useGlobalDefault
);
276 APPLY_VAL(value
, skip_switchpanel
, ASkipSwitchPanel
);
278 value
= get_value(dw
, dc
, dn
, da
, AKeepInsideScreen
, No
, useGlobalDefault
);
279 APPLY_VAL(value
, dont_move_off
, AKeepInsideScreen
);
281 value
= get_value(dw
, dc
, dn
, da
, AUnfocusable
, No
, useGlobalDefault
);
282 APPLY_VAL(value
, no_focusable
, AUnfocusable
);
284 value
= get_value(dw
, dc
, dn
, da
, AAlwaysUserIcon
, No
, useGlobalDefault
);
285 APPLY_VAL(value
, always_user_icon
, AAlwaysUserIcon
);
287 value
= get_value(dw
, dc
, dn
, da
, AStartMiniaturized
, No
, useGlobalDefault
);
288 APPLY_VAL(value
, start_miniaturized
, AStartMiniaturized
);
290 value
= get_value(dw
, dc
, dn
, da
, AStartHidden
, No
, useGlobalDefault
);
291 APPLY_VAL(value
, start_hidden
, AStartHidden
);
293 value
= get_value(dw
, dc
, dn
, da
, AStartMaximized
, No
, useGlobalDefault
);
294 APPLY_VAL(value
, start_maximized
, AStartMaximized
);
296 value
= get_value(dw
, dc
, dn
, da
, ADontSaveSession
, No
, useGlobalDefault
);
297 APPLY_VAL(value
, dont_save_session
, ADontSaveSession
);
299 value
= get_value(dw
, dc
, dn
, da
, AEmulateAppIcon
, No
, useGlobalDefault
);
300 APPLY_VAL(value
, emulate_appicon
, AEmulateAppIcon
);
302 value
= get_value(dw
, dc
, dn
, da
, AFocusAcrossWorkspace
, No
, useGlobalDefault
);
303 APPLY_VAL(value
, focus_across_wksp
, AFocusAcrossWorkspace
);
305 value
= get_value(dw
, dc
, dn
, da
, AFullMaximize
, No
, useGlobalDefault
);
306 APPLY_VAL(value
, full_maximize
, AFullMaximize
);
308 #ifdef XKB_BUTTON_HINT
309 value
= get_value(dw
, dc
, dn
, da
, ANoLanguageButton
, No
, useGlobalDefault
);
310 APPLY_VAL(value
, no_language_button
, ANoLanguageButton
);
314 WMPLSetCaseSensitive(False
);
317 static WMPropList
*get_generic_value(char *instance
, char *class,
318 WMPropList
*option
, Bool default_icon
)
320 WMPropList
*value
, *key
, *dict
;
324 WMPLSetCaseSensitive(True
);
326 /* Search the icon name using class and instance */
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
);
342 /* Search the icon name using instance */
343 if (!value
&& instance
) {
344 key
= WMCreatePLString(instance
);
346 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
347 WMReleasePropList(key
);
350 value
= WMGetFromPLDictionary(dict
, option
);
353 /* Search the icon name using class */
354 if (!value
&& class) {
355 key
= WMCreatePLString(class);
357 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
358 WMReleasePropList(key
);
361 value
= WMGetFromPLDictionary(dict
, option
);
364 /* Search the default icon name - See default_icon argument! */
365 if (!value
&& default_icon
) {
366 /* AnyWindow is "*" - see wdefaults.c */
367 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, AnyWindow
);
370 value
= WMGetFromPLDictionary(dict
, option
);
373 WMPLSetCaseSensitive(False
);
378 /* Get the file name of the image, using instance and class */
379 char *get_icon_filename(WScreen
*scr
, char *winstance
, char *wclass
, char *command
,
382 char *file_name
= NULL
;
383 char *file_path
= NULL
;
385 /* Get the file name of the image, using instance and class */
386 file_name
= wDefaultGetIconFile(winstance
, wclass
, default_icon
);
388 /* Check if the file really exists in the disk */
390 file_path
= FindImage(wPreferences
.icon_path
, file_name
);
392 /* If the specific icon filename is not found, and command is specified,
393 * then include the .app icons and re-do the search. */
394 if ((!file_name
|| !file_path
) && scr
&& command
) {
395 wApplicationExtractDirPackIcon(scr
, command
, winstance
, wclass
);
396 file_name
= wDefaultGetIconFile(winstance
, wclass
, False
);
399 /* Get the full path for the image file */
401 file_path
= FindImage(wPreferences
.icon_path
, file_name
);
404 wwarning(_("icon \"%s\" doesn't exist, check your config files"), file_name
);
406 /* FIXME: Here, if file_path don't exists, then the icon is in the
407 * "icon database" (WDWindowAttributes->dictionary), but the icon
408 * is not en disk. Therefore, we should remove it from the icon
409 * database. Is possible to do that using wDefaultChangeIcon() */
411 /* Don't wfree(file_name) here, because is a pointer to the icon
412 * dictionary (WDWindowAttributes->dictionary) value. */
415 if (!file_path
&& default_icon
)
416 file_path
= get_default_image_path();
421 /* This function returns the image picture for the file_name file */
422 RImage
*get_rimage_from_file(WScreen
*scr
, char *file_name
, int max_size
)
424 RImage
*image
= NULL
;
429 image
= RLoadImage(scr
->rcontext
, file_name
, 0);
431 wwarning(_("error loading image file \"%s\": %s"), file_name
,
432 RMessageForError(RErrorCode
));
434 image
= wIconValidateIconSize(image
, max_size
);
439 /* This function returns the default icon's full path
440 * If the path for an icon is not found, returns NULL */
441 char *get_default_image_path(void)
443 char *path
= NULL
, *file
= NULL
;
445 /* Get the default icon */
446 file
= wDefaultGetIconFile(NULL
, NULL
, True
);
448 path
= FindImage(wPreferences
.icon_path
, file
);
453 /* This function creates the RImage using the default icon */
454 RImage
*get_default_image(WScreen
*scr
)
456 RImage
*image
= NULL
;
459 /* Get the filename full path */
460 path
= get_default_image_path();
464 /* Get the default icon */
465 image
= get_rimage_from_file(scr
, path
, wPreferences
.icon_size
);
467 wwarning(_("could not find default icon \"%s\""), path
);
469 /* Resize the icon to the wPreferences.icon_size size
470 * usually this function will return early, because size is right */
471 image
= wIconValidateIconSize(image
, wPreferences
.icon_size
);
476 RImage
*get_icon_image(WScreen
*scr
, char *winstance
, char *wclass
, int max_size
)
478 char *file_name
= NULL
;
480 /* Get the file name of the image, using instance and class */
481 file_name
= get_icon_filename(scr
, winstance
, wclass
, NULL
, True
);
483 return get_rimage_from_file(scr
, file_name
, max_size
);
486 int wDefaultGetStartWorkspace(WScreen
* scr
, char *instance
, char *class)
495 if (!WDWindowAttributes
->dictionary
)
498 value
= get_generic_value(instance
, class, AStartWorkspace
, True
);
503 tmp
= getString(AStartWorkspace
, value
);
505 if (!tmp
|| strlen(tmp
) == 0)
508 /* Get the workspace number for the workspace name */
509 w
= wGetWorkspaceNumber(scr
, tmp
);
514 /* Get the name of the Icon File. If default_icon is True, then, default value included */
515 char *wDefaultGetIconFile(char *instance
, char *class, Bool default_icon
)
523 if (!WDWindowAttributes
|| !WDWindowAttributes
->dictionary
)
526 value
= get_generic_value(instance
, class, AIcon
, default_icon
);
531 tmp
= getString(AIcon
, value
);
536 void wDefaultChangeIcon(WScreen
* scr
, char *instance
, char *class, char *file
)
538 WDDomain
*db
= WDWindowAttributes
;
539 WMPropList
*icon_value
= NULL
, *value
, *attr
, *key
, *def_win
, *def_icon
= NULL
;
540 WMPropList
*dict
= db
->dictionary
;
544 dict
= WMCreatePLDictionary(NULL
, NULL
);
546 db
->dictionary
= dict
;
551 WMPLSetCaseSensitive(True
);
553 if (instance
&& class) {
556 buffer
= StrConcatDot(instance
, class);
557 key
= WMCreatePLString(buffer
);
559 } else if (instance
) {
560 key
= WMCreatePLString(instance
);
562 key
= WMCreatePLString(class);
564 key
= WMRetainPropList(AnyWindow
);
568 value
= WMCreatePLString(file
);
569 icon_value
= WMCreatePLDictionary(AIcon
, value
, NULL
);
570 WMReleasePropList(value
);
572 if ((def_win
= WMGetFromPLDictionary(dict
, AnyWindow
)) != NULL
)
573 def_icon
= WMGetFromPLDictionary(def_win
, AIcon
);
575 if (def_icon
&& !strcmp(WMGetFromPLString(def_icon
), file
))
579 if ((attr
= WMGetFromPLDictionary(dict
, key
)) != NULL
) {
580 if (WMIsPLDictionary(attr
)) {
581 if (icon_value
!= NULL
&& !same
)
582 WMMergePLDictionaries(attr
, icon_value
, False
);
584 WMRemoveFromPLDictionary(attr
, AIcon
);
586 } else if (icon_value
!= NULL
&& !same
) {
587 WMPutInPLDictionary(dict
, key
, icon_value
);
590 if (!wPreferences
.flags
.noupdates
)
591 UpdateDomainFile(db
);
593 WMReleasePropList(key
);
595 WMReleasePropList(icon_value
);
597 WMPLSetCaseSensitive(False
);
600 void wDefaultPurgeInfo(WScreen
*scr
, char *instance
, char *class)
602 WMPropList
*value
, *key
, *dict
;
605 if (!AIcon
) { /* Unnecessary precaution */
609 WMPLSetCaseSensitive(True
);
611 buffer
= wmalloc(strlen(class) + strlen(instance
) + 2);
612 sprintf(buffer
, "%s.%s", instance
, class);
613 key
= WMCreatePLString(buffer
);
615 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
618 value
= WMGetFromPLDictionary(dict
, AIcon
);
620 WMRemoveFromPLDictionary(dict
, AIcon
);
622 WMRemoveFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
623 UpdateDomainFile(WDWindowAttributes
);
627 WMReleasePropList(key
);
628 WMPLSetCaseSensitive(False
);
631 /* --------------------------- Local ----------------------- */
633 static int getBool(WMPropList
* key
, WMPropList
* value
)
637 if (!WMIsPLString(value
)) {
638 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
639 WMGetFromPLString(key
), "Boolean");
642 val
= WMGetFromPLString(value
);
644 if ((val
[1] == '\0' && (val
[0] == 'y' || val
[0] == 'Y' || val
[0] == 'T' || val
[0] == 't' || val
[0] == '1'))
645 || (strcasecmp(val
, "YES") == 0 || strcasecmp(val
, "TRUE") == 0)) {
648 } else if ((val
[1] == '\0'
649 && (val
[0] == 'n' || val
[0] == 'N' || val
[0] == 'F' || val
[0] == 'f' || val
[0] == '0'))
650 || (strcasecmp(val
, "NO") == 0 || strcasecmp(val
, "FALSE") == 0)) {
654 wwarning(_("can't convert \"%s\" to boolean"), val
);
655 /* We return False if we can't convert to BOOLEAN.
656 * This is because all options defaults to False.
657 * -1 is not checked and thus is interpreted as True,
658 * which is not good.*/
663 /* WARNING: Do not free the value returned by this function!! */
664 static char *getString(WMPropList
* key
, WMPropList
* value
)
666 if (!WMIsPLString(value
)) {
667 wwarning(_("Wrong option format for key \"%s\". Should be %s."), WMGetFromPLString(key
), "String");
671 return WMGetFromPLString(value
);