MenuStyle option
[wmaker-crm.git] / src / defaults.c
blob4ead8fbf7bb531d5c44b76bff063e835ca3ed3ca
1 /* defaults.c - manage configuration through defaults db
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <ctype.h>
30 #include <time.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h>
34 #include <limits.h>
35 #include <signal.h>
37 #ifdef HAVE_DLFCN_H
38 # include <dlfcn.h>
39 #endif
43 #ifndef PATH_MAX
44 #define PATH_MAX DEFAULT_PATH_MAX
45 #endif
47 #include <X11/Xlib.h>
48 #include <X11/Xutil.h>
49 #include <X11/keysym.h>
51 #include <wraster.h>
54 #include "WindowMaker.h"
55 #include "wcore.h"
56 #include "framewin.h"
57 #include "window.h"
58 #include "texture.h"
59 #include "screen.h"
60 #include "resources.h"
61 #include "defaults.h"
62 #include "keybind.h"
63 #include "xmodifier.h"
64 #include "icon.h"
65 #include "funcs.h"
66 #include "actions.h"
67 #include "dock.h"
68 #include "workspace.h"
72 * Our own proplist reader parser. This one will not accept any
73 * syntax errors and is more descriptive in the error messages.
74 * It also doesn't seem to crash.
76 extern proplist_t ReadProplistFromFile(char *file);
79 /***** Global *****/
81 extern WDDomain *WDWindowMaker;
82 extern WDDomain *WDWindowAttributes;
83 extern WDDomain *WDRootMenu;
85 extern int wScreenCount;
88 extern proplist_t wDomainName;
89 extern proplist_t wAttributeDomainName;
91 extern WPreferences wPreferences;
93 extern WShortKey wKeyBindings[WKBD_LAST];
95 typedef struct {
96 char *key;
97 char *default_value;
98 void *extra_data;
99 void *addr;
100 int (*convert)();
101 int (*update)();
102 proplist_t plkey;
103 proplist_t plvalue; /* default value */
104 } WDefaultEntry;
107 /* used to map strings to integers */
108 typedef struct {
109 char *string;
110 short value;
111 char is_alias;
112 } WOptionEnumeration;
115 /* type converters */
116 static int getBool();
117 static int getInt();
118 static int getCoord();
119 #if 0
120 /* this is not used yet */
121 static int getString();
122 #endif
123 static int getPathList();
124 static int getEnum();
125 static int getTexture();
126 static int getWSBackground();
127 static int getWSSpecificBackground();
128 static int getFont();
129 static int getColor();
130 static int getKeybind();
131 static int getModMask();
132 #ifdef NEWSTUFF
133 static int getRImage();
134 #endif
137 /* value setting functions */
138 static int setJustify();
139 static int setIfDockPresent();
140 static int setStickyIcons();
142 static int setPositive();
144 static int setWidgetColor();
145 static int setIconTile();
146 static int setWinTitleFont();
147 static int setMenuTitleFont();
148 static int setMenuTextFont();
149 static int setIconTitleFont();
150 static int setIconTitleColor();
151 static int setIconTitleBack();
152 static int setDisplayFont();
153 static int setWTitleColor();
154 static int setFTitleBack();
155 static int setPTitleBack();
156 static int setUTitleBack();
157 static int setWorkspaceBack();
158 static int setWorkspaceSpecificBack();
159 static int setMenuTitleColor();
160 static int setMenuTextColor();
161 static int setMenuDisabledColor();
162 static int setMenuTitleBack();
163 static int setMenuTextBack();
164 static int setHightlight();
165 static int setHightlightText();
166 static int setKeyGrab();
167 static int setDoubleClick();
168 static int setIconPosition();
170 static int setClipTitleFont();
171 static int setClipTitleColor();
173 static int setMenuStyle();
176 static int updateUsableArea();
181 * Tables to convert strings to enumeration values.
182 * Values stored are char
186 /* WARNING: sum of length of all value strings must not exceed
187 * this value */
188 #define TOTAL_VALUES_LENGTH 80
193 #define REFRESH_WINDOW_TEXTURES (1<<0)
194 #define REFRESH_MENU_TEXTURE (1<<1)
195 #define REFRESH_MENU_FONT (1<<2)
196 #define REFRESH_MENU_COLOR (1<<3)
197 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
198 #define REFRESH_MENU_TITLE_FONT (1<<5)
199 #define REFRESH_MENU_TITLE_COLOR (1<<6)
200 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
201 #define REFRESH_WINDOW_FONT (1<<8)
202 #define REFRESH_FORE_COLOR (1<<9)
203 #define REFRESH_ICON_TILE (1<<10)
204 #define REFRESH_ICON_FONT (1<<11)
205 #define REFRESH_WORKSPACE_BACK (1<<12)
207 #define REFRESH_BUTTON_IMAGES (1<<13)
209 #define REFRESH_ICON_TITLE_COLOR (1<<14)
210 #define REFRESH_ICON_TITLE_BACK (1<<15)
214 static WOptionEnumeration seFocusModes[] = {
215 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
216 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
217 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
218 {NULL, 0, 0}
221 static WOptionEnumeration seColormapModes[] = {
222 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
223 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
224 {NULL, 0, 0}
227 static WOptionEnumeration sePlacements[] = {
228 {"Auto", WPM_SMART, 0}, {"Smart", WPM_SMART, 1},
229 {"Cascade", WPM_CASCADE, 0},
230 {"Random", WPM_RANDOM, 0},
231 {"Manual", WPM_MANUAL, 0},
232 {NULL, 0, 0}
235 static WOptionEnumeration seGeomDisplays[] = {
236 {"Center", WDIS_CENTER, 0},
237 {"Corner", WDIS_TOPLEFT, 0},
238 {"Floating", WDIS_FRAME_CENTER, 0},
239 {"Line", WDIS_NEW, 0},
240 {NULL, 0, 0}
243 static WOptionEnumeration seSpeeds[] = {
244 {"UltraFast", SPEED_ULTRAFAST, 0},
245 {"Fast", SPEED_FAST, 0},
246 {"Medium", SPEED_MEDIUM, 0},
247 {"Slow", SPEED_SLOW, 0},
248 {"UltraSlow", SPEED_ULTRASLOW, 0},
249 {NULL, 0, 0}
252 static WOptionEnumeration seMouseButtons[] = {
253 {"Left", Button1, 0}, {"Button1", Button1, 1},
254 {"Middle", Button2, 0}, {"Button2", Button2, 1},
255 {"Right", Button3, 0}, {"Button3", Button3, 1},
256 {"Button4", Button4, 0},
257 {"Button5", Button5, 0},
258 {NULL, 0, 0}
261 static WOptionEnumeration seIconificationStyles[] = {
262 {"Zoom", WIS_ZOOM, 0},
263 {"Twist", WIS_TWIST, 0},
264 {"Flip", WIS_FLIP, 0},
265 {"None", WIS_NONE, 0},
266 {"random", WIS_RANDOM, 0},
267 {NULL, 0, 0}
270 static WOptionEnumeration seJustifications[] = {
271 {"Left", WTJ_LEFT, 0},
272 {"Center", WTJ_CENTER, 0},
273 {"Right", WTJ_RIGHT, 0},
274 {NULL, 0, 0}
277 static WOptionEnumeration seIconPositions[] = {
278 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
279 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
280 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
281 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
282 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
283 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
284 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
285 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
286 {NULL, 0, 0}
289 static WOptionEnumeration seMenuStyles[] = {
290 {"normal", MS_NORMAL, 0},
291 {"singletexture", MS_SINGLE_TEXTURE, 0},
292 {"flat", MS_FLAT, 0},
293 {NULL, 0, 0}
298 * ALL entries in the tables bellow, NEED to have a default value
299 * defined, and this value needs to be correct.
302 /* these options will only affect the window manager on startup
304 * static defaults can't access the screen data, because it is
305 * created after these defaults are read
307 WDefaultEntry staticOptionList[] = {
309 {"DisableDithering", "NO", NULL,
310 &wPreferences.no_dithering, getBool, NULL
312 {"ColormapSize", "4", NULL,
313 &wPreferences.cmap_size, getInt, NULL
315 /* static by laziness */
316 {"IconSize", "64", NULL,
317 &wPreferences.icon_size, getInt, NULL
319 {"ModifierKey", "Mod1", NULL,
320 &wPreferences.modifier_mask, getModMask, NULL
322 {"DisableWSMouseActions", "NO", NULL,
323 &wPreferences.disable_root_mouse, getBool, NULL
325 {"FocusMode", "manual", seFocusModes,
326 &wPreferences.focus_mode, getEnum, NULL
327 }, /* have a problem when switching from manual to sloppy without restart */
328 {"NewStyle", "NO", NULL,
329 &wPreferences.new_style, getBool, NULL
331 {"DisableDock", "NO", (void*) WM_DOCK,
332 NULL, getBool, setIfDockPresent
334 {"DisableClip", "NO", (void*) WM_CLIP,
335 NULL, getBool, setIfDockPresent
337 {"DisableMiniwindows", "NO", NULL,
338 &wPreferences.disable_miniwindows, getBool, NULL
344 WDefaultEntry optionList[] = {
345 /* dynamic options */
346 {"IconPosition", "blh", seIconPositions,
347 &wPreferences.icon_yard, getEnum, setIconPosition
349 {"IconificationStyle", "Zoom", seIconificationStyles,
350 &wPreferences.iconification_style, getEnum, NULL
352 {"SelectWindowsMouseButton", "Left", seMouseButtons,
353 &wPreferences.select_button, getEnum, NULL
355 {"WindowListMouseButton", "Middle", seMouseButtons,
356 &wPreferences.windowl_button, getEnum, NULL
358 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
359 &wPreferences.menu_button, getEnum, NULL
361 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
362 &wPreferences.pixmap_path, getPathList, NULL
364 {"IconPath", DEF_ICON_PATHS, NULL,
365 &wPreferences.icon_path, getPathList, NULL
367 {"ColormapMode", "auto", seColormapModes,
368 &wPreferences.colormap_mode, getEnum, NULL
370 {"AutoFocus", "NO", NULL,
371 &wPreferences.auto_focus, getBool, NULL
373 {"RaiseDelay", "0", NULL,
374 &wPreferences.raise_delay, getInt, NULL
376 {"CirculateRaise", "NO", NULL,
377 &wPreferences.circ_raise, getBool, NULL
379 {"Superfluous", "NO", NULL,
380 &wPreferences.superfluous, getBool, NULL
382 {"AdvanceToNewWorkspace", "NO", NULL,
383 &wPreferences.ws_advance, getBool, NULL
385 {"CycleWorkspaces", "NO", NULL,
386 &wPreferences.ws_cycle, getBool, NULL
388 {"StickyIcons", "NO", NULL,
389 &wPreferences.sticky_icons, getBool, setStickyIcons
391 {"SaveSessionOnExit", "NO", NULL,
392 &wPreferences.save_session_on_exit, getBool, NULL
394 {"WrapMenus", "NO", NULL,
395 &wPreferences.wrap_menus, getBool, NULL
397 {"ScrollableMenus", "NO", NULL,
398 &wPreferences.scrollable_menus, getBool, NULL
400 {"MenuScrollSpeed", "medium", seSpeeds,
401 &wPreferences.menu_scroll_speed, getEnum, NULL
403 {"IconSlideSpeed", "medium", seSpeeds,
404 &wPreferences.icon_slide_speed, getEnum, NULL
406 {"ShadeSpeed", "medium", seSpeeds,
407 &wPreferences.shade_speed, getEnum, NULL
409 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
410 &wPreferences.dblclick_time, getInt, setDoubleClick,
412 {"AlignSubmenus", "NO", NULL,
413 &wPreferences.align_menus, getBool, NULL
415 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
416 &wPreferences.open_transients_with_parent, getBool, NULL
418 {"WindowPlacement", "auto", sePlacements,
419 &wPreferences.window_placement, getEnum, NULL
421 {"IgnoreFocusClick","NO", NULL,
422 &wPreferences.ignore_focus_click, getBool, NULL
424 {"UseSaveUnders", "NO", NULL,
425 &wPreferences.use_saveunders, getBool, NULL
427 {"OpaqueMove", "NO", NULL,
428 &wPreferences.opaque_move, getBool, NULL
430 {"DisableSound", "NO", NULL,
431 &wPreferences.no_sound, getBool, NULL
433 {"DisableAnimations", "NO", NULL,
434 &wPreferences.no_animations, getBool, NULL
436 {"DontLinkWorkspaces","NO", NULL,
437 &wPreferences.no_autowrap, getBool, NULL
439 {"AutoArrangeIcons", "NO", NULL,
440 &wPreferences.auto_arrange_icons, getBool, NULL
442 {"NoWindowOverDock", "NO", NULL,
443 &wPreferences.no_window_over_dock, getBool, updateUsableArea
445 {"NoWindowOverIcons", "NO", NULL,
446 &wPreferences.no_window_over_icons, getBool, updateUsableArea
448 {"WindowPlaceOrigin", "(0, 0)", NULL,
449 &wPreferences.window_place_origin, getCoord, NULL
451 {"ResizeDisplay", "corner", seGeomDisplays,
452 &wPreferences.size_display, getEnum, NULL
454 {"MoveDisplay", "corner", seGeomDisplays,
455 &wPreferences.move_display, getEnum, NULL
457 {"DontConfirmKill", "NO", NULL,
458 &wPreferences.dont_confirm_kill, getBool,NULL
460 {"WindowTitleBalloons", "NO", NULL,
461 &wPreferences.window_balloon, getBool, NULL
463 {"MiniwindowTitleBalloons", "NO", NULL,
464 &wPreferences.miniwin_balloon,getBool, NULL
466 {"AppIconBalloons", "NO", NULL,
467 &wPreferences.appicon_balloon,getBool, NULL
469 {"EdgeResistance", "30", NULL,
470 &wPreferences.edge_resistance,getInt, NULL
472 {"DisableBlinking", "NO", NULL,
473 &wPreferences.dont_blink, getBool, NULL
475 #ifdef WEENDOZE_CYCLE
476 {"WindozeCycling","NO", NULL,
477 &wPreferences.windoze_cycling, getBool, NULL
479 {"PopupSwitchMenu","YES", NULL,
480 &wPreferences.popup_switchmenu, getBool, NULL
482 #endif /* WEENDOZE_CYCLE */
483 /* style options */
484 {"MenuStyle", "normal", seMenuStyles,
485 &wPreferences.menu_style, getEnum, setMenuStyle
487 {"WidgetColor", "(solid, gray)", NULL,
488 NULL, getTexture, setWidgetColor,
490 {"WorkspaceSpecificBack","()", NULL,
491 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
493 /* WorkspaceBack must come after WorkspaceSpecificBack or
494 * WorkspaceBack wont know WorkspaceSpecificBack was also
495 * specified and 2 copies of wmsetbg will be launched */
496 {"WorkspaceBack", "(solid, black)", NULL,
497 NULL, getWSBackground,setWorkspaceBack
499 {"IconBack", "(solid, gray)", NULL,
500 NULL, getTexture, setIconTile
502 {"TitleJustify", "center", seJustifications,
503 &wPreferences.title_justification, getEnum, setJustify
505 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
506 NULL, getFont, setWinTitleFont,
508 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
509 NULL, getFont, setMenuTitleFont
511 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
512 NULL, getFont, setMenuTextFont
514 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
515 NULL, getFont, setIconTitleFont
517 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
518 NULL, getFont, setClipTitleFont
520 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
521 NULL, getFont, setDisplayFont
523 {"HighlightColor", "white", NULL,
524 NULL, getColor, setHightlight
526 {"HighlightTextColor", "black", NULL,
527 NULL, getColor, setHightlightText
529 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
530 NULL, getColor, setClipTitleColor
532 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
533 NULL, getColor, setClipTitleColor
535 {"FTitleColor", "white", (void*)WS_FOCUSED,
536 NULL, getColor, setWTitleColor
538 {"PTitleColor", "white", (void*)WS_PFOCUSED,
539 NULL, getColor, setWTitleColor
541 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
542 NULL, getColor, setWTitleColor
544 {"FTitleBack", "(solid, black)", NULL,
545 NULL, getTexture, setFTitleBack
547 {"PTitleBack", "(solid, \"#616161\")", NULL,
548 NULL, getTexture, setPTitleBack
550 {"UTitleBack", "(solid, gray)", NULL,
551 NULL, getTexture, setUTitleBack
553 {"MenuTitleColor", "white", NULL,
554 NULL, getColor, setMenuTitleColor
556 {"MenuTextColor", "black", NULL,
557 NULL, getColor, setMenuTextColor
559 {"MenuDisabledColor", "\"#616161\"", NULL,
560 NULL, getColor, setMenuDisabledColor
562 {"MenuTitleBack", "(solid, black)", NULL,
563 NULL, getTexture, setMenuTitleBack
565 {"MenuTextBack", "(solid, gray)", NULL,
566 NULL, getTexture, setMenuTextBack
568 {"IconTitleColor", "white", NULL,
569 NULL, getColor, setIconTitleColor
571 {"IconTitleBack", "black", NULL,
572 NULL, getColor, setIconTitleBack
574 /* keybindings */
575 #ifndef LITE
576 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
577 NULL, getKeybind, setKeyGrab
579 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
580 NULL, getKeybind, setKeyGrab
582 #endif /* LITE */
583 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
584 NULL, getKeybind, setKeyGrab
586 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
587 NULL, getKeybind, setKeyGrab
589 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
590 NULL, getKeybind, setKeyGrab
592 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
593 NULL, getKeybind, setKeyGrab
595 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
596 NULL, getKeybind, setKeyGrab
598 {"HideKey", "None", (void*)WKBD_HIDE,
599 NULL, getKeybind, setKeyGrab
601 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
602 NULL, getKeybind, setKeyGrab
604 {"CloseKey", "None", (void*)WKBD_CLOSE,
605 NULL, getKeybind, setKeyGrab
607 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
608 NULL, getKeybind, setKeyGrab
610 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
611 NULL, getKeybind, setKeyGrab
613 {"RaiseKey", "Meta+Up", (void*)WKBD_RAISE,
614 NULL, getKeybind, setKeyGrab
616 {"LowerKey", "Meta+Down", (void*)WKBD_LOWER,
617 NULL, getKeybind, setKeyGrab
619 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
620 NULL, getKeybind, setKeyGrab
622 {"ShadeKey", "None", (void*)WKBD_SHADE,
623 NULL, getKeybind, setKeyGrab
625 {"SelectKey", "None", (void*)WKBD_SELECT,
626 NULL, getKeybind, setKeyGrab
628 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
629 NULL, getKeybind, setKeyGrab
631 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
632 NULL, getKeybind, setKeyGrab
634 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
635 NULL, getKeybind, setKeyGrab
637 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
638 NULL, getKeybind, setKeyGrab
640 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
641 NULL, getKeybind, setKeyGrab
643 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
644 NULL, getKeybind, setKeyGrab
646 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
647 NULL, getKeybind, setKeyGrab
649 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
650 NULL, getKeybind, setKeyGrab
652 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
653 NULL, getKeybind, setKeyGrab
655 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
656 NULL, getKeybind, setKeyGrab
658 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
659 NULL, getKeybind, setKeyGrab
661 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
662 NULL, getKeybind, setKeyGrab
664 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
665 NULL, getKeybind, setKeyGrab
667 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
668 NULL, getKeybind, setKeyGrab
670 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
671 NULL, getKeybind, setKeyGrab
673 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
674 NULL, getKeybind, setKeyGrab
676 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
677 NULL, getKeybind, setKeyGrab
679 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
680 NULL, getKeybind, setKeyGrab
682 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
683 NULL, getKeybind, setKeyGrab
685 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
686 NULL, getKeybind, setKeyGrab
688 #ifdef EXTEND_WINDOWSHORTCUT
689 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
690 NULL, getKeybind, setKeyGrab
692 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
693 NULL, getKeybind, setKeyGrab
695 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
696 NULL, getKeybind, setKeyGrab
698 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
699 NULL, getKeybind, setKeyGrab
701 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
702 NULL, getKeybind, setKeyGrab
704 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
705 NULL, getKeybind, setKeyGrab
707 #endif /* EXTEND_WINDOWSHORTCUT */
709 #ifdef KEEP_XKB_LOCK_STATUS
710 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
711 NULL, getKeybind, setKeyGrab
713 {"KbdModeLock", "NO", NULL,
714 &wPreferences.modelock, getBool, NULL
716 #endif /* KEEP_XKB_LOCK_STATUS */
717 #ifdef TITLE_TEXT_SHADOW
718 ,{"FShadowColor", "black", (void*)WS_SFOCUSED,
719 NULL, getColor, setWTitleColor
721 {"PShadowColor", "black", (void*)WS_SPFOCUSED,
722 NULL, getColor, setWTitleColor
724 {"UShadowColor", "grey50", (void*)WS_SUNFOCUSED,
725 NULL, getColor, setWTitleColor
727 {"MShadowColor", "black", (void*)WS_SMENU,
728 NULL, getColor, setMenuTitleColor
730 {"Shadow", "Yes", NULL,
731 &wPreferences.title_shadow, getBool, setJustify
733 #endif /* TITLE_TEXT_SHADOW */
737 #if 0
738 static void rereadDefaults(void);
739 #endif
741 #if 0
742 static void
743 rereadDefaults(void)
745 /* must defer the update because accessing X data from a
746 * signal handler can mess up Xlib */
749 #endif
751 static void
752 initDefaults()
754 int i;
755 WDefaultEntry *entry;
757 PLSetStringCmpHook(StringCompareHook);
759 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
760 entry = &optionList[i];
762 entry->plkey = PLMakeString(entry->key);
763 if (entry->default_value)
764 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
765 else
766 entry->plvalue = NULL;
769 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
770 entry = &staticOptionList[i];
772 entry->plkey = PLMakeString(entry->key);
773 if (entry->default_value)
774 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
775 else
776 entry->plvalue = NULL;
780 wDomainName = PLMakeString(WMDOMAIN_NAME);
781 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
783 PLRegister(wDomainName, rereadDefaults);
784 PLRegister(wAttributeDomainName, rereadDefaults);
791 #if 0
792 proplist_t
793 wDefaultsInit(int screen_number)
795 static int defaults_inited = 0;
796 proplist_t dict;
798 if (!defaults_inited) {
799 initDefaults();
802 dict = PLGetDomain(wDomainName);
803 if (!dict) {
804 wwarning(_("could not read domain \"%s\" from defaults database"),
805 PLGetString(wDomainName));
808 return dict;
810 #endif
813 void
814 wDefaultsDestroyDomain(WDDomain *domain)
816 if (domain->dictionary)
817 PLRelease(domain->dictionary);
818 free(domain->path);
819 free(domain);
823 WDDomain*
824 wDefaultsInitDomain(char *domain, Bool requireDictionary)
826 WDDomain *db;
827 struct stat stbuf;
828 static int inited = 0;
829 char path[PATH_MAX];
830 char *the_path;
831 proplist_t shared_dict=NULL;
833 if (!inited) {
834 inited = 1;
835 initDefaults();
838 db = wmalloc(sizeof(WDDomain));
839 memset(db, 0, sizeof(WDDomain));
840 db->domain_name = domain;
841 db->path = wdefaultspathfordomain(domain);
842 the_path = db->path;
844 if (the_path && stat(the_path, &stbuf)>=0) {
845 db->dictionary = ReadProplistFromFile(the_path);
846 if (db->dictionary) {
847 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
848 PLRelease(db->dictionary);
849 db->dictionary = NULL;
850 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
851 domain, the_path);
853 db->timestamp = stbuf.st_mtime;
854 } else {
855 wwarning(_("could not load domain %s from user defaults database"),
856 domain);
860 /* global system dictionary */
861 sprintf(path, "%s/%s", SYSCONFDIR, domain);
862 if (stat(path, &stbuf)>=0) {
863 shared_dict = ReadProplistFromFile(path);
864 if (shared_dict) {
865 if (requireDictionary && !PLIsDictionary(shared_dict)) {
866 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
867 domain, path);
868 PLRelease(shared_dict);
869 shared_dict = NULL;
870 } else {
871 if (db->dictionary && PLIsDictionary(shared_dict) &&
872 PLIsDictionary(db->dictionary)) {
873 PLMergeDictionaries(shared_dict, db->dictionary);
874 PLRelease(db->dictionary);
875 db->dictionary = shared_dict;
876 if (stbuf.st_mtime > db->timestamp)
877 db->timestamp = stbuf.st_mtime;
878 } else if (!db->dictionary) {
879 db->dictionary = shared_dict;
880 if (stbuf.st_mtime > db->timestamp)
881 db->timestamp = stbuf.st_mtime;
884 } else {
885 wwarning(_("could not load domain %s from global defaults database"),
886 domain);
890 /* set to save it in user's directory, no matter from where it was read */
891 if (db->dictionary) {
892 proplist_t tmp = PLMakeString(db->path);
894 PLSetFilename(db->dictionary, tmp);
895 PLRelease(tmp);
898 return db;
902 void
903 wReadStaticDefaults(proplist_t dict)
905 proplist_t plvalue;
906 WDefaultEntry *entry;
907 int i;
908 void *tdata;
911 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
912 entry = &staticOptionList[i];
914 if (dict)
915 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
916 else
917 plvalue = NULL;
919 if (!plvalue) {
920 /* no default in the DB. Use builtin default */
921 plvalue = entry->plvalue;
924 if (plvalue) {
925 /* convert data */
926 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
927 if (entry->update) {
928 (*entry->update)(NULL, entry, tdata, entry->extra_data);
935 void
936 wDefaultsCheckDomains(void *foo)
938 WScreen *scr;
939 struct stat stbuf;
940 proplist_t dict;
941 int i;
942 char path[PATH_MAX];
944 #ifdef HEARTBEAT
945 puts("Checking domains...");
946 #endif
947 if (stat(WDWindowMaker->path, &stbuf)>=0
948 && WDWindowMaker->timestamp < stbuf.st_mtime) {
949 proplist_t shared_dict = NULL;
950 #ifdef HEARTBEAT
951 puts("Checking WindowMaker domain");
952 #endif
953 WDWindowMaker->timestamp = stbuf.st_mtime;
955 /* global dictionary */
956 sprintf(path, "%s/WindowMaker", SYSCONFDIR);
957 if (stat(path, &stbuf)>=0) {
958 shared_dict = ReadProplistFromFile(path);
959 if (shared_dict && !PLIsDictionary(shared_dict)) {
960 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
961 "WindowMaker", path);
962 PLRelease(shared_dict);
963 shared_dict = NULL;
964 } else if (!shared_dict) {
965 wwarning(_("could not load domain %s from global defaults database"),
966 "WindowMaker");
969 /* user dictionary */
970 dict = ReadProplistFromFile(WDWindowMaker->path);
971 if (dict) {
972 if (!PLIsDictionary(dict)) {
973 PLRelease(dict);
974 dict = NULL;
975 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
976 "WindowMaker", WDWindowMaker->path);
977 } else {
978 if (shared_dict) {
979 PLSetFilename(shared_dict, PLGetFilename(dict));
980 PLMergeDictionaries(shared_dict, dict);
981 PLRelease(dict);
982 dict = shared_dict;
983 shared_dict = NULL;
985 for (i=0; i<wScreenCount; i++) {
986 scr = wScreenWithNumber(i);
987 if (scr)
988 wReadDefaults(scr, dict);
990 if (WDWindowMaker->dictionary) {
991 PLRelease(WDWindowMaker->dictionary);
993 WDWindowMaker->dictionary = dict;
995 } else {
996 wwarning(_("could not load domain %s from user defaults database"),
997 "WindowMaker");
999 if (shared_dict) {
1000 PLRelease(shared_dict);
1004 if (stat(WDWindowAttributes->path, &stbuf)>=0
1005 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1006 #ifdef HEARTBEAT
1007 puts("Checking WMWindowAttributes domain");
1008 #endif
1009 dict = ReadProplistFromFile(WDWindowAttributes->path);
1010 if (dict) {
1011 if (!PLIsDictionary(dict)) {
1012 PLRelease(dict);
1013 dict = NULL;
1014 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1015 "WMWindowAttributes", WDWindowAttributes->path);
1016 } else {
1017 if (WDWindowAttributes->dictionary)
1018 PLRelease(WDWindowAttributes->dictionary);
1019 WDWindowAttributes->dictionary = dict;
1020 for (i=0; i<wScreenCount; i++) {
1021 scr = wScreenWithNumber(i);
1022 if (scr)
1023 wDefaultUpdateIcons(scr);
1026 } else {
1027 wwarning(_("could not load domain %s from user defaults database"),
1028 "WMWindowAttributes");
1030 WDWindowAttributes->timestamp = stbuf.st_mtime;
1033 #ifndef LITE
1034 if (stat(WDRootMenu->path, &stbuf)>=0
1035 && WDRootMenu->timestamp < stbuf.st_mtime) {
1036 dict = ReadProplistFromFile(WDRootMenu->path);
1037 #ifdef HEARTBEAT
1038 puts("Checking WMRootMenu domain");
1039 #endif
1040 if (dict) {
1041 if (!PLIsArray(dict) && !PLIsString(dict)) {
1042 PLRelease(dict);
1043 dict = NULL;
1044 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1045 "WMRootMenu", WDRootMenu->path);
1046 } else {
1047 if (WDRootMenu->dictionary) {
1048 PLRelease(WDRootMenu->dictionary);
1050 WDRootMenu->dictionary = dict;
1052 } else {
1053 wwarning(_("could not load domain %s from user defaults database"),
1054 "WMRootMenu");
1056 WDRootMenu->timestamp = stbuf.st_mtime;
1058 #endif /* !LITE */
1060 if (!foo)
1061 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1065 void
1066 wReadDefaults(WScreen *scr, proplist_t new_dict)
1068 proplist_t plvalue, old_value;
1069 WDefaultEntry *entry;
1070 int i, must_update;
1071 int needs_refresh;
1072 void *tdata;
1073 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1074 ? WDWindowMaker->dictionary : NULL);
1076 must_update = 0;
1078 needs_refresh = 0;
1080 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1081 entry = &optionList[i];
1083 if (new_dict)
1084 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1085 else
1086 plvalue = NULL;
1088 if (!old_dict)
1089 old_value = NULL;
1090 else
1091 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1094 if (!plvalue && !old_value) {
1095 /* no default in the DB. Use builtin default */
1096 plvalue = entry->plvalue;
1097 if (plvalue && new_dict) {
1098 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1099 must_update = 1;
1101 } else if (!plvalue) {
1102 /* value was deleted from DB. Keep current value */
1103 continue;
1104 } else if (!old_value) {
1105 /* set value for the 1st time */
1106 } else if (!PLIsEqual(plvalue, old_value)) {
1107 /* value has changed */
1108 } else {
1109 /* value was not changed since last time */
1110 continue;
1113 if (plvalue) {
1114 #ifdef DEBUG
1115 printf("Updating %s to %s\n", entry->key, PLGetDescription(plvalue));
1116 #endif
1117 /* convert data */
1118 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1119 if (entry->update) {
1120 needs_refresh |=
1121 (*entry->update)(scr, entry, tdata, entry->extra_data);
1127 if (needs_refresh!=0 && !scr->flags.startup) {
1128 int foo;
1130 foo = 0;
1131 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1132 foo |= WTextureSettings;
1133 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1134 foo |= WFontSettings;
1135 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1136 foo |= WColorSettings;
1137 if (foo)
1138 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1139 (void*)foo);
1141 foo = 0;
1142 if (needs_refresh & REFRESH_MENU_TEXTURE)
1143 foo |= WTextureSettings;
1144 if (needs_refresh & REFRESH_MENU_FONT)
1145 foo |= WFontSettings;
1146 if (needs_refresh & REFRESH_MENU_COLOR)
1147 foo |= WColorSettings;
1148 if (foo)
1149 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1150 (void*)foo);
1152 foo = 0;
1153 if (needs_refresh & REFRESH_WINDOW_FONT) {
1154 foo |= WFontSettings;
1156 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1157 foo |= WTextureSettings;
1159 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1160 foo |= WColorSettings;
1162 if (foo)
1163 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1164 (void*)foo);
1166 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1167 foo = 0;
1168 if (needs_refresh & REFRESH_ICON_FONT) {
1169 foo |= WFontSettings;
1171 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1172 foo |= WTextureSettings;
1174 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1175 foo |= WTextureSettings;
1177 if (foo)
1178 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1179 (void*)foo);
1181 if (needs_refresh & REFRESH_ICON_TILE)
1182 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1187 void
1188 wDefaultUpdateIcons(WScreen *scr)
1190 WAppIcon *aicon = scr->app_icon_list;
1191 WWindow *wwin = scr->focused_window;
1192 char *file;
1194 while(aicon) {
1195 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1196 False);
1197 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1198 || (file && !aicon->icon->file)) {
1199 RImage *new_image;
1201 if (aicon->icon->file)
1202 free(aicon->icon->file);
1203 aicon->icon->file = wstrdup(file);
1205 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1206 aicon->wm_class);
1207 if (new_image) {
1208 wIconChangeImage(aicon->icon, new_image);
1209 wAppIconPaint(aicon);
1212 aicon = aicon->next;
1215 if (!wPreferences.flags.noclip)
1216 wClipIconPaint(scr->clip_icon);
1218 while (wwin) {
1219 if (wwin->icon && wwin->flags.miniaturized) {
1220 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1221 False);
1222 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1223 || (file && !wwin->icon->file)) {
1224 RImage *new_image;
1226 if (wwin->icon->file)
1227 free(wwin->icon->file);
1228 wwin->icon->file = wstrdup(file);
1230 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1231 wwin->wm_class);
1232 if (new_image)
1233 wIconChangeImage(wwin->icon, new_image);
1236 wwin = wwin->prev;
1241 /* --------------------------- Local ----------------------- */
1243 #define STRINGP(x) if (!PLIsString(value)) { \
1244 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1245 entry->key, x); \
1246 return False; }
1250 static int
1251 string2index(proplist_t key, proplist_t val, proplist_t def,
1252 WOptionEnumeration *values)
1254 char *str;
1255 WOptionEnumeration *v;
1256 char buffer[TOTAL_VALUES_LENGTH];
1258 if (PLIsString(val) && (str = PLGetString(val))) {
1259 for (v=values; v->string!=NULL; v++) {
1260 if (strcasecmp(v->string, str)==0)
1261 return v->value;
1265 buffer[0] = 0;
1266 for (v=values; v->string!=NULL; v++) {
1267 if (!v->is_alias) {
1268 if (buffer[0]!=0)
1269 strcat(buffer, ", ");
1270 strcat(buffer, v->string);
1273 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1274 PLGetString(key), buffer);
1276 if (def) {
1277 return string2index(key, val, NULL, values);
1280 return -1;
1287 * value - is the value in the defaults DB
1288 * addr - is the address to store the data
1289 * ret - is the address to store a pointer to a temporary buffer. ret
1290 * must not be freed and is used by the set functions
1292 static int
1293 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1294 void **ret)
1296 static char data;
1297 char *val;
1298 int second_pass=0;
1300 STRINGP("Boolean");
1302 val = PLGetString(value);
1304 again:
1305 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1306 || strcasecmp(val, "YES")==0) {
1308 data = 1;
1309 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1310 || strcasecmp(val, "NO")==0) {
1311 data = 0;
1312 } else {
1313 int i;
1314 if (sscanf(val, "%i", &i)==1) {
1315 if (i!=0)
1316 data = 1;
1317 else
1318 data = 0;
1319 } else {
1320 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1321 val, entry->key);
1322 if (second_pass==0) {
1323 val = PLGetString(entry->plvalue);
1324 second_pass = 1;
1325 wwarning(_("using default \"%s\" instead"), val);
1326 goto again;
1328 return False;
1332 if (ret)
1333 *ret = &data;
1335 if (addr) {
1336 *(char*)addr = data;
1339 return True;
1343 static int
1344 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1345 void **ret)
1347 static int data;
1348 char *val;
1351 STRINGP("Integer");
1353 val = PLGetString(value);
1355 if (sscanf(val, "%i", &data)!=1) {
1356 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1357 val, entry->key);
1358 val = PLGetString(entry->plvalue);
1359 wwarning(_("using default \"%s\" instead"), val);
1360 if (sscanf(val, "%i", &data)!=1) {
1361 return False;
1365 if (ret)
1366 *ret = &data;
1368 if (addr) {
1369 *(int*)addr = data;
1371 return True;
1375 static int
1376 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1377 void **ret)
1379 static WCoord data;
1380 char *val_x, *val_y;
1381 int nelem, changed=0;
1382 proplist_t elem_x, elem_y;
1384 again:
1385 if (!PLIsArray(value)) {
1386 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1387 entry->key, "Coordinate");
1388 if (changed==0) {
1389 value = entry->plvalue;
1390 changed = 1;
1391 wwarning(_("using default \"%s\" instead"), entry->default_value);
1392 goto again;
1394 return False;
1397 nelem = PLGetNumberOfElements(value);
1398 if (nelem != 2) {
1399 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1400 entry->key);
1401 if (changed==0) {
1402 value = entry->plvalue;
1403 changed = 1;
1404 wwarning(_("using default \"%s\" instead"), entry->default_value);
1405 goto again;
1407 return False;
1410 elem_x = PLGetArrayElement(value, 0);
1411 elem_y = PLGetArrayElement(value, 1);
1413 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1414 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1415 entry->key);
1416 if (changed==0) {
1417 value = entry->plvalue;
1418 changed = 1;
1419 wwarning(_("using default \"%s\" instead"), entry->default_value);
1420 goto again;
1422 return False;
1425 val_x = PLGetString(elem_x);
1426 val_y = PLGetString(elem_y);
1428 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1429 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1430 if (changed==0) {
1431 value = entry->plvalue;
1432 changed = 1;
1433 wwarning(_("using default \"%s\" instead"), entry->default_value);
1434 goto again;
1436 return False;
1439 if (data.x < 0)
1440 data.x = 0;
1441 else if (data.x > scr->scr_width/3)
1442 data.x = scr->scr_width/3;
1443 if (data.y < 0)
1444 data.y = 0;
1445 else if (data.y > scr->scr_height/3)
1446 data.y = scr->scr_height/3;
1448 if (ret)
1449 *ret = &data;
1451 if (addr) {
1452 *(WCoord*)addr = data;
1455 return True;
1459 #if 0
1460 /* This function is not used at the moment. */
1461 static int
1462 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1463 void **ret)
1465 static char *data;
1467 STRINGP("String");
1469 data = PLGetString(value);
1471 if (!data) {
1472 data = PLGetString(entry->plvalue);
1473 if (!data)
1474 return False;
1477 if (ret)
1478 *ret = &data;
1480 if (addr)
1481 *(char**)addr = wstrdup(data);
1483 return True;
1485 #endif
1488 static int
1489 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1490 void **ret)
1492 static char *data;
1493 int i, count, len;
1494 char *ptr;
1495 proplist_t d;
1496 int changed=0;
1498 again:
1499 if (!PLIsArray(value)) {
1500 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1501 entry->key, "an array of paths");
1502 if (changed==0) {
1503 value = entry->plvalue;
1504 changed = 1;
1505 wwarning(_("using default \"%s\" instead"), entry->default_value);
1506 goto again;
1508 return False;
1511 i = 0;
1512 count = PLGetNumberOfElements(value);
1513 if (count < 1) {
1514 if (changed==0) {
1515 value = entry->plvalue;
1516 changed = 1;
1517 wwarning(_("using default \"%s\" instead"), entry->default_value);
1518 goto again;
1520 return False;
1523 len = 0;
1524 for (i=0; i<count; i++) {
1525 d = PLGetArrayElement(value, i);
1526 if (!d || !PLIsString(d)) {
1527 count = i;
1528 break;
1530 len += strlen(PLGetString(d))+1;
1533 ptr = data = wmalloc(len+1);
1535 for (i=0; i<count; i++) {
1536 d = PLGetArrayElement(value, i);
1537 if (!d || !PLIsString(d)) {
1538 break;
1540 strcpy(ptr, PLGetString(d));
1541 ptr += strlen(PLGetString(d));
1542 *ptr = ':';
1543 ptr++;
1545 ptr--; *(ptr--) = 0;
1547 if (*(char**)addr!=NULL) {
1548 free(*(char**)addr);
1550 *(char**)addr = data;
1552 return True;
1556 static int
1557 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1558 void **ret)
1560 static signed char data;
1562 data = string2index(entry->plkey, value, entry->default_value,
1563 (WOptionEnumeration*)entry->extra_data);
1564 if (data < 0)
1565 return False;
1567 if (ret)
1568 *ret = &data;
1570 if (addr)
1571 *(signed char*)addr = data;
1573 return True;
1579 * (solid <color>)
1580 * (hgradient <color> <color>)
1581 * (vgradient <color> <color>)
1582 * (dgradient <color> <color>)
1583 * (mhgradient <color> <color> ...)
1584 * (mvgradient <color> <color> ...)
1585 * (tpixmap <file> <color>)
1586 * (spixmap <file> <color>)
1587 * (cpixmap <file> <color>)
1588 * (thgradient <file> <opaqueness> <color> <color>)
1589 * (tvgradient <file> <opaqueness> <color> <color>)
1590 * (tdgradient <file> <opaqueness> <color> <color>)
1591 * (function <lib> <function> ...)
1594 static WTexture*
1595 parse_texture(WScreen *scr, proplist_t pl)
1597 proplist_t elem;
1598 char *val;
1599 int nelem;
1600 WTexture *texture=NULL;
1602 nelem = PLGetNumberOfElements(pl);
1603 if (nelem < 1)
1604 return NULL;
1607 elem = PLGetArrayElement(pl, 0);
1608 if (!elem || !PLIsString(elem))
1609 return NULL;
1610 val = PLGetString(elem);
1613 if (strcasecmp(val, "solid")==0) {
1614 XColor color;
1616 if (nelem != 2)
1617 return NULL;
1619 /* get color */
1621 elem = PLGetArrayElement(pl, 1);
1622 if (!elem || !PLIsString(elem))
1623 return NULL;
1624 val = PLGetString(elem);
1626 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1627 wwarning(_("\"%s\" is not a valid color name"), val);
1628 return NULL;
1631 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1632 } else if (strcasecmp(val, "dgradient")==0
1633 || strcasecmp(val, "vgradient")==0
1634 || strcasecmp(val, "hgradient")==0) {
1635 RColor color1, color2;
1636 XColor xcolor;
1637 int type;
1639 if (nelem != 3) {
1640 wwarning(_("bad number of arguments in gradient specification"));
1641 return NULL;
1644 if (val[0]=='d' || val[0]=='D')
1645 type = WTEX_DGRADIENT;
1646 else if (val[0]=='h' || val[0]=='H')
1647 type = WTEX_HGRADIENT;
1648 else
1649 type = WTEX_VGRADIENT;
1652 /* get from 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, &xcolor)) {
1659 wwarning(_("\"%s\" is not a valid color name"), val);
1660 return NULL;
1662 color1.alpha = 255;
1663 color1.red = xcolor.red >> 8;
1664 color1.green = xcolor.green >> 8;
1665 color1.blue = xcolor.blue >> 8;
1667 /* get to color */
1668 elem = PLGetArrayElement(pl, 2);
1669 if (!elem || !PLIsString(elem)) {
1670 return NULL;
1672 val = PLGetString(elem);
1674 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1675 wwarning(_("\"%s\" is not a valid color name"), val);
1676 return NULL;
1678 color2.alpha = 255;
1679 color2.red = xcolor.red >> 8;
1680 color2.green = xcolor.green >> 8;
1681 color2.blue = xcolor.blue >> 8;
1683 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1685 } else if (strcasecmp(val, "mhgradient")==0
1686 || strcasecmp(val, "mvgradient")==0
1687 || strcasecmp(val, "mdgradient")==0) {
1688 XColor color;
1689 RColor **colors;
1690 int i, count;
1691 int type;
1693 if (nelem < 3) {
1694 wwarning(_("too few arguments in multicolor gradient specification"));
1695 return NULL;
1698 if (val[1]=='h' || val[1]=='H')
1699 type = WTEX_MHGRADIENT;
1700 else if (val[1]=='v' || val[1]=='V')
1701 type = WTEX_MVGRADIENT;
1702 else
1703 type = WTEX_MDGRADIENT;
1705 count = nelem-1;
1707 colors = wmalloc(sizeof(RColor*)*(count+1));
1709 for (i=0; i<count; i++) {
1710 elem = PLGetArrayElement(pl, i+1);
1711 if (!elem || !PLIsString(elem)) {
1712 for (--i; i>=0; --i) {
1713 free(colors[i]);
1715 free(colors);
1716 return NULL;
1718 val = PLGetString(elem);
1720 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1721 wwarning(_("\"%s\" is not a valid color name"), val);
1722 for (--i; i>=0; --i) {
1723 free(colors[i]);
1725 free(colors);
1726 return NULL;
1727 } else {
1728 colors[i] = wmalloc(sizeof(RColor));
1729 colors[i]->red = color.red >> 8;
1730 colors[i]->green = color.green >> 8;
1731 colors[i]->blue = color.blue >> 8;
1734 colors[i] = NULL;
1736 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1737 } else if (strcasecmp(val, "spixmap")==0 ||
1738 strcasecmp(val, "cpixmap")==0 ||
1739 strcasecmp(val, "tpixmap")==0) {
1740 XColor color;
1741 int type;
1743 if (nelem != 3)
1744 return NULL;
1746 if (val[0] == 's' || val[0] == 'S')
1747 type = WTP_SCALE;
1748 else if (val[0] == 'c' || val[0] == 'C')
1749 type = WTP_CENTER;
1750 else
1751 type = WTP_TILE;
1753 /* get color */
1754 elem = PLGetArrayElement(pl, 2);
1755 if (!elem || !PLIsString(elem)) {
1756 return NULL;
1758 val = PLGetString(elem);
1760 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1761 wwarning(_("\"%s\" is not a valid color name"), val);
1762 return NULL;
1765 /* file name */
1766 elem = PLGetArrayElement(pl, 1);
1767 if (!elem || !PLIsString(elem))
1768 return NULL;
1769 val = PLGetString(elem);
1771 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1772 } else if (strcasecmp(val, "thgradient")==0
1773 || strcasecmp(val, "tvgradient")==0
1774 || strcasecmp(val, "tdgradient")==0) {
1775 RColor color1, color2;
1776 XColor xcolor;
1777 int opacity;
1778 int style;
1780 if (val[1]=='h' || val[1]=='H')
1781 style = WTEX_THGRADIENT;
1782 else if (val[1]=='v' || val[1]=='V')
1783 style = WTEX_TVGRADIENT;
1784 else
1785 style = WTEX_TDGRADIENT;
1787 if (nelem != 5) {
1788 wwarning(_("bad number of arguments in textured gradient specification"));
1789 return NULL;
1792 /* get from color */
1793 elem = PLGetArrayElement(pl, 3);
1794 if (!elem || !PLIsString(elem))
1795 return NULL;
1796 val = PLGetString(elem);
1798 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1799 wwarning(_("\"%s\" is not a valid color name"), val);
1800 return NULL;
1802 color1.alpha = 255;
1803 color1.red = xcolor.red >> 8;
1804 color1.green = xcolor.green >> 8;
1805 color1.blue = xcolor.blue >> 8;
1807 /* get to color */
1808 elem = PLGetArrayElement(pl, 4);
1809 if (!elem || !PLIsString(elem)) {
1810 return NULL;
1812 val = PLGetString(elem);
1814 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1815 wwarning(_("\"%s\" is not a valid color name"), val);
1816 return NULL;
1818 color2.alpha = 255;
1819 color2.red = xcolor.red >> 8;
1820 color2.green = xcolor.green >> 8;
1821 color2.blue = xcolor.blue >> 8;
1823 /* get opacity */
1824 elem = PLGetArrayElement(pl, 2);
1825 if (!elem || !PLIsString(elem))
1826 opacity = 128;
1827 else
1828 val = PLGetString(elem);
1830 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1831 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1832 opacity = 128;
1835 /* get file name */
1836 elem = PLGetArrayElement(pl, 1);
1837 if (!elem || !PLIsString(elem))
1838 return NULL;
1839 val = PLGetString(elem);
1841 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1842 val, opacity);
1844 #ifdef TEXTURE_PLUGIN
1845 else if (strcasecmp(val, "function")==0) {
1846 WTexFunction *function;
1847 void (*initFunc) (Display *, Colormap);
1848 char *lib, *func, **argv;
1849 int i, argc;
1851 if (nelem < 3)
1852 return NULL;
1854 /* get the library name */
1855 elem = PLGetArrayElement(pl, 1);
1856 if (!elem || !PLIsString(elem)) {
1857 return NULL;
1859 lib = PLGetString(elem);
1861 /* get the function name */
1862 elem = PLGetArrayElement(pl, 2);
1863 if (!elem || !PLIsString(elem)) {
1864 return NULL;
1866 func = PLGetString(elem);
1868 argc = nelem - 2;
1869 argv = (char **)wmalloc(argc * sizeof(char *));
1871 /* get the parameters */
1872 argv[0] = wstrdup(func);
1873 for (i = 0; i < argc - 1; i++) {
1874 elem = PLGetArrayElement(pl, 3 + i);
1875 if (!elem || !PLIsString(elem)) {
1876 free(argv);
1878 return NULL;
1880 argv[i+1] = wstrdup(PLGetString(elem));
1883 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1885 #ifdef HAVE_DLFCN_H
1886 if (function) {
1887 initFunc = dlsym(function->handle, "initWindowMaker");
1888 if (initFunc) {
1889 initFunc(dpy, scr->w_colormap);
1890 } else {
1891 wwarning(_("could not initialize library %s"), lib);
1893 } else {
1894 wwarning(_("could not find function %s::%s"), lib, func);
1896 #endif /* HAVE_DLFCN_H */
1897 texture = (WTexture*)function;
1899 #endif /* TEXTURE_PLUGIN */
1900 else {
1901 wwarning(_("invalid texture type %s"), val);
1902 return NULL;
1904 return texture;
1909 static int
1910 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1911 void **ret)
1913 static WTexture *texture;
1914 int changed=0;
1916 again:
1917 if (!PLIsArray(value)) {
1918 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1919 entry->key, "Texture");
1920 if (changed==0) {
1921 value = entry->plvalue;
1922 changed = 1;
1923 wwarning(_("using default \"%s\" instead"), entry->default_value);
1924 goto again;
1926 return False;
1929 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
1930 proplist_t pl;
1932 pl = PLGetArrayElement(value, 0);
1933 if (!pl || !PLIsString(pl) || !PLGetString(pl)
1934 || strcasecmp(PLGetString(pl), "solid")!=0) {
1935 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1936 entry->key, "Solid Texture");
1938 value = entry->plvalue;
1939 changed = 1;
1940 wwarning(_("using default \"%s\" instead"), entry->default_value);
1941 goto again;
1945 texture = parse_texture(scr, value);
1947 if (!texture) {
1948 wwarning(_("Error in texture specification for key \"%s\""),
1949 entry->key);
1950 if (changed==0) {
1951 value = entry->plvalue;
1952 changed = 1;
1953 wwarning(_("using default \"%s\" instead"), entry->default_value);
1954 goto again;
1956 return False;
1959 if (ret)
1960 *ret = &texture;
1962 if (addr)
1963 *(WTexture**)addr = texture;
1965 return True;
1970 static int
1971 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
1972 void *addr, void **ret)
1974 proplist_t elem;
1975 int changed = 0;
1976 char *val;
1977 int nelem;
1979 again:
1980 if (!PLIsArray(value)) {
1981 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1982 "WorkspaceBack", "Texture or None");
1983 if (changed==0) {
1984 value = entry->plvalue;
1985 changed = 1;
1986 wwarning(_("using default \"%s\" instead"), entry->default_value);
1987 goto again;
1989 return False;
1992 /* only do basic error checking and verify for None texture */
1994 nelem = PLGetNumberOfElements(value);
1995 if (nelem > 0) {
1996 elem = PLGetArrayElement(value, 0);
1997 if (!elem || !PLIsString(elem)) {
1998 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1999 if (changed==0) {
2000 value = entry->plvalue;
2001 changed = 1;
2002 wwarning(_("using default \"%s\" instead"), entry->default_value);
2003 goto again;
2005 return False;
2007 val = PLGetString(elem);
2009 if (strcasecmp(val, "None")==0)
2010 return True;
2012 *ret = PLRetain(value);
2014 return True;
2018 static int
2019 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2020 void *addr, void **ret)
2022 proplist_t elem;
2023 int nelem;
2024 int changed = 0;
2026 again:
2027 if (!PLIsArray(value)) {
2028 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2029 "WorkspaceSpecificBack", "an array of textures");
2030 if (changed==0) {
2031 value = entry->plvalue;
2032 changed = 1;
2033 wwarning(_("using default \"%s\" instead"), entry->default_value);
2034 goto again;
2036 return False;
2039 /* only do basic error checking and verify for None texture */
2041 nelem = PLGetNumberOfElements(value);
2042 if (nelem > 0) {
2043 while (nelem--) {
2044 elem = PLGetArrayElement(value, nelem);
2045 if (!elem || !PLIsArray(elem)) {
2046 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2047 nelem);
2052 *ret = PLRetain(value);
2054 #ifdef notworking
2056 * Kluge to force wmsetbg helper to set the default background.
2057 * If the WorkspaceSpecificBack is changed once wmaker has started,
2058 * the WorkspaceBack won't be sent to the helper, unless the user
2059 * changes it's value too. So, we must force this by removing the
2060 * value from the defaults DB.
2062 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2063 proplist_t key = PLMakeString("WorkspaceBack");
2065 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2067 PLRelease(key);
2069 #endif
2070 return True;
2074 static int
2075 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2076 void **ret)
2078 static WFont *font;
2079 char *val;
2081 STRINGP("Font");
2083 val = PLGetString(value);
2085 font = wLoadFont(val);
2086 if (!font) {
2087 wfatal(_("could not load any usable font!!!"));
2088 exit(1);
2091 if (ret)
2092 *ret = font;
2094 /* can't assign font value outside update function */
2095 wassertrv(addr == NULL, True);
2097 return True;
2101 static int
2102 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2103 void **ret)
2105 static unsigned long pixel;
2106 XColor color;
2107 char *val;
2108 int second_pass=0;
2110 STRINGP("Color");
2112 val = PLGetString(value);
2114 again:
2115 if (!wGetColor(scr, val, &color)) {
2116 wwarning(_("could not get color for key \"%s\""),
2117 entry->key);
2118 if (second_pass==0) {
2119 val = PLGetString(entry->plvalue);
2120 second_pass = 1;
2121 wwarning(_("using default \"%s\" instead"), val);
2122 goto again;
2124 return False;
2127 pixel = color.pixel;
2129 if (ret)
2130 *ret = &pixel;
2132 if (addr)
2133 *(unsigned long*)addr = pixel;
2135 return True;
2140 static int
2141 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2142 void **ret)
2144 static WShortKey shortcut;
2145 KeySym ksym;
2146 char *val;
2147 char *k;
2148 char buf[128], *b;
2151 STRINGP("Key spec");
2153 val = PLGetString(value);
2155 if (!val || strcasecmp(val, "NONE")==0) {
2156 shortcut.keycode = 0;
2157 shortcut.modifier = 0;
2158 if (ret)
2159 *ret = &shortcut;
2160 return True;
2163 strcpy(buf, val);
2165 b = (char*)buf;
2167 /* get modifiers */
2168 shortcut.modifier = 0;
2169 while ((k = strchr(b, '+'))!=NULL) {
2170 int mod;
2172 *k = 0;
2173 mod = wXModifierFromKey(b);
2174 if (mod<0) {
2175 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2176 return False;
2178 shortcut.modifier |= mod;
2180 b = k+1;
2183 /* get key */
2184 ksym = XStringToKeysym(b);
2186 if (ksym==NoSymbol) {
2187 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2188 val);
2189 return False;
2192 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2193 if (shortcut.keycode==0) {
2194 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2195 return False;
2198 if (ret)
2199 *ret = &shortcut;
2201 return True;
2205 static int
2206 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2207 void **ret)
2209 static unsigned int mask;
2210 char *str;
2212 STRINGP("Modifier Key");
2214 str = PLGetString(value);
2215 if (!str)
2216 return False;
2218 mask = wXModifierFromKey(str);
2219 if (mask < 0) {
2220 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2221 mask = 0;
2222 return False;
2225 if (addr)
2226 *(unsigned int*)addr = mask;
2228 if (ret)
2229 *ret = &mask;
2231 return True;
2235 #ifdef NEWSTUFF
2236 static int
2237 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2238 void *addr, void **ret)
2240 unsigned int mask;
2241 char *str;
2242 RImage *image;
2243 int i, n;
2244 int w, h;
2246 STRINGP("Image File Path");
2248 str = PLGetString(value);
2249 if (!str)
2250 return False;
2252 image = RLoadImage(scr->rcontext, str, 0);
2253 if (!image) {
2254 wwarning(_("could not load image in option %s: %s"), entry->key,
2255 RMessageForError(RErrorCode));
2256 return False;
2259 if (*(RImage**)addr) {
2260 RDestroyImage(*(RImage**)addr);
2262 if (addr)
2263 *(RImage**)addr = image;
2265 assert(ret == NULL);
2267 if (ret)
2268 *(RImage**)ret = image;
2271 return True;
2273 #endif
2276 /* ---------------- value setting functions --------------- */
2277 static int
2278 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2280 return REFRESH_FORE_COLOR;
2284 static int
2285 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2287 switch (which) {
2288 case WM_DOCK:
2289 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2290 break;
2291 case WM_CLIP:
2292 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2293 break;
2294 default:
2295 break;
2297 return 0;
2301 static int
2302 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2304 if (scr->workspaces) {
2305 wWorkspaceForceChange(scr, scr->current_workspace);
2306 wArrangeIcons(scr, False);
2308 return 0;
2311 #if not_used
2312 static int
2313 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2315 if (*value <= 0)
2316 *(int*)foo = 1;
2318 return 0;
2320 #endif
2324 static int
2325 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2327 Pixmap pixmap;
2328 RImage *img;
2329 int reset = 0;
2331 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2332 wPreferences.icon_size,
2333 ((*texture)->any.type & WREL_BORDER_MASK)
2334 ? WREL_ICON : WREL_FLAT);
2335 if (!img) {
2336 wwarning(_("could not render texture for icon background"));
2337 if (!entry->addr)
2338 wTextureDestroy(scr, *texture);
2339 return 0;
2341 RConvertImage(scr->rcontext, img, &pixmap);
2343 if (scr->icon_tile) {
2344 reset = 1;
2345 RDestroyImage(scr->icon_tile);
2346 XFreePixmap(dpy, scr->icon_tile_pixmap);
2349 scr->icon_tile = img;
2351 if (!wPreferences.flags.noclip) {
2352 if (scr->clip_tile) {
2353 RDestroyImage(scr->clip_tile);
2355 scr->clip_tile = wClipMakeTile(scr, img);
2358 scr->icon_tile_pixmap = pixmap;
2360 if (scr->def_icon_pixmap) {
2361 XFreePixmap(dpy, scr->def_icon_pixmap);
2362 scr->def_icon_pixmap = None;
2364 if (scr->def_ticon_pixmap) {
2365 XFreePixmap(dpy, scr->def_ticon_pixmap);
2366 scr->def_ticon_pixmap = None;
2369 if (scr->icon_back_texture) {
2370 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2372 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2374 if (scr->clip_balloon)
2375 XSetWindowBackground(dpy, scr->clip_balloon,
2376 (*texture)->any.color.pixel);
2379 * Free the texture as nobody else will use it, nor refer to it.
2381 if (!entry->addr)
2382 wTextureDestroy(scr, *texture);
2384 return (reset ? REFRESH_ICON_TILE : 0);
2389 static int
2390 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2392 if (scr->title_font) {
2393 wFreeFont(scr->title_font);
2396 scr->title_font = font;
2398 #ifndef I18N_MB
2399 XSetFont(dpy, scr->window_title_gc, font->font->fid);
2400 #endif
2402 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2406 static int
2407 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2409 if (scr->menu_title_font) {
2410 wFreeFont(scr->menu_title_font);
2413 scr->menu_title_font = font;
2415 #ifndef I18N_MB
2416 XSetFont(dpy, scr->menu_title_gc, font->font->fid);
2417 #endif
2419 return REFRESH_MENU_TITLE_FONT;
2423 static int
2424 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2426 if (scr->menu_entry_font) {
2427 wFreeFont(scr->menu_entry_font);
2430 scr->menu_entry_font = font;
2432 #ifndef I18N_MB
2433 XSetFont(dpy, scr->menu_entry_gc, font->font->fid);
2434 XSetFont(dpy, scr->disabled_menu_entry_gc, font->font->fid);
2435 XSetFont(dpy, scr->select_menu_gc, font->font->fid);
2436 #endif
2438 return REFRESH_MENU_FONT;
2443 static int
2444 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2446 if (scr->icon_title_font) {
2447 wFreeFont(scr->icon_title_font);
2450 scr->icon_title_font = font;
2452 #ifndef I18N_MB
2453 XSetFont(dpy, scr->icon_title_gc, font->font->fid);
2454 #endif
2456 return REFRESH_ICON_FONT;
2460 static int
2461 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2463 if (scr->clip_title_font) {
2464 wFreeFont(scr->clip_title_font);
2467 scr->clip_title_font = font;
2469 #ifndef I18N_MB
2470 XSetFont(dpy, scr->clip_title_gc, font->font->fid);
2471 #endif
2473 return REFRESH_ICON_FONT;
2477 static int
2478 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2480 if (scr->info_text_font) {
2481 wFreeFont(scr->info_text_font);
2484 scr->info_text_font = font;
2486 #ifndef I18N_MB
2487 XSetFont(dpy, scr->info_text_gc, font->font->fid);
2488 XSetFont(dpy, scr->line_gc, font->font->fid);
2489 #endif
2491 /* This test works because the scr structure is initially zeroed out
2492 and None = 0. Any other time, the window should be valid. */
2493 if (scr->geometry_display != None) {
2494 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2495 &scr->geometry_display_height);
2496 XResizeWindow(dpy, scr->geometry_display,
2497 scr->geometry_display_width, scr->geometry_display_height);
2500 return 0;
2504 static int
2505 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2507 if (scr->select_pixel!=scr->white_pixel &&
2508 scr->select_pixel!=scr->black_pixel) {
2509 wFreeColor(scr, scr->select_pixel);
2512 scr->select_pixel = color->pixel;
2514 return REFRESH_FORE_COLOR;
2518 static int
2519 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2521 if (scr->select_text_pixel!=scr->white_pixel &&
2522 scr->select_text_pixel!=scr->black_pixel) {
2523 wFreeColor(scr, scr->select_text_pixel);
2526 scr->select_text_pixel = color->pixel;
2528 return REFRESH_FORE_COLOR;
2532 static int
2533 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2535 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2536 scr->clip_title_pixel[index]!=scr->black_pixel) {
2537 wFreeColor(scr, scr->clip_title_pixel[index]);
2540 scr->clip_title_pixel[index] = color->pixel;
2542 return REFRESH_FORE_COLOR;
2546 static int
2547 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2549 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2550 scr->window_title_pixel[index]!=scr->black_pixel) {
2551 wFreeColor(scr, scr->window_title_pixel[index]);
2554 scr->window_title_pixel[index] = color->pixel;
2556 if (index == WS_UNFOCUSED)
2557 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2559 return REFRESH_WINDOW_TITLE_COLOR;
2563 static int
2564 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2566 #ifdef TITLE_TEXT_SHADOW
2567 if (index == WS_SMENU){
2568 if (scr->menu_title_pixel[WS_SMENU]!=scr->white_pixel &&
2569 scr->menu_title_pixel[WS_SMENU]!=scr->black_pixel) {
2570 wFreeColor(scr, scr->menu_title_pixel[WS_SMENU]);
2572 scr->menu_title_pixel[WS_SMENU] = color->pixel;
2574 else {
2575 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2576 scr->menu_title_pixel[0]!=scr->black_pixel) {
2577 wFreeColor(scr, scr->menu_title_pixel[0]);
2579 scr->menu_title_pixel[0] = color->pixel;
2581 #else /* !TITLE_TEXT_SHADOW */
2582 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2583 scr->menu_title_pixel[0]!=scr->black_pixel) {
2584 wFreeColor(scr, scr->menu_title_pixel[0]);
2587 scr->menu_title_pixel[0] = color->pixel;
2588 #endif /* !TITLE_TEXT_SHADOW */
2589 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2591 return REFRESH_MENU_TITLE_COLOR;
2595 static int
2596 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2598 XGCValues gcv;
2599 #define gcm (GCForeground|GCBackground|GCFillStyle)
2601 if (scr->mtext_pixel!=scr->white_pixel &&
2602 scr->mtext_pixel!=scr->black_pixel) {
2603 wFreeColor(scr, scr->mtext_pixel);
2606 scr->mtext_pixel = color->pixel;
2608 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2611 if (scr->dtext_pixel == scr->mtext_pixel) {
2612 gcv.foreground = scr->white_pixel;
2613 gcv.background = scr->black_pixel;
2614 gcv.fill_style = FillStippled;
2615 } else {
2616 gcv.foreground = scr->dtext_pixel;
2617 gcv.fill_style = FillSolid;
2619 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2621 return REFRESH_MENU_COLOR;
2622 #undef gcm
2626 static int
2627 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2629 XGCValues gcv;
2630 #define gcm (GCForeground|GCBackground|GCFillStyle)
2632 if (scr->dtext_pixel!=scr->white_pixel &&
2633 scr->dtext_pixel!=scr->black_pixel) {
2634 wFreeColor(scr, scr->dtext_pixel);
2637 scr->dtext_pixel = color->pixel;
2639 if (scr->dtext_pixel == scr->mtext_pixel) {
2640 gcv.foreground = scr->white_pixel;
2641 gcv.background = scr->black_pixel;
2642 gcv.fill_style = FillStippled;
2643 } else {
2644 gcv.foreground = scr->dtext_pixel;
2645 gcv.fill_style = FillSolid;
2647 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2649 return REFRESH_FORE_COLOR;
2650 #undef gcm
2653 static int
2654 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2656 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2658 return REFRESH_ICON_TITLE_COLOR;
2662 static int
2663 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2665 if (scr->icon_title_texture) {
2666 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2668 XQueryColor (dpy, scr->w_colormap, color);
2669 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2671 return REFRESH_ICON_TITLE_BACK;
2675 static void
2676 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2678 close(scr->helper_fd);
2679 scr->helper_fd = 0;
2680 scr->helper_pid = 0;
2681 scr->flags.backimage_helper_launched = 0;
2685 static int
2686 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2687 void *bar)
2689 int i;
2690 proplist_t val;
2691 char *str;
2693 if (scr->flags.backimage_helper_launched) {
2694 if (PLGetNumberOfElements(value)==0) {
2695 SendHelperMessage(scr, 'C', 0, NULL);
2696 SendHelperMessage(scr, 'K', 0, NULL);
2698 PLRelease(value);
2699 return 0;
2701 } else {
2702 pid_t pid;
2703 int filedes[2];
2705 if (PLGetNumberOfElements(value) == 0)
2706 return 0;
2708 if (pipe(filedes) < 0) {
2709 wsyserror("pipe() failed:can't set workspace specific background image");
2711 PLRelease(value);
2712 return 0;
2715 pid = fork();
2716 if (pid < 0) {
2717 wsyserror("fork() failed:can't set workspace specific background image");
2718 if (close(filedes[0]) < 0)
2719 wsyserror("could not close pipe");
2720 if (close(filedes[1]) < 0)
2721 wsyserror("could not close pipe");
2723 } else if (pid == 0) {
2724 SetupEnvironment(scr);
2726 if (close(0) < 0)
2727 wsyserror("could not close pipe");
2728 if (dup(filedes[0]) < 0) {
2729 wsyserror("dup() failed:can't set workspace specific background image");
2731 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2732 wsyserror("could not execute wmsetbg");
2733 exit(1);
2734 } else {
2736 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2737 wsyserror("error setting close-on-exec flag");
2739 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2740 wsyserror("error setting close-on-exec flag");
2743 scr->helper_fd = filedes[1];
2744 scr->helper_pid = pid;
2745 scr->flags.backimage_helper_launched = 1;
2747 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2749 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2753 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2754 val = PLGetArrayElement(value, i);
2755 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2756 str = PLGetDescription(val);
2758 SendHelperMessage(scr, 'S', i+1, str);
2760 free(str);
2761 } else {
2762 SendHelperMessage(scr, 'U', i+1, NULL);
2765 sleep(1);
2767 PLRelease(value);
2768 return 0;
2772 static int
2773 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2774 void *bar)
2776 if (scr->flags.backimage_helper_launched) {
2777 char *str;
2779 if (PLGetNumberOfElements(value)==0) {
2780 SendHelperMessage(scr, 'U', 0, NULL);
2781 } else {
2782 /* set the default workspace background to this one */
2783 str = PLGetDescription(value);
2784 if (str) {
2785 SendHelperMessage(scr, 'S', 0, str);
2786 free(str);
2787 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2788 } else {
2789 SendHelperMessage(scr, 'U', 0, NULL);
2792 } else {
2793 char *command;
2794 char *text;
2796 SetupEnvironment(scr);
2797 text = PLGetDescription(value);
2798 command = wmalloc(strlen(text)+40);
2799 sprintf(command, "wmsetbg -d -p '%s' &", text);
2800 free(text);
2801 system(command);
2802 free(command);
2804 PLRelease(value);
2806 return 0;
2810 static int
2811 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2813 if (scr->widget_texture) {
2814 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2816 scr->widget_texture = *(WTexSolid**)texture;
2818 return 0;
2822 static int
2823 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2825 if (scr->window_title_texture[WS_FOCUSED]) {
2826 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2828 scr->window_title_texture[WS_FOCUSED] = *texture;
2830 return REFRESH_WINDOW_TEXTURES;
2834 static int
2835 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2837 if (scr->window_title_texture[WS_PFOCUSED]) {
2838 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2840 scr->window_title_texture[WS_PFOCUSED] = *texture;
2842 return REFRESH_WINDOW_TEXTURES;
2846 static int
2847 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2849 if (scr->window_title_texture[WS_UNFOCUSED]) {
2850 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2852 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2854 if (scr->resizebar_texture[0]) {
2855 wTextureDestroy(scr, (WTexture*)scr->resizebar_texture[0]);
2857 scr->resizebar_texture[0]
2858 = wTextureMakeSolid(scr, &scr->window_title_texture[WS_UNFOCUSED]->any.color);
2860 if (scr->geometry_display != None)
2861 XSetWindowBackground(dpy, scr->geometry_display,
2862 scr->resizebar_texture[0]->normal.pixel);
2864 return REFRESH_WINDOW_TEXTURES;
2868 static int
2869 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2871 if (scr->menu_title_texture[0]) {
2872 wTextureDestroy(scr, scr->menu_title_texture[0]);
2874 scr->menu_title_texture[0] = *texture;
2876 return REFRESH_MENU_TITLE_TEXTURE;
2880 static int
2881 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2883 if (scr->menu_item_texture) {
2884 wTextureDestroy(scr, scr->menu_item_texture);
2885 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2887 scr->menu_item_texture = *texture;
2889 scr->menu_item_auxtexture
2890 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2892 return REFRESH_MENU_TEXTURE;
2896 static int
2897 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
2899 WWindow *wwin;
2900 wKeyBindings[index] = *shortcut;
2902 wwin = scr->focused_window;
2904 while (wwin!=NULL) {
2905 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2907 if (!WFLAGP(wwin, no_bind_keys)) {
2908 wWindowSetKeyGrabs(wwin);
2910 wwin = wwin->prev;
2913 return 0;
2917 static int
2918 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2920 wArrangeIcons(scr, True);
2922 return 0;
2926 static int
2927 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2929 wScreenUpdateUsableArea(scr);
2931 return 0;
2935 static int
2936 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2938 return REFRESH_MENU_TEXTURE;
2943 static int
2944 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2946 return REFRESH_BUTTON_IMAGES;
2951 * Very ugly kluge.
2952 * Need access to the double click variables, so that all widgets in
2953 * wmaker panels will have the same dbl-click values.
2954 * TODO: figure a better way of dealing with it.
2956 #include "WINGsP.h"
2958 static int
2959 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2961 extern _WINGsConfiguration WINGsConfiguration;
2963 if (*value <= 0)
2964 *(int*)foo = 1;
2966 WINGsConfiguration.doubleClickDelay = *value;
2968 return 0;