bug fixes, faq update, fix of wrong bug fix in actions.c etc
[wmaker-crm.git] / src / defaults.c
blob65e6948e4ce37ab130b2e823a8fb70eb54cc6699
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 setLargeDisplayFont();
155 static int setWTitleColor();
156 static int setFTitleBack();
157 static int setPTitleBack();
158 static int setUTitleBack();
159 static int setResizebarBack();
160 static int setWorkspaceBack();
161 static int setWorkspaceSpecificBack();
162 static int setMenuTitleColor();
163 static int setMenuTextColor();
164 static int setMenuDisabledColor();
165 static int setMenuTitleBack();
166 static int setMenuTextBack();
167 static int setHightlight();
168 static int setHightlightText();
169 static int setKeyGrab();
170 static int setDoubleClick();
171 static int setIconPosition();
173 static int setClipTitleFont();
174 static int setClipTitleColor();
176 static int setMenuStyle();
179 static int updateUsableArea();
184 * Tables to convert strings to enumeration values.
185 * Values stored are char
189 /* WARNING: sum of length of all value strings must not exceed
190 * this value */
191 #define TOTAL_VALUES_LENGTH 80
196 #define REFRESH_WINDOW_TEXTURES (1<<0)
197 #define REFRESH_MENU_TEXTURE (1<<1)
198 #define REFRESH_MENU_FONT (1<<2)
199 #define REFRESH_MENU_COLOR (1<<3)
200 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
201 #define REFRESH_MENU_TITLE_FONT (1<<5)
202 #define REFRESH_MENU_TITLE_COLOR (1<<6)
203 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
204 #define REFRESH_WINDOW_FONT (1<<8)
205 #define REFRESH_ICON_TILE (1<<9)
206 #define REFRESH_ICON_FONT (1<<10)
207 #define REFRESH_WORKSPACE_BACK (1<<11)
209 #define REFRESH_BUTTON_IMAGES (1<<12)
211 #define REFRESH_ICON_TITLE_COLOR (1<<13)
212 #define REFRESH_ICON_TITLE_BACK (1<<14)
216 static WOptionEnumeration seFocusModes[] = {
217 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
218 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
219 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
220 {NULL, 0, 0}
223 static WOptionEnumeration seColormapModes[] = {
224 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
225 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
226 {NULL, 0, 0}
229 static WOptionEnumeration sePlacements[] = {
230 {"Auto", WPM_SMART, 0}, {"Smart", WPM_SMART, 1},
231 {"Cascade", WPM_CASCADE, 0},
232 {"Random", WPM_RANDOM, 0},
233 {"Manual", WPM_MANUAL, 0},
234 {NULL, 0, 0}
237 static WOptionEnumeration seGeomDisplays[] = {
238 {"Center", WDIS_CENTER, 0},
239 {"Corner", WDIS_TOPLEFT, 0},
240 {"Floating", WDIS_FRAME_CENTER, 0},
241 {"Line", WDIS_NEW, 0},
242 {NULL, 0, 0}
245 static WOptionEnumeration seSpeeds[] = {
246 {"UltraFast", SPEED_ULTRAFAST, 0},
247 {"Fast", SPEED_FAST, 0},
248 {"Medium", SPEED_MEDIUM, 0},
249 {"Slow", SPEED_SLOW, 0},
250 {"UltraSlow", SPEED_ULTRASLOW, 0},
251 {NULL, 0, 0}
254 static WOptionEnumeration seMouseButtons[] = {
255 {"Left", Button1, 0}, {"Button1", Button1, 1},
256 {"Middle", Button2, 0}, {"Button2", Button2, 1},
257 {"Right", Button3, 0}, {"Button3", Button3, 1},
258 {"Button4", Button4, 0},
259 {"Button5", Button5, 0},
260 {NULL, 0, 0}
263 static WOptionEnumeration seIconificationStyles[] = {
264 {"Zoom", WIS_ZOOM, 0},
265 {"Twist", WIS_TWIST, 0},
266 {"Flip", WIS_FLIP, 0},
267 {"None", WIS_NONE, 0},
268 {"random", WIS_RANDOM, 0},
269 {NULL, 0, 0}
272 static WOptionEnumeration seJustifications[] = {
273 {"Left", WTJ_LEFT, 0},
274 {"Center", WTJ_CENTER, 0},
275 {"Right", WTJ_RIGHT, 0},
276 {NULL, 0, 0}
279 static WOptionEnumeration seIconPositions[] = {
280 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
281 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
282 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
283 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
284 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
285 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
286 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
287 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
288 {NULL, 0, 0}
291 static WOptionEnumeration seMenuStyles[] = {
292 {"normal", MS_NORMAL, 0},
293 {"singletexture", MS_SINGLE_TEXTURE, 0},
294 {"flat", MS_FLAT, 0},
295 {NULL, 0, 0}
300 * ALL entries in the tables bellow, NEED to have a default value
301 * defined, and this value needs to be correct.
304 /* these options will only affect the window manager on startup
306 * static defaults can't access the screen data, because it is
307 * created after these defaults are read
309 WDefaultEntry staticOptionList[] = {
311 {"DisableDithering", "NO", NULL,
312 &wPreferences.no_dithering, getBool, NULL
314 {"ColormapSize", "4", NULL,
315 &wPreferences.cmap_size, getInt, NULL
317 /* static by laziness */
318 {"IconSize", "64", NULL,
319 &wPreferences.icon_size, getInt, NULL
321 {"ModifierKey", "Mod1", NULL,
322 &wPreferences.modifier_mask, getModMask, NULL
324 {"DisableWSMouseActions", "NO", NULL,
325 &wPreferences.disable_root_mouse, getBool, NULL
327 {"FocusMode", "manual", seFocusModes,
328 &wPreferences.focus_mode, getEnum, NULL
329 }, /* have a problem when switching from manual to sloppy without restart */
330 {"NewStyle", "NO", NULL,
331 &wPreferences.new_style, getBool, NULL
333 {"DisableDock", "NO", (void*) WM_DOCK,
334 NULL, getBool, setIfDockPresent
336 {"DisableClip", "NO", (void*) WM_CLIP,
337 NULL, getBool, setIfDockPresent
339 {"DisableMiniwindows", "NO", NULL,
340 &wPreferences.disable_miniwindows, getBool, NULL
346 WDefaultEntry optionList[] = {
347 /* dynamic options */
348 {"IconPosition", "blh", seIconPositions,
349 &wPreferences.icon_yard, getEnum, setIconPosition
351 {"IconificationStyle", "Zoom", seIconificationStyles,
352 &wPreferences.iconification_style, getEnum, NULL
354 {"SelectWindowsMouseButton", "Left", seMouseButtons,
355 &wPreferences.select_button, getEnum, NULL
357 {"WindowListMouseButton", "Middle", seMouseButtons,
358 &wPreferences.windowl_button, getEnum, NULL
360 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
361 &wPreferences.menu_button, getEnum, NULL
363 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
364 &wPreferences.pixmap_path, getPathList, NULL
366 {"IconPath", DEF_ICON_PATHS, NULL,
367 &wPreferences.icon_path, getPathList, NULL
369 {"ColormapMode", "auto", seColormapModes,
370 &wPreferences.colormap_mode, getEnum, NULL
372 {"AutoFocus", "NO", NULL,
373 &wPreferences.auto_focus, getBool, NULL
375 {"RaiseDelay", "0", NULL,
376 &wPreferences.raise_delay, getInt, NULL
378 {"CirculateRaise", "NO", NULL,
379 &wPreferences.circ_raise, getBool, NULL
381 {"Superfluous", "NO", NULL,
382 &wPreferences.superfluous, getBool, NULL
384 {"AdvanceToNewWorkspace", "NO", NULL,
385 &wPreferences.ws_advance, getBool, NULL
387 {"CycleWorkspaces", "NO", NULL,
388 &wPreferences.ws_cycle, getBool, NULL
390 {"StickyIcons", "NO", NULL,
391 &wPreferences.sticky_icons, getBool, setStickyIcons
393 {"SaveSessionOnExit", "NO", NULL,
394 &wPreferences.save_session_on_exit, getBool, NULL
396 {"WrapMenus", "NO", NULL,
397 &wPreferences.wrap_menus, getBool, NULL
399 {"ScrollableMenus", "NO", NULL,
400 &wPreferences.scrollable_menus, getBool, NULL
402 {"MenuScrollSpeed", "medium", seSpeeds,
403 &wPreferences.menu_scroll_speed, getEnum, NULL
405 {"IconSlideSpeed", "medium", seSpeeds,
406 &wPreferences.icon_slide_speed, getEnum, NULL
408 {"ShadeSpeed", "medium", seSpeeds,
409 &wPreferences.shade_speed, getEnum, NULL
411 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
412 &wPreferences.dblclick_time, getInt, setDoubleClick,
414 {"AlignSubmenus", "NO", NULL,
415 &wPreferences.align_menus, getBool, NULL
417 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
418 &wPreferences.open_transients_with_parent, getBool, NULL
420 {"WindowPlacement", "auto", sePlacements,
421 &wPreferences.window_placement, getEnum, NULL
423 {"IgnoreFocusClick","NO", NULL,
424 &wPreferences.ignore_focus_click, getBool, NULL
426 {"UseSaveUnders", "NO", NULL,
427 &wPreferences.use_saveunders, getBool, NULL
429 {"OpaqueMove", "NO", NULL,
430 &wPreferences.opaque_move, getBool, NULL
432 {"DisableSound", "NO", NULL,
433 &wPreferences.no_sound, getBool, NULL
435 {"DisableAnimations", "NO", NULL,
436 &wPreferences.no_animations, getBool, NULL
438 {"DontLinkWorkspaces","NO", NULL,
439 &wPreferences.no_autowrap, getBool, NULL
441 {"AutoArrangeIcons", "NO", NULL,
442 &wPreferences.auto_arrange_icons, getBool, NULL
444 {"NoWindowOverDock", "NO", NULL,
445 &wPreferences.no_window_over_dock, getBool, updateUsableArea
447 {"NoWindowOverIcons", "NO", NULL,
448 &wPreferences.no_window_over_icons, getBool, updateUsableArea
450 {"WindowPlaceOrigin", "(0, 0)", NULL,
451 &wPreferences.window_place_origin, getCoord, NULL
453 {"ResizeDisplay", "corner", seGeomDisplays,
454 &wPreferences.size_display, getEnum, NULL
456 {"MoveDisplay", "corner", seGeomDisplays,
457 &wPreferences.move_display, getEnum, NULL
459 {"DontConfirmKill", "NO", NULL,
460 &wPreferences.dont_confirm_kill, getBool,NULL
462 {"WindowTitleBalloons", "NO", NULL,
463 &wPreferences.window_balloon, getBool, NULL
465 {"MiniwindowTitleBalloons", "NO", NULL,
466 &wPreferences.miniwin_balloon,getBool, NULL
468 {"AppIconBalloons", "NO", NULL,
469 &wPreferences.appicon_balloon,getBool, NULL
471 {"EdgeResistance", "30", NULL,
472 &wPreferences.edge_resistance,getInt, NULL
474 {"DisableBlinking", "NO", NULL,
475 &wPreferences.dont_blink, getBool, NULL
477 #ifdef WEENDOZE_CYCLE
478 {"WindozeCycling","NO", NULL,
479 &wPreferences.windoze_cycling, getBool, NULL
481 {"PopupSwitchMenu","YES", NULL,
482 &wPreferences.popup_switchmenu, getBool, NULL
484 #endif /* WEENDOZE_CYCLE */
485 /* style options */
486 {"MenuStyle", "normal", seMenuStyles,
487 &wPreferences.menu_style, getEnum, setMenuStyle
489 {"WidgetColor", "(solid, gray)", NULL,
490 NULL, getTexture, setWidgetColor,
492 {"WorkspaceSpecificBack","()", NULL,
493 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
495 /* WorkspaceBack must come after WorkspaceSpecificBack or
496 * WorkspaceBack wont know WorkspaceSpecificBack was also
497 * specified and 2 copies of wmsetbg will be launched */
498 {"WorkspaceBack", "(solid, black)", NULL,
499 NULL, getWSBackground,setWorkspaceBack
501 {"IconBack", "(solid, gray)", NULL,
502 NULL, getTexture, setIconTile
504 {"TitleJustify", "center", seJustifications,
505 &wPreferences.title_justification, getEnum, setJustify
507 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
508 NULL, getFont, setWinTitleFont,
510 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
511 NULL, getFont, setMenuTitleFont
513 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
514 NULL, getFont, setMenuTextFont
516 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
517 NULL, getFont, setIconTitleFont
519 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
520 NULL, getFont, setClipTitleFont
522 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
523 NULL, getFont, setDisplayFont
525 {"LargeDisplayFont" DEF_WORKSPACE_NAME_FONT, NULL,
526 NULL, getFont, setLargeDisplayFont
528 {"HighlightColor", "white", NULL,
529 NULL, getColor, setHightlight
531 {"HighlightTextColor", "black", NULL,
532 NULL, getColor, setHightlightText
534 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
535 NULL, getColor, setClipTitleColor
537 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
538 NULL, getColor, setClipTitleColor
540 {"FTitleColor", "white", (void*)WS_FOCUSED,
541 NULL, getColor, setWTitleColor
543 {"PTitleColor", "white", (void*)WS_PFOCUSED,
544 NULL, getColor, setWTitleColor
546 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
547 NULL, getColor, setWTitleColor
549 {"FTitleBack", "(solid, black)", NULL,
550 NULL, getTexture, setFTitleBack
552 {"PTitleBack", "(solid, \"#616161\")", NULL,
553 NULL, getTexture, setPTitleBack
555 {"UTitleBack", "(solid, gray)", NULL,
556 NULL, getTexture, setUTitleBack
558 {"ResizebarBack", "(solid, gray)", NULL,
559 NULL, getTexture, setResizebarBack
561 {"MenuTitleColor", "white", NULL,
562 NULL, getColor, setMenuTitleColor
564 {"MenuTextColor", "black", NULL,
565 NULL, getColor, setMenuTextColor
567 {"MenuDisabledColor", "\"#616161\"", NULL,
568 NULL, getColor, setMenuDisabledColor
570 {"MenuTitleBack", "(solid, black)", NULL,
571 NULL, getTexture, setMenuTitleBack
573 {"MenuTextBack", "(solid, gray)", NULL,
574 NULL, getTexture, setMenuTextBack
576 {"IconTitleColor", "white", NULL,
577 NULL, getColor, setIconTitleColor
579 {"IconTitleBack", "black", NULL,
580 NULL, getColor, setIconTitleBack
582 /* keybindings */
583 #ifndef LITE
584 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
585 NULL, getKeybind, setKeyGrab
587 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
588 NULL, getKeybind, setKeyGrab
590 #endif /* LITE */
591 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
592 NULL, getKeybind, setKeyGrab
594 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
595 NULL, getKeybind, setKeyGrab
597 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
598 NULL, getKeybind, setKeyGrab
600 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
601 NULL, getKeybind, setKeyGrab
603 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
604 NULL, getKeybind, setKeyGrab
606 {"HideKey", "None", (void*)WKBD_HIDE,
607 NULL, getKeybind, setKeyGrab
609 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
610 NULL, getKeybind, setKeyGrab
612 {"CloseKey", "None", (void*)WKBD_CLOSE,
613 NULL, getKeybind, setKeyGrab
615 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
616 NULL, getKeybind, setKeyGrab
618 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
619 NULL, getKeybind, setKeyGrab
621 {"RaiseKey", "Meta+Up", (void*)WKBD_RAISE,
622 NULL, getKeybind, setKeyGrab
624 {"LowerKey", "Meta+Down", (void*)WKBD_LOWER,
625 NULL, getKeybind, setKeyGrab
627 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
628 NULL, getKeybind, setKeyGrab
630 {"ShadeKey", "None", (void*)WKBD_SHADE,
631 NULL, getKeybind, setKeyGrab
633 {"SelectKey", "None", (void*)WKBD_SELECT,
634 NULL, getKeybind, setKeyGrab
636 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
637 NULL, getKeybind, setKeyGrab
639 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
640 NULL, getKeybind, setKeyGrab
642 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
643 NULL, getKeybind, setKeyGrab
645 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
646 NULL, getKeybind, setKeyGrab
648 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
649 NULL, getKeybind, setKeyGrab
651 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
652 NULL, getKeybind, setKeyGrab
654 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
655 NULL, getKeybind, setKeyGrab
657 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
658 NULL, getKeybind, setKeyGrab
660 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
661 NULL, getKeybind, setKeyGrab
663 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
664 NULL, getKeybind, setKeyGrab
666 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
667 NULL, getKeybind, setKeyGrab
669 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
670 NULL, getKeybind, setKeyGrab
672 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
673 NULL, getKeybind, setKeyGrab
675 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
676 NULL, getKeybind, setKeyGrab
678 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
679 NULL, getKeybind, setKeyGrab
681 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
682 NULL, getKeybind, setKeyGrab
684 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
685 NULL, getKeybind, setKeyGrab
687 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
688 NULL, getKeybind, setKeyGrab
690 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
691 NULL, getKeybind, setKeyGrab
693 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
694 NULL, getKeybind, setKeyGrab
696 #ifdef EXTEND_WINDOWSHORTCUT
697 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
698 NULL, getKeybind, setKeyGrab
700 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
701 NULL, getKeybind, setKeyGrab
703 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
704 NULL, getKeybind, setKeyGrab
706 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
707 NULL, getKeybind, setKeyGrab
709 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
710 NULL, getKeybind, setKeyGrab
712 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
713 NULL, getKeybind, setKeyGrab
715 #endif /* EXTEND_WINDOWSHORTCUT */
717 #ifdef KEEP_XKB_LOCK_STATUS
718 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
719 NULL, getKeybind, setKeyGrab
721 {"KbdModeLock", "NO", NULL,
722 &wPreferences.modelock, getBool, NULL
724 #endif /* KEEP_XKB_LOCK_STATUS */
725 #ifdef TITLE_TEXT_SHADOW
726 ,{"FShadowColor", "black", (void*)WS_SFOCUSED,
727 NULL, getColor, setWTitleColor
729 {"PShadowColor", "black", (void*)WS_SPFOCUSED,
730 NULL, getColor, setWTitleColor
732 {"UShadowColor", "grey50", (void*)WS_SUNFOCUSED,
733 NULL, getColor, setWTitleColor
735 {"MShadowColor", "black", (void*)WS_SMENU,
736 NULL, getColor, setMenuTitleColor
738 {"Shadow", "Yes", NULL,
739 &wPreferences.title_shadow, getBool, setJustify
741 #endif /* TITLE_TEXT_SHADOW */
745 #if 0
746 static void rereadDefaults(void);
747 #endif
749 #if 0
750 static void
751 rereadDefaults(void)
753 /* must defer the update because accessing X data from a
754 * signal handler can mess up Xlib */
757 #endif
759 static void
760 initDefaults()
762 int i;
763 WDefaultEntry *entry;
765 PLSetStringCmpHook(StringCompareHook);
767 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
768 entry = &optionList[i];
770 entry->plkey = PLMakeString(entry->key);
771 if (entry->default_value)
772 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
773 else
774 entry->plvalue = NULL;
777 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
778 entry = &staticOptionList[i];
780 entry->plkey = PLMakeString(entry->key);
781 if (entry->default_value)
782 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
783 else
784 entry->plvalue = NULL;
788 wDomainName = PLMakeString(WMDOMAIN_NAME);
789 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
791 PLRegister(wDomainName, rereadDefaults);
792 PLRegister(wAttributeDomainName, rereadDefaults);
799 #if 0
800 proplist_t
801 wDefaultsInit(int screen_number)
803 static int defaults_inited = 0;
804 proplist_t dict;
806 if (!defaults_inited) {
807 initDefaults();
810 dict = PLGetDomain(wDomainName);
811 if (!dict) {
812 wwarning(_("could not read domain \"%s\" from defaults database"),
813 PLGetString(wDomainName));
816 return dict;
818 #endif
821 void
822 wDefaultsDestroyDomain(WDDomain *domain)
824 if (domain->dictionary)
825 PLRelease(domain->dictionary);
826 free(domain->path);
827 free(domain);
831 WDDomain*
832 wDefaultsInitDomain(char *domain, Bool requireDictionary)
834 WDDomain *db;
835 struct stat stbuf;
836 static int inited = 0;
837 char path[PATH_MAX];
838 char *the_path;
839 proplist_t shared_dict=NULL;
841 if (!inited) {
842 inited = 1;
843 initDefaults();
846 db = wmalloc(sizeof(WDDomain));
847 memset(db, 0, sizeof(WDDomain));
848 db->domain_name = domain;
849 db->path = wdefaultspathfordomain(domain);
850 the_path = db->path;
852 if (the_path && stat(the_path, &stbuf)>=0) {
853 db->dictionary = ReadProplistFromFile(the_path);
854 if (db->dictionary) {
855 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
856 PLRelease(db->dictionary);
857 db->dictionary = NULL;
858 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
859 domain, the_path);
861 db->timestamp = stbuf.st_mtime;
862 } else {
863 wwarning(_("could not load domain %s from user defaults database"),
864 domain);
868 /* global system dictionary */
869 sprintf(path, "%s/%s", SYSCONFDIR, domain);
870 if (stat(path, &stbuf)>=0) {
871 shared_dict = ReadProplistFromFile(path);
872 if (shared_dict) {
873 if (requireDictionary && !PLIsDictionary(shared_dict)) {
874 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
875 domain, path);
876 PLRelease(shared_dict);
877 shared_dict = NULL;
878 } else {
879 if (db->dictionary && PLIsDictionary(shared_dict) &&
880 PLIsDictionary(db->dictionary)) {
881 PLMergeDictionaries(shared_dict, db->dictionary);
882 PLRelease(db->dictionary);
883 db->dictionary = shared_dict;
884 if (stbuf.st_mtime > db->timestamp)
885 db->timestamp = stbuf.st_mtime;
886 } else if (!db->dictionary) {
887 db->dictionary = shared_dict;
888 if (stbuf.st_mtime > db->timestamp)
889 db->timestamp = stbuf.st_mtime;
892 } else {
893 wwarning(_("could not load domain %s from global defaults database"),
894 domain);
898 /* set to save it in user's directory, no matter from where it was read */
899 if (db->dictionary) {
900 proplist_t tmp = PLMakeString(db->path);
902 PLSetFilename(db->dictionary, tmp);
903 PLRelease(tmp);
906 return db;
910 void
911 wReadStaticDefaults(proplist_t dict)
913 proplist_t plvalue;
914 WDefaultEntry *entry;
915 int i;
916 void *tdata;
919 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
920 entry = &staticOptionList[i];
922 if (dict)
923 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
924 else
925 plvalue = NULL;
927 if (!plvalue) {
928 /* no default in the DB. Use builtin default */
929 plvalue = entry->plvalue;
932 if (plvalue) {
933 /* convert data */
934 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
935 if (entry->update) {
936 (*entry->update)(NULL, entry, tdata, entry->extra_data);
943 void
944 wDefaultsCheckDomains(void *foo)
946 WScreen *scr;
947 struct stat stbuf;
948 proplist_t dict;
949 int i;
950 char path[PATH_MAX];
952 #ifdef HEARTBEAT
953 puts("Checking domains...");
954 #endif
955 if (stat(WDWindowMaker->path, &stbuf)>=0
956 && WDWindowMaker->timestamp < stbuf.st_mtime) {
957 proplist_t shared_dict = NULL;
958 #ifdef HEARTBEAT
959 puts("Checking WindowMaker domain");
960 #endif
961 WDWindowMaker->timestamp = stbuf.st_mtime;
963 /* global dictionary */
964 sprintf(path, "%s/WindowMaker", SYSCONFDIR);
965 if (stat(path, &stbuf)>=0) {
966 shared_dict = ReadProplistFromFile(path);
967 if (shared_dict && !PLIsDictionary(shared_dict)) {
968 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
969 "WindowMaker", path);
970 PLRelease(shared_dict);
971 shared_dict = NULL;
972 } else if (!shared_dict) {
973 wwarning(_("could not load domain %s from global defaults database"),
974 "WindowMaker");
977 /* user dictionary */
978 dict = ReadProplistFromFile(WDWindowMaker->path);
979 if (dict) {
980 if (!PLIsDictionary(dict)) {
981 PLRelease(dict);
982 dict = NULL;
983 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
984 "WindowMaker", WDWindowMaker->path);
985 } else {
986 if (shared_dict) {
987 PLSetFilename(shared_dict, PLGetFilename(dict));
988 PLMergeDictionaries(shared_dict, dict);
989 PLRelease(dict);
990 dict = shared_dict;
991 shared_dict = NULL;
993 for (i=0; i<wScreenCount; i++) {
994 scr = wScreenWithNumber(i);
995 if (scr)
996 wReadDefaults(scr, dict);
998 if (WDWindowMaker->dictionary) {
999 PLRelease(WDWindowMaker->dictionary);
1001 WDWindowMaker->dictionary = dict;
1003 } else {
1004 wwarning(_("could not load domain %s from user defaults database"),
1005 "WindowMaker");
1007 if (shared_dict) {
1008 PLRelease(shared_dict);
1012 if (stat(WDWindowAttributes->path, &stbuf)>=0
1013 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1014 #ifdef HEARTBEAT
1015 puts("Checking WMWindowAttributes domain");
1016 #endif
1017 dict = ReadProplistFromFile(WDWindowAttributes->path);
1018 if (dict) {
1019 if (!PLIsDictionary(dict)) {
1020 PLRelease(dict);
1021 dict = NULL;
1022 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1023 "WMWindowAttributes", WDWindowAttributes->path);
1024 } else {
1025 if (WDWindowAttributes->dictionary)
1026 PLRelease(WDWindowAttributes->dictionary);
1027 WDWindowAttributes->dictionary = dict;
1028 for (i=0; i<wScreenCount; i++) {
1029 scr = wScreenWithNumber(i);
1030 if (scr)
1031 wDefaultUpdateIcons(scr);
1034 } else {
1035 wwarning(_("could not load domain %s from user defaults database"),
1036 "WMWindowAttributes");
1038 WDWindowAttributes->timestamp = stbuf.st_mtime;
1041 #ifndef LITE
1042 if (stat(WDRootMenu->path, &stbuf)>=0
1043 && WDRootMenu->timestamp < stbuf.st_mtime) {
1044 dict = ReadProplistFromFile(WDRootMenu->path);
1045 #ifdef HEARTBEAT
1046 puts("Checking WMRootMenu domain");
1047 #endif
1048 if (dict) {
1049 if (!PLIsArray(dict) && !PLIsString(dict)) {
1050 PLRelease(dict);
1051 dict = NULL;
1052 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1053 "WMRootMenu", WDRootMenu->path);
1054 } else {
1055 if (WDRootMenu->dictionary) {
1056 PLRelease(WDRootMenu->dictionary);
1058 WDRootMenu->dictionary = dict;
1060 } else {
1061 wwarning(_("could not load domain %s from user defaults database"),
1062 "WMRootMenu");
1064 WDRootMenu->timestamp = stbuf.st_mtime;
1066 #endif /* !LITE */
1068 if (!foo)
1069 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1073 void
1074 wReadDefaults(WScreen *scr, proplist_t new_dict)
1076 proplist_t plvalue, old_value;
1077 WDefaultEntry *entry;
1078 int i, must_update;
1079 int needs_refresh;
1080 void *tdata;
1081 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1082 ? WDWindowMaker->dictionary : NULL);
1084 must_update = 0;
1086 needs_refresh = 0;
1088 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1089 entry = &optionList[i];
1091 if (new_dict)
1092 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1093 else
1094 plvalue = NULL;
1096 if (!old_dict)
1097 old_value = NULL;
1098 else
1099 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1102 if (!plvalue && !old_value) {
1103 /* no default in the DB. Use builtin default */
1104 plvalue = entry->plvalue;
1105 if (plvalue && new_dict) {
1106 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1107 must_update = 1;
1109 } else if (!plvalue) {
1110 /* value was deleted from DB. Keep current value */
1111 continue;
1112 } else if (!old_value) {
1113 /* set value for the 1st time */
1114 } else if (!PLIsEqual(plvalue, old_value)) {
1115 /* value has changed */
1116 } else {
1117 /* value was not changed since last time */
1118 continue;
1121 if (plvalue) {
1122 #ifdef DEBUG
1123 printf("Updating %s to %s\n", entry->key, PLGetDescription(plvalue));
1124 #endif
1125 /* convert data */
1126 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1127 if (entry->update) {
1128 needs_refresh |=
1129 (*entry->update)(scr, entry, tdata, entry->extra_data);
1135 if (needs_refresh!=0 && !scr->flags.startup) {
1136 int foo;
1138 foo = 0;
1139 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1140 foo |= WTextureSettings;
1141 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1142 foo |= WFontSettings;
1143 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1144 foo |= WColorSettings;
1145 if (foo)
1146 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1147 (void*)foo);
1149 foo = 0;
1150 if (needs_refresh & REFRESH_MENU_TEXTURE)
1151 foo |= WTextureSettings;
1152 if (needs_refresh & REFRESH_MENU_FONT)
1153 foo |= WFontSettings;
1154 if (needs_refresh & REFRESH_MENU_COLOR)
1155 foo |= WColorSettings;
1156 if (foo)
1157 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1158 (void*)foo);
1160 foo = 0;
1161 if (needs_refresh & REFRESH_WINDOW_FONT) {
1162 foo |= WFontSettings;
1164 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1165 foo |= WTextureSettings;
1167 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1168 foo |= WColorSettings;
1170 if (foo)
1171 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1172 (void*)foo);
1174 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1175 foo = 0;
1176 if (needs_refresh & REFRESH_ICON_FONT) {
1177 foo |= WFontSettings;
1179 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1180 foo |= WTextureSettings;
1182 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1183 foo |= WTextureSettings;
1185 if (foo)
1186 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1187 (void*)foo);
1189 if (needs_refresh & REFRESH_ICON_TILE)
1190 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1195 void
1196 wDefaultUpdateIcons(WScreen *scr)
1198 WAppIcon *aicon = scr->app_icon_list;
1199 WWindow *wwin = scr->focused_window;
1200 char *file;
1202 while(aicon) {
1203 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1204 False);
1205 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1206 || (file && !aicon->icon->file)) {
1207 RImage *new_image;
1209 if (aicon->icon->file)
1210 free(aicon->icon->file);
1211 aicon->icon->file = wstrdup(file);
1213 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1214 aicon->wm_class);
1215 if (new_image) {
1216 wIconChangeImage(aicon->icon, new_image);
1217 wAppIconPaint(aicon);
1220 aicon = aicon->next;
1223 if (!wPreferences.flags.noclip)
1224 wClipIconPaint(scr->clip_icon);
1226 while (wwin) {
1227 if (wwin->icon && wwin->flags.miniaturized) {
1228 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1229 False);
1230 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1231 || (file && !wwin->icon->file)) {
1232 RImage *new_image;
1234 if (wwin->icon->file)
1235 free(wwin->icon->file);
1236 wwin->icon->file = wstrdup(file);
1238 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1239 wwin->wm_class);
1240 if (new_image)
1241 wIconChangeImage(wwin->icon, new_image);
1244 wwin = wwin->prev;
1249 /* --------------------------- Local ----------------------- */
1251 #define STRINGP(x) if (!PLIsString(value)) { \
1252 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1253 entry->key, x); \
1254 return False; }
1258 static int
1259 string2index(proplist_t key, proplist_t val, proplist_t def,
1260 WOptionEnumeration *values)
1262 char *str;
1263 WOptionEnumeration *v;
1264 char buffer[TOTAL_VALUES_LENGTH];
1266 if (PLIsString(val) && (str = PLGetString(val))) {
1267 for (v=values; v->string!=NULL; v++) {
1268 if (strcasecmp(v->string, str)==0)
1269 return v->value;
1273 buffer[0] = 0;
1274 for (v=values; v->string!=NULL; v++) {
1275 if (!v->is_alias) {
1276 if (buffer[0]!=0)
1277 strcat(buffer, ", ");
1278 strcat(buffer, v->string);
1281 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1282 PLGetString(key), buffer);
1284 if (def) {
1285 return string2index(key, val, NULL, values);
1288 return -1;
1295 * value - is the value in the defaults DB
1296 * addr - is the address to store the data
1297 * ret - is the address to store a pointer to a temporary buffer. ret
1298 * must not be freed and is used by the set functions
1300 static int
1301 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1302 void **ret)
1304 static char data;
1305 char *val;
1306 int second_pass=0;
1308 STRINGP("Boolean");
1310 val = PLGetString(value);
1312 again:
1313 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1314 || strcasecmp(val, "YES")==0) {
1316 data = 1;
1317 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1318 || strcasecmp(val, "NO")==0) {
1319 data = 0;
1320 } else {
1321 int i;
1322 if (sscanf(val, "%i", &i)==1) {
1323 if (i!=0)
1324 data = 1;
1325 else
1326 data = 0;
1327 } else {
1328 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1329 val, entry->key);
1330 if (second_pass==0) {
1331 val = PLGetString(entry->plvalue);
1332 second_pass = 1;
1333 wwarning(_("using default \"%s\" instead"), val);
1334 goto again;
1336 return False;
1340 if (ret)
1341 *ret = &data;
1343 if (addr) {
1344 *(char*)addr = data;
1347 return True;
1351 static int
1352 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1353 void **ret)
1355 static int data;
1356 char *val;
1359 STRINGP("Integer");
1361 val = PLGetString(value);
1363 if (sscanf(val, "%i", &data)!=1) {
1364 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1365 val, entry->key);
1366 val = PLGetString(entry->plvalue);
1367 wwarning(_("using default \"%s\" instead"), val);
1368 if (sscanf(val, "%i", &data)!=1) {
1369 return False;
1373 if (ret)
1374 *ret = &data;
1376 if (addr) {
1377 *(int*)addr = data;
1379 return True;
1383 static int
1384 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1385 void **ret)
1387 static WCoord data;
1388 char *val_x, *val_y;
1389 int nelem, changed=0;
1390 proplist_t elem_x, elem_y;
1392 again:
1393 if (!PLIsArray(value)) {
1394 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1395 entry->key, "Coordinate");
1396 if (changed==0) {
1397 value = entry->plvalue;
1398 changed = 1;
1399 wwarning(_("using default \"%s\" instead"), entry->default_value);
1400 goto again;
1402 return False;
1405 nelem = PLGetNumberOfElements(value);
1406 if (nelem != 2) {
1407 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1408 entry->key);
1409 if (changed==0) {
1410 value = entry->plvalue;
1411 changed = 1;
1412 wwarning(_("using default \"%s\" instead"), entry->default_value);
1413 goto again;
1415 return False;
1418 elem_x = PLGetArrayElement(value, 0);
1419 elem_y = PLGetArrayElement(value, 1);
1421 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1422 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1423 entry->key);
1424 if (changed==0) {
1425 value = entry->plvalue;
1426 changed = 1;
1427 wwarning(_("using default \"%s\" instead"), entry->default_value);
1428 goto again;
1430 return False;
1433 val_x = PLGetString(elem_x);
1434 val_y = PLGetString(elem_y);
1436 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1437 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1438 if (changed==0) {
1439 value = entry->plvalue;
1440 changed = 1;
1441 wwarning(_("using default \"%s\" instead"), entry->default_value);
1442 goto again;
1444 return False;
1447 if (data.x < 0)
1448 data.x = 0;
1449 else if (data.x > scr->scr_width/3)
1450 data.x = scr->scr_width/3;
1451 if (data.y < 0)
1452 data.y = 0;
1453 else if (data.y > scr->scr_height/3)
1454 data.y = scr->scr_height/3;
1456 if (ret)
1457 *ret = &data;
1459 if (addr) {
1460 *(WCoord*)addr = data;
1463 return True;
1467 #if 0
1468 /* This function is not used at the moment. */
1469 static int
1470 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1471 void **ret)
1473 static char *data;
1475 STRINGP("String");
1477 data = PLGetString(value);
1479 if (!data) {
1480 data = PLGetString(entry->plvalue);
1481 if (!data)
1482 return False;
1485 if (ret)
1486 *ret = &data;
1488 if (addr)
1489 *(char**)addr = wstrdup(data);
1491 return True;
1493 #endif
1496 static int
1497 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1498 void **ret)
1500 static char *data;
1501 int i, count, len;
1502 char *ptr;
1503 proplist_t d;
1504 int changed=0;
1506 again:
1507 if (!PLIsArray(value)) {
1508 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1509 entry->key, "an array of paths");
1510 if (changed==0) {
1511 value = entry->plvalue;
1512 changed = 1;
1513 wwarning(_("using default \"%s\" instead"), entry->default_value);
1514 goto again;
1516 return False;
1519 i = 0;
1520 count = PLGetNumberOfElements(value);
1521 if (count < 1) {
1522 if (changed==0) {
1523 value = entry->plvalue;
1524 changed = 1;
1525 wwarning(_("using default \"%s\" instead"), entry->default_value);
1526 goto again;
1528 return False;
1531 len = 0;
1532 for (i=0; i<count; i++) {
1533 d = PLGetArrayElement(value, i);
1534 if (!d || !PLIsString(d)) {
1535 count = i;
1536 break;
1538 len += strlen(PLGetString(d))+1;
1541 ptr = data = wmalloc(len+1);
1543 for (i=0; i<count; i++) {
1544 d = PLGetArrayElement(value, i);
1545 if (!d || !PLIsString(d)) {
1546 break;
1548 strcpy(ptr, PLGetString(d));
1549 ptr += strlen(PLGetString(d));
1550 *ptr = ':';
1551 ptr++;
1553 ptr--; *(ptr--) = 0;
1555 if (*(char**)addr!=NULL) {
1556 free(*(char**)addr);
1558 *(char**)addr = data;
1560 return True;
1564 static int
1565 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1566 void **ret)
1568 static signed char data;
1570 data = string2index(entry->plkey, value, entry->default_value,
1571 (WOptionEnumeration*)entry->extra_data);
1572 if (data < 0)
1573 return False;
1575 if (ret)
1576 *ret = &data;
1578 if (addr)
1579 *(signed char*)addr = data;
1581 return True;
1587 * (solid <color>)
1588 * (hgradient <color> <color>)
1589 * (vgradient <color> <color>)
1590 * (dgradient <color> <color>)
1591 * (mhgradient <color> <color> ...)
1592 * (mvgradient <color> <color> ...)
1593 * (tpixmap <file> <color>)
1594 * (spixmap <file> <color>)
1595 * (cpixmap <file> <color>)
1596 * (thgradient <file> <opaqueness> <color> <color>)
1597 * (tvgradient <file> <opaqueness> <color> <color>)
1598 * (tdgradient <file> <opaqueness> <color> <color>)
1599 * (function <lib> <function> ...)
1602 static WTexture*
1603 parse_texture(WScreen *scr, proplist_t pl)
1605 proplist_t elem;
1606 char *val;
1607 int nelem;
1608 WTexture *texture=NULL;
1610 nelem = PLGetNumberOfElements(pl);
1611 if (nelem < 1)
1612 return NULL;
1615 elem = PLGetArrayElement(pl, 0);
1616 if (!elem || !PLIsString(elem))
1617 return NULL;
1618 val = PLGetString(elem);
1621 if (strcasecmp(val, "solid")==0) {
1622 XColor color;
1624 if (nelem != 2)
1625 return NULL;
1627 /* get color */
1629 elem = PLGetArrayElement(pl, 1);
1630 if (!elem || !PLIsString(elem))
1631 return NULL;
1632 val = PLGetString(elem);
1634 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1635 wwarning(_("\"%s\" is not a valid color name"), val);
1636 return NULL;
1639 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1640 } else if (strcasecmp(val, "dgradient")==0
1641 || strcasecmp(val, "vgradient")==0
1642 || strcasecmp(val, "hgradient")==0) {
1643 RColor color1, color2;
1644 XColor xcolor;
1645 int type;
1647 if (nelem != 3) {
1648 wwarning(_("bad number of arguments in gradient specification"));
1649 return NULL;
1652 if (val[0]=='d' || val[0]=='D')
1653 type = WTEX_DGRADIENT;
1654 else if (val[0]=='h' || val[0]=='H')
1655 type = WTEX_HGRADIENT;
1656 else
1657 type = WTEX_VGRADIENT;
1660 /* get from color */
1661 elem = PLGetArrayElement(pl, 1);
1662 if (!elem || !PLIsString(elem))
1663 return NULL;
1664 val = PLGetString(elem);
1666 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1667 wwarning(_("\"%s\" is not a valid color name"), val);
1668 return NULL;
1670 color1.alpha = 255;
1671 color1.red = xcolor.red >> 8;
1672 color1.green = xcolor.green >> 8;
1673 color1.blue = xcolor.blue >> 8;
1675 /* get to color */
1676 elem = PLGetArrayElement(pl, 2);
1677 if (!elem || !PLIsString(elem)) {
1678 return NULL;
1680 val = PLGetString(elem);
1682 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1683 wwarning(_("\"%s\" is not a valid color name"), val);
1684 return NULL;
1686 color2.alpha = 255;
1687 color2.red = xcolor.red >> 8;
1688 color2.green = xcolor.green >> 8;
1689 color2.blue = xcolor.blue >> 8;
1691 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1693 } else if (strcasecmp(val, "mhgradient")==0
1694 || strcasecmp(val, "mvgradient")==0
1695 || strcasecmp(val, "mdgradient")==0) {
1696 XColor color;
1697 RColor **colors;
1698 int i, count;
1699 int type;
1701 if (nelem < 3) {
1702 wwarning(_("too few arguments in multicolor gradient specification"));
1703 return NULL;
1706 if (val[1]=='h' || val[1]=='H')
1707 type = WTEX_MHGRADIENT;
1708 else if (val[1]=='v' || val[1]=='V')
1709 type = WTEX_MVGRADIENT;
1710 else
1711 type = WTEX_MDGRADIENT;
1713 count = nelem-1;
1715 colors = wmalloc(sizeof(RColor*)*(count+1));
1717 for (i=0; i<count; i++) {
1718 elem = PLGetArrayElement(pl, i+1);
1719 if (!elem || !PLIsString(elem)) {
1720 for (--i; i>=0; --i) {
1721 free(colors[i]);
1723 free(colors);
1724 return NULL;
1726 val = PLGetString(elem);
1728 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1729 wwarning(_("\"%s\" is not a valid color name"), val);
1730 for (--i; i>=0; --i) {
1731 free(colors[i]);
1733 free(colors);
1734 return NULL;
1735 } else {
1736 colors[i] = wmalloc(sizeof(RColor));
1737 colors[i]->red = color.red >> 8;
1738 colors[i]->green = color.green >> 8;
1739 colors[i]->blue = color.blue >> 8;
1742 colors[i] = NULL;
1744 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1745 } else if (strcasecmp(val, "spixmap")==0 ||
1746 strcasecmp(val, "cpixmap")==0 ||
1747 strcasecmp(val, "tpixmap")==0) {
1748 XColor color;
1749 int type;
1751 if (nelem != 3)
1752 return NULL;
1754 if (val[0] == 's' || val[0] == 'S')
1755 type = WTP_SCALE;
1756 else if (val[0] == 'c' || val[0] == 'C')
1757 type = WTP_CENTER;
1758 else
1759 type = WTP_TILE;
1761 /* get color */
1762 elem = PLGetArrayElement(pl, 2);
1763 if (!elem || !PLIsString(elem)) {
1764 return NULL;
1766 val = PLGetString(elem);
1768 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1769 wwarning(_("\"%s\" is not a valid color name"), val);
1770 return NULL;
1773 /* file name */
1774 elem = PLGetArrayElement(pl, 1);
1775 if (!elem || !PLIsString(elem))
1776 return NULL;
1777 val = PLGetString(elem);
1779 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1780 } else if (strcasecmp(val, "thgradient")==0
1781 || strcasecmp(val, "tvgradient")==0
1782 || strcasecmp(val, "tdgradient")==0) {
1783 RColor color1, color2;
1784 XColor xcolor;
1785 int opacity;
1786 int style;
1788 if (val[1]=='h' || val[1]=='H')
1789 style = WTEX_THGRADIENT;
1790 else if (val[1]=='v' || val[1]=='V')
1791 style = WTEX_TVGRADIENT;
1792 else
1793 style = WTEX_TDGRADIENT;
1795 if (nelem != 5) {
1796 wwarning(_("bad number of arguments in textured gradient specification"));
1797 return NULL;
1800 /* get from color */
1801 elem = PLGetArrayElement(pl, 3);
1802 if (!elem || !PLIsString(elem))
1803 return NULL;
1804 val = PLGetString(elem);
1806 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1807 wwarning(_("\"%s\" is not a valid color name"), val);
1808 return NULL;
1810 color1.alpha = 255;
1811 color1.red = xcolor.red >> 8;
1812 color1.green = xcolor.green >> 8;
1813 color1.blue = xcolor.blue >> 8;
1815 /* get to color */
1816 elem = PLGetArrayElement(pl, 4);
1817 if (!elem || !PLIsString(elem)) {
1818 return NULL;
1820 val = PLGetString(elem);
1822 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1823 wwarning(_("\"%s\" is not a valid color name"), val);
1824 return NULL;
1826 color2.alpha = 255;
1827 color2.red = xcolor.red >> 8;
1828 color2.green = xcolor.green >> 8;
1829 color2.blue = xcolor.blue >> 8;
1831 /* get opacity */
1832 elem = PLGetArrayElement(pl, 2);
1833 if (!elem || !PLIsString(elem))
1834 opacity = 128;
1835 else
1836 val = PLGetString(elem);
1838 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1839 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1840 opacity = 128;
1843 /* get file name */
1844 elem = PLGetArrayElement(pl, 1);
1845 if (!elem || !PLIsString(elem))
1846 return NULL;
1847 val = PLGetString(elem);
1849 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1850 val, opacity);
1852 #ifdef TEXTURE_PLUGIN
1853 else if (strcasecmp(val, "function")==0) {
1854 WTexFunction *function;
1855 void (*initFunc) (Display *, Colormap);
1856 char *lib, *func, **argv;
1857 int i, argc;
1859 if (nelem < 3)
1860 return NULL;
1862 /* get the library name */
1863 elem = PLGetArrayElement(pl, 1);
1864 if (!elem || !PLIsString(elem)) {
1865 return NULL;
1867 lib = PLGetString(elem);
1869 /* get the function name */
1870 elem = PLGetArrayElement(pl, 2);
1871 if (!elem || !PLIsString(elem)) {
1872 return NULL;
1874 func = PLGetString(elem);
1876 argc = nelem - 2;
1877 argv = (char **)wmalloc(argc * sizeof(char *));
1879 /* get the parameters */
1880 argv[0] = wstrdup(func);
1881 for (i = 0; i < argc - 1; i++) {
1882 elem = PLGetArrayElement(pl, 3 + i);
1883 if (!elem || !PLIsString(elem)) {
1884 free(argv);
1886 return NULL;
1888 argv[i+1] = wstrdup(PLGetString(elem));
1891 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1893 #ifdef HAVE_DLFCN_H
1894 if (function) {
1895 initFunc = dlsym(function->handle, "initWindowMaker");
1896 if (initFunc) {
1897 initFunc(dpy, scr->w_colormap);
1898 } else {
1899 wwarning(_("could not initialize library %s"), lib);
1901 } else {
1902 wwarning(_("could not find function %s::%s"), lib, func);
1904 #endif /* HAVE_DLFCN_H */
1905 texture = (WTexture*)function;
1907 #endif /* TEXTURE_PLUGIN */
1908 else {
1909 wwarning(_("invalid texture type %s"), val);
1910 return NULL;
1912 return texture;
1917 static int
1918 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1919 void **ret)
1921 static WTexture *texture;
1922 int changed=0;
1924 again:
1925 if (!PLIsArray(value)) {
1926 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1927 entry->key, "Texture");
1928 if (changed==0) {
1929 value = entry->plvalue;
1930 changed = 1;
1931 wwarning(_("using default \"%s\" instead"), entry->default_value);
1932 goto again;
1934 return False;
1937 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
1938 proplist_t pl;
1940 pl = PLGetArrayElement(value, 0);
1941 if (!pl || !PLIsString(pl) || !PLGetString(pl)
1942 || strcasecmp(PLGetString(pl), "solid")!=0) {
1943 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1944 entry->key, "Solid Texture");
1946 value = entry->plvalue;
1947 changed = 1;
1948 wwarning(_("using default \"%s\" instead"), entry->default_value);
1949 goto again;
1953 texture = parse_texture(scr, value);
1955 if (!texture) {
1956 wwarning(_("Error in texture specification for key \"%s\""),
1957 entry->key);
1958 if (changed==0) {
1959 value = entry->plvalue;
1960 changed = 1;
1961 wwarning(_("using default \"%s\" instead"), entry->default_value);
1962 goto again;
1964 return False;
1967 if (ret)
1968 *ret = &texture;
1970 if (addr)
1971 *(WTexture**)addr = texture;
1973 return True;
1978 static int
1979 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
1980 void *addr, void **ret)
1982 proplist_t elem;
1983 int changed = 0;
1984 char *val;
1985 int nelem;
1987 again:
1988 if (!PLIsArray(value)) {
1989 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1990 "WorkspaceBack", "Texture or None");
1991 if (changed==0) {
1992 value = entry->plvalue;
1993 changed = 1;
1994 wwarning(_("using default \"%s\" instead"), entry->default_value);
1995 goto again;
1997 return False;
2000 /* only do basic error checking and verify for None texture */
2002 nelem = PLGetNumberOfElements(value);
2003 if (nelem > 0) {
2004 elem = PLGetArrayElement(value, 0);
2005 if (!elem || !PLIsString(elem)) {
2006 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2007 if (changed==0) {
2008 value = entry->plvalue;
2009 changed = 1;
2010 wwarning(_("using default \"%s\" instead"), entry->default_value);
2011 goto again;
2013 return False;
2015 val = PLGetString(elem);
2017 if (strcasecmp(val, "None")==0)
2018 return True;
2020 *ret = PLRetain(value);
2022 return True;
2026 static int
2027 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2028 void *addr, void **ret)
2030 proplist_t elem;
2031 int nelem;
2032 int changed = 0;
2034 again:
2035 if (!PLIsArray(value)) {
2036 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2037 "WorkspaceSpecificBack", "an array of textures");
2038 if (changed==0) {
2039 value = entry->plvalue;
2040 changed = 1;
2041 wwarning(_("using default \"%s\" instead"), entry->default_value);
2042 goto again;
2044 return False;
2047 /* only do basic error checking and verify for None texture */
2049 nelem = PLGetNumberOfElements(value);
2050 if (nelem > 0) {
2051 while (nelem--) {
2052 elem = PLGetArrayElement(value, nelem);
2053 if (!elem || !PLIsArray(elem)) {
2054 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2055 nelem);
2060 *ret = PLRetain(value);
2062 #ifdef notworking
2064 * Kluge to force wmsetbg helper to set the default background.
2065 * If the WorkspaceSpecificBack is changed once wmaker has started,
2066 * the WorkspaceBack won't be sent to the helper, unless the user
2067 * changes it's value too. So, we must force this by removing the
2068 * value from the defaults DB.
2070 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2071 proplist_t key = PLMakeString("WorkspaceBack");
2073 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2075 PLRelease(key);
2077 #endif
2078 return True;
2082 static int
2083 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2084 void **ret)
2086 static WFont *font;
2087 char *val;
2089 STRINGP("Font");
2091 val = PLGetString(value);
2093 font = wLoadFont(val);
2094 if (!font) {
2095 wfatal(_("could not load any usable font!!!"));
2096 exit(1);
2099 if (ret)
2100 *ret = font;
2102 /* can't assign font value outside update function */
2103 wassertrv(addr == NULL, True);
2105 return True;
2109 static int
2110 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2111 void **ret)
2113 static XColor color;
2114 char *val;
2115 int second_pass=0;
2117 STRINGP("Color");
2119 val = PLGetString(value);
2121 again:
2122 if (!wGetColor(scr, val, &color)) {
2123 wwarning(_("could not get color for key \"%s\""),
2124 entry->key);
2125 if (second_pass==0) {
2126 val = PLGetString(entry->plvalue);
2127 second_pass = 1;
2128 wwarning(_("using default \"%s\" instead"), val);
2129 goto again;
2131 return False;
2134 if (ret)
2135 *ret = &color;
2137 assert(addr==NULL);
2139 if (addr)
2140 *(unsigned long*)addr = pixel;
2143 return True;
2148 static int
2149 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2150 void **ret)
2152 static WShortKey shortcut;
2153 KeySym ksym;
2154 char *val;
2155 char *k;
2156 char buf[128], *b;
2159 STRINGP("Key spec");
2161 val = PLGetString(value);
2163 if (!val || strcasecmp(val, "NONE")==0) {
2164 shortcut.keycode = 0;
2165 shortcut.modifier = 0;
2166 if (ret)
2167 *ret = &shortcut;
2168 return True;
2171 strcpy(buf, val);
2173 b = (char*)buf;
2175 /* get modifiers */
2176 shortcut.modifier = 0;
2177 while ((k = strchr(b, '+'))!=NULL) {
2178 int mod;
2180 *k = 0;
2181 mod = wXModifierFromKey(b);
2182 if (mod<0) {
2183 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2184 return False;
2186 shortcut.modifier |= mod;
2188 b = k+1;
2191 /* get key */
2192 ksym = XStringToKeysym(b);
2194 if (ksym==NoSymbol) {
2195 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2196 val);
2197 return False;
2200 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2201 if (shortcut.keycode==0) {
2202 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2203 return False;
2206 if (ret)
2207 *ret = &shortcut;
2209 return True;
2213 static int
2214 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2215 void **ret)
2217 static unsigned int mask;
2218 char *str;
2220 STRINGP("Modifier Key");
2222 str = PLGetString(value);
2223 if (!str)
2224 return False;
2226 mask = wXModifierFromKey(str);
2227 if (mask < 0) {
2228 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2229 mask = 0;
2230 return False;
2233 if (addr)
2234 *(unsigned int*)addr = mask;
2236 if (ret)
2237 *ret = &mask;
2239 return True;
2243 #ifdef NEWSTUFF
2244 static int
2245 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2246 void *addr, void **ret)
2248 unsigned int mask;
2249 char *str;
2250 RImage *image;
2251 int i, n;
2252 int w, h;
2254 STRINGP("Image File Path");
2256 str = PLGetString(value);
2257 if (!str)
2258 return False;
2260 image = RLoadImage(scr->rcontext, str, 0);
2261 if (!image) {
2262 wwarning(_("could not load image in option %s: %s"), entry->key,
2263 RMessageForError(RErrorCode));
2264 return False;
2267 if (*(RImage**)addr) {
2268 RDestroyImage(*(RImage**)addr);
2270 if (addr)
2271 *(RImage**)addr = image;
2273 assert(ret == NULL);
2275 if (ret)
2276 *(RImage**)ret = image;
2279 return True;
2281 #endif
2284 /* ---------------- value setting functions --------------- */
2285 static int
2286 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2288 return REFRESH_WINDOW_TITLE_COLOR;
2292 static int
2293 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2295 switch (which) {
2296 case WM_DOCK:
2297 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2298 break;
2299 case WM_CLIP:
2300 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2301 break;
2302 default:
2303 break;
2305 return 0;
2309 static int
2310 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2312 if (scr->workspaces) {
2313 wWorkspaceForceChange(scr, scr->current_workspace);
2314 wArrangeIcons(scr, False);
2316 return 0;
2319 #if not_used
2320 static int
2321 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2323 if (*value <= 0)
2324 *(int*)foo = 1;
2326 return 0;
2328 #endif
2332 static int
2333 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2335 Pixmap pixmap;
2336 RImage *img;
2337 int reset = 0;
2339 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2340 wPreferences.icon_size,
2341 ((*texture)->any.type & WREL_BORDER_MASK)
2342 ? WREL_ICON : WREL_FLAT);
2343 if (!img) {
2344 wwarning(_("could not render texture for icon background"));
2345 if (!entry->addr)
2346 wTextureDestroy(scr, *texture);
2347 return 0;
2349 RConvertImage(scr->rcontext, img, &pixmap);
2351 if (scr->icon_tile) {
2352 reset = 1;
2353 RDestroyImage(scr->icon_tile);
2354 XFreePixmap(dpy, scr->icon_tile_pixmap);
2357 scr->icon_tile = img;
2359 if (!wPreferences.flags.noclip) {
2360 if (scr->clip_tile) {
2361 RDestroyImage(scr->clip_tile);
2363 scr->clip_tile = wClipMakeTile(scr, img);
2366 scr->icon_tile_pixmap = pixmap;
2368 if (scr->def_icon_pixmap) {
2369 XFreePixmap(dpy, scr->def_icon_pixmap);
2370 scr->def_icon_pixmap = None;
2372 if (scr->def_ticon_pixmap) {
2373 XFreePixmap(dpy, scr->def_ticon_pixmap);
2374 scr->def_ticon_pixmap = None;
2377 if (scr->icon_back_texture) {
2378 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2380 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2382 if (scr->clip_balloon)
2383 XSetWindowBackground(dpy, scr->clip_balloon,
2384 (*texture)->any.color.pixel);
2387 * Free the texture as nobody else will use it, nor refer to it.
2389 if (!entry->addr)
2390 wTextureDestroy(scr, *texture);
2392 return (reset ? REFRESH_ICON_TILE : 0);
2397 static int
2398 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2400 if (scr->title_font) {
2401 wFreeFont(scr->title_font);
2404 scr->title_font = font;
2406 #ifndef I18N_MB
2407 XSetFont(dpy, scr->window_title_gc, font->font->fid);
2408 #endif
2410 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2414 static int
2415 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2417 if (scr->menu_title_font) {
2418 wFreeFont(scr->menu_title_font);
2421 scr->menu_title_font = font;
2423 #ifndef I18N_MB
2424 XSetFont(dpy, scr->menu_title_gc, font->font->fid);
2425 #endif
2427 return REFRESH_MENU_TITLE_FONT;
2431 static int
2432 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2434 if (scr->menu_entry_font) {
2435 wFreeFont(scr->menu_entry_font);
2438 scr->menu_entry_font = font;
2440 #ifndef I18N_MB
2441 XSetFont(dpy, scr->menu_entry_gc, font->font->fid);
2442 XSetFont(dpy, scr->disabled_menu_entry_gc, font->font->fid);
2443 XSetFont(dpy, scr->select_menu_gc, font->font->fid);
2444 #endif
2446 return REFRESH_MENU_FONT;
2451 static int
2452 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2454 if (scr->icon_title_font) {
2455 wFreeFont(scr->icon_title_font);
2458 scr->icon_title_font = font;
2460 #ifndef I18N_MB
2461 XSetFont(dpy, scr->icon_title_gc, font->font->fid);
2462 #endif
2464 return REFRESH_ICON_FONT;
2468 static int
2469 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2471 if (scr->clip_title_font) {
2472 wFreeFont(scr->clip_title_font);
2475 scr->clip_title_font = font;
2477 #ifndef I18N_MB
2478 XSetFont(dpy, scr->clip_title_gc, font->font->fid);
2479 #endif
2481 return REFRESH_ICON_FONT;
2485 static int
2486 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2488 if (scr->info_text_font) {
2489 wFreeFont(scr->info_text_font);
2492 scr->info_text_font = font;
2494 #ifndef I18N_MB
2495 XSetFont(dpy, scr->info_text_gc, font->font->fid);
2496 XSetFont(dpy, scr->line_gc, font->font->fid);
2497 #endif
2499 /* This test works because the scr structure is initially zeroed out
2500 and None = 0. Any other time, the window should be valid. */
2501 if (scr->geometry_display != None) {
2502 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2503 &scr->geometry_display_height);
2504 XResizeWindow(dpy, scr->geometry_display,
2505 scr->geometry_display_width, scr->geometry_display_height);
2508 return 0;
2512 static int
2513 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2515 if (scr->workspace_name_font) {
2516 wFreeFont(scr->workspace_name_font);
2519 scr->workspace_name_font = font;
2521 return 0;
2525 static int
2526 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2528 if (scr->select_pixel!=scr->white_pixel &&
2529 scr->select_pixel!=scr->black_pixel) {
2530 wFreeColor(scr, scr->select_pixel);
2533 scr->select_pixel = color->pixel;
2535 return REFRESH_MENU_COLOR;
2539 static int
2540 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2542 if (scr->select_text_pixel!=scr->white_pixel &&
2543 scr->select_text_pixel!=scr->black_pixel) {
2544 wFreeColor(scr, scr->select_text_pixel);
2547 scr->select_text_pixel = color->pixel;
2549 return REFRESH_MENU_COLOR;
2553 static int
2554 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2556 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2557 scr->clip_title_pixel[index]!=scr->black_pixel) {
2558 wFreeColor(scr, scr->clip_title_pixel[index]);
2560 scr->clip_title_pixel[index] = color->pixel;
2562 #ifdef GRADIENT_CLIP_ARROW
2563 if (index == CLIP_NORMAL) {
2564 RImage *image;
2565 RColor color1, color2;
2566 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2567 int as = pt - 15; /* 15 = 5+5+5 */
2569 FREE_PIXMAP(scr->clip_arrow_gradient);
2571 color1.red = (color->red >> 8)*6/10;
2572 color1.green = (color->green >> 8)*6/10;
2573 color1.blue = (color->blue >> 8)*6/10;
2575 color2.red = WMIN((color->red >> 8)*20/10, 255);
2576 color2.green = WMIN((color->green >> 8)*20/10, 255);
2577 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2579 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2580 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2581 RDestroyImage(image);
2583 #endif /* GRADIENT_CLIP_ARROW */
2585 return REFRESH_ICON_TITLE_COLOR;
2589 static int
2590 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2592 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2593 scr->window_title_pixel[index]!=scr->black_pixel) {
2594 wFreeColor(scr, scr->window_title_pixel[index]);
2597 scr->window_title_pixel[index] = color->pixel;
2599 if (index == WS_UNFOCUSED)
2600 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2602 return REFRESH_WINDOW_TITLE_COLOR;
2606 static int
2607 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2609 #ifdef TITLE_TEXT_SHADOW
2610 if (index == WS_SMENU){
2611 if (scr->menu_title_pixel[WS_SMENU]!=scr->white_pixel &&
2612 scr->menu_title_pixel[WS_SMENU]!=scr->black_pixel) {
2613 wFreeColor(scr, scr->menu_title_pixel[WS_SMENU]);
2615 scr->menu_title_pixel[WS_SMENU] = color->pixel;
2617 else {
2618 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2619 scr->menu_title_pixel[0]!=scr->black_pixel) {
2620 wFreeColor(scr, scr->menu_title_pixel[0]);
2622 scr->menu_title_pixel[0] = color->pixel;
2624 #else /* !TITLE_TEXT_SHADOW */
2625 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2626 scr->menu_title_pixel[0]!=scr->black_pixel) {
2627 wFreeColor(scr, scr->menu_title_pixel[0]);
2630 scr->menu_title_pixel[0] = color->pixel;
2631 #endif /* !TITLE_TEXT_SHADOW */
2632 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2634 return REFRESH_MENU_TITLE_COLOR;
2638 static int
2639 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2641 XGCValues gcv;
2642 #define gcm (GCForeground|GCBackground|GCFillStyle)
2644 if (scr->mtext_pixel!=scr->white_pixel &&
2645 scr->mtext_pixel!=scr->black_pixel) {
2646 wFreeColor(scr, scr->mtext_pixel);
2649 scr->mtext_pixel = color->pixel;
2651 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2654 if (scr->dtext_pixel == scr->mtext_pixel) {
2655 gcv.foreground = scr->white_pixel;
2656 gcv.background = scr->black_pixel;
2657 gcv.fill_style = FillStippled;
2658 } else {
2659 gcv.foreground = scr->dtext_pixel;
2660 gcv.fill_style = FillSolid;
2662 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2664 return REFRESH_MENU_COLOR;
2665 #undef gcm
2669 static int
2670 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2672 XGCValues gcv;
2673 #define gcm (GCForeground|GCBackground|GCFillStyle)
2675 if (scr->dtext_pixel!=scr->white_pixel &&
2676 scr->dtext_pixel!=scr->black_pixel) {
2677 wFreeColor(scr, scr->dtext_pixel);
2680 scr->dtext_pixel = color->pixel;
2682 if (scr->dtext_pixel == scr->mtext_pixel) {
2683 gcv.foreground = scr->white_pixel;
2684 gcv.background = scr->black_pixel;
2685 gcv.fill_style = FillStippled;
2686 } else {
2687 gcv.foreground = scr->dtext_pixel;
2688 gcv.fill_style = FillSolid;
2690 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2692 return REFRESH_MENU_COLOR;
2693 #undef gcm
2696 static int
2697 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2699 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2701 return REFRESH_ICON_TITLE_COLOR;
2705 static int
2706 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2708 if (scr->icon_title_texture) {
2709 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2711 XQueryColor (dpy, scr->w_colormap, color);
2712 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2714 return REFRESH_ICON_TITLE_BACK;
2718 static void
2719 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2721 close(scr->helper_fd);
2722 scr->helper_fd = 0;
2723 scr->helper_pid = 0;
2724 scr->flags.backimage_helper_launched = 0;
2728 static int
2729 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2730 void *bar)
2732 int i;
2733 proplist_t val;
2734 char *str;
2736 if (scr->flags.backimage_helper_launched) {
2737 if (PLGetNumberOfElements(value)==0) {
2738 SendHelperMessage(scr, 'C', 0, NULL);
2739 SendHelperMessage(scr, 'K', 0, NULL);
2741 PLRelease(value);
2742 return 0;
2744 } else {
2745 pid_t pid;
2746 int filedes[2];
2748 if (PLGetNumberOfElements(value) == 0)
2749 return 0;
2751 if (pipe(filedes) < 0) {
2752 wsyserror("pipe() failed:can't set workspace specific background image");
2754 PLRelease(value);
2755 return 0;
2758 pid = fork();
2759 if (pid < 0) {
2760 wsyserror("fork() failed:can't set workspace specific background image");
2761 if (close(filedes[0]) < 0)
2762 wsyserror("could not close pipe");
2763 if (close(filedes[1]) < 0)
2764 wsyserror("could not close pipe");
2766 } else if (pid == 0) {
2767 SetupEnvironment(scr);
2769 if (close(0) < 0)
2770 wsyserror("could not close pipe");
2771 if (dup(filedes[0]) < 0) {
2772 wsyserror("dup() failed:can't set workspace specific background image");
2774 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2775 wsyserror("could not execute wmsetbg");
2776 exit(1);
2777 } else {
2779 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2780 wsyserror("error setting close-on-exec flag");
2782 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2783 wsyserror("error setting close-on-exec flag");
2786 scr->helper_fd = filedes[1];
2787 scr->helper_pid = pid;
2788 scr->flags.backimage_helper_launched = 1;
2790 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2792 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2796 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2797 val = PLGetArrayElement(value, i);
2798 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2799 str = PLGetDescription(val);
2801 SendHelperMessage(scr, 'S', i+1, str);
2803 free(str);
2804 } else {
2805 SendHelperMessage(scr, 'U', i+1, NULL);
2808 sleep(1);
2810 PLRelease(value);
2811 return 0;
2815 static int
2816 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2817 void *bar)
2819 if (scr->flags.backimage_helper_launched) {
2820 char *str;
2822 if (PLGetNumberOfElements(value)==0) {
2823 SendHelperMessage(scr, 'U', 0, NULL);
2824 } else {
2825 /* set the default workspace background to this one */
2826 str = PLGetDescription(value);
2827 if (str) {
2828 SendHelperMessage(scr, 'S', 0, str);
2829 free(str);
2830 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2831 } else {
2832 SendHelperMessage(scr, 'U', 0, NULL);
2835 } else {
2836 char *command;
2837 char *text;
2839 SetupEnvironment(scr);
2840 text = PLGetDescription(value);
2841 command = wmalloc(strlen(text)+40);
2842 sprintf(command, "wmsetbg -d -p '%s' &", text);
2843 free(text);
2844 system(command);
2845 free(command);
2847 PLRelease(value);
2849 return 0;
2853 static int
2854 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2856 if (scr->widget_texture) {
2857 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2859 scr->widget_texture = *(WTexSolid**)texture;
2861 if (scr->geometry_display != None)
2862 XSetWindowBackground(dpy, scr->geometry_display,
2863 scr->widget_texture->normal.pixel);
2865 return 0;
2869 static int
2870 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2872 if (scr->window_title_texture[WS_FOCUSED]) {
2873 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2875 scr->window_title_texture[WS_FOCUSED] = *texture;
2877 return REFRESH_WINDOW_TEXTURES;
2881 static int
2882 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2884 if (scr->window_title_texture[WS_PFOCUSED]) {
2885 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2887 scr->window_title_texture[WS_PFOCUSED] = *texture;
2889 return REFRESH_WINDOW_TEXTURES;
2893 static int
2894 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2896 if (scr->window_title_texture[WS_UNFOCUSED]) {
2897 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2899 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2901 return REFRESH_WINDOW_TEXTURES;
2905 static int
2906 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2908 if (scr->resizebar_texture[0]) {
2909 wTextureDestroy(scr, scr->resizebar_texture[0]);
2911 scr->resizebar_texture[0] = *texture;
2913 return REFRESH_WINDOW_TEXTURES;
2917 static int
2918 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2920 if (scr->menu_title_texture[0]) {
2921 wTextureDestroy(scr, scr->menu_title_texture[0]);
2923 scr->menu_title_texture[0] = *texture;
2925 return REFRESH_MENU_TITLE_TEXTURE;
2929 static int
2930 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2932 if (scr->menu_item_texture) {
2933 wTextureDestroy(scr, scr->menu_item_texture);
2934 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2936 scr->menu_item_texture = *texture;
2938 scr->menu_item_auxtexture
2939 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2941 return REFRESH_MENU_TEXTURE;
2945 static int
2946 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
2948 WWindow *wwin;
2949 wKeyBindings[index] = *shortcut;
2951 wwin = scr->focused_window;
2953 while (wwin!=NULL) {
2954 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2956 if (!WFLAGP(wwin, no_bind_keys)) {
2957 wWindowSetKeyGrabs(wwin);
2959 wwin = wwin->prev;
2962 return 0;
2966 static int
2967 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2969 wArrangeIcons(scr, True);
2971 return 0;
2975 static int
2976 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2978 wScreenUpdateUsableArea(scr);
2980 return 0;
2984 static int
2985 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2987 return REFRESH_MENU_TEXTURE;
2992 static int
2993 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2995 return REFRESH_BUTTON_IMAGES;
3000 * Very ugly kluge.
3001 * Need access to the double click variables, so that all widgets in
3002 * wmaker panels will have the same dbl-click values.
3003 * TODO: figure a better way of dealing with it.
3005 #include "WINGsP.h"
3007 static int
3008 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3010 extern _WINGsConfiguration WINGsConfiguration;
3012 if (*value <= 0)
3013 *(int*)foo = 1;
3015 WINGsConfiguration.doubleClickDelay = *value;
3017 return 0;