style file updates, gradiented clip arrows
[wmaker-crm.git] / src / defaults.c
blob9e3068a21542504f5dc59813b237177ec7735bc0
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;
115 /* type converters */
116 static int getBool();
117 static int getInt();
118 static int getCoord();
119 #if 0
120 /* this is not used yet */
121 static int getString();
122 #endif
123 static int getPathList();
124 static int getEnum();
125 static int getTexture();
126 static int getWSBackground();
127 static int getWSSpecificBackground();
128 static int getFont();
129 static int getColor();
130 static int getKeybind();
131 static int getModMask();
132 #ifdef NEWSTUFF
133 static int getRImage();
134 #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 setResizebarBack();
158 static int setWorkspaceBack();
159 static int setWorkspaceSpecificBack();
160 static int setMenuTitleColor();
161 static int setMenuTextColor();
162 static int setMenuDisabledColor();
163 static int setMenuTitleBack();
164 static int setMenuTextBack();
165 static int setHightlight();
166 static int setHightlightText();
167 static int setKeyGrab();
168 static int setDoubleClick();
169 static int setIconPosition();
171 static int setClipTitleFont();
172 static int setClipTitleColor();
174 static int setMenuStyle();
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
194 #define REFRESH_WINDOW_TEXTURES (1<<0)
195 #define REFRESH_MENU_TEXTURE (1<<1)
196 #define REFRESH_MENU_FONT (1<<2)
197 #define REFRESH_MENU_COLOR (1<<3)
198 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
199 #define REFRESH_MENU_TITLE_FONT (1<<5)
200 #define REFRESH_MENU_TITLE_COLOR (1<<6)
201 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
202 #define REFRESH_WINDOW_FONT (1<<8)
203 #define REFRESH_ICON_TILE (1<<9)
204 #define REFRESH_ICON_FONT (1<<10)
205 #define REFRESH_WORKSPACE_BACK (1<<11)
207 #define REFRESH_BUTTON_IMAGES (1<<12)
209 #define REFRESH_ICON_TITLE_COLOR (1<<13)
210 #define REFRESH_ICON_TITLE_BACK (1<<14)
214 static WOptionEnumeration seFocusModes[] = {
215 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
216 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
217 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
218 {NULL, 0, 0}
221 static WOptionEnumeration seColormapModes[] = {
222 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
223 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
224 {NULL, 0, 0}
227 static WOptionEnumeration sePlacements[] = {
228 {"Auto", WPM_SMART, 0}, {"Smart", WPM_SMART, 1},
229 {"Cascade", WPM_CASCADE, 0},
230 {"Random", WPM_RANDOM, 0},
231 {"Manual", WPM_MANUAL, 0},
232 {NULL, 0, 0}
235 static WOptionEnumeration seGeomDisplays[] = {
236 {"Center", WDIS_CENTER, 0},
237 {"Corner", WDIS_TOPLEFT, 0},
238 {"Floating", WDIS_FRAME_CENTER, 0},
239 {"Line", WDIS_NEW, 0},
240 {NULL, 0, 0}
243 static WOptionEnumeration seSpeeds[] = {
244 {"UltraFast", SPEED_ULTRAFAST, 0},
245 {"Fast", SPEED_FAST, 0},
246 {"Medium", SPEED_MEDIUM, 0},
247 {"Slow", SPEED_SLOW, 0},
248 {"UltraSlow", SPEED_ULTRASLOW, 0},
249 {NULL, 0, 0}
252 static WOptionEnumeration seMouseButtons[] = {
253 {"Left", Button1, 0}, {"Button1", Button1, 1},
254 {"Middle", Button2, 0}, {"Button2", Button2, 1},
255 {"Right", Button3, 0}, {"Button3", Button3, 1},
256 {"Button4", Button4, 0},
257 {"Button5", Button5, 0},
258 {NULL, 0, 0}
261 static WOptionEnumeration seIconificationStyles[] = {
262 {"Zoom", WIS_ZOOM, 0},
263 {"Twist", WIS_TWIST, 0},
264 {"Flip", WIS_FLIP, 0},
265 {"None", WIS_NONE, 0},
266 {"random", WIS_RANDOM, 0},
267 {NULL, 0, 0}
270 static WOptionEnumeration seJustifications[] = {
271 {"Left", WTJ_LEFT, 0},
272 {"Center", WTJ_CENTER, 0},
273 {"Right", WTJ_RIGHT, 0},
274 {NULL, 0, 0}
277 static WOptionEnumeration seIconPositions[] = {
278 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
279 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
280 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
281 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
282 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
283 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
284 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
285 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
286 {NULL, 0, 0}
289 static WOptionEnumeration seMenuStyles[] = {
290 {"normal", MS_NORMAL, 0},
291 {"singletexture", MS_SINGLE_TEXTURE, 0},
292 {"flat", MS_FLAT, 0},
293 {NULL, 0, 0}
298 * ALL entries in the tables bellow, NEED to have a default value
299 * defined, and this value needs to be correct.
302 /* these options will only affect the window manager on startup
304 * static defaults can't access the screen data, because it is
305 * created after these defaults are read
307 WDefaultEntry staticOptionList[] = {
309 {"DisableDithering", "NO", NULL,
310 &wPreferences.no_dithering, getBool, NULL
312 {"ColormapSize", "4", NULL,
313 &wPreferences.cmap_size, getInt, NULL
315 /* static by laziness */
316 {"IconSize", "64", NULL,
317 &wPreferences.icon_size, getInt, NULL
319 {"ModifierKey", "Mod1", NULL,
320 &wPreferences.modifier_mask, getModMask, NULL
322 {"DisableWSMouseActions", "NO", NULL,
323 &wPreferences.disable_root_mouse, getBool, NULL
325 {"FocusMode", "manual", seFocusModes,
326 &wPreferences.focus_mode, getEnum, NULL
327 }, /* have a problem when switching from manual to sloppy without restart */
328 {"NewStyle", "NO", NULL,
329 &wPreferences.new_style, getBool, NULL
331 {"DisableDock", "NO", (void*) WM_DOCK,
332 NULL, getBool, setIfDockPresent
334 {"DisableClip", "NO", (void*) WM_CLIP,
335 NULL, getBool, setIfDockPresent
337 {"DisableMiniwindows", "NO", NULL,
338 &wPreferences.disable_miniwindows, getBool, NULL
344 WDefaultEntry optionList[] = {
345 /* dynamic options */
346 {"IconPosition", "blh", seIconPositions,
347 &wPreferences.icon_yard, getEnum, setIconPosition
349 {"IconificationStyle", "Zoom", seIconificationStyles,
350 &wPreferences.iconification_style, getEnum, NULL
352 {"SelectWindowsMouseButton", "Left", seMouseButtons,
353 &wPreferences.select_button, getEnum, NULL
355 {"WindowListMouseButton", "Middle", seMouseButtons,
356 &wPreferences.windowl_button, getEnum, NULL
358 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
359 &wPreferences.menu_button, getEnum, NULL
361 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
362 &wPreferences.pixmap_path, getPathList, NULL
364 {"IconPath", DEF_ICON_PATHS, NULL,
365 &wPreferences.icon_path, getPathList, NULL
367 {"ColormapMode", "auto", seColormapModes,
368 &wPreferences.colormap_mode, getEnum, NULL
370 {"AutoFocus", "NO", NULL,
371 &wPreferences.auto_focus, getBool, NULL
373 {"RaiseDelay", "0", NULL,
374 &wPreferences.raise_delay, getInt, NULL
376 {"CirculateRaise", "NO", NULL,
377 &wPreferences.circ_raise, getBool, NULL
379 {"Superfluous", "NO", NULL,
380 &wPreferences.superfluous, getBool, NULL
382 {"AdvanceToNewWorkspace", "NO", NULL,
383 &wPreferences.ws_advance, getBool, NULL
385 {"CycleWorkspaces", "NO", NULL,
386 &wPreferences.ws_cycle, getBool, NULL
388 {"StickyIcons", "NO", NULL,
389 &wPreferences.sticky_icons, getBool, setStickyIcons
391 {"SaveSessionOnExit", "NO", NULL,
392 &wPreferences.save_session_on_exit, getBool, NULL
394 {"WrapMenus", "NO", NULL,
395 &wPreferences.wrap_menus, getBool, NULL
397 {"ScrollableMenus", "NO", NULL,
398 &wPreferences.scrollable_menus, getBool, NULL
400 {"MenuScrollSpeed", "medium", seSpeeds,
401 &wPreferences.menu_scroll_speed, getEnum, NULL
403 {"IconSlideSpeed", "medium", seSpeeds,
404 &wPreferences.icon_slide_speed, getEnum, NULL
406 {"ShadeSpeed", "medium", seSpeeds,
407 &wPreferences.shade_speed, getEnum, NULL
409 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
410 &wPreferences.dblclick_time, getInt, setDoubleClick,
412 {"AlignSubmenus", "NO", NULL,
413 &wPreferences.align_menus, getBool, NULL
415 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
416 &wPreferences.open_transients_with_parent, getBool, NULL
418 {"WindowPlacement", "auto", sePlacements,
419 &wPreferences.window_placement, getEnum, NULL
421 {"IgnoreFocusClick","NO", NULL,
422 &wPreferences.ignore_focus_click, getBool, NULL
424 {"UseSaveUnders", "NO", NULL,
425 &wPreferences.use_saveunders, getBool, NULL
427 {"OpaqueMove", "NO", NULL,
428 &wPreferences.opaque_move, getBool, NULL
430 {"DisableSound", "NO", NULL,
431 &wPreferences.no_sound, getBool, NULL
433 {"DisableAnimations", "NO", NULL,
434 &wPreferences.no_animations, getBool, NULL
436 {"DontLinkWorkspaces","NO", NULL,
437 &wPreferences.no_autowrap, getBool, NULL
439 {"AutoArrangeIcons", "NO", NULL,
440 &wPreferences.auto_arrange_icons, getBool, NULL
442 {"NoWindowOverDock", "NO", NULL,
443 &wPreferences.no_window_over_dock, getBool, updateUsableArea
445 {"NoWindowOverIcons", "NO", NULL,
446 &wPreferences.no_window_over_icons, getBool, updateUsableArea
448 {"WindowPlaceOrigin", "(0, 0)", NULL,
449 &wPreferences.window_place_origin, getCoord, NULL
451 {"ResizeDisplay", "corner", seGeomDisplays,
452 &wPreferences.size_display, getEnum, NULL
454 {"MoveDisplay", "corner", seGeomDisplays,
455 &wPreferences.move_display, getEnum, NULL
457 {"DontConfirmKill", "NO", NULL,
458 &wPreferences.dont_confirm_kill, getBool,NULL
460 {"WindowTitleBalloons", "NO", NULL,
461 &wPreferences.window_balloon, getBool, NULL
463 {"MiniwindowTitleBalloons", "NO", NULL,
464 &wPreferences.miniwin_balloon,getBool, NULL
466 {"AppIconBalloons", "NO", NULL,
467 &wPreferences.appicon_balloon,getBool, NULL
469 {"EdgeResistance", "30", NULL,
470 &wPreferences.edge_resistance,getInt, NULL
472 {"DisableBlinking", "NO", NULL,
473 &wPreferences.dont_blink, getBool, NULL
475 #ifdef WEENDOZE_CYCLE
476 {"WindozeCycling","NO", NULL,
477 &wPreferences.windoze_cycling, getBool, NULL
479 {"PopupSwitchMenu","YES", NULL,
480 &wPreferences.popup_switchmenu, getBool, NULL
482 #endif /* WEENDOZE_CYCLE */
483 /* style options */
484 {"MenuStyle", "normal", seMenuStyles,
485 &wPreferences.menu_style, getEnum, setMenuStyle
487 {"WidgetColor", "(solid, gray)", NULL,
488 NULL, getTexture, setWidgetColor,
490 {"WorkspaceSpecificBack","()", NULL,
491 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
493 /* WorkspaceBack must come after WorkspaceSpecificBack or
494 * WorkspaceBack wont know WorkspaceSpecificBack was also
495 * specified and 2 copies of wmsetbg will be launched */
496 {"WorkspaceBack", "(solid, black)", NULL,
497 NULL, getWSBackground,setWorkspaceBack
499 {"IconBack", "(solid, gray)", NULL,
500 NULL, getTexture, setIconTile
502 {"TitleJustify", "center", seJustifications,
503 &wPreferences.title_justification, getEnum, setJustify
505 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
506 NULL, getFont, setWinTitleFont,
508 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
509 NULL, getFont, setMenuTitleFont
511 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
512 NULL, getFont, setMenuTextFont
514 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
515 NULL, getFont, setIconTitleFont
517 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
518 NULL, getFont, setClipTitleFont
520 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
521 NULL, getFont, setDisplayFont
523 {"HighlightColor", "white", NULL,
524 NULL, getColor, setHightlight
526 {"HighlightTextColor", "black", NULL,
527 NULL, getColor, setHightlightText
529 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
530 NULL, getColor, setClipTitleColor
532 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
533 NULL, getColor, setClipTitleColor
535 {"FTitleColor", "white", (void*)WS_FOCUSED,
536 NULL, getColor, setWTitleColor
538 {"PTitleColor", "white", (void*)WS_PFOCUSED,
539 NULL, getColor, setWTitleColor
541 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
542 NULL, getColor, setWTitleColor
544 {"FTitleBack", "(solid, black)", NULL,
545 NULL, getTexture, setFTitleBack
547 {"PTitleBack", "(solid, \"#616161\")", NULL,
548 NULL, getTexture, setPTitleBack
550 {"UTitleBack", "(solid, gray)", NULL,
551 NULL, getTexture, setUTitleBack
553 {"ResizebarBack", "(solid, gray)", NULL,
554 NULL, getTexture, setResizebarBack
556 {"MenuTitleColor", "white", NULL,
557 NULL, getColor, setMenuTitleColor
559 {"MenuTextColor", "black", NULL,
560 NULL, getColor, setMenuTextColor
562 {"MenuDisabledColor", "\"#616161\"", NULL,
563 NULL, getColor, setMenuDisabledColor
565 {"MenuTitleBack", "(solid, black)", NULL,
566 NULL, getTexture, setMenuTitleBack
568 {"MenuTextBack", "(solid, gray)", NULL,
569 NULL, getTexture, setMenuTextBack
571 {"IconTitleColor", "white", NULL,
572 NULL, getColor, setIconTitleColor
574 {"IconTitleBack", "black", NULL,
575 NULL, getColor, setIconTitleBack
577 /* keybindings */
578 #ifndef LITE
579 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
580 NULL, getKeybind, setKeyGrab
582 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
583 NULL, getKeybind, setKeyGrab
585 #endif /* LITE */
586 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
587 NULL, getKeybind, setKeyGrab
589 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
590 NULL, getKeybind, setKeyGrab
592 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
593 NULL, getKeybind, setKeyGrab
595 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
596 NULL, getKeybind, setKeyGrab
598 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
599 NULL, getKeybind, setKeyGrab
601 {"HideKey", "None", (void*)WKBD_HIDE,
602 NULL, getKeybind, setKeyGrab
604 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
605 NULL, getKeybind, setKeyGrab
607 {"CloseKey", "None", (void*)WKBD_CLOSE,
608 NULL, getKeybind, setKeyGrab
610 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
611 NULL, getKeybind, setKeyGrab
613 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
614 NULL, getKeybind, setKeyGrab
616 {"RaiseKey", "Meta+Up", (void*)WKBD_RAISE,
617 NULL, getKeybind, setKeyGrab
619 {"LowerKey", "Meta+Down", (void*)WKBD_LOWER,
620 NULL, getKeybind, setKeyGrab
622 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
623 NULL, getKeybind, setKeyGrab
625 {"ShadeKey", "None", (void*)WKBD_SHADE,
626 NULL, getKeybind, setKeyGrab
628 {"SelectKey", "None", (void*)WKBD_SELECT,
629 NULL, getKeybind, setKeyGrab
631 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
632 NULL, getKeybind, setKeyGrab
634 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
635 NULL, getKeybind, setKeyGrab
637 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
638 NULL, getKeybind, setKeyGrab
640 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
641 NULL, getKeybind, setKeyGrab
643 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
644 NULL, getKeybind, setKeyGrab
646 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
647 NULL, getKeybind, setKeyGrab
649 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
650 NULL, getKeybind, setKeyGrab
652 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
653 NULL, getKeybind, setKeyGrab
655 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
656 NULL, getKeybind, setKeyGrab
658 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
659 NULL, getKeybind, setKeyGrab
661 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
662 NULL, getKeybind, setKeyGrab
664 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
665 NULL, getKeybind, setKeyGrab
667 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
668 NULL, getKeybind, setKeyGrab
670 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
671 NULL, getKeybind, setKeyGrab
673 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
674 NULL, getKeybind, setKeyGrab
676 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
677 NULL, getKeybind, setKeyGrab
679 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
680 NULL, getKeybind, setKeyGrab
682 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
683 NULL, getKeybind, setKeyGrab
685 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
686 NULL, getKeybind, setKeyGrab
688 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
689 NULL, getKeybind, setKeyGrab
691 #ifdef EXTEND_WINDOWSHORTCUT
692 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
693 NULL, getKeybind, setKeyGrab
695 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
696 NULL, getKeybind, setKeyGrab
698 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
699 NULL, getKeybind, setKeyGrab
701 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
702 NULL, getKeybind, setKeyGrab
704 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
705 NULL, getKeybind, setKeyGrab
707 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
708 NULL, getKeybind, setKeyGrab
710 #endif /* EXTEND_WINDOWSHORTCUT */
712 #ifdef KEEP_XKB_LOCK_STATUS
713 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
714 NULL, getKeybind, setKeyGrab
716 {"KbdModeLock", "NO", NULL,
717 &wPreferences.modelock, getBool, NULL
719 #endif /* KEEP_XKB_LOCK_STATUS */
720 #ifdef TITLE_TEXT_SHADOW
721 ,{"FShadowColor", "black", (void*)WS_SFOCUSED,
722 NULL, getColor, setWTitleColor
724 {"PShadowColor", "black", (void*)WS_SPFOCUSED,
725 NULL, getColor, setWTitleColor
727 {"UShadowColor", "grey50", (void*)WS_SUNFOCUSED,
728 NULL, getColor, setWTitleColor
730 {"MShadowColor", "black", (void*)WS_SMENU,
731 NULL, getColor, setMenuTitleColor
733 {"Shadow", "Yes", NULL,
734 &wPreferences.title_shadow, getBool, setJustify
736 #endif /* TITLE_TEXT_SHADOW */
740 #if 0
741 static void rereadDefaults(void);
742 #endif
744 #if 0
745 static void
746 rereadDefaults(void)
748 /* must defer the update because accessing X data from a
749 * signal handler can mess up Xlib */
752 #endif
754 static void
755 initDefaults()
757 int i;
758 WDefaultEntry *entry;
760 PLSetStringCmpHook(StringCompareHook);
762 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
763 entry = &optionList[i];
765 entry->plkey = PLMakeString(entry->key);
766 if (entry->default_value)
767 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
768 else
769 entry->plvalue = NULL;
772 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
773 entry = &staticOptionList[i];
775 entry->plkey = PLMakeString(entry->key);
776 if (entry->default_value)
777 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
778 else
779 entry->plvalue = NULL;
783 wDomainName = PLMakeString(WMDOMAIN_NAME);
784 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
786 PLRegister(wDomainName, rereadDefaults);
787 PLRegister(wAttributeDomainName, rereadDefaults);
794 #if 0
795 proplist_t
796 wDefaultsInit(int screen_number)
798 static int defaults_inited = 0;
799 proplist_t dict;
801 if (!defaults_inited) {
802 initDefaults();
805 dict = PLGetDomain(wDomainName);
806 if (!dict) {
807 wwarning(_("could not read domain \"%s\" from defaults database"),
808 PLGetString(wDomainName));
811 return dict;
813 #endif
816 void
817 wDefaultsDestroyDomain(WDDomain *domain)
819 if (domain->dictionary)
820 PLRelease(domain->dictionary);
821 free(domain->path);
822 free(domain);
826 WDDomain*
827 wDefaultsInitDomain(char *domain, Bool requireDictionary)
829 WDDomain *db;
830 struct stat stbuf;
831 static int inited = 0;
832 char path[PATH_MAX];
833 char *the_path;
834 proplist_t shared_dict=NULL;
836 if (!inited) {
837 inited = 1;
838 initDefaults();
841 db = wmalloc(sizeof(WDDomain));
842 memset(db, 0, sizeof(WDDomain));
843 db->domain_name = domain;
844 db->path = wdefaultspathfordomain(domain);
845 the_path = db->path;
847 if (the_path && stat(the_path, &stbuf)>=0) {
848 db->dictionary = ReadProplistFromFile(the_path);
849 if (db->dictionary) {
850 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
851 PLRelease(db->dictionary);
852 db->dictionary = NULL;
853 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
854 domain, the_path);
856 db->timestamp = stbuf.st_mtime;
857 } else {
858 wwarning(_("could not load domain %s from user defaults database"),
859 domain);
863 /* global system dictionary */
864 sprintf(path, "%s/%s", SYSCONFDIR, domain);
865 if (stat(path, &stbuf)>=0) {
866 shared_dict = ReadProplistFromFile(path);
867 if (shared_dict) {
868 if (requireDictionary && !PLIsDictionary(shared_dict)) {
869 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
870 domain, path);
871 PLRelease(shared_dict);
872 shared_dict = NULL;
873 } else {
874 if (db->dictionary && PLIsDictionary(shared_dict) &&
875 PLIsDictionary(db->dictionary)) {
876 PLMergeDictionaries(shared_dict, db->dictionary);
877 PLRelease(db->dictionary);
878 db->dictionary = shared_dict;
879 if (stbuf.st_mtime > db->timestamp)
880 db->timestamp = stbuf.st_mtime;
881 } else if (!db->dictionary) {
882 db->dictionary = shared_dict;
883 if (stbuf.st_mtime > db->timestamp)
884 db->timestamp = stbuf.st_mtime;
887 } else {
888 wwarning(_("could not load domain %s from global defaults database"),
889 domain);
893 /* set to save it in user's directory, no matter from where it was read */
894 if (db->dictionary) {
895 proplist_t tmp = PLMakeString(db->path);
897 PLSetFilename(db->dictionary, tmp);
898 PLRelease(tmp);
901 return db;
905 void
906 wReadStaticDefaults(proplist_t dict)
908 proplist_t plvalue;
909 WDefaultEntry *entry;
910 int i;
911 void *tdata;
914 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
915 entry = &staticOptionList[i];
917 if (dict)
918 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
919 else
920 plvalue = NULL;
922 if (!plvalue) {
923 /* no default in the DB. Use builtin default */
924 plvalue = entry->plvalue;
927 if (plvalue) {
928 /* convert data */
929 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
930 if (entry->update) {
931 (*entry->update)(NULL, entry, tdata, entry->extra_data);
938 void
939 wDefaultsCheckDomains(void *foo)
941 WScreen *scr;
942 struct stat stbuf;
943 proplist_t dict;
944 int i;
945 char path[PATH_MAX];
947 #ifdef HEARTBEAT
948 puts("Checking domains...");
949 #endif
950 if (stat(WDWindowMaker->path, &stbuf)>=0
951 && WDWindowMaker->timestamp < stbuf.st_mtime) {
952 proplist_t shared_dict = NULL;
953 #ifdef HEARTBEAT
954 puts("Checking WindowMaker domain");
955 #endif
956 WDWindowMaker->timestamp = stbuf.st_mtime;
958 /* global dictionary */
959 sprintf(path, "%s/WindowMaker", SYSCONFDIR);
960 if (stat(path, &stbuf)>=0) {
961 shared_dict = ReadProplistFromFile(path);
962 if (shared_dict && !PLIsDictionary(shared_dict)) {
963 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
964 "WindowMaker", path);
965 PLRelease(shared_dict);
966 shared_dict = NULL;
967 } else if (!shared_dict) {
968 wwarning(_("could not load domain %s from global defaults database"),
969 "WindowMaker");
972 /* user dictionary */
973 dict = ReadProplistFromFile(WDWindowMaker->path);
974 if (dict) {
975 if (!PLIsDictionary(dict)) {
976 PLRelease(dict);
977 dict = NULL;
978 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
979 "WindowMaker", WDWindowMaker->path);
980 } else {
981 if (shared_dict) {
982 PLSetFilename(shared_dict, PLGetFilename(dict));
983 PLMergeDictionaries(shared_dict, dict);
984 PLRelease(dict);
985 dict = shared_dict;
986 shared_dict = NULL;
988 for (i=0; i<wScreenCount; i++) {
989 scr = wScreenWithNumber(i);
990 if (scr)
991 wReadDefaults(scr, dict);
993 if (WDWindowMaker->dictionary) {
994 PLRelease(WDWindowMaker->dictionary);
996 WDWindowMaker->dictionary = dict;
998 } else {
999 wwarning(_("could not load domain %s from user defaults database"),
1000 "WindowMaker");
1002 if (shared_dict) {
1003 PLRelease(shared_dict);
1007 if (stat(WDWindowAttributes->path, &stbuf)>=0
1008 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1009 #ifdef HEARTBEAT
1010 puts("Checking WMWindowAttributes domain");
1011 #endif
1012 dict = ReadProplistFromFile(WDWindowAttributes->path);
1013 if (dict) {
1014 if (!PLIsDictionary(dict)) {
1015 PLRelease(dict);
1016 dict = NULL;
1017 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1018 "WMWindowAttributes", WDWindowAttributes->path);
1019 } else {
1020 if (WDWindowAttributes->dictionary)
1021 PLRelease(WDWindowAttributes->dictionary);
1022 WDWindowAttributes->dictionary = dict;
1023 for (i=0; i<wScreenCount; i++) {
1024 scr = wScreenWithNumber(i);
1025 if (scr)
1026 wDefaultUpdateIcons(scr);
1029 } else {
1030 wwarning(_("could not load domain %s from user defaults database"),
1031 "WMWindowAttributes");
1033 WDWindowAttributes->timestamp = stbuf.st_mtime;
1036 #ifndef LITE
1037 if (stat(WDRootMenu->path, &stbuf)>=0
1038 && WDRootMenu->timestamp < stbuf.st_mtime) {
1039 dict = ReadProplistFromFile(WDRootMenu->path);
1040 #ifdef HEARTBEAT
1041 puts("Checking WMRootMenu domain");
1042 #endif
1043 if (dict) {
1044 if (!PLIsArray(dict) && !PLIsString(dict)) {
1045 PLRelease(dict);
1046 dict = NULL;
1047 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1048 "WMRootMenu", WDRootMenu->path);
1049 } else {
1050 if (WDRootMenu->dictionary) {
1051 PLRelease(WDRootMenu->dictionary);
1053 WDRootMenu->dictionary = dict;
1055 } else {
1056 wwarning(_("could not load domain %s from user defaults database"),
1057 "WMRootMenu");
1059 WDRootMenu->timestamp = stbuf.st_mtime;
1061 #endif /* !LITE */
1063 if (!foo)
1064 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1068 void
1069 wReadDefaults(WScreen *scr, proplist_t new_dict)
1071 proplist_t plvalue, old_value;
1072 WDefaultEntry *entry;
1073 int i, must_update;
1074 int needs_refresh;
1075 void *tdata;
1076 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1077 ? WDWindowMaker->dictionary : NULL);
1079 must_update = 0;
1081 needs_refresh = 0;
1083 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1084 entry = &optionList[i];
1086 if (new_dict)
1087 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1088 else
1089 plvalue = NULL;
1091 if (!old_dict)
1092 old_value = NULL;
1093 else
1094 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1097 if (!plvalue && !old_value) {
1098 /* no default in the DB. Use builtin default */
1099 plvalue = entry->plvalue;
1100 if (plvalue && new_dict) {
1101 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1102 must_update = 1;
1104 } else if (!plvalue) {
1105 /* value was deleted from DB. Keep current value */
1106 continue;
1107 } else if (!old_value) {
1108 /* set value for the 1st time */
1109 } else if (!PLIsEqual(plvalue, old_value)) {
1110 /* value has changed */
1111 } else {
1112 /* value was not changed since last time */
1113 continue;
1116 if (plvalue) {
1117 #ifdef DEBUG
1118 printf("Updating %s to %s\n", entry->key, PLGetDescription(plvalue));
1119 #endif
1120 /* convert data */
1121 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1122 if (entry->update) {
1123 needs_refresh |=
1124 (*entry->update)(scr, entry, tdata, entry->extra_data);
1130 if (needs_refresh!=0 && !scr->flags.startup) {
1131 int foo;
1133 foo = 0;
1134 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1135 foo |= WTextureSettings;
1136 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1137 foo |= WFontSettings;
1138 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1139 foo |= WColorSettings;
1140 if (foo)
1141 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1142 (void*)foo);
1144 foo = 0;
1145 if (needs_refresh & REFRESH_MENU_TEXTURE)
1146 foo |= WTextureSettings;
1147 if (needs_refresh & REFRESH_MENU_FONT)
1148 foo |= WFontSettings;
1149 if (needs_refresh & REFRESH_MENU_COLOR)
1150 foo |= WColorSettings;
1151 if (foo)
1152 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1153 (void*)foo);
1155 foo = 0;
1156 if (needs_refresh & REFRESH_WINDOW_FONT) {
1157 foo |= WFontSettings;
1159 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1160 foo |= WTextureSettings;
1162 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1163 foo |= WColorSettings;
1165 if (foo)
1166 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1167 (void*)foo);
1169 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1170 foo = 0;
1171 if (needs_refresh & REFRESH_ICON_FONT) {
1172 foo |= WFontSettings;
1174 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1175 foo |= WTextureSettings;
1177 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1178 foo |= WTextureSettings;
1180 if (foo)
1181 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1182 (void*)foo);
1184 if (needs_refresh & REFRESH_ICON_TILE)
1185 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1190 void
1191 wDefaultUpdateIcons(WScreen *scr)
1193 WAppIcon *aicon = scr->app_icon_list;
1194 WWindow *wwin = scr->focused_window;
1195 char *file;
1197 while(aicon) {
1198 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1199 False);
1200 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1201 || (file && !aicon->icon->file)) {
1202 RImage *new_image;
1204 if (aicon->icon->file)
1205 free(aicon->icon->file);
1206 aicon->icon->file = wstrdup(file);
1208 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1209 aicon->wm_class);
1210 if (new_image) {
1211 wIconChangeImage(aicon->icon, new_image);
1212 wAppIconPaint(aicon);
1215 aicon = aicon->next;
1218 if (!wPreferences.flags.noclip)
1219 wClipIconPaint(scr->clip_icon);
1221 while (wwin) {
1222 if (wwin->icon && wwin->flags.miniaturized) {
1223 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1224 False);
1225 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1226 || (file && !wwin->icon->file)) {
1227 RImage *new_image;
1229 if (wwin->icon->file)
1230 free(wwin->icon->file);
1231 wwin->icon->file = wstrdup(file);
1233 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1234 wwin->wm_class);
1235 if (new_image)
1236 wIconChangeImage(wwin->icon, new_image);
1239 wwin = wwin->prev;
1244 /* --------------------------- Local ----------------------- */
1246 #define STRINGP(x) if (!PLIsString(value)) { \
1247 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1248 entry->key, x); \
1249 return False; }
1253 static int
1254 string2index(proplist_t key, proplist_t val, proplist_t def,
1255 WOptionEnumeration *values)
1257 char *str;
1258 WOptionEnumeration *v;
1259 char buffer[TOTAL_VALUES_LENGTH];
1261 if (PLIsString(val) && (str = PLGetString(val))) {
1262 for (v=values; v->string!=NULL; v++) {
1263 if (strcasecmp(v->string, str)==0)
1264 return v->value;
1268 buffer[0] = 0;
1269 for (v=values; v->string!=NULL; v++) {
1270 if (!v->is_alias) {
1271 if (buffer[0]!=0)
1272 strcat(buffer, ", ");
1273 strcat(buffer, v->string);
1276 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1277 PLGetString(key), buffer);
1279 if (def) {
1280 return string2index(key, val, NULL, values);
1283 return -1;
1290 * value - is the value in the defaults DB
1291 * addr - is the address to store the data
1292 * ret - is the address to store a pointer to a temporary buffer. ret
1293 * must not be freed and is used by the set functions
1295 static int
1296 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1297 void **ret)
1299 static char data;
1300 char *val;
1301 int second_pass=0;
1303 STRINGP("Boolean");
1305 val = PLGetString(value);
1307 again:
1308 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1309 || strcasecmp(val, "YES")==0) {
1311 data = 1;
1312 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1313 || strcasecmp(val, "NO")==0) {
1314 data = 0;
1315 } else {
1316 int i;
1317 if (sscanf(val, "%i", &i)==1) {
1318 if (i!=0)
1319 data = 1;
1320 else
1321 data = 0;
1322 } else {
1323 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1324 val, entry->key);
1325 if (second_pass==0) {
1326 val = PLGetString(entry->plvalue);
1327 second_pass = 1;
1328 wwarning(_("using default \"%s\" instead"), val);
1329 goto again;
1331 return False;
1335 if (ret)
1336 *ret = &data;
1338 if (addr) {
1339 *(char*)addr = data;
1342 return True;
1346 static int
1347 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1348 void **ret)
1350 static int data;
1351 char *val;
1354 STRINGP("Integer");
1356 val = PLGetString(value);
1358 if (sscanf(val, "%i", &data)!=1) {
1359 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1360 val, entry->key);
1361 val = PLGetString(entry->plvalue);
1362 wwarning(_("using default \"%s\" instead"), val);
1363 if (sscanf(val, "%i", &data)!=1) {
1364 return False;
1368 if (ret)
1369 *ret = &data;
1371 if (addr) {
1372 *(int*)addr = data;
1374 return True;
1378 static int
1379 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1380 void **ret)
1382 static WCoord data;
1383 char *val_x, *val_y;
1384 int nelem, changed=0;
1385 proplist_t elem_x, elem_y;
1387 again:
1388 if (!PLIsArray(value)) {
1389 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1390 entry->key, "Coordinate");
1391 if (changed==0) {
1392 value = entry->plvalue;
1393 changed = 1;
1394 wwarning(_("using default \"%s\" instead"), entry->default_value);
1395 goto again;
1397 return False;
1400 nelem = PLGetNumberOfElements(value);
1401 if (nelem != 2) {
1402 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1403 entry->key);
1404 if (changed==0) {
1405 value = entry->plvalue;
1406 changed = 1;
1407 wwarning(_("using default \"%s\" instead"), entry->default_value);
1408 goto again;
1410 return False;
1413 elem_x = PLGetArrayElement(value, 0);
1414 elem_y = PLGetArrayElement(value, 1);
1416 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1417 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1418 entry->key);
1419 if (changed==0) {
1420 value = entry->plvalue;
1421 changed = 1;
1422 wwarning(_("using default \"%s\" instead"), entry->default_value);
1423 goto again;
1425 return False;
1428 val_x = PLGetString(elem_x);
1429 val_y = PLGetString(elem_y);
1431 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1432 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1433 if (changed==0) {
1434 value = entry->plvalue;
1435 changed = 1;
1436 wwarning(_("using default \"%s\" instead"), entry->default_value);
1437 goto again;
1439 return False;
1442 if (data.x < 0)
1443 data.x = 0;
1444 else if (data.x > scr->scr_width/3)
1445 data.x = scr->scr_width/3;
1446 if (data.y < 0)
1447 data.y = 0;
1448 else if (data.y > scr->scr_height/3)
1449 data.y = scr->scr_height/3;
1451 if (ret)
1452 *ret = &data;
1454 if (addr) {
1455 *(WCoord*)addr = data;
1458 return True;
1462 #if 0
1463 /* This function is not used at the moment. */
1464 static int
1465 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1466 void **ret)
1468 static char *data;
1470 STRINGP("String");
1472 data = PLGetString(value);
1474 if (!data) {
1475 data = PLGetString(entry->plvalue);
1476 if (!data)
1477 return False;
1480 if (ret)
1481 *ret = &data;
1483 if (addr)
1484 *(char**)addr = wstrdup(data);
1486 return True;
1488 #endif
1491 static int
1492 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1493 void **ret)
1495 static char *data;
1496 int i, count, len;
1497 char *ptr;
1498 proplist_t d;
1499 int changed=0;
1501 again:
1502 if (!PLIsArray(value)) {
1503 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1504 entry->key, "an array of paths");
1505 if (changed==0) {
1506 value = entry->plvalue;
1507 changed = 1;
1508 wwarning(_("using default \"%s\" instead"), entry->default_value);
1509 goto again;
1511 return False;
1514 i = 0;
1515 count = PLGetNumberOfElements(value);
1516 if (count < 1) {
1517 if (changed==0) {
1518 value = entry->plvalue;
1519 changed = 1;
1520 wwarning(_("using default \"%s\" instead"), entry->default_value);
1521 goto again;
1523 return False;
1526 len = 0;
1527 for (i=0; i<count; i++) {
1528 d = PLGetArrayElement(value, i);
1529 if (!d || !PLIsString(d)) {
1530 count = i;
1531 break;
1533 len += strlen(PLGetString(d))+1;
1536 ptr = data = wmalloc(len+1);
1538 for (i=0; i<count; i++) {
1539 d = PLGetArrayElement(value, i);
1540 if (!d || !PLIsString(d)) {
1541 break;
1543 strcpy(ptr, PLGetString(d));
1544 ptr += strlen(PLGetString(d));
1545 *ptr = ':';
1546 ptr++;
1548 ptr--; *(ptr--) = 0;
1550 if (*(char**)addr!=NULL) {
1551 free(*(char**)addr);
1553 *(char**)addr = data;
1555 return True;
1559 static int
1560 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1561 void **ret)
1563 static signed char data;
1565 data = string2index(entry->plkey, value, entry->default_value,
1566 (WOptionEnumeration*)entry->extra_data);
1567 if (data < 0)
1568 return False;
1570 if (ret)
1571 *ret = &data;
1573 if (addr)
1574 *(signed char*)addr = data;
1576 return True;
1582 * (solid <color>)
1583 * (hgradient <color> <color>)
1584 * (vgradient <color> <color>)
1585 * (dgradient <color> <color>)
1586 * (mhgradient <color> <color> ...)
1587 * (mvgradient <color> <color> ...)
1588 * (tpixmap <file> <color>)
1589 * (spixmap <file> <color>)
1590 * (cpixmap <file> <color>)
1591 * (thgradient <file> <opaqueness> <color> <color>)
1592 * (tvgradient <file> <opaqueness> <color> <color>)
1593 * (tdgradient <file> <opaqueness> <color> <color>)
1594 * (function <lib> <function> ...)
1597 static WTexture*
1598 parse_texture(WScreen *scr, proplist_t pl)
1600 proplist_t elem;
1601 char *val;
1602 int nelem;
1603 WTexture *texture=NULL;
1605 nelem = PLGetNumberOfElements(pl);
1606 if (nelem < 1)
1607 return NULL;
1610 elem = PLGetArrayElement(pl, 0);
1611 if (!elem || !PLIsString(elem))
1612 return NULL;
1613 val = PLGetString(elem);
1616 if (strcasecmp(val, "solid")==0) {
1617 XColor color;
1619 if (nelem != 2)
1620 return NULL;
1622 /* get color */
1624 elem = PLGetArrayElement(pl, 1);
1625 if (!elem || !PLIsString(elem))
1626 return NULL;
1627 val = PLGetString(elem);
1629 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1630 wwarning(_("\"%s\" is not a valid color name"), val);
1631 return NULL;
1634 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1635 } else if (strcasecmp(val, "dgradient")==0
1636 || strcasecmp(val, "vgradient")==0
1637 || strcasecmp(val, "hgradient")==0) {
1638 RColor color1, color2;
1639 XColor xcolor;
1640 int type;
1642 if (nelem != 3) {
1643 wwarning(_("bad number of arguments in gradient specification"));
1644 return NULL;
1647 if (val[0]=='d' || val[0]=='D')
1648 type = WTEX_DGRADIENT;
1649 else if (val[0]=='h' || val[0]=='H')
1650 type = WTEX_HGRADIENT;
1651 else
1652 type = WTEX_VGRADIENT;
1655 /* get from color */
1656 elem = PLGetArrayElement(pl, 1);
1657 if (!elem || !PLIsString(elem))
1658 return NULL;
1659 val = PLGetString(elem);
1661 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1662 wwarning(_("\"%s\" is not a valid color name"), val);
1663 return NULL;
1665 color1.alpha = 255;
1666 color1.red = xcolor.red >> 8;
1667 color1.green = xcolor.green >> 8;
1668 color1.blue = xcolor.blue >> 8;
1670 /* get to color */
1671 elem = PLGetArrayElement(pl, 2);
1672 if (!elem || !PLIsString(elem)) {
1673 return NULL;
1675 val = PLGetString(elem);
1677 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1678 wwarning(_("\"%s\" is not a valid color name"), val);
1679 return NULL;
1681 color2.alpha = 255;
1682 color2.red = xcolor.red >> 8;
1683 color2.green = xcolor.green >> 8;
1684 color2.blue = xcolor.blue >> 8;
1686 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1688 } else if (strcasecmp(val, "mhgradient")==0
1689 || strcasecmp(val, "mvgradient")==0
1690 || strcasecmp(val, "mdgradient")==0) {
1691 XColor color;
1692 RColor **colors;
1693 int i, count;
1694 int type;
1696 if (nelem < 3) {
1697 wwarning(_("too few arguments in multicolor gradient specification"));
1698 return NULL;
1701 if (val[1]=='h' || val[1]=='H')
1702 type = WTEX_MHGRADIENT;
1703 else if (val[1]=='v' || val[1]=='V')
1704 type = WTEX_MVGRADIENT;
1705 else
1706 type = WTEX_MDGRADIENT;
1708 count = nelem-1;
1710 colors = wmalloc(sizeof(RColor*)*(count+1));
1712 for (i=0; i<count; i++) {
1713 elem = PLGetArrayElement(pl, i+1);
1714 if (!elem || !PLIsString(elem)) {
1715 for (--i; i>=0; --i) {
1716 free(colors[i]);
1718 free(colors);
1719 return NULL;
1721 val = PLGetString(elem);
1723 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1724 wwarning(_("\"%s\" is not a valid color name"), val);
1725 for (--i; i>=0; --i) {
1726 free(colors[i]);
1728 free(colors);
1729 return NULL;
1730 } else {
1731 colors[i] = wmalloc(sizeof(RColor));
1732 colors[i]->red = color.red >> 8;
1733 colors[i]->green = color.green >> 8;
1734 colors[i]->blue = color.blue >> 8;
1737 colors[i] = NULL;
1739 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1740 } else if (strcasecmp(val, "spixmap")==0 ||
1741 strcasecmp(val, "cpixmap")==0 ||
1742 strcasecmp(val, "tpixmap")==0) {
1743 XColor color;
1744 int type;
1746 if (nelem != 3)
1747 return NULL;
1749 if (val[0] == 's' || val[0] == 'S')
1750 type = WTP_SCALE;
1751 else if (val[0] == 'c' || val[0] == 'C')
1752 type = WTP_CENTER;
1753 else
1754 type = WTP_TILE;
1756 /* get color */
1757 elem = PLGetArrayElement(pl, 2);
1758 if (!elem || !PLIsString(elem)) {
1759 return NULL;
1761 val = PLGetString(elem);
1763 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1764 wwarning(_("\"%s\" is not a valid color name"), val);
1765 return NULL;
1768 /* file name */
1769 elem = PLGetArrayElement(pl, 1);
1770 if (!elem || !PLIsString(elem))
1771 return NULL;
1772 val = PLGetString(elem);
1774 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1775 } else if (strcasecmp(val, "thgradient")==0
1776 || strcasecmp(val, "tvgradient")==0
1777 || strcasecmp(val, "tdgradient")==0) {
1778 RColor color1, color2;
1779 XColor xcolor;
1780 int opacity;
1781 int style;
1783 if (val[1]=='h' || val[1]=='H')
1784 style = WTEX_THGRADIENT;
1785 else if (val[1]=='v' || val[1]=='V')
1786 style = WTEX_TVGRADIENT;
1787 else
1788 style = WTEX_TDGRADIENT;
1790 if (nelem != 5) {
1791 wwarning(_("bad number of arguments in textured gradient specification"));
1792 return NULL;
1795 /* get from color */
1796 elem = PLGetArrayElement(pl, 3);
1797 if (!elem || !PLIsString(elem))
1798 return NULL;
1799 val = PLGetString(elem);
1801 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1802 wwarning(_("\"%s\" is not a valid color name"), val);
1803 return NULL;
1805 color1.alpha = 255;
1806 color1.red = xcolor.red >> 8;
1807 color1.green = xcolor.green >> 8;
1808 color1.blue = xcolor.blue >> 8;
1810 /* get to color */
1811 elem = PLGetArrayElement(pl, 4);
1812 if (!elem || !PLIsString(elem)) {
1813 return NULL;
1815 val = PLGetString(elem);
1817 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1818 wwarning(_("\"%s\" is not a valid color name"), val);
1819 return NULL;
1821 color2.alpha = 255;
1822 color2.red = xcolor.red >> 8;
1823 color2.green = xcolor.green >> 8;
1824 color2.blue = xcolor.blue >> 8;
1826 /* get opacity */
1827 elem = PLGetArrayElement(pl, 2);
1828 if (!elem || !PLIsString(elem))
1829 opacity = 128;
1830 else
1831 val = PLGetString(elem);
1833 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1834 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1835 opacity = 128;
1838 /* get file name */
1839 elem = PLGetArrayElement(pl, 1);
1840 if (!elem || !PLIsString(elem))
1841 return NULL;
1842 val = PLGetString(elem);
1844 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1845 val, opacity);
1847 #ifdef TEXTURE_PLUGIN
1848 else if (strcasecmp(val, "function")==0) {
1849 WTexFunction *function;
1850 void (*initFunc) (Display *, Colormap);
1851 char *lib, *func, **argv;
1852 int i, argc;
1854 if (nelem < 3)
1855 return NULL;
1857 /* get the library name */
1858 elem = PLGetArrayElement(pl, 1);
1859 if (!elem || !PLIsString(elem)) {
1860 return NULL;
1862 lib = PLGetString(elem);
1864 /* get the function name */
1865 elem = PLGetArrayElement(pl, 2);
1866 if (!elem || !PLIsString(elem)) {
1867 return NULL;
1869 func = PLGetString(elem);
1871 argc = nelem - 2;
1872 argv = (char **)wmalloc(argc * sizeof(char *));
1874 /* get the parameters */
1875 argv[0] = wstrdup(func);
1876 for (i = 0; i < argc - 1; i++) {
1877 elem = PLGetArrayElement(pl, 3 + i);
1878 if (!elem || !PLIsString(elem)) {
1879 free(argv);
1881 return NULL;
1883 argv[i+1] = wstrdup(PLGetString(elem));
1886 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1888 #ifdef HAVE_DLFCN_H
1889 if (function) {
1890 initFunc = dlsym(function->handle, "initWindowMaker");
1891 if (initFunc) {
1892 initFunc(dpy, scr->w_colormap);
1893 } else {
1894 wwarning(_("could not initialize library %s"), lib);
1896 } else {
1897 wwarning(_("could not find function %s::%s"), lib, func);
1899 #endif /* HAVE_DLFCN_H */
1900 texture = (WTexture*)function;
1902 #endif /* TEXTURE_PLUGIN */
1903 else {
1904 wwarning(_("invalid texture type %s"), val);
1905 return NULL;
1907 return texture;
1912 static int
1913 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1914 void **ret)
1916 static WTexture *texture;
1917 int changed=0;
1919 again:
1920 if (!PLIsArray(value)) {
1921 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1922 entry->key, "Texture");
1923 if (changed==0) {
1924 value = entry->plvalue;
1925 changed = 1;
1926 wwarning(_("using default \"%s\" instead"), entry->default_value);
1927 goto again;
1929 return False;
1932 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
1933 proplist_t pl;
1935 pl = PLGetArrayElement(value, 0);
1936 if (!pl || !PLIsString(pl) || !PLGetString(pl)
1937 || strcasecmp(PLGetString(pl), "solid")!=0) {
1938 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1939 entry->key, "Solid Texture");
1941 value = entry->plvalue;
1942 changed = 1;
1943 wwarning(_("using default \"%s\" instead"), entry->default_value);
1944 goto again;
1948 texture = parse_texture(scr, value);
1950 if (!texture) {
1951 wwarning(_("Error in texture specification for key \"%s\""),
1952 entry->key);
1953 if (changed==0) {
1954 value = entry->plvalue;
1955 changed = 1;
1956 wwarning(_("using default \"%s\" instead"), entry->default_value);
1957 goto again;
1959 return False;
1962 if (ret)
1963 *ret = &texture;
1965 if (addr)
1966 *(WTexture**)addr = texture;
1968 return True;
1973 static int
1974 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
1975 void *addr, void **ret)
1977 proplist_t elem;
1978 int changed = 0;
1979 char *val;
1980 int nelem;
1982 again:
1983 if (!PLIsArray(value)) {
1984 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1985 "WorkspaceBack", "Texture or None");
1986 if (changed==0) {
1987 value = entry->plvalue;
1988 changed = 1;
1989 wwarning(_("using default \"%s\" instead"), entry->default_value);
1990 goto again;
1992 return False;
1995 /* only do basic error checking and verify for None texture */
1997 nelem = PLGetNumberOfElements(value);
1998 if (nelem > 0) {
1999 elem = PLGetArrayElement(value, 0);
2000 if (!elem || !PLIsString(elem)) {
2001 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2002 if (changed==0) {
2003 value = entry->plvalue;
2004 changed = 1;
2005 wwarning(_("using default \"%s\" instead"), entry->default_value);
2006 goto again;
2008 return False;
2010 val = PLGetString(elem);
2012 if (strcasecmp(val, "None")==0)
2013 return True;
2015 *ret = PLRetain(value);
2017 return True;
2021 static int
2022 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2023 void *addr, void **ret)
2025 proplist_t elem;
2026 int nelem;
2027 int changed = 0;
2029 again:
2030 if (!PLIsArray(value)) {
2031 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2032 "WorkspaceSpecificBack", "an array of textures");
2033 if (changed==0) {
2034 value = entry->plvalue;
2035 changed = 1;
2036 wwarning(_("using default \"%s\" instead"), entry->default_value);
2037 goto again;
2039 return False;
2042 /* only do basic error checking and verify for None texture */
2044 nelem = PLGetNumberOfElements(value);
2045 if (nelem > 0) {
2046 while (nelem--) {
2047 elem = PLGetArrayElement(value, nelem);
2048 if (!elem || !PLIsArray(elem)) {
2049 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2050 nelem);
2055 *ret = PLRetain(value);
2057 #ifdef notworking
2059 * Kluge to force wmsetbg helper to set the default background.
2060 * If the WorkspaceSpecificBack is changed once wmaker has started,
2061 * the WorkspaceBack won't be sent to the helper, unless the user
2062 * changes it's value too. So, we must force this by removing the
2063 * value from the defaults DB.
2065 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2066 proplist_t key = PLMakeString("WorkspaceBack");
2068 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2070 PLRelease(key);
2072 #endif
2073 return True;
2077 static int
2078 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2079 void **ret)
2081 static WFont *font;
2082 char *val;
2084 STRINGP("Font");
2086 val = PLGetString(value);
2088 font = wLoadFont(val);
2089 if (!font) {
2090 wfatal(_("could not load any usable font!!!"));
2091 exit(1);
2094 if (ret)
2095 *ret = font;
2097 /* can't assign font value outside update function */
2098 wassertrv(addr == NULL, True);
2100 return True;
2104 static int
2105 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2106 void **ret)
2108 static XColor color;
2109 char *val;
2110 int second_pass=0;
2112 STRINGP("Color");
2114 val = PLGetString(value);
2116 again:
2117 if (!wGetColor(scr, val, &color)) {
2118 wwarning(_("could not get color for key \"%s\""),
2119 entry->key);
2120 if (second_pass==0) {
2121 val = PLGetString(entry->plvalue);
2122 second_pass = 1;
2123 wwarning(_("using default \"%s\" instead"), val);
2124 goto again;
2126 return False;
2129 if (ret)
2130 *ret = &color;
2132 assert(addr==NULL);
2134 if (addr)
2135 *(unsigned long*)addr = pixel;
2138 return True;
2143 static int
2144 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2145 void **ret)
2147 static WShortKey shortcut;
2148 KeySym ksym;
2149 char *val;
2150 char *k;
2151 char buf[128], *b;
2154 STRINGP("Key spec");
2156 val = PLGetString(value);
2158 if (!val || strcasecmp(val, "NONE")==0) {
2159 shortcut.keycode = 0;
2160 shortcut.modifier = 0;
2161 if (ret)
2162 *ret = &shortcut;
2163 return True;
2166 strcpy(buf, val);
2168 b = (char*)buf;
2170 /* get modifiers */
2171 shortcut.modifier = 0;
2172 while ((k = strchr(b, '+'))!=NULL) {
2173 int mod;
2175 *k = 0;
2176 mod = wXModifierFromKey(b);
2177 if (mod<0) {
2178 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2179 return False;
2181 shortcut.modifier |= mod;
2183 b = k+1;
2186 /* get key */
2187 ksym = XStringToKeysym(b);
2189 if (ksym==NoSymbol) {
2190 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2191 val);
2192 return False;
2195 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2196 if (shortcut.keycode==0) {
2197 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2198 return False;
2201 if (ret)
2202 *ret = &shortcut;
2204 return True;
2208 static int
2209 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2210 void **ret)
2212 static unsigned int mask;
2213 char *str;
2215 STRINGP("Modifier Key");
2217 str = PLGetString(value);
2218 if (!str)
2219 return False;
2221 mask = wXModifierFromKey(str);
2222 if (mask < 0) {
2223 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2224 mask = 0;
2225 return False;
2228 if (addr)
2229 *(unsigned int*)addr = mask;
2231 if (ret)
2232 *ret = &mask;
2234 return True;
2238 #ifdef NEWSTUFF
2239 static int
2240 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2241 void *addr, void **ret)
2243 unsigned int mask;
2244 char *str;
2245 RImage *image;
2246 int i, n;
2247 int w, h;
2249 STRINGP("Image File Path");
2251 str = PLGetString(value);
2252 if (!str)
2253 return False;
2255 image = RLoadImage(scr->rcontext, str, 0);
2256 if (!image) {
2257 wwarning(_("could not load image in option %s: %s"), entry->key,
2258 RMessageForError(RErrorCode));
2259 return False;
2262 if (*(RImage**)addr) {
2263 RDestroyImage(*(RImage**)addr);
2265 if (addr)
2266 *(RImage**)addr = image;
2268 assert(ret == NULL);
2270 if (ret)
2271 *(RImage**)ret = image;
2274 return True;
2276 #endif
2279 /* ---------------- value setting functions --------------- */
2280 static int
2281 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2283 return REFRESH_WINDOW_TITLE_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|REFRESH_BUTTON_IMAGES;
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_MENU_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_MENU_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]);
2542 scr->clip_title_pixel[index] = color->pixel;
2544 if (index == CLIP_NORMAL) {
2545 RImage *image;
2546 RColor color1, color2;
2547 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2548 int as = pt - 15; /* 15 = 5+5+5 */
2550 FREE_PIXMAP(scr->clip_arrow_gradient);
2552 color1.red = (color->red >> 8)*6/10;
2553 color1.green = (color->green >> 8)*6/10;
2554 color1.blue = (color->blue >> 8)*6/10;
2556 color2.red = WMIN((color->red >> 8)*20/10, 255);
2557 color2.green = WMIN((color->green >> 8)*20/10, 255);
2558 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2560 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2561 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2562 RDestroyImage(image);
2564 return REFRESH_ICON_TITLE_COLOR;
2568 static int
2569 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2571 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2572 scr->window_title_pixel[index]!=scr->black_pixel) {
2573 wFreeColor(scr, scr->window_title_pixel[index]);
2576 scr->window_title_pixel[index] = color->pixel;
2578 if (index == WS_UNFOCUSED)
2579 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2581 return REFRESH_WINDOW_TITLE_COLOR;
2585 static int
2586 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2588 #ifdef TITLE_TEXT_SHADOW
2589 if (index == WS_SMENU){
2590 if (scr->menu_title_pixel[WS_SMENU]!=scr->white_pixel &&
2591 scr->menu_title_pixel[WS_SMENU]!=scr->black_pixel) {
2592 wFreeColor(scr, scr->menu_title_pixel[WS_SMENU]);
2594 scr->menu_title_pixel[WS_SMENU] = color->pixel;
2596 else {
2597 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2598 scr->menu_title_pixel[0]!=scr->black_pixel) {
2599 wFreeColor(scr, scr->menu_title_pixel[0]);
2601 scr->menu_title_pixel[0] = color->pixel;
2603 #else /* !TITLE_TEXT_SHADOW */
2604 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2605 scr->menu_title_pixel[0]!=scr->black_pixel) {
2606 wFreeColor(scr, scr->menu_title_pixel[0]);
2609 scr->menu_title_pixel[0] = color->pixel;
2610 #endif /* !TITLE_TEXT_SHADOW */
2611 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2613 return REFRESH_MENU_TITLE_COLOR;
2617 static int
2618 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2620 XGCValues gcv;
2621 #define gcm (GCForeground|GCBackground|GCFillStyle)
2623 if (scr->mtext_pixel!=scr->white_pixel &&
2624 scr->mtext_pixel!=scr->black_pixel) {
2625 wFreeColor(scr, scr->mtext_pixel);
2628 scr->mtext_pixel = color->pixel;
2630 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2633 if (scr->dtext_pixel == scr->mtext_pixel) {
2634 gcv.foreground = scr->white_pixel;
2635 gcv.background = scr->black_pixel;
2636 gcv.fill_style = FillStippled;
2637 } else {
2638 gcv.foreground = scr->dtext_pixel;
2639 gcv.fill_style = FillSolid;
2641 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2643 return REFRESH_MENU_COLOR;
2644 #undef gcm
2648 static int
2649 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2651 XGCValues gcv;
2652 #define gcm (GCForeground|GCBackground|GCFillStyle)
2654 if (scr->dtext_pixel!=scr->white_pixel &&
2655 scr->dtext_pixel!=scr->black_pixel) {
2656 wFreeColor(scr, scr->dtext_pixel);
2659 scr->dtext_pixel = color->pixel;
2661 if (scr->dtext_pixel == scr->mtext_pixel) {
2662 gcv.foreground = scr->white_pixel;
2663 gcv.background = scr->black_pixel;
2664 gcv.fill_style = FillStippled;
2665 } else {
2666 gcv.foreground = scr->dtext_pixel;
2667 gcv.fill_style = FillSolid;
2669 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2671 return REFRESH_MENU_COLOR;
2672 #undef gcm
2675 static int
2676 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2678 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2680 return REFRESH_ICON_TITLE_COLOR;
2684 static int
2685 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2687 if (scr->icon_title_texture) {
2688 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2690 XQueryColor (dpy, scr->w_colormap, color);
2691 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2693 return REFRESH_ICON_TITLE_BACK;
2697 static void
2698 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2700 close(scr->helper_fd);
2701 scr->helper_fd = 0;
2702 scr->helper_pid = 0;
2703 scr->flags.backimage_helper_launched = 0;
2707 static int
2708 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2709 void *bar)
2711 int i;
2712 proplist_t val;
2713 char *str;
2715 if (scr->flags.backimage_helper_launched) {
2716 if (PLGetNumberOfElements(value)==0) {
2717 SendHelperMessage(scr, 'C', 0, NULL);
2718 SendHelperMessage(scr, 'K', 0, NULL);
2720 PLRelease(value);
2721 return 0;
2723 } else {
2724 pid_t pid;
2725 int filedes[2];
2727 if (PLGetNumberOfElements(value) == 0)
2728 return 0;
2730 if (pipe(filedes) < 0) {
2731 wsyserror("pipe() failed:can't set workspace specific background image");
2733 PLRelease(value);
2734 return 0;
2737 pid = fork();
2738 if (pid < 0) {
2739 wsyserror("fork() failed:can't set workspace specific background image");
2740 if (close(filedes[0]) < 0)
2741 wsyserror("could not close pipe");
2742 if (close(filedes[1]) < 0)
2743 wsyserror("could not close pipe");
2745 } else if (pid == 0) {
2746 SetupEnvironment(scr);
2748 if (close(0) < 0)
2749 wsyserror("could not close pipe");
2750 if (dup(filedes[0]) < 0) {
2751 wsyserror("dup() failed:can't set workspace specific background image");
2753 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2754 wsyserror("could not execute wmsetbg");
2755 exit(1);
2756 } else {
2758 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2759 wsyserror("error setting close-on-exec flag");
2761 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2762 wsyserror("error setting close-on-exec flag");
2765 scr->helper_fd = filedes[1];
2766 scr->helper_pid = pid;
2767 scr->flags.backimage_helper_launched = 1;
2769 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2771 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2775 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2776 val = PLGetArrayElement(value, i);
2777 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2778 str = PLGetDescription(val);
2780 SendHelperMessage(scr, 'S', i+1, str);
2782 free(str);
2783 } else {
2784 SendHelperMessage(scr, 'U', i+1, NULL);
2787 sleep(1);
2789 PLRelease(value);
2790 return 0;
2794 static int
2795 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2796 void *bar)
2798 if (scr->flags.backimage_helper_launched) {
2799 char *str;
2801 if (PLGetNumberOfElements(value)==0) {
2802 SendHelperMessage(scr, 'U', 0, NULL);
2803 } else {
2804 /* set the default workspace background to this one */
2805 str = PLGetDescription(value);
2806 if (str) {
2807 SendHelperMessage(scr, 'S', 0, str);
2808 free(str);
2809 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2810 } else {
2811 SendHelperMessage(scr, 'U', 0, NULL);
2814 } else {
2815 char *command;
2816 char *text;
2818 SetupEnvironment(scr);
2819 text = PLGetDescription(value);
2820 command = wmalloc(strlen(text)+40);
2821 sprintf(command, "wmsetbg -d -p '%s' &", text);
2822 free(text);
2823 system(command);
2824 free(command);
2826 PLRelease(value);
2828 return 0;
2832 static int
2833 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2835 if (scr->widget_texture) {
2836 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2838 scr->widget_texture = *(WTexSolid**)texture;
2840 if (scr->geometry_display != None)
2841 XSetWindowBackground(dpy, scr->geometry_display,
2842 scr->widget_texture->normal.pixel);
2844 return 0;
2848 static int
2849 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2851 if (scr->window_title_texture[WS_FOCUSED]) {
2852 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2854 scr->window_title_texture[WS_FOCUSED] = *texture;
2856 return REFRESH_WINDOW_TEXTURES;
2860 static int
2861 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2863 if (scr->window_title_texture[WS_PFOCUSED]) {
2864 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2866 scr->window_title_texture[WS_PFOCUSED] = *texture;
2868 return REFRESH_WINDOW_TEXTURES;
2872 static int
2873 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2875 if (scr->window_title_texture[WS_UNFOCUSED]) {
2876 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2878 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2880 return REFRESH_WINDOW_TEXTURES;
2884 static int
2885 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2887 if (scr->resizebar_texture[0]) {
2888 wTextureDestroy(scr, scr->resizebar_texture[0]);
2890 scr->resizebar_texture[0] = *texture;
2892 return REFRESH_WINDOW_TEXTURES;
2896 static int
2897 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2899 if (scr->menu_title_texture[0]) {
2900 wTextureDestroy(scr, scr->menu_title_texture[0]);
2902 scr->menu_title_texture[0] = *texture;
2904 return REFRESH_MENU_TITLE_TEXTURE;
2908 static int
2909 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2911 if (scr->menu_item_texture) {
2912 wTextureDestroy(scr, scr->menu_item_texture);
2913 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2915 scr->menu_item_texture = *texture;
2917 scr->menu_item_auxtexture
2918 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2920 return REFRESH_MENU_TEXTURE;
2924 static int
2925 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
2927 WWindow *wwin;
2928 wKeyBindings[index] = *shortcut;
2930 wwin = scr->focused_window;
2932 while (wwin!=NULL) {
2933 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2935 if (!WFLAGP(wwin, no_bind_keys)) {
2936 wWindowSetKeyGrabs(wwin);
2938 wwin = wwin->prev;
2941 return 0;
2945 static int
2946 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2948 wArrangeIcons(scr, True);
2950 return 0;
2954 static int
2955 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2957 wScreenUpdateUsableArea(scr);
2959 return 0;
2963 static int
2964 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2966 return REFRESH_MENU_TEXTURE;
2971 static int
2972 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2974 return REFRESH_BUTTON_IMAGES;
2979 * Very ugly kluge.
2980 * Need access to the double click variables, so that all widgets in
2981 * wmaker panels will have the same dbl-click values.
2982 * TODO: figure a better way of dealing with it.
2984 #include "WINGsP.h"
2986 static int
2987 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2989 extern _WINGsConfiguration WINGsConfiguration;
2991 if (*value <= 0)
2992 *(int*)foo = 1;
2994 WINGsConfiguration.doubleClickDelay = *value;
2996 return 0;