kde 1.1 update
[wmaker-crm.git] / src / defaults.c
blobc6f517637c6fcdf0c78ee507cb694d4e1d3aad64
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 <fcntl.h>
34 #include <limits.h>
35 #include <signal.h>
37 #ifdef HAVE_DLFCN_H
38 # include <dlfcn.h>
39 #endif
43 #ifndef PATH_MAX
44 #define PATH_MAX DEFAULT_PATH_MAX
45 #endif
47 #include <X11/Xlib.h>
48 #include <X11/Xutil.h>
49 #include <X11/keysym.h>
51 #include <wraster.h>
54 #include "WindowMaker.h"
55 #include "wcore.h"
56 #include "framewin.h"
57 #include "window.h"
58 #include "texture.h"
59 #include "screen.h"
60 #include "resources.h"
61 #include "defaults.h"
62 #include "keybind.h"
63 #include "xmodifier.h"
64 #include "icon.h"
65 #include "funcs.h"
66 #include "actions.h"
67 #include "dock.h"
68 #include "workspace.h"
72 * Our own proplist reader parser. This one will not accept any
73 * syntax errors and is more descriptive in the error messages.
74 * It also doesn't seem to crash.
76 extern proplist_t ReadProplistFromFile(char *file);
79 /***** Global *****/
81 extern WDDomain *WDWindowMaker;
82 extern WDDomain *WDWindowAttributes;
83 extern WDDomain *WDRootMenu;
85 extern int wScreenCount;
88 extern proplist_t wDomainName;
89 extern proplist_t wAttributeDomainName;
91 extern WPreferences wPreferences;
93 extern WShortKey wKeyBindings[WKBD_LAST];
95 typedef struct {
96 char *key;
97 char *default_value;
98 void *extra_data;
99 void *addr;
100 int (*convert)();
101 int (*update)();
102 proplist_t plkey;
103 proplist_t plvalue; /* default value */
104 } WDefaultEntry;
107 /* used to map strings to integers */
108 typedef struct {
109 char *string;
110 short value;
111 char is_alias;
112 } WOptionEnumeration;
116 /* type converters */
117 static int getBool();
118 static int getInt();
119 static int getCoord();
120 #if 0
121 /* this is not used yet */
122 static int getString();
123 #endif
124 static int getPathList();
125 static int getEnum();
126 static int getTexture();
127 static int getWSBackground();
128 static int getWSSpecificBackground();
129 static int getFont();
130 static int getColor();
131 static int getKeybind();
132 static int getModMask();
133 #ifdef NEWSTUFF
134 static int getRImage();
135 #endif
137 /* value setting functions */
138 static int setJustify();
139 static int setIfDockPresent();
140 static int setStickyIcons();
142 static int setPositive();
144 static int setWidgetColor();
145 static int setIconTile();
146 static int setWinTitleFont();
147 static int setMenuTitleFont();
148 static int setMenuTextFont();
149 static int setIconTitleFont();
150 static int setIconTitleColor();
151 static int setIconTitleBack();
152 static int setDisplayFont();
153 static int setWTitleColor();
154 static int setFTitleBack();
155 static int setPTitleBack();
156 static int setUTitleBack();
157 static int setWorkspaceBack();
158 static int setWorkspaceSpecificBack();
159 static int setMenuTitleColor();
160 static int setMenuTextColor();
161 static int setMenuDisabledColor();
162 static int setMenuTitleBack();
163 static int setMenuTextBack();
164 static int setHightlight();
165 static int setHightlightText();
166 static int setKeyGrab();
167 static int setDoubleClick();
168 static int setIconPosition();
170 static int setClipTitleFont();
171 static int setClipTitleColor();
173 #ifdef NEWSTUFF
174 static int setButtonImages();
175 #endif
177 static int updateUsableArea();
182 * Tables to convert strings to enumeration values.
183 * Values stored are char
187 /* WARNING: sum of length of all value strings must not exceed
188 * this value */
189 #define TOTAL_VALUES_LENGTH 80
193 static WOptionEnumeration seFocusModes[] = {
194 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
195 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
196 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
197 {NULL, 0, 0}
200 static WOptionEnumeration seColormapModes[] = {
201 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
202 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
203 {NULL, 0, 0}
206 static WOptionEnumeration sePlacements[] = {
207 {"Auto", WPM_SMART, 0}, {"Smart", WPM_SMART, 1},
208 {"Cascade", WPM_CASCADE, 0},
209 {"Random", WPM_RANDOM, 0},
210 {"Manual", WPM_MANUAL, 0},
211 {NULL, 0, 0}
214 static WOptionEnumeration seGeomDisplays[] = {
215 {"Center", WDIS_CENTER, 0},
216 {"Corner", WDIS_TOPLEFT, 0},
217 {"Floating", WDIS_FRAME_CENTER, 0},
218 {"Line", WDIS_NEW, 0},
219 {NULL, 0, 0}
222 static WOptionEnumeration seSpeeds[] = {
223 {"UltraFast", SPEED_ULTRAFAST, 0},
224 {"Fast", SPEED_FAST, 0},
225 {"Medium", SPEED_MEDIUM, 0},
226 {"Slow", SPEED_SLOW, 0},
227 {"UltraSlow", SPEED_ULTRASLOW, 0},
228 {NULL, 0, 0}
231 static WOptionEnumeration seMouseButtons[] = {
232 {"Left", Button1, 0}, {"Button1", Button1, 1},
233 {"Middle", Button2, 0}, {"Button2", Button2, 1},
234 {"Right", Button3, 0}, {"Button3", Button3, 1},
235 {"Button4", Button4, 0},
236 {"Button5", Button5, 0},
237 {NULL, 0, 0}
240 static WOptionEnumeration seIconificationStyles[] = {
241 {"Zoom", WIS_ZOOM, 0},
242 {"Twist", WIS_TWIST, 0},
243 {"Flip", WIS_FLIP, 0},
244 {"None", WIS_NONE, 0},
245 {"random", WIS_RANDOM, 0},
246 {NULL, 0, 0}
249 static WOptionEnumeration seJustifications[] = {
250 {"Left", WTJ_LEFT, 0},
251 {"Center", WTJ_CENTER, 0},
252 {"Right", WTJ_RIGHT, 0},
253 {NULL, 0, 0}
256 static WOptionEnumeration seIconPositions[] = {
257 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
258 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
259 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
260 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
261 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
262 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
263 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
264 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
265 {NULL, 0, 0}
271 * All entries in the tables bellow, NEED to have a default value
272 * defined, and this value needs to be correct.
275 /* these options will only affect the window manager on startup
277 * static defaults can't access the screen data, because it is
278 * created after these defaults are read
280 WDefaultEntry staticOptionList[] = {
282 {"DisableDithering", "NO", NULL,
283 &wPreferences.no_dithering, getBool, NULL
285 {"ColormapSize", "4", NULL,
286 &wPreferences.cmap_size, getInt, NULL
288 /* static by laziness */
289 {"IconSize", "64", NULL,
290 &wPreferences.icon_size, getInt, NULL
292 {"ModifierKey", "Mod1", NULL,
293 &wPreferences.modifier_mask, getModMask, NULL
295 {"DisableWSMouseActions", "NO", NULL,
296 &wPreferences.disable_root_mouse, getBool, NULL
298 {"FocusMode", "manual", seFocusModes,
299 &wPreferences.focus_mode, getEnum, NULL
300 }, /* have a problem when switching from manual to sloppy without restart */
301 {"NewStyle", "NO", NULL,
302 &wPreferences.new_style, getBool, NULL
304 {"DisableDock", "NO", (void*) WM_DOCK,
305 NULL, getBool, setIfDockPresent
307 {"DisableClip", "NO", (void*) WM_CLIP,
308 NULL, getBool, setIfDockPresent
310 {"DisableMiniwindows", "NO", NULL,
311 &wPreferences.disable_miniwindows, getBool, NULL
317 WDefaultEntry optionList[] = {
318 /* dynamic options */
319 {"IconPosition", "blh", seIconPositions,
320 &wPreferences.icon_yard, getEnum, setIconPosition
322 {"IconificationStyle", "Zoom", seIconificationStyles,
323 &wPreferences.iconification_style, getEnum, NULL
325 {"SelectWindowsMouseButton", "Left", seMouseButtons,
326 &wPreferences.select_button, getEnum, NULL
328 {"WindowListMouseButton", "Middle", seMouseButtons,
329 &wPreferences.windowl_button, getEnum, NULL
331 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
332 &wPreferences.menu_button, getEnum, NULL
334 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
335 &wPreferences.pixmap_path, getPathList, NULL
337 {"IconPath", DEF_ICON_PATHS, NULL,
338 &wPreferences.icon_path, getPathList, NULL
340 {"ColormapMode", "auto", seColormapModes,
341 &wPreferences.colormap_mode, getEnum, NULL
343 {"AutoFocus", "NO", NULL,
344 &wPreferences.auto_focus, getBool, NULL
346 {"RaiseDelay", "0", NULL,
347 &wPreferences.raise_delay, getInt, NULL
349 {"CirculateRaise", "NO", NULL,
350 &wPreferences.circ_raise, getBool, NULL
352 {"Superfluous", "NO", NULL,
353 &wPreferences.superfluous, getBool, NULL
355 {"AdvanceToNewWorkspace", "NO", NULL,
356 &wPreferences.ws_advance, getBool, NULL
358 {"CycleWorkspaces", "NO", NULL,
359 &wPreferences.ws_cycle, getBool, NULL
361 {"StickyIcons", "NO", NULL,
362 &wPreferences.sticky_icons, getBool, setStickyIcons
364 {"SaveSessionOnExit", "NO", NULL,
365 &wPreferences.save_session_on_exit, getBool, NULL
367 {"WrapMenus", "NO", NULL,
368 &wPreferences.wrap_menus, getBool, NULL
370 {"ScrollableMenus", "NO", NULL,
371 &wPreferences.scrollable_menus, getBool, NULL
373 {"MenuScrollSpeed", "medium", seSpeeds,
374 &wPreferences.menu_scroll_speed, getEnum, NULL
376 {"IconSlideSpeed", "medium", seSpeeds,
377 &wPreferences.icon_slide_speed, getEnum, NULL
379 {"ShadeSpeed", "medium", seSpeeds,
380 &wPreferences.shade_speed, getEnum, NULL
382 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
383 &wPreferences.dblclick_time, getInt, setDoubleClick,
385 {"AlignSubmenus", "NO", NULL,
386 &wPreferences.align_menus, getBool, NULL
388 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
389 &wPreferences.open_transients_with_parent, getBool, NULL
391 {"WindowPlacement", "auto", sePlacements,
392 &wPreferences.window_placement, getEnum, NULL
394 {"IgnoreFocusClick","NO", NULL,
395 &wPreferences.ignore_focus_click, getBool, NULL
397 {"UseSaveUnders", "NO", NULL,
398 &wPreferences.use_saveunders, getBool, NULL
400 {"OpaqueMove", "NO", NULL,
401 &wPreferences.opaque_move, getBool, NULL
403 {"DisableSound", "NO", NULL,
404 &wPreferences.no_sound, getBool, NULL
406 {"DisableAnimations", "NO", NULL,
407 &wPreferences.no_animations, getBool, NULL
409 {"DontLinkWorkspaces","NO", NULL,
410 &wPreferences.no_autowrap, getBool, NULL
412 {"AutoArrangeIcons", "NO", NULL,
413 &wPreferences.auto_arrange_icons, getBool, NULL
415 {"NoWindowOverDock", "NO", NULL,
416 &wPreferences.no_window_over_dock, getBool, updateUsableArea
418 {"NoWindowOverIcons", "NO", NULL,
419 &wPreferences.no_window_over_icons, getBool, updateUsableArea
421 {"WindowPlaceOrigin", "(0, 0)", NULL,
422 &wPreferences.window_place_origin, getCoord, NULL
424 {"ResizeDisplay", "corner", seGeomDisplays,
425 &wPreferences.size_display, getEnum, NULL
427 {"MoveDisplay", "corner", seGeomDisplays,
428 &wPreferences.move_display, getEnum, NULL
430 {"DontConfirmKill", "NO", NULL,
431 &wPreferences.dont_confirm_kill, getBool,NULL
433 {"WindowTitleBalloons", "NO", NULL,
434 &wPreferences.window_balloon, getBool, NULL
436 {"MiniwindowTitleBalloons", "NO", NULL,
437 &wPreferences.miniwin_balloon,getBool, NULL
439 {"AppIconBalloons", "NO", NULL,
440 &wPreferences.appicon_balloon,getBool, NULL
442 {"EdgeResistance", "30", NULL,
443 &wPreferences.edge_resistance,getInt, NULL
445 {"DisableBlinking", "NO", NULL,
446 &wPreferences.dont_blink, getBool, NULL
448 #ifdef WEENDOZE_CYCLE
449 {"WindozeCycling","NO", NULL,
450 &wPreferences.windoze_cycling, getBool, NULL
452 {"PopupSwitchMenu","YES",NULL,
453 &wPreferences.popup_switchmenu, getBool, NULL
455 #endif /* WEENDOZE_CYCLE */
456 /* style options */
457 #ifdef NEWSTUFF
458 {"WindowButtonImages", DEF_BUTTON_IMAGES, NULL,
459 &wPreferences.button_images, getRImage, setButtonImages
461 #else
462 {"WidgetColor", "(solid, gray)", NULL,
463 NULL, getTexture, setWidgetColor,
465 #endif
466 {"WorkspaceSpecificBack","()", NULL,
467 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
469 /* WorkspaceBack must come after WorkspaceSpecificBack or
470 * WorkspaceBack wont know WorkspaceSpecificBack was also
471 * specified and 2 copies of wmsetbg will be launched */
472 {"WorkspaceBack", "(solid, black)", NULL,
473 NULL, getWSBackground,setWorkspaceBack
475 {"IconBack", "(solid, gray)", NULL,
476 NULL, getTexture, setIconTile
478 {"TitleJustify", "center", seJustifications,
479 &wPreferences.title_justification, getEnum, setJustify
481 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
482 NULL, getFont, setWinTitleFont
484 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
485 NULL, getFont, setMenuTitleFont
487 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
488 NULL, getFont, setMenuTextFont
490 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
491 NULL, getFont, setIconTitleFont
493 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
494 NULL, getFont, setClipTitleFont
496 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
497 NULL, getFont, setDisplayFont
499 {"HighlightColor", "white", NULL,
500 NULL, getColor, setHightlight
502 {"HighlightTextColor", "black", NULL,
503 NULL, getColor, setHightlightText
505 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
506 NULL, getColor, setClipTitleColor
508 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
509 NULL, getColor, setClipTitleColor
511 {"FTitleColor", "white", (void*)WS_FOCUSED,
512 NULL, getColor, setWTitleColor
514 {"PTitleColor", "white", (void*)WS_PFOCUSED,
515 NULL, getColor, setWTitleColor
517 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
518 NULL, getColor, setWTitleColor
520 {"FTitleBack", "(solid, black)", NULL,
521 NULL, getTexture, setFTitleBack
523 {"PTitleBack", "(solid, \"#616161\")", NULL,
524 NULL, getTexture, setPTitleBack
526 {"UTitleBack", "(solid, gray)", NULL,
527 NULL, getTexture, setUTitleBack
529 {"MenuTitleColor", "white", NULL,
530 NULL, getColor, setMenuTitleColor
532 {"MenuTextColor", "black", NULL,
533 NULL, getColor, setMenuTextColor
535 {"MenuDisabledColor", "\"#616161\"", NULL,
536 NULL, getColor, setMenuDisabledColor
538 {"MenuTitleBack", "(solid, black)", NULL,
539 NULL, getTexture, setMenuTitleBack
541 {"MenuTextBack", "(solid, gray)", NULL,
542 NULL, getTexture, setMenuTextBack
544 {"IconTitleColor", "white", NULL,
545 NULL, getColor, setIconTitleColor
547 {"IconTitleBack", "black", NULL,
548 NULL, getColor, setIconTitleBack
550 /* keybindings */
551 #ifndef LITE
552 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
553 NULL, getKeybind, setKeyGrab
555 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
556 NULL, getKeybind, setKeyGrab
558 #endif /* LITE */
559 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
560 NULL, getKeybind, setKeyGrab
562 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
563 NULL, getKeybind, setKeyGrab
565 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
566 NULL, getKeybind, setKeyGrab
568 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
569 NULL, getKeybind, setKeyGrab
571 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
572 NULL, getKeybind, setKeyGrab
574 {"HideKey", "None", (void*)WKBD_HIDE,
575 NULL, getKeybind, setKeyGrab
577 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
578 NULL, getKeybind, setKeyGrab
580 {"CloseKey", "None", (void*)WKBD_CLOSE,
581 NULL, getKeybind, setKeyGrab
583 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
584 NULL, getKeybind, setKeyGrab
586 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
587 NULL, getKeybind, setKeyGrab
589 {"RaiseKey", "Meta+Up", (void*)WKBD_RAISE,
590 NULL, getKeybind, setKeyGrab
592 {"LowerKey", "Meta+Down", (void*)WKBD_LOWER,
593 NULL, getKeybind, setKeyGrab
595 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
596 NULL, getKeybind, setKeyGrab
598 {"ShadeKey", "None", (void*)WKBD_SHADE,
599 NULL, getKeybind, setKeyGrab
601 {"SelectKey", "None", (void*)WKBD_SELECT,
602 NULL, getKeybind, setKeyGrab
604 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
605 NULL, getKeybind, setKeyGrab
607 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
608 NULL, getKeybind, setKeyGrab
610 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
611 NULL, getKeybind, setKeyGrab
613 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
614 NULL, getKeybind, setKeyGrab
616 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
617 NULL, getKeybind, setKeyGrab
619 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
620 NULL, getKeybind, setKeyGrab
622 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
623 NULL, getKeybind, setKeyGrab
625 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
626 NULL, getKeybind, setKeyGrab
628 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
629 NULL, getKeybind, setKeyGrab
631 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
632 NULL, getKeybind, setKeyGrab
634 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
635 NULL, getKeybind, setKeyGrab
637 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
638 NULL, getKeybind, setKeyGrab
640 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
641 NULL, getKeybind, setKeyGrab
643 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
644 NULL, getKeybind, setKeyGrab
646 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
647 NULL, getKeybind, setKeyGrab
649 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
650 NULL, getKeybind, setKeyGrab
652 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
653 NULL, getKeybind, setKeyGrab
655 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
656 NULL, getKeybind, setKeyGrab
658 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
659 NULL, getKeybind, setKeyGrab
661 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
662 NULL, getKeybind, setKeyGrab
664 #ifdef EXTEND_WINDOWSHORTCUT
665 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
666 NULL, getKeybind, setKeyGrab
668 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
669 NULL, getKeybind, setKeyGrab
671 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
672 NULL, getKeybind, setKeyGrab
674 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
675 NULL, getKeybind, setKeyGrab
677 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
678 NULL, getKeybind, setKeyGrab
680 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
681 NULL, getKeybind, setKeyGrab
683 #endif /* EXTEND_WINDOWSHORTCUT */
685 #ifdef KEEP_XKB_LOCK_STATUS
686 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
687 NULL, getKeybind, setKeyGrab
689 {"KbdModeLock", "NO", NULL,
690 &wPreferences.modelock, getBool, NULL
692 #endif /* KEEP_XKB_LOCK_STATUS */
693 #ifdef TITLE_TEXT_SHADOW
694 ,{"FShadowColor", "black", (void*)WS_SFOCUSED,
695 NULL, getColor, setWTitleColor
697 {"PShadowColor", "black", (void*)WS_SPFOCUSED,
698 NULL, getColor, setWTitleColor
700 {"UShadowColor", "grey50", (void*)WS_SUNFOCUSED,
701 NULL, getColor, setWTitleColor
703 {"MShadowColor", "black", (void*)WS_SMENU,
704 NULL, getColor, setMenuTitleColor
706 {"Shadow", "Yes", NULL,
707 &wPreferences.title_shadow, getBool, setJustify
709 #endif /* TITLE_TEXT_SHADOW */
713 #if 0
714 static void rereadDefaults(void);
715 #endif
717 #if 0
718 static void
719 rereadDefaults(void)
721 /* must defer the update because accessing X data from a
722 * signal handler can mess up Xlib */
725 #endif
727 static void
728 initDefaults()
730 int i;
731 WDefaultEntry *entry;
733 PLSetStringCmpHook(StringCompareHook);
735 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
736 entry = &optionList[i];
738 entry->plkey = PLMakeString(entry->key);
739 if (entry->default_value)
740 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
741 else
742 entry->plvalue = NULL;
745 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
746 entry = &staticOptionList[i];
748 entry->plkey = PLMakeString(entry->key);
749 if (entry->default_value)
750 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
751 else
752 entry->plvalue = NULL;
756 wDomainName = PLMakeString(WMDOMAIN_NAME);
757 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
759 PLRegister(wDomainName, rereadDefaults);
760 PLRegister(wAttributeDomainName, rereadDefaults);
767 #if 0
768 proplist_t
769 wDefaultsInit(int screen_number)
771 static int defaults_inited = 0;
772 proplist_t dict;
774 if (!defaults_inited) {
775 initDefaults();
778 dict = PLGetDomain(wDomainName);
779 if (!dict) {
780 wwarning(_("could not read domain \"%s\" from defaults database"),
781 PLGetString(wDomainName));
784 return dict;
786 #endif
789 void
790 wDefaultsDestroyDomain(WDDomain *domain)
792 if (domain->dictionary)
793 PLRelease(domain->dictionary);
794 free(domain->path);
795 free(domain);
799 WDDomain*
800 wDefaultsInitDomain(char *domain, Bool requireDictionary)
802 WDDomain *db;
803 struct stat stbuf;
804 static int inited = 0;
805 char path[PATH_MAX];
806 char *the_path;
807 proplist_t shared_dict=NULL;
809 if (!inited) {
810 inited = 1;
811 initDefaults();
814 db = wmalloc(sizeof(WDDomain));
815 memset(db, 0, sizeof(WDDomain));
816 db->domain_name = domain;
817 db->path = wdefaultspathfordomain(domain);
818 the_path = db->path;
820 if (the_path && stat(the_path, &stbuf)>=0) {
821 db->dictionary = ReadProplistFromFile(the_path);
822 if (db->dictionary) {
823 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
824 PLRelease(db->dictionary);
825 db->dictionary = NULL;
826 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
827 domain, the_path);
829 db->timestamp = stbuf.st_mtime;
830 } else {
831 wwarning(_("could not load domain %s from user defaults database"),
832 domain);
836 /* global system dictionary */
837 sprintf(path, "%s/%s", SYSCONFDIR, domain);
838 if (stat(path, &stbuf)>=0) {
839 shared_dict = ReadProplistFromFile(path);
840 if (shared_dict) {
841 if (requireDictionary && !PLIsDictionary(shared_dict)) {
842 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
843 domain, path);
844 PLRelease(shared_dict);
845 shared_dict = NULL;
846 } else {
847 if (db->dictionary && PLIsDictionary(shared_dict) &&
848 PLIsDictionary(db->dictionary)) {
849 PLMergeDictionaries(shared_dict, db->dictionary);
850 PLRelease(db->dictionary);
851 db->dictionary = shared_dict;
852 if (stbuf.st_mtime > db->timestamp)
853 db->timestamp = stbuf.st_mtime;
854 } else if (!db->dictionary) {
855 db->dictionary = shared_dict;
856 if (stbuf.st_mtime > db->timestamp)
857 db->timestamp = stbuf.st_mtime;
860 } else {
861 wwarning(_("could not load domain %s from global defaults database"),
862 domain);
866 /* set to save it in user's directory, no matter from where it was read */
867 if (db->dictionary) {
868 proplist_t tmp = PLMakeString(db->path);
870 PLSetFilename(db->dictionary, tmp);
871 PLRelease(tmp);
874 return db;
878 void
879 wReadStaticDefaults(proplist_t dict)
881 proplist_t plvalue;
882 WDefaultEntry *entry;
883 int i;
884 void *tdata;
887 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
888 entry = &staticOptionList[i];
890 if (dict)
891 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
892 else
893 plvalue = NULL;
895 if (!plvalue) {
896 /* no default in the DB. Use builtin default */
897 plvalue = entry->plvalue;
900 if (plvalue) {
901 /* convert data */
902 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
903 if (entry->update) {
904 (*entry->update)(NULL, entry, tdata, entry->extra_data);
910 void
911 wDefaultsCheckDomains(void *foo)
913 WScreen *scr;
914 struct stat stbuf;
915 proplist_t dict;
916 int i;
917 char path[PATH_MAX];
919 #ifdef HEARTBEAT
920 puts("Checking domains...");
921 #endif
922 if (stat(WDWindowMaker->path, &stbuf)>=0
923 && WDWindowMaker->timestamp < stbuf.st_mtime) {
924 proplist_t shared_dict = NULL;
925 #ifdef HEARTBEAT
926 puts("Checking WindowMaker domain");
927 #endif
928 WDWindowMaker->timestamp = stbuf.st_mtime;
930 /* global dictionary */
931 sprintf(path, "%s/WindowMaker", SYSCONFDIR);
932 if (stat(path, &stbuf)>=0) {
933 shared_dict = ReadProplistFromFile(path);
934 if (shared_dict && !PLIsDictionary(shared_dict)) {
935 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
936 "WindowMaker", path);
937 PLRelease(shared_dict);
938 shared_dict = NULL;
939 } else if (!shared_dict) {
940 wwarning(_("could not load domain %s from global defaults database"),
941 "WindowMaker");
944 /* user dictionary */
945 dict = ReadProplistFromFile(WDWindowMaker->path);
946 if (dict) {
947 if (!PLIsDictionary(dict)) {
948 PLRelease(dict);
949 dict = NULL;
950 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
951 "WindowMaker", WDWindowMaker->path);
952 } else {
953 if (shared_dict) {
954 PLSetFilename(shared_dict, PLGetFilename(dict));
955 PLMergeDictionaries(shared_dict, dict);
956 PLRelease(dict);
957 dict = shared_dict;
958 shared_dict = NULL;
960 for (i=0; i<wScreenCount; i++) {
961 scr = wScreenWithNumber(i);
962 if (scr)
963 wReadDefaults(scr, dict);
965 if (WDWindowMaker->dictionary) {
966 PLRelease(WDWindowMaker->dictionary);
968 WDWindowMaker->dictionary = dict;
970 } else {
971 wwarning(_("could not load domain %s from user defaults database"),
972 "WindowMaker");
974 if (shared_dict) {
975 PLRelease(shared_dict);
979 if (stat(WDWindowAttributes->path, &stbuf)>=0
980 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
981 #ifdef HEARTBEAT
982 puts("Checking WMWindowAttributes domain");
983 #endif
984 dict = ReadProplistFromFile(WDWindowAttributes->path);
985 if (dict) {
986 if (!PLIsDictionary(dict)) {
987 PLRelease(dict);
988 dict = NULL;
989 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
990 "WMWindowAttributes", WDWindowAttributes->path);
991 } else {
992 if (WDWindowAttributes->dictionary)
993 PLRelease(WDWindowAttributes->dictionary);
994 WDWindowAttributes->dictionary = dict;
995 for (i=0; i<wScreenCount; i++) {
996 scr = wScreenWithNumber(i);
997 if (scr)
998 wDefaultUpdateIcons(scr);
1001 } else {
1002 wwarning(_("could not load domain %s from user defaults database"),
1003 "WMWindowAttributes");
1005 WDWindowAttributes->timestamp = stbuf.st_mtime;
1008 #ifndef LITE
1009 if (stat(WDRootMenu->path, &stbuf)>=0
1010 && WDRootMenu->timestamp < stbuf.st_mtime) {
1011 dict = ReadProplistFromFile(WDRootMenu->path);
1012 #ifdef HEARTBEAT
1013 puts("Checking WMRootMenu domain");
1014 #endif
1015 if (dict) {
1016 if (!PLIsArray(dict) && !PLIsString(dict)) {
1017 PLRelease(dict);
1018 dict = NULL;
1019 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1020 "WMRootMenu", WDRootMenu->path);
1021 } else {
1022 if (WDRootMenu->dictionary) {
1023 PLRelease(WDRootMenu->dictionary);
1025 WDRootMenu->dictionary = dict;
1027 } else {
1028 wwarning(_("could not load domain %s from user defaults database"),
1029 "WMRootMenu");
1031 WDRootMenu->timestamp = stbuf.st_mtime;
1033 #endif /* !LITE */
1035 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1040 #define REFRESH_WINDOW_TEXTURES (1<<0)
1041 #define REFRESH_MENU_TEXTURES (1<<1)
1042 #define REFRESH_WINDOW_FONT (1<<2)
1043 #define REFRESH_MENU_TITLE_FONT (1<<3)
1044 #define REFRESH_MENU_FONT (1<<4)
1045 #define REFRESH_FORE_COLOR (1<<5)
1046 #define REFRESH_ICON_TILE (1<<6)
1047 #define REFRESH_ICON_FONT (1<<7)
1048 #define REFRESH_WORKSPACE_BACK (1<<8)
1050 #define REFRESH_BUTTON_IMAGES (1<<9)
1052 static void
1053 refreshMenus(WScreen *scr, int flags)
1055 WMenu *menu;
1057 #ifndef LITE
1058 menu = scr->root_menu;
1059 if (menu)
1060 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
1062 menu = scr->switch_menu;
1063 if (menu)
1064 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
1066 #endif /* !LITE */
1068 menu = scr->workspace_menu;
1069 if (menu)
1070 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
1072 menu = scr->window_menu;
1073 if (menu)
1074 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
1076 menu = scr->icon_menu;
1077 if (menu)
1078 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
1080 if (scr->dock) {
1081 menu = scr->dock->menu;
1082 if (menu)
1083 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
1085 menu = scr->clip_menu;
1086 if (menu)
1087 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
1089 menu = scr->clip_submenu;
1090 if (menu)
1091 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
1093 menu = scr->clip_options;
1094 if (menu)
1095 wMenuRefresh(!menu->flags.brother ? menu : menu->brother, flags);
1099 static void
1100 refreshAppIcons(WScreen *scr, int flags)
1102 WAppIcon *aicon = scr->app_icon_list;
1104 while (aicon) {
1105 if (aicon->icon) {
1106 aicon->icon->force_paint = 1;
1108 aicon = aicon->next;
1113 static void
1114 refreshWindows(WScreen *scr, int flags)
1116 WWindow *wwin;
1118 wwin = scr->focused_window;
1119 while (wwin) {
1120 if (flags & REFRESH_WINDOW_FONT) {
1121 wWindowConfigureBorders(wwin);
1123 if ((flags & (REFRESH_ICON_TILE|REFRESH_WINDOW_TEXTURES)) &&
1124 wwin->flags.miniaturized && wwin->icon) {
1125 wwin->icon->force_paint = 1;
1127 if (flags & REFRESH_WINDOW_TEXTURES) {
1128 wwin->frame->flags.need_texture_remake = 1;
1130 wwin = wwin->prev;
1135 void
1136 wReadDefaults(WScreen *scr, proplist_t new_dict)
1138 proplist_t plvalue, old_value;
1139 WDefaultEntry *entry;
1140 int i, must_update;
1141 int needs_refresh;
1142 void *tdata;
1143 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1144 ? WDWindowMaker->dictionary : NULL);
1146 must_update = 0;
1148 needs_refresh = 0;
1150 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1151 entry = &optionList[i];
1153 if (new_dict)
1154 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1155 else
1156 plvalue = NULL;
1158 if (!old_dict)
1159 old_value = NULL;
1160 else
1161 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1164 if (!plvalue && !old_value) {
1165 /* no default in the DB. Use builtin default */
1166 plvalue = entry->plvalue;
1167 if (plvalue && new_dict) {
1168 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1169 must_update = 1;
1171 } else if (!plvalue) {
1172 /* value was deleted from DB. Keep current value */
1173 continue;
1174 } else if (!old_value) {
1175 /* set value for the 1st time */
1176 } else if (!PLIsEqual(plvalue, old_value)) {
1177 /* value has changed */
1178 } else {
1179 /* value was not changed since last time */
1180 continue;
1183 if (plvalue) {
1184 #ifdef DEBUG
1185 printf("Updating %s to %s\n", entry->key, PLGetDescription(plvalue));
1186 #endif
1187 /* convert data */
1188 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1189 if (entry->update) {
1190 needs_refresh |=
1191 (*entry->update)(scr, entry, tdata, entry->extra_data);
1197 if (needs_refresh!=0) {
1198 int foo;
1200 foo = 0;
1201 if (needs_refresh & REFRESH_MENU_TEXTURES)
1202 foo |= MR_TEXT_BACK;
1203 if (needs_refresh & REFRESH_MENU_FONT)
1204 foo |= MR_RESIZED;
1205 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1206 foo |= MR_TITLE_TEXT;
1208 if (foo)
1209 refreshMenus(scr, foo);
1211 if (needs_refresh & (REFRESH_WINDOW_TEXTURES|REFRESH_WINDOW_FONT|
1212 REFRESH_ICON_TILE))
1213 refreshWindows(scr, needs_refresh);
1215 if (needs_refresh & REFRESH_ICON_TILE)
1216 refreshAppIcons(scr, needs_refresh);
1218 #ifdef NEWSTUFF
1219 if ((needs_refresh & REFRESH_BUTTON_IMAGES)
1220 && wPreferences.button_images) {
1222 int w, h;
1223 RImage *image = wPreferences.button_images;
1224 RImage *tmp;
1225 int theight;
1227 w = wPreferences.button_images->width / 2;
1228 h = wPreferences.button_images->height / PRED_BPIXMAPS;
1230 theight = scr->title_font->height + TITLEBAR_EXTRA_HEIGHT - 3;
1232 for (i = 0; i < PRED_BPIXMAPS; i++) {
1233 tmp = RGetSubImage(image, 0, i * h, w, h);
1234 if (scr->button_images[0][i])
1235 RDestroyImage(scr->button_images[0][i]);
1237 scr->button_images[0][i] = RScaleImage(tmp, theight, theight);
1238 RDestroyImage(tmp);
1240 tmp = RGetSubImage(image, w, i * h, image->width - w, h);
1241 if (scr->button_images[1][i])
1242 RDestroyImage(scr->button_images[1][i]);
1244 scr->button_images[1][i] = RScaleImage(tmp, theight, theight);
1245 RDestroyImage(tmp);
1248 #endif /* NEWSTUFF */
1249 wRefreshDesktop(scr);
1254 void
1255 wDefaultUpdateIcons(WScreen *scr)
1257 WAppIcon *aicon = scr->app_icon_list;
1258 WWindow *wwin = scr->focused_window;
1259 char *file;
1261 while(aicon) {
1262 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1263 False);
1264 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1265 || (file && !aicon->icon->file)) {
1266 RImage *new_image;
1268 if (aicon->icon->file)
1269 free(aicon->icon->file);
1270 aicon->icon->file = wstrdup(file);
1272 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1273 aicon->wm_class);
1274 if (new_image) {
1275 wIconChangeImage(aicon->icon, new_image);
1276 wAppIconPaint(aicon);
1279 aicon = aicon->next;
1282 if (!wPreferences.flags.noclip)
1283 wClipIconPaint(scr->clip_icon);
1285 while (wwin) {
1286 if (wwin->icon && wwin->flags.miniaturized) {
1287 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1288 False);
1289 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1290 || (file && !wwin->icon->file)) {
1291 RImage *new_image;
1293 if (wwin->icon->file)
1294 free(wwin->icon->file);
1295 wwin->icon->file = wstrdup(file);
1297 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1298 wwin->wm_class);
1299 if (new_image)
1300 wIconChangeImage(wwin->icon, new_image);
1303 wwin = wwin->prev;
1308 /* --------------------------- Local ----------------------- */
1310 #define STRINGP(x) if (!PLIsString(value)) { \
1311 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1312 entry->key, x); \
1313 return False; }
1317 static int
1318 string2index(proplist_t key, proplist_t val, proplist_t def,
1319 WOptionEnumeration *values)
1321 char *str;
1322 WOptionEnumeration *v;
1323 char buffer[TOTAL_VALUES_LENGTH];
1325 if (PLIsString(val) && (str = PLGetString(val))) {
1326 for (v=values; v->string!=NULL; v++) {
1327 if (strcasecmp(v->string, str)==0)
1328 return v->value;
1332 buffer[0] = 0;
1333 for (v=values; v->string!=NULL; v++) {
1334 if (!v->is_alias) {
1335 if (buffer[0]!=0)
1336 strcat(buffer, ", ");
1337 strcat(buffer, v->string);
1340 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1341 PLGetString(key), buffer);
1343 if (def) {
1344 return string2index(key, val, NULL, values);
1347 return -1;
1354 * value - is the value in the defaults DB
1355 * addr - is the address to store the data
1356 * ret - is the address to store a pointer to a temporary buffer. ret
1357 * must not be freed and is used by the set functions
1359 static int
1360 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1361 void **ret)
1363 static char data;
1364 char *val;
1365 int second_pass=0;
1367 STRINGP("Boolean");
1369 val = PLGetString(value);
1371 again:
1372 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1373 || strcasecmp(val, "YES")==0) {
1375 data = 1;
1376 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1377 || strcasecmp(val, "NO")==0) {
1378 data = 0;
1379 } else {
1380 int i;
1381 if (sscanf(val, "%i", &i)==1) {
1382 if (i!=0)
1383 data = 1;
1384 else
1385 data = 0;
1386 } else {
1387 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1388 val, entry->key);
1389 if (second_pass==0) {
1390 val = PLGetString(entry->plvalue);
1391 second_pass = 1;
1392 wwarning(_("using default \"%s\" instead"), val);
1393 goto again;
1395 return False;
1399 if (ret)
1400 *ret = &data;
1402 if (addr) {
1403 *(char*)addr = data;
1406 return True;
1410 static int
1411 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1412 void **ret)
1414 static int data;
1415 char *val;
1418 STRINGP("Integer");
1420 val = PLGetString(value);
1422 if (sscanf(val, "%i", &data)!=1) {
1423 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1424 val, entry->key);
1425 val = PLGetString(entry->plvalue);
1426 wwarning(_("using default \"%s\" instead"), val);
1427 if (sscanf(val, "%i", &data)!=1) {
1428 return False;
1432 if (ret)
1433 *ret = &data;
1435 if (addr) {
1436 *(int*)addr = data;
1438 return True;
1442 static int
1443 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1444 void **ret)
1446 static WCoord data;
1447 char *val_x, *val_y;
1448 int nelem, changed=0;
1449 proplist_t elem_x, elem_y;
1451 again:
1452 if (!PLIsArray(value)) {
1453 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1454 entry->key, "Coordinate");
1455 if (changed==0) {
1456 value = entry->plvalue;
1457 changed = 1;
1458 wwarning(_("using default \"%s\" instead"), entry->default_value);
1459 goto again;
1461 return False;
1464 nelem = PLGetNumberOfElements(value);
1465 if (nelem != 2) {
1466 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1467 entry->key);
1468 if (changed==0) {
1469 value = entry->plvalue;
1470 changed = 1;
1471 wwarning(_("using default \"%s\" instead"), entry->default_value);
1472 goto again;
1474 return False;
1477 elem_x = PLGetArrayElement(value, 0);
1478 elem_y = PLGetArrayElement(value, 1);
1480 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1481 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1482 entry->key);
1483 if (changed==0) {
1484 value = entry->plvalue;
1485 changed = 1;
1486 wwarning(_("using default \"%s\" instead"), entry->default_value);
1487 goto again;
1489 return False;
1492 val_x = PLGetString(elem_x);
1493 val_y = PLGetString(elem_y);
1495 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1496 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1497 if (changed==0) {
1498 value = entry->plvalue;
1499 changed = 1;
1500 wwarning(_("using default \"%s\" instead"), entry->default_value);
1501 goto again;
1503 return False;
1506 if (data.x < 0)
1507 data.x = 0;
1508 else if (data.x > scr->scr_width/3)
1509 data.x = scr->scr_width/3;
1510 if (data.y < 0)
1511 data.y = 0;
1512 else if (data.y > scr->scr_height/3)
1513 data.y = scr->scr_height/3;
1515 if (ret)
1516 *ret = &data;
1518 if (addr) {
1519 *(WCoord*)addr = data;
1522 return True;
1526 #if 0
1527 /* This function is not used at the moment. */
1528 static int
1529 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1530 void **ret)
1532 static char *data;
1534 STRINGP("String");
1536 data = PLGetString(value);
1538 if (!data) {
1539 data = PLGetString(entry->plvalue);
1540 if (!data)
1541 return False;
1544 if (ret)
1545 *ret = &data;
1547 if (addr)
1548 *(char**)addr = wstrdup(data);
1550 return True;
1552 #endif
1555 static int
1556 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1557 void **ret)
1559 static char *data;
1560 int i, count, len;
1561 char *ptr;
1562 proplist_t d;
1563 int changed=0;
1565 again:
1566 if (!PLIsArray(value)) {
1567 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1568 entry->key, "an array of paths");
1569 if (changed==0) {
1570 value = entry->plvalue;
1571 changed = 1;
1572 wwarning(_("using default \"%s\" instead"), entry->default_value);
1573 goto again;
1575 return False;
1578 i = 0;
1579 count = PLGetNumberOfElements(value);
1580 if (count < 1) {
1581 if (changed==0) {
1582 value = entry->plvalue;
1583 changed = 1;
1584 wwarning(_("using default \"%s\" instead"), entry->default_value);
1585 goto again;
1587 return False;
1590 len = 0;
1591 for (i=0; i<count; i++) {
1592 d = PLGetArrayElement(value, i);
1593 if (!d || !PLIsString(d)) {
1594 count = i;
1595 break;
1597 len += strlen(PLGetString(d))+1;
1600 ptr = data = wmalloc(len+1);
1602 for (i=0; i<count; i++) {
1603 d = PLGetArrayElement(value, i);
1604 if (!d || !PLIsString(d)) {
1605 break;
1607 strcpy(ptr, PLGetString(d));
1608 ptr += strlen(PLGetString(d));
1609 *ptr = ':';
1610 ptr++;
1612 ptr--; *(ptr--) = 0;
1614 if (*(char**)addr!=NULL) {
1615 free(*(char**)addr);
1617 *(char**)addr = data;
1619 return True;
1623 static int
1624 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1625 void **ret)
1627 static signed char data;
1629 data = string2index(entry->plkey, value, entry->default_value,
1630 (WOptionEnumeration*)entry->extra_data);
1631 if (data < 0)
1632 return False;
1634 if (ret)
1635 *ret = &data;
1637 if (addr)
1638 *(signed char*)addr = data;
1640 return True;
1646 * (solid <color>)
1647 * (hgradient <color> <color>)
1648 * (vgradient <color> <color>)
1649 * (dgradient <color> <color>)
1650 * (mhgradient <color> <color> ...)
1651 * (mvgradient <color> <color> ...)
1652 * (tpixmap <file> <color>)
1653 * (spixmap <file> <color>)
1654 * (cpixmap <file> <color>)
1655 * (thgradient <file> <opaqueness> <color> <color>)
1656 * (tvgradient <file> <opaqueness> <color> <color>)
1657 * (tdgradient <file> <opaqueness> <color> <color>)
1658 * (function <lib> <function> ...)
1661 static WTexture*
1662 parse_texture(WScreen *scr, proplist_t pl)
1664 proplist_t elem;
1665 char *val;
1666 int nelem;
1667 WTexture *texture=NULL;
1669 nelem = PLGetNumberOfElements(pl);
1670 if (nelem < 1)
1671 return NULL;
1674 elem = PLGetArrayElement(pl, 0);
1675 if (!elem || !PLIsString(elem))
1676 return NULL;
1677 val = PLGetString(elem);
1680 if (strcasecmp(val, "solid")==0) {
1681 XColor color;
1683 if (nelem != 2)
1684 return NULL;
1686 /* get color */
1688 elem = PLGetArrayElement(pl, 1);
1689 if (!elem || !PLIsString(elem))
1690 return NULL;
1691 val = PLGetString(elem);
1693 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1694 wwarning(_("\"%s\" is not a valid color name"), val);
1695 return NULL;
1698 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1699 } else if (strcasecmp(val, "dgradient")==0
1700 || strcasecmp(val, "vgradient")==0
1701 || strcasecmp(val, "hgradient")==0) {
1702 RColor color1, color2;
1703 XColor xcolor;
1704 int type;
1706 if (nelem != 3) {
1707 wwarning(_("bad number of arguments in gradient specification"));
1708 return NULL;
1711 if (val[0]=='d' || val[0]=='D')
1712 type = WTEX_DGRADIENT;
1713 else if (val[0]=='h' || val[0]=='H')
1714 type = WTEX_HGRADIENT;
1715 else
1716 type = WTEX_VGRADIENT;
1719 /* get from color */
1720 elem = PLGetArrayElement(pl, 1);
1721 if (!elem || !PLIsString(elem))
1722 return NULL;
1723 val = PLGetString(elem);
1725 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1726 wwarning(_("\"%s\" is not a valid color name"), val);
1727 return NULL;
1729 color1.alpha = 255;
1730 color1.red = xcolor.red >> 8;
1731 color1.green = xcolor.green >> 8;
1732 color1.blue = xcolor.blue >> 8;
1734 /* get to color */
1735 elem = PLGetArrayElement(pl, 2);
1736 if (!elem || !PLIsString(elem)) {
1737 return NULL;
1739 val = PLGetString(elem);
1741 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1742 wwarning(_("\"%s\" is not a valid color name"), val);
1743 return NULL;
1745 color2.alpha = 255;
1746 color2.red = xcolor.red >> 8;
1747 color2.green = xcolor.green >> 8;
1748 color2.blue = xcolor.blue >> 8;
1750 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1752 } else if (strcasecmp(val, "mhgradient")==0
1753 || strcasecmp(val, "mvgradient")==0
1754 || strcasecmp(val, "mdgradient")==0) {
1755 XColor color;
1756 RColor **colors;
1757 int i, count;
1758 int type;
1760 if (nelem < 3) {
1761 wwarning(_("too few arguments in multicolor gradient specification"));
1762 return NULL;
1765 if (val[1]=='h' || val[1]=='H')
1766 type = WTEX_MHGRADIENT;
1767 else if (val[1]=='v' || val[1]=='V')
1768 type = WTEX_MVGRADIENT;
1769 else
1770 type = WTEX_MDGRADIENT;
1772 count = nelem-1;
1774 colors = wmalloc(sizeof(RColor*)*(count+1));
1776 for (i=0; i<count; i++) {
1777 elem = PLGetArrayElement(pl, i+1);
1778 if (!elem || !PLIsString(elem)) {
1779 for (--i; i>=0; --i) {
1780 free(colors[i]);
1782 free(colors);
1783 return NULL;
1785 val = PLGetString(elem);
1787 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1788 wwarning(_("\"%s\" is not a valid color name"), val);
1789 for (--i; i>=0; --i) {
1790 free(colors[i]);
1792 free(colors);
1793 return NULL;
1794 } else {
1795 colors[i] = wmalloc(sizeof(RColor));
1796 colors[i]->red = color.red >> 8;
1797 colors[i]->green = color.green >> 8;
1798 colors[i]->blue = color.blue >> 8;
1801 colors[i] = NULL;
1803 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1804 } else if (strcasecmp(val, "spixmap")==0 ||
1805 strcasecmp(val, "cpixmap")==0 ||
1806 strcasecmp(val, "tpixmap")==0) {
1807 XColor color;
1808 int type;
1810 if (nelem != 3)
1811 return NULL;
1813 if (val[0] == 's' || val[0] == 'S')
1814 type = WTP_SCALE;
1815 else if (val[0] == 'c' || val[0] == 'C')
1816 type = WTP_CENTER;
1817 else
1818 type = WTP_TILE;
1820 /* get color */
1821 elem = PLGetArrayElement(pl, 2);
1822 if (!elem || !PLIsString(elem)) {
1823 return NULL;
1825 val = PLGetString(elem);
1827 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1828 wwarning(_("\"%s\" is not a valid color name"), val);
1829 return NULL;
1832 /* file name */
1833 elem = PLGetArrayElement(pl, 1);
1834 if (!elem || !PLIsString(elem))
1835 return NULL;
1836 val = PLGetString(elem);
1838 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1839 } else if (strcasecmp(val, "thgradient")==0
1840 || strcasecmp(val, "tvgradient")==0
1841 || strcasecmp(val, "tdgradient")==0) {
1842 RColor color1, color2;
1843 XColor xcolor;
1844 int opacity;
1845 int style;
1847 if (val[1]=='h' || val[1]=='H')
1848 style = WTEX_THGRADIENT;
1849 else if (val[1]=='v' || val[1]=='V')
1850 style = WTEX_TVGRADIENT;
1851 else
1852 style = WTEX_TDGRADIENT;
1854 if (nelem != 5) {
1855 wwarning(_("bad number of arguments in textured gradient specification"));
1856 return NULL;
1859 /* get from color */
1860 elem = PLGetArrayElement(pl, 3);
1861 if (!elem || !PLIsString(elem))
1862 return NULL;
1863 val = PLGetString(elem);
1865 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1866 wwarning(_("\"%s\" is not a valid color name"), val);
1867 return NULL;
1869 color1.alpha = 255;
1870 color1.red = xcolor.red >> 8;
1871 color1.green = xcolor.green >> 8;
1872 color1.blue = xcolor.blue >> 8;
1874 /* get to color */
1875 elem = PLGetArrayElement(pl, 4);
1876 if (!elem || !PLIsString(elem)) {
1877 return NULL;
1879 val = PLGetString(elem);
1881 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1882 wwarning(_("\"%s\" is not a valid color name"), val);
1883 return NULL;
1885 color2.alpha = 255;
1886 color2.red = xcolor.red >> 8;
1887 color2.green = xcolor.green >> 8;
1888 color2.blue = xcolor.blue >> 8;
1890 /* get opacity */
1891 elem = PLGetArrayElement(pl, 2);
1892 if (!elem || !PLIsString(elem))
1893 opacity = 128;
1894 else
1895 val = PLGetString(elem);
1897 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1898 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1899 opacity = 128;
1902 /* get file name */
1903 elem = PLGetArrayElement(pl, 1);
1904 if (!elem || !PLIsString(elem))
1905 return NULL;
1906 val = PLGetString(elem);
1908 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1909 val, opacity);
1911 #ifdef TEXTURE_PLUGIN
1912 else if (strcasecmp(val, "function")==0) {
1913 WTexFunction *function;
1914 void (*initFunc) (Display *, Colormap);
1915 char *lib, *func, **argv;
1916 int i, argc;
1918 if (nelem < 3)
1919 return NULL;
1921 /* get the library name */
1922 elem = PLGetArrayElement(pl, 1);
1923 if (!elem || !PLIsString(elem)) {
1924 return NULL;
1926 lib = PLGetString(elem);
1928 /* get the function name */
1929 elem = PLGetArrayElement(pl, 2);
1930 if (!elem || !PLIsString(elem)) {
1931 return NULL;
1933 func = PLGetString(elem);
1935 argc = nelem - 2;
1936 argv = (char **)wmalloc(argc * sizeof(char *));
1938 /* get the parameters */
1939 argv[0] = wstrdup(func);
1940 for (i = 0; i < argc - 1; i++) {
1941 elem = PLGetArrayElement(pl, 3 + i);
1942 if (!elem || !PLIsString(elem)) {
1943 free(argv);
1945 return NULL;
1947 argv[i+1] = wstrdup(PLGetString(elem));
1950 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1952 #ifdef HAVE_DLFCN_H
1953 if (function) {
1954 initFunc = dlsym(function->handle, "initWindowMaker");
1955 if (initFunc) {
1956 initFunc(dpy, scr->w_colormap);
1957 } else {
1958 wwarning(_("could not initialize library %s"), lib);
1960 } else {
1961 wwarning(_("could not find function %s::%s"), lib, func);
1963 #endif /* HAVE_DLFCN_H */
1964 texture = (WTexture*)function;
1966 #endif /* TEXTURE_PLUGIN */
1967 else {
1968 wwarning(_("invalid texture type %s"), val);
1969 return NULL;
1971 return texture;
1976 static int
1977 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1978 void **ret)
1980 static WTexture *texture;
1981 int changed=0;
1983 again:
1984 if (!PLIsArray(value)) {
1985 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1986 entry->key, "Texture");
1987 if (changed==0) {
1988 value = entry->plvalue;
1989 changed = 1;
1990 wwarning(_("using default \"%s\" instead"), entry->default_value);
1991 goto again;
1993 return False;
1996 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
1997 proplist_t pl;
1999 pl = PLGetArrayElement(value, 0);
2000 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2001 || strcasecmp(PLGetString(pl), "solid")!=0) {
2002 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2003 entry->key, "Solid Texture");
2005 value = entry->plvalue;
2006 changed = 1;
2007 wwarning(_("using default \"%s\" instead"), entry->default_value);
2008 goto again;
2012 texture = parse_texture(scr, value);
2014 if (!texture) {
2015 wwarning(_("Error in texture specification for key \"%s\""),
2016 entry->key);
2017 if (changed==0) {
2018 value = entry->plvalue;
2019 changed = 1;
2020 wwarning(_("using default \"%s\" instead"), entry->default_value);
2021 goto again;
2023 return False;
2026 if (ret)
2027 *ret = &texture;
2029 if (addr)
2030 *(WTexture**)addr = texture;
2032 return True;
2037 static int
2038 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2039 void *addr, void **ret)
2041 proplist_t elem;
2042 int changed = 0;
2043 char *val;
2044 int nelem;
2046 again:
2047 if (!PLIsArray(value)) {
2048 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2049 "WorkspaceBack", "Texture or None");
2050 if (changed==0) {
2051 value = entry->plvalue;
2052 changed = 1;
2053 wwarning(_("using default \"%s\" instead"), entry->default_value);
2054 goto again;
2056 return False;
2059 /* only do basic error checking and verify for None texture */
2061 nelem = PLGetNumberOfElements(value);
2062 if (nelem > 0) {
2063 elem = PLGetArrayElement(value, 0);
2064 if (!elem || !PLIsString(elem)) {
2065 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2066 if (changed==0) {
2067 value = entry->plvalue;
2068 changed = 1;
2069 wwarning(_("using default \"%s\" instead"), entry->default_value);
2070 goto again;
2072 return False;
2074 val = PLGetString(elem);
2076 if (strcasecmp(val, "None")==0)
2077 return True;
2079 *ret = PLRetain(value);
2081 return True;
2085 static int
2086 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2087 void *addr, void **ret)
2089 proplist_t elem;
2090 int nelem;
2091 int changed = 0;
2093 again:
2094 if (!PLIsArray(value)) {
2095 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2096 "WorkspaceSpecificBack", "an array of textures");
2097 if (changed==0) {
2098 value = entry->plvalue;
2099 changed = 1;
2100 wwarning(_("using default \"%s\" instead"), entry->default_value);
2101 goto again;
2103 return False;
2106 /* only do basic error checking and verify for None texture */
2108 nelem = PLGetNumberOfElements(value);
2109 if (nelem > 0) {
2110 while (nelem--) {
2111 elem = PLGetArrayElement(value, nelem);
2112 if (!elem || !PLIsArray(elem)) {
2113 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2114 nelem);
2119 *ret = PLRetain(value);
2121 #ifdef notworking
2123 * Kluge to force wmsetbg helper to set the default background.
2124 * If the WorkspaceSpecificBack is changed once wmaker has started,
2125 * the WorkspaceBack won't be sent to the helper, unless the user
2126 * changes it's value too. So, we must force this by removing the
2127 * value from the defaults DB.
2129 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2130 proplist_t key = PLMakeString("WorkspaceBack");
2132 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2134 PLRelease(key);
2136 #endif
2137 return True;
2141 static int
2142 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2143 void **ret)
2145 static WFont *font;
2146 char *val;
2148 STRINGP("Font");
2150 val = PLGetString(value);
2152 font = wLoadFont(val);
2153 if (!font) {
2154 wfatal(_("could not load any usable font!!!"));
2155 exit(1);
2158 if (ret)
2159 *ret = font;
2161 /* can't assign font value outside update function */
2162 wassertrv(addr == NULL, True);
2164 return True;
2168 static int
2169 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2170 void **ret)
2172 static unsigned long pixel;
2173 XColor color;
2174 char *val;
2175 int second_pass=0;
2177 STRINGP("Color");
2179 val = PLGetString(value);
2181 again:
2182 if (!wGetColor(scr, val, &color)) {
2183 wwarning(_("could not get color for key \"%s\""),
2184 entry->key);
2185 if (second_pass==0) {
2186 val = PLGetString(entry->plvalue);
2187 second_pass = 1;
2188 wwarning(_("using default \"%s\" instead"), val);
2189 goto again;
2191 return False;
2194 pixel = color.pixel;
2196 if (ret)
2197 *ret = &pixel;
2199 if (addr)
2200 *(unsigned long*)addr = pixel;
2202 return True;
2207 static int
2208 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2209 void **ret)
2211 static WShortKey shortcut;
2212 KeySym ksym;
2213 char *val;
2214 char *k;
2215 char buf[128], *b;
2218 STRINGP("Key spec");
2220 val = PLGetString(value);
2222 if (!val || strcasecmp(val, "NONE")==0) {
2223 shortcut.keycode = 0;
2224 shortcut.modifier = 0;
2225 if (ret)
2226 *ret = &shortcut;
2227 return True;
2230 strcpy(buf, val);
2232 b = (char*)buf;
2234 /* get modifiers */
2235 shortcut.modifier = 0;
2236 while ((k = strchr(b, '+'))!=NULL) {
2237 int mod;
2239 *k = 0;
2240 mod = wXModifierFromKey(b);
2241 if (mod<0) {
2242 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2243 return False;
2245 shortcut.modifier |= mod;
2247 b = k+1;
2250 /* get key */
2251 ksym = XStringToKeysym(b);
2253 if (ksym==NoSymbol) {
2254 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2255 val);
2256 return False;
2259 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2260 if (shortcut.keycode==0) {
2261 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2262 return False;
2265 if (ret)
2266 *ret = &shortcut;
2268 return True;
2272 static int
2273 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2274 void **ret)
2276 unsigned int mask;
2277 char *str;
2279 STRINGP("Modifier Key");
2281 str = PLGetString(value);
2282 if (!str)
2283 return False;
2285 mask = wXModifierFromKey(str);
2286 if (mask < 0) {
2287 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2288 mask = 0;
2289 return False;
2292 if (addr)
2293 *(unsigned int*)addr = mask;
2295 if (ret)
2296 *ret = &mask;
2298 return True;
2302 #ifdef NEWSTUFF
2303 static int
2304 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2305 void *addr, void **ret)
2307 unsigned int mask;
2308 char *str;
2309 RImage *image;
2310 int i, n;
2311 int w, h;
2313 STRINGP("Image File Path");
2315 str = PLGetString(value);
2316 if (!str)
2317 return False;
2319 image = RLoadImage(scr->rcontext, str, 0);
2320 if (!image) {
2321 wwarning(_("could not load image in option %s: %s"), entry->key,
2322 RMessageForError(RErrorCode));
2323 return False;
2326 if (*(RImage**)addr) {
2327 RDestroyImage(*(RImage**)addr);
2329 if (addr)
2330 *(RImage**)addr = image;
2332 assert(ret == NULL);
2334 if (ret)
2335 *(RImage**)ret = image;
2338 return True;
2340 #endif
2343 /* ---------------- value setting functions --------------- */
2344 static int
2345 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2347 return REFRESH_FORE_COLOR;
2351 static int
2352 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2354 switch (which) {
2355 case WM_DOCK:
2356 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2357 break;
2358 case WM_CLIP:
2359 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2360 break;
2361 default:
2362 break;
2364 return 0;
2368 static int
2369 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2371 if (scr->workspaces) {
2372 wWorkspaceForceChange(scr, scr->current_workspace);
2373 wArrangeIcons(scr, False);
2375 return 0;
2378 #if not_used
2379 static int
2380 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2382 if (*value <= 0)
2383 *(int*)foo = 1;
2385 return 0;
2387 #endif
2391 static int
2392 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2394 Pixmap pixmap;
2395 RImage *img;
2396 int reset = 0;
2398 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2399 wPreferences.icon_size,
2400 ((*texture)->any.type & WREL_BORDER_MASK)
2401 ? WREL_ICON : WREL_FLAT);
2402 if (!img) {
2403 wwarning(_("could not render texture for icon background"));
2404 if (!entry->addr)
2405 wTextureDestroy(scr, *texture);
2406 return 0;
2408 RConvertImage(scr->rcontext, img, &pixmap);
2410 if (scr->icon_tile) {
2411 reset = 1;
2412 RDestroyImage(scr->icon_tile);
2413 XFreePixmap(dpy, scr->icon_tile_pixmap);
2416 scr->icon_tile = img;
2418 if (!wPreferences.flags.noclip) {
2419 if (scr->clip_tile) {
2420 RDestroyImage(scr->clip_tile);
2422 scr->clip_tile = wClipMakeTile(scr, img);
2425 scr->icon_tile_pixmap = pixmap;
2427 if (scr->def_icon_pixmap) {
2428 XFreePixmap(dpy, scr->def_icon_pixmap);
2429 scr->def_icon_pixmap = None;
2431 if (scr->def_ticon_pixmap) {
2432 XFreePixmap(dpy, scr->def_ticon_pixmap);
2433 scr->def_ticon_pixmap = None;
2436 if (scr->icon_back_texture) {
2437 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2439 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2441 if (scr->clip_balloon)
2442 XSetWindowBackground(dpy, scr->clip_balloon,
2443 (*texture)->any.color.pixel);
2446 * Free the texture as nobody else will use it, nor refer to it.
2448 if (!entry->addr)
2449 wTextureDestroy(scr, *texture);
2451 return (reset ? REFRESH_ICON_TILE : 0);
2456 static int
2457 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2459 if (scr->title_font) {
2460 wFreeFont(scr->title_font);
2463 scr->title_font = font;
2465 #ifndef I18N_MB
2466 XSetFont(dpy, scr->window_title_gc, font->font->fid);
2467 #endif
2469 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2473 static int
2474 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2476 if (scr->menu_title_font) {
2477 wFreeFont(scr->menu_title_font);
2480 scr->menu_title_font = font;
2482 #ifndef I18N_MB
2483 XSetFont(dpy, scr->menu_title_gc, font->font->fid);
2484 #endif
2486 return REFRESH_MENU_TITLE_FONT;
2490 static int
2491 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2493 if (scr->menu_entry_font) {
2494 wFreeFont(scr->menu_entry_font);
2497 scr->menu_entry_font = font;
2499 #ifndef I18N_MB
2500 XSetFont(dpy, scr->menu_entry_gc, font->font->fid);
2501 XSetFont(dpy, scr->disabled_menu_entry_gc, font->font->fid);
2502 XSetFont(dpy, scr->select_menu_gc, font->font->fid);
2503 #endif
2505 return REFRESH_MENU_FONT;
2510 static int
2511 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2513 if (scr->icon_title_font) {
2514 wFreeFont(scr->icon_title_font);
2517 scr->icon_title_font = font;
2519 #ifndef I18N_MB
2520 XSetFont(dpy, scr->icon_title_gc, font->font->fid);
2521 #endif
2523 return REFRESH_ICON_FONT;
2527 static int
2528 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2530 if (scr->clip_title_font) {
2531 wFreeFont(scr->clip_title_font);
2534 scr->clip_title_font = font;
2536 #ifndef I18N_MB
2537 XSetFont(dpy, scr->clip_title_gc, font->font->fid);
2538 #endif
2540 return REFRESH_ICON_FONT;
2544 static int
2545 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2547 if (scr->info_text_font) {
2548 wFreeFont(scr->info_text_font);
2551 scr->info_text_font = font;
2553 #ifndef I18N_MB
2554 XSetFont(dpy, scr->info_text_gc, font->font->fid);
2555 XSetFont(dpy, scr->line_gc, font->font->fid);
2556 #endif
2558 /* This test works because the scr structure is initially zeroed out
2559 and None = 0. Any other time, the window should be valid. */
2560 if (scr->geometry_display != None) {
2561 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2562 &scr->geometry_display_height);
2563 XResizeWindow(dpy, scr->geometry_display,
2564 scr->geometry_display_width, scr->geometry_display_height);
2567 return 0;
2571 static int
2572 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2574 if (scr->select_pixel!=scr->white_pixel &&
2575 scr->select_pixel!=scr->black_pixel) {
2576 wFreeColor(scr, scr->select_pixel);
2579 scr->select_pixel = color->pixel;
2581 return REFRESH_FORE_COLOR;
2585 static int
2586 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2588 if (scr->select_text_pixel!=scr->white_pixel &&
2589 scr->select_text_pixel!=scr->black_pixel) {
2590 wFreeColor(scr, scr->select_text_pixel);
2593 scr->select_text_pixel = color->pixel;
2595 return REFRESH_FORE_COLOR;
2599 static int
2600 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2602 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2603 scr->clip_title_pixel[index]!=scr->black_pixel) {
2604 wFreeColor(scr, scr->clip_title_pixel[index]);
2607 scr->clip_title_pixel[index] = color->pixel;
2609 return REFRESH_FORE_COLOR;
2613 static int
2614 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2616 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2617 scr->window_title_pixel[index]!=scr->black_pixel) {
2618 wFreeColor(scr, scr->window_title_pixel[index]);
2621 scr->window_title_pixel[index] = color->pixel;
2623 if (index == WS_UNFOCUSED)
2624 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2626 return REFRESH_FORE_COLOR;
2630 static int
2631 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2633 #ifdef TITLE_TEXT_SHADOW
2634 if (index == WS_SMENU){
2635 if (scr->menu_title_pixel[WS_SMENU]!=scr->white_pixel &&
2636 scr->menu_title_pixel[WS_SMENU]!=scr->black_pixel) {
2637 wFreeColor(scr, scr->menu_title_pixel[WS_SMENU]);
2639 scr->menu_title_pixel[WS_SMENU] = color->pixel;
2641 else {
2642 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2643 scr->menu_title_pixel[0]!=scr->black_pixel) {
2644 wFreeColor(scr, scr->menu_title_pixel[0]);
2646 scr->menu_title_pixel[0] = color->pixel;
2648 #else /* !TITLE_TEXT_SHADOW */
2649 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2650 scr->menu_title_pixel[0]!=scr->black_pixel) {
2651 wFreeColor(scr, scr->menu_title_pixel[0]);
2654 scr->menu_title_pixel[0] = color->pixel;
2655 #endif /* !TITLE_TEXT_SHADOW */
2656 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2658 return REFRESH_FORE_COLOR;
2662 static int
2663 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2665 XGCValues gcv;
2666 #define gcm (GCForeground|GCBackground|GCFillStyle)
2668 if (scr->mtext_pixel!=scr->white_pixel &&
2669 scr->mtext_pixel!=scr->black_pixel) {
2670 wFreeColor(scr, scr->mtext_pixel);
2673 scr->mtext_pixel = color->pixel;
2675 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2678 if (scr->dtext_pixel == scr->mtext_pixel) {
2679 gcv.foreground = scr->white_pixel;
2680 gcv.background = scr->black_pixel;
2681 gcv.fill_style = FillStippled;
2682 } else {
2683 gcv.foreground = scr->dtext_pixel;
2684 gcv.fill_style = FillSolid;
2686 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2688 return REFRESH_FORE_COLOR;
2689 #undef gcm
2693 static int
2694 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2696 XGCValues gcv;
2697 #define gcm (GCForeground|GCBackground|GCFillStyle)
2699 if (scr->dtext_pixel!=scr->white_pixel &&
2700 scr->dtext_pixel!=scr->black_pixel) {
2701 wFreeColor(scr, scr->dtext_pixel);
2704 scr->dtext_pixel = color->pixel;
2706 if (scr->dtext_pixel == scr->mtext_pixel) {
2707 gcv.foreground = scr->white_pixel;
2708 gcv.background = scr->black_pixel;
2709 gcv.fill_style = FillStippled;
2710 } else {
2711 gcv.foreground = scr->dtext_pixel;
2712 gcv.fill_style = FillSolid;
2714 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2716 return REFRESH_FORE_COLOR;
2717 #undef gcm
2720 static int
2721 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2723 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2725 return REFRESH_FORE_COLOR;
2728 static int
2729 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2731 if (scr->icon_title_texture) {
2732 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2734 XQueryColor (dpy, scr->w_colormap, color);
2735 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2737 return REFRESH_WINDOW_TEXTURES;
2741 static void
2742 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2744 close(scr->helper_fd);
2745 scr->helper_fd = 0;
2746 scr->helper_pid = 0;
2747 scr->flags.backimage_helper_launched = 0;
2751 static int
2752 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2753 void *bar)
2755 int i;
2756 proplist_t val;
2757 char *str;
2759 if (scr->flags.backimage_helper_launched) {
2760 if (PLGetNumberOfElements(value)==0) {
2761 SendHelperMessage(scr, 'C', 0, NULL);
2762 SendHelperMessage(scr, 'K', 0, NULL);
2764 PLRelease(value);
2765 return 0;
2767 } else {
2768 pid_t pid;
2769 int filedes[2];
2771 if (PLGetNumberOfElements(value) == 0)
2772 return 0;
2774 if (pipe(filedes) < 0) {
2775 wsyserror("pipe() failed:can't set workspace specific background image");
2777 PLRelease(value);
2778 return 0;
2781 pid = fork();
2782 if (pid < 0) {
2783 wsyserror("fork() failed:can't set workspace specific background image");
2784 if (close(filedes[0]) < 0)
2785 wsyserror("could not close pipe");
2786 if (close(filedes[1]) < 0)
2787 wsyserror("could not close pipe");
2789 } else if (pid == 0) {
2790 SetupEnvironment(scr);
2792 if (close(0) < 0)
2793 wsyserror("could not close pipe");
2794 if (dup(filedes[0]) < 0) {
2795 wsyserror("dup() failed:can't set workspace specific background image");
2797 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2798 wsyserror("could not execute wmsetbg");
2799 exit(1);
2800 } else {
2802 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2803 wsyserror("error setting close-on-exec flag");
2805 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2806 wsyserror("error setting close-on-exec flag");
2809 scr->helper_fd = filedes[1];
2810 scr->helper_pid = pid;
2811 scr->flags.backimage_helper_launched = 1;
2813 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2815 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2819 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2820 val = PLGetArrayElement(value, i);
2821 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2822 str = PLGetDescription(val);
2824 SendHelperMessage(scr, 'S', i+1, str);
2826 free(str);
2827 } else {
2828 SendHelperMessage(scr, 'U', i+1, NULL);
2831 sleep(1);
2833 PLRelease(value);
2834 return 0;
2838 static int
2839 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2840 void *bar)
2842 if (scr->flags.backimage_helper_launched) {
2843 char *str;
2845 if (PLGetNumberOfElements(value)==0) {
2846 SendHelperMessage(scr, 'U', 0, NULL);
2847 } else {
2848 /* set the default workspace background to this one */
2849 str = PLGetDescription(value);
2850 if (str) {
2851 SendHelperMessage(scr, 'S', 0, str);
2852 free(str);
2853 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2854 } else {
2855 SendHelperMessage(scr, 'U', 0, NULL);
2858 } else {
2859 char *command;
2860 char *text;
2862 SetupEnvironment(scr);
2863 text = PLGetDescription(value);
2864 command = wmalloc(strlen(text)+40);
2865 sprintf(command, "wmsetbg -d -p '%s' &", text);
2866 free(text);
2867 system(command);
2868 free(command);
2870 PLRelease(value);
2872 return 0;
2876 static int
2877 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2879 if (scr->widget_texture) {
2880 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2882 scr->widget_texture = *(WTexSolid**)texture;
2884 return 0;
2888 static int
2889 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2891 if (scr->window_title_texture[WS_FOCUSED]) {
2892 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2894 scr->window_title_texture[WS_FOCUSED] = *texture;
2896 return REFRESH_WINDOW_TEXTURES;
2900 static int
2901 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2903 if (scr->window_title_texture[WS_PFOCUSED]) {
2904 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2906 scr->window_title_texture[WS_PFOCUSED] = *texture;
2908 return REFRESH_WINDOW_TEXTURES;
2912 static int
2913 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2915 if (scr->window_title_texture[WS_UNFOCUSED]) {
2916 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2918 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2920 if (scr->resizebar_texture[0]) {
2921 wTextureDestroy(scr, (WTexture*)scr->resizebar_texture[0]);
2923 scr->resizebar_texture[0]
2924 = wTextureMakeSolid(scr, &scr->window_title_texture[WS_UNFOCUSED]->any.color);
2926 if (scr->geometry_display != None)
2927 XSetWindowBackground(dpy, scr->geometry_display,
2928 scr->resizebar_texture[0]->normal.pixel);
2930 return REFRESH_WINDOW_TEXTURES;
2934 static int
2935 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2937 if (scr->menu_title_texture[0]) {
2938 wTextureDestroy(scr, scr->menu_title_texture[0]);
2940 scr->menu_title_texture[0] = *texture;
2942 return REFRESH_MENU_TEXTURES;
2946 static int
2947 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2949 if (scr->menu_item_texture) {
2950 wTextureDestroy(scr, scr->menu_item_texture);
2951 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2953 scr->menu_item_texture = *texture;
2955 scr->menu_item_auxtexture
2956 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2958 return REFRESH_MENU_TEXTURES;
2962 static int
2963 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
2965 WWindow *wwin;
2966 wKeyBindings[index] = *shortcut;
2968 wwin = scr->focused_window;
2970 while (wwin!=NULL) {
2971 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2973 if (!WFLAGP(wwin, no_bind_keys)) {
2974 wWindowSetKeyGrabs(wwin);
2976 wwin = wwin->prev;
2979 return 0;
2983 static int
2984 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2986 wArrangeIcons(scr, True);
2988 return 0;
2992 static int
2993 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2995 wScreenUpdateUsableArea(scr);
2997 return 0;
3002 static int
3003 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3005 return REFRESH_BUTTON_IMAGES;
3010 * Very ugly kluge.
3011 * Need access to the double click variables, so that all widgets in
3012 * wmaker panels will have the same dbl-click values.
3013 * TODO: figure a better way of dealing with it.
3015 #include "WINGsP.h"
3017 static int
3018 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3020 extern _WINGsConfiguration WINGsConfiguration;
3022 if (*value <= 0)
3023 *(int*)foo = 1;
3025 WINGsConfiguration.doubleClickDelay = *value;
3027 return 0;