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 AStartHidden
; /* app */
82 static proplist_t ADontSaveSession
; /* app */
83 static proplist_t AEmulateAppIcon
;
85 static proplist_t AStartWorkspace
;
87 static proplist_t AIcon
;
90 static proplist_t AnyWindow
;
95 init_wdefaults(WScreen
*scr
)
97 AIcon
= PLMakeString("Icon");
99 ANoTitlebar
= PLMakeString("NoTitlebar");
100 ANoResizebar
= PLMakeString("NoResizebar");
101 ANoMiniaturizeButton
= PLMakeString("NoMiniaturizeButton");
102 ANoCloseButton
= PLMakeString("NoCloseButton");
103 ANoHideOthers
= PLMakeString("NoHideOthers");
104 ANoMouseBindings
= PLMakeString("NoMouseBindings");
105 ANoKeyBindings
= PLMakeString("NoKeyBindings");
106 ANoAppIcon
= PLMakeString("NoAppIcon");
107 AKeepOnTop
= PLMakeString("KeepOnTop");
108 AKeepOnBottom
= PLMakeString("KeepOnBottom");
109 AOmnipresent
= PLMakeString("Omnipresent");
110 ASkipWindowList
= PLMakeString("SkipWindowList");
111 AKeepInsideScreen
= PLMakeString("KeepInsideScreen");
112 AUnfocusable
= PLMakeString("Unfocusable");
113 AAlwaysUserIcon
= PLMakeString("AlwaysUserIcon");
114 AStartMiniaturized
= PLMakeString("StartMiniaturized");
115 AStartHidden
= PLMakeString("StartHidden");
116 ADontSaveSession
= PLMakeString("DontSaveSession");
117 AEmulateAppIcon
= PLMakeString("EmulateAppIcon");
119 AStartWorkspace
= PLMakeString("StartWorkspace");
121 AnyWindow
= PLMakeString("*");
122 No
= PLMakeString("No");
124 if (!scr->wattribs) {
125 scr->wattribs = PLGetDomain(wAttributeDomainName);
132 get_value(proplist_t dict_win
, proplist_t dict_class
, proplist_t dict_name
,
133 proplist_t dict_any
, proplist_t option
, proplist_t default_value
,
134 Bool useGlobalDefault
)
140 value
= PLGetDictionaryEntry(dict_win
, option
);
146 value
= PLGetDictionaryEntry(dict_name
, option
);
152 value
= PLGetDictionaryEntry(dict_class
, option
);
157 if (!useGlobalDefault
)
161 value
= PLGetDictionaryEntry(dict_any
, option
);
166 return default_value
;
171 wDefaultFillAttributes(WScreen
*scr
, char *instance
, char *class,
172 WWindowAttributes
*attr
, Bool useGlobalDefault
)
175 proplist_t key1
, key2
, key3
;
176 proplist_t dw
, dc
, dn
, da
;
180 if (class && instance
)
181 key1
= PLMakeString(strcat(strcat(strcpy(buffer
,instance
),"."),class));
186 key2
= PLMakeString(instance
);
191 key3
= PLMakeString(class);
199 PLSetStringCmpHook(NULL
);
201 if (WDWindowAttributes
->dictionary
) {
202 dw
= key1
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key1
) : NULL
;
203 dn
= key2
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key2
) : NULL
;
204 dc
= key3
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key3
) : NULL
;
205 if (useGlobalDefault
)
206 da
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, AnyWindow
);
223 value
= get_value(dw
, dc
, dn
, da
, ANoTitlebar
, No
, useGlobalDefault
);
225 attr
->no_titlebar
= getBool(ANoTitlebar
, value
);
227 value
= get_value(dw
, dc
, dn
, da
, ANoResizebar
, No
, useGlobalDefault
);
229 attr
->no_resizebar
= getBool(ANoResizebar
, value
);
231 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizeButton
, No
, useGlobalDefault
);
233 attr
->no_miniaturize_button
= getBool(ANoMiniaturizeButton
, value
);
235 value
= get_value(dw
, dc
, dn
, da
, ANoCloseButton
, No
, useGlobalDefault
);
237 attr
->no_close_button
= getBool(ANoCloseButton
, value
);
239 value
= get_value(dw
, dc
, dn
, da
, ANoHideOthers
, No
, useGlobalDefault
);
241 attr
->no_hide_others
= getBool(ANoHideOthers
, value
);
243 value
= get_value(dw
, dc
, dn
, da
, ANoMouseBindings
, No
, useGlobalDefault
);
245 attr
->no_bind_mouse
= getBool(ANoMouseBindings
, value
);
247 value
= get_value(dw
, dc
, dn
, da
, ANoKeyBindings
, No
, useGlobalDefault
);
249 attr
->no_bind_keys
= getBool(ANoKeyBindings
, value
);
251 value
= get_value(dw
, dc
, dn
, da
, ANoAppIcon
, No
, useGlobalDefault
);
253 attr
->no_appicon
= getBool(ANoAppIcon
, value
);
255 value
= get_value(dw
, dc
, dn
, da
, AKeepOnTop
, No
, useGlobalDefault
);
257 attr
->floating
= getBool(AKeepOnTop
, value
);
259 value
= get_value(dw
, dc
, dn
, da
, AKeepOnBottom
, No
, useGlobalDefault
);
261 attr
->floating
= getBool(AKeepOnBottom
, value
);
263 value
= get_value(dw
, dc
, dn
, da
, AOmnipresent
, No
, useGlobalDefault
);
265 attr
->omnipresent
= getBool(AOmnipresent
, value
);
267 value
= get_value(dw
, dc
, dn
, da
, ASkipWindowList
, No
, useGlobalDefault
);
269 attr
->skip_window_list
= getBool(ASkipWindowList
, value
);
271 value
= get_value(dw
, dc
, dn
, da
, AKeepInsideScreen
, No
, useGlobalDefault
);
273 attr
->dont_move_off
= getBool(AKeepInsideScreen
, value
);
275 value
= get_value(dw
, dc
, dn
, da
, AUnfocusable
, No
, useGlobalDefault
);
277 attr
->no_focusable
= getBool(AUnfocusable
, value
);
279 value
= get_value(dw
, dc
, dn
, da
, AAlwaysUserIcon
, No
, useGlobalDefault
);
281 attr
->always_user_icon
= getBool(AAlwaysUserIcon
, value
);
283 value
= get_value(dw
, dc
, dn
, da
, AStartMiniaturized
, No
, useGlobalDefault
);
285 attr
->start_miniaturized
= getBool(AStartMiniaturized
, value
);
287 value
= get_value(dw
, dc
, dn
, da
, AStartHidden
, No
, useGlobalDefault
);
289 attr
->start_hidden
= getBool(AStartHidden
, value
);
291 value
= get_value(dw
, dc
, dn
, da
, ADontSaveSession
, No
, useGlobalDefault
);
293 attr
->dont_save_session
= getBool(ADontSaveSession
, value
);
295 value
= get_value(dw
, dc
, dn
, da
, AEmulateAppIcon
, No
, useGlobalDefault
);
297 attr
->emulate_appicon
= getBool(AEmulateAppIcon
, value
);
300 PLSetStringCmpHook(StringCompareHook
);
306 get_generic_value(WScreen
*scr
, char *instance
, char *class, proplist_t option
,
309 proplist_t value
, key
, dict
;
314 PLSetStringCmpHook(NULL
);
316 if (class && instance
) {
317 key
= PLMakeString(strcat(strcat(strcpy(buffer
,instance
),"."),class));
319 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
323 value
= PLGetDictionaryEntry(dict
, option
);
327 if (!value
&& instance
) {
328 key
= PLMakeString(instance
);
330 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
334 value
= PLGetDictionaryEntry(dict
, option
);
338 if (!value
&& class) {
339 key
= PLMakeString(class);
341 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
345 value
= PLGetDictionaryEntry(dict
, option
);
349 if (!value
&& !noDefault
) {
350 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, AnyWindow
);
353 value
= PLGetDictionaryEntry(dict
, option
);
357 PLSetStringCmpHook(StringCompareHook
);
364 wDefaultGetIconFile(WScreen
*scr
, char *instance
, char *class,
374 if (!WDWindowAttributes
->dictionary
)
377 value
= get_generic_value(scr
, instance
, class, AIcon
, noDefault
);
382 tmp
= getString(AIcon
, value
);
389 wDefaultGetImage(WScreen
*scr
, char *winstance
, char *wclass
)
395 file_name
= wDefaultGetIconFile(scr
, winstance
, wclass
, False
);
399 path
= FindImage(wPreferences
.icon_path
, file_name
);
402 wwarning(_("could not find icon file \"%s\""), file_name
);
406 image
= RLoadImage(scr
->rcontext
, path
, 0);
408 wwarning(_("error loading image file \"%s\""), path
, RMessageForError(RErrorCode
));
412 image
= wIconValidateIconSize(scr
, image
);
419 wDefaultGetStartWorkspace(WScreen
*scr
, char *instance
, char *class)
429 if (!WDWindowAttributes
->dictionary
)
432 value
= get_generic_value(scr
, instance
, class, AStartWorkspace
,
438 tmp
= getString(AStartWorkspace
, value
);
440 if (!tmp
|| strlen(tmp
)==0)
443 if (sscanf(tmp
, "%i", &w
)!=1) {
445 for (i
=0; i
< scr
->workspace_count
; i
++) {
446 if (strcmp(scr
->workspaces
[i
]->name
, tmp
)==0) {
460 wDefaultChangeIcon(WScreen
*scr
, char *instance
, char* class, char *file
)
462 WDDomain
*db
= WDWindowAttributes
;
463 proplist_t icon_value
=NULL
, value
, attr
, key
, def_win
, def_icon
=NULL
;
464 proplist_t dict
= db
->dictionary
;
469 dict
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
471 db
->dictionary
= dict
;
472 value
= PLMakeString(db
->path
);
473 PLSetFilename(dict
, value
);
480 PLSetStringCmpHook(NULL
);
482 if (instance
&& class) {
483 buffer
= wmalloc(strlen(instance
) + strlen(class) + 2);
484 strcat(strcat(strcpy(buffer
, instance
), "."), class);
485 key
= PLMakeString(buffer
);
486 if (PLGetDictionaryEntry(dict
, key
)==NULL
) {
488 key
= PLMakeString(instance
);
489 if (PLGetDictionaryEntry(dict
, key
)==NULL
) {
491 key
= PLMakeString(class);
492 if (PLGetDictionaryEntry(dict
, key
)==NULL
) {
494 key
= PLMakeString(buffer
);
499 } else if (instance
) {
500 key
= PLMakeString(instance
);
502 key
= PLMakeString(class);
504 key
= PLRetain(AnyWindow
);
508 value
= PLMakeString(file
);
509 icon_value
= PLMakeDictionaryFromEntries(AIcon
, value
, NULL
);
512 if ((def_win
= PLGetDictionaryEntry(dict
, AnyWindow
)) != NULL
) {
513 def_icon
= PLGetDictionaryEntry(def_win
, AIcon
);
516 if (def_icon
&& !strcmp(PLGetString(def_icon
), file
))
520 if((attr
= PLGetDictionaryEntry(dict
, key
)) != NULL
) {
521 if (PLIsDictionary(attr
)) {
522 if (icon_value
!=NULL
&& !same
)
523 PLMergeDictionaries(attr
, icon_value
);
525 PLRemoveDictionaryEntry(attr
, AIcon
);
528 else if (icon_value
!=NULL
&& !same
) {
529 PLInsertDictionaryEntry(dict
, key
, icon_value
);
531 if (!wPreferences
.flags
.noupdates
)
536 PLRelease(icon_value
);
538 PLSetStringCmpHook(StringCompareHook
);
543 /* --------------------------- Local ----------------------- */
546 getBool(proplist_t key
, proplist_t value
)
550 if (!PLIsString(value
)) {
551 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
552 PLGetString(key
), "Boolean");
555 val
= PLGetString(value
);
557 if ((val
[1]=='\0' && (val
[0]=='y' || val
[0]=='Y' || val
[0]=='T'
558 || val
[0]=='t' || val
[0]=='1'))
559 || (strcasecmp(val
, "YES")==0 || strcasecmp(val
, "TRUE")==0)) {
562 } else if ((val
[1]=='\0'
563 && (val
[0]=='n' || val
[0]=='N' || val
[0]=='F'
564 || val
[0]=='f' || val
[0]=='0'))
565 || (strcasecmp(val
, "NO")==0 || strcasecmp(val
, "FALSE")==0)) {
569 wwarning(_("can't convert \"%s\" to boolean"), val
);
570 /* We return False if we can't convert to BOOLEAN.
571 * This is because all options defaults to False.
572 * -1 is not checked and thus is interpreted as True,
573 * which is not good.*/
581 * WARNING: Do not free value returned by this!!
584 getString(proplist_t key
, proplist_t value
)
586 if (!PLIsString(value
)) {
587 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
588 PLGetString(key
), "String");
592 return PLGetString(value
);