fixed cosmetic bug in geom. dpy window for 8bpp
[wmaker-crm.git] / src / defaults.c
blob0ca2590e72314eb15b7aff2726927548f5f25d91
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 {"DisableBlinking", "NO", NULL,
496 &wPreferences.dont_blink, getBool, NULL
498 #ifdef WEENDOZE_CYCLE
499 {"WindozeCycling","NO", NULL,
500 &wPreferences.windoze_cycling, getBool, NULL
502 {"PopupSwitchMenu","YES", NULL,
503 &wPreferences.popup_switchmenu, getBool, NULL
505 #endif /* WEENDOZE_CYCLE */
506 /* style options */
507 {"MenuStyle", "normal", seMenuStyles,
508 &wPreferences.menu_style, getEnum, setMenuStyle
510 {"WidgetColor", "(solid, gray)", NULL,
511 NULL, getTexture, setWidgetColor,
513 {"WorkspaceSpecificBack","()", NULL,
514 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
516 /* WorkspaceBack must come after WorkspaceSpecificBack or
517 * WorkspaceBack wont know WorkspaceSpecificBack was also
518 * specified and 2 copies of wmsetbg will be launched */
519 {"WorkspaceBack", "(solid, black)", NULL,
520 NULL, getWSBackground,setWorkspaceBack
522 {"SmoothWorkspaceBack", "NO", NULL,
523 NULL, getBool, NULL
525 {"IconBack", "(solid, gray)", NULL,
526 NULL, getTexture, setIconTile
528 {"TitleJustify", "center", seJustifications,
529 &wPreferences.title_justification, getEnum, setJustify
531 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
532 NULL, getFont, setWinTitleFont,
534 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
535 NULL, getFont, setMenuTitleFont
537 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
538 NULL, getFont, setMenuTextFont
540 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
541 NULL, getFont, setIconTitleFont
543 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
544 NULL, getFont, setClipTitleFont
546 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
547 NULL, getFont, setDisplayFont
549 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
550 NULL, getFont, setLargeDisplayFont
552 {"HighlightColor", "white", NULL,
553 NULL, getColor, setHightlight
555 {"HighlightTextColor", "black", NULL,
556 NULL, getColor, setHightlightText
558 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
559 NULL, getColor, setClipTitleColor
561 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
562 NULL, getColor, setClipTitleColor
564 {"FTitleColor", "white", (void*)WS_FOCUSED,
565 NULL, getColor, setWTitleColor
567 {"PTitleColor", "white", (void*)WS_PFOCUSED,
568 NULL, getColor, setWTitleColor
570 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
571 NULL, getColor, setWTitleColor
573 {"FTitleBack", "(solid, black)", NULL,
574 NULL, getTexture, setFTitleBack
576 {"PTitleBack", "(solid, \"#616161\")", NULL,
577 NULL, getTexture, setPTitleBack
579 {"UTitleBack", "(solid, gray)", NULL,
580 NULL, getTexture, setUTitleBack
582 {"ResizebarBack", "(solid, gray)", NULL,
583 NULL, getTexture, setResizebarBack
585 {"MenuTitleColor", "white", NULL,
586 NULL, getColor, setMenuTitleColor
588 {"MenuTextColor", "black", NULL,
589 NULL, getColor, setMenuTextColor
591 {"MenuDisabledColor", "\"#616161\"", NULL,
592 NULL, getColor, setMenuDisabledColor
594 {"MenuTitleBack", "(solid, black)", NULL,
595 NULL, getTexture, setMenuTitleBack
597 {"MenuTextBack", "(solid, gray)", NULL,
598 NULL, getTexture, setMenuTextBack
600 {"IconTitleColor", "white", NULL,
601 NULL, getColor, setIconTitleColor
603 {"IconTitleBack", "black", NULL,
604 NULL, getColor, setIconTitleBack
606 /* keybindings */
607 #ifndef LITE
608 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
609 NULL, getKeybind, setKeyGrab
611 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
612 NULL, getKeybind, setKeyGrab
614 #endif /* LITE */
615 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
616 NULL, getKeybind, setKeyGrab
618 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
619 NULL, getKeybind, setKeyGrab
621 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
622 NULL, getKeybind, setKeyGrab
624 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
625 NULL, getKeybind, setKeyGrab
627 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
628 NULL, getKeybind, setKeyGrab
630 {"HideKey", "None", (void*)WKBD_HIDE,
631 NULL, getKeybind, setKeyGrab
633 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
634 NULL, getKeybind, setKeyGrab
636 {"CloseKey", "None", (void*)WKBD_CLOSE,
637 NULL, getKeybind, setKeyGrab
639 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
640 NULL, getKeybind, setKeyGrab
642 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
643 NULL, getKeybind, setKeyGrab
645 {"RaiseKey", "Meta+Up", (void*)WKBD_RAISE,
646 NULL, getKeybind, setKeyGrab
648 {"LowerKey", "Meta+Down", (void*)WKBD_LOWER,
649 NULL, getKeybind, setKeyGrab
651 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
652 NULL, getKeybind, setKeyGrab
654 {"ShadeKey", "None", (void*)WKBD_SHADE,
655 NULL, getKeybind, setKeyGrab
657 {"SelectKey", "None", (void*)WKBD_SELECT,
658 NULL, getKeybind, setKeyGrab
660 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
661 NULL, getKeybind, setKeyGrab
663 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
664 NULL, getKeybind, setKeyGrab
666 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
667 NULL, getKeybind, setKeyGrab
669 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
670 NULL, getKeybind, setKeyGrab
672 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
673 NULL, getKeybind, setKeyGrab
675 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
676 NULL, getKeybind, setKeyGrab
678 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
679 NULL, getKeybind, setKeyGrab
681 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
682 NULL, getKeybind, setKeyGrab
684 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
685 NULL, getKeybind, setKeyGrab
687 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
688 NULL, getKeybind, setKeyGrab
690 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
691 NULL, getKeybind, setKeyGrab
693 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
694 NULL, getKeybind, setKeyGrab
696 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
697 NULL, getKeybind, setKeyGrab
699 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
700 NULL, getKeybind, setKeyGrab
702 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
703 NULL, getKeybind, setKeyGrab
705 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
706 NULL, getKeybind, setKeyGrab
708 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
709 NULL, getKeybind, setKeyGrab
711 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
712 NULL, getKeybind, setKeyGrab
714 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
715 NULL, getKeybind, setKeyGrab
717 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
718 NULL, getKeybind, setKeyGrab
720 #ifdef EXTEND_WINDOWSHORTCUT
721 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
722 NULL, getKeybind, setKeyGrab
724 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
725 NULL, getKeybind, setKeyGrab
727 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
728 NULL, getKeybind, setKeyGrab
730 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
731 NULL, getKeybind, setKeyGrab
733 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
734 NULL, getKeybind, setKeyGrab
736 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
737 NULL, getKeybind, setKeyGrab
739 #endif /* EXTEND_WINDOWSHORTCUT */
741 #ifdef KEEP_XKB_LOCK_STATUS
742 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
743 NULL, getKeybind, setKeyGrab
745 {"KbdModeLock", "NO", NULL,
746 &wPreferences.modelock, getBool, NULL
748 #endif /* KEEP_XKB_LOCK_STATUS */
749 #ifdef TITLE_TEXT_SHADOW
750 ,{"FShadowColor", "black", (void*)WS_SFOCUSED,
751 NULL, getColor, setWTitleColor
753 {"PShadowColor", "black", (void*)WS_SPFOCUSED,
754 NULL, getColor, setWTitleColor
756 {"UShadowColor", "grey50", (void*)WS_SUNFOCUSED,
757 NULL, getColor, setWTitleColor
759 {"MShadowColor", "black", (void*)WS_SMENU,
760 NULL, getColor, setMenuTitleColor
762 {"Shadow", "Yes", NULL,
763 &wPreferences.title_shadow, getBool, setJustify
765 #endif /* TITLE_TEXT_SHADOW */
769 #if 0
770 static void rereadDefaults(void);
771 #endif
773 #if 0
774 static void
775 rereadDefaults(void)
777 /* must defer the update because accessing X data from a
778 * signal handler can mess up Xlib */
781 #endif
783 static void
784 initDefaults()
786 int i;
787 WDefaultEntry *entry;
789 PLSetStringCmpHook(StringCompareHook);
791 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
792 entry = &optionList[i];
794 entry->plkey = PLMakeString(entry->key);
795 if (entry->default_value)
796 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
797 else
798 entry->plvalue = NULL;
801 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
802 entry = &staticOptionList[i];
804 entry->plkey = PLMakeString(entry->key);
805 if (entry->default_value)
806 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
807 else
808 entry->plvalue = NULL;
812 wDomainName = PLMakeString(WMDOMAIN_NAME);
813 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
815 PLRegister(wDomainName, rereadDefaults);
816 PLRegister(wAttributeDomainName, rereadDefaults);
823 #if 0
824 proplist_t
825 wDefaultsInit(int screen_number)
827 static int defaults_inited = 0;
828 proplist_t dict;
830 if (!defaults_inited) {
831 initDefaults();
834 dict = PLGetDomain(wDomainName);
835 if (!dict) {
836 wwarning(_("could not read domain \"%s\" from defaults database"),
837 PLGetString(wDomainName));
840 return dict;
842 #endif
845 void
846 wDefaultsDestroyDomain(WDDomain *domain)
848 if (domain->dictionary)
849 PLRelease(domain->dictionary);
850 free(domain->path);
851 free(domain);
855 WDDomain*
856 wDefaultsInitDomain(char *domain, Bool requireDictionary)
858 WDDomain *db;
859 struct stat stbuf;
860 static int inited = 0;
861 char path[PATH_MAX];
862 char *the_path;
863 proplist_t shared_dict=NULL;
865 if (!inited) {
866 inited = 1;
867 initDefaults();
870 db = wmalloc(sizeof(WDDomain));
871 memset(db, 0, sizeof(WDDomain));
872 db->domain_name = domain;
873 db->path = wdefaultspathfordomain(domain);
874 the_path = db->path;
876 if (the_path && stat(the_path, &stbuf)>=0) {
877 db->dictionary = ReadProplistFromFile(the_path);
878 if (db->dictionary) {
879 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
880 PLRelease(db->dictionary);
881 db->dictionary = NULL;
882 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
883 domain, the_path);
885 db->timestamp = stbuf.st_mtime;
886 } else {
887 wwarning(_("could not load domain %s from user defaults database"),
888 domain);
892 /* global system dictionary */
893 sprintf(path, "%s/%s", SYSCONFDIR, domain);
894 if (stat(path, &stbuf)>=0) {
895 shared_dict = ReadProplistFromFile(path);
896 if (shared_dict) {
897 if (requireDictionary && !PLIsDictionary(shared_dict)) {
898 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
899 domain, path);
900 PLRelease(shared_dict);
901 shared_dict = NULL;
902 } else {
903 if (db->dictionary && PLIsDictionary(shared_dict) &&
904 PLIsDictionary(db->dictionary)) {
905 PLMergeDictionaries(shared_dict, db->dictionary);
906 PLRelease(db->dictionary);
907 db->dictionary = shared_dict;
908 if (stbuf.st_mtime > db->timestamp)
909 db->timestamp = stbuf.st_mtime;
910 } else if (!db->dictionary) {
911 db->dictionary = shared_dict;
912 if (stbuf.st_mtime > db->timestamp)
913 db->timestamp = stbuf.st_mtime;
916 } else {
917 wwarning(_("could not load domain %s from global defaults database"),
918 domain);
922 /* set to save it in user's directory, no matter from where it was read */
923 if (db->dictionary) {
924 proplist_t tmp = PLMakeString(db->path);
926 PLSetFilename(db->dictionary, tmp);
927 PLRelease(tmp);
930 return db;
934 void
935 wReadStaticDefaults(proplist_t dict)
937 proplist_t plvalue;
938 WDefaultEntry *entry;
939 int i;
940 void *tdata;
943 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
944 entry = &staticOptionList[i];
946 if (dict)
947 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
948 else
949 plvalue = NULL;
951 if (!plvalue) {
952 /* no default in the DB. Use builtin default */
953 plvalue = entry->plvalue;
956 if (plvalue) {
957 /* convert data */
958 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
959 if (entry->update) {
960 (*entry->update)(NULL, entry, tdata, entry->extra_data);
967 void
968 wDefaultsCheckDomains(void *foo)
970 WScreen *scr;
971 struct stat stbuf;
972 proplist_t dict;
973 int i;
974 char path[PATH_MAX];
976 #ifdef HEARTBEAT
977 puts("Checking domains...");
978 #endif
979 if (stat(WDWindowMaker->path, &stbuf)>=0
980 && WDWindowMaker->timestamp < stbuf.st_mtime) {
981 proplist_t shared_dict = NULL;
982 #ifdef HEARTBEAT
983 puts("Checking WindowMaker domain");
984 #endif
985 WDWindowMaker->timestamp = stbuf.st_mtime;
987 /* global dictionary */
988 sprintf(path, "%s/WindowMaker", SYSCONFDIR);
989 if (stat(path, &stbuf)>=0) {
990 shared_dict = ReadProplistFromFile(path);
991 if (shared_dict && !PLIsDictionary(shared_dict)) {
992 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
993 "WindowMaker", path);
994 PLRelease(shared_dict);
995 shared_dict = NULL;
996 } else if (!shared_dict) {
997 wwarning(_("could not load domain %s from global defaults database"),
998 "WindowMaker");
1001 /* user dictionary */
1002 dict = ReadProplistFromFile(WDWindowMaker->path);
1003 if (dict) {
1004 if (!PLIsDictionary(dict)) {
1005 PLRelease(dict);
1006 dict = NULL;
1007 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1008 "WindowMaker", WDWindowMaker->path);
1009 } else {
1010 if (shared_dict) {
1011 PLSetFilename(shared_dict, PLGetFilename(dict));
1012 PLMergeDictionaries(shared_dict, dict);
1013 PLRelease(dict);
1014 dict = shared_dict;
1015 shared_dict = NULL;
1017 for (i=0; i<wScreenCount; i++) {
1018 scr = wScreenWithNumber(i);
1019 if (scr)
1020 wReadDefaults(scr, dict);
1022 if (WDWindowMaker->dictionary) {
1023 PLRelease(WDWindowMaker->dictionary);
1025 WDWindowMaker->dictionary = dict;
1027 } else {
1028 wwarning(_("could not load domain %s from user defaults database"),
1029 "WindowMaker");
1031 if (shared_dict) {
1032 PLRelease(shared_dict);
1036 if (stat(WDWindowAttributes->path, &stbuf)>=0
1037 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1038 #ifdef HEARTBEAT
1039 puts("Checking WMWindowAttributes domain");
1040 #endif
1041 dict = ReadProplistFromFile(WDWindowAttributes->path);
1042 if (dict) {
1043 if (!PLIsDictionary(dict)) {
1044 PLRelease(dict);
1045 dict = NULL;
1046 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1047 "WMWindowAttributes", WDWindowAttributes->path);
1048 } else {
1049 if (WDWindowAttributes->dictionary)
1050 PLRelease(WDWindowAttributes->dictionary);
1051 WDWindowAttributes->dictionary = dict;
1052 for (i=0; i<wScreenCount; i++) {
1053 scr = wScreenWithNumber(i);
1054 if (scr)
1055 wDefaultUpdateIcons(scr);
1058 } else {
1059 wwarning(_("could not load domain %s from user defaults database"),
1060 "WMWindowAttributes");
1062 WDWindowAttributes->timestamp = stbuf.st_mtime;
1065 #ifndef LITE
1066 if (stat(WDRootMenu->path, &stbuf)>=0
1067 && WDRootMenu->timestamp < stbuf.st_mtime) {
1068 dict = ReadProplistFromFile(WDRootMenu->path);
1069 #ifdef HEARTBEAT
1070 puts("Checking WMRootMenu domain");
1071 #endif
1072 if (dict) {
1073 if (!PLIsArray(dict) && !PLIsString(dict)) {
1074 PLRelease(dict);
1075 dict = NULL;
1076 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1077 "WMRootMenu", WDRootMenu->path);
1078 } else {
1079 if (WDRootMenu->dictionary) {
1080 PLRelease(WDRootMenu->dictionary);
1082 WDRootMenu->dictionary = dict;
1084 } else {
1085 wwarning(_("could not load domain %s from user defaults database"),
1086 "WMRootMenu");
1088 WDRootMenu->timestamp = stbuf.st_mtime;
1090 #endif /* !LITE */
1092 if (!foo)
1093 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1097 void
1098 wReadDefaults(WScreen *scr, proplist_t new_dict)
1100 proplist_t plvalue, old_value;
1101 WDefaultEntry *entry;
1102 int i, must_update;
1103 int needs_refresh;
1104 void *tdata;
1105 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1106 ? WDWindowMaker->dictionary : NULL);
1108 must_update = 0;
1110 needs_refresh = 0;
1112 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1113 entry = &optionList[i];
1115 if (new_dict)
1116 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1117 else
1118 plvalue = NULL;
1120 if (!old_dict)
1121 old_value = NULL;
1122 else
1123 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1126 if (!plvalue && !old_value) {
1127 /* no default in the DB. Use builtin default */
1128 plvalue = entry->plvalue;
1129 if (plvalue && new_dict) {
1130 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1131 must_update = 1;
1133 } else if (!plvalue) {
1134 /* value was deleted from DB. Keep current value */
1135 continue;
1136 } else if (!old_value) {
1137 /* set value for the 1st time */
1138 } else if (!PLIsEqual(plvalue, old_value)) {
1139 /* value has changed */
1140 } else {
1141 /* value was not changed since last time */
1142 continue;
1145 if (plvalue) {
1146 #ifdef DEBUG
1147 printf("Updating %s to %s\n", entry->key, PLGetDescription(plvalue));
1148 #endif
1149 /* convert data */
1150 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1151 if (entry->update) {
1152 needs_refresh |=
1153 (*entry->update)(scr, entry, tdata, entry->extra_data);
1159 if (needs_refresh!=0 && !scr->flags.startup) {
1160 int foo;
1162 foo = 0;
1163 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1164 foo |= WTextureSettings;
1165 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1166 foo |= WFontSettings;
1167 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1168 foo |= WColorSettings;
1169 if (foo)
1170 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1171 (void*)foo);
1173 foo = 0;
1174 if (needs_refresh & REFRESH_MENU_TEXTURE)
1175 foo |= WTextureSettings;
1176 if (needs_refresh & REFRESH_MENU_FONT)
1177 foo |= WFontSettings;
1178 if (needs_refresh & REFRESH_MENU_COLOR)
1179 foo |= WColorSettings;
1180 if (foo)
1181 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1182 (void*)foo);
1184 foo = 0;
1185 if (needs_refresh & REFRESH_WINDOW_FONT) {
1186 foo |= WFontSettings;
1188 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1189 foo |= WTextureSettings;
1191 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1192 foo |= WColorSettings;
1194 if (foo)
1195 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1196 (void*)foo);
1198 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1199 foo = 0;
1200 if (needs_refresh & REFRESH_ICON_FONT) {
1201 foo |= WFontSettings;
1203 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1204 foo |= WTextureSettings;
1206 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1207 foo |= WTextureSettings;
1209 if (foo)
1210 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1211 (void*)foo);
1213 if (needs_refresh & REFRESH_ICON_TILE)
1214 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1219 void
1220 wDefaultUpdateIcons(WScreen *scr)
1222 WAppIcon *aicon = scr->app_icon_list;
1223 WWindow *wwin = scr->focused_window;
1224 char *file;
1226 while(aicon) {
1227 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1228 False);
1229 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1230 || (file && !aicon->icon->file)) {
1231 RImage *new_image;
1233 if (aicon->icon->file)
1234 free(aicon->icon->file);
1235 aicon->icon->file = wstrdup(file);
1237 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1238 aicon->wm_class);
1239 if (new_image) {
1240 wIconChangeImage(aicon->icon, new_image);
1241 wAppIconPaint(aicon);
1244 aicon = aicon->next;
1247 if (!wPreferences.flags.noclip)
1248 wClipIconPaint(scr->clip_icon);
1250 while (wwin) {
1251 if (wwin->icon && wwin->flags.miniaturized) {
1252 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1253 False);
1254 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1255 || (file && !wwin->icon->file)) {
1256 RImage *new_image;
1258 if (wwin->icon->file)
1259 free(wwin->icon->file);
1260 wwin->icon->file = wstrdup(file);
1262 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1263 wwin->wm_class);
1264 if (new_image)
1265 wIconChangeImage(wwin->icon, new_image);
1268 wwin = wwin->prev;
1273 /* --------------------------- Local ----------------------- */
1275 #define STRINGP(x) if (!PLIsString(value)) { \
1276 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1277 entry->key, x); \
1278 return False; }
1282 static int
1283 string2index(proplist_t key, proplist_t val, proplist_t def,
1284 WOptionEnumeration *values)
1286 char *str;
1287 WOptionEnumeration *v;
1288 char buffer[TOTAL_VALUES_LENGTH];
1290 if (PLIsString(val) && (str = PLGetString(val))) {
1291 for (v=values; v->string!=NULL; v++) {
1292 if (strcasecmp(v->string, str)==0)
1293 return v->value;
1297 buffer[0] = 0;
1298 for (v=values; v->string!=NULL; v++) {
1299 if (!v->is_alias) {
1300 if (buffer[0]!=0)
1301 strcat(buffer, ", ");
1302 strcat(buffer, v->string);
1305 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1306 PLGetString(key), buffer);
1308 if (def) {
1309 return string2index(key, val, NULL, values);
1312 return -1;
1319 * value - is the value in the defaults DB
1320 * addr - is the address to store the data
1321 * ret - is the address to store a pointer to a temporary buffer. ret
1322 * must not be freed and is used by the set functions
1324 static int
1325 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1326 void **ret)
1328 static char data;
1329 char *val;
1330 int second_pass=0;
1332 STRINGP("Boolean");
1334 val = PLGetString(value);
1336 again:
1337 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1338 || strcasecmp(val, "YES")==0) {
1340 data = 1;
1341 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1342 || strcasecmp(val, "NO")==0) {
1343 data = 0;
1344 } else {
1345 int i;
1346 if (sscanf(val, "%i", &i)==1) {
1347 if (i!=0)
1348 data = 1;
1349 else
1350 data = 0;
1351 } else {
1352 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1353 val, entry->key);
1354 if (second_pass==0) {
1355 val = PLGetString(entry->plvalue);
1356 second_pass = 1;
1357 wwarning(_("using default \"%s\" instead"), val);
1358 goto again;
1360 return False;
1364 if (ret)
1365 *ret = &data;
1367 if (addr) {
1368 *(char*)addr = data;
1371 return True;
1375 static int
1376 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1377 void **ret)
1379 static int data;
1380 char *val;
1383 STRINGP("Integer");
1385 val = PLGetString(value);
1387 if (sscanf(val, "%i", &data)!=1) {
1388 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1389 val, entry->key);
1390 val = PLGetString(entry->plvalue);
1391 wwarning(_("using default \"%s\" instead"), val);
1392 if (sscanf(val, "%i", &data)!=1) {
1393 return False;
1397 if (ret)
1398 *ret = &data;
1400 if (addr) {
1401 *(int*)addr = data;
1403 return True;
1407 static int
1408 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1409 void **ret)
1411 static WCoord data;
1412 char *val_x, *val_y;
1413 int nelem, changed=0;
1414 proplist_t elem_x, elem_y;
1416 again:
1417 if (!PLIsArray(value)) {
1418 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1419 entry->key, "Coordinate");
1420 if (changed==0) {
1421 value = entry->plvalue;
1422 changed = 1;
1423 wwarning(_("using default \"%s\" instead"), entry->default_value);
1424 goto again;
1426 return False;
1429 nelem = PLGetNumberOfElements(value);
1430 if (nelem != 2) {
1431 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1432 entry->key);
1433 if (changed==0) {
1434 value = entry->plvalue;
1435 changed = 1;
1436 wwarning(_("using default \"%s\" instead"), entry->default_value);
1437 goto again;
1439 return False;
1442 elem_x = PLGetArrayElement(value, 0);
1443 elem_y = PLGetArrayElement(value, 1);
1445 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1446 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1447 entry->key);
1448 if (changed==0) {
1449 value = entry->plvalue;
1450 changed = 1;
1451 wwarning(_("using default \"%s\" instead"), entry->default_value);
1452 goto again;
1454 return False;
1457 val_x = PLGetString(elem_x);
1458 val_y = PLGetString(elem_y);
1460 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1461 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1462 if (changed==0) {
1463 value = entry->plvalue;
1464 changed = 1;
1465 wwarning(_("using default \"%s\" instead"), entry->default_value);
1466 goto again;
1468 return False;
1471 if (data.x < 0)
1472 data.x = 0;
1473 else if (data.x > scr->scr_width/3)
1474 data.x = scr->scr_width/3;
1475 if (data.y < 0)
1476 data.y = 0;
1477 else if (data.y > scr->scr_height/3)
1478 data.y = scr->scr_height/3;
1480 if (ret)
1481 *ret = &data;
1483 if (addr) {
1484 *(WCoord*)addr = data;
1487 return True;
1491 #if 0
1492 /* This function is not used at the moment. */
1493 static int
1494 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1495 void **ret)
1497 static char *data;
1499 STRINGP("String");
1501 data = PLGetString(value);
1503 if (!data) {
1504 data = PLGetString(entry->plvalue);
1505 if (!data)
1506 return False;
1509 if (ret)
1510 *ret = &data;
1512 if (addr)
1513 *(char**)addr = wstrdup(data);
1515 return True;
1517 #endif
1520 static int
1521 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1522 void **ret)
1524 static char *data;
1525 int i, count, len;
1526 char *ptr;
1527 proplist_t d;
1528 int changed=0;
1530 again:
1531 if (!PLIsArray(value)) {
1532 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1533 entry->key, "an array of paths");
1534 if (changed==0) {
1535 value = entry->plvalue;
1536 changed = 1;
1537 wwarning(_("using default \"%s\" instead"), entry->default_value);
1538 goto again;
1540 return False;
1543 i = 0;
1544 count = PLGetNumberOfElements(value);
1545 if (count < 1) {
1546 if (changed==0) {
1547 value = entry->plvalue;
1548 changed = 1;
1549 wwarning(_("using default \"%s\" instead"), entry->default_value);
1550 goto again;
1552 return False;
1555 len = 0;
1556 for (i=0; i<count; i++) {
1557 d = PLGetArrayElement(value, i);
1558 if (!d || !PLIsString(d)) {
1559 count = i;
1560 break;
1562 len += strlen(PLGetString(d))+1;
1565 ptr = data = wmalloc(len+1);
1567 for (i=0; i<count; i++) {
1568 d = PLGetArrayElement(value, i);
1569 if (!d || !PLIsString(d)) {
1570 break;
1572 strcpy(ptr, PLGetString(d));
1573 ptr += strlen(PLGetString(d));
1574 *ptr = ':';
1575 ptr++;
1577 ptr--; *(ptr--) = 0;
1579 if (*(char**)addr!=NULL) {
1580 free(*(char**)addr);
1582 *(char**)addr = data;
1584 return True;
1588 static int
1589 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1590 void **ret)
1592 static signed char data;
1594 data = string2index(entry->plkey, value, entry->default_value,
1595 (WOptionEnumeration*)entry->extra_data);
1596 if (data < 0)
1597 return False;
1599 if (ret)
1600 *ret = &data;
1602 if (addr)
1603 *(signed char*)addr = data;
1605 return True;
1611 * (solid <color>)
1612 * (hgradient <color> <color>)
1613 * (vgradient <color> <color>)
1614 * (dgradient <color> <color>)
1615 * (mhgradient <color> <color> ...)
1616 * (mvgradient <color> <color> ...)
1617 * (tpixmap <file> <color>)
1618 * (spixmap <file> <color>)
1619 * (cpixmap <file> <color>)
1620 * (thgradient <file> <opaqueness> <color> <color>)
1621 * (tvgradient <file> <opaqueness> <color> <color>)
1622 * (tdgradient <file> <opaqueness> <color> <color>)
1623 * (function <lib> <function> ...)
1626 static WTexture*
1627 parse_texture(WScreen *scr, proplist_t pl)
1629 proplist_t elem;
1630 char *val;
1631 int nelem;
1632 WTexture *texture=NULL;
1634 nelem = PLGetNumberOfElements(pl);
1635 if (nelem < 1)
1636 return NULL;
1639 elem = PLGetArrayElement(pl, 0);
1640 if (!elem || !PLIsString(elem))
1641 return NULL;
1642 val = PLGetString(elem);
1645 if (strcasecmp(val, "solid")==0) {
1646 XColor color;
1648 if (nelem != 2)
1649 return NULL;
1651 /* get color */
1653 elem = PLGetArrayElement(pl, 1);
1654 if (!elem || !PLIsString(elem))
1655 return NULL;
1656 val = PLGetString(elem);
1658 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1659 wwarning(_("\"%s\" is not a valid color name"), val);
1660 return NULL;
1663 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1664 } else if (strcasecmp(val, "dgradient")==0
1665 || strcasecmp(val, "vgradient")==0
1666 || strcasecmp(val, "hgradient")==0) {
1667 RColor color1, color2;
1668 XColor xcolor;
1669 int type;
1671 if (nelem != 3) {
1672 wwarning(_("bad number of arguments in gradient specification"));
1673 return NULL;
1676 if (val[0]=='d' || val[0]=='D')
1677 type = WTEX_DGRADIENT;
1678 else if (val[0]=='h' || val[0]=='H')
1679 type = WTEX_HGRADIENT;
1680 else
1681 type = WTEX_VGRADIENT;
1684 /* get from color */
1685 elem = PLGetArrayElement(pl, 1);
1686 if (!elem || !PLIsString(elem))
1687 return NULL;
1688 val = PLGetString(elem);
1690 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1691 wwarning(_("\"%s\" is not a valid color name"), val);
1692 return NULL;
1694 color1.alpha = 255;
1695 color1.red = xcolor.red >> 8;
1696 color1.green = xcolor.green >> 8;
1697 color1.blue = xcolor.blue >> 8;
1699 /* get to color */
1700 elem = PLGetArrayElement(pl, 2);
1701 if (!elem || !PLIsString(elem)) {
1702 return NULL;
1704 val = PLGetString(elem);
1706 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1707 wwarning(_("\"%s\" is not a valid color name"), val);
1708 return NULL;
1710 color2.alpha = 255;
1711 color2.red = xcolor.red >> 8;
1712 color2.green = xcolor.green >> 8;
1713 color2.blue = xcolor.blue >> 8;
1715 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1717 } else if (strcasecmp(val, "mhgradient")==0
1718 || strcasecmp(val, "mvgradient")==0
1719 || strcasecmp(val, "mdgradient")==0) {
1720 XColor color;
1721 RColor **colors;
1722 int i, count;
1723 int type;
1725 if (nelem < 3) {
1726 wwarning(_("too few arguments in multicolor gradient specification"));
1727 return NULL;
1730 if (val[1]=='h' || val[1]=='H')
1731 type = WTEX_MHGRADIENT;
1732 else if (val[1]=='v' || val[1]=='V')
1733 type = WTEX_MVGRADIENT;
1734 else
1735 type = WTEX_MDGRADIENT;
1737 count = nelem-1;
1739 colors = wmalloc(sizeof(RColor*)*(count+1));
1741 for (i=0; i<count; i++) {
1742 elem = PLGetArrayElement(pl, i+1);
1743 if (!elem || !PLIsString(elem)) {
1744 for (--i; i>=0; --i) {
1745 free(colors[i]);
1747 free(colors);
1748 return NULL;
1750 val = PLGetString(elem);
1752 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1753 wwarning(_("\"%s\" is not a valid color name"), val);
1754 for (--i; i>=0; --i) {
1755 free(colors[i]);
1757 free(colors);
1758 return NULL;
1759 } else {
1760 colors[i] = wmalloc(sizeof(RColor));
1761 colors[i]->red = color.red >> 8;
1762 colors[i]->green = color.green >> 8;
1763 colors[i]->blue = color.blue >> 8;
1766 colors[i] = NULL;
1768 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1769 } else if (strcasecmp(val, "spixmap")==0 ||
1770 strcasecmp(val, "cpixmap")==0 ||
1771 strcasecmp(val, "tpixmap")==0) {
1772 XColor color;
1773 int type;
1775 if (nelem != 3)
1776 return NULL;
1778 if (val[0] == 's' || val[0] == 'S')
1779 type = WTP_SCALE;
1780 else if (val[0] == 'c' || val[0] == 'C')
1781 type = WTP_CENTER;
1782 else
1783 type = WTP_TILE;
1785 /* get color */
1786 elem = PLGetArrayElement(pl, 2);
1787 if (!elem || !PLIsString(elem)) {
1788 return NULL;
1790 val = PLGetString(elem);
1792 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1793 wwarning(_("\"%s\" is not a valid color name"), val);
1794 return NULL;
1797 /* file name */
1798 elem = PLGetArrayElement(pl, 1);
1799 if (!elem || !PLIsString(elem))
1800 return NULL;
1801 val = PLGetString(elem);
1803 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1804 } else if (strcasecmp(val, "thgradient")==0
1805 || strcasecmp(val, "tvgradient")==0
1806 || strcasecmp(val, "tdgradient")==0) {
1807 RColor color1, color2;
1808 XColor xcolor;
1809 int opacity;
1810 int style;
1812 if (val[1]=='h' || val[1]=='H')
1813 style = WTEX_THGRADIENT;
1814 else if (val[1]=='v' || val[1]=='V')
1815 style = WTEX_TVGRADIENT;
1816 else
1817 style = WTEX_TDGRADIENT;
1819 if (nelem != 5) {
1820 wwarning(_("bad number of arguments in textured gradient specification"));
1821 return NULL;
1824 /* get from color */
1825 elem = PLGetArrayElement(pl, 3);
1826 if (!elem || !PLIsString(elem))
1827 return NULL;
1828 val = PLGetString(elem);
1830 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1831 wwarning(_("\"%s\" is not a valid color name"), val);
1832 return NULL;
1834 color1.alpha = 255;
1835 color1.red = xcolor.red >> 8;
1836 color1.green = xcolor.green >> 8;
1837 color1.blue = xcolor.blue >> 8;
1839 /* get to color */
1840 elem = PLGetArrayElement(pl, 4);
1841 if (!elem || !PLIsString(elem)) {
1842 return NULL;
1844 val = PLGetString(elem);
1846 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1847 wwarning(_("\"%s\" is not a valid color name"), val);
1848 return NULL;
1850 color2.alpha = 255;
1851 color2.red = xcolor.red >> 8;
1852 color2.green = xcolor.green >> 8;
1853 color2.blue = xcolor.blue >> 8;
1855 /* get opacity */
1856 elem = PLGetArrayElement(pl, 2);
1857 if (!elem || !PLIsString(elem))
1858 opacity = 128;
1859 else
1860 val = PLGetString(elem);
1862 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1863 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1864 opacity = 128;
1867 /* get file name */
1868 elem = PLGetArrayElement(pl, 1);
1869 if (!elem || !PLIsString(elem))
1870 return NULL;
1871 val = PLGetString(elem);
1873 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1874 val, opacity);
1876 #ifdef TEXTURE_PLUGIN
1877 else if (strcasecmp(val, "function")==0) {
1878 WTexFunction *function;
1879 void (*initFunc) (Display *, Colormap);
1880 char *lib, *func, **argv;
1881 int i, argc;
1883 if (nelem < 3)
1884 return NULL;
1886 /* get the library name */
1887 elem = PLGetArrayElement(pl, 1);
1888 if (!elem || !PLIsString(elem)) {
1889 return NULL;
1891 lib = PLGetString(elem);
1893 /* get the function name */
1894 elem = PLGetArrayElement(pl, 2);
1895 if (!elem || !PLIsString(elem)) {
1896 return NULL;
1898 func = PLGetString(elem);
1900 argc = nelem - 2;
1901 argv = (char **)wmalloc(argc * sizeof(char *));
1903 /* get the parameters */
1904 argv[0] = wstrdup(func);
1905 for (i = 0; i < argc - 1; i++) {
1906 elem = PLGetArrayElement(pl, 3 + i);
1907 if (!elem || !PLIsString(elem)) {
1908 free(argv);
1910 return NULL;
1912 argv[i+1] = wstrdup(PLGetString(elem));
1915 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1917 #ifdef HAVE_DLFCN_H
1918 if (function) {
1919 initFunc = dlsym(function->handle, "initWindowMaker");
1920 if (initFunc) {
1921 initFunc(dpy, scr->w_colormap);
1922 } else {
1923 wwarning(_("could not initialize library %s"), lib);
1925 } else {
1926 wwarning(_("could not find function %s::%s"), lib, func);
1928 #endif /* HAVE_DLFCN_H */
1929 texture = (WTexture*)function;
1931 #endif /* TEXTURE_PLUGIN */
1932 else {
1933 wwarning(_("invalid texture type %s"), val);
1934 return NULL;
1936 return texture;
1941 static int
1942 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1943 void **ret)
1945 static WTexture *texture;
1946 int changed=0;
1948 again:
1949 if (!PLIsArray(value)) {
1950 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1951 entry->key, "Texture");
1952 if (changed==0) {
1953 value = entry->plvalue;
1954 changed = 1;
1955 wwarning(_("using default \"%s\" instead"), entry->default_value);
1956 goto again;
1958 return False;
1961 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
1962 proplist_t pl;
1964 pl = PLGetArrayElement(value, 0);
1965 if (!pl || !PLIsString(pl) || !PLGetString(pl)
1966 || strcasecmp(PLGetString(pl), "solid")!=0) {
1967 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1968 entry->key, "Solid Texture");
1970 value = entry->plvalue;
1971 changed = 1;
1972 wwarning(_("using default \"%s\" instead"), entry->default_value);
1973 goto again;
1977 texture = parse_texture(scr, value);
1979 if (!texture) {
1980 wwarning(_("Error in texture specification for key \"%s\""),
1981 entry->key);
1982 if (changed==0) {
1983 value = entry->plvalue;
1984 changed = 1;
1985 wwarning(_("using default \"%s\" instead"), entry->default_value);
1986 goto again;
1988 return False;
1991 if (ret)
1992 *ret = &texture;
1994 if (addr)
1995 *(WTexture**)addr = texture;
1997 return True;
2002 static int
2003 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2004 void *addr, void **ret)
2006 proplist_t elem;
2007 int changed = 0;
2008 char *val;
2009 int nelem;
2011 again:
2012 if (!PLIsArray(value)) {
2013 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2014 "WorkspaceBack", "Texture or None");
2015 if (changed==0) {
2016 value = entry->plvalue;
2017 changed = 1;
2018 wwarning(_("using default \"%s\" instead"), entry->default_value);
2019 goto again;
2021 return False;
2024 /* only do basic error checking and verify for None texture */
2026 nelem = PLGetNumberOfElements(value);
2027 if (nelem > 0) {
2028 elem = PLGetArrayElement(value, 0);
2029 if (!elem || !PLIsString(elem)) {
2030 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2031 if (changed==0) {
2032 value = entry->plvalue;
2033 changed = 1;
2034 wwarning(_("using default \"%s\" instead"), entry->default_value);
2035 goto again;
2037 return False;
2039 val = PLGetString(elem);
2041 if (strcasecmp(val, "None")==0)
2042 return True;
2044 *ret = PLRetain(value);
2046 return True;
2050 static int
2051 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2052 void *addr, void **ret)
2054 proplist_t elem;
2055 int nelem;
2056 int changed = 0;
2058 again:
2059 if (!PLIsArray(value)) {
2060 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2061 "WorkspaceSpecificBack", "an array of textures");
2062 if (changed==0) {
2063 value = entry->plvalue;
2064 changed = 1;
2065 wwarning(_("using default \"%s\" instead"), entry->default_value);
2066 goto again;
2068 return False;
2071 /* only do basic error checking and verify for None texture */
2073 nelem = PLGetNumberOfElements(value);
2074 if (nelem > 0) {
2075 while (nelem--) {
2076 elem = PLGetArrayElement(value, nelem);
2077 if (!elem || !PLIsArray(elem)) {
2078 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2079 nelem);
2084 *ret = PLRetain(value);
2086 #ifdef notworking
2088 * Kluge to force wmsetbg helper to set the default background.
2089 * If the WorkspaceSpecificBack is changed once wmaker has started,
2090 * the WorkspaceBack won't be sent to the helper, unless the user
2091 * changes it's value too. So, we must force this by removing the
2092 * value from the defaults DB.
2094 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2095 proplist_t key = PLMakeString("WorkspaceBack");
2097 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2099 PLRelease(key);
2101 #endif
2102 return True;
2106 static int
2107 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2108 void **ret)
2110 static WMFont *font;
2111 char *val;
2113 STRINGP("Font");
2115 val = PLGetString(value);
2117 font = WMCreateFont(scr->wmscreen, val);
2118 if (!font) {
2119 wfatal(_("could not load any usable font!!!"));
2120 exit(1);
2123 if (ret)
2124 *ret = font;
2126 /* can't assign font value outside update function */
2127 wassertrv(addr == NULL, True);
2129 return True;
2133 static int
2134 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2135 void **ret)
2137 static XColor color;
2138 char *val;
2139 int second_pass=0;
2141 STRINGP("Color");
2143 val = PLGetString(value);
2145 again:
2146 if (!wGetColor(scr, val, &color)) {
2147 wwarning(_("could not get color for key \"%s\""),
2148 entry->key);
2149 if (second_pass==0) {
2150 val = PLGetString(entry->plvalue);
2151 second_pass = 1;
2152 wwarning(_("using default \"%s\" instead"), val);
2153 goto again;
2155 return False;
2158 if (ret)
2159 *ret = &color;
2161 assert(addr==NULL);
2163 if (addr)
2164 *(unsigned long*)addr = pixel;
2167 return True;
2172 static int
2173 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2174 void **ret)
2176 static WShortKey shortcut;
2177 KeySym ksym;
2178 char *val;
2179 char *k;
2180 char buf[128], *b;
2183 STRINGP("Key spec");
2185 val = PLGetString(value);
2187 if (!val || strcasecmp(val, "NONE")==0) {
2188 shortcut.keycode = 0;
2189 shortcut.modifier = 0;
2190 if (ret)
2191 *ret = &shortcut;
2192 return True;
2195 strcpy(buf, val);
2197 b = (char*)buf;
2199 /* get modifiers */
2200 shortcut.modifier = 0;
2201 while ((k = strchr(b, '+'))!=NULL) {
2202 int mod;
2204 *k = 0;
2205 mod = wXModifierFromKey(b);
2206 if (mod<0) {
2207 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2208 return False;
2210 shortcut.modifier |= mod;
2212 b = k+1;
2215 /* get key */
2216 ksym = XStringToKeysym(b);
2218 if (ksym==NoSymbol) {
2219 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2220 val);
2221 return False;
2224 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2225 if (shortcut.keycode==0) {
2226 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2227 return False;
2230 if (ret)
2231 *ret = &shortcut;
2233 return True;
2237 static int
2238 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2239 void **ret)
2241 static unsigned int mask;
2242 char *str;
2244 STRINGP("Modifier Key");
2246 str = PLGetString(value);
2247 if (!str)
2248 return False;
2250 mask = wXModifierFromKey(str);
2251 if (mask < 0) {
2252 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2253 mask = 0;
2254 return False;
2257 if (addr)
2258 *(unsigned int*)addr = mask;
2260 if (ret)
2261 *ret = &mask;
2263 return True;
2267 #ifdef NEWSTUFF
2268 static int
2269 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2270 void *addr, void **ret)
2272 unsigned int mask;
2273 char *str;
2274 RImage *image;
2275 int i, n;
2276 int w, h;
2278 STRINGP("Image File Path");
2280 str = PLGetString(value);
2281 if (!str)
2282 return False;
2284 image = RLoadImage(scr->rcontext, str, 0);
2285 if (!image) {
2286 wwarning(_("could not load image in option %s: %s"), entry->key,
2287 RMessageForError(RErrorCode));
2288 return False;
2291 if (*(RImage**)addr) {
2292 RDestroyImage(*(RImage**)addr);
2294 if (addr)
2295 *(RImage**)addr = image;
2297 assert(ret == NULL);
2299 if (ret)
2300 *(RImage**)ret = image;
2303 return True;
2305 #endif
2308 /* ---------------- value setting functions --------------- */
2309 static int
2310 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2312 return REFRESH_WINDOW_TITLE_COLOR;
2316 static int
2317 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2319 switch (which) {
2320 case WM_DOCK:
2321 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2322 break;
2323 case WM_CLIP:
2324 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2325 break;
2326 default:
2327 break;
2329 return 0;
2333 static int
2334 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2336 if (scr->workspaces) {
2337 wWorkspaceForceChange(scr, scr->current_workspace);
2338 wArrangeIcons(scr, False);
2340 return 0;
2343 #if not_used
2344 static int
2345 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2347 if (*value <= 0)
2348 *(int*)foo = 1;
2350 return 0;
2352 #endif
2356 static int
2357 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2359 Pixmap pixmap;
2360 RImage *img;
2361 int reset = 0;
2363 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2364 wPreferences.icon_size,
2365 ((*texture)->any.type & WREL_BORDER_MASK)
2366 ? WREL_ICON : WREL_FLAT);
2367 if (!img) {
2368 wwarning(_("could not render texture for icon background"));
2369 if (!entry->addr)
2370 wTextureDestroy(scr, *texture);
2371 return 0;
2373 RConvertImage(scr->rcontext, img, &pixmap);
2375 if (scr->icon_tile) {
2376 reset = 1;
2377 RDestroyImage(scr->icon_tile);
2378 XFreePixmap(dpy, scr->icon_tile_pixmap);
2381 scr->icon_tile = img;
2383 if (!wPreferences.flags.noclip) {
2384 if (scr->clip_tile) {
2385 RDestroyImage(scr->clip_tile);
2387 scr->clip_tile = wClipMakeTile(scr, img);
2390 scr->icon_tile_pixmap = pixmap;
2392 if (scr->def_icon_pixmap) {
2393 XFreePixmap(dpy, scr->def_icon_pixmap);
2394 scr->def_icon_pixmap = None;
2396 if (scr->def_ticon_pixmap) {
2397 XFreePixmap(dpy, scr->def_ticon_pixmap);
2398 scr->def_ticon_pixmap = None;
2401 if (scr->icon_back_texture) {
2402 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2404 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2406 if (scr->clip_balloon)
2407 XSetWindowBackground(dpy, scr->clip_balloon,
2408 (*texture)->any.color.pixel);
2411 * Free the texture as nobody else will use it, nor refer to it.
2413 if (!entry->addr)
2414 wTextureDestroy(scr, *texture);
2416 return (reset ? REFRESH_ICON_TILE : 0);
2421 static int
2422 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2424 if (scr->title_font) {
2425 WMReleaseFont(scr->title_font);
2427 scr->title_font = font;
2429 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2433 static int
2434 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2436 if (scr->menu_title_font) {
2437 WMReleaseFont(scr->menu_title_font);
2440 scr->menu_title_font = font;
2442 return REFRESH_MENU_TITLE_FONT;
2446 static int
2447 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2449 if (scr->menu_entry_font) {
2450 WMReleaseFont(scr->menu_entry_font);
2452 scr->menu_entry_font = font;
2454 return REFRESH_MENU_FONT;
2459 static int
2460 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2462 if (scr->icon_title_font) {
2463 WMReleaseFont(scr->icon_title_font);
2466 scr->icon_title_font = font;
2468 return REFRESH_ICON_FONT;
2472 static int
2473 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2475 if (scr->clip_title_font) {
2476 WMReleaseFont(scr->clip_title_font);
2479 scr->clip_title_font = font;
2481 return REFRESH_ICON_FONT;
2485 static int
2486 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2488 if (scr->info_text_font) {
2489 WMReleaseFont(scr->info_text_font);
2492 scr->info_text_font = font;
2494 /* This test works because the scr structure is initially zeroed out
2495 and None = 0. Any other time, the window should be valid. */
2496 if (scr->geometry_display != None) {
2497 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2498 &scr->geometry_display_height);
2499 XResizeWindow(dpy, scr->geometry_display,
2500 scr->geometry_display_width, scr->geometry_display_height);
2503 return 0;
2507 static int
2508 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2510 if (scr->workspace_name_font) {
2511 WMReleaseFont(scr->workspace_name_font);
2514 scr->workspace_name_font = font;
2516 return 0;
2520 static int
2521 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2523 if (scr->select_pixel!=scr->white_pixel &&
2524 scr->select_pixel!=scr->black_pixel) {
2525 wFreeColor(scr, scr->select_pixel);
2528 scr->select_pixel = color->pixel;
2530 return REFRESH_MENU_COLOR;
2534 static int
2535 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2537 if (scr->select_text_pixel!=scr->white_pixel &&
2538 scr->select_text_pixel!=scr->black_pixel) {
2539 wFreeColor(scr, scr->select_text_pixel);
2542 scr->select_text_pixel = color->pixel;
2544 return REFRESH_MENU_COLOR;
2548 static int
2549 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2551 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2552 scr->clip_title_pixel[index]!=scr->black_pixel) {
2553 wFreeColor(scr, scr->clip_title_pixel[index]);
2555 scr->clip_title_pixel[index] = color->pixel;
2557 #ifdef GRADIENT_CLIP_ARROW
2558 if (index == CLIP_NORMAL) {
2559 RImage *image;
2560 RColor color1, color2;
2561 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2562 int as = pt - 15; /* 15 = 5+5+5 */
2564 FREE_PIXMAP(scr->clip_arrow_gradient);
2566 color1.red = (color->red >> 8)*6/10;
2567 color1.green = (color->green >> 8)*6/10;
2568 color1.blue = (color->blue >> 8)*6/10;
2570 color2.red = WMIN((color->red >> 8)*20/10, 255);
2571 color2.green = WMIN((color->green >> 8)*20/10, 255);
2572 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2574 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2575 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2576 RDestroyImage(image);
2578 #endif /* GRADIENT_CLIP_ARROW */
2580 return REFRESH_ICON_TITLE_COLOR;
2584 static int
2585 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2587 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2588 scr->window_title_pixel[index]!=scr->black_pixel) {
2589 wFreeColor(scr, scr->window_title_pixel[index]);
2592 scr->window_title_pixel[index] = color->pixel;
2594 if (index == WS_UNFOCUSED)
2595 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2597 return REFRESH_WINDOW_TITLE_COLOR;
2601 static int
2602 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2604 #ifdef TITLE_TEXT_SHADOW
2605 if (index == WS_SMENU){
2606 if (scr->menu_title_pixel[WS_SMENU]!=scr->white_pixel &&
2607 scr->menu_title_pixel[WS_SMENU]!=scr->black_pixel) {
2608 wFreeColor(scr, scr->menu_title_pixel[WS_SMENU]);
2610 scr->menu_title_pixel[WS_SMENU] = color->pixel;
2612 else {
2613 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2614 scr->menu_title_pixel[0]!=scr->black_pixel) {
2615 wFreeColor(scr, scr->menu_title_pixel[0]);
2617 scr->menu_title_pixel[0] = color->pixel;
2619 #else /* !TITLE_TEXT_SHADOW */
2620 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2621 scr->menu_title_pixel[0]!=scr->black_pixel) {
2622 wFreeColor(scr, scr->menu_title_pixel[0]);
2625 scr->menu_title_pixel[0] = color->pixel;
2626 #endif /* !TITLE_TEXT_SHADOW */
2627 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2629 return REFRESH_MENU_TITLE_COLOR;
2633 static int
2634 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2636 XGCValues gcv;
2637 #define gcm (GCForeground|GCBackground|GCFillStyle)
2639 if (scr->mtext_pixel!=scr->white_pixel &&
2640 scr->mtext_pixel!=scr->black_pixel) {
2641 wFreeColor(scr, scr->mtext_pixel);
2644 scr->mtext_pixel = color->pixel;
2646 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2649 if (scr->dtext_pixel == scr->mtext_pixel) {
2650 gcv.foreground = scr->white_pixel;
2651 gcv.background = scr->black_pixel;
2652 gcv.fill_style = FillStippled;
2653 } else {
2654 gcv.foreground = scr->dtext_pixel;
2655 gcv.fill_style = FillSolid;
2657 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2659 return REFRESH_MENU_COLOR;
2660 #undef gcm
2664 static int
2665 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2667 XGCValues gcv;
2668 #define gcm (GCForeground|GCBackground|GCFillStyle)
2670 if (scr->dtext_pixel!=scr->white_pixel &&
2671 scr->dtext_pixel!=scr->black_pixel) {
2672 wFreeColor(scr, scr->dtext_pixel);
2675 scr->dtext_pixel = color->pixel;
2677 if (scr->dtext_pixel == scr->mtext_pixel) {
2678 gcv.foreground = scr->white_pixel;
2679 gcv.background = scr->black_pixel;
2680 gcv.fill_style = FillStippled;
2681 } else {
2682 gcv.foreground = scr->dtext_pixel;
2683 gcv.fill_style = FillSolid;
2685 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2687 return REFRESH_MENU_COLOR;
2688 #undef gcm
2691 static int
2692 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2694 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2696 return REFRESH_ICON_TITLE_COLOR;
2700 static int
2701 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2703 if (scr->icon_title_texture) {
2704 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2706 XQueryColor (dpy, scr->w_colormap, color);
2707 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2709 return REFRESH_ICON_TITLE_BACK;
2713 static void
2714 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2716 close(scr->helper_fd);
2717 scr->helper_fd = 0;
2718 scr->helper_pid = 0;
2719 scr->flags.backimage_helper_launched = 0;
2723 static int
2724 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2725 void *bar)
2727 int i;
2728 proplist_t val;
2729 char *str;
2731 if (scr->flags.backimage_helper_launched) {
2732 if (PLGetNumberOfElements(value)==0) {
2733 SendHelperMessage(scr, 'C', 0, NULL);
2734 SendHelperMessage(scr, 'K', 0, NULL);
2736 PLRelease(value);
2737 return 0;
2739 } else {
2740 pid_t pid;
2741 int filedes[2];
2743 if (PLGetNumberOfElements(value) == 0)
2744 return 0;
2746 if (pipe(filedes) < 0) {
2747 wsyserror("pipe() failed:can't set workspace specific background image");
2749 PLRelease(value);
2750 return 0;
2753 pid = fork();
2754 if (pid < 0) {
2755 wsyserror("fork() failed:can't set workspace specific background image");
2756 if (close(filedes[0]) < 0)
2757 wsyserror("could not close pipe");
2758 if (close(filedes[1]) < 0)
2759 wsyserror("could not close pipe");
2761 } else if (pid == 0) {
2762 SetupEnvironment(scr);
2764 if (close(0) < 0)
2765 wsyserror("could not close pipe");
2766 if (dup(filedes[0]) < 0) {
2767 wsyserror("dup() failed:can't set workspace specific background image");
2769 if (wPreferences.smooth_workspace_back)
2770 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
2771 else
2772 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2773 wsyserror("could not execute wmsetbg");
2774 exit(1);
2775 } else {
2777 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2778 wsyserror("error setting close-on-exec flag");
2780 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2781 wsyserror("error setting close-on-exec flag");
2784 scr->helper_fd = filedes[1];
2785 scr->helper_pid = pid;
2786 scr->flags.backimage_helper_launched = 1;
2788 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2790 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2794 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2795 val = PLGetArrayElement(value, i);
2796 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2797 str = PLGetDescription(val);
2799 SendHelperMessage(scr, 'S', i+1, str);
2801 free(str);
2802 } else {
2803 SendHelperMessage(scr, 'U', i+1, NULL);
2806 sleep(1);
2808 PLRelease(value);
2809 return 0;
2813 static int
2814 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2815 void *bar)
2817 if (scr->flags.backimage_helper_launched) {
2818 char *str;
2820 if (PLGetNumberOfElements(value)==0) {
2821 SendHelperMessage(scr, 'U', 0, NULL);
2822 } else {
2823 /* set the default workspace background to this one */
2824 str = PLGetDescription(value);
2825 if (str) {
2826 SendHelperMessage(scr, 'S', 0, str);
2827 free(str);
2828 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2829 } else {
2830 SendHelperMessage(scr, 'U', 0, NULL);
2833 } else {
2834 char *command;
2835 char *text;
2837 SetupEnvironment(scr);
2838 text = PLGetDescription(value);
2839 command = wmalloc(strlen(text)+40);
2840 if (wPreferences.smooth_workspace_back)
2841 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
2842 else
2843 sprintf(command, "wmsetbg -d -p '%s' &", text);
2844 free(text);
2845 system(command);
2846 free(command);
2848 PLRelease(value);
2850 return 0;
2854 static int
2855 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2857 if (scr->widget_texture) {
2858 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2860 scr->widget_texture = *(WTexSolid**)texture;
2862 if (scr->geometry_display != None)
2863 XSetWindowBackground(dpy, scr->geometry_display,
2864 scr->widget_texture->normal.pixel);
2866 return 0;
2870 static int
2871 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2873 if (scr->window_title_texture[WS_FOCUSED]) {
2874 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2876 scr->window_title_texture[WS_FOCUSED] = *texture;
2878 return REFRESH_WINDOW_TEXTURES;
2882 static int
2883 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2885 if (scr->window_title_texture[WS_PFOCUSED]) {
2886 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2888 scr->window_title_texture[WS_PFOCUSED] = *texture;
2890 return REFRESH_WINDOW_TEXTURES;
2894 static int
2895 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2897 if (scr->window_title_texture[WS_UNFOCUSED]) {
2898 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2900 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2902 return REFRESH_WINDOW_TEXTURES;
2906 static int
2907 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2909 if (scr->resizebar_texture[0]) {
2910 wTextureDestroy(scr, scr->resizebar_texture[0]);
2912 scr->resizebar_texture[0] = *texture;
2914 return REFRESH_WINDOW_TEXTURES;
2918 static int
2919 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2921 if (scr->menu_title_texture[0]) {
2922 wTextureDestroy(scr, scr->menu_title_texture[0]);
2924 scr->menu_title_texture[0] = *texture;
2926 return REFRESH_MENU_TITLE_TEXTURE;
2930 static int
2931 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2933 if (scr->menu_item_texture) {
2934 wTextureDestroy(scr, scr->menu_item_texture);
2935 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2937 scr->menu_item_texture = *texture;
2939 scr->menu_item_auxtexture
2940 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2942 return REFRESH_MENU_TEXTURE;
2946 static int
2947 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
2949 WWindow *wwin;
2950 wKeyBindings[index] = *shortcut;
2952 wwin = scr->focused_window;
2954 while (wwin!=NULL) {
2955 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2957 if (!WFLAGP(wwin, no_bind_keys)) {
2958 wWindowSetKeyGrabs(wwin);
2960 wwin = wwin->prev;
2963 return 0;
2967 static int
2968 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2970 wArrangeIcons(scr, True);
2972 return 0;
2976 static int
2977 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2979 wScreenUpdateUsableArea(scr);
2981 return 0;
2985 static int
2986 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2988 return REFRESH_MENU_TEXTURE;
2993 static int
2994 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2996 return REFRESH_BUTTON_IMAGES;
3001 * Very ugly kluge.
3002 * Need access to the double click variables, so that all widgets in
3003 * wmaker panels will have the same dbl-click values.
3004 * TODO: figure a better way of dealing with it.
3006 #include "WINGsP.h"
3008 static int
3009 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3011 extern _WINGsConfiguration WINGsConfiguration;
3013 if (*value <= 0)
3014 *(int*)foo = 1;
3016 WINGsConfiguration.doubleClickDelay = *value;
3018 return 0;
3023 static int
3024 setMultiByte(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3026 extern _WINGsConfiguration WINGsConfiguration;
3028 WINGsConfiguration.useMultiByte = *value;
3030 return 0;