1 /* wdefaults.c - window specific defaults
3 * WindowMaker 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 AOmnipresent
;
75 static proplist_t ASkipWindowList
;
76 static proplist_t AKeepInsideScreen
;
77 static proplist_t AUnfocusable
;
78 static proplist_t AAlwaysUserIcon
;
79 static proplist_t AStartMiniaturized
;
80 static proplist_t AStartHidden
; /* app */
81 static proplist_t ADontSaveSession
; /* app */
82 static proplist_t AEmulateAppIcon
;
84 static proplist_t AStartWorkspace
;
86 static proplist_t AIcon
;
89 static proplist_t AnyWindow
;
94 init_wdefaults(WScreen
*scr
)
96 AIcon
= PLMakeString("Icon");
98 ANoTitlebar
= PLMakeString("NoTitlebar");
99 ANoResizebar
= PLMakeString("NoResizebar");
100 ANoMiniaturizeButton
= PLMakeString("NoMiniaturizeButton");
101 ANoCloseButton
= PLMakeString("NoCloseButton");
102 ANoHideOthers
= PLMakeString("NoHideOthers");
103 ANoMouseBindings
= PLMakeString("NoMouseBindings");
104 ANoKeyBindings
= PLMakeString("NoKeyBindings");
105 ANoAppIcon
= PLMakeString("NoAppIcon");
106 AKeepOnTop
= PLMakeString("KeepOnTop");
107 AOmnipresent
= PLMakeString("Omnipresent");
108 ASkipWindowList
= PLMakeString("SkipWindowList");
109 AKeepInsideScreen
= PLMakeString("KeepInsideScreen");
110 AUnfocusable
= PLMakeString("Unfocusable");
111 AAlwaysUserIcon
= PLMakeString("AlwaysUserIcon");
112 AStartMiniaturized
= PLMakeString("StartMiniaturized");
113 AStartHidden
= PLMakeString("StartHidden");
114 ADontSaveSession
= PLMakeString("DontSaveSession");
115 AEmulateAppIcon
= PLMakeString("EmulateAppIcon");
117 AStartWorkspace
= PLMakeString("StartWorkspace");
119 AnyWindow
= PLMakeString("*");
120 No
= PLMakeString("No");
122 if (!scr->wattribs) {
123 scr->wattribs = PLGetDomain(wAttributeDomainName);
130 get_value(proplist_t dict_win
, proplist_t dict_class
, proplist_t dict_name
,
131 proplist_t dict_any
, proplist_t option
, proplist_t default_value
,
132 Bool useGlobalDefault
)
138 value
= PLGetDictionaryEntry(dict_win
, option
);
144 value
= PLGetDictionaryEntry(dict_name
, option
);
150 value
= PLGetDictionaryEntry(dict_class
, option
);
155 if (!useGlobalDefault
)
159 value
= PLGetDictionaryEntry(dict_any
, option
);
164 return default_value
;
169 wDefaultFillAttributes(WScreen
*scr
, char *instance
, char *class,
170 WWindowAttributes
*attr
, Bool useGlobalDefault
)
173 proplist_t key1
, key2
, key3
;
174 proplist_t dw
, dc
, dn
, da
;
178 if (class && instance
)
179 key1
= PLMakeString(strcat(strcat(strcpy(buffer
,instance
),"."),class));
184 key2
= PLMakeString(instance
);
189 key3
= PLMakeString(class);
197 PLSetStringCmpHook(NULL
);
199 if (WDWindowAttributes
->dictionary
) {
200 dw
= key1
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key1
) : NULL
;
201 dn
= key2
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key2
) : NULL
;
202 dc
= key3
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key3
) : NULL
;
203 if (useGlobalDefault
)
204 da
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, AnyWindow
);
221 value
= get_value(dw
, dc
, dn
, da
, ANoTitlebar
, No
, useGlobalDefault
);
223 attr
->no_titlebar
= getBool(ANoTitlebar
, value
);
225 value
= get_value(dw
, dc
, dn
, da
, ANoResizebar
, No
, useGlobalDefault
);
227 attr
->no_resizebar
= getBool(ANoResizebar
, value
);
229 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizeButton
, No
, useGlobalDefault
);
231 attr
->no_miniaturize_button
= getBool(ANoMiniaturizeButton
, value
);
233 value
= get_value(dw
, dc
, dn
, da
, ANoCloseButton
, No
, useGlobalDefault
);
235 attr
->no_close_button
= getBool(ANoCloseButton
, value
);
237 value
= get_value(dw
, dc
, dn
, da
, ANoHideOthers
, No
, useGlobalDefault
);
239 attr
->no_hide_others
= getBool(ANoHideOthers
, value
);
241 value
= get_value(dw
, dc
, dn
, da
, ANoMouseBindings
, No
, useGlobalDefault
);
243 attr
->no_bind_mouse
= getBool(ANoMouseBindings
, value
);
245 value
= get_value(dw
, dc
, dn
, da
, ANoKeyBindings
, No
, useGlobalDefault
);
247 attr
->no_bind_keys
= getBool(ANoKeyBindings
, value
);
249 value
= get_value(dw
, dc
, dn
, da
, ANoAppIcon
, No
, useGlobalDefault
);
251 attr
->no_appicon
= getBool(ANoAppIcon
, value
);
253 value
= get_value(dw
, dc
, dn
, da
, AKeepOnTop
, No
, useGlobalDefault
);
255 attr
->floating
= getBool(AKeepOnTop
, value
);
257 value
= get_value(dw
, dc
, dn
, da
, AOmnipresent
, No
, useGlobalDefault
);
259 attr
->omnipresent
= getBool(AOmnipresent
, value
);
261 value
= get_value(dw
, dc
, dn
, da
, ASkipWindowList
, No
, useGlobalDefault
);
263 attr
->skip_window_list
= getBool(ASkipWindowList
, value
);
265 value
= get_value(dw
, dc
, dn
, da
, AKeepInsideScreen
, No
, useGlobalDefault
);
267 attr
->dont_move_off
= getBool(AKeepInsideScreen
, value
);
269 value
= get_value(dw
, dc
, dn
, da
, AUnfocusable
, No
, useGlobalDefault
);
271 attr
->no_focusable
= getBool(AUnfocusable
, value
);
273 value
= get_value(dw
, dc
, dn
, da
, AAlwaysUserIcon
, No
, useGlobalDefault
);
275 attr
->always_user_icon
= getBool(AAlwaysUserIcon
, value
);
277 value
= get_value(dw
, dc
, dn
, da
, AStartMiniaturized
, No
, useGlobalDefault
);
279 attr
->start_miniaturized
= getBool(AStartMiniaturized
, value
);
281 value
= get_value(dw
, dc
, dn
, da
, AStartHidden
, No
, useGlobalDefault
);
283 attr
->start_hidden
= getBool(AStartHidden
, value
);
285 value
= get_value(dw
, dc
, dn
, da
, ADontSaveSession
, No
, useGlobalDefault
);
287 attr
->dont_save_session
= getBool(ADontSaveSession
, value
);
289 value
= get_value(dw
, dc
, dn
, da
, AEmulateAppIcon
, No
, useGlobalDefault
);
291 attr
->emulate_appicon
= getBool(AEmulateAppIcon
, value
);
294 PLSetStringCmpHook(StringCompareHook
);
300 get_generic_value(WScreen
*scr
, char *instance
, char *class, proplist_t option
,
303 proplist_t value
, key
, dict
;
308 PLSetStringCmpHook(NULL
);
310 if (class && instance
) {
311 key
= PLMakeString(strcat(strcat(strcpy(buffer
,instance
),"."),class));
313 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
317 value
= PLGetDictionaryEntry(dict
, option
);
321 if (!value
&& instance
) {
322 key
= PLMakeString(instance
);
324 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
328 value
= PLGetDictionaryEntry(dict
, option
);
332 if (!value
&& class) {
333 key
= PLMakeString(class);
335 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
339 value
= PLGetDictionaryEntry(dict
, option
);
343 if (!value
&& !noDefault
) {
344 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, AnyWindow
);
347 value
= PLGetDictionaryEntry(dict
, option
);
351 PLSetStringCmpHook(StringCompareHook
);
358 wDefaultGetIconFile(WScreen
*scr
, char *instance
, char *class,
368 if (!WDWindowAttributes
->dictionary
)
371 value
= get_generic_value(scr
, instance
, class, AIcon
, noDefault
);
376 tmp
= getString(AIcon
, value
);
383 wDefaultGetImage(WScreen
*scr
, char *winstance
, char *wclass
)
389 file_name
= wDefaultGetIconFile(scr
, winstance
, wclass
, False
);
393 path
= FindImage(wPreferences
.icon_path
, file_name
);
396 wwarning(_("could not find icon file \"%s\""), file_name
);
400 image
= RLoadImage(scr
->rcontext
, path
, 0);
402 wwarning(_("error loading image file \"%s\""), path
, RErrorString
);
406 image
= wIconValidateIconSize(scr
, image
);
413 wDefaultGetStartWorkspace(WScreen
*scr
, char *instance
, char *class)
423 if (!WDWindowAttributes
->dictionary
)
426 value
= get_generic_value(scr
, instance
, class, AStartWorkspace
,
432 tmp
= getString(AStartWorkspace
, value
);
434 if (!tmp
|| strlen(tmp
)==0)
437 if (sscanf(tmp
, "%i", &w
)!=1) {
439 for (i
=0; i
< scr
->workspace_count
; i
++) {
440 if (strcmp(scr
->workspaces
[i
]->name
, tmp
)==0) {
454 wDefaultChangeIcon(WScreen
*scr
, char *instance
, char* class, char *file
)
456 WDDomain
*db
= WDWindowAttributes
;
457 proplist_t icon_value
=NULL
, value
, attr
, key
, def_win
, def_icon
=NULL
;
458 proplist_t dict
= db
->dictionary
;
463 dict
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
465 db
->dictionary
= dict
;
466 value
= PLMakeString(db
->path
);
467 PLSetFilename(dict
, value
);
474 PLSetStringCmpHook(NULL
);
476 if (instance
&& class) {
477 buffer
= wmalloc(strlen(instance
) + strlen(class) + 2);
478 strcat(strcat(strcpy(buffer
, instance
), "."), class);
479 key
= PLMakeString(buffer
);
480 if (PLGetDictionaryEntry(dict
, key
)==NULL
) {
482 key
= PLMakeString(instance
);
483 if (PLGetDictionaryEntry(dict
, key
)==NULL
) {
485 key
= PLMakeString(class);
486 if (PLGetDictionaryEntry(dict
, key
)==NULL
) {
488 key
= PLMakeString(buffer
);
493 } else if (instance
) {
494 key
= PLMakeString(instance
);
496 key
= PLMakeString(class);
498 key
= PLRetain(AnyWindow
);
502 value
= PLMakeString(file
);
503 icon_value
= PLMakeDictionaryFromEntries(AIcon
, value
, NULL
);
506 if ((def_win
= PLGetDictionaryEntry(dict
, AnyWindow
)) != NULL
) {
507 def_icon
= PLGetDictionaryEntry(def_win
, AIcon
);
510 if (def_icon
&& !strcmp(PLGetString(def_icon
), file
))
514 if((attr
= PLGetDictionaryEntry(dict
, key
)) != NULL
) {
515 if (PLIsDictionary(attr
)) {
516 if (icon_value
!=NULL
&& !same
)
517 PLMergeDictionaries(attr
, icon_value
);
519 PLRemoveDictionaryEntry(attr
, AIcon
);
522 else if (icon_value
!=NULL
&& !same
) {
523 PLInsertDictionaryEntry(dict
, key
, icon_value
);
529 PLRelease(icon_value
);
531 PLSetStringCmpHook(StringCompareHook
);
536 /* --------------------------- Local ----------------------- */
539 getBool(proplist_t key
, proplist_t value
)
543 if (!PLIsString(value
)) {
544 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
545 PLGetString(key
), "Boolean");
548 val
= PLGetString(value
);
550 if ((val
[1]=='\0' && (val
[0]=='y' || val
[0]=='Y' || val
[0]=='T'
551 || val
[0]=='t' || val
[0]=='1'))
552 || (strcasecmp(val
, "YES")==0 || strcasecmp(val
, "TRUE")==0)) {
555 } else if ((val
[1]=='\0'
556 && (val
[0]=='n' || val
[0]=='N' || val
[0]=='F'
557 || val
[0]=='f' || val
[0]=='0'))
558 || (strcasecmp(val
, "NO")==0 || strcasecmp(val
, "FALSE")==0)) {
562 wwarning(_("can't convert \"%s\" to boolean"), val
);
563 /* We return False if we can't convert to BOOLEAN.
564 * This is because all options defaults to False.
565 * -1 is not checked and thus is interpreted as True,
566 * which is not good.*/
574 * WARNING: Do not free value returned by this!!
577 getString(proplist_t key
, proplist_t value
)
579 if (!PLIsString(value
)) {
580 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
581 PLGetString(key
), "String");
585 return PLGetString(value
);