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
;
86 #ifdef XKB_BUTTON_HINT
87 static proplist_t ANoLanguageButton
;
90 static proplist_t AStartWorkspace
;
92 static proplist_t AIcon
;
95 static proplist_t AnyWindow
;
100 init_wdefaults(WScreen
*scr
)
102 AIcon
= PLMakeString("Icon");
104 ANoTitlebar
= PLMakeString("NoTitlebar");
105 ANoResizebar
= PLMakeString("NoResizebar");
106 ANoMiniaturizeButton
= PLMakeString("NoMiniaturizeButton");
107 ANoCloseButton
= PLMakeString("NoCloseButton");
108 ANoHideOthers
= PLMakeString("NoHideOthers");
109 ANoMouseBindings
= PLMakeString("NoMouseBindings");
110 ANoKeyBindings
= PLMakeString("NoKeyBindings");
111 ANoAppIcon
= PLMakeString("NoAppIcon");
112 AKeepOnTop
= PLMakeString("KeepOnTop");
113 AKeepOnBottom
= PLMakeString("KeepOnBottom");
114 AOmnipresent
= PLMakeString("Omnipresent");
115 ASkipWindowList
= PLMakeString("SkipWindowList");
116 AKeepInsideScreen
= PLMakeString("KeepInsideScreen");
117 AUnfocusable
= PLMakeString("Unfocusable");
118 AAlwaysUserIcon
= PLMakeString("AlwaysUserIcon");
119 AStartMiniaturized
= PLMakeString("StartMiniaturized");
120 AStartHidden
= PLMakeString("StartHidden");
121 AStartMaximized
= PLMakeString("StartMaximized");
122 ADontSaveSession
= PLMakeString("DontSaveSession");
123 AEmulateAppIcon
= PLMakeString("EmulateAppIcon");
124 AFullMaximize
= PLMakeString("FullMaximize");
125 #ifdef XKB_BUTTON_HINT
126 ANoLanguageButton
= PLMakeString("NoLanguageButton");
129 AStartWorkspace
= PLMakeString("StartWorkspace");
131 AnyWindow
= PLMakeString("*");
132 No
= PLMakeString("No");
134 if (!scr->wattribs) {
135 scr->wattribs = PLGetDomain(wAttributeDomainName);
142 get_value(proplist_t dict_win
, proplist_t dict_class
, proplist_t dict_name
,
143 proplist_t dict_any
, proplist_t option
, proplist_t default_value
,
144 Bool useGlobalDefault
)
150 value
= PLGetDictionaryEntry(dict_win
, option
);
156 value
= PLGetDictionaryEntry(dict_name
, option
);
162 value
= PLGetDictionaryEntry(dict_class
, option
);
167 if (!useGlobalDefault
)
171 value
= PLGetDictionaryEntry(dict_any
, option
);
176 return default_value
;
181 *----------------------------------------------------------------------
182 * wDefaultFillAttributes--
183 * Retrieves attributes for the specified instance/class and
184 * fills attr with it. Values that are actually defined are also
185 * set in mask. If useGlobalDefault is True, the default for
186 * all windows ("*") will be used for when no values are found
187 * for that instance/class.
189 *----------------------------------------------------------------------
192 wDefaultFillAttributes(WScreen
*scr
, char *instance
, char *class,
193 WWindowAttributes
*attr
,
194 WWindowAttributes
*mask
,
195 Bool useGlobalDefault
)
198 proplist_t key1
, key2
, key3
;
199 proplist_t dw
, dc
, dn
, da
;
203 if (class && instance
)
204 key1
= PLMakeString(strcat(strcat(strcpy(buffer
,instance
),"."),class));
209 key2
= PLMakeString(instance
);
214 key3
= PLMakeString(class);
222 PLSetStringCmpHook(NULL
);
224 if (WDWindowAttributes
->dictionary
) {
225 dw
= key1
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key1
) : NULL
;
226 dn
= key2
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key2
) : NULL
;
227 dc
= key3
? PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key3
) : NULL
;
228 if (useGlobalDefault
)
229 da
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, AnyWindow
);
245 #define APPLY_VAL(value, flag, attrib) \
246 if (value) {attr->flag = getBool(attrib, value); \
247 if (mask) mask->flag = 1;}
250 value
= get_value(dw
, dc
, dn
, da
, ANoTitlebar
, No
, useGlobalDefault
);
251 APPLY_VAL(value
, no_titlebar
, ANoTitlebar
);
253 value
= get_value(dw
, dc
, dn
, da
, ANoResizebar
, No
, useGlobalDefault
);
254 APPLY_VAL(value
, no_resizebar
, ANoResizebar
);
256 value
= get_value(dw
, dc
, dn
, da
, ANoMiniaturizeButton
, No
, useGlobalDefault
);
257 APPLY_VAL(value
, no_miniaturize_button
, ANoMiniaturizeButton
);
259 value
= get_value(dw
, dc
, dn
, da
, ANoCloseButton
, No
, useGlobalDefault
);
260 APPLY_VAL(value
, no_close_button
, ANoCloseButton
);
262 value
= get_value(dw
, dc
, dn
, da
, ANoHideOthers
, No
, useGlobalDefault
);
263 APPLY_VAL(value
, no_hide_others
, ANoHideOthers
);
265 value
= get_value(dw
, dc
, dn
, da
, ANoMouseBindings
, No
, useGlobalDefault
);
266 APPLY_VAL(value
, no_bind_mouse
, ANoMouseBindings
);
268 value
= get_value(dw
, dc
, dn
, da
, ANoKeyBindings
, No
, useGlobalDefault
);
269 APPLY_VAL(value
, no_bind_keys
, ANoKeyBindings
);
271 value
= get_value(dw
, dc
, dn
, da
, ANoAppIcon
, No
, useGlobalDefault
);
272 APPLY_VAL(value
, no_appicon
, ANoAppIcon
);
274 value
= get_value(dw
, dc
, dn
, da
, AKeepOnTop
, No
, useGlobalDefault
);
275 APPLY_VAL(value
, floating
, AKeepOnTop
);
277 value
= get_value(dw
, dc
, dn
, da
, AKeepOnBottom
, No
, useGlobalDefault
);
278 APPLY_VAL(value
, sunken
, AKeepOnBottom
);
280 value
= get_value(dw
, dc
, dn
, da
, AOmnipresent
, No
, useGlobalDefault
);
281 APPLY_VAL(value
, omnipresent
, AOmnipresent
);
283 value
= get_value(dw
, dc
, dn
, da
, ASkipWindowList
, No
, useGlobalDefault
);
284 APPLY_VAL(value
, skip_window_list
, ASkipWindowList
);
286 value
= get_value(dw
, dc
, dn
, da
, AKeepInsideScreen
, No
, useGlobalDefault
);
287 APPLY_VAL(value
, dont_move_off
, AKeepInsideScreen
);
289 value
= get_value(dw
, dc
, dn
, da
, AUnfocusable
, No
, useGlobalDefault
);
290 APPLY_VAL(value
, no_focusable
, AUnfocusable
);
292 value
= get_value(dw
, dc
, dn
, da
, AAlwaysUserIcon
, No
, useGlobalDefault
);
293 APPLY_VAL(value
, always_user_icon
, AAlwaysUserIcon
);
295 value
= get_value(dw
, dc
, dn
, da
, AStartMiniaturized
, No
, useGlobalDefault
);
296 APPLY_VAL(value
, start_miniaturized
, AStartMiniaturized
);
298 value
= get_value(dw
, dc
, dn
, da
, AStartHidden
, No
, useGlobalDefault
);
299 APPLY_VAL(value
, start_hidden
, AStartHidden
);
301 value
= get_value(dw
, dc
, dn
, da
, AStartMaximized
, No
, useGlobalDefault
);
302 APPLY_VAL(value
, start_maximized
, AStartMaximized
);
304 value
= get_value(dw
, dc
, dn
, da
, ADontSaveSession
, No
, useGlobalDefault
);
305 APPLY_VAL(value
, dont_save_session
, ADontSaveSession
);
307 value
= get_value(dw
, dc
, dn
, da
, AEmulateAppIcon
, No
, useGlobalDefault
);
308 APPLY_VAL(value
, emulate_appicon
, AEmulateAppIcon
);
310 value
= get_value(dw
, dc
, dn
, da
, AFullMaximize
, No
, useGlobalDefault
);
311 APPLY_VAL(value
, full_maximize
, AFullMaximize
);
313 #ifdef XKB_BUTTON_HINT
314 value
= get_value(dw
, dc
, dn
, da
, ANoLanguageButton
, No
, useGlobalDefault
);
315 APPLY_VAL(value
, no_language_button
, ANoLanguageButton
);
319 PLSetStringCmpHook(StringCompareHook
);
325 get_generic_value(WScreen
*scr
, char *instance
, char *class, proplist_t option
,
328 proplist_t value
, key
, dict
;
333 PLSetStringCmpHook(NULL
);
335 if (class && instance
) {
336 key
= PLMakeString(strcat(strcat(strcpy(buffer
,instance
),"."),class));
338 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
342 value
= PLGetDictionaryEntry(dict
, option
);
346 if (!value
&& instance
) {
347 key
= PLMakeString(instance
);
349 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
353 value
= PLGetDictionaryEntry(dict
, option
);
357 if (!value
&& class) {
358 key
= PLMakeString(class);
360 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, key
);
364 value
= PLGetDictionaryEntry(dict
, option
);
368 if (!value
&& !noDefault
) {
369 dict
= PLGetDictionaryEntry(WDWindowAttributes
->dictionary
, AnyWindow
);
372 value
= PLGetDictionaryEntry(dict
, option
);
376 PLSetStringCmpHook(StringCompareHook
);
383 wDefaultGetIconFile(WScreen
*scr
, char *instance
, char *class,
393 if (!WDWindowAttributes
->dictionary
)
396 value
= get_generic_value(scr
, instance
, class, AIcon
, noDefault
);
401 tmp
= getString(AIcon
, value
);
408 wDefaultGetImage(WScreen
*scr
, char *winstance
, char *wclass
)
414 file_name
= wDefaultGetIconFile(scr
, winstance
, wclass
, False
);
418 path
= FindImage(wPreferences
.icon_path
, file_name
);
421 wwarning(_("could not find icon file \"%s\""), file_name
);
425 image
= RLoadImage(scr
->rcontext
, path
, 0);
427 wwarning(_("error loading image file \"%s\""), path
, RMessageForError(RErrorCode
));
431 image
= wIconValidateIconSize(scr
, image
);
438 wDefaultGetStartWorkspace(WScreen
*scr
, char *instance
, char *class)
448 if (!WDWindowAttributes
->dictionary
)
451 value
= get_generic_value(scr
, instance
, class, AStartWorkspace
,
457 tmp
= getString(AStartWorkspace
, value
);
459 if (!tmp
|| strlen(tmp
)==0)
462 if (sscanf(tmp
, "%i", &w
)!=1) {
464 for (i
=0; i
< scr
->workspace_count
; i
++) {
465 if (strcmp(scr
->workspaces
[i
]->name
, tmp
)==0) {
479 wDefaultChangeIcon(WScreen
*scr
, char *instance
, char* class, char *file
)
481 WDDomain
*db
= WDWindowAttributes
;
482 proplist_t icon_value
=NULL
, value
, attr
, key
, def_win
, def_icon
=NULL
;
483 proplist_t dict
= db
->dictionary
;
488 dict
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
490 db
->dictionary
= dict
;
491 value
= PLMakeString(db
->path
);
492 PLSetFilename(dict
, value
);
499 PLSetStringCmpHook(NULL
);
501 if (instance
&& class) {
502 buffer
= wmalloc(strlen(instance
) + strlen(class) + 2);
503 strcat(strcat(strcpy(buffer
, instance
), "."), class);
504 key
= PLMakeString(buffer
);
506 } else if (instance
) {
507 key
= PLMakeString(instance
);
509 key
= PLMakeString(class);
511 key
= PLRetain(AnyWindow
);
515 value
= PLMakeString(file
);
516 icon_value
= PLMakeDictionaryFromEntries(AIcon
, value
, NULL
);
519 if ((def_win
= PLGetDictionaryEntry(dict
, AnyWindow
)) != NULL
) {
520 def_icon
= PLGetDictionaryEntry(def_win
, AIcon
);
523 if (def_icon
&& !strcmp(PLGetString(def_icon
), file
))
527 if ((attr
= PLGetDictionaryEntry(dict
, key
)) != NULL
) {
528 if (PLIsDictionary(attr
)) {
529 if (icon_value
!=NULL
&& !same
)
530 PLMergeDictionaries(attr
, icon_value
);
532 PLRemoveDictionaryEntry(attr
, AIcon
);
534 } else if (icon_value
!=NULL
&& !same
) {
535 PLInsertDictionaryEntry(dict
, key
, icon_value
);
537 if (!wPreferences
.flags
.noupdates
)
542 PLRelease(icon_value
);
544 PLSetStringCmpHook(StringCompareHook
);
549 /* --------------------------- Local ----------------------- */
552 getBool(proplist_t key
, proplist_t value
)
556 if (!PLIsString(value
)) {
557 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
558 PLGetString(key
), "Boolean");
561 val
= PLGetString(value
);
563 if ((val
[1]=='\0' && (val
[0]=='y' || val
[0]=='Y' || val
[0]=='T'
564 || val
[0]=='t' || val
[0]=='1'))
565 || (strcasecmp(val
, "YES")==0 || strcasecmp(val
, "TRUE")==0)) {
568 } else if ((val
[1]=='\0'
569 && (val
[0]=='n' || val
[0]=='N' || val
[0]=='F'
570 || val
[0]=='f' || val
[0]=='0'))
571 || (strcasecmp(val
, "NO")==0 || strcasecmp(val
, "FALSE")==0)) {
575 wwarning(_("can't convert \"%s\" to boolean"), val
);
576 /* We return False if we can't convert to BOOLEAN.
577 * This is because all options defaults to False.
578 * -1 is not checked and thus is interpreted as True,
579 * which is not good.*/
587 * WARNING: Do not free value returned by this!!
590 getString(proplist_t key
, proplist_t value
)
592 if (!PLIsString(value
)) {
593 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
594 PLGetString(key
), "String");
598 return PLGetString(value
);