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
*ADontFocusAcrossWorkspace
;
82 static WMPropList
*AFullMaximize
;
83 static WMPropList
*ASharedAppIcon
; /* app */
84 #ifdef XKB_BUTTON_HINT
85 static WMPropList
*ANoLanguageButton
;
88 static WMPropList
*AStartWorkspace
;
90 static WMPropList
*AIcon
;
92 static WMPropList
*AnyWindow
;
93 static WMPropList
*No
;
95 static void init_wdefaults(WScreen
* scr
)
97 AIcon
= WMCreatePLString("Icon");
99 ANoTitlebar
= WMCreatePLString("NoTitlebar");
100 ANoResizebar
= WMCreatePLString("NoResizebar");
101 ANoMiniaturizeButton
= WMCreatePLString("NoMiniaturizeButton");
102 ANoCloseButton
= WMCreatePLString("NoCloseButton");
103 ANoBorder
= WMCreatePLString("NoBorder");
104 ANoHideOthers
= WMCreatePLString("NoHideOthers");
105 ANoMouseBindings
= WMCreatePLString("NoMouseBindings");
106 ANoKeyBindings
= WMCreatePLString("NoKeyBindings");
107 ANoAppIcon
= WMCreatePLString("NoAppIcon");
108 AKeepOnTop
= WMCreatePLString("KeepOnTop");
109 AKeepOnBottom
= WMCreatePLString("KeepOnBottom");
110 AOmnipresent
= WMCreatePLString("Omnipresent");
111 ASkipWindowList
= WMCreatePLString("SkipWindowList");
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 ADontFocusAcrossWorkspace
= WMCreatePLString("DontFocusAcrossWorkspace");
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");
132 if (!scr->wattribs) {
133 scr->wattribs = PLGetDomain(wAttributeDomainName);
137 static WMPropList
*get_value(WMPropList
* dict_win
, WMPropList
* dict_class
, WMPropList
* dict_name
,
138 WMPropList
* dict_any
, WMPropList
* option
, WMPropList
* default_value
,
139 Bool useGlobalDefault
)
144 value
= WMGetFromPLDictionary(dict_win
, option
);
150 value
= WMGetFromPLDictionary(dict_name
, option
);
156 value
= WMGetFromPLDictionary(dict_class
, option
);
161 if (!useGlobalDefault
)
165 value
= WMGetFromPLDictionary(dict_any
, option
);
170 return default_value
;
174 *----------------------------------------------------------------------
175 * wDefaultFillAttributes--
176 * Retrieves attributes for the specified instance/class and
177 * fills attr with it. Values that are actually defined are also
178 * set in mask. If useGlobalDefault is True, the default for
179 * all windows ("*") will be used for when no values are found
180 * for that instance/class.
182 *----------------------------------------------------------------------
185 wDefaultFillAttributes(WScreen
* scr
, char *instance
, char *class,
186 WWindowAttributes
* attr
, WWindowAttributes
* mask
, Bool useGlobalDefault
)
188 WMPropList
*value
, *key1
, *key2
, *key3
, *dw
, *dc
, *dn
, *da
;
190 if (class && instance
) {
193 buffer
= wmalloc(strlen(class) + strlen(instance
) + 2);
194 sprintf(buffer
, "%s.%s", instance
, class);
195 key1
= WMCreatePLString(buffer
);
202 key2
= WMCreatePLString(instance
);
207 key3
= WMCreatePLString(class);
215 WMPLSetCaseSensitive(True
);
217 if (WDWindowAttributes
->dictionary
) {
218 dw
= key1
? WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key1
) : NULL
;
219 dn
= key2
? WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key2
) : NULL
;
220 dc
= key3
? WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key3
) : NULL
;
221 if (useGlobalDefault
)
222 da
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, AnyWindow
);
232 WMReleasePropList(key1
);
234 WMReleasePropList(key2
);
236 WMReleasePropList(key3
);
238 #define APPLY_VAL(value, flag, attrib) \
239 if (value) {attr->flag = getBool(attrib, value); \
240 if (mask) mask->flag = 1;}
243 value
= get_value(dw
, dc
, dn
, da
, ANoTitlebar
, No
, useGlobalDefault
);
244 APPLY_VAL(value
, no_titlebar
, ANoTitlebar
);
246 value
= get_value(dw
, dc
, dn
, da
, ANoResizebar
, No
, useGlobalDefault
);
247 APPLY_VAL(value
, no_resizebar
, ANoResizebar
);
249 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizeButton
, No
, useGlobalDefault
);
250 APPLY_VAL(value
, no_miniaturize_button
, ANoMiniaturizeButton
);
252 value
= get_value(dw
, dc
, dn
, da
, ANoCloseButton
, No
, useGlobalDefault
);
253 APPLY_VAL(value
, no_close_button
, ANoCloseButton
);
255 value
= get_value(dw
, dc
, dn
, da
, ANoBorder
, No
, useGlobalDefault
);
256 APPLY_VAL(value
, no_border
, ANoBorder
);
258 value
= get_value(dw
, dc
, dn
, da
, ANoHideOthers
, No
, useGlobalDefault
);
259 APPLY_VAL(value
, no_hide_others
, ANoHideOthers
);
261 value
= get_value(dw
, dc
, dn
, da
, ANoMouseBindings
, No
, useGlobalDefault
);
262 APPLY_VAL(value
, no_bind_mouse
, ANoMouseBindings
);
264 value
= get_value(dw
, dc
, dn
, da
, ANoKeyBindings
, No
, useGlobalDefault
);
265 APPLY_VAL(value
, no_bind_keys
, ANoKeyBindings
);
267 value
= get_value(dw
, dc
, dn
, da
, ANoAppIcon
, No
, useGlobalDefault
);
268 APPLY_VAL(value
, no_appicon
, ANoAppIcon
);
270 value
= get_value(dw
, dc
, dn
, da
, ASharedAppIcon
, No
, useGlobalDefault
);
271 APPLY_VAL(value
, shared_appicon
, ASharedAppIcon
);
273 value
= get_value(dw
, dc
, dn
, da
, AKeepOnTop
, No
, useGlobalDefault
);
274 APPLY_VAL(value
, floating
, AKeepOnTop
);
276 value
= get_value(dw
, dc
, dn
, da
, AKeepOnBottom
, No
, useGlobalDefault
);
277 APPLY_VAL(value
, sunken
, AKeepOnBottom
);
279 value
= get_value(dw
, dc
, dn
, da
, AOmnipresent
, No
, useGlobalDefault
);
280 APPLY_VAL(value
, omnipresent
, AOmnipresent
);
282 value
= get_value(dw
, dc
, dn
, da
, ASkipWindowList
, No
, useGlobalDefault
);
283 APPLY_VAL(value
, skip_window_list
, ASkipWindowList
);
285 value
= get_value(dw
, dc
, dn
, da
, AKeepInsideScreen
, No
, useGlobalDefault
);
286 APPLY_VAL(value
, dont_move_off
, AKeepInsideScreen
);
288 value
= get_value(dw
, dc
, dn
, da
, AUnfocusable
, No
, useGlobalDefault
);
289 APPLY_VAL(value
, no_focusable
, AUnfocusable
);
291 value
= get_value(dw
, dc
, dn
, da
, AAlwaysUserIcon
, No
, useGlobalDefault
);
292 APPLY_VAL(value
, always_user_icon
, AAlwaysUserIcon
);
294 value
= get_value(dw
, dc
, dn
, da
, AStartMiniaturized
, No
, useGlobalDefault
);
295 APPLY_VAL(value
, start_miniaturized
, AStartMiniaturized
);
297 value
= get_value(dw
, dc
, dn
, da
, AStartHidden
, No
, useGlobalDefault
);
298 APPLY_VAL(value
, start_hidden
, AStartHidden
);
300 value
= get_value(dw
, dc
, dn
, da
, AStartMaximized
, No
, useGlobalDefault
);
301 APPLY_VAL(value
, start_maximized
, AStartMaximized
);
303 value
= get_value(dw
, dc
, dn
, da
, ADontSaveSession
, No
, useGlobalDefault
);
304 APPLY_VAL(value
, dont_save_session
, ADontSaveSession
);
306 value
= get_value(dw
, dc
, dn
, da
, AEmulateAppIcon
, No
, useGlobalDefault
);
307 APPLY_VAL(value
, emulate_appicon
, AEmulateAppIcon
);
309 value
= get_value(dw
, dc
, dn
, da
, ADontFocusAcrossWorkspace
, No
, useGlobalDefault
);
310 APPLY_VAL(value
, dont_focus_across_wksp
, ADontFocusAcrossWorkspace
);
312 value
= get_value(dw
, dc
, dn
, da
, AFullMaximize
, No
, useGlobalDefault
);
313 APPLY_VAL(value
, full_maximize
, AFullMaximize
);
315 #ifdef XKB_BUTTON_HINT
316 value
= get_value(dw
, dc
, dn
, da
, ANoLanguageButton
, No
, useGlobalDefault
);
317 APPLY_VAL(value
, no_language_button
, ANoLanguageButton
);
321 WMPLSetCaseSensitive(False
);
324 WMPropList
*get_generic_value(WScreen
* scr
, char *instance
, char *class, WMPropList
* option
, Bool noDefault
)
326 WMPropList
*value
, *key
, *dict
;
330 WMPLSetCaseSensitive(True
);
332 if (class && instance
) {
335 buffer
= wmalloc(strlen(class) + strlen(instance
) + 2);
336 sprintf(buffer
, "%s.%s", instance
, class);
337 key
= WMCreatePLString(buffer
);
340 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
341 WMReleasePropList(key
);
344 value
= WMGetFromPLDictionary(dict
, option
);
348 if (!value
&& instance
) {
349 key
= WMCreatePLString(instance
);
351 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
352 WMReleasePropList(key
);
354 value
= WMGetFromPLDictionary(dict
, option
);
358 if (!value
&& class) {
359 key
= WMCreatePLString(class);
361 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, key
);
362 WMReleasePropList(key
);
365 value
= WMGetFromPLDictionary(dict
, option
);
369 if (!value
&& !noDefault
) {
370 dict
= WMGetFromPLDictionary(WDWindowAttributes
->dictionary
, AnyWindow
);
373 value
= WMGetFromPLDictionary(dict
, option
);
377 WMPLSetCaseSensitive(False
);
382 char *wDefaultGetIconFile(WScreen
* scr
, char *instance
, char *class, Bool noDefault
)
391 if (!WDWindowAttributes
->dictionary
)
394 value
= get_generic_value(scr
, instance
, class, AIcon
, noDefault
);
399 tmp
= getString(AIcon
, value
);
404 RImage
*wDefaultGetImage(WScreen
* scr
, char *winstance
, char *wclass
)
410 file_name
= wDefaultGetIconFile(scr
, winstance
, wclass
, False
);
414 path
= FindImage(wPreferences
.icon_path
, file_name
);
417 wwarning(_("could not find icon file \"%s\""), file_name
);
421 image
= RLoadImage(scr
->rcontext
, path
, 0);
423 wwarning(_("error loading image file \"%s\""), path
, RMessageForError(RErrorCode
));
427 image
= wIconValidateIconSize(scr
, image
);
432 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 if (sscanf(tmp
, "%i", &w
) != 1) {
457 for (i
= 0; i
< scr
->workspace_count
; i
++) {
458 if (strcmp(scr
->workspaces
[i
]->name
, tmp
) == 0) {
470 void wDefaultChangeIcon(WScreen
* scr
, char *instance
, char *class, char *file
)
472 WDDomain
*db
= WDWindowAttributes
;
473 WMPropList
*icon_value
= NULL
, *value
, *attr
, *key
, *def_win
, *def_icon
= NULL
;
474 WMPropList
*dict
= db
->dictionary
;
478 dict
= WMCreatePLDictionary(NULL
, NULL
);
480 db
->dictionary
= dict
;
486 WMPLSetCaseSensitive(True
);
488 if (instance
&& class) {
490 buffer
= wmalloc(strlen(instance
) + strlen(class) + 2);
491 sprintf(buffer
, "%s.%s", instance
, class);
492 key
= WMCreatePLString(buffer
);
494 } else if (instance
) {
495 key
= WMCreatePLString(instance
);
497 key
= WMCreatePLString(class);
499 key
= WMRetainPropList(AnyWindow
);
503 value
= WMCreatePLString(file
);
504 icon_value
= WMCreatePLDictionary(AIcon
, value
, NULL
);
505 WMReleasePropList(value
);
507 if ((def_win
= WMGetFromPLDictionary(dict
, AnyWindow
)) != NULL
) {
508 def_icon
= WMGetFromPLDictionary(def_win
, AIcon
);
511 if (def_icon
&& !strcmp(WMGetFromPLString(def_icon
), file
))
515 if ((attr
= WMGetFromPLDictionary(dict
, key
)) != NULL
) {
516 if (WMIsPLDictionary(attr
)) {
517 if (icon_value
!= NULL
&& !same
)
518 WMMergePLDictionaries(attr
, icon_value
, False
);
520 WMRemoveFromPLDictionary(attr
, AIcon
);
522 } else if (icon_value
!= NULL
&& !same
) {
523 WMPutInPLDictionary(dict
, key
, icon_value
);
525 if (!wPreferences
.flags
.noupdates
) {
526 UpdateDomainFile(db
);
529 WMReleasePropList(key
);
531 WMReleasePropList(icon_value
);
533 WMPLSetCaseSensitive(False
);
536 /* --------------------------- Local ----------------------- */
538 static int getBool(WMPropList
* key
, WMPropList
* value
)
542 if (!WMIsPLString(value
)) {
543 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
544 WMGetFromPLString(key
), "Boolean");
547 val
= WMGetFromPLString(value
);
549 if ((val
[1] == '\0' && (val
[0] == 'y' || val
[0] == 'Y' || val
[0] == 'T' || val
[0] == 't' || val
[0] == '1'))
550 || (strcasecmp(val
, "YES") == 0 || strcasecmp(val
, "TRUE") == 0)) {
553 } else if ((val
[1] == '\0'
554 && (val
[0] == 'n' || val
[0] == 'N' || val
[0] == 'F' || val
[0] == 'f' || val
[0] == '0'))
555 || (strcasecmp(val
, "NO") == 0 || strcasecmp(val
, "FALSE") == 0)) {
559 wwarning(_("can't convert \"%s\" to boolean"), val
);
560 /* We return False if we can't convert to BOOLEAN.
561 * This is because all options defaults to False.
562 * -1 is not checked and thus is interpreted as True,
563 * which is not good.*/
568 /* WARNING: Do not free the value returned by this function!! */
569 static char *getString(WMPropList
* key
, WMPropList
* value
)
571 if (!WMIsPLString(value
)) {
572 wwarning(_("Wrong option format for key \"%s\". Should be %s."), WMGetFromPLString(key
), "String");
576 return WMGetFromPLString(value
);