dunno
[wmaker-crm.git] / src / defaults.c
bloba5340f79c99420bfe3ffc9e1796a4dfb14e71c98
1 /* defaults.c - manage configuration through defaults db
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998 Dan Pascu
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <time.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <limits.h>
36 #include <signal.h>
38 #ifdef HAVE_DLFCN_H
39 # include <dlfcn.h>
40 #endif
44 #ifndef PATH_MAX
45 #define PATH_MAX DEFAULT_PATH_MAX
46 #endif
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #include <X11/keysym.h>
52 #include <wraster.h>
55 #include "WindowMaker.h"
56 #include "wcore.h"
57 #include "framewin.h"
58 #include "window.h"
59 #include "texture.h"
60 #include "screen.h"
61 #include "resources.h"
62 #include "defaults.h"
63 #include "keybind.h"
64 #include "xmodifier.h"
65 #include "icon.h"
66 #include "funcs.h"
67 #include "actions.h"
68 #include "dock.h"
69 #include "workspace.h"
73 * Our own proplist reader parser. This one will not accept any
74 * syntax errors and is more descriptive in the error messages.
75 * It also doesn't seem to crash.
77 extern proplist_t ReadProplistFromFile(char *file);
80 /***** Global *****/
82 extern WDDomain *WDWindowMaker;
83 extern WDDomain *WDWindowAttributes;
84 extern WDDomain *WDRootMenu;
86 extern int wScreenCount;
89 extern proplist_t wDomainName;
90 extern proplist_t wAttributeDomainName;
92 extern WPreferences wPreferences;
94 extern WShortKey wKeyBindings[WKBD_LAST];
96 typedef struct {
97 char *key;
98 char *default_value;
99 void *extra_data;
100 void *addr;
101 int (*convert)();
102 int (*update)();
103 proplist_t plkey;
104 proplist_t plvalue; /* default value */
105 } WDefaultEntry;
108 /* used to map strings to integers */
109 typedef struct {
110 char *string;
111 short value;
112 char is_alias;
113 } 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
138 /* value setting functions */
139 static int setJustify();
140 static int setIfDockPresent();
141 static int setStickyIcons();
143 static int setPositive();
145 static int setWidgetColor();
146 static int setIconTile();
147 static int setWinTitleFont();
148 static int setMenuTitleFont();
149 static int setMenuTextFont();
150 static int setIconTitleFont();
151 static int setIconTitleColor();
152 static int setIconTitleBack();
153 static int setDisplayFont();
154 static int setWTitleColor();
155 static int setFTitleBack();
156 static int setPTitleBack();
157 static int setUTitleBack();
158 static int setResizebarBack();
159 static int setWorkspaceBack();
160 static int setWorkspaceSpecificBack();
161 static int setMenuTitleColor();
162 static int setMenuTextColor();
163 static int setMenuDisabledColor();
164 static int setMenuTitleBack();
165 static int setMenuTextBack();
166 static int setHightlight();
167 static int setHightlightText();
168 static int setKeyGrab();
169 static int setDoubleClick();
170 static int setIconPosition();
172 static int setClipTitleFont();
173 static int setClipTitleColor();
175 static int setMenuStyle();
178 static int updateUsableArea();
183 * Tables to convert strings to enumeration values.
184 * Values stored are char
188 /* WARNING: sum of length of all value strings must not exceed
189 * this value */
190 #define TOTAL_VALUES_LENGTH 80
195 #define REFRESH_WINDOW_TEXTURES (1<<0)
196 #define REFRESH_MENU_TEXTURE (1<<1)
197 #define REFRESH_MENU_FONT (1<<2)
198 #define REFRESH_MENU_COLOR (1<<3)
199 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
200 #define REFRESH_MENU_TITLE_FONT (1<<5)
201 #define REFRESH_MENU_TITLE_COLOR (1<<6)
202 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
203 #define REFRESH_WINDOW_FONT (1<<8)
204 #define REFRESH_ICON_TILE (1<<9)
205 #define REFRESH_ICON_FONT (1<<10)
206 #define REFRESH_WORKSPACE_BACK (1<<11)
208 #define REFRESH_BUTTON_IMAGES (1<<12)
210 #define REFRESH_ICON_TITLE_COLOR (1<<13)
211 #define REFRESH_ICON_TITLE_BACK (1<<14)
215 static WOptionEnumeration seFocusModes[] = {
216 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
217 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
218 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
219 {NULL, 0, 0}
222 static WOptionEnumeration seColormapModes[] = {
223 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
224 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
225 {NULL, 0, 0}
228 static WOptionEnumeration sePlacements[] = {
229 {"Auto", WPM_SMART, 0}, {"Smart", WPM_SMART, 1},
230 {"Cascade", WPM_CASCADE, 0},
231 {"Random", WPM_RANDOM, 0},
232 {"Manual", WPM_MANUAL, 0},
233 {NULL, 0, 0}
236 static WOptionEnumeration seGeomDisplays[] = {
237 {"Center", WDIS_CENTER, 0},
238 {"Corner", WDIS_TOPLEFT, 0},
239 {"Floating", WDIS_FRAME_CENTER, 0},
240 {"Line", WDIS_NEW, 0},
241 {NULL, 0, 0}
244 static WOptionEnumeration seSpeeds[] = {
245 {"UltraFast", SPEED_ULTRAFAST, 0},
246 {"Fast", SPEED_FAST, 0},
247 {"Medium", SPEED_MEDIUM, 0},
248 {"Slow", SPEED_SLOW, 0},
249 {"UltraSlow", SPEED_ULTRASLOW, 0},
250 {NULL, 0, 0}
253 static WOptionEnumeration seMouseButtons[] = {
254 {"Left", Button1, 0}, {"Button1", Button1, 1},
255 {"Middle", Button2, 0}, {"Button2", Button2, 1},
256 {"Right", Button3, 0}, {"Button3", Button3, 1},
257 {"Button4", Button4, 0},
258 {"Button5", Button5, 0},
259 {NULL, 0, 0}
262 static WOptionEnumeration seIconificationStyles[] = {
263 {"Zoom", WIS_ZOOM, 0},
264 {"Twist", WIS_TWIST, 0},
265 {"Flip", WIS_FLIP, 0},
266 {"None", WIS_NONE, 0},
267 {"random", WIS_RANDOM, 0},
268 {NULL, 0, 0}
271 static WOptionEnumeration seJustifications[] = {
272 {"Left", WTJ_LEFT, 0},
273 {"Center", WTJ_CENTER, 0},
274 {"Right", WTJ_RIGHT, 0},
275 {NULL, 0, 0}
278 static WOptionEnumeration seIconPositions[] = {
279 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
280 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
281 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
282 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
283 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
284 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
285 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
286 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
287 {NULL, 0, 0}
290 static WOptionEnumeration seMenuStyles[] = {
291 {"normal", MS_NORMAL, 0},
292 {"singletexture", MS_SINGLE_TEXTURE, 0},
293 {"flat", MS_FLAT, 0},
294 {NULL, 0, 0}
299 * ALL entries in the tables bellow, NEED to have a default value
300 * defined, and this value needs to be correct.
303 /* these options will only affect the window manager on startup
305 * static defaults can't access the screen data, because it is
306 * created after these defaults are read
308 WDefaultEntry staticOptionList[] = {
310 {"DisableDithering", "NO", NULL,
311 &wPreferences.no_dithering, getBool, NULL
313 {"ColormapSize", "4", NULL,
314 &wPreferences.cmap_size, getInt, NULL
316 /* static by laziness */
317 {"IconSize", "64", NULL,
318 &wPreferences.icon_size, getInt, NULL
320 {"ModifierKey", "Mod1", NULL,
321 &wPreferences.modifier_mask, getModMask, NULL
323 {"DisableWSMouseActions", "NO", NULL,
324 &wPreferences.disable_root_mouse, getBool, NULL
326 {"FocusMode", "manual", seFocusModes,
327 &wPreferences.focus_mode, getEnum, NULL
328 }, /* have a problem when switching from manual to sloppy without restart */
329 {"NewStyle", "NO", NULL,
330 &wPreferences.new_style, getBool, NULL
332 {"DisableDock", "NO", (void*) WM_DOCK,
333 NULL, getBool, setIfDockPresent
335 {"DisableClip", "NO", (void*) WM_CLIP,
336 NULL, getBool, setIfDockPresent
338 {"DisableMiniwindows", "NO", NULL,
339 &wPreferences.disable_miniwindows, getBool, NULL
345 WDefaultEntry optionList[] = {
346 /* dynamic options */
347 {"IconPosition", "blh", seIconPositions,
348 &wPreferences.icon_yard, getEnum, setIconPosition
350 {"IconificationStyle", "Zoom", seIconificationStyles,
351 &wPreferences.iconification_style, getEnum, NULL
353 {"SelectWindowsMouseButton", "Left", seMouseButtons,
354 &wPreferences.select_button, getEnum, NULL
356 {"WindowListMouseButton", "Middle", seMouseButtons,
357 &wPreferences.windowl_button, getEnum, NULL
359 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
360 &wPreferences.menu_button, getEnum, NULL
362 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
363 &wPreferences.pixmap_path, getPathList, NULL
365 {"IconPath", DEF_ICON_PATHS, NULL,
366 &wPreferences.icon_path, getPathList, NULL
368 {"ColormapMode", "auto", seColormapModes,
369 &wPreferences.colormap_mode, getEnum, NULL
371 {"AutoFocus", "NO", NULL,
372 &wPreferences.auto_focus, getBool, NULL
374 {"RaiseDelay", "0", NULL,
375 &wPreferences.raise_delay, getInt, NULL
377 {"CirculateRaise", "NO", NULL,
378 &wPreferences.circ_raise, getBool, NULL
380 {"Superfluous", "NO", NULL,
381 &wPreferences.superfluous, getBool, NULL
383 {"AdvanceToNewWorkspace", "NO", NULL,
384 &wPreferences.ws_advance, getBool, NULL
386 {"CycleWorkspaces", "NO", NULL,
387 &wPreferences.ws_cycle, getBool, NULL
389 {"StickyIcons", "NO", NULL,
390 &wPreferences.sticky_icons, getBool, setStickyIcons
392 {"SaveSessionOnExit", "NO", NULL,
393 &wPreferences.save_session_on_exit, getBool, NULL
395 {"WrapMenus", "NO", NULL,
396 &wPreferences.wrap_menus, getBool, NULL
398 {"ScrollableMenus", "NO", NULL,
399 &wPreferences.scrollable_menus, getBool, NULL
401 {"MenuScrollSpeed", "medium", seSpeeds,
402 &wPreferences.menu_scroll_speed, getEnum, NULL
404 {"IconSlideSpeed", "medium", seSpeeds,
405 &wPreferences.icon_slide_speed, getEnum, NULL
407 {"ShadeSpeed", "medium", seSpeeds,
408 &wPreferences.shade_speed, getEnum, NULL
410 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
411 &wPreferences.dblclick_time, getInt, setDoubleClick,
413 {"AlignSubmenus", "NO", NULL,
414 &wPreferences.align_menus, getBool, NULL
416 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
417 &wPreferences.open_transients_with_parent, getBool, NULL
419 {"WindowPlacement", "auto", sePlacements,
420 &wPreferences.window_placement, getEnum, NULL
422 {"IgnoreFocusClick","NO", NULL,
423 &wPreferences.ignore_focus_click, getBool, NULL
425 {"UseSaveUnders", "NO", NULL,
426 &wPreferences.use_saveunders, getBool, NULL
428 {"OpaqueMove", "NO", NULL,
429 &wPreferences.opaque_move, getBool, NULL
431 {"DisableSound", "NO", NULL,
432 &wPreferences.no_sound, getBool, NULL
434 {"DisableAnimations", "NO", NULL,
435 &wPreferences.no_animations, getBool, NULL
437 {"DontLinkWorkspaces","NO", NULL,
438 &wPreferences.no_autowrap, getBool, NULL
440 {"AutoArrangeIcons", "NO", NULL,
441 &wPreferences.auto_arrange_icons, getBool, NULL
443 {"NoWindowOverDock", "NO", NULL,
444 &wPreferences.no_window_over_dock, getBool, updateUsableArea
446 {"NoWindowOverIcons", "NO", NULL,
447 &wPreferences.no_window_over_icons, getBool, updateUsableArea
449 {"WindowPlaceOrigin", "(0, 0)", NULL,
450 &wPreferences.window_place_origin, getCoord, NULL
452 {"ResizeDisplay", "corner", seGeomDisplays,
453 &wPreferences.size_display, getEnum, NULL
455 {"MoveDisplay", "corner", seGeomDisplays,
456 &wPreferences.move_display, getEnum, NULL
458 {"DontConfirmKill", "NO", NULL,
459 &wPreferences.dont_confirm_kill, getBool,NULL
461 {"WindowTitleBalloons", "NO", NULL,
462 &wPreferences.window_balloon, getBool, NULL
464 {"MiniwindowTitleBalloons", "NO", NULL,
465 &wPreferences.miniwin_balloon,getBool, NULL
467 {"AppIconBalloons", "NO", NULL,
468 &wPreferences.appicon_balloon,getBool, NULL
470 {"EdgeResistance", "30", NULL,
471 &wPreferences.edge_resistance,getInt, NULL
473 {"DisableBlinking", "NO", NULL,
474 &wPreferences.dont_blink, getBool, NULL
476 #ifdef WEENDOZE_CYCLE
477 {"WindozeCycling","NO", NULL,
478 &wPreferences.windoze_cycling, getBool, NULL
480 {"PopupSwitchMenu","YES", NULL,
481 &wPreferences.popup_switchmenu, getBool, NULL
483 #endif /* WEENDOZE_CYCLE */
484 /* style options */
485 {"MenuStyle", "normal", seMenuStyles,
486 &wPreferences.menu_style, getEnum, setMenuStyle
488 {"WidgetColor", "(solid, gray)", NULL,
489 NULL, getTexture, setWidgetColor,
491 {"WorkspaceSpecificBack","()", NULL,
492 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
494 /* WorkspaceBack must come after WorkspaceSpecificBack or
495 * WorkspaceBack wont know WorkspaceSpecificBack was also
496 * specified and 2 copies of wmsetbg will be launched */
497 {"WorkspaceBack", "(solid, black)", NULL,
498 NULL, getWSBackground,setWorkspaceBack
500 {"IconBack", "(solid, gray)", NULL,
501 NULL, getTexture, setIconTile
503 {"TitleJustify", "center", seJustifications,
504 &wPreferences.title_justification, getEnum, setJustify
506 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
507 NULL, getFont, setWinTitleFont,
509 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
510 NULL, getFont, setMenuTitleFont
512 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
513 NULL, getFont, setMenuTextFont
515 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
516 NULL, getFont, setIconTitleFont
518 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
519 NULL, getFont, setClipTitleFont
521 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
522 NULL, getFont, setDisplayFont
524 {"HighlightColor", "white", NULL,
525 NULL, getColor, setHightlight
527 {"HighlightTextColor", "black", NULL,
528 NULL, getColor, setHightlightText
530 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
531 NULL, getColor, setClipTitleColor
533 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
534 NULL, getColor, setClipTitleColor
536 {"FTitleColor", "white", (void*)WS_FOCUSED,
537 NULL, getColor, setWTitleColor
539 {"PTitleColor", "white", (void*)WS_PFOCUSED,
540 NULL, getColor, setWTitleColor
542 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
543 NULL, getColor, setWTitleColor
545 {"FTitleBack", "(solid, black)", NULL,
546 NULL, getTexture, setFTitleBack
548 {"PTitleBack", "(solid, \"#616161\")", NULL,
549 NULL, getTexture, setPTitleBack
551 {"UTitleBack", "(solid, gray)", NULL,
552 NULL, getTexture, setUTitleBack
554 {"ResizebarBack", "(solid, gray)", NULL,
555 NULL, getTexture, setResizebarBack
557 {"MenuTitleColor", "white", NULL,
558 NULL, getColor, setMenuTitleColor
560 {"MenuTextColor", "black", NULL,
561 NULL, getColor, setMenuTextColor
563 {"MenuDisabledColor", "\"#616161\"", NULL,
564 NULL, getColor, setMenuDisabledColor
566 {"MenuTitleBack", "(solid, black)", NULL,
567 NULL, getTexture, setMenuTitleBack
569 {"MenuTextBack", "(solid, gray)", NULL,
570 NULL, getTexture, setMenuTextBack
572 {"IconTitleColor", "white", NULL,
573 NULL, getColor, setIconTitleColor
575 {"IconTitleBack", "black", NULL,
576 NULL, getColor, setIconTitleBack
578 /* keybindings */
579 #ifndef LITE
580 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
581 NULL, getKeybind, setKeyGrab
583 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
584 NULL, getKeybind, setKeyGrab
586 #endif /* LITE */
587 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
588 NULL, getKeybind, setKeyGrab
590 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
591 NULL, getKeybind, setKeyGrab
593 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
594 NULL, getKeybind, setKeyGrab
596 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
597 NULL, getKeybind, setKeyGrab
599 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
600 NULL, getKeybind, setKeyGrab
602 {"HideKey", "None", (void*)WKBD_HIDE,
603 NULL, getKeybind, setKeyGrab
605 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
606 NULL, getKeybind, setKeyGrab
608 {"CloseKey", "None", (void*)WKBD_CLOSE,
609 NULL, getKeybind, setKeyGrab
611 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
612 NULL, getKeybind, setKeyGrab
614 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
615 NULL, getKeybind, setKeyGrab
617 {"RaiseKey", "Meta+Up", (void*)WKBD_RAISE,
618 NULL, getKeybind, setKeyGrab
620 {"LowerKey", "Meta+Down", (void*)WKBD_LOWER,
621 NULL, getKeybind, setKeyGrab
623 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
624 NULL, getKeybind, setKeyGrab
626 {"ShadeKey", "None", (void*)WKBD_SHADE,
627 NULL, getKeybind, setKeyGrab
629 {"SelectKey", "None", (void*)WKBD_SELECT,
630 NULL, getKeybind, setKeyGrab
632 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
633 NULL, getKeybind, setKeyGrab
635 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
636 NULL, getKeybind, setKeyGrab
638 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
639 NULL, getKeybind, setKeyGrab
641 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
642 NULL, getKeybind, setKeyGrab
644 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
645 NULL, getKeybind, setKeyGrab
647 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
648 NULL, getKeybind, setKeyGrab
650 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
651 NULL, getKeybind, setKeyGrab
653 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
654 NULL, getKeybind, setKeyGrab
656 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
657 NULL, getKeybind, setKeyGrab
659 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
660 NULL, getKeybind, setKeyGrab
662 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
663 NULL, getKeybind, setKeyGrab
665 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
666 NULL, getKeybind, setKeyGrab
668 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
669 NULL, getKeybind, setKeyGrab
671 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
672 NULL, getKeybind, setKeyGrab
674 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
675 NULL, getKeybind, setKeyGrab
677 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
678 NULL, getKeybind, setKeyGrab
680 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
681 NULL, getKeybind, setKeyGrab
683 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
684 NULL, getKeybind, setKeyGrab
686 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
687 NULL, getKeybind, setKeyGrab
689 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
690 NULL, getKeybind, setKeyGrab
692 #ifdef EXTEND_WINDOWSHORTCUT
693 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
694 NULL, getKeybind, setKeyGrab
696 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
697 NULL, getKeybind, setKeyGrab
699 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
700 NULL, getKeybind, setKeyGrab
702 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
703 NULL, getKeybind, setKeyGrab
705 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
706 NULL, getKeybind, setKeyGrab
708 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
709 NULL, getKeybind, setKeyGrab
711 #endif /* EXTEND_WINDOWSHORTCUT */
713 #ifdef KEEP_XKB_LOCK_STATUS
714 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
715 NULL, getKeybind, setKeyGrab
717 {"KbdModeLock", "NO", NULL,
718 &wPreferences.modelock, getBool, NULL
720 #endif /* KEEP_XKB_LOCK_STATUS */
721 #ifdef TITLE_TEXT_SHADOW
722 ,{"FShadowColor", "black", (void*)WS_SFOCUSED,
723 NULL, getColor, setWTitleColor
725 {"PShadowColor", "black", (void*)WS_SPFOCUSED,
726 NULL, getColor, setWTitleColor
728 {"UShadowColor", "grey50", (void*)WS_SUNFOCUSED,
729 NULL, getColor, setWTitleColor
731 {"MShadowColor", "black", (void*)WS_SMENU,
732 NULL, getColor, setMenuTitleColor
734 {"Shadow", "Yes", NULL,
735 &wPreferences.title_shadow, getBool, setJustify
737 #endif /* TITLE_TEXT_SHADOW */
741 #if 0
742 static void rereadDefaults(void);
743 #endif
745 #if 0
746 static void
747 rereadDefaults(void)
749 /* must defer the update because accessing X data from a
750 * signal handler can mess up Xlib */
753 #endif
755 static void
756 initDefaults()
758 int i;
759 WDefaultEntry *entry;
761 PLSetStringCmpHook(StringCompareHook);
763 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
764 entry = &optionList[i];
766 entry->plkey = PLMakeString(entry->key);
767 if (entry->default_value)
768 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
769 else
770 entry->plvalue = NULL;
773 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
774 entry = &staticOptionList[i];
776 entry->plkey = PLMakeString(entry->key);
777 if (entry->default_value)
778 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
779 else
780 entry->plvalue = NULL;
784 wDomainName = PLMakeString(WMDOMAIN_NAME);
785 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
787 PLRegister(wDomainName, rereadDefaults);
788 PLRegister(wAttributeDomainName, rereadDefaults);
795 #if 0
796 proplist_t
797 wDefaultsInit(int screen_number)
799 static int defaults_inited = 0;
800 proplist_t dict;
802 if (!defaults_inited) {
803 initDefaults();
806 dict = PLGetDomain(wDomainName);
807 if (!dict) {
808 wwarning(_("could not read domain \"%s\" from defaults database"),
809 PLGetString(wDomainName));
812 return dict;
814 #endif
817 void
818 wDefaultsDestroyDomain(WDDomain *domain)
820 if (domain->dictionary)
821 PLRelease(domain->dictionary);
822 free(domain->path);
823 free(domain);
827 WDDomain*
828 wDefaultsInitDomain(char *domain, Bool requireDictionary)
830 WDDomain *db;
831 struct stat stbuf;
832 static int inited = 0;
833 char path[PATH_MAX];
834 char *the_path;
835 proplist_t shared_dict=NULL;
837 if (!inited) {
838 inited = 1;
839 initDefaults();
842 db = wmalloc(sizeof(WDDomain));
843 memset(db, 0, sizeof(WDDomain));
844 db->domain_name = domain;
845 db->path = wdefaultspathfordomain(domain);
846 the_path = db->path;
848 if (the_path && stat(the_path, &stbuf)>=0) {
849 db->dictionary = ReadProplistFromFile(the_path);
850 if (db->dictionary) {
851 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
852 PLRelease(db->dictionary);
853 db->dictionary = NULL;
854 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
855 domain, the_path);
857 db->timestamp = stbuf.st_mtime;
858 } else {
859 wwarning(_("could not load domain %s from user defaults database"),
860 domain);
864 /* global system dictionary */
865 sprintf(path, "%s/%s", SYSCONFDIR, domain);
866 if (stat(path, &stbuf)>=0) {
867 shared_dict = ReadProplistFromFile(path);
868 if (shared_dict) {
869 if (requireDictionary && !PLIsDictionary(shared_dict)) {
870 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
871 domain, path);
872 PLRelease(shared_dict);
873 shared_dict = NULL;
874 } else {
875 if (db->dictionary && PLIsDictionary(shared_dict) &&
876 PLIsDictionary(db->dictionary)) {
877 PLMergeDictionaries(shared_dict, db->dictionary);
878 PLRelease(db->dictionary);
879 db->dictionary = shared_dict;
880 if (stbuf.st_mtime > db->timestamp)
881 db->timestamp = stbuf.st_mtime;
882 } else if (!db->dictionary) {
883 db->dictionary = shared_dict;
884 if (stbuf.st_mtime > db->timestamp)
885 db->timestamp = stbuf.st_mtime;
888 } else {
889 wwarning(_("could not load domain %s from global defaults database"),
890 domain);
894 /* set to save it in user's directory, no matter from where it was read */
895 if (db->dictionary) {
896 proplist_t tmp = PLMakeString(db->path);
898 PLSetFilename(db->dictionary, tmp);
899 PLRelease(tmp);
902 return db;
906 void
907 wReadStaticDefaults(proplist_t dict)
909 proplist_t plvalue;
910 WDefaultEntry *entry;
911 int i;
912 void *tdata;
915 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
916 entry = &staticOptionList[i];
918 if (dict)
919 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
920 else
921 plvalue = NULL;
923 if (!plvalue) {
924 /* no default in the DB. Use builtin default */
925 plvalue = entry->plvalue;
928 if (plvalue) {
929 /* convert data */
930 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
931 if (entry->update) {
932 (*entry->update)(NULL, entry, tdata, entry->extra_data);
939 void
940 wDefaultsCheckDomains(void *foo)
942 WScreen *scr;
943 struct stat stbuf;
944 proplist_t dict;
945 int i;
946 char path[PATH_MAX];
948 #ifdef HEARTBEAT
949 puts("Checking domains...");
950 #endif
951 if (stat(WDWindowMaker->path, &stbuf)>=0
952 && WDWindowMaker->timestamp < stbuf.st_mtime) {
953 proplist_t shared_dict = NULL;
954 #ifdef HEARTBEAT
955 puts("Checking WindowMaker domain");
956 #endif
957 WDWindowMaker->timestamp = stbuf.st_mtime;
959 /* global dictionary */
960 sprintf(path, "%s/WindowMaker", SYSCONFDIR);
961 if (stat(path, &stbuf)>=0) {
962 shared_dict = ReadProplistFromFile(path);
963 if (shared_dict && !PLIsDictionary(shared_dict)) {
964 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
965 "WindowMaker", path);
966 PLRelease(shared_dict);
967 shared_dict = NULL;
968 } else if (!shared_dict) {
969 wwarning(_("could not load domain %s from global defaults database"),
970 "WindowMaker");
973 /* user dictionary */
974 dict = ReadProplistFromFile(WDWindowMaker->path);
975 if (dict) {
976 if (!PLIsDictionary(dict)) {
977 PLRelease(dict);
978 dict = NULL;
979 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
980 "WindowMaker", WDWindowMaker->path);
981 } else {
982 if (shared_dict) {
983 PLSetFilename(shared_dict, PLGetFilename(dict));
984 PLMergeDictionaries(shared_dict, dict);
985 PLRelease(dict);
986 dict = shared_dict;
987 shared_dict = NULL;
989 for (i=0; i<wScreenCount; i++) {
990 scr = wScreenWithNumber(i);
991 if (scr)
992 wReadDefaults(scr, dict);
994 if (WDWindowMaker->dictionary) {
995 PLRelease(WDWindowMaker->dictionary);
997 WDWindowMaker->dictionary = dict;
999 } else {
1000 wwarning(_("could not load domain %s from user defaults database"),
1001 "WindowMaker");
1003 if (shared_dict) {
1004 PLRelease(shared_dict);
1008 if (stat(WDWindowAttributes->path, &stbuf)>=0
1009 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1010 #ifdef HEARTBEAT
1011 puts("Checking WMWindowAttributes domain");
1012 #endif
1013 dict = ReadProplistFromFile(WDWindowAttributes->path);
1014 if (dict) {
1015 if (!PLIsDictionary(dict)) {
1016 PLRelease(dict);
1017 dict = NULL;
1018 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1019 "WMWindowAttributes", WDWindowAttributes->path);
1020 } else {
1021 if (WDWindowAttributes->dictionary)
1022 PLRelease(WDWindowAttributes->dictionary);
1023 WDWindowAttributes->dictionary = dict;
1024 for (i=0; i<wScreenCount; i++) {
1025 scr = wScreenWithNumber(i);
1026 if (scr)
1027 wDefaultUpdateIcons(scr);
1030 } else {
1031 wwarning(_("could not load domain %s from user defaults database"),
1032 "WMWindowAttributes");
1034 WDWindowAttributes->timestamp = stbuf.st_mtime;
1037 #ifndef LITE
1038 if (stat(WDRootMenu->path, &stbuf)>=0
1039 && WDRootMenu->timestamp < stbuf.st_mtime) {
1040 dict = ReadProplistFromFile(WDRootMenu->path);
1041 #ifdef HEARTBEAT
1042 puts("Checking WMRootMenu domain");
1043 #endif
1044 if (dict) {
1045 if (!PLIsArray(dict) && !PLIsString(dict)) {
1046 PLRelease(dict);
1047 dict = NULL;
1048 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1049 "WMRootMenu", WDRootMenu->path);
1050 } else {
1051 if (WDRootMenu->dictionary) {
1052 PLRelease(WDRootMenu->dictionary);
1054 WDRootMenu->dictionary = dict;
1056 } else {
1057 wwarning(_("could not load domain %s from user defaults database"),
1058 "WMRootMenu");
1060 WDRootMenu->timestamp = stbuf.st_mtime;
1062 #endif /* !LITE */
1064 if (!foo)
1065 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1069 void
1070 wReadDefaults(WScreen *scr, proplist_t new_dict)
1072 proplist_t plvalue, old_value;
1073 WDefaultEntry *entry;
1074 int i, must_update;
1075 int needs_refresh;
1076 void *tdata;
1077 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1078 ? WDWindowMaker->dictionary : NULL);
1080 must_update = 0;
1082 needs_refresh = 0;
1084 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1085 entry = &optionList[i];
1087 if (new_dict)
1088 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1089 else
1090 plvalue = NULL;
1092 if (!old_dict)
1093 old_value = NULL;
1094 else
1095 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1098 if (!plvalue && !old_value) {
1099 /* no default in the DB. Use builtin default */
1100 plvalue = entry->plvalue;
1101 if (plvalue && new_dict) {
1102 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1103 must_update = 1;
1105 } else if (!plvalue) {
1106 /* value was deleted from DB. Keep current value */
1107 continue;
1108 } else if (!old_value) {
1109 /* set value for the 1st time */
1110 } else if (!PLIsEqual(plvalue, old_value)) {
1111 /* value has changed */
1112 } else {
1113 /* value was not changed since last time */
1114 continue;
1117 if (plvalue) {
1118 #ifdef DEBUG
1119 printf("Updating %s to %s\n", entry->key, PLGetDescription(plvalue));
1120 #endif
1121 /* convert data */
1122 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1123 if (entry->update) {
1124 needs_refresh |=
1125 (*entry->update)(scr, entry, tdata, entry->extra_data);
1131 if (needs_refresh!=0 && !scr->flags.startup) {
1132 int foo;
1134 foo = 0;
1135 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1136 foo |= WTextureSettings;
1137 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1138 foo |= WFontSettings;
1139 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1140 foo |= WColorSettings;
1141 if (foo)
1142 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1143 (void*)foo);
1145 foo = 0;
1146 if (needs_refresh & REFRESH_MENU_TEXTURE)
1147 foo |= WTextureSettings;
1148 if (needs_refresh & REFRESH_MENU_FONT)
1149 foo |= WFontSettings;
1150 if (needs_refresh & REFRESH_MENU_COLOR)
1151 foo |= WColorSettings;
1152 if (foo)
1153 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1154 (void*)foo);
1156 foo = 0;
1157 if (needs_refresh & REFRESH_WINDOW_FONT) {
1158 foo |= WFontSettings;
1160 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1161 foo |= WTextureSettings;
1163 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1164 foo |= WColorSettings;
1166 if (foo)
1167 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1168 (void*)foo);
1170 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1171 foo = 0;
1172 if (needs_refresh & REFRESH_ICON_FONT) {
1173 foo |= WFontSettings;
1175 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1176 foo |= WTextureSettings;
1178 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1179 foo |= WTextureSettings;
1181 if (foo)
1182 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1183 (void*)foo);
1185 if (needs_refresh & REFRESH_ICON_TILE)
1186 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1191 void
1192 wDefaultUpdateIcons(WScreen *scr)
1194 WAppIcon *aicon = scr->app_icon_list;
1195 WWindow *wwin = scr->focused_window;
1196 char *file;
1198 while(aicon) {
1199 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1200 False);
1201 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1202 || (file && !aicon->icon->file)) {
1203 RImage *new_image;
1205 if (aicon->icon->file)
1206 free(aicon->icon->file);
1207 aicon->icon->file = wstrdup(file);
1209 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1210 aicon->wm_class);
1211 if (new_image) {
1212 wIconChangeImage(aicon->icon, new_image);
1213 wAppIconPaint(aicon);
1216 aicon = aicon->next;
1219 if (!wPreferences.flags.noclip)
1220 wClipIconPaint(scr->clip_icon);
1222 while (wwin) {
1223 if (wwin->icon && wwin->flags.miniaturized) {
1224 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1225 False);
1226 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1227 || (file && !wwin->icon->file)) {
1228 RImage *new_image;
1230 if (wwin->icon->file)
1231 free(wwin->icon->file);
1232 wwin->icon->file = wstrdup(file);
1234 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1235 wwin->wm_class);
1236 if (new_image)
1237 wIconChangeImage(wwin->icon, new_image);
1240 wwin = wwin->prev;
1245 /* --------------------------- Local ----------------------- */
1247 #define STRINGP(x) if (!PLIsString(value)) { \
1248 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1249 entry->key, x); \
1250 return False; }
1254 static int
1255 string2index(proplist_t key, proplist_t val, proplist_t def,
1256 WOptionEnumeration *values)
1258 char *str;
1259 WOptionEnumeration *v;
1260 char buffer[TOTAL_VALUES_LENGTH];
1262 if (PLIsString(val) && (str = PLGetString(val))) {
1263 for (v=values; v->string!=NULL; v++) {
1264 if (strcasecmp(v->string, str)==0)
1265 return v->value;
1269 buffer[0] = 0;
1270 for (v=values; v->string!=NULL; v++) {
1271 if (!v->is_alias) {
1272 if (buffer[0]!=0)
1273 strcat(buffer, ", ");
1274 strcat(buffer, v->string);
1277 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1278 PLGetString(key), buffer);
1280 if (def) {
1281 return string2index(key, val, NULL, values);
1284 return -1;
1291 * value - is the value in the defaults DB
1292 * addr - is the address to store the data
1293 * ret - is the address to store a pointer to a temporary buffer. ret
1294 * must not be freed and is used by the set functions
1296 static int
1297 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1298 void **ret)
1300 static char data;
1301 char *val;
1302 int second_pass=0;
1304 STRINGP("Boolean");
1306 val = PLGetString(value);
1308 again:
1309 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1310 || strcasecmp(val, "YES")==0) {
1312 data = 1;
1313 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1314 || strcasecmp(val, "NO")==0) {
1315 data = 0;
1316 } else {
1317 int i;
1318 if (sscanf(val, "%i", &i)==1) {
1319 if (i!=0)
1320 data = 1;
1321 else
1322 data = 0;
1323 } else {
1324 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1325 val, entry->key);
1326 if (second_pass==0) {
1327 val = PLGetString(entry->plvalue);
1328 second_pass = 1;
1329 wwarning(_("using default \"%s\" instead"), val);
1330 goto again;
1332 return False;
1336 if (ret)
1337 *ret = &data;
1339 if (addr) {
1340 *(char*)addr = data;
1343 return True;
1347 static int
1348 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1349 void **ret)
1351 static int data;
1352 char *val;
1355 STRINGP("Integer");
1357 val = PLGetString(value);
1359 if (sscanf(val, "%i", &data)!=1) {
1360 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1361 val, entry->key);
1362 val = PLGetString(entry->plvalue);
1363 wwarning(_("using default \"%s\" instead"), val);
1364 if (sscanf(val, "%i", &data)!=1) {
1365 return False;
1369 if (ret)
1370 *ret = &data;
1372 if (addr) {
1373 *(int*)addr = data;
1375 return True;
1379 static int
1380 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1381 void **ret)
1383 static WCoord data;
1384 char *val_x, *val_y;
1385 int nelem, changed=0;
1386 proplist_t elem_x, elem_y;
1388 again:
1389 if (!PLIsArray(value)) {
1390 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1391 entry->key, "Coordinate");
1392 if (changed==0) {
1393 value = entry->plvalue;
1394 changed = 1;
1395 wwarning(_("using default \"%s\" instead"), entry->default_value);
1396 goto again;
1398 return False;
1401 nelem = PLGetNumberOfElements(value);
1402 if (nelem != 2) {
1403 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1404 entry->key);
1405 if (changed==0) {
1406 value = entry->plvalue;
1407 changed = 1;
1408 wwarning(_("using default \"%s\" instead"), entry->default_value);
1409 goto again;
1411 return False;
1414 elem_x = PLGetArrayElement(value, 0);
1415 elem_y = PLGetArrayElement(value, 1);
1417 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1418 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1419 entry->key);
1420 if (changed==0) {
1421 value = entry->plvalue;
1422 changed = 1;
1423 wwarning(_("using default \"%s\" instead"), entry->default_value);
1424 goto again;
1426 return False;
1429 val_x = PLGetString(elem_x);
1430 val_y = PLGetString(elem_y);
1432 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1433 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1434 if (changed==0) {
1435 value = entry->plvalue;
1436 changed = 1;
1437 wwarning(_("using default \"%s\" instead"), entry->default_value);
1438 goto again;
1440 return False;
1443 if (data.x < 0)
1444 data.x = 0;
1445 else if (data.x > scr->scr_width/3)
1446 data.x = scr->scr_width/3;
1447 if (data.y < 0)
1448 data.y = 0;
1449 else if (data.y > scr->scr_height/3)
1450 data.y = scr->scr_height/3;
1452 if (ret)
1453 *ret = &data;
1455 if (addr) {
1456 *(WCoord*)addr = data;
1459 return True;
1463 #if 0
1464 /* This function is not used at the moment. */
1465 static int
1466 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1467 void **ret)
1469 static char *data;
1471 STRINGP("String");
1473 data = PLGetString(value);
1475 if (!data) {
1476 data = PLGetString(entry->plvalue);
1477 if (!data)
1478 return False;
1481 if (ret)
1482 *ret = &data;
1484 if (addr)
1485 *(char**)addr = wstrdup(data);
1487 return True;
1489 #endif
1492 static int
1493 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1494 void **ret)
1496 static char *data;
1497 int i, count, len;
1498 char *ptr;
1499 proplist_t d;
1500 int changed=0;
1502 again:
1503 if (!PLIsArray(value)) {
1504 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1505 entry->key, "an array of paths");
1506 if (changed==0) {
1507 value = entry->plvalue;
1508 changed = 1;
1509 wwarning(_("using default \"%s\" instead"), entry->default_value);
1510 goto again;
1512 return False;
1515 i = 0;
1516 count = PLGetNumberOfElements(value);
1517 if (count < 1) {
1518 if (changed==0) {
1519 value = entry->plvalue;
1520 changed = 1;
1521 wwarning(_("using default \"%s\" instead"), entry->default_value);
1522 goto again;
1524 return False;
1527 len = 0;
1528 for (i=0; i<count; i++) {
1529 d = PLGetArrayElement(value, i);
1530 if (!d || !PLIsString(d)) {
1531 count = i;
1532 break;
1534 len += strlen(PLGetString(d))+1;
1537 ptr = data = wmalloc(len+1);
1539 for (i=0; i<count; i++) {
1540 d = PLGetArrayElement(value, i);
1541 if (!d || !PLIsString(d)) {
1542 break;
1544 strcpy(ptr, PLGetString(d));
1545 ptr += strlen(PLGetString(d));
1546 *ptr = ':';
1547 ptr++;
1549 ptr--; *(ptr--) = 0;
1551 if (*(char**)addr!=NULL) {
1552 free(*(char**)addr);
1554 *(char**)addr = data;
1556 return True;
1560 static int
1561 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1562 void **ret)
1564 static signed char data;
1566 data = string2index(entry->plkey, value, entry->default_value,
1567 (WOptionEnumeration*)entry->extra_data);
1568 if (data < 0)
1569 return False;
1571 if (ret)
1572 *ret = &data;
1574 if (addr)
1575 *(signed char*)addr = data;
1577 return True;
1583 * (solid <color>)
1584 * (hgradient <color> <color>)
1585 * (vgradient <color> <color>)
1586 * (dgradient <color> <color>)
1587 * (mhgradient <color> <color> ...)
1588 * (mvgradient <color> <color> ...)
1589 * (tpixmap <file> <color>)
1590 * (spixmap <file> <color>)
1591 * (cpixmap <file> <color>)
1592 * (thgradient <file> <opaqueness> <color> <color>)
1593 * (tvgradient <file> <opaqueness> <color> <color>)
1594 * (tdgradient <file> <opaqueness> <color> <color>)
1595 * (function <lib> <function> ...)
1598 static WTexture*
1599 parse_texture(WScreen *scr, proplist_t pl)
1601 proplist_t elem;
1602 char *val;
1603 int nelem;
1604 WTexture *texture=NULL;
1606 nelem = PLGetNumberOfElements(pl);
1607 if (nelem < 1)
1608 return NULL;
1611 elem = PLGetArrayElement(pl, 0);
1612 if (!elem || !PLIsString(elem))
1613 return NULL;
1614 val = PLGetString(elem);
1617 if (strcasecmp(val, "solid")==0) {
1618 XColor color;
1620 if (nelem != 2)
1621 return NULL;
1623 /* get color */
1625 elem = PLGetArrayElement(pl, 1);
1626 if (!elem || !PLIsString(elem))
1627 return NULL;
1628 val = PLGetString(elem);
1630 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1631 wwarning(_("\"%s\" is not a valid color name"), val);
1632 return NULL;
1635 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1636 } else if (strcasecmp(val, "dgradient")==0
1637 || strcasecmp(val, "vgradient")==0
1638 || strcasecmp(val, "hgradient")==0) {
1639 RColor color1, color2;
1640 XColor xcolor;
1641 int type;
1643 if (nelem != 3) {
1644 wwarning(_("bad number of arguments in gradient specification"));
1645 return NULL;
1648 if (val[0]=='d' || val[0]=='D')
1649 type = WTEX_DGRADIENT;
1650 else if (val[0]=='h' || val[0]=='H')
1651 type = WTEX_HGRADIENT;
1652 else
1653 type = WTEX_VGRADIENT;
1656 /* get from color */
1657 elem = PLGetArrayElement(pl, 1);
1658 if (!elem || !PLIsString(elem))
1659 return NULL;
1660 val = PLGetString(elem);
1662 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1663 wwarning(_("\"%s\" is not a valid color name"), val);
1664 return NULL;
1666 color1.alpha = 255;
1667 color1.red = xcolor.red >> 8;
1668 color1.green = xcolor.green >> 8;
1669 color1.blue = xcolor.blue >> 8;
1671 /* get to color */
1672 elem = PLGetArrayElement(pl, 2);
1673 if (!elem || !PLIsString(elem)) {
1674 return NULL;
1676 val = PLGetString(elem);
1678 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1679 wwarning(_("\"%s\" is not a valid color name"), val);
1680 return NULL;
1682 color2.alpha = 255;
1683 color2.red = xcolor.red >> 8;
1684 color2.green = xcolor.green >> 8;
1685 color2.blue = xcolor.blue >> 8;
1687 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1689 } else if (strcasecmp(val, "mhgradient")==0
1690 || strcasecmp(val, "mvgradient")==0
1691 || strcasecmp(val, "mdgradient")==0) {
1692 XColor color;
1693 RColor **colors;
1694 int i, count;
1695 int type;
1697 if (nelem < 3) {
1698 wwarning(_("too few arguments in multicolor gradient specification"));
1699 return NULL;
1702 if (val[1]=='h' || val[1]=='H')
1703 type = WTEX_MHGRADIENT;
1704 else if (val[1]=='v' || val[1]=='V')
1705 type = WTEX_MVGRADIENT;
1706 else
1707 type = WTEX_MDGRADIENT;
1709 count = nelem-1;
1711 colors = wmalloc(sizeof(RColor*)*(count+1));
1713 for (i=0; i<count; i++) {
1714 elem = PLGetArrayElement(pl, i+1);
1715 if (!elem || !PLIsString(elem)) {
1716 for (--i; i>=0; --i) {
1717 free(colors[i]);
1719 free(colors);
1720 return NULL;
1722 val = PLGetString(elem);
1724 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1725 wwarning(_("\"%s\" is not a valid color name"), val);
1726 for (--i; i>=0; --i) {
1727 free(colors[i]);
1729 free(colors);
1730 return NULL;
1731 } else {
1732 colors[i] = wmalloc(sizeof(RColor));
1733 colors[i]->red = color.red >> 8;
1734 colors[i]->green = color.green >> 8;
1735 colors[i]->blue = color.blue >> 8;
1738 colors[i] = NULL;
1740 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1741 } else if (strcasecmp(val, "spixmap")==0 ||
1742 strcasecmp(val, "cpixmap")==0 ||
1743 strcasecmp(val, "tpixmap")==0) {
1744 XColor color;
1745 int type;
1747 if (nelem != 3)
1748 return NULL;
1750 if (val[0] == 's' || val[0] == 'S')
1751 type = WTP_SCALE;
1752 else if (val[0] == 'c' || val[0] == 'C')
1753 type = WTP_CENTER;
1754 else
1755 type = WTP_TILE;
1757 /* get color */
1758 elem = PLGetArrayElement(pl, 2);
1759 if (!elem || !PLIsString(elem)) {
1760 return NULL;
1762 val = PLGetString(elem);
1764 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1765 wwarning(_("\"%s\" is not a valid color name"), val);
1766 return NULL;
1769 /* file name */
1770 elem = PLGetArrayElement(pl, 1);
1771 if (!elem || !PLIsString(elem))
1772 return NULL;
1773 val = PLGetString(elem);
1775 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1776 } else if (strcasecmp(val, "thgradient")==0
1777 || strcasecmp(val, "tvgradient")==0
1778 || strcasecmp(val, "tdgradient")==0) {
1779 RColor color1, color2;
1780 XColor xcolor;
1781 int opacity;
1782 int style;
1784 if (val[1]=='h' || val[1]=='H')
1785 style = WTEX_THGRADIENT;
1786 else if (val[1]=='v' || val[1]=='V')
1787 style = WTEX_TVGRADIENT;
1788 else
1789 style = WTEX_TDGRADIENT;
1791 if (nelem != 5) {
1792 wwarning(_("bad number of arguments in textured gradient specification"));
1793 return NULL;
1796 /* get from color */
1797 elem = PLGetArrayElement(pl, 3);
1798 if (!elem || !PLIsString(elem))
1799 return NULL;
1800 val = PLGetString(elem);
1802 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1803 wwarning(_("\"%s\" is not a valid color name"), val);
1804 return NULL;
1806 color1.alpha = 255;
1807 color1.red = xcolor.red >> 8;
1808 color1.green = xcolor.green >> 8;
1809 color1.blue = xcolor.blue >> 8;
1811 /* get to color */
1812 elem = PLGetArrayElement(pl, 4);
1813 if (!elem || !PLIsString(elem)) {
1814 return NULL;
1816 val = PLGetString(elem);
1818 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1819 wwarning(_("\"%s\" is not a valid color name"), val);
1820 return NULL;
1822 color2.alpha = 255;
1823 color2.red = xcolor.red >> 8;
1824 color2.green = xcolor.green >> 8;
1825 color2.blue = xcolor.blue >> 8;
1827 /* get opacity */
1828 elem = PLGetArrayElement(pl, 2);
1829 if (!elem || !PLIsString(elem))
1830 opacity = 128;
1831 else
1832 val = PLGetString(elem);
1834 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1835 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1836 opacity = 128;
1839 /* get file name */
1840 elem = PLGetArrayElement(pl, 1);
1841 if (!elem || !PLIsString(elem))
1842 return NULL;
1843 val = PLGetString(elem);
1845 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1846 val, opacity);
1848 #ifdef TEXTURE_PLUGIN
1849 else if (strcasecmp(val, "function")==0) {
1850 WTexFunction *function;
1851 void (*initFunc) (Display *, Colormap);
1852 char *lib, *func, **argv;
1853 int i, argc;
1855 if (nelem < 3)
1856 return NULL;
1858 /* get the library name */
1859 elem = PLGetArrayElement(pl, 1);
1860 if (!elem || !PLIsString(elem)) {
1861 return NULL;
1863 lib = PLGetString(elem);
1865 /* get the function name */
1866 elem = PLGetArrayElement(pl, 2);
1867 if (!elem || !PLIsString(elem)) {
1868 return NULL;
1870 func = PLGetString(elem);
1872 argc = nelem - 2;
1873 argv = (char **)wmalloc(argc * sizeof(char *));
1875 /* get the parameters */
1876 argv[0] = wstrdup(func);
1877 for (i = 0; i < argc - 1; i++) {
1878 elem = PLGetArrayElement(pl, 3 + i);
1879 if (!elem || !PLIsString(elem)) {
1880 free(argv);
1882 return NULL;
1884 argv[i+1] = wstrdup(PLGetString(elem));
1887 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1889 #ifdef HAVE_DLFCN_H
1890 if (function) {
1891 initFunc = dlsym(function->handle, "initWindowMaker");
1892 if (initFunc) {
1893 initFunc(dpy, scr->w_colormap);
1894 } else {
1895 wwarning(_("could not initialize library %s"), lib);
1897 } else {
1898 wwarning(_("could not find function %s::%s"), lib, func);
1900 #endif /* HAVE_DLFCN_H */
1901 texture = (WTexture*)function;
1903 #endif /* TEXTURE_PLUGIN */
1904 else {
1905 wwarning(_("invalid texture type %s"), val);
1906 return NULL;
1908 return texture;
1913 static int
1914 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1915 void **ret)
1917 static WTexture *texture;
1918 int changed=0;
1920 again:
1921 if (!PLIsArray(value)) {
1922 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1923 entry->key, "Texture");
1924 if (changed==0) {
1925 value = entry->plvalue;
1926 changed = 1;
1927 wwarning(_("using default \"%s\" instead"), entry->default_value);
1928 goto again;
1930 return False;
1933 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
1934 proplist_t pl;
1936 pl = PLGetArrayElement(value, 0);
1937 if (!pl || !PLIsString(pl) || !PLGetString(pl)
1938 || strcasecmp(PLGetString(pl), "solid")!=0) {
1939 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1940 entry->key, "Solid Texture");
1942 value = entry->plvalue;
1943 changed = 1;
1944 wwarning(_("using default \"%s\" instead"), entry->default_value);
1945 goto again;
1949 texture = parse_texture(scr, value);
1951 if (!texture) {
1952 wwarning(_("Error in texture specification for key \"%s\""),
1953 entry->key);
1954 if (changed==0) {
1955 value = entry->plvalue;
1956 changed = 1;
1957 wwarning(_("using default \"%s\" instead"), entry->default_value);
1958 goto again;
1960 return False;
1963 if (ret)
1964 *ret = &texture;
1966 if (addr)
1967 *(WTexture**)addr = texture;
1969 return True;
1974 static int
1975 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
1976 void *addr, void **ret)
1978 proplist_t elem;
1979 int changed = 0;
1980 char *val;
1981 int nelem;
1983 again:
1984 if (!PLIsArray(value)) {
1985 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1986 "WorkspaceBack", "Texture or None");
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 /* only do basic error checking and verify for None texture */
1998 nelem = PLGetNumberOfElements(value);
1999 if (nelem > 0) {
2000 elem = PLGetArrayElement(value, 0);
2001 if (!elem || !PLIsString(elem)) {
2002 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2003 if (changed==0) {
2004 value = entry->plvalue;
2005 changed = 1;
2006 wwarning(_("using default \"%s\" instead"), entry->default_value);
2007 goto again;
2009 return False;
2011 val = PLGetString(elem);
2013 if (strcasecmp(val, "None")==0)
2014 return True;
2016 *ret = PLRetain(value);
2018 return True;
2022 static int
2023 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2024 void *addr, void **ret)
2026 proplist_t elem;
2027 int nelem;
2028 int changed = 0;
2030 again:
2031 if (!PLIsArray(value)) {
2032 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2033 "WorkspaceSpecificBack", "an array of textures");
2034 if (changed==0) {
2035 value = entry->plvalue;
2036 changed = 1;
2037 wwarning(_("using default \"%s\" instead"), entry->default_value);
2038 goto again;
2040 return False;
2043 /* only do basic error checking and verify for None texture */
2045 nelem = PLGetNumberOfElements(value);
2046 if (nelem > 0) {
2047 while (nelem--) {
2048 elem = PLGetArrayElement(value, nelem);
2049 if (!elem || !PLIsArray(elem)) {
2050 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2051 nelem);
2056 *ret = PLRetain(value);
2058 #ifdef notworking
2060 * Kluge to force wmsetbg helper to set the default background.
2061 * If the WorkspaceSpecificBack is changed once wmaker has started,
2062 * the WorkspaceBack won't be sent to the helper, unless the user
2063 * changes it's value too. So, we must force this by removing the
2064 * value from the defaults DB.
2066 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2067 proplist_t key = PLMakeString("WorkspaceBack");
2069 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2071 PLRelease(key);
2073 #endif
2074 return True;
2078 static int
2079 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2080 void **ret)
2082 static WFont *font;
2083 char *val;
2085 STRINGP("Font");
2087 val = PLGetString(value);
2089 font = wLoadFont(val);
2090 if (!font) {
2091 wfatal(_("could not load any usable font!!!"));
2092 exit(1);
2095 if (ret)
2096 *ret = font;
2098 /* can't assign font value outside update function */
2099 wassertrv(addr == NULL, True);
2101 return True;
2105 static int
2106 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2107 void **ret)
2109 static XColor color;
2110 char *val;
2111 int second_pass=0;
2113 STRINGP("Color");
2115 val = PLGetString(value);
2117 again:
2118 if (!wGetColor(scr, val, &color)) {
2119 wwarning(_("could not get color for key \"%s\""),
2120 entry->key);
2121 if (second_pass==0) {
2122 val = PLGetString(entry->plvalue);
2123 second_pass = 1;
2124 wwarning(_("using default \"%s\" instead"), val);
2125 goto again;
2127 return False;
2130 if (ret)
2131 *ret = &color;
2133 assert(addr==NULL);
2135 if (addr)
2136 *(unsigned long*)addr = pixel;
2139 return True;
2144 static int
2145 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2146 void **ret)
2148 static WShortKey shortcut;
2149 KeySym ksym;
2150 char *val;
2151 char *k;
2152 char buf[128], *b;
2155 STRINGP("Key spec");
2157 val = PLGetString(value);
2159 if (!val || strcasecmp(val, "NONE")==0) {
2160 shortcut.keycode = 0;
2161 shortcut.modifier = 0;
2162 if (ret)
2163 *ret = &shortcut;
2164 return True;
2167 strcpy(buf, val);
2169 b = (char*)buf;
2171 /* get modifiers */
2172 shortcut.modifier = 0;
2173 while ((k = strchr(b, '+'))!=NULL) {
2174 int mod;
2176 *k = 0;
2177 mod = wXModifierFromKey(b);
2178 if (mod<0) {
2179 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2180 return False;
2182 shortcut.modifier |= mod;
2184 b = k+1;
2187 /* get key */
2188 ksym = XStringToKeysym(b);
2190 if (ksym==NoSymbol) {
2191 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2192 val);
2193 return False;
2196 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2197 if (shortcut.keycode==0) {
2198 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2199 return False;
2202 if (ret)
2203 *ret = &shortcut;
2205 return True;
2209 static int
2210 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2211 void **ret)
2213 static unsigned int mask;
2214 char *str;
2216 STRINGP("Modifier Key");
2218 str = PLGetString(value);
2219 if (!str)
2220 return False;
2222 mask = wXModifierFromKey(str);
2223 if (mask < 0) {
2224 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2225 mask = 0;
2226 return False;
2229 if (addr)
2230 *(unsigned int*)addr = mask;
2232 if (ret)
2233 *ret = &mask;
2235 return True;
2239 #ifdef NEWSTUFF
2240 static int
2241 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2242 void *addr, void **ret)
2244 unsigned int mask;
2245 char *str;
2246 RImage *image;
2247 int i, n;
2248 int w, h;
2250 STRINGP("Image File Path");
2252 str = PLGetString(value);
2253 if (!str)
2254 return False;
2256 image = RLoadImage(scr->rcontext, str, 0);
2257 if (!image) {
2258 wwarning(_("could not load image in option %s: %s"), entry->key,
2259 RMessageForError(RErrorCode));
2260 return False;
2263 if (*(RImage**)addr) {
2264 RDestroyImage(*(RImage**)addr);
2266 if (addr)
2267 *(RImage**)addr = image;
2269 assert(ret == NULL);
2271 if (ret)
2272 *(RImage**)ret = image;
2275 return True;
2277 #endif
2280 /* ---------------- value setting functions --------------- */
2281 static int
2282 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2284 return REFRESH_WINDOW_TITLE_COLOR;
2288 static int
2289 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2291 switch (which) {
2292 case WM_DOCK:
2293 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2294 break;
2295 case WM_CLIP:
2296 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2297 break;
2298 default:
2299 break;
2301 return 0;
2305 static int
2306 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2308 if (scr->workspaces) {
2309 wWorkspaceForceChange(scr, scr->current_workspace);
2310 wArrangeIcons(scr, False);
2312 return 0;
2315 #if not_used
2316 static int
2317 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2319 if (*value <= 0)
2320 *(int*)foo = 1;
2322 return 0;
2324 #endif
2328 static int
2329 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2331 Pixmap pixmap;
2332 RImage *img;
2333 int reset = 0;
2335 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2336 wPreferences.icon_size,
2337 ((*texture)->any.type & WREL_BORDER_MASK)
2338 ? WREL_ICON : WREL_FLAT);
2339 if (!img) {
2340 wwarning(_("could not render texture for icon background"));
2341 if (!entry->addr)
2342 wTextureDestroy(scr, *texture);
2343 return 0;
2345 RConvertImage(scr->rcontext, img, &pixmap);
2347 if (scr->icon_tile) {
2348 reset = 1;
2349 RDestroyImage(scr->icon_tile);
2350 XFreePixmap(dpy, scr->icon_tile_pixmap);
2353 scr->icon_tile = img;
2355 if (!wPreferences.flags.noclip) {
2356 if (scr->clip_tile) {
2357 RDestroyImage(scr->clip_tile);
2359 scr->clip_tile = wClipMakeTile(scr, img);
2362 scr->icon_tile_pixmap = pixmap;
2364 if (scr->def_icon_pixmap) {
2365 XFreePixmap(dpy, scr->def_icon_pixmap);
2366 scr->def_icon_pixmap = None;
2368 if (scr->def_ticon_pixmap) {
2369 XFreePixmap(dpy, scr->def_ticon_pixmap);
2370 scr->def_ticon_pixmap = None;
2373 if (scr->icon_back_texture) {
2374 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2376 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2378 if (scr->clip_balloon)
2379 XSetWindowBackground(dpy, scr->clip_balloon,
2380 (*texture)->any.color.pixel);
2383 * Free the texture as nobody else will use it, nor refer to it.
2385 if (!entry->addr)
2386 wTextureDestroy(scr, *texture);
2388 return (reset ? REFRESH_ICON_TILE : 0);
2393 static int
2394 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2396 if (scr->title_font) {
2397 wFreeFont(scr->title_font);
2400 scr->title_font = font;
2402 #ifndef I18N_MB
2403 XSetFont(dpy, scr->window_title_gc, font->font->fid);
2404 #endif
2406 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2410 static int
2411 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2413 if (scr->menu_title_font) {
2414 wFreeFont(scr->menu_title_font);
2417 scr->menu_title_font = font;
2419 #ifndef I18N_MB
2420 XSetFont(dpy, scr->menu_title_gc, font->font->fid);
2421 #endif
2423 return REFRESH_MENU_TITLE_FONT;
2427 static int
2428 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2430 if (scr->menu_entry_font) {
2431 wFreeFont(scr->menu_entry_font);
2434 scr->menu_entry_font = font;
2436 #ifndef I18N_MB
2437 XSetFont(dpy, scr->menu_entry_gc, font->font->fid);
2438 XSetFont(dpy, scr->disabled_menu_entry_gc, font->font->fid);
2439 XSetFont(dpy, scr->select_menu_gc, font->font->fid);
2440 #endif
2442 return REFRESH_MENU_FONT;
2447 static int
2448 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2450 if (scr->icon_title_font) {
2451 wFreeFont(scr->icon_title_font);
2454 scr->icon_title_font = font;
2456 #ifndef I18N_MB
2457 XSetFont(dpy, scr->icon_title_gc, font->font->fid);
2458 #endif
2460 return REFRESH_ICON_FONT;
2464 static int
2465 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2467 if (scr->clip_title_font) {
2468 wFreeFont(scr->clip_title_font);
2471 scr->clip_title_font = font;
2473 #ifndef I18N_MB
2474 XSetFont(dpy, scr->clip_title_gc, font->font->fid);
2475 #endif
2477 return REFRESH_ICON_FONT;
2481 static int
2482 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2484 if (scr->info_text_font) {
2485 wFreeFont(scr->info_text_font);
2488 scr->info_text_font = font;
2490 #ifndef I18N_MB
2491 XSetFont(dpy, scr->info_text_gc, font->font->fid);
2492 XSetFont(dpy, scr->line_gc, font->font->fid);
2493 #endif
2495 /* This test works because the scr structure is initially zeroed out
2496 and None = 0. Any other time, the window should be valid. */
2497 if (scr->geometry_display != None) {
2498 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2499 &scr->geometry_display_height);
2500 XResizeWindow(dpy, scr->geometry_display,
2501 scr->geometry_display_width, scr->geometry_display_height);
2504 return 0;
2508 static int
2509 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2511 if (scr->select_pixel!=scr->white_pixel &&
2512 scr->select_pixel!=scr->black_pixel) {
2513 wFreeColor(scr, scr->select_pixel);
2516 scr->select_pixel = color->pixel;
2518 return REFRESH_MENU_COLOR;
2522 static int
2523 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2525 if (scr->select_text_pixel!=scr->white_pixel &&
2526 scr->select_text_pixel!=scr->black_pixel) {
2527 wFreeColor(scr, scr->select_text_pixel);
2530 scr->select_text_pixel = color->pixel;
2532 return REFRESH_MENU_COLOR;
2536 static int
2537 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2539 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2540 scr->clip_title_pixel[index]!=scr->black_pixel) {
2541 wFreeColor(scr, scr->clip_title_pixel[index]);
2543 scr->clip_title_pixel[index] = color->pixel;
2545 #ifdef GRADIENT_CLIP_ARROW
2546 if (index == CLIP_NORMAL) {
2547 RImage *image;
2548 RColor color1, color2;
2549 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2550 int as = pt - 15; /* 15 = 5+5+5 */
2552 FREE_PIXMAP(scr->clip_arrow_gradient);
2554 color1.red = (color->red >> 8)*6/10;
2555 color1.green = (color->green >> 8)*6/10;
2556 color1.blue = (color->blue >> 8)*6/10;
2558 color2.red = WMIN((color->red >> 8)*20/10, 255);
2559 color2.green = WMIN((color->green >> 8)*20/10, 255);
2560 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2562 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2563 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2564 RDestroyImage(image);
2566 #endif /* GRADIENT_CLIP_ARROW */
2568 return REFRESH_ICON_TITLE_COLOR;
2572 static int
2573 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2575 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2576 scr->window_title_pixel[index]!=scr->black_pixel) {
2577 wFreeColor(scr, scr->window_title_pixel[index]);
2580 scr->window_title_pixel[index] = color->pixel;
2582 if (index == WS_UNFOCUSED)
2583 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2585 return REFRESH_WINDOW_TITLE_COLOR;
2589 static int
2590 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2592 #ifdef TITLE_TEXT_SHADOW
2593 if (index == WS_SMENU){
2594 if (scr->menu_title_pixel[WS_SMENU]!=scr->white_pixel &&
2595 scr->menu_title_pixel[WS_SMENU]!=scr->black_pixel) {
2596 wFreeColor(scr, scr->menu_title_pixel[WS_SMENU]);
2598 scr->menu_title_pixel[WS_SMENU] = color->pixel;
2600 else {
2601 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2602 scr->menu_title_pixel[0]!=scr->black_pixel) {
2603 wFreeColor(scr, scr->menu_title_pixel[0]);
2605 scr->menu_title_pixel[0] = color->pixel;
2607 #else /* !TITLE_TEXT_SHADOW */
2608 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2609 scr->menu_title_pixel[0]!=scr->black_pixel) {
2610 wFreeColor(scr, scr->menu_title_pixel[0]);
2613 scr->menu_title_pixel[0] = color->pixel;
2614 #endif /* !TITLE_TEXT_SHADOW */
2615 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2617 return REFRESH_MENU_TITLE_COLOR;
2621 static int
2622 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2624 XGCValues gcv;
2625 #define gcm (GCForeground|GCBackground|GCFillStyle)
2627 if (scr->mtext_pixel!=scr->white_pixel &&
2628 scr->mtext_pixel!=scr->black_pixel) {
2629 wFreeColor(scr, scr->mtext_pixel);
2632 scr->mtext_pixel = color->pixel;
2634 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2637 if (scr->dtext_pixel == scr->mtext_pixel) {
2638 gcv.foreground = scr->white_pixel;
2639 gcv.background = scr->black_pixel;
2640 gcv.fill_style = FillStippled;
2641 } else {
2642 gcv.foreground = scr->dtext_pixel;
2643 gcv.fill_style = FillSolid;
2645 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2647 return REFRESH_MENU_COLOR;
2648 #undef gcm
2652 static int
2653 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2655 XGCValues gcv;
2656 #define gcm (GCForeground|GCBackground|GCFillStyle)
2658 if (scr->dtext_pixel!=scr->white_pixel &&
2659 scr->dtext_pixel!=scr->black_pixel) {
2660 wFreeColor(scr, scr->dtext_pixel);
2663 scr->dtext_pixel = color->pixel;
2665 if (scr->dtext_pixel == scr->mtext_pixel) {
2666 gcv.foreground = scr->white_pixel;
2667 gcv.background = scr->black_pixel;
2668 gcv.fill_style = FillStippled;
2669 } else {
2670 gcv.foreground = scr->dtext_pixel;
2671 gcv.fill_style = FillSolid;
2673 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2675 return REFRESH_MENU_COLOR;
2676 #undef gcm
2679 static int
2680 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2682 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2684 return REFRESH_ICON_TITLE_COLOR;
2688 static int
2689 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2691 if (scr->icon_title_texture) {
2692 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2694 XQueryColor (dpy, scr->w_colormap, color);
2695 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2697 return REFRESH_ICON_TITLE_BACK;
2701 static void
2702 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2704 close(scr->helper_fd);
2705 scr->helper_fd = 0;
2706 scr->helper_pid = 0;
2707 scr->flags.backimage_helper_launched = 0;
2711 static int
2712 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2713 void *bar)
2715 int i;
2716 proplist_t val;
2717 char *str;
2719 if (scr->flags.backimage_helper_launched) {
2720 if (PLGetNumberOfElements(value)==0) {
2721 SendHelperMessage(scr, 'C', 0, NULL);
2722 SendHelperMessage(scr, 'K', 0, NULL);
2724 PLRelease(value);
2725 return 0;
2727 } else {
2728 pid_t pid;
2729 int filedes[2];
2731 if (PLGetNumberOfElements(value) == 0)
2732 return 0;
2734 if (pipe(filedes) < 0) {
2735 wsyserror("pipe() failed:can't set workspace specific background image");
2737 PLRelease(value);
2738 return 0;
2741 pid = fork();
2742 if (pid < 0) {
2743 wsyserror("fork() failed:can't set workspace specific background image");
2744 if (close(filedes[0]) < 0)
2745 wsyserror("could not close pipe");
2746 if (close(filedes[1]) < 0)
2747 wsyserror("could not close pipe");
2749 } else if (pid == 0) {
2750 SetupEnvironment(scr);
2752 if (close(0) < 0)
2753 wsyserror("could not close pipe");
2754 if (dup(filedes[0]) < 0) {
2755 wsyserror("dup() failed:can't set workspace specific background image");
2757 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2758 wsyserror("could not execute wmsetbg");
2759 exit(1);
2760 } else {
2762 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2763 wsyserror("error setting close-on-exec flag");
2765 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2766 wsyserror("error setting close-on-exec flag");
2769 scr->helper_fd = filedes[1];
2770 scr->helper_pid = pid;
2771 scr->flags.backimage_helper_launched = 1;
2773 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2775 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2779 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2780 val = PLGetArrayElement(value, i);
2781 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2782 str = PLGetDescription(val);
2784 SendHelperMessage(scr, 'S', i+1, str);
2786 free(str);
2787 } else {
2788 SendHelperMessage(scr, 'U', i+1, NULL);
2791 sleep(1);
2793 PLRelease(value);
2794 return 0;
2798 static int
2799 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2800 void *bar)
2802 if (scr->flags.backimage_helper_launched) {
2803 char *str;
2805 if (PLGetNumberOfElements(value)==0) {
2806 SendHelperMessage(scr, 'U', 0, NULL);
2807 } else {
2808 /* set the default workspace background to this one */
2809 str = PLGetDescription(value);
2810 if (str) {
2811 SendHelperMessage(scr, 'S', 0, str);
2812 free(str);
2813 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2814 } else {
2815 SendHelperMessage(scr, 'U', 0, NULL);
2818 } else {
2819 char *command;
2820 char *text;
2822 SetupEnvironment(scr);
2823 text = PLGetDescription(value);
2824 command = wmalloc(strlen(text)+40);
2825 sprintf(command, "wmsetbg -d -p '%s' &", text);
2826 free(text);
2827 system(command);
2828 free(command);
2830 PLRelease(value);
2832 return 0;
2836 static int
2837 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2839 if (scr->widget_texture) {
2840 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2842 scr->widget_texture = *(WTexSolid**)texture;
2844 if (scr->geometry_display != None)
2845 XSetWindowBackground(dpy, scr->geometry_display,
2846 scr->widget_texture->normal.pixel);
2848 return 0;
2852 static int
2853 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2855 if (scr->window_title_texture[WS_FOCUSED]) {
2856 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2858 scr->window_title_texture[WS_FOCUSED] = *texture;
2860 return REFRESH_WINDOW_TEXTURES;
2864 static int
2865 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2867 if (scr->window_title_texture[WS_PFOCUSED]) {
2868 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2870 scr->window_title_texture[WS_PFOCUSED] = *texture;
2872 return REFRESH_WINDOW_TEXTURES;
2876 static int
2877 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2879 if (scr->window_title_texture[WS_UNFOCUSED]) {
2880 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2882 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2884 return REFRESH_WINDOW_TEXTURES;
2888 static int
2889 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2891 if (scr->resizebar_texture[0]) {
2892 wTextureDestroy(scr, scr->resizebar_texture[0]);
2894 scr->resizebar_texture[0] = *texture;
2896 return REFRESH_WINDOW_TEXTURES;
2900 static int
2901 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2903 if (scr->menu_title_texture[0]) {
2904 wTextureDestroy(scr, scr->menu_title_texture[0]);
2906 scr->menu_title_texture[0] = *texture;
2908 return REFRESH_MENU_TITLE_TEXTURE;
2912 static int
2913 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2915 if (scr->menu_item_texture) {
2916 wTextureDestroy(scr, scr->menu_item_texture);
2917 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2919 scr->menu_item_texture = *texture;
2921 scr->menu_item_auxtexture
2922 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2924 return REFRESH_MENU_TEXTURE;
2928 static int
2929 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
2931 WWindow *wwin;
2932 wKeyBindings[index] = *shortcut;
2934 wwin = scr->focused_window;
2936 while (wwin!=NULL) {
2937 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2939 if (!WFLAGP(wwin, no_bind_keys)) {
2940 wWindowSetKeyGrabs(wwin);
2942 wwin = wwin->prev;
2945 return 0;
2949 static int
2950 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2952 wArrangeIcons(scr, True);
2954 return 0;
2958 static int
2959 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2961 wScreenUpdateUsableArea(scr);
2963 return 0;
2967 static int
2968 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2970 return REFRESH_MENU_TEXTURE;
2975 static int
2976 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2978 return REFRESH_BUTTON_IMAGES;
2983 * Very ugly kluge.
2984 * Need access to the double click variables, so that all widgets in
2985 * wmaker panels will have the same dbl-click values.
2986 * TODO: figure a better way of dealing with it.
2988 #include "WINGsP.h"
2990 static int
2991 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2993 extern _WINGsConfiguration WINGsConfiguration;
2995 if (*value <= 0)
2996 *(int*)foo = 1;
2998 WINGsConfiguration.doubleClickDelay = *value;
3000 return 0;