1 /* wdefaults.c - window specific defaults
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 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>
38 #include "WindowMaker.h"
42 #include "workspace.h"
49 extern WPreferences wPreferences
;
51 extern proplist_t wAttributeDomainName
;
53 extern WDDomain
*WDWindowAttributes
;
60 static int getBool(proplist_t
, proplist_t
);
62 static char* getString(proplist_t
, proplist_t
);
65 static proplist_t ANoTitlebar
= NULL
;
66 static proplist_t ANoResizebar
;
67 static proplist_t ANoMiniaturizeButton
;
68 static proplist_t ANoCloseButton
;
69 static proplist_t ANoHideOthers
;
70 static proplist_t ANoMouseBindings
;
71 static proplist_t ANoKeyBindings
;
72 static proplist_t ANoAppIcon
; /* app */
73 static proplist_t AKeepOnTop
;
74 static proplist_t AKeepOnBottom
;
75 static proplist_t AOmnipresent
;
76 static proplist_t ASkipWindowList
;
77 static proplist_t AKeepInsideScreen
;
78 static proplist_t AUnfocusable
;
79 static proplist_t AAlwaysUserIcon
;
80 static proplist_t AStartMiniaturized
;
81 static proplist_t AStartMaximized
;
82 static proplist_t AStartHidden
; /* app */
83 static proplist_t ADontSaveSession
; /* app */
84 static proplist_t AEmulateAppIcon
;
85 static proplist_t AFullMaximize
;
87 static proplist_t AStartWorkspace
;
89 static proplist_t AIcon
;
92 static proplist_t AnyWindow
;
97 init_wdefaults(WScreen
*scr
)
99 AIcon
= PLMakeString("Icon");
101 ANoTitlebar
= PLMakeString("NoTitlebar");
102 ANoResizebar
= PLMakeString("NoResizebar");
103 ANoMiniaturizeButton
= PLMakeString("NoMiniaturizeButton");
104 ANoCloseButton
= PLMakeString("NoCloseButton");
105 ANoHideOthers
= PLMakeString("NoHideOthers");
106 ANoMouseBindings
= PLMakeString("NoMouseBindings");
107 ANoKeyBindings
= PLMakeString("NoKeyBindings");
108 ANoAppIcon
= PLMakeString("NoAppIcon");
109 AKeepOnTop
= PLMakeString("KeepOnTop");
110 AKeepOnBottom
= PLMakeString("KeepOnBottom");
111 AOmnipresent
= PLMakeString("Omnipresent");
112 ASkipWindowList
= PLMakeString("SkipWindowList");
113 AKeepInsideScreen
= PLMakeString("KeepInsideScreen");
114 AUnfocusable
= PLMakeString("Unfocusable");
115 AAlwaysUserIcon
= PLMakeString("AlwaysUserIcon");
116 AStartMiniaturized
= PLMakeString("StartMiniaturized");
117 AStartHidden
= PLMakeString("StartHidden");
118 AStartMaximized
= PLMakeString("StartMaximized");
119 ADontSaveSession
= PLMakeString("DontSaveSession");
120 AEmulateAppIcon
= PLMakeString("EmulateAppIcon");
121 AFullMaximize
= PLMakeString("FullMaximize");
123 AStartWorkspace
= PLMakeString("StartWorkspace");
125 AnyWindow
= PLMakeString("*");
126 No
= PLMakeString("No");
128 if (!scr->wattribs) {
129 scr->wattribs = PLGetDomain(wAttributeDomainName);
136 get_value(proplist_t dict_win
, proplist_t dict_class
, proplist_t dict_name
,
137 proplist_t dict_any
, proplist_t option
, proplist_t default_value
,
138 Bool useGlobalDefault
)
144 value
= PLGetDictionaryEntry(dict_win
, option
);
150 value
= PLGetDictionaryEntry(dict_name
, option
);
156 value
= PLGetDictionaryEntry(dict_class
, option
);
161 if (!useGlobalDefault
)
165 value
= PLGetDictionaryEntry(dict_any
, option
);
170 return default_value
;
175 *----------------------------------------------------------------------
176 * wDefaultFillAttributes--
177 * Retrieves attributes for the specified instance/class and
178 * fills attr with it. Values that are actually defined are also
179 * set in mask. If useGlobalDefault is True, the default for
180 * all windows ("*") will be used for when no values are found
181 * for that instance/class.
183 *----------------------------------------------------------------------
186 wDefaultFillAttributes(WScreen
*scr
, char *instance
, char *class,
187 WWindowAttributes
*attr
,
188 WWindowAttributes
*mask
,
189 Bool useGlobalDefault
)
192 proplist_t key1
, key2
, key3
;
193 proplist_t dw
, dc
, dn
, da
;
197 if (class && instance
)
198 key1
= PLMakeString(strcat(strcat(strcpy(buffer
,instance
),"."),class));
203 key2
= PLMakeString(instance
);
208 key3
= PLMakeString(class);
216 PLSetStringCmpHook(NULL
);
218 if (WDWindowAttributes
->dictionary
) {
219 dw
= key1
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key1
) : NULL
;
220 dn
= key2
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key2
) : NULL
;
221 dc
= key3
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key3
) : NULL
;
222 if (useGlobalDefault
)
223 da
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, AnyWindow
);
239 #define APPLY_VAL(value, flag, attrib) \
240 if (value) {attr->flag = getBool(attrib, value); \
241 if (mask) mask->flag = 1;}
244 value
= get_value(dw
, dc
, dn
, da
, ANoTitlebar
, No
, useGlobalDefault
);
245 APPLY_VAL(value
, no_titlebar
, ANoTitlebar
);
247 value
= get_value(dw
, dc
, dn
, da
, ANoResizebar
, No
, useGlobalDefault
);
248 APPLY_VAL(value
, no_resizebar
, ANoResizebar
);
250 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizeButton
, No
, useGlobalDefault
);
251 APPLY_VAL(value
, no_miniaturize_button
, ANoMiniaturizeButton
);
253 value
= get_value(dw
, dc
, dn
, da
, ANoCloseButton
, No
, useGlobalDefault
);
254 APPLY_VAL(value
, no_close_button
, ANoCloseButton
);
256 value
= get_value(dw
, dc
, dn
, da
, ANoHideOthers
, No
, useGlobalDefault
);
257 APPLY_VAL(value
, no_hide_others
, ANoHideOthers
);
259 value
= get_value(dw
, dc
, dn
, da
, ANoMouseBindings
, No
, useGlobalDefault
);
260 APPLY_VAL(value
, no_bind_mouse
, ANoMouseBindings
);
262 value
= get_value(dw
, dc
, dn
, da
, ANoKeyBindings
, No
, useGlobalDefault
);
263 APPLY_VAL(value
, no_bind_keys
, ANoKeyBindings
);
265 value
= get_value(dw
, dc
, dn
, da
, ANoAppIcon
, No
, useGlobalDefault
);
266 APPLY_VAL(value
, no_appicon
, ANoAppIcon
);
268 value
= get_value(dw
, dc
, dn
, da
, AKeepOnTop
, No
, useGlobalDefault
);
269 APPLY_VAL(value
, floating
, AKeepOnTop
);
271 value
= get_value(dw
, dc
, dn
, da
, AKeepOnBottom
, No
, useGlobalDefault
);
272 APPLY_VAL(value
, sunken
, AKeepOnBottom
);
274 value
= get_value(dw
, dc
, dn
, da
, AOmnipresent
, No
, useGlobalDefault
);
275 APPLY_VAL(value
, omnipresent
, AOmnipresent
);
277 value
= get_value(dw
, dc
, dn
, da
, ASkipWindowList
, No
, useGlobalDefault
);
278 APPLY_VAL(value
, skip_window_list
, ASkipWindowList
);
280 value
= get_value(dw
, dc
, dn
, da
, AKeepInsideScreen
, No
, useGlobalDefault
);
281 APPLY_VAL(value
, dont_move_off
, AKeepInsideScreen
);
283 value
= get_value(dw
, dc
, dn
, da
, AUnfocusable
, No
, useGlobalDefault
);
284 APPLY_VAL(value
, no_focusable
, AUnfocusable
);
286 value
= get_value(dw
, dc
, dn
, da
, AAlwaysUserIcon
, No
, useGlobalDefault
);
287 APPLY_VAL(value
, always_user_icon
, AAlwaysUserIcon
);
289 value
= get_value(dw
, dc
, dn
, da
, AStartMiniaturized
, No
, useGlobalDefault
);
290 APPLY_VAL(value
, start_miniaturized
, AStartMiniaturized
);
292 value
= get_value(dw
, dc
, dn
, da
, AStartHidden
, No
, useGlobalDefault
);
293 APPLY_VAL(value
, start_hidden
, AStartHidden
);
295 value
= get_value(dw
, dc
, dn
, da
, AStartMaximized
, No
, useGlobalDefault
);
296 APPLY_VAL(value
, start_maximized
, AStartMaximized
);
298 value
= get_value(dw
, dc
, dn
, da
, ADontSaveSession
, No
, useGlobalDefault
);
299 APPLY_VAL(value
, dont_save_session
, ADontSaveSession
);
301 value
= get_value(dw
, dc
, dn
, da
, AEmulateAppIcon
, No
, useGlobalDefault
);
302 APPLY_VAL(value
, emulate_appicon
, AEmulateAppIcon
);
304 value
= get_value(dw
, dc
, dn
, da
, AFullMaximize
, No
, useGlobalDefault
);
305 APPLY_VAL(value
, emulate_appicon
, AFullMaximize
);
308 PLSetStringCmpHook(StringCompareHook
);
314 get_generic_value(WScreen
*scr
, char *instance
, char *class, proplist_t option
,
317 proplist_t value
, key
, dict
;
322 PLSetStringCmpHook(NULL
);
324 if (class && instance
) {
325 key
= PLMakeString(strcat(strcat(strcpy(buffer
,instance
),"."),class));
327 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
331 value
= PLGetDictionaryEntry(dict
, option
);
335 if (!value
&& instance
) {
336 key
= PLMakeString(instance
);
338 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
342 value
= PLGetDictionaryEntry(dict
, option
);
346 if (!value
&& class) {
347 key
= PLMakeString(class);
349 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
353 value
= PLGetDictionaryEntry(dict
, option
);
357 if (!value
&& !noDefault
) {
358 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, AnyWindow
);
361 value
= PLGetDictionaryEntry(dict
, option
);
365 PLSetStringCmpHook(StringCompareHook
);
372 wDefaultGetIconFile(WScreen
*scr
, char *instance
, char *class,
382 if (!WDWindowAttributes
->dictionary
)
385 value
= get_generic_value(scr
, instance
, class, AIcon
, noDefault
);
390 tmp
= getString(AIcon
, value
);
397 wDefaultGetImage(WScreen
*scr
, char *winstance
, char *wclass
)
403 file_name
= wDefaultGetIconFile(scr
, winstance
, wclass
, False
);
407 path
= FindImage(wPreferences
.icon_path
, file_name
);
410 wwarning(_("could not find icon file \"%s\""), file_name
);
414 image
= RLoadImage(scr
->rcontext
, path
, 0);
416 wwarning(_("error loading image file \"%s\""), path
, RMessageForError(RErrorCode
));
420 image
= wIconValidateIconSize(scr
, image
);
427 wDefaultGetStartWorkspace(WScreen
*scr
, char *instance
, char *class)
437 if (!WDWindowAttributes
->dictionary
)
440 value
= get_generic_value(scr
, instance
, class, AStartWorkspace
,
446 tmp
= getString(AStartWorkspace
, value
);
448 if (!tmp
|| strlen(tmp
)==0)
451 if (sscanf(tmp
, "%i", &w
)!=1) {
453 for (i
=0; i
< scr
->workspace_count
; i
++) {
454 if (strcmp(scr
->workspaces
[i
]->name
, tmp
)==0) {
468 wDefaultChangeIcon(WScreen
*scr
, char *instance
, char* class, char *file
)
470 WDDomain
*db
= WDWindowAttributes
;
471 proplist_t icon_value
=NULL
, value
, attr
, key
, def_win
, def_icon
=NULL
;
472 proplist_t dict
= db
->dictionary
;
477 dict
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
479 db
->dictionary
= dict
;
480 value
= PLMakeString(db
->path
);
481 PLSetFilename(dict
, value
);
488 PLSetStringCmpHook(NULL
);
490 if (instance
&& class) {
491 buffer
= wmalloc(strlen(instance
) + strlen(class) + 2);
492 strcat(strcat(strcpy(buffer
, instance
), "."), class);
493 key
= PLMakeString(buffer
);
495 } else if (instance
) {
496 key
= PLMakeString(instance
);
498 key
= PLMakeString(class);
500 key
= PLRetain(AnyWindow
);
504 value
= PLMakeString(file
);
505 icon_value
= PLMakeDictionaryFromEntries(AIcon
, value
, NULL
);
508 if ((def_win
= PLGetDictionaryEntry(dict
, AnyWindow
)) != NULL
) {
509 def_icon
= PLGetDictionaryEntry(def_win
, AIcon
);
512 if (def_icon
&& !strcmp(PLGetString(def_icon
), file
))
516 if ((attr
= PLGetDictionaryEntry(dict
, key
)) != NULL
) {
517 if (PLIsDictionary(attr
)) {
518 if (icon_value
!=NULL
&& !same
)
519 PLMergeDictionaries(attr
, icon_value
);
521 PLRemoveDictionaryEntry(attr
, AIcon
);
523 } else if (icon_value
!=NULL
&& !same
) {
524 PLInsertDictionaryEntry(dict
, key
, icon_value
);
526 if (!wPreferences
.flags
.noupdates
)
531 PLRelease(icon_value
);
533 PLSetStringCmpHook(StringCompareHook
);
538 /* --------------------------- Local ----------------------- */
541 getBool(proplist_t key
, proplist_t value
)
545 if (!PLIsString(value
)) {
546 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
547 PLGetString(key
), "Boolean");
550 val
= PLGetString(value
);
552 if ((val
[1]=='\0' && (val
[0]=='y' || val
[0]=='Y' || val
[0]=='T'
553 || val
[0]=='t' || val
[0]=='1'))
554 || (strcasecmp(val
, "YES")==0 || strcasecmp(val
, "TRUE")==0)) {
557 } else if ((val
[1]=='\0'
558 && (val
[0]=='n' || val
[0]=='N' || val
[0]=='F'
559 || val
[0]=='f' || val
[0]=='0'))
560 || (strcasecmp(val
, "NO")==0 || strcasecmp(val
, "FALSE")==0)) {
564 wwarning(_("can't convert \"%s\" to boolean"), val
);
565 /* We return False if we can't convert to BOOLEAN.
566 * This is because all options defaults to False.
567 * -1 is not checked and thus is interpreted as True,
568 * which is not good.*/
576 * WARNING: Do not free value returned by this!!
579 getString(proplist_t key
, proplist_t value
)
581 if (!PLIsString(value
)) {
582 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
583 PLGetString(key
), "String");
587 return PLGetString(value
);