Bug fixes for 0.20.3 pre-release 2
[wmaker-crm.git] / src / defaults.c
blob40669ead00624baa68a74b9ad7b5e6a902b1c569
1 /* defaults.c - manage configuration through defaults db
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
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,
20 * USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <ctype.h>
30 #include <time.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <limits.h>
35 #ifndef PATH_MAX
36 #define PATH_MAX DEFAULT_PATH_MAX
37 #endif
39 #include <X11/Xlib.h>
40 #include <X11/Xutil.h>
41 #include <X11/keysym.h>
43 #include <wraster.h>
46 #include "WindowMaker.h"
47 #include "wcore.h"
48 #include "framewin.h"
49 #include "window.h"
50 #include "texture.h"
51 #include "screen.h"
52 #include "resources.h"
53 #include "defaults.h"
54 #include "keybind.h"
55 #include "xmodifier.h"
56 #include "icon.h"
57 #include "funcs.h"
58 #include "actions.h"
59 #include "dock.h"
60 #include "workspace.h"
64 * Our own proplist reader parser. This one will not accept any
65 * syntax errors and is more descriptive in the error messages.
66 * It also doesn't seem to crash.
68 extern proplist_t ReadProplistFromFile(char *file);
71 /***** Global *****/
73 extern WDDomain *WDWindowMaker;
74 extern WDDomain *WDWindowAttributes;
75 extern WDDomain *WDRootMenu;
77 extern int wScreenCount;
80 extern proplist_t wDomainName;
81 extern proplist_t wAttributeDomainName;
83 extern WPreferences wPreferences;
85 extern WShortKey wKeyBindings[WKBD_LAST];
87 typedef struct {
88 char *key;
89 char *default_value;
90 void *extra_data;
91 void *addr;
92 int (*convert)();
93 int (*update)();
94 proplist_t plkey;
95 proplist_t plvalue;
96 } WDefaultEntry;
99 /* used to map strings to integers */
100 typedef struct {
101 char *string;
102 short value;
103 char is_alias;
104 } WOptionEnumeration;
108 /* type converters */
109 static int getBool();
110 static int getInt();
111 static int getCoord();
112 #if 0
113 /* this is not used yet */
114 static int getString();
115 #endif
116 static int getPathList();
117 static int getEnum();
118 static int getTexture();
119 static int getWSBackground();
120 static int getFont();
121 static int getColor();
122 static int getKeybind();
123 static int getModMask();
126 /* value setting functions */
127 static int setJustify();
128 static int setIfDockPresent();
129 static int setStickyIcons();
131 static int setPositive();
133 static int setWidgetColor();
134 static int setIconTile();
135 static int setWinTitleFont();
136 static int setMenuTitleFont();
137 static int setMenuTextFont();
138 static int setIconTitleFont();
139 static int setDisplayFont();
140 static int setWTitleColor();
141 static int setFTitleBack();
142 static int setPTitleBack();
143 static int setUTitleBack();
144 static int setWorkspaceBack();
145 static int setMenuTitleColor();
146 static int setMenuTextColor();
147 static int setMenuDisabledColor();
148 static int setMenuTitleBack();
149 static int setMenuTextBack();
150 static int setHightlight();
151 static int setHightlightText();
152 static int setKeyGrab();
153 static int setDoubleClick();
154 static int setIconPosition();
156 static int setClipTitleFont();
157 static int setClipTitleColor();
162 * Tables to convert strings to enumeration values.
163 * Values stored are char
167 /* WARNING: sum of length of all value strings must not exceed
168 * this value */
169 #define TOTAL_VALUES_LENGTH 80
173 static WOptionEnumeration seFocusModes[] = {
174 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
175 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
176 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
177 {NULL, 0, 0}
180 static WOptionEnumeration seColormapModes[] = {
181 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
182 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
183 {NULL, 0, 0}
186 static WOptionEnumeration sePlacements[] = {
187 {"Auto", WPM_SMART, 0}, {"Smart", WPM_SMART, 1},
188 {"Cascade", WPM_CASCADE, 0},
189 {"Random", WPM_RANDOM, 0},
190 {"Manual", WPM_MANUAL, 0},
191 {NULL, 0, 0}
194 static WOptionEnumeration seGeomDisplays[] = {
195 {"Center", WDIS_CENTER, 0},
196 {"Corner", WDIS_TOPLEFT, 0},
197 {"Floating", WDIS_FRAME_CENTER, 0},
198 {"Line", WDIS_NEW, 0},
199 {NULL, 0, 0}
202 static WOptionEnumeration seSpeeds[] = {
203 {"UltraFast", SPEED_ULTRAFAST, 0},
204 {"Fast", SPEED_FAST, 0},
205 {"Medium", SPEED_MEDIUM, 0},
206 {"Slow", SPEED_SLOW, 0},
207 {"UltraSlow", SPEED_ULTRASLOW, 0},
208 {NULL, 0, 0}
211 static WOptionEnumeration seMouseButtons[] = {
212 {"Left", Button1, 0}, {"Button1", Button1, 1},
213 {"Middle", Button2, 0}, {"Button2", Button2, 1},
214 {"Right", Button3, 0}, {"Button3", Button3, 1},
215 {"Button4", Button4, 0},
216 {"Button5", Button5, 0},
217 {NULL, 0, 0}
220 static WOptionEnumeration seIconificationStyles[] = {
221 {"Zoom", WIS_ZOOM, 0},
222 {"Twist", WIS_TWIST, 0},
223 {"Flip", WIS_FLIP, 0},
224 {"None", WIS_NONE, 0},
225 {NULL, 0, 0}
228 static WOptionEnumeration seJustifications[] = {
229 {"Left", WTJ_LEFT, 0},
230 {"Center", WTJ_CENTER, 0},
231 {"Right", WTJ_RIGHT, 0},
232 {NULL, 0, 0}
235 static WOptionEnumeration seIconPositions[] = {
236 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
237 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
238 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
239 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
240 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
241 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
242 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
243 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
244 {NULL, 0, 0}
250 * All entries in the tables bellow, NEED to have a default value
251 * defined, and this value needs to be correct.
254 /* these options will only affect the window manager on startup
256 * static defaults can't access the screen data, because it is
257 * created after these defaults are read
259 WDefaultEntry staticOptionList[] = {
261 {"DisableDithering", "NO", NULL,
262 &wPreferences.no_dithering, getBool, NULL
264 {"ColormapSize", "4", NULL,
265 &wPreferences.cmap_size, getInt, NULL
267 /* static by laziness */
268 {"IconSize", "64", NULL,
269 &wPreferences.icon_size, getInt, NULL
271 {"ModifierKey", "Mod1", NULL,
272 &wPreferences.modifier_mask, getModMask, NULL
274 {"DisableWSMouseActions", "NO", NULL,
275 &wPreferences.disable_root_mouse, getBool, NULL
277 {"FocusMode", "manual", seFocusModes,
278 &wPreferences.focus_mode, getEnum, NULL
279 }, /* have a problem when switching from manual to sloppy without restart */
280 {"NewStyle", "NO", NULL,
281 &wPreferences.new_style, getBool, NULL
283 {"DisableDock", "NO", (void*) WM_DOCK,
284 NULL, getBool, setIfDockPresent
286 {"DisableClip", "NO", (void*) WM_CLIP,
287 NULL, getBool, setIfDockPresent
293 WDefaultEntry optionList[] = {
294 /* dynamic options */
295 {"IconPosition", "blh", seIconPositions,
296 &wPreferences.icon_yard, getEnum, setIconPosition
298 {"IconificationStyle", "Zoom", seIconificationStyles,
299 &wPreferences.iconification_style, getEnum, NULL
301 {"SelectWindowsMouseButton", "Left", seMouseButtons,
302 &wPreferences.select_button, getEnum, NULL
304 {"WindowListMouseButton", "Middle", seMouseButtons,
305 &wPreferences.windowl_button, getEnum, NULL
307 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
308 &wPreferences.menu_button, getEnum, NULL
310 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
311 &wPreferences.pixmap_path, getPathList, NULL
313 {"IconPath", DEF_ICON_PATHS, NULL,
314 &wPreferences.icon_path, getPathList, NULL
316 {"ColormapMode", "auto", seColormapModes,
317 &wPreferences.colormap_mode, getEnum, NULL
319 {"AutoFocus", "NO", NULL,
320 &wPreferences.auto_focus, getBool, NULL
322 {"RaiseDelay", "0", NULL,
323 &wPreferences.raise_delay, getInt, NULL
325 {"CirculateRaise", "NO", NULL,
326 &wPreferences.circ_raise, getBool, NULL
328 {"Superfluous", "NO", NULL,
329 &wPreferences.superfluous, getBool, NULL
331 {"AdvanceToNewWorkspace", "NO", NULL,
332 &wPreferences.ws_advance, getBool, NULL
334 {"CycleWorkspaces", "NO", NULL,
335 &wPreferences.ws_cycle, getBool, NULL
337 {"StickyIcons", "NO", NULL,
338 &wPreferences.sticky_icons, getBool, setStickyIcons
340 {"SaveSessionOnExit", "NO", NULL,
341 &wPreferences.save_session_on_exit, getBool, NULL
343 {"WrapMenus", "NO", NULL,
344 &wPreferences.wrap_menus, getBool, NULL
346 {"ScrollableMenus", "NO", NULL,
347 &wPreferences.scrollable_menus, getBool, NULL
349 {"MenuScrollSpeed", "medium", seSpeeds,
350 &wPreferences.menu_scroll_speed, getEnum, NULL
352 {"IconSlideSpeed", "medium", seSpeeds,
353 &wPreferences.icon_slide_speed, getEnum, NULL
355 {"ShadeSpeed", "medium", seSpeeds,
356 &wPreferences.shade_speed, getEnum, NULL
358 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
359 &wPreferences.dblclick_time, getInt, setDoubleClick,
361 {"AlignSubmenus", "NO", NULL,
362 &wPreferences.align_menus, getBool, NULL
364 {"OnTopTransients", "NO", NULL,
365 &wPreferences.on_top_transients, getBool, NULL
367 {"WindowPlacement", "auto", sePlacements,
368 &wPreferences.window_placement, getEnum, NULL
370 {"IgnoreFocusClick","NO", NULL,
371 &wPreferences.ignore_focus_click, getBool, NULL
373 {"UseSaveUnders", "NO", NULL,
374 &wPreferences.use_saveunders, getBool, NULL
376 {"OpaqueMove", "NO", NULL,
377 &wPreferences.opaque_move, getBool, NULL
379 {"DisableSound", "NO", NULL,
380 &wPreferences.no_sound, getBool, NULL
382 {"DisableAnimations", "NO", NULL,
383 &wPreferences.no_animations, getBool, NULL
385 {"DontLinkWorkspaces","NO", NULL,
386 &wPreferences.no_autowrap, getBool, NULL
388 {"EdgeResistance", "0", NULL,
389 &wPreferences.edge_resistance,getInt, NULL
391 {"AutoArrangeIcons", "NO", NULL,
392 &wPreferences.auto_arrange_icons, getBool, NULL
395 {"NoWindowUnderDock", "NO", NULL,
396 &wPreferences.no_window_under_dock, getBool, NULL
399 {"NoWindowOverIcons", "NO", NULL,
400 &wPreferences.no_window_over_icons, getBool, NULL
402 {"WindowPlaceOrigin", "(0, 0)", NULL,
403 &wPreferences.window_place_origin, getCoord, NULL
405 {"ResizeDisplay", "corner", seGeomDisplays,
406 &wPreferences.size_display, getEnum, NULL
408 {"MoveDisplay", "corner", seGeomDisplays,
409 &wPreferences.move_display, getEnum, NULL
411 {"DontConfirmKill", "NO", NULL,
412 &wPreferences.dont_confirm_kill, getBool,NULL
414 {"WindowTitleBalloons", "NO", NULL,
415 &wPreferences.window_balloon, getBool, NULL
417 {"MiniwindowTitleBalloons", "NO", NULL,
418 &wPreferences.miniwin_balloon,getBool, NULL
420 {"AppIconBalloons", "NO", NULL,
421 &wPreferences.appicon_balloon,getBool, NULL
423 {"DisableBlinking", "NO", NULL,
424 &wPreferences.dont_blink, getBool, NULL
426 /* style options */
427 {"WidgetColor", "(solid, gray)", NULL,
428 NULL, getTexture, setWidgetColor,
430 {"WorkspaceBack", "(solid, black)", NULL,
431 NULL, getWSBackground,setWorkspaceBack
433 {"IconBack", "(solid, gray)", NULL,
434 NULL, getTexture, setIconTile
436 {"TitleJustify", "center", seJustifications,
437 &wPreferences.title_justification, getEnum, setJustify
439 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
440 NULL, getFont, setWinTitleFont
442 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
443 NULL, getFont, setMenuTitleFont
445 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
446 NULL, getFont, setMenuTextFont
448 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
449 NULL, getFont, setIconTitleFont
451 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
452 NULL, getFont, setClipTitleFont
454 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
455 NULL, getFont, setDisplayFont
457 {"HighlightColor", "white", NULL,
458 NULL, getColor, setHightlight
460 {"HighlightTextColor", "black", NULL,
461 NULL, getColor, setHightlightText
463 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
464 NULL, getColor, setClipTitleColor
466 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
467 NULL, getColor, setClipTitleColor
469 {"FTitleColor", "white", (void*)WS_FOCUSED,
470 NULL, getColor, setWTitleColor
472 {"PTitleColor", "white", (void*)WS_PFOCUSED,
473 NULL, getColor, setWTitleColor
475 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
476 NULL, getColor, setWTitleColor
478 {"FTitleBack", "(solid, black)", NULL,
479 NULL, getTexture, setFTitleBack
481 {"PTitleBack", "(solid, \"#616161\")", NULL,
482 NULL, getTexture, setPTitleBack
484 {"UTitleBack", "(solid, gray)", NULL,
485 NULL, getTexture, setUTitleBack
487 {"MenuTitleColor", "white", NULL,
488 NULL, getColor, setMenuTitleColor
490 {"MenuTextColor", "black", NULL,
491 NULL, getColor, setMenuTextColor
493 {"MenuDisabledColor", "\"#616161\"", NULL,
494 NULL, getColor, setMenuDisabledColor
496 {"MenuTitleBack", "(solid, black)", NULL,
497 NULL, getTexture, setMenuTitleBack
499 {"MenuTextBack", "(solid, gray)", NULL,
500 NULL, getTexture, setMenuTextBack
503 /* keybindings */
504 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
505 NULL, getKeybind, setKeyGrab
507 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
508 NULL, getKeybind, setKeyGrab
510 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
511 NULL, getKeybind, setKeyGrab
513 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
514 NULL, getKeybind, setKeyGrab
516 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
517 NULL, getKeybind, setKeyGrab
519 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
520 NULL, getKeybind, setKeyGrab
522 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
523 NULL, getKeybind, setKeyGrab
525 {"HideKey", "None", (void*)WKBD_HIDE,
526 NULL, getKeybind, setKeyGrab
528 {"CloseKey", "None", (void*)WKBD_CLOSE,
529 NULL, getKeybind, setKeyGrab
531 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
532 NULL, getKeybind, setKeyGrab
534 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
535 NULL, getKeybind, setKeyGrab
537 {"RaiseKey", "Meta+Up", (void*)WKBD_RAISE,
538 NULL, getKeybind, setKeyGrab
540 {"LowerKey", "Meta+Down", (void*)WKBD_LOWER,
541 NULL, getKeybind, setKeyGrab
543 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
544 NULL, getKeybind, setKeyGrab
546 {"ShadeKey", "None", (void*)WKBD_SHADE,
547 NULL, getKeybind, setKeyGrab
549 {"SelectKey", "None", (void*)WKBD_SELECT,
550 NULL, getKeybind, setKeyGrab
552 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
553 NULL, getKeybind, setKeyGrab
555 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
556 NULL, getKeybind, setKeyGrab
558 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
559 NULL, getKeybind, setKeyGrab
561 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
562 NULL, getKeybind, setKeyGrab
564 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
565 NULL, getKeybind, setKeyGrab
567 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
568 NULL, getKeybind, setKeyGrab
570 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
571 NULL, getKeybind, setKeyGrab
573 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
574 NULL, getKeybind, setKeyGrab
576 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
577 NULL, getKeybind, setKeyGrab
579 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
580 NULL, getKeybind, setKeyGrab
582 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
583 NULL, getKeybind, setKeyGrab
585 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
586 NULL, getKeybind, setKeyGrab
588 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
589 NULL, getKeybind, setKeyGrab
591 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
592 NULL, getKeybind, setKeyGrab
594 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
595 NULL, getKeybind, setKeyGrab
597 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
598 NULL, getKeybind, setKeyGrab
600 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
601 NULL, getKeybind, setKeyGrab
603 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
604 NULL, getKeybind, setKeyGrab
606 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
607 NULL, getKeybind, setKeyGrab
609 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
610 NULL, getKeybind, setKeyGrab
612 #ifdef KEEP_XKB_LOCK_STATUS
613 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
614 NULL, getKeybind, setKeyGrab
616 {"KbdModeLock", "NO", NULL,
617 &wPreferences.modelock, getBool, NULL
619 #endif /* KEEP_XKB_LOCK_STATUS */
623 #if 0
624 static void rereadDefaults(void);
625 #endif
627 #if 0
628 static void
629 rereadDefaults(void)
631 /* must defer the update because accessing X data from a
632 * signal handler can mess up Xlib */
635 #endif
637 static void
638 initDefaults()
640 int i;
641 WDefaultEntry *entry;
643 PLSetStringCmpHook(StringCompareHook);
645 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
646 entry = &optionList[i];
648 entry->plkey = PLMakeString(entry->key);
649 if (entry->default_value)
650 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
651 else
652 entry->plvalue = NULL;
655 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
656 entry = &staticOptionList[i];
658 entry->plkey = PLMakeString(entry->key);
659 if (entry->default_value)
660 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
661 else
662 entry->plvalue = NULL;
666 wDomainName = PLMakeString(WMDOMAIN_NAME);
667 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
669 PLRegister(wDomainName, rereadDefaults);
670 PLRegister(wAttributeDomainName, rereadDefaults);
677 #if 0
678 proplist_t
679 wDefaultsInit(int screen_number)
681 static int defaults_inited = 0;
682 proplist_t dict;
684 if (!defaults_inited) {
685 initDefaults();
688 dict = PLGetDomain(wDomainName);
689 if (!dict) {
690 wwarning(_("could not read domain \"%s\" from defaults database"),
691 PLGetString(wDomainName));
694 return dict;
696 #endif
699 void
700 wDefaultsDestroyDomain(WDDomain *domain)
702 if (domain->dictionary)
703 PLRelease(domain->dictionary);
704 free(domain->path);
705 free(domain);
709 WDDomain*
710 wDefaultsInitDomain(char *domain, Bool requireDictionary)
712 WDDomain *db;
713 struct stat stbuf;
714 static int inited = 0;
715 char path[PATH_MAX];
716 char *the_path;
717 proplist_t shared_dict=NULL;
719 if (!inited) {
720 inited = 1;
721 initDefaults();
724 db = wmalloc(sizeof(WDDomain));
725 memset(db, 0, sizeof(WDDomain));
726 db->domain_name = domain;
727 db->path = wdefaultspathfordomain(domain);
728 the_path = db->path;
730 if (the_path && stat(the_path, &stbuf)>=0) {
731 db->dictionary = ReadProplistFromFile(the_path);
732 if (db->dictionary) {
733 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
734 PLRelease(db->dictionary);
735 db->dictionary = NULL;
736 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
737 domain, the_path);
739 db->timestamp = stbuf.st_mtime;
740 } else {
741 wwarning(_("could not load domain %s from user defaults database"),
742 domain);
746 /* global system dictionary */
747 sprintf(path, "%s/%s/%s", PKGDATADIR, DEFAULTS_DIR, domain);
748 if (stat(path, &stbuf)>=0) {
749 shared_dict = ReadProplistFromFile(path);
750 if (shared_dict) {
751 if (requireDictionary && !PLIsDictionary(shared_dict)) {
752 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
753 domain, path);
754 PLRelease(shared_dict);
755 shared_dict = NULL;
756 } else {
757 if (db->dictionary && PLIsDictionary(shared_dict) &&
758 PLIsDictionary(db->dictionary)) {
759 PLMergeDictionaries(shared_dict, db->dictionary);
760 PLRelease(db->dictionary);
761 db->dictionary = shared_dict;
762 if (stbuf.st_mtime > db->timestamp)
763 db->timestamp = stbuf.st_mtime;
764 } else if (!db->dictionary) {
765 db->dictionary = shared_dict;
766 if (stbuf.st_mtime > db->timestamp)
767 db->timestamp = stbuf.st_mtime;
770 } else {
771 wwarning(_("could not load domain %s from global defaults database"),
772 domain);
776 /* set to save it in user's directory, no matter from where it was read */
777 if (db->dictionary) {
778 proplist_t tmp = PLMakeString(db->path);
780 PLSetFilename(db->dictionary, tmp);
781 PLRelease(tmp);
784 return db;
788 void
789 wReadStaticDefaults(proplist_t dict)
791 proplist_t plvalue;
792 WDefaultEntry *entry;
793 int i;
794 void *tdata;
797 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
798 entry = &staticOptionList[i];
800 if (dict)
801 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
802 else
803 plvalue = NULL;
805 if (!plvalue) {
806 /* no default in the DB. Use builtin default */
807 plvalue = entry->plvalue;
810 if (plvalue) {
811 /* convert data */
812 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
813 if (entry->update) {
814 (*entry->update)(NULL, entry, tdata, entry->extra_data);
820 void
821 wDefaultsCheckDomains(void *foo)
823 WScreen *scr;
824 struct stat stbuf;
825 proplist_t dict;
826 int i;
827 char path[PATH_MAX];
829 #ifdef HEARTBEAT
830 puts("Checking domains...");
831 #endif
832 if (stat(WDWindowMaker->path, &stbuf)>=0
833 && WDWindowMaker->timestamp < stbuf.st_mtime) {
834 proplist_t shared_dict = NULL;
835 #ifdef HEARTBEAT
836 puts("Checking WindowMaker domain");
837 #endif
838 WDWindowMaker->timestamp = stbuf.st_mtime;
840 /* global dictionary */
841 sprintf(path, "%s/%s/WindowMaker", PKGDATADIR, DEFAULTS_DIR);
842 if (stat(path, &stbuf)>=0) {
843 shared_dict = ReadProplistFromFile(path);
844 if (shared_dict && !PLIsDictionary(shared_dict)) {
845 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
846 "WindowMaker", path);
847 PLRelease(shared_dict);
848 shared_dict = NULL;
849 } else if (!shared_dict) {
850 wwarning(_("could not load domain %s from global defaults database"),
851 "WindowMaker");
854 /* user dictionary */
855 dict = ReadProplistFromFile(WDWindowMaker->path);
856 if (dict) {
857 if (!PLIsDictionary(dict)) {
858 PLRelease(dict);
859 dict = NULL;
860 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
861 "WindowMaker", WDWindowMaker->path);
862 } else {
863 if (shared_dict) {
864 PLSetFilename(shared_dict, PLGetFilename(dict));
865 PLMergeDictionaries(shared_dict, dict);
866 PLRelease(dict);
867 dict = shared_dict;
868 shared_dict = NULL;
870 for (i=0; i<wScreenCount; i++) {
871 scr = wScreenWithNumber(i);
872 if (scr)
873 wReadDefaults(scr, dict);
875 if (WDWindowMaker->dictionary) {
876 PLRelease(WDWindowMaker->dictionary);
878 WDWindowMaker->dictionary = dict;
880 } else {
881 wwarning(_("could not load domain %s from user defaults database"),
882 "WindowMaker");
884 if (shared_dict) {
885 PLRelease(shared_dict);
889 if (stat(WDWindowAttributes->path, &stbuf)>=0
890 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
891 #ifdef HEARTBEAT
892 puts("Checking WMWindowAttributes domain");
893 #endif
894 dict = ReadProplistFromFile(WDWindowAttributes->path);
895 if (dict) {
896 if (!PLIsDictionary(dict)) {
897 PLRelease(dict);
898 dict = NULL;
899 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
900 "WMWindowAttributes", WDWindowAttributes->path);
901 } else {
902 if (WDWindowAttributes->dictionary)
903 PLRelease(WDWindowAttributes->dictionary);
904 WDWindowAttributes->dictionary = dict;
905 for (i=0; i<wScreenCount; i++) {
906 scr = wScreenWithNumber(i);
907 if (scr)
908 wDefaultUpdateIcons(scr);
911 } else {
912 wwarning(_("could not load domain %s from user defaults database"),
913 "WMWindowAttributes");
915 WDWindowAttributes->timestamp = stbuf.st_mtime;
919 if (stat(WDRootMenu->path, &stbuf)>=0
920 && WDRootMenu->timestamp < stbuf.st_mtime) {
921 dict = ReadProplistFromFile(WDRootMenu->path);
922 #ifdef HEARTBEAT
923 puts("Checking WMRootMenu domain");
924 #endif
925 if (dict) {
926 if (!PLIsArray(dict) && !PLIsString(dict)) {
927 PLRelease(dict);
928 dict = NULL;
929 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
930 "WMRootMenu", WDRootMenu->path);
931 } else {
932 if (WDRootMenu->dictionary) {
933 PLRelease(WDRootMenu->dictionary);
935 WDRootMenu->dictionary = dict;
937 } else {
938 wwarning(_("could not load domain %s from user defaults database"),
939 "WMRootMenu");
941 WDRootMenu->timestamp = stbuf.st_mtime;
944 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
949 #define REFRESH_WINDOW_TEXTURES (1<<0)
950 #define REFRESH_MENU_TEXTURES (1<<1)
951 #define REFRESH_WINDOW_FONT (1<<2)
952 #define REFRESH_MENU_TITLE_FONT (1<<3)
953 #define REFRESH_MENU_FONT (1<<4)
954 #define REFRESH_FORE_COLOR (1<<5)
955 #define REFRESH_ICON_TILE (1<<6)
956 #define REFRESH_ICON_FONT (1<<7)
957 #define REFRESH_WORKSPACE_BACK (1<<8)
959 static void
960 refreshMenus(WScreen *scr, int flags)
962 WMenu *menu;
964 menu = scr->root_menu;
965 if (menu)
966 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
968 menu = scr->workspace_menu;
969 if (menu)
970 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
972 menu = scr->switch_menu;
973 if (menu)
974 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
976 menu = scr->window_menu;
977 if (menu)
978 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
980 menu = scr->icon_menu;
981 if (menu)
982 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
984 if (scr->dock) {
985 menu = scr->dock->menu;
986 if (menu)
987 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
989 menu = scr->clip_menu;
990 if (menu)
991 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
993 menu = scr->clip_submenu;
994 if (menu)
995 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
997 menu = scr->clip_options;
998 if (menu)
999 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
1003 static void
1004 refreshAppIcons(WScreen *scr, int flags)
1006 WAppIcon *aicon = scr->app_icon_list;
1008 while (aicon) {
1009 if (aicon->icon) {
1010 aicon->icon->force_paint = 1;
1012 aicon = aicon->next;
1017 static void
1018 refreshWindows(WScreen *scr, int flags)
1020 WWindow *wwin;
1022 wwin = scr->focused_window;
1023 while (wwin) {
1024 if (flags & REFRESH_WINDOW_FONT) {
1025 wWindowConfigureBorders(wwin);
1027 if ((flags & (REFRESH_ICON_TILE|REFRESH_WINDOW_TEXTURES)) &&
1028 wwin->flags.miniaturized && wwin->icon) {
1029 wwin->icon->force_paint = 1;
1031 if (flags & REFRESH_WINDOW_TEXTURES) {
1032 wwin->frame->flags.need_texture_remake = 1;
1034 wwin = wwin->prev;
1039 void
1040 wReadDefaults(WScreen *scr, proplist_t new_dict)
1042 proplist_t plvalue, old_value;
1043 WDefaultEntry *entry;
1044 int i, changed, must_update;
1045 int needs_refresh;
1046 void *tdata;
1047 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1048 ? WDWindowMaker->dictionary : NULL);
1050 changed = 0;
1051 must_update = 0;
1053 needs_refresh = 0;
1055 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1056 entry = &optionList[i];
1058 if (new_dict)
1059 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1060 else
1061 plvalue = NULL;
1063 if (!old_dict)
1064 old_value = NULL;
1065 else
1066 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1069 if (!plvalue && !old_value) {
1070 /* no default in the DB. Use builtin default */
1071 plvalue = entry->plvalue;
1072 if (plvalue && new_dict) {
1073 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1074 changed = 1;
1075 must_update = 1;
1077 } else if (!plvalue) {
1078 /* value was deleted from DB. Keep current value */
1079 continue;
1080 } else if (!old_value) {
1081 /* set value for the 1st time */
1082 changed = 1;
1083 } else if (!PLIsEqual(plvalue, old_value)) {
1084 /* value has changed */
1085 changed = 1;
1086 } else {
1087 /* value was not changed since last time */
1088 continue;
1091 if (plvalue) {
1092 #ifdef DEBUG
1093 printf("Updating %s to %s\n", entry->key, PLGetDescription(plvalue));
1094 #endif
1095 /* convert data */
1096 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1097 if (entry->update) {
1098 needs_refresh |=
1099 (*entry->update)(scr, entry, tdata, entry->extra_data);
1105 if (needs_refresh!=0) {
1106 int foo;
1108 foo = 0;
1109 if (needs_refresh & REFRESH_MENU_TEXTURES)
1110 foo |= MR_TEXT_BACK;
1111 if (needs_refresh & REFRESH_MENU_FONT)
1112 foo |= MR_RESIZED;
1113 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1114 foo |= MR_TITLE_TEXT;
1116 if (foo)
1117 refreshMenus(scr, foo);
1119 if (needs_refresh & (REFRESH_WINDOW_TEXTURES|REFRESH_WINDOW_FONT|
1120 REFRESH_ICON_TILE))
1121 refreshWindows(scr, needs_refresh);
1123 if (needs_refresh & REFRESH_ICON_TILE)
1124 refreshAppIcons(scr, needs_refresh);
1126 #ifdef EXPERIMENTAL
1127 if (needs_refresh & REFRESH_WORKSPACE_BACK) {
1128 WWorkspaceTexture *wsback;
1130 /* update the background for the workspace */
1131 if (scr->current_workspace < scr->wspaceTextureCount
1132 && scr->wspaceTextures[scr->current_workspace]) {
1133 wsback = scr->wspaceTextures[scr->current_workspace];
1134 } else {
1135 wsback = scr->defaultTexure;
1137 if (wsback) {
1138 if (wsback->pixmap!=None) {
1139 XSetWindowBackgroundPixmap(dpy, scr->root_win,
1140 wsback->pixmap);
1141 } else {
1142 XSetWindowBackground(dpy, scr->root_win, wsback->solid);
1144 XClearWindow(dpy, scr->root_win);
1145 XFlush(dpy);
1148 #endif /* !EXPERIMENTAL */
1149 wRefreshDesktop(scr);
1154 void
1155 wDefaultUpdateIcons(WScreen *scr)
1157 WAppIcon *aicon = scr->app_icon_list;
1158 WWindow *wwin = scr->focused_window;
1159 char *file;
1161 while(aicon) {
1162 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1163 False);
1164 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1165 || (file && !aicon->icon->file)) {
1166 RImage *new_image;
1168 if (aicon->icon->file)
1169 free(aicon->icon->file);
1170 aicon->icon->file = wstrdup(file);
1172 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1173 aicon->wm_class);
1174 if (new_image) {
1175 wIconChangeImage(aicon->icon, new_image);
1176 wAppIconPaint(aicon);
1179 aicon = aicon->next;
1182 if (!wPreferences.flags.noclip)
1183 wClipIconPaint(scr->clip_icon);
1185 while (wwin) {
1186 if (wwin->icon && wwin->flags.miniaturized) {
1187 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1188 False);
1189 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1190 || (file && !wwin->icon->file)) {
1191 RImage *new_image;
1193 if (wwin->icon->file)
1194 free(wwin->icon->file);
1195 wwin->icon->file = wstrdup(file);
1197 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1198 wwin->wm_class);
1199 if (new_image)
1200 wIconChangeImage(wwin->icon, new_image);
1203 wwin = wwin->prev;
1208 /* --------------------------- Local ----------------------- */
1210 #define STRINGP(x) if (!PLIsString(value)) { \
1211 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1212 PLGetString(entry->plkey), x); \
1213 return False; }
1217 static int
1218 string2index(proplist_t key, proplist_t val, proplist_t def,
1219 WOptionEnumeration *values)
1221 char *str;
1222 WOptionEnumeration *v;
1223 char buffer[TOTAL_VALUES_LENGTH];
1225 if (PLIsString(val) && (str = PLGetString(val))) {
1226 for (v=values; v->string!=NULL; v++) {
1227 if (strcasecmp(v->string, str)==0)
1228 return v->value;
1232 buffer[0] = 0;
1233 for (v=values; v->string!=NULL; v++) {
1234 if (!v->is_alias) {
1235 if (buffer[0]!=0)
1236 strcat(buffer, ", ");
1237 strcat(buffer, v->string);
1240 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1241 PLGetString(key), buffer);
1243 if (def) {
1244 return string2index(key, val, NULL, values);
1247 return -1;
1254 * value - is the value in the defaults DB
1255 * addr - is the address to store the data
1256 * ret - is the address to store a pointer to a temporary buffer. ret
1257 * must not be freed and is used by the set functions
1259 static int
1260 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1261 void **ret)
1263 static char data;
1264 char *val;
1265 int second_pass=0;
1267 STRINGP("Boolean");
1269 val = PLGetString(value);
1271 again:
1272 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1273 || strcasecmp(val, "YES")==0) {
1275 data = 1;
1276 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1277 || strcasecmp(val, "NO")==0) {
1278 data = 0;
1279 } else {
1280 int i;
1281 if (sscanf(val, "%i", &i)==1) {
1282 if (i!=0)
1283 data = 1;
1284 else
1285 data = 0;
1286 } else {
1287 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1288 val, PLGetString(entry->plkey));
1289 if (second_pass==0) {
1290 val = PLGetString(entry->plvalue);
1291 second_pass = 1;
1292 wwarning(_("using default \"%s\" instead"), val);
1293 goto again;
1295 return False;
1299 if (ret)
1300 *ret = &data;
1302 if (addr) {
1303 *(char*)addr = data;
1306 return True;
1310 static int
1311 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1312 void **ret)
1314 static int data;
1315 char *val;
1318 STRINGP("Integer");
1320 val = PLGetString(value);
1322 if (sscanf(val, "%i", &data)!=1) {
1323 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1324 val, PLGetString(entry->plkey));
1325 val = PLGetString(entry->plvalue);
1326 wwarning(_("using default \"%s\" instead"), val);
1327 if (sscanf(val, "%i", &data)!=1) {
1328 return False;
1332 if (ret)
1333 *ret = &data;
1335 if (addr) {
1336 *(int*)addr = data;
1338 return True;
1342 static int
1343 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1344 void **ret)
1346 static WCoord data;
1347 char *val_x, *val_y;
1348 int nelem, changed=0;
1349 proplist_t elem_x, elem_y;
1351 again:
1352 if (!PLIsArray(value)) {
1353 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1354 PLGetString(entry->plkey), "Coordinate");
1355 if (changed==0) {
1356 value = entry->plvalue;
1357 changed = 1;
1358 wwarning(_("using default \"%s\" instead"), entry->default_value);
1359 goto again;
1361 return False;
1364 nelem = PLGetNumberOfElements(value);
1365 if (nelem != 2) {
1366 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1367 PLGetString(entry->plkey));
1368 if (changed==0) {
1369 value = entry->plvalue;
1370 changed = 1;
1371 wwarning(_("using default \"%s\" instead"), entry->default_value);
1372 goto again;
1374 return False;
1377 elem_x = PLGetArrayElement(value, 0);
1378 elem_y = PLGetArrayElement(value, 1);
1380 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1381 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1382 PLGetString(entry->plkey));
1383 if (changed==0) {
1384 value = entry->plvalue;
1385 changed = 1;
1386 wwarning(_("using default \"%s\" instead"), entry->default_value);
1387 goto again;
1389 return False;
1392 val_x = PLGetString(elem_x);
1393 val_y = PLGetString(elem_y);
1395 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1396 wwarning(_("can't convert array to integers for \"%s\"."),
1397 PLGetString(entry->plkey));
1398 if (changed==0) {
1399 value = entry->plvalue;
1400 changed = 1;
1401 wwarning(_("using default \"%s\" instead"), entry->default_value);
1402 goto again;
1404 return False;
1407 if (data.x < 0)
1408 data.x = 0;
1409 else if (data.x > scr->scr_width/3)
1410 data.x = scr->scr_width/3;
1411 if (data.y < 0)
1412 data.y = 0;
1413 else if (data.y > scr->scr_height/3)
1414 data.y = scr->scr_height/3;
1416 if (ret)
1417 *ret = &data;
1419 if (addr) {
1420 *(WCoord*)addr = data;
1423 return True;
1427 #if 0
1428 /* This function is not used at the moment. */
1429 static int
1430 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1431 void **ret)
1433 static char *data;
1435 STRINGP("String");
1437 data = PLGetString(value);
1439 if (!data) {
1440 data = PLGetString(entry->plvalue);
1441 if (!data)
1442 return False;
1445 if (ret)
1446 *ret = &data;
1448 if (addr)
1449 *(char**)addr = wstrdup(data);
1451 return True;
1453 #endif
1456 static int
1457 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1458 void **ret)
1460 static char **data;
1461 int i, count;
1462 proplist_t d;
1463 int changed=0;
1465 again:
1466 if (!PLIsArray(value)) {
1467 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1468 PLGetString(entry->plkey), "an array of paths");
1469 if (changed==0) {
1470 value = entry->plvalue;
1471 changed = 1;
1472 wwarning(_("using default \"%s\" instead"), entry->default_value);
1473 goto again;
1475 return False;
1478 i = 0;
1479 count = PLGetNumberOfElements(value);
1480 if (count < 1) {
1481 if (changed==0) {
1482 value = entry->plvalue;
1483 changed = 1;
1484 wwarning(_("using default \"%s\" instead"), entry->default_value);
1485 goto again;
1487 return False;
1490 data = wmalloc(sizeof(char*)*(count+1));
1491 for (i=0; i<count; i++) {
1492 d = PLGetArrayElement(value, i);
1493 if (!d || !PLIsString(d)) {
1494 break;
1496 data[i] = wstrdup(PLGetString(d));
1498 data[i]=NULL;
1500 if (*(char***)addr!=NULL) {
1501 char **tmp = *(char***)addr;
1502 for (i=0; tmp[i]!=NULL; i++) {
1503 free(tmp[i]);
1505 free(tmp);
1507 *(char***)addr = data;
1509 return True;
1513 static int
1514 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1515 void **ret)
1517 static char data;
1519 data = string2index(entry->key, value, entry->default_value,
1520 (WOptionEnumeration*)entry->extra_data);
1521 if (data < 0)
1522 return False;
1524 if (ret)
1525 *ret = &data;
1527 if (addr)
1528 *(char*)addr = data;
1530 return True;
1536 * (solid <color>)
1537 * (hgradient <color> <color>)
1538 * (vgradient <color> <color>)
1539 * (dgradient <color> <color>)
1540 * (mhgradient <color> <color> ...)
1541 * (mvgradient <color> <color> ...)
1542 * (tpixmap <file> <color>)
1543 * (spixmap <file> <color>)
1544 * (cpixmap <file> <color>)
1547 static WTexture*
1548 parse_texture(WScreen *scr, proplist_t pl)
1550 proplist_t elem;
1551 char *val;
1552 int nelem;
1553 WTexture *texture=NULL;
1555 nelem = PLGetNumberOfElements(pl);
1556 if (nelem < 1)
1557 return NULL;
1560 elem = PLGetArrayElement(pl, 0);
1561 if (!elem || !PLIsString(elem))
1562 return NULL;
1563 val = PLGetString(elem);
1566 if (strcasecmp(val, "solid")==0) {
1567 XColor color;
1569 if (nelem != 2)
1570 return NULL;
1572 /* get color */
1574 elem = PLGetArrayElement(pl, 1);
1575 if (!elem || !PLIsString(elem))
1576 return NULL;
1577 val = PLGetString(elem);
1579 if (!XParseColor(dpy, scr->colormap, val, &color)) {
1580 wwarning(_("\"%s\" is not a valid color name"), val);
1581 return NULL;
1584 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1585 } else if (strcasecmp(val, "dgradient")==0
1586 || strcasecmp(val, "vgradient")==0
1587 || strcasecmp(val, "hgradient")==0) {
1588 XColor color1, color2;
1589 int type;
1591 if (nelem != 3) {
1592 wwarning(_("bad number of arguments in gradient specification"));
1593 return NULL;
1596 if (val[0]=='d' || val[0]=='D')
1597 type = WTEX_DGRADIENT;
1598 else if (val[0]=='h' || val[0]=='H')
1599 type = WTEX_HGRADIENT;
1600 else
1601 type = WTEX_VGRADIENT;
1604 /* get from color */
1605 elem = PLGetArrayElement(pl, 1);
1606 if (!elem || !PLIsString(elem))
1607 return NULL;
1608 val = PLGetString(elem);
1610 if (!XParseColor(dpy, scr->colormap, val, &color1)) {
1611 wwarning(_("\"%s\" is not a valid color name"), val);
1612 return NULL;
1615 /* get to color */
1616 elem = PLGetArrayElement(pl, 2);
1617 if (!elem || !PLIsString(elem)) {
1618 return NULL;
1620 val = PLGetString(elem);
1622 if (!XParseColor(dpy, scr->colormap, val, &color2)) {
1623 wwarning(_("\"%s\" is not a valid color name"), val);
1624 return NULL;
1627 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1629 } else if (strcasecmp(val, "mhgradient")==0
1630 || strcasecmp(val, "mvgradient")==0
1631 || strcasecmp(val, "mdgradient")==0) {
1632 XColor color;
1633 RColor **colors;
1634 int i, count;
1635 int type;
1637 if (nelem < 3) {
1638 wwarning(_("too few arguments in multicolor gradient specification"));
1639 return NULL;
1642 if (val[1]=='h' || val[1]=='H')
1643 type = WTEX_MHGRADIENT;
1644 else if (val[1]=='v' || val[1]=='V')
1645 type = WTEX_MVGRADIENT;
1646 else
1647 type = WTEX_MDGRADIENT;
1649 count = nelem-1;
1651 colors = wmalloc(sizeof(RColor*)*(count+1));
1653 for (i=0; i<count; i++) {
1654 elem = PLGetArrayElement(pl, i+1);
1655 if (!elem || !PLIsString(elem)) {
1656 for (--i; i>=0; --i) {
1657 free(colors[i]);
1659 free(colors);
1660 return NULL;
1662 val = PLGetString(elem);
1664 if (!XParseColor(dpy, scr->colormap, val, &color)) {
1665 wwarning(_("\"%s\" is not a valid color name"), val);
1666 for (--i; i>=0; --i) {
1667 free(colors[i]);
1669 free(colors);
1670 return NULL;
1671 } else {
1672 colors[i] = wmalloc(sizeof(RColor));
1673 colors[i]->red = color.red >> 8;
1674 colors[i]->green = color.green >> 8;
1675 colors[i]->blue = color.blue >> 8;
1678 colors[i] = NULL;
1680 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1681 } else if (strcasecmp(val, "spixmap")==0 ||
1682 strcasecmp(val, "cpixmap")==0 ||
1683 strcasecmp(val, "tpixmap")==0) {
1684 XColor color;
1685 int type;
1687 if (nelem != 3)
1688 return NULL;
1690 if (val[0] == 's' || val[0] == 'S')
1691 type = WTP_SCALE;
1692 else if (val[0] == 'c' || val[0] == 'C')
1693 type = WTP_CENTER;
1694 else
1695 type = WTP_TILE;
1697 /* get color */
1698 elem = PLGetArrayElement(pl, 2);
1699 if (!elem || !PLIsString(elem)) {
1700 return NULL;
1702 val = PLGetString(elem);
1704 if (!XParseColor(dpy, scr->colormap, val, &color)) {
1705 wwarning(_("\"%s\" is not a valid color name"), val);
1706 return NULL;
1709 /* file name */
1710 elem = PLGetArrayElement(pl, 1);
1711 if (!elem || !PLIsString(elem))
1712 return NULL;
1713 val = PLGetString(elem);
1715 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1717 } else {
1718 return NULL;
1720 return texture;
1725 static int
1726 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1727 void **ret)
1729 static WTexture *texture;
1730 int changed=0;
1732 again:
1733 if (!PLIsArray(value)) {
1734 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1735 PLGetString(entry->plkey), "Texture");
1736 if (changed==0) {
1737 value = entry->plvalue;
1738 changed = 1;
1739 wwarning(_("using default \"%s\" instead"), entry->default_value);
1740 goto again;
1742 return False;
1745 texture = parse_texture(scr, value);
1747 if (!texture) {
1748 wwarning(_("Error in texture specification for key \"%s\""),
1749 PLGetString(entry->plkey));
1750 if (changed==0) {
1751 value = entry->plvalue;
1752 changed = 1;
1753 wwarning(_("using default \"%s\" instead"), entry->default_value);
1754 goto again;
1756 return False;
1759 if (ret)
1760 *ret = &texture;
1762 if (addr)
1763 *(WTexture**)addr = texture;
1765 return True;
1770 #ifdef EXPERIMENTAL
1771 static int
1772 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
1773 void *addr, void **ret)
1775 proplist_t elem;
1776 char *val;
1777 int nelem;
1778 static WTexture *texture=NULL;
1779 int changed=0;
1780 char *file = NULL;
1782 again:
1783 entry->extra_data = NULL;
1785 if (!PLIsArray(value)) {
1786 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1787 "WorkspaceBack", "Texture");
1788 if (changed==0) {
1789 value = entry->plvalue;
1790 changed = 1;
1791 wwarning(_("using default \"%s\" instead"), entry->default_value);
1792 goto again;
1794 return False;
1797 nelem = PLGetNumberOfElements(value);
1798 if (nelem < 1) {
1799 wwarning(_("Too few elements in array for key \"WorkspaceBack\"."));
1800 if (changed==0) {
1801 value = entry->plvalue;
1802 changed = 1;
1803 wwarning(_("using default \"%s\" instead"), entry->default_value);
1804 goto again;
1806 return False;
1809 elem = PLGetArrayElement(value, 0);
1810 if (!elem || !PLIsString(elem)) {
1811 wwarning(_("Wrong type for workspace background. Should be Texture."));
1812 if (changed==0) {
1813 value = entry->plvalue;
1814 changed = 1;
1815 wwarning(_("using default \"%s\" instead"), entry->default_value);
1816 goto again;
1818 return False;
1820 val = PLGetString(elem);
1822 if (strcasecmp(val, "None")==0)
1823 return False;
1825 if (strcasecmp(val, "spixmap")!=0 && strcasecmp(val, "tpixmap")!=0
1826 && strcasecmp(val, "cpixmap")!=0) {
1827 texture = parse_texture(scr, value);
1828 } else {
1829 /* spixmap || tpixmap || cpixmap */
1830 XColor color;
1831 int style;
1833 if (nelem != 3) {
1834 wwarning(_("Too few elements in array for key \"WorkspaceBack\"."));
1835 if (changed==0) {
1836 value = entry->plvalue;
1837 changed = 1;
1838 wwarning(_("using default \"%s\" instead"), entry->default_value);
1839 goto again;
1841 return False;
1844 switch (val[0]) {
1845 case 's':
1846 case 'S':
1847 style = WTP_SCALE;
1848 break;
1849 case 'C':
1850 case 'c':
1851 style = WTP_CENTER;
1852 break;
1853 default:
1854 style = WTP_TILE;
1855 break;
1858 /* get color */
1859 elem = PLGetArrayElement(value, 2);
1860 if (!elem || !PLIsString(elem)) {
1861 wwarning(_("Cannot get color entry for key \"WorkspaceBack\"."));
1862 if (changed==0) {
1863 value = entry->plvalue;
1864 changed = 1;
1865 wwarning(_("using default \"%s\" instead"), entry->default_value);
1866 goto again;
1868 return False;
1870 val = PLGetString(elem);
1872 if (!XParseColor(dpy, scr->colormap, val, &color)) {
1873 wwarning(_("key \"WorkspaceBack\" has invalid color \"%s\""),
1874 val);
1875 if (changed==0) {
1876 value = entry->plvalue;
1877 changed = 1;
1878 wwarning(_("using default \"%s\" instead"), entry->default_value);
1879 goto again;
1881 return False;
1884 /* file name */
1885 elem = PLGetArrayElement(value, 1);
1886 if (!elem || !PLIsString(elem)) {
1887 wwarning(_("Cannot get file entry for key \"WorkspaceBack\"."));
1888 if (changed==0) {
1889 value = entry->plvalue;
1890 changed = 1;
1891 wwarning(_("using default \"%s\" instead"), entry->default_value);
1892 goto again;
1894 return False;
1897 val = PLGetString(elem);
1898 file = FindImage(wPreferences.pixmap_path, val);
1899 if (!file) {
1900 wwarning(_("could not find background image \"%s\""), val);
1901 /*return False;*/
1904 /* create a dummy texture.
1905 * use free() to free this texture.
1907 texture = wmalloc(sizeof(WTexture));
1908 memset(texture, 0, sizeof(WTexture));
1909 texture->type = WTEX_PIXMAP;
1910 texture->subtype = style;
1911 texture->normal = color;
1914 if (!texture) {
1915 if (file)
1916 free(file);
1917 wwarning(_("Error in texture specification for key \"WorkspaceBack\""));
1918 if (changed==0) {
1919 value = entry->plvalue;
1920 changed = 1;
1921 wwarning(_("using default \"%s\" instead"), entry->default_value);
1922 goto again;
1924 return False;
1927 if (ret)
1928 *ret = &texture;
1930 if (addr)
1931 *(WTexture**)addr = texture;
1933 /* we use the extra_data field to pass the filename string
1934 * to the background setting function. We can't pass it with
1935 * WTexture because it holds a RImage, not a file name.
1936 * It also would be dirtier to cast the RImage to char* to make it
1937 * hold the file name. The extra_data must be freed by the
1938 * setting function.
1940 entry->extra_data = file;
1942 return True;
1944 #else /* !EXPERIMENTAL */
1945 static int
1946 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
1947 void *addr, void **ret)
1949 proplist_t elem;
1950 char *val;
1951 int nelem;
1952 static WTexture *texture=NULL;
1953 int changed=0;
1955 again:
1956 if (!PLIsArray(value)) {
1957 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1958 "WorkspaceBack", "Texture");
1959 if (changed==0) {
1960 value = entry->plvalue;
1961 changed = 1;
1962 wwarning(_("using default \"%s\" instead"), entry->default_value);
1963 goto again;
1965 return False;
1968 nelem = PLGetNumberOfElements(value);
1969 if (nelem < 1) {
1970 wwarning(_("Too few elements in array for key \"WorkspaceBack\"."));
1971 if (changed==0) {
1972 value = entry->plvalue;
1973 changed = 1;
1974 wwarning(_("using default \"%s\" instead"), entry->default_value);
1975 goto again;
1977 return False;
1980 elem = PLGetArrayElement(value, 0);
1981 if (!elem || !PLIsString(elem)) {
1982 wwarning(_("Wrong type for workspace background. Should be Texture."));
1983 if (changed==0) {
1984 value = entry->plvalue;
1985 changed = 1;
1986 wwarning(_("using default \"%s\" instead"), entry->default_value);
1987 goto again;
1989 return False;
1991 val = PLGetString(elem);
1993 if (strcasecmp(val, "None")==0)
1994 return False;
1996 if (strcasecmp(val, "spixmap")!=0 && strcasecmp(val, "tpixmap")!=0
1997 && strcasecmp(val, "cpixmap")!=0) {
1998 texture = parse_texture(scr, value);
2000 else {
2001 /* spixmap || tpixmap || cpixmap */
2002 XColor color;
2003 char *file, cpc[30], *style = "-s";
2004 char *program = "wmsetbg";
2005 char *back;
2007 if (nelem != 3) {
2008 wwarning(_("Too few elements in array for key \"WorkspaceBack\"."));
2009 if (changed==0) {
2010 value = entry->plvalue;
2011 changed = 1;
2012 wwarning(_("using default \"%s\" instead"), entry->default_value);
2013 goto again;
2015 return False;
2018 if (val[0] == 't' || val[0] == 'T')
2019 style = "-t";
2020 else if (val[0] == 'c' || val[0] == 'C')
2021 style = "-e";
2023 sprintf(cpc, "%i", wPreferences.cmap_size);
2025 /* get color */
2026 elem = PLGetArrayElement(value, 2);
2027 if (!elem || !PLIsString(elem)) {
2028 wwarning(_("Cannot get color entry for key \"WorkspaceBack\"."));
2029 if (changed==0) {
2030 value = entry->plvalue;
2031 changed = 1;
2032 wwarning(_("using default \"%s\" instead"), entry->default_value);
2033 goto again;
2035 return False;
2037 val = PLGetString(elem);
2039 if (!XParseColor(dpy, scr->colormap, val, &color)) {
2040 wwarning(_("key \"WorkspaceBack\" has invalid color \"%s\""),
2041 val);
2042 if (changed==0) {
2043 value = entry->plvalue;
2044 changed = 1;
2045 wwarning(_("using default \"%s\" instead"), entry->default_value);
2046 goto again;
2048 return False;
2051 back = wstrdup(val);
2053 /* file name */
2054 elem = PLGetArrayElement(value, 1);
2055 if (!elem || !PLIsString(elem)) {
2056 wwarning(_("Cannot get file entry for key \"WorkspaceBack\"."));
2057 if (changed==0) {
2058 value = entry->plvalue;
2059 changed = 1;
2060 wwarning(_("using default \"%s\" instead"), entry->default_value);
2061 goto again;
2063 return False;
2066 val = PLGetString(elem);
2068 file = FindImage(wPreferences.pixmap_path, val);
2069 if (file) {
2070 if (fork()==0) {
2071 SetupEnvironment(scr);
2073 close(ConnectionNumber(dpy));
2075 execlp(program, program, style, "-c", cpc, "-b", back, file, NULL);
2076 wwarning(_("could not run \"%s\""), program);
2077 exit(-1);
2079 free(file);
2080 } else {
2081 wwarning(_("could not find background image \"%s\""), val);
2084 free(back);
2086 /* This is to let WindowMaker put a color in the background
2087 * until the pixmap is loaded, if the image is big and loads slow.
2088 * It assumes that the color will be set before the image is set
2089 * by the child. Is this true for very small images?
2091 texture = (WTexture*)wTextureMakeSolid(scr, &color);
2094 if (!texture) {
2095 wwarning(_("Error in texture specification for key \"WorkspaceBack\""));
2096 if (changed==0) {
2097 value = entry->plvalue;
2098 changed = 1;
2099 wwarning(_("using default \"%s\" instead"), entry->default_value);
2100 goto again;
2102 return False;
2105 if (ret)
2106 *ret = &texture;
2108 if (addr)
2109 *(WTexture**)addr = texture;
2111 return True;
2113 #endif /* !EXPERIMENTAL */
2116 static int
2117 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2118 void **ret)
2120 static WFont *font;
2121 char *val;
2123 STRINGP("Font");
2125 val = PLGetString(value);
2127 font = wLoadFont(val);
2128 if (!font) {
2129 wwarning(_("could not load any usable font"));
2130 return False;
2133 if (ret)
2134 *ret = font;
2136 if (addr) {
2137 wwarning("BUG:can't assign font value outside update function");
2140 return True;
2144 static int
2145 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2146 void **ret)
2148 static unsigned long pixel;
2149 XColor color;
2150 char *val;
2151 int second_pass=0;
2153 STRINGP("Color");
2155 val = PLGetString(value);
2157 again:
2158 if (!wGetColor(scr, val, &color)) {
2159 wwarning(_("could not get color for key \"%s\""),
2160 PLGetString(entry->plkey));
2161 if (second_pass==0) {
2162 val = PLGetString(entry->plvalue);
2163 second_pass = 1;
2164 wwarning(_("using default \"%s\" instead"), val);
2165 goto again;
2167 return False;
2170 pixel = color.pixel;
2172 if (ret)
2173 *ret = &pixel;
2175 if (addr)
2176 *(unsigned long*)addr = pixel;
2178 return True;
2183 static int
2184 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2185 void **ret)
2187 static WShortKey shortcut;
2188 KeySym ksym;
2189 char *val;
2190 char *k;
2191 char buf[128], *b;
2194 STRINGP("Key spec");
2196 val = PLGetString(value);
2198 if (!val || strcasecmp(val, "NONE")==0) {
2199 shortcut.keycode = 0;
2200 shortcut.modifier = 0;
2201 if (ret)
2202 *ret = &shortcut;
2203 return True;
2206 strcpy(buf, val);
2208 b = (char*)buf;
2210 /* get modifiers */
2211 shortcut.modifier = 0;
2212 while ((k = strchr(b, '+'))!=NULL) {
2213 int mod;
2215 *k = 0;
2216 mod = wXModifierFromKey(b);
2217 if (mod<0) {
2218 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, val);
2219 return False;
2221 shortcut.modifier |= mod;
2223 b = k+1;
2226 /* get key */
2227 ksym = XStringToKeysym(b);
2229 if (ksym==NoSymbol) {
2230 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2231 val);
2232 return False;
2235 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2236 if (shortcut.keycode==0) {
2237 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2238 return False;
2241 if (ret)
2242 *ret = &shortcut;
2244 return True;
2248 static int
2249 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2250 void **ret)
2252 unsigned int mask;
2253 char *str;
2255 STRINGP("Modifier Key");
2257 str = PLGetString(value);
2258 if (!str)
2259 return False;
2261 mask = wXModifierFromKey(str);
2262 if (mask < 0) {
2263 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2264 mask = 0;
2265 return False;
2268 if (addr)
2269 *(unsigned int*)addr = mask;
2271 if (ret)
2272 *ret = &mask;
2274 return True;
2279 /* ---------------- value setting functions --------------- */
2280 static int
2281 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2283 return REFRESH_FORE_COLOR;
2287 static int
2288 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2290 switch (which) {
2291 case WM_DOCK:
2292 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2293 break;
2294 case WM_CLIP:
2295 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2296 break;
2297 default:
2298 break;
2300 return 0;
2304 static int
2305 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2307 if (scr->workspaces) {
2308 wWorkspaceForceChange(scr, scr->current_workspace);
2309 wArrangeIcons(scr, False);
2311 return 0;
2314 #if not_used
2315 static int
2316 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2318 if (*value <= 0)
2319 *(int*)foo = 1;
2321 return 0;
2323 #endif
2327 static int
2328 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2330 Pixmap pixmap;
2331 RImage *img;
2332 int reset = 0;
2334 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2335 wPreferences.icon_size,
2336 ((*texture)->any.type & WREL_BORDER_MASK)
2337 ? WREL_ICON : WREL_FLAT);
2338 if (!img) {
2339 wwarning(_("could not render texture for icon background"));
2340 if (!entry->addr)
2341 wTextureDestroy(scr, *texture);
2342 return 0;
2344 RConvertImage(scr->rcontext, img, &pixmap);
2346 if (scr->icon_tile) {
2347 reset = 1;
2348 RDestroyImage(scr->icon_tile);
2349 XFreePixmap(dpy, scr->icon_tile_pixmap);
2352 scr->icon_tile = img;
2354 if (!wPreferences.flags.noclip) {
2355 if (scr->clip_tile) {
2356 RDestroyImage(scr->clip_tile);
2358 scr->clip_tile = wClipMakeTile(scr, img);
2361 scr->icon_tile_pixmap = pixmap;
2363 if (scr->def_icon_pixmap) {
2364 XFreePixmap(dpy, scr->def_icon_pixmap);
2365 scr->def_icon_pixmap = None;
2367 if (scr->def_ticon_pixmap) {
2368 XFreePixmap(dpy, scr->def_ticon_pixmap);
2369 scr->def_ticon_pixmap = None;
2372 if (scr->icon_back_texture) {
2373 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2375 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2377 if (scr->clip_balloon)
2378 XSetWindowBackground(dpy, scr->clip_balloon,
2379 (*texture)->any.color.pixel);
2382 * Free the texture as nobody else will use it, nor refer to it.
2384 if (!entry->addr)
2385 wTextureDestroy(scr, *texture);
2387 return (reset ? REFRESH_ICON_TILE : 0);
2392 static int
2393 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2395 if (scr->title_font) {
2396 wFreeFont(scr->title_font);
2399 scr->title_font = font;
2401 #ifndef I18N_MB
2402 XSetFont(dpy, scr->window_title_gc, font->font->fid);
2403 #endif
2405 return REFRESH_WINDOW_FONT;
2409 static int
2410 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2412 if (scr->menu_title_font) {
2413 wFreeFont(scr->menu_title_font);
2416 scr->menu_title_font = font;
2418 #ifndef I18N_MB
2419 XSetFont(dpy, scr->menu_title_gc, font->font->fid);
2420 #endif
2422 return REFRESH_MENU_TITLE_FONT;
2426 static int
2427 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2429 if (scr->menu_entry_font) {
2430 wFreeFont(scr->menu_entry_font);
2433 scr->menu_entry_font = font;
2435 #ifndef I18N_MB
2436 XSetFont(dpy, scr->menu_entry_gc, font->font->fid);
2437 XSetFont(dpy, scr->disabled_menu_entry_gc, font->font->fid);
2438 XSetFont(dpy, scr->select_menu_gc, font->font->fid);
2439 #endif
2441 return REFRESH_MENU_FONT;
2446 static int
2447 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2449 if (scr->icon_title_font) {
2450 wFreeFont(scr->icon_title_font);
2453 scr->icon_title_font = font;
2455 #ifndef I18N_MB
2456 XSetFont(dpy, scr->icon_title_gc, font->font->fid);
2457 #endif
2459 return REFRESH_ICON_FONT;
2463 static int
2464 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2466 if (scr->clip_title_font) {
2467 wFreeFont(scr->clip_title_font);
2470 scr->clip_title_font = font;
2472 #ifndef I18N_MB
2473 XSetFont(dpy, scr->clip_title_gc, font->font->fid);
2474 #endif
2476 return REFRESH_ICON_FONT;
2480 static int
2481 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2483 if (scr->info_text_font) {
2484 wFreeFont(scr->info_text_font);
2487 scr->info_text_font = font;
2489 #ifndef I18N_MB
2490 XSetFont(dpy, scr->info_text_gc, font->font->fid);
2491 XSetFont(dpy, scr->line_gc, font->font->fid);
2492 #endif
2494 /* This test works because the scr structure is initially zeroed out
2495 and None = 0. Any other time, the window should be valid. */
2496 if (scr->geometry_display != None) {
2497 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2498 &scr->geometry_display_height);
2499 XResizeWindow(dpy, scr->geometry_display,
2500 scr->geometry_display_width, scr->geometry_display_height);
2503 return 0;
2507 static int
2508 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2510 if (scr->select_pixel!=scr->white_pixel &&
2511 scr->select_pixel!=scr->black_pixel) {
2512 wFreeColor(scr, scr->select_pixel);
2515 scr->select_pixel = color->pixel;
2517 return REFRESH_FORE_COLOR;
2521 static int
2522 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2524 if (scr->select_text_pixel!=scr->white_pixel &&
2525 scr->select_text_pixel!=scr->black_pixel) {
2526 wFreeColor(scr, scr->select_text_pixel);
2529 scr->select_text_pixel = color->pixel;
2531 return REFRESH_FORE_COLOR;
2535 static int
2536 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2538 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2539 scr->clip_title_pixel[index]!=scr->black_pixel) {
2540 wFreeColor(scr, scr->clip_title_pixel[index]);
2543 scr->clip_title_pixel[index] = color->pixel;
2545 return REFRESH_FORE_COLOR;
2549 static int
2550 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2552 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2553 scr->window_title_pixel[index]!=scr->black_pixel) {
2554 wFreeColor(scr, scr->window_title_pixel[index]);
2557 scr->window_title_pixel[index] = color->pixel;
2559 if (index == WS_FOCUSED)
2560 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2561 else if (index == WS_UNFOCUSED)
2562 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2564 return REFRESH_FORE_COLOR;
2568 static int
2569 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2571 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2572 scr->menu_title_pixel[0]!=scr->black_pixel) {
2573 wFreeColor(scr, scr->menu_title_pixel[0]);
2576 scr->menu_title_pixel[0] = color->pixel;
2578 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2580 return REFRESH_FORE_COLOR;
2584 static int
2585 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2587 XGCValues gcv;
2588 #define gcm (GCForeground|GCBackground|GCFillStyle)
2590 if (scr->mtext_pixel!=scr->white_pixel &&
2591 scr->mtext_pixel!=scr->black_pixel) {
2592 wFreeColor(scr, scr->mtext_pixel);
2595 scr->mtext_pixel = color->pixel;
2597 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2600 if (scr->dtext_pixel == scr->mtext_pixel) {
2601 gcv.foreground = scr->white_pixel;
2602 gcv.background = scr->black_pixel;
2603 gcv.fill_style = FillStippled;
2604 } else {
2605 gcv.foreground = scr->dtext_pixel;
2606 gcv.fill_style = FillSolid;
2608 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2610 return REFRESH_FORE_COLOR;
2611 #undef gcm
2615 static int
2616 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2618 XGCValues gcv;
2619 #define gcm (GCForeground|GCBackground|GCFillStyle)
2621 if (scr->dtext_pixel!=scr->white_pixel &&
2622 scr->dtext_pixel!=scr->black_pixel) {
2623 wFreeColor(scr, scr->dtext_pixel);
2626 scr->dtext_pixel = color->pixel;
2628 if (scr->dtext_pixel == scr->mtext_pixel) {
2629 gcv.foreground = scr->white_pixel;
2630 gcv.background = scr->black_pixel;
2631 gcv.fill_style = FillStippled;
2632 } else {
2633 gcv.foreground = scr->dtext_pixel;
2634 gcv.fill_style = FillSolid;
2636 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2638 return REFRESH_FORE_COLOR;
2639 #undef gcm
2645 * Implementation of workspace specific backgrounds.
2647 * WorkspaceBack is used as the default background.
2648 * WorkspaceSpecificBack supplies an array with the textures for
2649 * other workspaces.
2650 * WorkspaceSpecificBack = (ws1texture, ws2texture, "", ws4texture);
2651 * "" means that workspace3 should use the default texture.
2653 * struct WWorkspaceTexture {
2654 * Pixmap pixmap; // the pixmap for non-solid textures.
2655 * //None means the texture is solid
2656 * WPixel color; // color for solid texture
2657 * proplist_t texture; // for checking updates
2658 * };
2661 * All textures are rendered by wmsetbg. When it exits with status 0
2662 * it outputs the pixmap ID.
2663 * wmaker will monitor the fd and when it becomes available it reads the
2664 * pixmap ID and uses it in the texture. The data read from the fd
2665 * is the pixmap ID and the pid of the wmsetbg process, separated by
2666 * a space (the pid is to allow paralel wmsetbg processes).
2668 * The workspace background cant be set if the pid field of the
2669 * texture is 0. Otherwise, the texture is still being rendered
2670 * and cant be set.
2672 * If the workspace background is changed before wmsetbg finishes
2673 * the rendering, wmsetbg must be killed.
2675 * Optimizations:
2676 * Workspace specific textures are generated only when switching to
2677 * that workspace, unless #define SLOW_CONFIGURATION_UPDATE.
2679 * -readme
2681 #ifdef EXPERIMENTAL
2682 static void
2683 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2685 WWorkspaceTexture *wsback;
2686 int setBackground = 0;
2688 /* find out to which wsback, this process belongs to */
2690 wsback->pid = 0;
2691 if (status != 123) {
2692 /* something went wrong during rendering */
2693 XFreePixmap(dpy, wsback->pixmap);
2694 wsback->pixmap = None;
2695 wwarning(_("background texture rendering was unsuccessfull"));
2698 if (setBackground) {
2702 WWorkspaceTexture*
2703 makeWorkspaceTexture(WScreen *scr, WTexture *texture, char *file, char *option)
2705 WWorkspaceTexture *wsback;
2707 wsback = wmalloc(sizeof(WWorkspaceTexture));
2708 wsback->pid = 0;
2710 wsback->solid = (*texture)->any.color.pixel;
2712 if (texture->any.type==WTEX_SOLID) {
2713 wsback->pixmap = None;
2714 } else if (texture->any.type == WTEX_PIXMAP) {
2715 Pixmap pixmap;
2716 if (texture->pixmap.subtype == WTP_TILE) {
2717 RImage *image;
2719 /* render ourseves */
2720 image = RLoadImage(scr->rcontext, file, 0);
2721 if (!image) {
2722 wwarning(_("could not load image %s for option %s:%s\n"),
2723 file, option, RErrorString);
2724 wsback->pixmap = None;
2725 } else {
2727 } else {
2728 /* create a empty pixmap... */
2729 pid_t pid;
2730 int style = texture->pixmap.subtype;
2732 pixmap = XCreatePixmap(dpy, scr->root_win, scr->scr_width,
2733 scr->scr_height, scr->depth);
2735 /* ...and let wmsetbg render it */
2736 pid = fork();
2737 if (pid < 0) {
2738 wsyserror(_("could not spawn texture rendering subprocess for option"));
2739 } else if (pid == 0) {
2740 char *colorn, *pix;
2742 SetupEnvironment(scr);
2744 close(ConnectionNumber(dpy));
2746 colorn = wmalloc(32);
2747 sprintf(colorn, "\"#%2x%2x%2x\"",
2748 texture->any.color.red,
2749 texture->any.color.green,
2750 texture->any.color.blue);
2751 pix = wmalloc(32);
2752 sprintf(pix, "%x", pixmap);
2753 execlp("wmsetbg", "wmsetbg", (style==WTP_SCALE ? "-s":"-e"),
2754 "-b", colorn, "-x", pix, file);
2755 exit(1);
2757 wsback->pixmap = pixmap;
2758 /* must add a death handler to detect when wmsetbg has
2759 * exited (with exit status 123) and refresh the background.
2761 wsback->pid = pid;
2763 } else {
2764 int w, h;
2765 Pixmap pixmap;
2767 switch (texture->any.type) {
2768 case WTEX_HGRADIENT:
2769 case WTEX_MHGRADIENT:
2770 w = scr->scr_width;
2771 h = 8;
2772 break;
2774 case WTEX_VGRADIENT:
2775 case WTEX_MVGRADIENT:
2776 w = 8;
2777 h = scr->scr_height;
2778 break;
2780 case WTEX_DGRADIENT:
2781 case WTEX_MDGRADIENT:
2782 w = scr->scr_width;
2783 h = scr->scr_height;
2784 break;
2786 default:
2787 return NULL;
2790 img = wTextureRenderImage(texture, w, h, WREL_FLAT);
2791 if (!img) {
2792 wwarning(_("could not render texture for workspace background"));
2793 free(wsback);
2794 return NULL;
2796 RConvertImage(scr->rcontext, img, &pixmap);
2797 RDestroyImage(img);
2798 wsback->pixmap = pixmap;
2801 return wsback;
2805 static int
2806 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture,
2807 char *file)
2809 Pixmap pixmap;
2810 RImage *img;
2812 if (scr->defaultTexture) {
2813 if (scr->defaultTexture->pixmap)
2814 XFreePixmap(dpy, scr->defaultTexture->pixmap);
2815 free(scr->defaultTexture);
2818 if (!*texture) {
2819 scr->defaultTexture = NULL;
2820 if (file)
2821 free(file);
2822 return 0;
2825 scr->defaultTexture = makeWorkspaceTexture(scr, *texture, file);
2827 if (!entry->addr)
2828 wTextureDestroy(scr, *texture);
2830 /* free the file name that was passed from the getWSBackground()
2831 * function and placed in entry->extra_data */
2832 if (file)
2833 free(file);
2834 entry->extra_data = NULL;
2836 return REFRESH_WORKSPACE_BACK;
2838 #else /* !EXPERIMENTAL */
2839 static int
2840 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture,
2841 void *foo)
2843 Pixmap pixmap;
2844 RImage *img;
2847 if ((*texture)->any.type==WTEX_SOLID) {
2848 XSetWindowBackground(dpy, scr->root_win, (*texture)->solid.normal.pixel);
2849 XClearWindow(dpy, scr->root_win);
2850 } else {
2851 int w, h;
2853 switch ((*texture)->any.type) {
2854 case WTEX_HGRADIENT:
2855 case WTEX_MHGRADIENT:
2856 w = scr->scr_width;
2857 h = 8;
2858 break;
2860 case WTEX_VGRADIENT:
2861 case WTEX_MVGRADIENT:
2862 w = 8;
2863 h = scr->scr_height;
2864 break;
2866 case WTEX_DGRADIENT:
2867 case WTEX_MDGRADIENT:
2868 w = scr->scr_width;
2869 h = scr->scr_height;
2870 break;
2872 default:
2873 if (!entry->addr)
2874 wTextureDestroy(scr, *texture);
2875 return 0;
2878 img = wTextureRenderImage(*texture, w, h, WREL_FLAT);
2879 if (!img) {
2880 wwarning(_("could not render texture for workspace background"));
2881 if (!entry->addr)
2882 wTextureDestroy(scr, *texture);
2883 return 0;
2885 RConvertImage(scr->rcontext, img, &pixmap);
2886 RDestroyImage(img);
2887 XSetWindowBackgroundPixmap(dpy, scr->root_win, pixmap);
2888 XClearWindow(dpy, scr->root_win);
2892 * Free the texture as nobody else will use it, nor refer to it.
2894 if (!entry->addr)
2895 wTextureDestroy(scr, *texture);
2897 return 0;
2899 #endif /* !EXPERIMENTAL */
2901 static int
2902 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2904 if (scr->widget_texture) {
2905 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2907 scr->widget_texture = *(WTexSolid**)texture;
2909 return 0;
2913 static int
2914 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2916 if (scr->window_title_texture[WS_FOCUSED]) {
2917 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2919 scr->window_title_texture[WS_FOCUSED] = *texture;
2921 if (scr->icon_title_texture) {
2922 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2924 scr->icon_title_texture
2925 = wTextureMakeSolid(scr, &scr->window_title_texture[WS_FOCUSED]->any.color);
2927 return REFRESH_WINDOW_TEXTURES;
2931 static int
2932 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2934 if (scr->window_title_texture[WS_PFOCUSED]) {
2935 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2937 scr->window_title_texture[WS_PFOCUSED] = *texture;
2939 return REFRESH_WINDOW_TEXTURES;
2943 static int
2944 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2946 if (scr->window_title_texture[WS_UNFOCUSED]) {
2947 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2949 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2951 if (scr->resizebar_texture[0]) {
2952 wTextureDestroy(scr, (WTexture*)scr->resizebar_texture[0]);
2954 scr->resizebar_texture[0]
2955 = wTextureMakeSolid(scr, &scr->window_title_texture[WS_UNFOCUSED]->any.color);
2957 if (scr->geometry_display != None)
2958 XSetWindowBackground(dpy, scr->geometry_display,
2959 scr->resizebar_texture[0]->normal.pixel);
2961 return REFRESH_WINDOW_TEXTURES;
2965 static int
2966 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2968 if (scr->menu_title_texture[0]) {
2969 wTextureDestroy(scr, scr->menu_title_texture[0]);
2971 scr->menu_title_texture[0] = *texture;
2973 return REFRESH_MENU_TEXTURES;
2977 static int
2978 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2980 if (scr->menu_item_texture) {
2981 wTextureDestroy(scr, scr->menu_item_texture);
2982 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2984 scr->menu_item_texture = *texture;
2986 scr->menu_item_auxtexture
2987 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2989 return REFRESH_MENU_TEXTURES;
2993 static int
2994 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
2996 WWindow *wwin;
2997 wKeyBindings[index] = *shortcut;
2999 wwin = scr->focused_window;
3001 while (wwin!=NULL) {
3002 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3004 if (!wwin->window_flags.no_bind_keys) {
3005 wWindowSetKeyGrabs(wwin);
3007 wwin = wwin->prev;
3010 return 0;
3014 static int
3015 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3017 wArrangeIcons(scr, True);
3019 return 0;
3025 * Very ugly kluge.
3026 * Need access to the double click variables, so that all widgets in
3027 * wmaker panels will have the same dbl-click values.
3028 * TODO: figure a better way of dealing with it.
3030 #include "WINGsP.h"
3032 static int
3033 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3035 extern _WINGsConfiguration WINGsConfiguration;
3037 if (*value <= 0)
3038 *(int*)foo = 1;
3040 WINGsConfiguration.doubleClickDelay = *value;
3042 return 0;