Edge attraction.
[wmaker-crm.git] / src / defaults.c
blob73b4936a2a1ea4842abbdaea55942316d9e68ce5
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();
177 static int setMultiByte();
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}
299 static WOptionEnumeration seDisplayPositions[] = {
300 {"none", WD_NONE, 0},
301 {"center", WD_CENTER, 0},
302 {"top", WD_TOP, 0},
303 {"bottom", WD_BOTTOM, 0},
304 {"topleft", WD_TOPLEFT, 0},
305 {"topright", WD_TOPRIGHT, 0},
306 {"bottomleft", WD_BOTTOMLEFT, 0},
307 {"bottomright", WD_BOTTOMRIGHT, 0}
312 * ALL entries in the tables bellow, NEED to have a default value
313 * defined, and this value needs to be correct.
316 /* these options will only affect the window manager on startup
318 * static defaults can't access the screen data, because it is
319 * created after these defaults are read
321 WDefaultEntry staticOptionList[] = {
323 {"DisableDithering", "NO", NULL,
324 &wPreferences.no_dithering, getBool, NULL
326 {"ColormapSize", "4", NULL,
327 &wPreferences.cmap_size, getInt, NULL
329 /* static by laziness */
330 {"IconSize", "64", NULL,
331 &wPreferences.icon_size, getInt, NULL
333 {"ModifierKey", "Mod1", NULL,
334 &wPreferences.modifier_mask, getModMask, NULL
336 {"DisableWSMouseActions", "NO", NULL,
337 &wPreferences.disable_root_mouse, getBool, NULL
339 {"FocusMode", "manual", seFocusModes,
340 &wPreferences.focus_mode, getEnum, NULL
341 }, /* have a problem when switching from manual to sloppy without restart */
342 {"NewStyle", "NO", NULL,
343 &wPreferences.new_style, getBool, NULL
345 {"DisableDock", "NO", (void*) WM_DOCK,
346 NULL, getBool, setIfDockPresent
348 {"DisableClip", "NO", (void*) WM_CLIP,
349 NULL, getBool, setIfDockPresent
351 {"DisableMiniwindows", "NO", NULL,
352 &wPreferences.disable_miniwindows, getBool, NULL
354 {"MultiByteText", "NO", NULL,
355 &wPreferences.multi_byte_text, getBool, setMultiByte
361 WDefaultEntry optionList[] = {
362 /* dynamic options */
363 {"IconPosition", "blh", seIconPositions,
364 &wPreferences.icon_yard, getEnum, setIconPosition
366 {"IconificationStyle", "Zoom", seIconificationStyles,
367 &wPreferences.iconification_style, getEnum, NULL
369 {"SelectWindowsMouseButton", "Left", seMouseButtons,
370 &wPreferences.select_button, getEnum, NULL
372 {"WindowListMouseButton", "Middle", seMouseButtons,
373 &wPreferences.windowl_button, getEnum, NULL
375 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
376 &wPreferences.menu_button, getEnum, NULL
378 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
379 &wPreferences.pixmap_path, getPathList, NULL
381 {"IconPath", DEF_ICON_PATHS, NULL,
382 &wPreferences.icon_path, getPathList, NULL
384 {"ColormapMode", "auto", seColormapModes,
385 &wPreferences.colormap_mode, getEnum, NULL
387 {"AutoFocus", "NO", NULL,
388 &wPreferences.auto_focus, getBool, NULL
390 {"RaiseDelay", "0", NULL,
391 &wPreferences.raise_delay, getInt, NULL
393 {"CirculateRaise", "NO", NULL,
394 &wPreferences.circ_raise, getBool, NULL
396 {"Superfluous", "NO", NULL,
397 &wPreferences.superfluous, getBool, NULL
399 {"AdvanceToNewWorkspace", "NO", NULL,
400 &wPreferences.ws_advance, getBool, NULL
402 {"CycleWorkspaces", "NO", NULL,
403 &wPreferences.ws_cycle, getBool, NULL
405 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
406 &wPreferences.workspace_name_display_position, getEnum, NULL
408 {"StickyIcons", "NO", NULL,
409 &wPreferences.sticky_icons, getBool, setStickyIcons
411 {"SaveSessionOnExit", "NO", NULL,
412 &wPreferences.save_session_on_exit, getBool, NULL
414 {"WrapMenus", "NO", NULL,
415 &wPreferences.wrap_menus, getBool, NULL
417 {"ScrollableMenus", "NO", NULL,
418 &wPreferences.scrollable_menus, getBool, NULL
420 {"MenuScrollSpeed", "medium", seSpeeds,
421 &wPreferences.menu_scroll_speed, getEnum, NULL
423 {"IconSlideSpeed", "medium", seSpeeds,
424 &wPreferences.icon_slide_speed, getEnum, NULL
426 {"ShadeSpeed", "medium", seSpeeds,
427 &wPreferences.shade_speed, getEnum, NULL
429 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
430 &wPreferences.dblclick_time, getInt, setDoubleClick,
432 {"AlignSubmenus", "NO", NULL,
433 &wPreferences.align_menus, getBool, NULL
435 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
436 &wPreferences.open_transients_with_parent, getBool, NULL
438 {"WindowPlacement", "auto", sePlacements,
439 &wPreferences.window_placement, getEnum, NULL
441 {"IgnoreFocusClick","NO", NULL,
442 &wPreferences.ignore_focus_click, getBool, NULL
444 {"UseSaveUnders", "NO", NULL,
445 &wPreferences.use_saveunders, getBool, NULL
447 {"OpaqueMove", "NO", NULL,
448 &wPreferences.opaque_move, getBool, NULL
450 {"DisableSound", "NO", NULL,
451 &wPreferences.no_sound, getBool, NULL
453 {"DisableAnimations", "NO", NULL,
454 &wPreferences.no_animations, getBool, NULL
456 {"DontLinkWorkspaces","NO", NULL,
457 &wPreferences.no_autowrap, getBool, NULL
459 {"AutoArrangeIcons", "NO", NULL,
460 &wPreferences.auto_arrange_icons, getBool, NULL
462 {"NoWindowOverDock", "NO", NULL,
463 &wPreferences.no_window_over_dock, getBool, updateUsableArea
465 {"NoWindowOverIcons", "NO", NULL,
466 &wPreferences.no_window_over_icons, getBool, updateUsableArea
468 {"WindowPlaceOrigin", "(0, 0)", NULL,
469 &wPreferences.window_place_origin, getCoord, NULL
471 {"ResizeDisplay", "corner", seGeomDisplays,
472 &wPreferences.size_display, getEnum, NULL
474 {"MoveDisplay", "corner", seGeomDisplays,
475 &wPreferences.move_display, getEnum, NULL
477 {"DontConfirmKill", "NO", NULL,
478 &wPreferences.dont_confirm_kill, getBool,NULL
480 {"WindowTitleBalloons", "NO", NULL,
481 &wPreferences.window_balloon, getBool, NULL
483 {"MiniwindowTitleBalloons", "NO", NULL,
484 &wPreferences.miniwin_balloon,getBool, NULL
486 {"AppIconBalloons", "NO", NULL,
487 &wPreferences.appicon_balloon,getBool, NULL
489 {"HelpBalloons", "NO", NULL,
490 &wPreferences.help_balloon, getBool, NULL
492 {"EdgeResistance", "30", NULL,
493 &wPreferences.edge_resistance,getInt, NULL
495 {"Attraction", "NO", NULL,
496 &wPreferences.attract, getBool, NULL
498 {"DisableBlinking", "NO", NULL,
499 &wPreferences.dont_blink, getBool, NULL
501 #ifdef WEENDOZE_CYCLE
502 {"WindozeCycling","NO", NULL,
503 &wPreferences.windoze_cycling, getBool, NULL
505 {"PopupSwitchMenu","YES", NULL,
506 &wPreferences.popup_switchmenu, getBool, NULL
508 #endif /* WEENDOZE_CYCLE */
509 /* style options */
510 {"MenuStyle", "normal", seMenuStyles,
511 &wPreferences.menu_style, getEnum, setMenuStyle
513 {"WidgetColor", "(solid, gray)", NULL,
514 NULL, getTexture, setWidgetColor,
516 {"WorkspaceSpecificBack","()", NULL,
517 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
519 /* WorkspaceBack must come after WorkspaceSpecificBack or
520 * WorkspaceBack wont know WorkspaceSpecificBack was also
521 * specified and 2 copies of wmsetbg will be launched */
522 {"WorkspaceBack", "(solid, black)", NULL,
523 NULL, getWSBackground,setWorkspaceBack
525 {"SmoothWorkspaceBack", "NO", NULL,
526 NULL, getBool, NULL
528 {"IconBack", "(solid, gray)", NULL,
529 NULL, getTexture, setIconTile
531 {"TitleJustify", "center", seJustifications,
532 &wPreferences.title_justification, getEnum, setJustify
534 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
535 NULL, getFont, setWinTitleFont,
537 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
538 NULL, getFont, setMenuTitleFont
540 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
541 NULL, getFont, setMenuTextFont
543 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
544 NULL, getFont, setIconTitleFont
546 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
547 NULL, getFont, setClipTitleFont
549 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
550 NULL, getFont, setDisplayFont
552 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
553 NULL, getFont, setLargeDisplayFont
555 {"HighlightColor", "white", NULL,
556 NULL, getColor, setHightlight
558 {"HighlightTextColor", "black", NULL,
559 NULL, getColor, setHightlightText
561 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
562 NULL, getColor, setClipTitleColor
564 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
565 NULL, getColor, setClipTitleColor
567 {"FTitleColor", "white", (void*)WS_FOCUSED,
568 NULL, getColor, setWTitleColor
570 {"PTitleColor", "white", (void*)WS_PFOCUSED,
571 NULL, getColor, setWTitleColor
573 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
574 NULL, getColor, setWTitleColor
576 {"FTitleBack", "(solid, black)", NULL,
577 NULL, getTexture, setFTitleBack
579 {"PTitleBack", "(solid, \"#616161\")", NULL,
580 NULL, getTexture, setPTitleBack
582 {"UTitleBack", "(solid, gray)", NULL,
583 NULL, getTexture, setUTitleBack
585 {"ResizebarBack", "(solid, gray)", NULL,
586 NULL, getTexture, setResizebarBack
588 {"MenuTitleColor", "white", NULL,
589 NULL, getColor, setMenuTitleColor
591 {"MenuTextColor", "black", NULL,
592 NULL, getColor, setMenuTextColor
594 {"MenuDisabledColor", "\"#616161\"", NULL,
595 NULL, getColor, setMenuDisabledColor
597 {"MenuTitleBack", "(solid, black)", NULL,
598 NULL, getTexture, setMenuTitleBack
600 {"MenuTextBack", "(solid, gray)", NULL,
601 NULL, getTexture, setMenuTextBack
603 {"IconTitleColor", "white", NULL,
604 NULL, getColor, setIconTitleColor
606 {"IconTitleBack", "black", NULL,
607 NULL, getColor, setIconTitleBack
609 /* keybindings */
610 #ifndef LITE
611 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
612 NULL, getKeybind, setKeyGrab
614 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
615 NULL, getKeybind, setKeyGrab
617 #endif /* LITE */
618 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
619 NULL, getKeybind, setKeyGrab
621 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
622 NULL, getKeybind, setKeyGrab
624 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
625 NULL, getKeybind, setKeyGrab
627 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
628 NULL, getKeybind, setKeyGrab
630 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
631 NULL, getKeybind, setKeyGrab
633 {"HideKey", "None", (void*)WKBD_HIDE,
634 NULL, getKeybind, setKeyGrab
636 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
637 NULL, getKeybind, setKeyGrab
639 {"CloseKey", "None", (void*)WKBD_CLOSE,
640 NULL, getKeybind, setKeyGrab
642 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
643 NULL, getKeybind, setKeyGrab
645 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
646 NULL, getKeybind, setKeyGrab
648 {"RaiseKey", "Meta+Up", (void*)WKBD_RAISE,
649 NULL, getKeybind, setKeyGrab
651 {"LowerKey", "Meta+Down", (void*)WKBD_LOWER,
652 NULL, getKeybind, setKeyGrab
654 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
655 NULL, getKeybind, setKeyGrab
657 {"ShadeKey", "None", (void*)WKBD_SHADE,
658 NULL, getKeybind, setKeyGrab
660 {"SelectKey", "None", (void*)WKBD_SELECT,
661 NULL, getKeybind, setKeyGrab
663 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
664 NULL, getKeybind, setKeyGrab
666 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
667 NULL, getKeybind, setKeyGrab
669 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
670 NULL, getKeybind, setKeyGrab
672 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
673 NULL, getKeybind, setKeyGrab
675 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
676 NULL, getKeybind, setKeyGrab
678 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
679 NULL, getKeybind, setKeyGrab
681 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
682 NULL, getKeybind, setKeyGrab
684 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
685 NULL, getKeybind, setKeyGrab
687 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
688 NULL, getKeybind, setKeyGrab
690 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
691 NULL, getKeybind, setKeyGrab
693 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
694 NULL, getKeybind, setKeyGrab
696 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
697 NULL, getKeybind, setKeyGrab
699 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
700 NULL, getKeybind, setKeyGrab
702 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
703 NULL, getKeybind, setKeyGrab
705 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
706 NULL, getKeybind, setKeyGrab
708 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
709 NULL, getKeybind, setKeyGrab
711 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
712 NULL, getKeybind, setKeyGrab
714 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
715 NULL, getKeybind, setKeyGrab
717 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
718 NULL, getKeybind, setKeyGrab
720 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
721 NULL, getKeybind, setKeyGrab
723 #ifdef EXTEND_WINDOWSHORTCUT
724 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
725 NULL, getKeybind, setKeyGrab
727 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
728 NULL, getKeybind, setKeyGrab
730 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
731 NULL, getKeybind, setKeyGrab
733 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
734 NULL, getKeybind, setKeyGrab
736 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
737 NULL, getKeybind, setKeyGrab
739 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
740 NULL, getKeybind, setKeyGrab
742 #endif /* EXTEND_WINDOWSHORTCUT */
744 #ifdef KEEP_XKB_LOCK_STATUS
745 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
746 NULL, getKeybind, setKeyGrab
748 {"KbdModeLock", "NO", NULL,
749 &wPreferences.modelock, getBool, NULL
751 #endif /* KEEP_XKB_LOCK_STATUS */
752 #ifdef TITLE_TEXT_SHADOW
753 ,{"FShadowColor", "black", (void*)WS_SFOCUSED,
754 NULL, getColor, setWTitleColor
756 {"PShadowColor", "black", (void*)WS_SPFOCUSED,
757 NULL, getColor, setWTitleColor
759 {"UShadowColor", "grey50", (void*)WS_SUNFOCUSED,
760 NULL, getColor, setWTitleColor
762 {"MShadowColor", "black", (void*)WS_SMENU,
763 NULL, getColor, setMenuTitleColor
765 {"Shadow", "Yes", NULL,
766 &wPreferences.title_shadow, getBool, setJustify
768 #endif /* TITLE_TEXT_SHADOW */
772 #if 0
773 static void rereadDefaults(void);
774 #endif
776 #if 0
777 static void
778 rereadDefaults(void)
780 /* must defer the update because accessing X data from a
781 * signal handler can mess up Xlib */
784 #endif
786 static void
787 initDefaults()
789 int i;
790 WDefaultEntry *entry;
792 PLSetStringCmpHook(StringCompareHook);
794 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
795 entry = &optionList[i];
797 entry->plkey = PLMakeString(entry->key);
798 if (entry->default_value)
799 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
800 else
801 entry->plvalue = NULL;
804 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
805 entry = &staticOptionList[i];
807 entry->plkey = PLMakeString(entry->key);
808 if (entry->default_value)
809 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
810 else
811 entry->plvalue = NULL;
815 wDomainName = PLMakeString(WMDOMAIN_NAME);
816 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
818 PLRegister(wDomainName, rereadDefaults);
819 PLRegister(wAttributeDomainName, rereadDefaults);
826 #if 0
827 proplist_t
828 wDefaultsInit(int screen_number)
830 static int defaults_inited = 0;
831 proplist_t dict;
833 if (!defaults_inited) {
834 initDefaults();
837 dict = PLGetDomain(wDomainName);
838 if (!dict) {
839 wwarning(_("could not read domain \"%s\" from defaults database"),
840 PLGetString(wDomainName));
843 return dict;
845 #endif
848 void
849 wDefaultsDestroyDomain(WDDomain *domain)
851 if (domain->dictionary)
852 PLRelease(domain->dictionary);
853 free(domain->path);
854 free(domain);
858 WDDomain*
859 wDefaultsInitDomain(char *domain, Bool requireDictionary)
861 WDDomain *db;
862 struct stat stbuf;
863 static int inited = 0;
864 char path[PATH_MAX];
865 char *the_path;
866 proplist_t shared_dict=NULL;
868 if (!inited) {
869 inited = 1;
870 initDefaults();
873 db = wmalloc(sizeof(WDDomain));
874 memset(db, 0, sizeof(WDDomain));
875 db->domain_name = domain;
876 db->path = wdefaultspathfordomain(domain);
877 the_path = db->path;
879 if (the_path && stat(the_path, &stbuf)>=0) {
880 db->dictionary = ReadProplistFromFile(the_path);
881 if (db->dictionary) {
882 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
883 PLRelease(db->dictionary);
884 db->dictionary = NULL;
885 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
886 domain, the_path);
888 db->timestamp = stbuf.st_mtime;
889 } else {
890 wwarning(_("could not load domain %s from user defaults database"),
891 domain);
895 /* global system dictionary */
896 sprintf(path, "%s/%s", SYSCONFDIR, domain);
897 if (stat(path, &stbuf)>=0) {
898 shared_dict = ReadProplistFromFile(path);
899 if (shared_dict) {
900 if (requireDictionary && !PLIsDictionary(shared_dict)) {
901 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
902 domain, path);
903 PLRelease(shared_dict);
904 shared_dict = NULL;
905 } else {
906 if (db->dictionary && PLIsDictionary(shared_dict) &&
907 PLIsDictionary(db->dictionary)) {
908 PLMergeDictionaries(shared_dict, db->dictionary);
909 PLRelease(db->dictionary);
910 db->dictionary = shared_dict;
911 if (stbuf.st_mtime > db->timestamp)
912 db->timestamp = stbuf.st_mtime;
913 } else if (!db->dictionary) {
914 db->dictionary = shared_dict;
915 if (stbuf.st_mtime > db->timestamp)
916 db->timestamp = stbuf.st_mtime;
919 } else {
920 wwarning(_("could not load domain %s from global defaults database"),
921 domain);
925 /* set to save it in user's directory, no matter from where it was read */
926 if (db->dictionary) {
927 proplist_t tmp = PLMakeString(db->path);
929 PLSetFilename(db->dictionary, tmp);
930 PLRelease(tmp);
933 return db;
937 void
938 wReadStaticDefaults(proplist_t dict)
940 proplist_t plvalue;
941 WDefaultEntry *entry;
942 int i;
943 void *tdata;
946 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
947 entry = &staticOptionList[i];
949 if (dict)
950 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
951 else
952 plvalue = NULL;
954 if (!plvalue) {
955 /* no default in the DB. Use builtin default */
956 plvalue = entry->plvalue;
959 if (plvalue) {
960 /* convert data */
961 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
962 if (entry->update) {
963 (*entry->update)(NULL, entry, tdata, entry->extra_data);
970 void
971 wDefaultsCheckDomains(void *foo)
973 WScreen *scr;
974 struct stat stbuf;
975 proplist_t dict;
976 int i;
977 char path[PATH_MAX];
979 #ifdef HEARTBEAT
980 puts("Checking domains...");
981 #endif
982 if (stat(WDWindowMaker->path, &stbuf)>=0
983 && WDWindowMaker->timestamp < stbuf.st_mtime) {
984 proplist_t shared_dict = NULL;
985 #ifdef HEARTBEAT
986 puts("Checking WindowMaker domain");
987 #endif
988 WDWindowMaker->timestamp = stbuf.st_mtime;
990 /* global dictionary */
991 sprintf(path, "%s/WindowMaker", SYSCONFDIR);
992 if (stat(path, &stbuf)>=0) {
993 shared_dict = ReadProplistFromFile(path);
994 if (shared_dict && !PLIsDictionary(shared_dict)) {
995 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
996 "WindowMaker", path);
997 PLRelease(shared_dict);
998 shared_dict = NULL;
999 } else if (!shared_dict) {
1000 wwarning(_("could not load domain %s from global defaults database"),
1001 "WindowMaker");
1004 /* user dictionary */
1005 dict = ReadProplistFromFile(WDWindowMaker->path);
1006 if (dict) {
1007 if (!PLIsDictionary(dict)) {
1008 PLRelease(dict);
1009 dict = NULL;
1010 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1011 "WindowMaker", WDWindowMaker->path);
1012 } else {
1013 if (shared_dict) {
1014 PLSetFilename(shared_dict, PLGetFilename(dict));
1015 PLMergeDictionaries(shared_dict, dict);
1016 PLRelease(dict);
1017 dict = shared_dict;
1018 shared_dict = NULL;
1020 for (i=0; i<wScreenCount; i++) {
1021 scr = wScreenWithNumber(i);
1022 if (scr)
1023 wReadDefaults(scr, dict);
1025 if (WDWindowMaker->dictionary) {
1026 PLRelease(WDWindowMaker->dictionary);
1028 WDWindowMaker->dictionary = dict;
1030 } else {
1031 wwarning(_("could not load domain %s from user defaults database"),
1032 "WindowMaker");
1034 if (shared_dict) {
1035 PLRelease(shared_dict);
1039 if (stat(WDWindowAttributes->path, &stbuf)>=0
1040 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1041 #ifdef HEARTBEAT
1042 puts("Checking WMWindowAttributes domain");
1043 #endif
1044 dict = ReadProplistFromFile(WDWindowAttributes->path);
1045 if (dict) {
1046 if (!PLIsDictionary(dict)) {
1047 PLRelease(dict);
1048 dict = NULL;
1049 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1050 "WMWindowAttributes", WDWindowAttributes->path);
1051 } else {
1052 if (WDWindowAttributes->dictionary)
1053 PLRelease(WDWindowAttributes->dictionary);
1054 WDWindowAttributes->dictionary = dict;
1055 for (i=0; i<wScreenCount; i++) {
1056 scr = wScreenWithNumber(i);
1057 if (scr)
1058 wDefaultUpdateIcons(scr);
1061 } else {
1062 wwarning(_("could not load domain %s from user defaults database"),
1063 "WMWindowAttributes");
1065 WDWindowAttributes->timestamp = stbuf.st_mtime;
1068 #ifndef LITE
1069 if (stat(WDRootMenu->path, &stbuf)>=0
1070 && WDRootMenu->timestamp < stbuf.st_mtime) {
1071 dict = ReadProplistFromFile(WDRootMenu->path);
1072 #ifdef HEARTBEAT
1073 puts("Checking WMRootMenu domain");
1074 #endif
1075 if (dict) {
1076 if (!PLIsArray(dict) && !PLIsString(dict)) {
1077 PLRelease(dict);
1078 dict = NULL;
1079 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1080 "WMRootMenu", WDRootMenu->path);
1081 } else {
1082 if (WDRootMenu->dictionary) {
1083 PLRelease(WDRootMenu->dictionary);
1085 WDRootMenu->dictionary = dict;
1087 } else {
1088 wwarning(_("could not load domain %s from user defaults database"),
1089 "WMRootMenu");
1091 WDRootMenu->timestamp = stbuf.st_mtime;
1093 #endif /* !LITE */
1095 if (!foo)
1096 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1100 void
1101 wReadDefaults(WScreen *scr, proplist_t new_dict)
1103 proplist_t plvalue, old_value;
1104 WDefaultEntry *entry;
1105 int i, must_update;
1106 int needs_refresh;
1107 void *tdata;
1108 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1109 ? WDWindowMaker->dictionary : NULL);
1111 must_update = 0;
1113 needs_refresh = 0;
1115 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1116 entry = &optionList[i];
1118 if (new_dict)
1119 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1120 else
1121 plvalue = NULL;
1123 if (!old_dict)
1124 old_value = NULL;
1125 else
1126 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1129 if (!plvalue && !old_value) {
1130 /* no default in the DB. Use builtin default */
1131 plvalue = entry->plvalue;
1132 if (plvalue && new_dict) {
1133 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1134 must_update = 1;
1136 } else if (!plvalue) {
1137 /* value was deleted from DB. Keep current value */
1138 continue;
1139 } else if (!old_value) {
1140 /* set value for the 1st time */
1141 } else if (!PLIsEqual(plvalue, old_value)) {
1142 /* value has changed */
1143 } else {
1144 /* value was not changed since last time */
1145 continue;
1148 if (plvalue) {
1149 #ifdef DEBUG
1150 printf("Updating %s to %s\n", entry->key, PLGetDescription(plvalue));
1151 #endif
1152 /* convert data */
1153 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1154 if (entry->update) {
1155 needs_refresh |=
1156 (*entry->update)(scr, entry, tdata, entry->extra_data);
1162 if (needs_refresh!=0 && !scr->flags.startup) {
1163 int foo;
1165 foo = 0;
1166 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1167 foo |= WTextureSettings;
1168 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1169 foo |= WFontSettings;
1170 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1171 foo |= WColorSettings;
1172 if (foo)
1173 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1174 (void*)foo);
1176 foo = 0;
1177 if (needs_refresh & REFRESH_MENU_TEXTURE)
1178 foo |= WTextureSettings;
1179 if (needs_refresh & REFRESH_MENU_FONT)
1180 foo |= WFontSettings;
1181 if (needs_refresh & REFRESH_MENU_COLOR)
1182 foo |= WColorSettings;
1183 if (foo)
1184 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1185 (void*)foo);
1187 foo = 0;
1188 if (needs_refresh & REFRESH_WINDOW_FONT) {
1189 foo |= WFontSettings;
1191 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1192 foo |= WTextureSettings;
1194 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1195 foo |= WColorSettings;
1197 if (foo)
1198 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1199 (void*)foo);
1201 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1202 foo = 0;
1203 if (needs_refresh & REFRESH_ICON_FONT) {
1204 foo |= WFontSettings;
1206 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1207 foo |= WTextureSettings;
1209 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1210 foo |= WTextureSettings;
1212 if (foo)
1213 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1214 (void*)foo);
1216 if (needs_refresh & REFRESH_ICON_TILE)
1217 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1222 void
1223 wDefaultUpdateIcons(WScreen *scr)
1225 WAppIcon *aicon = scr->app_icon_list;
1226 WWindow *wwin = scr->focused_window;
1227 char *file;
1229 while(aicon) {
1230 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1231 False);
1232 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1233 || (file && !aicon->icon->file)) {
1234 RImage *new_image;
1236 if (aicon->icon->file)
1237 free(aicon->icon->file);
1238 aicon->icon->file = wstrdup(file);
1240 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1241 aicon->wm_class);
1242 if (new_image) {
1243 wIconChangeImage(aicon->icon, new_image);
1244 wAppIconPaint(aicon);
1247 aicon = aicon->next;
1250 if (!wPreferences.flags.noclip)
1251 wClipIconPaint(scr->clip_icon);
1253 while (wwin) {
1254 if (wwin->icon && wwin->flags.miniaturized) {
1255 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1256 False);
1257 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1258 || (file && !wwin->icon->file)) {
1259 RImage *new_image;
1261 if (wwin->icon->file)
1262 free(wwin->icon->file);
1263 wwin->icon->file = wstrdup(file);
1265 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1266 wwin->wm_class);
1267 if (new_image)
1268 wIconChangeImage(wwin->icon, new_image);
1271 wwin = wwin->prev;
1276 /* --------------------------- Local ----------------------- */
1278 #define STRINGP(x) if (!PLIsString(value)) { \
1279 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1280 entry->key, x); \
1281 return False; }
1285 static int
1286 string2index(proplist_t key, proplist_t val, proplist_t def,
1287 WOptionEnumeration *values)
1289 char *str;
1290 WOptionEnumeration *v;
1291 char buffer[TOTAL_VALUES_LENGTH];
1293 if (PLIsString(val) && (str = PLGetString(val))) {
1294 for (v=values; v->string!=NULL; v++) {
1295 if (strcasecmp(v->string, str)==0)
1296 return v->value;
1300 buffer[0] = 0;
1301 for (v=values; v->string!=NULL; v++) {
1302 if (!v->is_alias) {
1303 if (buffer[0]!=0)
1304 strcat(buffer, ", ");
1305 strcat(buffer, v->string);
1308 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1309 PLGetString(key), buffer);
1311 if (def) {
1312 return string2index(key, val, NULL, values);
1315 return -1;
1322 * value - is the value in the defaults DB
1323 * addr - is the address to store the data
1324 * ret - is the address to store a pointer to a temporary buffer. ret
1325 * must not be freed and is used by the set functions
1327 static int
1328 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1329 void **ret)
1331 static char data;
1332 char *val;
1333 int second_pass=0;
1335 STRINGP("Boolean");
1337 val = PLGetString(value);
1339 again:
1340 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1341 || strcasecmp(val, "YES")==0) {
1343 data = 1;
1344 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1345 || strcasecmp(val, "NO")==0) {
1346 data = 0;
1347 } else {
1348 int i;
1349 if (sscanf(val, "%i", &i)==1) {
1350 if (i!=0)
1351 data = 1;
1352 else
1353 data = 0;
1354 } else {
1355 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1356 val, entry->key);
1357 if (second_pass==0) {
1358 val = PLGetString(entry->plvalue);
1359 second_pass = 1;
1360 wwarning(_("using default \"%s\" instead"), val);
1361 goto again;
1363 return False;
1367 if (ret)
1368 *ret = &data;
1370 if (addr) {
1371 *(char*)addr = data;
1374 return True;
1378 static int
1379 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1380 void **ret)
1382 static int data;
1383 char *val;
1386 STRINGP("Integer");
1388 val = PLGetString(value);
1390 if (sscanf(val, "%i", &data)!=1) {
1391 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1392 val, entry->key);
1393 val = PLGetString(entry->plvalue);
1394 wwarning(_("using default \"%s\" instead"), val);
1395 if (sscanf(val, "%i", &data)!=1) {
1396 return False;
1400 if (ret)
1401 *ret = &data;
1403 if (addr) {
1404 *(int*)addr = data;
1406 return True;
1410 static int
1411 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1412 void **ret)
1414 static WCoord data;
1415 char *val_x, *val_y;
1416 int nelem, changed=0;
1417 proplist_t elem_x, elem_y;
1419 again:
1420 if (!PLIsArray(value)) {
1421 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1422 entry->key, "Coordinate");
1423 if (changed==0) {
1424 value = entry->plvalue;
1425 changed = 1;
1426 wwarning(_("using default \"%s\" instead"), entry->default_value);
1427 goto again;
1429 return False;
1432 nelem = PLGetNumberOfElements(value);
1433 if (nelem != 2) {
1434 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1435 entry->key);
1436 if (changed==0) {
1437 value = entry->plvalue;
1438 changed = 1;
1439 wwarning(_("using default \"%s\" instead"), entry->default_value);
1440 goto again;
1442 return False;
1445 elem_x = PLGetArrayElement(value, 0);
1446 elem_y = PLGetArrayElement(value, 1);
1448 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1449 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1450 entry->key);
1451 if (changed==0) {
1452 value = entry->plvalue;
1453 changed = 1;
1454 wwarning(_("using default \"%s\" instead"), entry->default_value);
1455 goto again;
1457 return False;
1460 val_x = PLGetString(elem_x);
1461 val_y = PLGetString(elem_y);
1463 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1464 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1465 if (changed==0) {
1466 value = entry->plvalue;
1467 changed = 1;
1468 wwarning(_("using default \"%s\" instead"), entry->default_value);
1469 goto again;
1471 return False;
1474 if (data.x < 0)
1475 data.x = 0;
1476 else if (data.x > scr->scr_width/3)
1477 data.x = scr->scr_width/3;
1478 if (data.y < 0)
1479 data.y = 0;
1480 else if (data.y > scr->scr_height/3)
1481 data.y = scr->scr_height/3;
1483 if (ret)
1484 *ret = &data;
1486 if (addr) {
1487 *(WCoord*)addr = data;
1490 return True;
1494 #if 0
1495 /* This function is not used at the moment. */
1496 static int
1497 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1498 void **ret)
1500 static char *data;
1502 STRINGP("String");
1504 data = PLGetString(value);
1506 if (!data) {
1507 data = PLGetString(entry->plvalue);
1508 if (!data)
1509 return False;
1512 if (ret)
1513 *ret = &data;
1515 if (addr)
1516 *(char**)addr = wstrdup(data);
1518 return True;
1520 #endif
1523 static int
1524 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1525 void **ret)
1527 static char *data;
1528 int i, count, len;
1529 char *ptr;
1530 proplist_t d;
1531 int changed=0;
1533 again:
1534 if (!PLIsArray(value)) {
1535 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1536 entry->key, "an array of paths");
1537 if (changed==0) {
1538 value = entry->plvalue;
1539 changed = 1;
1540 wwarning(_("using default \"%s\" instead"), entry->default_value);
1541 goto again;
1543 return False;
1546 i = 0;
1547 count = PLGetNumberOfElements(value);
1548 if (count < 1) {
1549 if (changed==0) {
1550 value = entry->plvalue;
1551 changed = 1;
1552 wwarning(_("using default \"%s\" instead"), entry->default_value);
1553 goto again;
1555 return False;
1558 len = 0;
1559 for (i=0; i<count; i++) {
1560 d = PLGetArrayElement(value, i);
1561 if (!d || !PLIsString(d)) {
1562 count = i;
1563 break;
1565 len += strlen(PLGetString(d))+1;
1568 ptr = data = wmalloc(len+1);
1570 for (i=0; i<count; i++) {
1571 d = PLGetArrayElement(value, i);
1572 if (!d || !PLIsString(d)) {
1573 break;
1575 strcpy(ptr, PLGetString(d));
1576 ptr += strlen(PLGetString(d));
1577 *ptr = ':';
1578 ptr++;
1580 ptr--; *(ptr--) = 0;
1582 if (*(char**)addr!=NULL) {
1583 free(*(char**)addr);
1585 *(char**)addr = data;
1587 return True;
1591 static int
1592 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1593 void **ret)
1595 static signed char data;
1597 data = string2index(entry->plkey, value, entry->default_value,
1598 (WOptionEnumeration*)entry->extra_data);
1599 if (data < 0)
1600 return False;
1602 if (ret)
1603 *ret = &data;
1605 if (addr)
1606 *(signed char*)addr = data;
1608 return True;
1614 * (solid <color>)
1615 * (hgradient <color> <color>)
1616 * (vgradient <color> <color>)
1617 * (dgradient <color> <color>)
1618 * (mhgradient <color> <color> ...)
1619 * (mvgradient <color> <color> ...)
1620 * (tpixmap <file> <color>)
1621 * (spixmap <file> <color>)
1622 * (cpixmap <file> <color>)
1623 * (thgradient <file> <opaqueness> <color> <color>)
1624 * (tvgradient <file> <opaqueness> <color> <color>)
1625 * (tdgradient <file> <opaqueness> <color> <color>)
1626 * (function <lib> <function> ...)
1629 static WTexture*
1630 parse_texture(WScreen *scr, proplist_t pl)
1632 proplist_t elem;
1633 char *val;
1634 int nelem;
1635 WTexture *texture=NULL;
1637 nelem = PLGetNumberOfElements(pl);
1638 if (nelem < 1)
1639 return NULL;
1642 elem = PLGetArrayElement(pl, 0);
1643 if (!elem || !PLIsString(elem))
1644 return NULL;
1645 val = PLGetString(elem);
1648 if (strcasecmp(val, "solid")==0) {
1649 XColor color;
1651 if (nelem != 2)
1652 return NULL;
1654 /* get color */
1656 elem = PLGetArrayElement(pl, 1);
1657 if (!elem || !PLIsString(elem))
1658 return NULL;
1659 val = PLGetString(elem);
1661 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1662 wwarning(_("\"%s\" is not a valid color name"), val);
1663 return NULL;
1666 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1667 } else if (strcasecmp(val, "dgradient")==0
1668 || strcasecmp(val, "vgradient")==0
1669 || strcasecmp(val, "hgradient")==0) {
1670 RColor color1, color2;
1671 XColor xcolor;
1672 int type;
1674 if (nelem != 3) {
1675 wwarning(_("bad number of arguments in gradient specification"));
1676 return NULL;
1679 if (val[0]=='d' || val[0]=='D')
1680 type = WTEX_DGRADIENT;
1681 else if (val[0]=='h' || val[0]=='H')
1682 type = WTEX_HGRADIENT;
1683 else
1684 type = WTEX_VGRADIENT;
1687 /* get from color */
1688 elem = PLGetArrayElement(pl, 1);
1689 if (!elem || !PLIsString(elem))
1690 return NULL;
1691 val = PLGetString(elem);
1693 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1694 wwarning(_("\"%s\" is not a valid color name"), val);
1695 return NULL;
1697 color1.alpha = 255;
1698 color1.red = xcolor.red >> 8;
1699 color1.green = xcolor.green >> 8;
1700 color1.blue = xcolor.blue >> 8;
1702 /* get to color */
1703 elem = PLGetArrayElement(pl, 2);
1704 if (!elem || !PLIsString(elem)) {
1705 return NULL;
1707 val = PLGetString(elem);
1709 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1710 wwarning(_("\"%s\" is not a valid color name"), val);
1711 return NULL;
1713 color2.alpha = 255;
1714 color2.red = xcolor.red >> 8;
1715 color2.green = xcolor.green >> 8;
1716 color2.blue = xcolor.blue >> 8;
1718 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1720 } else if (strcasecmp(val, "mhgradient")==0
1721 || strcasecmp(val, "mvgradient")==0
1722 || strcasecmp(val, "mdgradient")==0) {
1723 XColor color;
1724 RColor **colors;
1725 int i, count;
1726 int type;
1728 if (nelem < 3) {
1729 wwarning(_("too few arguments in multicolor gradient specification"));
1730 return NULL;
1733 if (val[1]=='h' || val[1]=='H')
1734 type = WTEX_MHGRADIENT;
1735 else if (val[1]=='v' || val[1]=='V')
1736 type = WTEX_MVGRADIENT;
1737 else
1738 type = WTEX_MDGRADIENT;
1740 count = nelem-1;
1742 colors = wmalloc(sizeof(RColor*)*(count+1));
1744 for (i=0; i<count; i++) {
1745 elem = PLGetArrayElement(pl, i+1);
1746 if (!elem || !PLIsString(elem)) {
1747 for (--i; i>=0; --i) {
1748 free(colors[i]);
1750 free(colors);
1751 return NULL;
1753 val = PLGetString(elem);
1755 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1756 wwarning(_("\"%s\" is not a valid color name"), val);
1757 for (--i; i>=0; --i) {
1758 free(colors[i]);
1760 free(colors);
1761 return NULL;
1762 } else {
1763 colors[i] = wmalloc(sizeof(RColor));
1764 colors[i]->red = color.red >> 8;
1765 colors[i]->green = color.green >> 8;
1766 colors[i]->blue = color.blue >> 8;
1769 colors[i] = NULL;
1771 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1772 } else if (strcasecmp(val, "spixmap")==0 ||
1773 strcasecmp(val, "cpixmap")==0 ||
1774 strcasecmp(val, "tpixmap")==0) {
1775 XColor color;
1776 int type;
1778 if (nelem != 3)
1779 return NULL;
1781 if (val[0] == 's' || val[0] == 'S')
1782 type = WTP_SCALE;
1783 else if (val[0] == 'c' || val[0] == 'C')
1784 type = WTP_CENTER;
1785 else
1786 type = WTP_TILE;
1788 /* get color */
1789 elem = PLGetArrayElement(pl, 2);
1790 if (!elem || !PLIsString(elem)) {
1791 return NULL;
1793 val = PLGetString(elem);
1795 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1796 wwarning(_("\"%s\" is not a valid color name"), val);
1797 return NULL;
1800 /* file name */
1801 elem = PLGetArrayElement(pl, 1);
1802 if (!elem || !PLIsString(elem))
1803 return NULL;
1804 val = PLGetString(elem);
1806 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1807 } else if (strcasecmp(val, "thgradient")==0
1808 || strcasecmp(val, "tvgradient")==0
1809 || strcasecmp(val, "tdgradient")==0) {
1810 RColor color1, color2;
1811 XColor xcolor;
1812 int opacity;
1813 int style;
1815 if (val[1]=='h' || val[1]=='H')
1816 style = WTEX_THGRADIENT;
1817 else if (val[1]=='v' || val[1]=='V')
1818 style = WTEX_TVGRADIENT;
1819 else
1820 style = WTEX_TDGRADIENT;
1822 if (nelem != 5) {
1823 wwarning(_("bad number of arguments in textured gradient specification"));
1824 return NULL;
1827 /* get from color */
1828 elem = PLGetArrayElement(pl, 3);
1829 if (!elem || !PLIsString(elem))
1830 return NULL;
1831 val = PLGetString(elem);
1833 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1834 wwarning(_("\"%s\" is not a valid color name"), val);
1835 return NULL;
1837 color1.alpha = 255;
1838 color1.red = xcolor.red >> 8;
1839 color1.green = xcolor.green >> 8;
1840 color1.blue = xcolor.blue >> 8;
1842 /* get to color */
1843 elem = PLGetArrayElement(pl, 4);
1844 if (!elem || !PLIsString(elem)) {
1845 return NULL;
1847 val = PLGetString(elem);
1849 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1850 wwarning(_("\"%s\" is not a valid color name"), val);
1851 return NULL;
1853 color2.alpha = 255;
1854 color2.red = xcolor.red >> 8;
1855 color2.green = xcolor.green >> 8;
1856 color2.blue = xcolor.blue >> 8;
1858 /* get opacity */
1859 elem = PLGetArrayElement(pl, 2);
1860 if (!elem || !PLIsString(elem))
1861 opacity = 128;
1862 else
1863 val = PLGetString(elem);
1865 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1866 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1867 opacity = 128;
1870 /* get file name */
1871 elem = PLGetArrayElement(pl, 1);
1872 if (!elem || !PLIsString(elem))
1873 return NULL;
1874 val = PLGetString(elem);
1876 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1877 val, opacity);
1879 #ifdef TEXTURE_PLUGIN
1880 else if (strcasecmp(val, "function")==0) {
1881 WTexFunction *function;
1882 void (*initFunc) (Display *, Colormap);
1883 char *lib, *func, **argv;
1884 int i, argc;
1886 if (nelem < 3)
1887 return NULL;
1889 /* get the library name */
1890 elem = PLGetArrayElement(pl, 1);
1891 if (!elem || !PLIsString(elem)) {
1892 return NULL;
1894 lib = PLGetString(elem);
1896 /* get the function name */
1897 elem = PLGetArrayElement(pl, 2);
1898 if (!elem || !PLIsString(elem)) {
1899 return NULL;
1901 func = PLGetString(elem);
1903 argc = nelem - 2;
1904 argv = (char **)wmalloc(argc * sizeof(char *));
1906 /* get the parameters */
1907 argv[0] = wstrdup(func);
1908 for (i = 0; i < argc - 1; i++) {
1909 elem = PLGetArrayElement(pl, 3 + i);
1910 if (!elem || !PLIsString(elem)) {
1911 free(argv);
1913 return NULL;
1915 argv[i+1] = wstrdup(PLGetString(elem));
1918 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1920 #ifdef HAVE_DLFCN_H
1921 if (function) {
1922 initFunc = dlsym(function->handle, "initWindowMaker");
1923 if (initFunc) {
1924 initFunc(dpy, scr->w_colormap);
1925 } else {
1926 wwarning(_("could not initialize library %s"), lib);
1928 } else {
1929 wwarning(_("could not find function %s::%s"), lib, func);
1931 #endif /* HAVE_DLFCN_H */
1932 texture = (WTexture*)function;
1934 #endif /* TEXTURE_PLUGIN */
1935 else {
1936 wwarning(_("invalid texture type %s"), val);
1937 return NULL;
1939 return texture;
1944 static int
1945 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1946 void **ret)
1948 static WTexture *texture;
1949 int changed=0;
1951 again:
1952 if (!PLIsArray(value)) {
1953 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1954 entry->key, "Texture");
1955 if (changed==0) {
1956 value = entry->plvalue;
1957 changed = 1;
1958 wwarning(_("using default \"%s\" instead"), entry->default_value);
1959 goto again;
1961 return False;
1964 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
1965 proplist_t pl;
1967 pl = PLGetArrayElement(value, 0);
1968 if (!pl || !PLIsString(pl) || !PLGetString(pl)
1969 || strcasecmp(PLGetString(pl), "solid")!=0) {
1970 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1971 entry->key, "Solid Texture");
1973 value = entry->plvalue;
1974 changed = 1;
1975 wwarning(_("using default \"%s\" instead"), entry->default_value);
1976 goto again;
1980 texture = parse_texture(scr, value);
1982 if (!texture) {
1983 wwarning(_("Error in texture specification for key \"%s\""),
1984 entry->key);
1985 if (changed==0) {
1986 value = entry->plvalue;
1987 changed = 1;
1988 wwarning(_("using default \"%s\" instead"), entry->default_value);
1989 goto again;
1991 return False;
1994 if (ret)
1995 *ret = &texture;
1997 if (addr)
1998 *(WTexture**)addr = texture;
2000 return True;
2005 static int
2006 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2007 void *addr, void **ret)
2009 proplist_t elem;
2010 int changed = 0;
2011 char *val;
2012 int nelem;
2014 again:
2015 if (!PLIsArray(value)) {
2016 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2017 "WorkspaceBack", "Texture or None");
2018 if (changed==0) {
2019 value = entry->plvalue;
2020 changed = 1;
2021 wwarning(_("using default \"%s\" instead"), entry->default_value);
2022 goto again;
2024 return False;
2027 /* only do basic error checking and verify for None texture */
2029 nelem = PLGetNumberOfElements(value);
2030 if (nelem > 0) {
2031 elem = PLGetArrayElement(value, 0);
2032 if (!elem || !PLIsString(elem)) {
2033 wwarning(_("Wrong type for workspace background. Should be a texture type."));
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;
2042 val = PLGetString(elem);
2044 if (strcasecmp(val, "None")==0)
2045 return True;
2047 *ret = PLRetain(value);
2049 return True;
2053 static int
2054 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2055 void *addr, void **ret)
2057 proplist_t elem;
2058 int nelem;
2059 int changed = 0;
2061 again:
2062 if (!PLIsArray(value)) {
2063 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2064 "WorkspaceSpecificBack", "an array of textures");
2065 if (changed==0) {
2066 value = entry->plvalue;
2067 changed = 1;
2068 wwarning(_("using default \"%s\" instead"), entry->default_value);
2069 goto again;
2071 return False;
2074 /* only do basic error checking and verify for None texture */
2076 nelem = PLGetNumberOfElements(value);
2077 if (nelem > 0) {
2078 while (nelem--) {
2079 elem = PLGetArrayElement(value, nelem);
2080 if (!elem || !PLIsArray(elem)) {
2081 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2082 nelem);
2087 *ret = PLRetain(value);
2089 #ifdef notworking
2091 * Kluge to force wmsetbg helper to set the default background.
2092 * If the WorkspaceSpecificBack is changed once wmaker has started,
2093 * the WorkspaceBack won't be sent to the helper, unless the user
2094 * changes it's value too. So, we must force this by removing the
2095 * value from the defaults DB.
2097 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2098 proplist_t key = PLMakeString("WorkspaceBack");
2100 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2102 PLRelease(key);
2104 #endif
2105 return True;
2109 static int
2110 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2111 void **ret)
2113 static WMFont *font;
2114 char *val;
2116 STRINGP("Font");
2118 val = PLGetString(value);
2120 font = WMCreateFont(scr->wmscreen, val);
2121 if (!font)
2122 font = WMCreateFont(scr->wmscreen, "fixed");
2124 if (!font) {
2125 wfatal(_("could not load any usable font!!!"));
2126 exit(1);
2129 if (ret)
2130 *ret = font;
2132 /* can't assign font value outside update function */
2133 wassertrv(addr == NULL, True);
2135 return True;
2139 static int
2140 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2141 void **ret)
2143 static XColor color;
2144 char *val;
2145 int second_pass=0;
2147 STRINGP("Color");
2149 val = PLGetString(value);
2151 again:
2152 if (!wGetColor(scr, val, &color)) {
2153 wwarning(_("could not get color for key \"%s\""),
2154 entry->key);
2155 if (second_pass==0) {
2156 val = PLGetString(entry->plvalue);
2157 second_pass = 1;
2158 wwarning(_("using default \"%s\" instead"), val);
2159 goto again;
2161 return False;
2164 if (ret)
2165 *ret = &color;
2167 assert(addr==NULL);
2169 if (addr)
2170 *(unsigned long*)addr = pixel;
2173 return True;
2178 static int
2179 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2180 void **ret)
2182 static WShortKey shortcut;
2183 KeySym ksym;
2184 char *val;
2185 char *k;
2186 char buf[128], *b;
2189 STRINGP("Key spec");
2191 val = PLGetString(value);
2193 if (!val || strcasecmp(val, "NONE")==0) {
2194 shortcut.keycode = 0;
2195 shortcut.modifier = 0;
2196 if (ret)
2197 *ret = &shortcut;
2198 return True;
2201 strcpy(buf, val);
2203 b = (char*)buf;
2205 /* get modifiers */
2206 shortcut.modifier = 0;
2207 while ((k = strchr(b, '+'))!=NULL) {
2208 int mod;
2210 *k = 0;
2211 mod = wXModifierFromKey(b);
2212 if (mod<0) {
2213 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2214 return False;
2216 shortcut.modifier |= mod;
2218 b = k+1;
2221 /* get key */
2222 ksym = XStringToKeysym(b);
2224 if (ksym==NoSymbol) {
2225 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2226 val);
2227 return False;
2230 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2231 if (shortcut.keycode==0) {
2232 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2233 return False;
2236 if (ret)
2237 *ret = &shortcut;
2239 return True;
2243 static int
2244 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2245 void **ret)
2247 static unsigned int mask;
2248 char *str;
2250 STRINGP("Modifier Key");
2252 str = PLGetString(value);
2253 if (!str)
2254 return False;
2256 mask = wXModifierFromKey(str);
2257 if (mask < 0) {
2258 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2259 mask = 0;
2260 return False;
2263 if (addr)
2264 *(unsigned int*)addr = mask;
2266 if (ret)
2267 *ret = &mask;
2269 return True;
2273 #ifdef NEWSTUFF
2274 static int
2275 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2276 void *addr, void **ret)
2278 unsigned int mask;
2279 char *str;
2280 RImage *image;
2281 int i, n;
2282 int w, h;
2284 STRINGP("Image File Path");
2286 str = PLGetString(value);
2287 if (!str)
2288 return False;
2290 image = RLoadImage(scr->rcontext, str, 0);
2291 if (!image) {
2292 wwarning(_("could not load image in option %s: %s"), entry->key,
2293 RMessageForError(RErrorCode));
2294 return False;
2297 if (*(RImage**)addr) {
2298 RDestroyImage(*(RImage**)addr);
2300 if (addr)
2301 *(RImage**)addr = image;
2303 assert(ret == NULL);
2305 if (ret)
2306 *(RImage**)ret = image;
2309 return True;
2311 #endif
2314 /* ---------------- value setting functions --------------- */
2315 static int
2316 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2318 return REFRESH_WINDOW_TITLE_COLOR;
2322 static int
2323 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2325 switch (which) {
2326 case WM_DOCK:
2327 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2328 break;
2329 case WM_CLIP:
2330 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2331 break;
2332 default:
2333 break;
2335 return 0;
2339 static int
2340 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2342 if (scr->workspaces) {
2343 wWorkspaceForceChange(scr, scr->current_workspace);
2344 wArrangeIcons(scr, False);
2346 return 0;
2349 #if not_used
2350 static int
2351 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2353 if (*value <= 0)
2354 *(int*)foo = 1;
2356 return 0;
2358 #endif
2362 static int
2363 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2365 Pixmap pixmap;
2366 RImage *img;
2367 int reset = 0;
2369 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2370 wPreferences.icon_size,
2371 ((*texture)->any.type & WREL_BORDER_MASK)
2372 ? WREL_ICON : WREL_FLAT);
2373 if (!img) {
2374 wwarning(_("could not render texture for icon background"));
2375 if (!entry->addr)
2376 wTextureDestroy(scr, *texture);
2377 return 0;
2379 RConvertImage(scr->rcontext, img, &pixmap);
2381 if (scr->icon_tile) {
2382 reset = 1;
2383 RDestroyImage(scr->icon_tile);
2384 XFreePixmap(dpy, scr->icon_tile_pixmap);
2387 scr->icon_tile = img;
2389 if (!wPreferences.flags.noclip) {
2390 if (scr->clip_tile) {
2391 RDestroyImage(scr->clip_tile);
2393 scr->clip_tile = wClipMakeTile(scr, img);
2396 scr->icon_tile_pixmap = pixmap;
2398 if (scr->def_icon_pixmap) {
2399 XFreePixmap(dpy, scr->def_icon_pixmap);
2400 scr->def_icon_pixmap = None;
2402 if (scr->def_ticon_pixmap) {
2403 XFreePixmap(dpy, scr->def_ticon_pixmap);
2404 scr->def_ticon_pixmap = None;
2407 if (scr->icon_back_texture) {
2408 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2410 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2412 if (scr->clip_balloon)
2413 XSetWindowBackground(dpy, scr->clip_balloon,
2414 (*texture)->any.color.pixel);
2417 * Free the texture as nobody else will use it, nor refer to it.
2419 if (!entry->addr)
2420 wTextureDestroy(scr, *texture);
2422 return (reset ? REFRESH_ICON_TILE : 0);
2427 static int
2428 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2430 if (scr->title_font) {
2431 WMReleaseFont(scr->title_font);
2433 scr->title_font = font;
2435 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2439 static int
2440 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2442 if (scr->menu_title_font) {
2443 WMReleaseFont(scr->menu_title_font);
2446 scr->menu_title_font = font;
2448 return REFRESH_MENU_TITLE_FONT;
2452 static int
2453 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2455 if (scr->menu_entry_font) {
2456 WMReleaseFont(scr->menu_entry_font);
2458 scr->menu_entry_font = font;
2460 return REFRESH_MENU_FONT;
2465 static int
2466 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2468 if (scr->icon_title_font) {
2469 WMReleaseFont(scr->icon_title_font);
2472 scr->icon_title_font = font;
2474 return REFRESH_ICON_FONT;
2478 static int
2479 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2481 if (scr->clip_title_font) {
2482 WMReleaseFont(scr->clip_title_font);
2485 scr->clip_title_font = font;
2487 return REFRESH_ICON_FONT;
2491 static int
2492 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2494 if (scr->info_text_font) {
2495 WMReleaseFont(scr->info_text_font);
2498 scr->info_text_font = font;
2500 /* This test works because the scr structure is initially zeroed out
2501 and None = 0. Any other time, the window should be valid. */
2502 if (scr->geometry_display != None) {
2503 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2504 &scr->geometry_display_height);
2505 XResizeWindow(dpy, scr->geometry_display,
2506 scr->geometry_display_width, scr->geometry_display_height);
2509 return 0;
2513 static int
2514 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2516 if (scr->workspace_name_font) {
2517 WMReleaseFont(scr->workspace_name_font);
2520 scr->workspace_name_font = font;
2522 return 0;
2526 static int
2527 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2529 if (scr->select_pixel!=scr->white_pixel &&
2530 scr->select_pixel!=scr->black_pixel) {
2531 wFreeColor(scr, scr->select_pixel);
2534 scr->select_pixel = color->pixel;
2536 return REFRESH_MENU_COLOR;
2540 static int
2541 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2543 if (scr->select_text_pixel!=scr->white_pixel &&
2544 scr->select_text_pixel!=scr->black_pixel) {
2545 wFreeColor(scr, scr->select_text_pixel);
2548 scr->select_text_pixel = color->pixel;
2550 return REFRESH_MENU_COLOR;
2554 static int
2555 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2557 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2558 scr->clip_title_pixel[index]!=scr->black_pixel) {
2559 wFreeColor(scr, scr->clip_title_pixel[index]);
2561 scr->clip_title_pixel[index] = color->pixel;
2563 #ifdef GRADIENT_CLIP_ARROW
2564 if (index == CLIP_NORMAL) {
2565 RImage *image;
2566 RColor color1, color2;
2567 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2568 int as = pt - 15; /* 15 = 5+5+5 */
2570 FREE_PIXMAP(scr->clip_arrow_gradient);
2572 color1.red = (color->red >> 8)*6/10;
2573 color1.green = (color->green >> 8)*6/10;
2574 color1.blue = (color->blue >> 8)*6/10;
2576 color2.red = WMIN((color->red >> 8)*20/10, 255);
2577 color2.green = WMIN((color->green >> 8)*20/10, 255);
2578 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2580 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2581 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2582 RDestroyImage(image);
2584 #endif /* GRADIENT_CLIP_ARROW */
2586 return REFRESH_ICON_TITLE_COLOR;
2590 static int
2591 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2593 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2594 scr->window_title_pixel[index]!=scr->black_pixel) {
2595 wFreeColor(scr, scr->window_title_pixel[index]);
2598 scr->window_title_pixel[index] = color->pixel;
2600 if (index == WS_UNFOCUSED)
2601 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2603 return REFRESH_WINDOW_TITLE_COLOR;
2607 static int
2608 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2610 #ifdef TITLE_TEXT_SHADOW
2611 if (index == WS_SMENU){
2612 if (scr->menu_title_pixel[WS_SMENU]!=scr->white_pixel &&
2613 scr->menu_title_pixel[WS_SMENU]!=scr->black_pixel) {
2614 wFreeColor(scr, scr->menu_title_pixel[WS_SMENU]);
2616 scr->menu_title_pixel[WS_SMENU] = color->pixel;
2618 else {
2619 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2620 scr->menu_title_pixel[0]!=scr->black_pixel) {
2621 wFreeColor(scr, scr->menu_title_pixel[0]);
2623 scr->menu_title_pixel[0] = color->pixel;
2625 #else /* !TITLE_TEXT_SHADOW */
2626 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2627 scr->menu_title_pixel[0]!=scr->black_pixel) {
2628 wFreeColor(scr, scr->menu_title_pixel[0]);
2631 scr->menu_title_pixel[0] = color->pixel;
2632 #endif /* !TITLE_TEXT_SHADOW */
2633 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2635 return REFRESH_MENU_TITLE_COLOR;
2639 static int
2640 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2642 XGCValues gcv;
2643 #define gcm (GCForeground|GCBackground|GCFillStyle)
2645 if (scr->mtext_pixel!=scr->white_pixel &&
2646 scr->mtext_pixel!=scr->black_pixel) {
2647 wFreeColor(scr, scr->mtext_pixel);
2650 scr->mtext_pixel = color->pixel;
2652 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2655 if (scr->dtext_pixel == scr->mtext_pixel) {
2656 gcv.foreground = scr->white_pixel;
2657 gcv.background = scr->black_pixel;
2658 gcv.fill_style = FillStippled;
2659 } else {
2660 gcv.foreground = scr->dtext_pixel;
2661 gcv.fill_style = FillSolid;
2663 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2665 return REFRESH_MENU_COLOR;
2666 #undef gcm
2670 static int
2671 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2673 XGCValues gcv;
2674 #define gcm (GCForeground|GCBackground|GCFillStyle)
2676 if (scr->dtext_pixel!=scr->white_pixel &&
2677 scr->dtext_pixel!=scr->black_pixel) {
2678 wFreeColor(scr, scr->dtext_pixel);
2681 scr->dtext_pixel = color->pixel;
2683 if (scr->dtext_pixel == scr->mtext_pixel) {
2684 gcv.foreground = scr->white_pixel;
2685 gcv.background = scr->black_pixel;
2686 gcv.fill_style = FillStippled;
2687 } else {
2688 gcv.foreground = scr->dtext_pixel;
2689 gcv.fill_style = FillSolid;
2691 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2693 return REFRESH_MENU_COLOR;
2694 #undef gcm
2697 static int
2698 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2700 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2702 return REFRESH_ICON_TITLE_COLOR;
2706 static int
2707 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2709 if (scr->icon_title_texture) {
2710 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2712 XQueryColor (dpy, scr->w_colormap, color);
2713 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2715 return REFRESH_ICON_TITLE_BACK;
2719 static void
2720 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2722 close(scr->helper_fd);
2723 scr->helper_fd = 0;
2724 scr->helper_pid = 0;
2725 scr->flags.backimage_helper_launched = 0;
2729 static int
2730 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2731 void *bar)
2733 int i;
2734 proplist_t val;
2735 char *str;
2737 if (scr->flags.backimage_helper_launched) {
2738 if (PLGetNumberOfElements(value)==0) {
2739 SendHelperMessage(scr, 'C', 0, NULL);
2740 SendHelperMessage(scr, 'K', 0, NULL);
2742 PLRelease(value);
2743 return 0;
2745 } else {
2746 pid_t pid;
2747 int filedes[2];
2749 if (PLGetNumberOfElements(value) == 0)
2750 return 0;
2752 if (pipe(filedes) < 0) {
2753 wsyserror("pipe() failed:can't set workspace specific background image");
2755 PLRelease(value);
2756 return 0;
2759 pid = fork();
2760 if (pid < 0) {
2761 wsyserror("fork() failed:can't set workspace specific background image");
2762 if (close(filedes[0]) < 0)
2763 wsyserror("could not close pipe");
2764 if (close(filedes[1]) < 0)
2765 wsyserror("could not close pipe");
2767 } else if (pid == 0) {
2768 SetupEnvironment(scr);
2770 if (close(0) < 0)
2771 wsyserror("could not close pipe");
2772 if (dup(filedes[0]) < 0) {
2773 wsyserror("dup() failed:can't set workspace specific background image");
2775 if (wPreferences.smooth_workspace_back)
2776 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
2777 else
2778 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2779 wsyserror("could not execute wmsetbg");
2780 exit(1);
2781 } else {
2783 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2784 wsyserror("error setting close-on-exec flag");
2786 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2787 wsyserror("error setting close-on-exec flag");
2790 scr->helper_fd = filedes[1];
2791 scr->helper_pid = pid;
2792 scr->flags.backimage_helper_launched = 1;
2794 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2796 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2800 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2801 val = PLGetArrayElement(value, i);
2802 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2803 str = PLGetDescription(val);
2805 SendHelperMessage(scr, 'S', i+1, str);
2807 free(str);
2808 } else {
2809 SendHelperMessage(scr, 'U', i+1, NULL);
2812 sleep(1);
2814 PLRelease(value);
2815 return 0;
2819 static int
2820 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2821 void *bar)
2823 if (scr->flags.backimage_helper_launched) {
2824 char *str;
2826 if (PLGetNumberOfElements(value)==0) {
2827 SendHelperMessage(scr, 'U', 0, NULL);
2828 } else {
2829 /* set the default workspace background to this one */
2830 str = PLGetDescription(value);
2831 if (str) {
2832 SendHelperMessage(scr, 'S', 0, str);
2833 free(str);
2834 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2835 } else {
2836 SendHelperMessage(scr, 'U', 0, NULL);
2839 } else {
2840 char *command;
2841 char *text;
2843 SetupEnvironment(scr);
2844 text = PLGetDescription(value);
2845 command = wmalloc(strlen(text)+40);
2846 if (wPreferences.smooth_workspace_back)
2847 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
2848 else
2849 sprintf(command, "wmsetbg -d -p '%s' &", text);
2850 free(text);
2851 system(command);
2852 free(command);
2854 PLRelease(value);
2856 return 0;
2860 static int
2861 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2863 if (scr->widget_texture) {
2864 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2866 scr->widget_texture = *(WTexSolid**)texture;
2868 if (scr->geometry_display != None)
2869 XSetWindowBackground(dpy, scr->geometry_display,
2870 scr->widget_texture->normal.pixel);
2872 return 0;
2876 static int
2877 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2879 if (scr->window_title_texture[WS_FOCUSED]) {
2880 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2882 scr->window_title_texture[WS_FOCUSED] = *texture;
2884 return REFRESH_WINDOW_TEXTURES;
2888 static int
2889 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2891 if (scr->window_title_texture[WS_PFOCUSED]) {
2892 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2894 scr->window_title_texture[WS_PFOCUSED] = *texture;
2896 return REFRESH_WINDOW_TEXTURES;
2900 static int
2901 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2903 if (scr->window_title_texture[WS_UNFOCUSED]) {
2904 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2906 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2908 return REFRESH_WINDOW_TEXTURES;
2912 static int
2913 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2915 if (scr->resizebar_texture[0]) {
2916 wTextureDestroy(scr, scr->resizebar_texture[0]);
2918 scr->resizebar_texture[0] = *texture;
2920 return REFRESH_WINDOW_TEXTURES;
2924 static int
2925 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2927 if (scr->menu_title_texture[0]) {
2928 wTextureDestroy(scr, scr->menu_title_texture[0]);
2930 scr->menu_title_texture[0] = *texture;
2932 return REFRESH_MENU_TITLE_TEXTURE;
2936 static int
2937 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2939 if (scr->menu_item_texture) {
2940 wTextureDestroy(scr, scr->menu_item_texture);
2941 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2943 scr->menu_item_texture = *texture;
2945 scr->menu_item_auxtexture
2946 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2948 return REFRESH_MENU_TEXTURE;
2952 static int
2953 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
2955 WWindow *wwin;
2956 wKeyBindings[index] = *shortcut;
2958 wwin = scr->focused_window;
2960 while (wwin!=NULL) {
2961 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2963 if (!WFLAGP(wwin, no_bind_keys)) {
2964 wWindowSetKeyGrabs(wwin);
2966 wwin = wwin->prev;
2969 return 0;
2973 static int
2974 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2976 wArrangeIcons(scr, True);
2978 return 0;
2982 static int
2983 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2985 wScreenUpdateUsableArea(scr);
2987 return 0;
2991 static int
2992 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2994 return REFRESH_MENU_TEXTURE;
2999 static int
3000 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3002 return REFRESH_BUTTON_IMAGES;
3007 * Very ugly kluge.
3008 * Need access to the double click variables, so that all widgets in
3009 * wmaker panels will have the same dbl-click values.
3010 * TODO: figure a better way of dealing with it.
3012 #include "WINGsP.h"
3014 static int
3015 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3017 extern _WINGsConfiguration WINGsConfiguration;
3019 if (*value <= 0)
3020 *(int*)foo = 1;
3022 WINGsConfiguration.doubleClickDelay = *value;
3024 return 0;
3029 static int
3030 setMultiByte(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3032 extern _WINGsConfiguration WINGsConfiguration;
3034 WINGsConfiguration.useMultiByte = *value;
3036 return 0;