fixed bug of handling non string values in string type options in defaults.c
[wmaker-crm.git] / src / defaults.c
blob545685955d9ebe72f2a3950a14fa94b0b9f07e92
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"
25 #include "plugin.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifdef HAVE_DLFCN_H
40 # include <dlfcn.h>
41 #endif
45 #ifndef PATH_MAX
46 #define PATH_MAX DEFAULT_PATH_MAX
47 #endif
49 #include <X11/Xlib.h>
50 #include <X11/Xutil.h>
51 #include <X11/keysym.h>
53 #include <wraster.h>
56 #include "WindowMaker.h"
57 #include "wcore.h"
58 #include "framewin.h"
59 #include "window.h"
60 #include "texture.h"
61 #include "screen.h"
62 #include "resources.h"
63 #include "defaults.h"
64 #include "keybind.h"
65 #include "xmodifier.h"
66 #include "icon.h"
67 #include "funcs.h"
68 #include "actions.h"
69 #include "dock.h"
70 #include "workspace.h"
74 * Our own proplist reader parser. This one will not accept any
75 * syntax errors and is more descriptive in the error messages.
76 * It also doesn't seem to crash.
78 extern proplist_t ReadProplistFromFile(char *file);
81 /***** Global *****/
83 extern WDDomain *WDWindowMaker;
84 extern WDDomain *WDWindowAttributes;
85 extern WDDomain *WDRootMenu;
87 extern int wScreenCount;
90 extern proplist_t wDomainName;
91 extern proplist_t wAttributeDomainName;
93 extern WPreferences wPreferences;
95 extern WShortKey wKeyBindings[WKBD_LAST];
97 typedef struct {
98 char *key;
99 char *default_value;
100 void *extra_data;
101 void *addr;
102 int (*convert)();
103 int (*update)();
104 proplist_t plkey;
105 proplist_t plvalue; /* default value */
106 } WDefaultEntry;
109 /* used to map strings to integers */
110 typedef struct {
111 char *string;
112 short value;
113 char is_alias;
114 } WOptionEnumeration;
117 /* type converters */
118 static int getBool();
119 static int getInt();
120 static int getCoord();
121 #if 0
122 /* this is not used yet */
123 static int getString();
124 #endif
125 static int getPathList();
126 static int getEnum();
127 static int getTexture();
128 #ifdef DRAWSTRING_PLUGIN
129 static int getTextRenderer();
130 #endif
131 static int getWSBackground();
132 static int getWSSpecificBackground();
133 static int getFont();
134 static int getColor();
135 static int getKeybind();
136 static int getModMask();
137 #ifdef NEWSTUFF
138 static int getRImage();
139 #endif
142 /* value setting functions */
143 static int setJustify();
144 static int setIfDockPresent();
145 static int setStickyIcons();
147 static int setPositive();
149 static int setWidgetColor();
150 static int setIconTile();
151 static int setWinTitleFont();
152 static int setMenuTitleFont();
153 static int setMenuTextFont();
154 static int setIconTitleFont();
155 static int setIconTitleColor();
156 static int setIconTitleBack();
157 static int setLargeDisplayFont();
158 static int setWTitleColor();
159 static int setFTitleBack();
160 static int setPTitleBack();
161 static int setUTitleBack();
162 static int setResizebarBack();
163 static int setWorkspaceBack();
164 static int setWorkspaceSpecificBack();
165 static int setMenuTitleColor();
166 static int setMenuTextColor();
167 static int setMenuDisabledColor();
168 static int setMenuTitleBack();
169 static int setMenuTextBack();
170 static int setHightlight();
171 static int setHightlightText();
172 static int setKeyGrab();
173 static int setDoubleClick();
174 static int setIconPosition();
176 static int setClipTitleFont();
177 static int setClipTitleColor();
179 static int setMenuStyle();
180 static int setMultiByte();
182 static int updateUsableArea();
187 * Tables to convert strings to enumeration values.
188 * Values stored are char
192 /* WARNING: sum of length of all value strings must not exceed
193 * this value */
194 #define TOTAL_VALUES_LENGTH 80
199 #define REFRESH_WINDOW_TEXTURES (1<<0)
200 #define REFRESH_MENU_TEXTURE (1<<1)
201 #define REFRESH_MENU_FONT (1<<2)
202 #define REFRESH_MENU_COLOR (1<<3)
203 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
204 #define REFRESH_MENU_TITLE_FONT (1<<5)
205 #define REFRESH_MENU_TITLE_COLOR (1<<6)
206 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
207 #define REFRESH_WINDOW_FONT (1<<8)
208 #define REFRESH_ICON_TILE (1<<9)
209 #define REFRESH_ICON_FONT (1<<10)
210 #define REFRESH_WORKSPACE_BACK (1<<11)
212 #define REFRESH_BUTTON_IMAGES (1<<12)
214 #define REFRESH_ICON_TITLE_COLOR (1<<13)
215 #define REFRESH_ICON_TITLE_BACK (1<<14)
219 static WOptionEnumeration seFocusModes[] = {
220 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
221 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
222 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
223 {NULL, 0, 0}
226 static WOptionEnumeration seColormapModes[] = {
227 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
228 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
229 {NULL, 0, 0}
232 static WOptionEnumeration sePlacements[] = {
233 {"Auto", WPM_AUTO, 0}, {"Smart", WPM_SMART, 0},
234 {"Cascade", WPM_CASCADE, 0},
235 {"Random", WPM_RANDOM, 0},
236 {"Manual", WPM_MANUAL, 0},
237 {NULL, 0, 0}
240 static WOptionEnumeration seGeomDisplays[] = {
241 {"Center", WDIS_CENTER, 0},
242 {"Corner", WDIS_TOPLEFT, 0},
243 {"Floating", WDIS_FRAME_CENTER, 0},
244 {"Line", WDIS_NEW, 0},
245 {NULL, 0, 0}
248 static WOptionEnumeration seSpeeds[] = {
249 {"UltraFast", SPEED_ULTRAFAST, 0},
250 {"Fast", SPEED_FAST, 0},
251 {"Medium", SPEED_MEDIUM, 0},
252 {"Slow", SPEED_SLOW, 0},
253 {"UltraSlow", SPEED_ULTRASLOW, 0},
254 {NULL, 0, 0}
257 static WOptionEnumeration seMouseButtons[] = {
258 {"None", -1, 0},
259 {"Left", Button1, 0}, {"Button1", Button1, 1},
260 {"Middle", Button2, 0}, {"Button2", Button2, 1},
261 {"Right", Button3, 0}, {"Button3", Button3, 1},
262 {"Button4", Button4, 0},
263 {"Button5", Button5, 0},
264 {NULL, 0, 0}
267 static WOptionEnumeration seIconificationStyles[] = {
268 {"Zoom", WIS_ZOOM, 0},
269 {"Twist", WIS_TWIST, 0},
270 {"Flip", WIS_FLIP, 0},
271 {"None", WIS_NONE, 0},
272 {"random", WIS_RANDOM, 0},
273 {NULL, 0, 0}
276 static WOptionEnumeration seJustifications[] = {
277 {"Left", WTJ_LEFT, 0},
278 {"Center", WTJ_CENTER, 0},
279 {"Right", WTJ_RIGHT, 0},
280 {NULL, 0, 0}
283 static WOptionEnumeration seIconPositions[] = {
284 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
285 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
286 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
287 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
288 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
289 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
290 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
291 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
292 {NULL, 0, 0}
295 static WOptionEnumeration seMenuStyles[] = {
296 {"normal", MS_NORMAL, 0},
297 {"singletexture", MS_SINGLE_TEXTURE, 0},
298 {"flat", MS_FLAT, 0},
299 {NULL, 0, 0}
303 static WOptionEnumeration seDisplayPositions[] = {
304 {"none", WD_NONE, 0},
305 {"center", WD_CENTER, 0},
306 {"top", WD_TOP, 0},
307 {"bottom", WD_BOTTOM, 0},
308 {"topleft", WD_TOPLEFT, 0},
309 {"topright", WD_TOPRIGHT, 0},
310 {"bottomleft", WD_BOTTOMLEFT, 0},
311 {"bottomright", WD_BOTTOMRIGHT, 0}
316 * ALL entries in the tables bellow, NEED to have a default value
317 * defined, and this value needs to be correct.
320 /* these options will only affect the window manager on startup
322 * static defaults can't access the screen data, because it is
323 * created after these defaults are read
325 WDefaultEntry staticOptionList[] = {
327 {"DisableDithering", "NO", NULL,
328 &wPreferences.no_dithering, getBool, NULL
330 {"ColormapSize", "4", NULL,
331 &wPreferences.cmap_size, getInt, NULL
333 /* static by laziness */
334 {"IconSize", "64", NULL,
335 &wPreferences.icon_size, getInt, NULL
337 {"ModifierKey", "Mod1", NULL,
338 &wPreferences.modifier_mask, getModMask, NULL
340 {"DisableWSMouseActions", "NO", NULL,
341 &wPreferences.disable_root_mouse, getBool, NULL
343 {"FocusMode", "manual", seFocusModes,
344 &wPreferences.focus_mode, getEnum, NULL
345 }, /* have a problem when switching from manual to sloppy without restart */
346 {"NewStyle", "NO", NULL,
347 &wPreferences.new_style, getBool, NULL
349 {"DisableDock", "NO", (void*) WM_DOCK,
350 NULL, getBool, setIfDockPresent
352 {"DisableClip", "NO", (void*) WM_CLIP,
353 NULL, getBool, setIfDockPresent
355 {"DisableMiniwindows", "NO", NULL,
356 &wPreferences.disable_miniwindows, getBool, NULL
358 {"MultiByteText", "NO", NULL,
359 &wPreferences.multi_byte_text, getBool, setMultiByte
365 WDefaultEntry optionList[] = {
366 /* dynamic options */
367 {"IconPosition", "blh", seIconPositions,
368 &wPreferences.icon_yard, getEnum, setIconPosition
370 {"IconificationStyle", "Zoom", seIconificationStyles,
371 &wPreferences.iconification_style, getEnum, NULL
373 {"SelectWindowsMouseButton", "Left", seMouseButtons,
374 &wPreferences.select_button, getEnum, NULL
376 {"WindowListMouseButton", "Middle", seMouseButtons,
377 &wPreferences.windowl_button, getEnum, NULL
379 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
380 &wPreferences.menu_button, getEnum, NULL
382 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
383 &wPreferences.pixmap_path, getPathList, NULL
385 {"IconPath", DEF_ICON_PATHS, NULL,
386 &wPreferences.icon_path, getPathList, NULL
388 {"ColormapMode", "auto", seColormapModes,
389 &wPreferences.colormap_mode, getEnum, NULL
391 {"AutoFocus", "NO", NULL,
392 &wPreferences.auto_focus, getBool, NULL
394 {"RaiseDelay", "0", NULL,
395 &wPreferences.raise_delay, getInt, NULL
397 {"CirculateRaise", "NO", NULL,
398 &wPreferences.circ_raise, getBool, NULL
400 {"Superfluous", "NO", NULL,
401 &wPreferences.superfluous, getBool, NULL
403 {"AdvanceToNewWorkspace", "NO", NULL,
404 &wPreferences.ws_advance, getBool, NULL
406 {"CycleWorkspaces", "NO", NULL,
407 &wPreferences.ws_cycle, getBool, NULL
409 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
410 &wPreferences.workspace_name_display_position, getEnum, NULL
412 #ifdef VIRTUAL_DESKTOP
413 {"VirtualEdgeThickness", "1", NULL,
414 &wPreferences.vedge_thickness, getInt, NULL
416 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
417 &wPreferences.vedge_hscrollspeed, getInt, NULL
419 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
420 &wPreferences.vedge_vscrollspeed, getInt, NULL
422 {"VirtualEdgeWidth", "2000", NULL,
423 &wPreferences.vedge_width, getInt, NULL
425 {"VirtualEdgeHeight", "2000", NULL,
426 &wPreferences.vedge_height, getInt, NULL
428 #endif
429 {"StickyIcons", "NO", NULL,
430 &wPreferences.sticky_icons, getBool, setStickyIcons
432 {"SaveSessionOnExit", "NO", NULL,
433 &wPreferences.save_session_on_exit, getBool, NULL
435 {"WrapMenus", "NO", NULL,
436 &wPreferences.wrap_menus, getBool, NULL
438 {"ScrollableMenus", "NO", NULL,
439 &wPreferences.scrollable_menus, getBool, NULL
441 {"MenuScrollSpeed", "medium", seSpeeds,
442 &wPreferences.menu_scroll_speed, getEnum, NULL
444 {"IconSlideSpeed", "medium", seSpeeds,
445 &wPreferences.icon_slide_speed, getEnum, NULL
447 {"ShadeSpeed", "medium", seSpeeds,
448 &wPreferences.shade_speed, getEnum, NULL
450 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
451 &wPreferences.dblclick_time, getInt, setDoubleClick,
453 {"AlignSubmenus", "NO", NULL,
454 &wPreferences.align_menus, getBool, NULL
456 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
457 &wPreferences.open_transients_with_parent, getBool, NULL
459 {"WindowPlacement", "auto", sePlacements,
460 &wPreferences.window_placement, getEnum, NULL
462 {"IgnoreFocusClick","NO", NULL,
463 &wPreferences.ignore_focus_click, getBool, NULL
465 {"UseSaveUnders", "NO", NULL,
466 &wPreferences.use_saveunders, getBool, NULL
468 {"OpaqueMove", "NO", NULL,
469 &wPreferences.opaque_move, getBool, NULL
471 {"DisableSound", "NO", NULL,
472 &wPreferences.no_sound, getBool, NULL
474 {"DisableAnimations", "NO", NULL,
475 &wPreferences.no_animations, getBool, NULL
477 {"DontLinkWorkspaces","NO", NULL,
478 &wPreferences.no_autowrap, getBool, NULL
480 {"AutoArrangeIcons", "NO", NULL,
481 &wPreferences.auto_arrange_icons, getBool, NULL
483 {"NoWindowOverDock", "NO", NULL,
484 &wPreferences.no_window_over_dock, getBool, updateUsableArea
486 {"NoWindowOverIcons", "NO", NULL,
487 &wPreferences.no_window_over_icons, getBool, updateUsableArea
489 {"WindowPlaceOrigin", "(0, 0)", NULL,
490 &wPreferences.window_place_origin, getCoord, NULL
492 {"ResizeDisplay", "corner", seGeomDisplays,
493 &wPreferences.size_display, getEnum, NULL
495 {"MoveDisplay", "corner", seGeomDisplays,
496 &wPreferences.move_display, getEnum, NULL
498 {"DontConfirmKill", "NO", NULL,
499 &wPreferences.dont_confirm_kill, getBool,NULL
501 {"WindowTitleBalloons", "NO", NULL,
502 &wPreferences.window_balloon, getBool, NULL
504 {"MiniwindowTitleBalloons", "NO", NULL,
505 &wPreferences.miniwin_balloon,getBool, NULL
507 {"AppIconBalloons", "NO", NULL,
508 &wPreferences.appicon_balloon,getBool, NULL
510 {"HelpBalloons", "NO", NULL,
511 &wPreferences.help_balloon, getBool, NULL
513 {"EdgeResistance", "30", NULL,
514 &wPreferences.edge_resistance,getInt, NULL
516 {"Attraction", "NO", NULL,
517 &wPreferences.attract, getBool, NULL
519 {"DisableBlinking", "NO", NULL,
520 &wPreferences.dont_blink, getBool, NULL
522 #ifdef WEENDOZE_CYCLE
523 {"WindozeCycling","NO", NULL,
524 &wPreferences.windoze_cycling, getBool, NULL
526 {"PopupSwitchMenu","YES", NULL,
527 &wPreferences.popup_switchmenu, getBool, NULL
529 #endif /* WEENDOZE_CYCLE */
530 /* style options */
531 {"MenuStyle", "normal", seMenuStyles,
532 &wPreferences.menu_style, getEnum, setMenuStyle
534 {"WidgetColor", "(solid, gray)", NULL,
535 NULL, getTexture, setWidgetColor,
537 {"WorkspaceSpecificBack","()", NULL,
538 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
540 /* WorkspaceBack must come after WorkspaceSpecificBack or
541 * WorkspaceBack wont know WorkspaceSpecificBack was also
542 * specified and 2 copies of wmsetbg will be launched */
543 {"WorkspaceBack", "(solid, black)", NULL,
544 NULL, getWSBackground,setWorkspaceBack
546 {"SmoothWorkspaceBack", "NO", NULL,
547 NULL, getBool, NULL
549 {"IconBack", "(solid, gray)", NULL,
550 NULL, getTexture, setIconTile
552 {"TitleJustify", "center", seJustifications,
553 &wPreferences.title_justification, getEnum, setJustify
555 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
556 NULL, getFont, setWinTitleFont,
558 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
559 NULL, getFont, setMenuTitleFont
561 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
562 NULL, getFont, setMenuTextFont
564 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
565 NULL, getFont, setIconTitleFont
567 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
568 NULL, getFont, setClipTitleFont
570 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
571 NULL, getFont, setLargeDisplayFont
573 {"HighlightColor", "white", NULL,
574 NULL, getColor, setHightlight
576 {"HighlightTextColor", "black", NULL,
577 NULL, getColor, setHightlightText
579 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
580 NULL, getColor, setClipTitleColor
582 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
583 NULL, getColor, setClipTitleColor
585 #ifdef DRAWSTRING_PLUGIN
586 {"FTitleColor", "white", (void*)WS_FOCUSED,
587 NULL, getTextRenderer, setWTitleColor
589 {"PTitleColor", "white", (void*)WS_PFOCUSED,
590 NULL, getTextRenderer, setWTitleColor
592 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
593 NULL, getTextRenderer, setWTitleColor
595 #else
596 {"FTitleColor", "white", (void*)WS_FOCUSED,
597 NULL, getColor, setWTitleColor
599 {"PTitleColor", "white", (void*)WS_PFOCUSED,
600 NULL, getColor, setWTitleColor
602 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
603 NULL, getColor, setWTitleColor
605 #endif
606 {"FTitleBack", "(solid, black)", NULL,
607 NULL, getTexture, setFTitleBack
609 {"PTitleBack", "(solid, \"#616161\")", NULL,
610 NULL, getTexture, setPTitleBack
612 {"UTitleBack", "(solid, gray)", NULL,
613 NULL, getTexture, setUTitleBack
615 {"ResizebarBack", "(solid, gray)", NULL,
616 NULL, getTexture, setResizebarBack
618 #ifdef DRAWSTRING_PLUGIN
619 {"MenuTitleColor", "white", NULL,
620 NULL, getTextRenderer, setMenuTitleColor
622 #else
623 {"MenuTitleColor", "white", NULL,
624 NULL, getColor, setMenuTitleColor
626 #endif
627 {"MenuTextColor", "black", NULL,
628 NULL, getColor, setMenuTextColor
630 {"MenuDisabledColor", "\"#616161\"", NULL,
631 NULL, getColor, setMenuDisabledColor
633 {"MenuTitleBack", "(solid, black)", NULL,
634 NULL, getTexture, setMenuTitleBack
636 {"MenuTextBack", "(solid, gray)", NULL,
637 NULL, getTexture, setMenuTextBack
639 {"IconTitleColor", "white", NULL,
640 NULL, getColor, setIconTitleColor
642 {"IconTitleBack", "black", NULL,
643 NULL, getColor, setIconTitleBack
645 /* keybindings */
646 #ifndef LITE
647 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
648 NULL, getKeybind, setKeyGrab
650 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
651 NULL, getKeybind, setKeyGrab
653 #endif /* LITE */
654 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
655 NULL, getKeybind, setKeyGrab
657 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
658 NULL, getKeybind, setKeyGrab
660 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
661 NULL, getKeybind, setKeyGrab
663 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
664 NULL, getKeybind, setKeyGrab
666 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
667 NULL, getKeybind, setKeyGrab
669 {"HideKey", "None", (void*)WKBD_HIDE,
670 NULL, getKeybind, setKeyGrab
672 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
673 NULL, getKeybind, setKeyGrab
675 {"CloseKey", "None", (void*)WKBD_CLOSE,
676 NULL, getKeybind, setKeyGrab
678 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
679 NULL, getKeybind, setKeyGrab
681 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
682 NULL, getKeybind, setKeyGrab
684 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
685 NULL, getKeybind, setKeyGrab
687 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
688 NULL, getKeybind, setKeyGrab
690 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
691 NULL, getKeybind, setKeyGrab
693 {"ShadeKey", "None", (void*)WKBD_SHADE,
694 NULL, getKeybind, setKeyGrab
696 {"SelectKey", "None", (void*)WKBD_SELECT,
697 NULL, getKeybind, setKeyGrab
699 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
700 NULL, getKeybind, setKeyGrab
702 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
703 NULL, getKeybind, setKeyGrab
705 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
706 NULL, getKeybind, setKeyGrab
708 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
709 NULL, getKeybind, setKeyGrab
711 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
712 NULL, getKeybind, setKeyGrab
714 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
715 NULL, getKeybind, setKeyGrab
717 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
718 NULL, getKeybind, setKeyGrab
720 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
721 NULL, getKeybind, setKeyGrab
723 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
724 NULL, getKeybind, setKeyGrab
726 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
727 NULL, getKeybind, setKeyGrab
729 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
730 NULL, getKeybind, setKeyGrab
732 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
733 NULL, getKeybind, setKeyGrab
735 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
736 NULL, getKeybind, setKeyGrab
738 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
739 NULL, getKeybind, setKeyGrab
741 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
742 NULL, getKeybind, setKeyGrab
744 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
745 NULL, getKeybind, setKeyGrab
747 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
748 NULL, getKeybind, setKeyGrab
750 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
751 NULL, getKeybind, setKeyGrab
753 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
754 NULL, getKeybind, setKeyGrab
756 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
757 NULL, getKeybind, setKeyGrab
759 #ifdef EXTEND_WINDOWSHORTCUT
760 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
761 NULL, getKeybind, setKeyGrab
763 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
764 NULL, getKeybind, setKeyGrab
766 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
767 NULL, getKeybind, setKeyGrab
769 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
770 NULL, getKeybind, setKeyGrab
772 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
773 NULL, getKeybind, setKeyGrab
775 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
776 NULL, getKeybind, setKeyGrab
778 #endif /* EXTEND_WINDOWSHORTCUT */
780 #ifdef KEEP_XKB_LOCK_STATUS
781 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
782 NULL, getKeybind, setKeyGrab
784 {"KbdModeLock", "NO", NULL,
785 &wPreferences.modelock, getBool, NULL
787 #endif /* KEEP_XKB_LOCK_STATUS */
791 #if 0
792 static void rereadDefaults(void);
793 #endif
795 #if 0
796 static void
797 rereadDefaults(void)
799 /* must defer the update because accessing X data from a
800 * signal handler can mess up Xlib */
803 #endif
805 static void
806 initDefaults()
808 int i;
809 WDefaultEntry *entry;
811 PLSetStringCmpHook(StringCompareHook);
813 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
814 entry = &optionList[i];
816 entry->plkey = PLMakeString(entry->key);
817 if (entry->default_value)
818 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
819 else
820 entry->plvalue = NULL;
823 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
824 entry = &staticOptionList[i];
826 entry->plkey = PLMakeString(entry->key);
827 if (entry->default_value)
828 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
829 else
830 entry->plvalue = NULL;
834 wDomainName = PLMakeString(WMDOMAIN_NAME);
835 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
837 PLRegister(wDomainName, rereadDefaults);
838 PLRegister(wAttributeDomainName, rereadDefaults);
845 #if 0
846 proplist_t
847 wDefaultsInit(int screen_number)
849 static int defaults_inited = 0;
850 proplist_t dict;
852 if (!defaults_inited) {
853 initDefaults();
856 dict = PLGetDomain(wDomainName);
857 if (!dict) {
858 wwarning(_("could not read domain \"%s\" from defaults database"),
859 PLGetString(wDomainName));
862 return dict;
864 #endif
867 void
868 wDefaultsDestroyDomain(WDDomain *domain)
870 if (domain->dictionary)
871 PLRelease(domain->dictionary);
872 free(domain->path);
873 free(domain);
877 WDDomain*
878 wDefaultsInitDomain(char *domain, Bool requireDictionary)
880 WDDomain *db;
881 struct stat stbuf;
882 static int inited = 0;
883 char path[PATH_MAX];
884 char *the_path;
885 proplist_t shared_dict=NULL;
887 if (!inited) {
888 inited = 1;
889 initDefaults();
892 db = wmalloc(sizeof(WDDomain));
893 memset(db, 0, sizeof(WDDomain));
894 db->domain_name = domain;
895 db->path = wdefaultspathfordomain(domain);
896 the_path = db->path;
898 if (the_path && stat(the_path, &stbuf)>=0) {
899 db->dictionary = ReadProplistFromFile(the_path);
900 if (db->dictionary) {
901 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
902 PLRelease(db->dictionary);
903 db->dictionary = NULL;
904 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
905 domain, the_path);
907 db->timestamp = stbuf.st_mtime;
908 } else {
909 wwarning(_("could not load domain %s from user defaults database"),
910 domain);
914 /* global system dictionary */
915 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
916 if (stat(path, &stbuf)>=0) {
917 shared_dict = ReadProplistFromFile(path);
918 if (shared_dict) {
919 if (requireDictionary && !PLIsDictionary(shared_dict)) {
920 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
921 domain, path);
922 PLRelease(shared_dict);
923 shared_dict = NULL;
924 } else {
925 if (db->dictionary && PLIsDictionary(shared_dict) &&
926 PLIsDictionary(db->dictionary)) {
927 PLMergeDictionaries(shared_dict, db->dictionary);
928 PLRelease(db->dictionary);
929 db->dictionary = shared_dict;
930 if (stbuf.st_mtime > db->timestamp)
931 db->timestamp = stbuf.st_mtime;
932 } else if (!db->dictionary) {
933 db->dictionary = shared_dict;
934 if (stbuf.st_mtime > db->timestamp)
935 db->timestamp = stbuf.st_mtime;
938 } else {
939 wwarning(_("could not load domain %s from global defaults database (%s)"),
940 domain, path);
944 /* set to save it in user's directory, no matter from where it was read */
945 if (db->dictionary) {
946 proplist_t tmp = PLMakeString(db->path);
948 PLSetFilename(db->dictionary, tmp);
949 PLRelease(tmp);
952 return db;
956 void
957 wReadStaticDefaults(proplist_t dict)
959 proplist_t plvalue;
960 WDefaultEntry *entry;
961 int i;
962 void *tdata;
965 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
966 entry = &staticOptionList[i];
968 if (dict)
969 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
970 else
971 plvalue = NULL;
973 if (!plvalue) {
974 /* no default in the DB. Use builtin default */
975 plvalue = entry->plvalue;
978 if (plvalue) {
979 /* convert data */
980 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
981 if (entry->update) {
982 (*entry->update)(NULL, entry, tdata, entry->extra_data);
989 void
990 wDefaultsCheckDomains(void *foo)
992 WScreen *scr;
993 struct stat stbuf;
994 proplist_t dict;
995 int i;
996 char path[PATH_MAX];
998 #ifdef HEARTBEAT
999 puts("Checking domains...");
1000 #endif
1001 if (stat(WDWindowMaker->path, &stbuf)>=0
1002 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1003 proplist_t shared_dict = NULL;
1004 #ifdef HEARTBEAT
1005 puts("Checking WindowMaker domain");
1006 #endif
1007 WDWindowMaker->timestamp = stbuf.st_mtime;
1009 /* global dictionary */
1010 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1011 if (stat(path, &stbuf)>=0) {
1012 shared_dict = ReadProplistFromFile(path);
1013 if (shared_dict && !PLIsDictionary(shared_dict)) {
1014 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1015 "WindowMaker", path);
1016 PLRelease(shared_dict);
1017 shared_dict = NULL;
1018 } else if (!shared_dict) {
1019 wwarning(_("could not load domain %s from global defaults database"),
1020 "WindowMaker");
1023 /* user dictionary */
1024 dict = ReadProplistFromFile(WDWindowMaker->path);
1025 if (dict) {
1026 if (!PLIsDictionary(dict)) {
1027 PLRelease(dict);
1028 dict = NULL;
1029 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1030 "WindowMaker", WDWindowMaker->path);
1031 } else {
1032 if (shared_dict) {
1033 PLSetFilename(shared_dict, PLGetFilename(dict));
1034 PLMergeDictionaries(shared_dict, dict);
1035 PLRelease(dict);
1036 dict = shared_dict;
1037 shared_dict = NULL;
1039 for (i=0; i<wScreenCount; i++) {
1040 scr = wScreenWithNumber(i);
1041 if (scr)
1042 wReadDefaults(scr, dict);
1044 if (WDWindowMaker->dictionary) {
1045 PLRelease(WDWindowMaker->dictionary);
1047 WDWindowMaker->dictionary = dict;
1049 } else {
1050 wwarning(_("could not load domain %s from user defaults database"),
1051 "WindowMaker");
1053 if (shared_dict) {
1054 PLRelease(shared_dict);
1058 if (stat(WDWindowAttributes->path, &stbuf)>=0
1059 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1060 #ifdef HEARTBEAT
1061 puts("Checking WMWindowAttributes domain");
1062 #endif
1063 dict = ReadProplistFromFile(WDWindowAttributes->path);
1064 if (dict) {
1065 if (!PLIsDictionary(dict)) {
1066 PLRelease(dict);
1067 dict = NULL;
1068 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1069 "WMWindowAttributes", WDWindowAttributes->path);
1070 } else {
1071 if (WDWindowAttributes->dictionary)
1072 PLRelease(WDWindowAttributes->dictionary);
1073 WDWindowAttributes->dictionary = dict;
1074 for (i=0; i<wScreenCount; i++) {
1075 scr = wScreenWithNumber(i);
1076 if (scr)
1077 wDefaultUpdateIcons(scr);
1080 } else {
1081 wwarning(_("could not load domain %s from user defaults database"),
1082 "WMWindowAttributes");
1084 WDWindowAttributes->timestamp = stbuf.st_mtime;
1087 #ifndef LITE
1088 if (stat(WDRootMenu->path, &stbuf)>=0
1089 && WDRootMenu->timestamp < stbuf.st_mtime) {
1090 dict = ReadProplistFromFile(WDRootMenu->path);
1091 #ifdef HEARTBEAT
1092 puts("Checking WMRootMenu domain");
1093 #endif
1094 if (dict) {
1095 if (!PLIsArray(dict) && !PLIsString(dict)) {
1096 PLRelease(dict);
1097 dict = NULL;
1098 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1099 "WMRootMenu", WDRootMenu->path);
1100 } else {
1101 if (WDRootMenu->dictionary) {
1102 PLRelease(WDRootMenu->dictionary);
1104 WDRootMenu->dictionary = dict;
1106 } else {
1107 wwarning(_("could not load domain %s from user defaults database"),
1108 "WMRootMenu");
1110 WDRootMenu->timestamp = stbuf.st_mtime;
1112 #endif /* !LITE */
1114 if (!foo)
1115 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1119 void
1120 wReadDefaults(WScreen *scr, proplist_t new_dict)
1122 proplist_t plvalue, old_value;
1123 WDefaultEntry *entry;
1124 int i, must_update;
1125 int update_workspace_back = 0; /* kluge :/ */
1126 int needs_refresh;
1127 void *tdata;
1128 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1129 ? WDWindowMaker->dictionary : NULL);
1131 must_update = 0;
1133 needs_refresh = 0;
1135 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1136 entry = &optionList[i];
1138 if (new_dict)
1139 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1140 else
1141 plvalue = NULL;
1143 if (!old_dict)
1144 old_value = NULL;
1145 else
1146 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1149 if (!plvalue && !old_value) {
1150 /* no default in the DB. Use builtin default */
1151 plvalue = entry->plvalue;
1152 if (plvalue && new_dict) {
1153 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1154 must_update = 1;
1156 } else if (!plvalue) {
1157 /* value was deleted from DB. Keep current value */
1158 continue;
1159 } else if (!old_value) {
1160 /* set value for the 1st time */
1161 } else if (!PLIsEqual(plvalue, old_value)) {
1162 /* value has changed */
1163 } else {
1165 if (strcmp(entry->key, "WorkspaceBack") == 0
1166 && update_workspace_back
1167 && scr->flags.backimage_helper_launched) {
1168 } else {
1169 /* value was not changed since last time */
1170 continue;
1174 if (plvalue) {
1175 #ifdef DEBUG
1176 printf("Updating %s to %s\n", entry->key,
1177 PLGetDescription(plvalue));
1178 #endif
1179 /* convert data */
1180 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1182 * If the WorkspaceSpecificBack data has been changed
1183 * so that the helper will be launched now, we must be
1184 * sure to send the default background texture config
1185 * to the helper.
1187 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1188 && !scr->flags.backimage_helper_launched) {
1189 update_workspace_back = 1;
1191 if (entry->update) {
1192 needs_refresh |=
1193 (*entry->update)(scr, entry, tdata, entry->extra_data);
1199 if (needs_refresh!=0 && !scr->flags.startup) {
1200 int foo;
1202 foo = 0;
1203 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1204 foo |= WTextureSettings;
1205 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1206 foo |= WFontSettings;
1207 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1208 foo |= WColorSettings;
1209 if (foo)
1210 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1211 (void*)foo);
1213 foo = 0;
1214 if (needs_refresh & REFRESH_MENU_TEXTURE)
1215 foo |= WTextureSettings;
1216 if (needs_refresh & REFRESH_MENU_FONT)
1217 foo |= WFontSettings;
1218 if (needs_refresh & REFRESH_MENU_COLOR)
1219 foo |= WColorSettings;
1220 if (foo)
1221 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1222 (void*)foo);
1224 foo = 0;
1225 if (needs_refresh & REFRESH_WINDOW_FONT) {
1226 foo |= WFontSettings;
1228 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1229 foo |= WTextureSettings;
1231 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1232 foo |= WColorSettings;
1234 if (foo)
1235 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1236 (void*)foo);
1238 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1239 foo = 0;
1240 if (needs_refresh & REFRESH_ICON_FONT) {
1241 foo |= WFontSettings;
1243 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1244 foo |= WTextureSettings;
1246 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1247 foo |= WTextureSettings;
1249 if (foo)
1250 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1251 (void*)foo);
1253 if (needs_refresh & REFRESH_ICON_TILE)
1254 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1259 void
1260 wDefaultUpdateIcons(WScreen *scr)
1262 WAppIcon *aicon = scr->app_icon_list;
1263 WWindow *wwin = scr->focused_window;
1264 char *file;
1266 while(aicon) {
1267 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1268 False);
1269 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1270 || (file && !aicon->icon->file)) {
1271 RImage *new_image;
1273 if (aicon->icon->file)
1274 free(aicon->icon->file);
1275 aicon->icon->file = wstrdup(file);
1277 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1278 aicon->wm_class);
1279 if (new_image) {
1280 wIconChangeImage(aicon->icon, new_image);
1281 wAppIconPaint(aicon);
1284 aicon = aicon->next;
1287 if (!wPreferences.flags.noclip)
1288 wClipIconPaint(scr->clip_icon);
1290 while (wwin) {
1291 if (wwin->icon && wwin->flags.miniaturized) {
1292 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1293 False);
1294 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1295 || (file && !wwin->icon->file)) {
1296 RImage *new_image;
1298 if (wwin->icon->file)
1299 free(wwin->icon->file);
1300 wwin->icon->file = wstrdup(file);
1302 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1303 wwin->wm_class);
1304 if (new_image)
1305 wIconChangeImage(wwin->icon, new_image);
1308 wwin = wwin->prev;
1313 /* --------------------------- Local ----------------------- */
1315 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1316 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1317 entry->key, x); \
1318 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1319 var = entry->default_value;\
1320 } else var = PLGetString(value)\
1326 static int
1327 string2index(proplist_t key, proplist_t val, proplist_t def,
1328 WOptionEnumeration *values)
1330 char *str;
1331 WOptionEnumeration *v;
1332 char buffer[TOTAL_VALUES_LENGTH];
1334 if (PLIsString(val) && (str = PLGetString(val))) {
1335 for (v=values; v->string!=NULL; v++) {
1336 if (strcasecmp(v->string, str)==0)
1337 return v->value;
1341 buffer[0] = 0;
1342 for (v=values; v->string!=NULL; v++) {
1343 if (!v->is_alias) {
1344 if (buffer[0]!=0)
1345 strcat(buffer, ", ");
1346 strcat(buffer, v->string);
1349 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1350 PLGetString(key), buffer);
1352 if (def) {
1353 return string2index(key, val, NULL, values);
1356 return -1;
1363 * value - is the value in the defaults DB
1364 * addr - is the address to store the data
1365 * ret - is the address to store a pointer to a temporary buffer. ret
1366 * must not be freed and is used by the set functions
1368 static int
1369 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1370 void **ret)
1372 static char data;
1373 char *val;
1374 int second_pass=0;
1376 GET_STRING_OR_DEFAULT("Boolean", val);
1378 again:
1379 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1380 || strcasecmp(val, "YES")==0) {
1382 data = 1;
1383 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1384 || strcasecmp(val, "NO")==0) {
1385 data = 0;
1386 } else {
1387 int i;
1388 if (sscanf(val, "%i", &i)==1) {
1389 if (i!=0)
1390 data = 1;
1391 else
1392 data = 0;
1393 } else {
1394 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1395 val, entry->key);
1396 if (second_pass==0) {
1397 val = PLGetString(entry->plvalue);
1398 second_pass = 1;
1399 wwarning(_("using default \"%s\" instead"), val);
1400 goto again;
1402 return False;
1406 if (ret)
1407 *ret = &data;
1409 if (addr) {
1410 *(char*)addr = data;
1413 return True;
1417 static int
1418 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1419 void **ret)
1421 static int data;
1422 char *val;
1425 GET_STRING_OR_DEFAULT("Integer", val);
1427 if (sscanf(val, "%i", &data)!=1) {
1428 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1429 val, entry->key);
1430 val = PLGetString(entry->plvalue);
1431 wwarning(_("using default \"%s\" instead"), val);
1432 if (sscanf(val, "%i", &data)!=1) {
1433 return False;
1437 if (ret)
1438 *ret = &data;
1440 if (addr) {
1441 *(int*)addr = data;
1443 return True;
1447 static int
1448 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1449 void **ret)
1451 static WCoord data;
1452 char *val_x, *val_y;
1453 int nelem, changed=0;
1454 proplist_t elem_x, elem_y;
1456 again:
1457 if (!PLIsArray(value)) {
1458 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1459 entry->key, "Coordinate");
1460 if (changed==0) {
1461 value = entry->plvalue;
1462 changed = 1;
1463 wwarning(_("using default \"%s\" instead"), entry->default_value);
1464 goto again;
1466 return False;
1469 nelem = PLGetNumberOfElements(value);
1470 if (nelem != 2) {
1471 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1472 entry->key);
1473 if (changed==0) {
1474 value = entry->plvalue;
1475 changed = 1;
1476 wwarning(_("using default \"%s\" instead"), entry->default_value);
1477 goto again;
1479 return False;
1482 elem_x = PLGetArrayElement(value, 0);
1483 elem_y = PLGetArrayElement(value, 1);
1485 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1486 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1487 entry->key);
1488 if (changed==0) {
1489 value = entry->plvalue;
1490 changed = 1;
1491 wwarning(_("using default \"%s\" instead"), entry->default_value);
1492 goto again;
1494 return False;
1497 val_x = PLGetString(elem_x);
1498 val_y = PLGetString(elem_y);
1500 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1501 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
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 if (data.x < 0)
1512 data.x = 0;
1513 else if (data.x > scr->scr_width/3)
1514 data.x = scr->scr_width/3;
1515 if (data.y < 0)
1516 data.y = 0;
1517 else if (data.y > scr->scr_height/3)
1518 data.y = scr->scr_height/3;
1520 if (ret)
1521 *ret = &data;
1523 if (addr) {
1524 *(WCoord*)addr = data;
1527 return True;
1531 #if 0
1532 /* This function is not used at the moment. */
1533 static int
1534 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1535 void **ret)
1537 static char *data;
1539 GET_STRING_OR_DEFAULT("String", data);
1541 if (!data) {
1542 data = PLGetString(entry->plvalue);
1543 if (!data)
1544 return False;
1547 if (ret)
1548 *ret = &data;
1550 if (addr)
1551 *(char**)addr = wstrdup(data);
1553 return True;
1555 #endif
1558 static int
1559 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1560 void **ret)
1562 static char *data;
1563 int i, count, len;
1564 char *ptr;
1565 proplist_t d;
1566 int changed=0;
1568 again:
1569 if (!PLIsArray(value)) {
1570 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1571 entry->key, "an array of paths");
1572 if (changed==0) {
1573 value = entry->plvalue;
1574 changed = 1;
1575 wwarning(_("using default \"%s\" instead"), entry->default_value);
1576 goto again;
1578 return False;
1581 i = 0;
1582 count = PLGetNumberOfElements(value);
1583 if (count < 1) {
1584 if (changed==0) {
1585 value = entry->plvalue;
1586 changed = 1;
1587 wwarning(_("using default \"%s\" instead"), entry->default_value);
1588 goto again;
1590 return False;
1593 len = 0;
1594 for (i=0; i<count; i++) {
1595 d = PLGetArrayElement(value, i);
1596 if (!d || !PLIsString(d)) {
1597 count = i;
1598 break;
1600 len += strlen(PLGetString(d))+1;
1603 ptr = data = wmalloc(len+1);
1605 for (i=0; i<count; i++) {
1606 d = PLGetArrayElement(value, i);
1607 if (!d || !PLIsString(d)) {
1608 break;
1610 strcpy(ptr, PLGetString(d));
1611 ptr += strlen(PLGetString(d));
1612 *ptr = ':';
1613 ptr++;
1615 ptr--; *(ptr--) = 0;
1617 if (*(char**)addr!=NULL) {
1618 free(*(char**)addr);
1620 *(char**)addr = data;
1622 return True;
1626 static int
1627 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1628 void **ret)
1630 static signed char data;
1632 data = string2index(entry->plkey, value, entry->default_value,
1633 (WOptionEnumeration*)entry->extra_data);
1634 if (data < 0)
1635 return False;
1637 if (ret)
1638 *ret = &data;
1640 if (addr)
1641 *(signed char*)addr = data;
1643 return True;
1649 * (solid <color>)
1650 * (hgradient <color> <color>)
1651 * (vgradient <color> <color>)
1652 * (dgradient <color> <color>)
1653 * (mhgradient <color> <color> ...)
1654 * (mvgradient <color> <color> ...)
1655 * (tpixmap <file> <color>)
1656 * (spixmap <file> <color>)
1657 * (cpixmap <file> <color>)
1658 * (thgradient <file> <opaqueness> <color> <color>)
1659 * (tvgradient <file> <opaqueness> <color> <color>)
1660 * (tdgradient <file> <opaqueness> <color> <color>)
1661 * (function <lib> <function> ...)
1664 static WTexture*
1665 parse_texture(WScreen *scr, proplist_t pl)
1667 proplist_t elem;
1668 char *val;
1669 int nelem;
1670 WTexture *texture=NULL;
1672 nelem = PLGetNumberOfElements(pl);
1673 if (nelem < 1)
1674 return NULL;
1677 elem = PLGetArrayElement(pl, 0);
1678 if (!elem || !PLIsString(elem))
1679 return NULL;
1680 val = PLGetString(elem);
1683 if (strcasecmp(val, "solid")==0) {
1684 XColor color;
1686 if (nelem != 2)
1687 return NULL;
1689 /* get color */
1691 elem = PLGetArrayElement(pl, 1);
1692 if (!elem || !PLIsString(elem))
1693 return NULL;
1694 val = PLGetString(elem);
1696 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1697 wwarning(_("\"%s\" is not a valid color name"), val);
1698 return NULL;
1701 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1702 } else if (strcasecmp(val, "dgradient")==0
1703 || strcasecmp(val, "vgradient")==0
1704 || strcasecmp(val, "hgradient")==0) {
1705 RColor color1, color2;
1706 XColor xcolor;
1707 int type;
1709 if (nelem != 3) {
1710 wwarning(_("bad number of arguments in gradient specification"));
1711 return NULL;
1714 if (val[0]=='d' || val[0]=='D')
1715 type = WTEX_DGRADIENT;
1716 else if (val[0]=='h' || val[0]=='H')
1717 type = WTEX_HGRADIENT;
1718 else
1719 type = WTEX_VGRADIENT;
1722 /* get from color */
1723 elem = PLGetArrayElement(pl, 1);
1724 if (!elem || !PLIsString(elem))
1725 return NULL;
1726 val = PLGetString(elem);
1728 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1729 wwarning(_("\"%s\" is not a valid color name"), val);
1730 return NULL;
1732 color1.alpha = 255;
1733 color1.red = xcolor.red >> 8;
1734 color1.green = xcolor.green >> 8;
1735 color1.blue = xcolor.blue >> 8;
1737 /* get to color */
1738 elem = PLGetArrayElement(pl, 2);
1739 if (!elem || !PLIsString(elem)) {
1740 return NULL;
1742 val = PLGetString(elem);
1744 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1745 wwarning(_("\"%s\" is not a valid color name"), val);
1746 return NULL;
1748 color2.alpha = 255;
1749 color2.red = xcolor.red >> 8;
1750 color2.green = xcolor.green >> 8;
1751 color2.blue = xcolor.blue >> 8;
1753 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1755 } else if (strcasecmp(val, "mhgradient")==0
1756 || strcasecmp(val, "mvgradient")==0
1757 || strcasecmp(val, "mdgradient")==0) {
1758 XColor color;
1759 RColor **colors;
1760 int i, count;
1761 int type;
1763 if (nelem < 3) {
1764 wwarning(_("too few arguments in multicolor gradient specification"));
1765 return NULL;
1768 if (val[1]=='h' || val[1]=='H')
1769 type = WTEX_MHGRADIENT;
1770 else if (val[1]=='v' || val[1]=='V')
1771 type = WTEX_MVGRADIENT;
1772 else
1773 type = WTEX_MDGRADIENT;
1775 count = nelem-1;
1777 colors = wmalloc(sizeof(RColor*)*(count+1));
1779 for (i=0; i<count; i++) {
1780 elem = PLGetArrayElement(pl, i+1);
1781 if (!elem || !PLIsString(elem)) {
1782 for (--i; i>=0; --i) {
1783 free(colors[i]);
1785 free(colors);
1786 return NULL;
1788 val = PLGetString(elem);
1790 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1791 wwarning(_("\"%s\" is not a valid color name"), val);
1792 for (--i; i>=0; --i) {
1793 free(colors[i]);
1795 free(colors);
1796 return NULL;
1797 } else {
1798 colors[i] = wmalloc(sizeof(RColor));
1799 colors[i]->red = color.red >> 8;
1800 colors[i]->green = color.green >> 8;
1801 colors[i]->blue = color.blue >> 8;
1804 colors[i] = NULL;
1806 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1807 } else if (strcasecmp(val, "spixmap")==0 ||
1808 strcasecmp(val, "cpixmap")==0 ||
1809 strcasecmp(val, "tpixmap")==0) {
1810 XColor color;
1811 int type;
1813 if (nelem != 3)
1814 return NULL;
1816 if (val[0] == 's' || val[0] == 'S')
1817 type = WTP_SCALE;
1818 else if (val[0] == 'c' || val[0] == 'C')
1819 type = WTP_CENTER;
1820 else
1821 type = WTP_TILE;
1823 /* get color */
1824 elem = PLGetArrayElement(pl, 2);
1825 if (!elem || !PLIsString(elem)) {
1826 return NULL;
1828 val = PLGetString(elem);
1830 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1831 wwarning(_("\"%s\" is not a valid color name"), val);
1832 return NULL;
1835 /* file name */
1836 elem = PLGetArrayElement(pl, 1);
1837 if (!elem || !PLIsString(elem))
1838 return NULL;
1839 val = PLGetString(elem);
1841 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1842 } else if (strcasecmp(val, "thgradient")==0
1843 || strcasecmp(val, "tvgradient")==0
1844 || strcasecmp(val, "tdgradient")==0) {
1845 RColor color1, color2;
1846 XColor xcolor;
1847 int opacity;
1848 int style;
1850 if (val[1]=='h' || val[1]=='H')
1851 style = WTEX_THGRADIENT;
1852 else if (val[1]=='v' || val[1]=='V')
1853 style = WTEX_TVGRADIENT;
1854 else
1855 style = WTEX_TDGRADIENT;
1857 if (nelem != 5) {
1858 wwarning(_("bad number of arguments in textured gradient specification"));
1859 return NULL;
1862 /* get from color */
1863 elem = PLGetArrayElement(pl, 3);
1864 if (!elem || !PLIsString(elem))
1865 return NULL;
1866 val = PLGetString(elem);
1868 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1869 wwarning(_("\"%s\" is not a valid color name"), val);
1870 return NULL;
1872 color1.alpha = 255;
1873 color1.red = xcolor.red >> 8;
1874 color1.green = xcolor.green >> 8;
1875 color1.blue = xcolor.blue >> 8;
1877 /* get to color */
1878 elem = PLGetArrayElement(pl, 4);
1879 if (!elem || !PLIsString(elem)) {
1880 return NULL;
1882 val = PLGetString(elem);
1884 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1885 wwarning(_("\"%s\" is not a valid color name"), val);
1886 return NULL;
1888 color2.alpha = 255;
1889 color2.red = xcolor.red >> 8;
1890 color2.green = xcolor.green >> 8;
1891 color2.blue = xcolor.blue >> 8;
1893 /* get opacity */
1894 elem = PLGetArrayElement(pl, 2);
1895 if (!elem || !PLIsString(elem))
1896 opacity = 128;
1897 else
1898 val = PLGetString(elem);
1900 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1901 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1902 opacity = 128;
1905 /* get file name */
1906 elem = PLGetArrayElement(pl, 1);
1907 if (!elem || !PLIsString(elem))
1908 return NULL;
1909 val = PLGetString(elem);
1911 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1912 val, opacity);
1914 #ifdef TEXTURE_PLUGIN
1915 else if (strcasecmp(val, "function")==0) {
1916 WTexFunction *function;
1917 void (*initFunc) (Display *, Colormap);
1918 char *lib, *func, **argv;
1919 int i, argc;
1921 if (nelem < 3)
1922 return NULL;
1924 /* get the library name */
1925 elem = PLGetArrayElement(pl, 1);
1926 if (!elem || !PLIsString(elem)) {
1927 return NULL;
1929 lib = PLGetString(elem);
1931 /* get the function name */
1932 elem = PLGetArrayElement(pl, 2);
1933 if (!elem || !PLIsString(elem)) {
1934 return NULL;
1936 func = PLGetString(elem);
1938 argc = nelem - 2;
1939 argv = (char **)wmalloc(argc * sizeof(char *));
1941 /* get the parameters */
1942 argv[0] = wstrdup(func);
1943 for (i = 0; i < argc - 1; i++) {
1944 elem = PLGetArrayElement(pl, 3 + i);
1945 if (!elem || !PLIsString(elem)) {
1946 free(argv);
1948 return NULL;
1950 argv[i+1] = wstrdup(PLGetString(elem));
1953 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1955 #ifdef HAVE_DLFCN_H
1956 if (function) {
1957 initFunc = dlsym(function->handle, "initWindowMaker");
1958 if (initFunc) {
1959 initFunc(dpy, scr->w_colormap);
1960 } else {
1961 wwarning(_("could not initialize library %s"), lib);
1963 } else {
1964 wwarning(_("could not find function %s::%s"), lib, func);
1966 #endif /* HAVE_DLFCN_H */
1967 texture = (WTexture*)function;
1969 #endif /* TEXTURE_PLUGIN */
1970 else {
1971 wwarning(_("invalid texture type %s"), val);
1972 return NULL;
1974 return texture;
1979 static int
1980 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1981 void **ret)
1983 static WTexture *texture;
1984 int changed=0;
1986 again:
1987 if (!PLIsArray(value)) {
1988 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1989 entry->key, "Texture");
1990 if (changed==0) {
1991 value = entry->plvalue;
1992 changed = 1;
1993 wwarning(_("using default \"%s\" instead"), entry->default_value);
1994 goto again;
1996 return False;
1999 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2000 proplist_t pl;
2002 pl = PLGetArrayElement(value, 0);
2003 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2004 || strcasecmp(PLGetString(pl), "solid")!=0) {
2005 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2006 entry->key, "Solid Texture");
2008 value = entry->plvalue;
2009 changed = 1;
2010 wwarning(_("using default \"%s\" instead"), entry->default_value);
2011 goto again;
2015 texture = parse_texture(scr, value);
2017 if (!texture) {
2018 wwarning(_("Error in texture specification for key \"%s\""),
2019 entry->key);
2020 if (changed==0) {
2021 value = entry->plvalue;
2022 changed = 1;
2023 wwarning(_("using default \"%s\" instead"), entry->default_value);
2024 goto again;
2026 return False;
2029 if (ret)
2030 *ret = &texture;
2032 if (addr)
2033 *(WTexture**)addr = texture;
2035 return True;
2040 #ifdef DRAWSTRING_PLUGIN
2041 static int
2042 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2043 void *addr, void **ret)
2045 proplist_t elem;
2046 char *val, *lib, *func, **argv;
2047 int argc, changed;
2049 if (strcmp(entry->key, "FTitleColor")==0) {
2050 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2051 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2052 } else if (strcmp(entry->key, "UTitleColor")==0) {
2053 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2054 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2055 } else if (strcmp(entry->key, "PTitleColor")==0) {
2056 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2057 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2058 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2059 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2060 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2061 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2062 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2063 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2066 if (PLIsArray(value)) {
2067 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2068 argc -= 2;
2069 argv = (char **)wmalloc(argc * sizeof(char *));
2071 elem = PLGetArrayElement(value,0);
2072 if (!elem || !PLIsString(elem)) return False;
2073 val = PLGetString(elem);
2074 if (strcasecmp(val, "function")==0) {
2075 elem = PLGetArrayElement(value, 1); /* library name */
2076 if (!elem || !PLIsString(elem)) return False;
2077 lib = PLGetString(elem);
2078 elem = PLGetArrayElement(value, 2); /* function name */
2079 if (!elem || !PLIsString(elem)) return False;
2080 func = PLGetString(elem);
2081 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2082 lib, "initDrawString", func, NULL, value,
2083 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2086 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2087 } else if (PLIsString(value)) {
2088 return getColor(scr, entry, value, addr, ret);
2091 return False;
2093 #endif /* DRAWSTRING_PLUGIN */
2097 static int
2098 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2099 void *addr, void **ret)
2101 proplist_t elem;
2102 int changed = 0;
2103 char *val;
2104 int nelem;
2106 again:
2107 if (!PLIsArray(value)) {
2108 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2109 "WorkspaceBack", "Texture or None");
2110 if (changed==0) {
2111 value = entry->plvalue;
2112 changed = 1;
2113 wwarning(_("using default \"%s\" instead"), entry->default_value);
2114 goto again;
2116 return False;
2119 /* only do basic error checking and verify for None texture */
2121 nelem = PLGetNumberOfElements(value);
2122 if (nelem > 0) {
2123 elem = PLGetArrayElement(value, 0);
2124 if (!elem || !PLIsString(elem)) {
2125 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2126 if (changed==0) {
2127 value = entry->plvalue;
2128 changed = 1;
2129 wwarning(_("using default \"%s\" instead"), entry->default_value);
2130 goto again;
2132 return False;
2134 val = PLGetString(elem);
2136 if (strcasecmp(val, "None")==0)
2137 return True;
2139 *ret = PLRetain(value);
2141 return True;
2145 static int
2146 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2147 void *addr, void **ret)
2149 proplist_t elem;
2150 int nelem;
2151 int changed = 0;
2153 again:
2154 if (!PLIsArray(value)) {
2155 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2156 "WorkspaceSpecificBack", "an array of textures");
2157 if (changed==0) {
2158 value = entry->plvalue;
2159 changed = 1;
2160 wwarning(_("using default \"%s\" instead"), entry->default_value);
2161 goto again;
2163 return False;
2166 /* only do basic error checking and verify for None texture */
2168 nelem = PLGetNumberOfElements(value);
2169 if (nelem > 0) {
2170 while (nelem--) {
2171 elem = PLGetArrayElement(value, nelem);
2172 if (!elem || !PLIsArray(elem)) {
2173 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2174 nelem);
2179 *ret = PLRetain(value);
2181 #ifdef notworking
2183 * Kluge to force wmsetbg helper to set the default background.
2184 * If the WorkspaceSpecificBack is changed once wmaker has started,
2185 * the WorkspaceBack won't be sent to the helper, unless the user
2186 * changes it's value too. So, we must force this by removing the
2187 * value from the defaults DB.
2189 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2190 proplist_t key = PLMakeString("WorkspaceBack");
2192 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2194 PLRelease(key);
2196 #endif
2197 return True;
2201 static int
2202 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2203 void **ret)
2205 static WMFont *font;
2206 char *val;
2208 GET_STRING_OR_DEFAULT("Font", val);
2210 font = WMCreateFont(scr->wmscreen, val);
2211 if (!font)
2212 font = WMCreateFont(scr->wmscreen, "fixed");
2214 if (!font) {
2215 wfatal(_("could not load any usable font!!!"));
2216 exit(1);
2219 if (ret)
2220 *ret = font;
2222 /* can't assign font value outside update function */
2223 wassertrv(addr == NULL, True);
2225 return True;
2229 static int
2230 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2231 void **ret)
2233 static XColor color;
2234 char *val;
2235 int second_pass=0;
2237 GET_STRING_OR_DEFAULT("Color", val);
2240 again:
2241 if (!wGetColor(scr, val, &color)) {
2242 wwarning(_("could not get color for key \"%s\""),
2243 entry->key);
2244 if (second_pass==0) {
2245 val = PLGetString(entry->plvalue);
2246 second_pass = 1;
2247 wwarning(_("using default \"%s\" instead"), val);
2248 goto again;
2250 return False;
2253 if (ret)
2254 *ret = &color;
2256 assert(addr==NULL);
2258 if (addr)
2259 *(unsigned long*)addr = pixel;
2262 return True;
2267 static int
2268 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2269 void **ret)
2271 static WShortKey shortcut;
2272 KeySym ksym;
2273 char *val;
2274 char *k;
2275 char buf[128], *b;
2278 GET_STRING_OR_DEFAULT("Key spec", val);
2280 if (!val || strcasecmp(val, "NONE")==0) {
2281 shortcut.keycode = 0;
2282 shortcut.modifier = 0;
2283 if (ret)
2284 *ret = &shortcut;
2285 return True;
2288 strcpy(buf, val);
2290 b = (char*)buf;
2292 /* get modifiers */
2293 shortcut.modifier = 0;
2294 while ((k = strchr(b, '+'))!=NULL) {
2295 int mod;
2297 *k = 0;
2298 mod = wXModifierFromKey(b);
2299 if (mod<0) {
2300 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2301 return False;
2303 shortcut.modifier |= mod;
2305 b = k+1;
2308 /* get key */
2309 ksym = XStringToKeysym(b);
2311 if (ksym==NoSymbol) {
2312 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2313 val);
2314 return False;
2317 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2318 if (shortcut.keycode==0) {
2319 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2320 return False;
2323 if (ret)
2324 *ret = &shortcut;
2326 return True;
2330 static int
2331 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2332 void **ret)
2334 static unsigned int mask;
2335 char *str;
2337 GET_STRING_OR_DEFAULT("Modifier Key", str);
2339 if (!str)
2340 return False;
2342 mask = wXModifierFromKey(str);
2343 if (mask < 0) {
2344 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2345 mask = 0;
2346 return False;
2349 if (addr)
2350 *(unsigned int*)addr = mask;
2352 if (ret)
2353 *ret = &mask;
2355 return True;
2359 #ifdef NEWSTUFF
2360 static int
2361 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2362 void *addr, void **ret)
2364 unsigned int mask;
2365 char *str;
2366 RImage *image;
2367 int i, n;
2368 int w, h;
2370 GET_STRING_OR_DEFAULT("Image File Path", str);
2371 if (!str)
2372 return False;
2374 image = RLoadImage(scr->rcontext, str, 0);
2375 if (!image) {
2376 wwarning(_("could not load image in option %s: %s"), entry->key,
2377 RMessageForError(RErrorCode));
2378 return False;
2381 if (*(RImage**)addr) {
2382 RDestroyImage(*(RImage**)addr);
2384 if (addr)
2385 *(RImage**)addr = image;
2387 assert(ret == NULL);
2389 if (ret)
2390 *(RImage**)ret = image;
2393 return True;
2395 #endif
2398 /* ---------------- value setting functions --------------- */
2399 static int
2400 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2402 return REFRESH_WINDOW_TITLE_COLOR;
2406 static int
2407 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2409 switch (which) {
2410 case WM_DOCK:
2411 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2412 break;
2413 case WM_CLIP:
2414 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2415 break;
2416 default:
2417 break;
2419 return 0;
2423 static int
2424 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2426 if (scr->workspaces) {
2427 wWorkspaceForceChange(scr, scr->current_workspace);
2428 wArrangeIcons(scr, False);
2430 return 0;
2433 #if not_used
2434 static int
2435 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2437 if (*value <= 0)
2438 *(int*)foo = 1;
2440 return 0;
2442 #endif
2446 static int
2447 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2449 Pixmap pixmap;
2450 RImage *img;
2451 int reset = 0;
2453 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2454 wPreferences.icon_size,
2455 ((*texture)->any.type & WREL_BORDER_MASK)
2456 ? WREL_ICON : WREL_FLAT);
2457 if (!img) {
2458 wwarning(_("could not render texture for icon background"));
2459 if (!entry->addr)
2460 wTextureDestroy(scr, *texture);
2461 return 0;
2463 RConvertImage(scr->rcontext, img, &pixmap);
2465 if (scr->icon_tile) {
2466 reset = 1;
2467 RDestroyImage(scr->icon_tile);
2468 XFreePixmap(dpy, scr->icon_tile_pixmap);
2471 scr->icon_tile = img;
2473 if (!wPreferences.flags.noclip) {
2474 if (scr->clip_tile) {
2475 RDestroyImage(scr->clip_tile);
2477 scr->clip_tile = wClipMakeTile(scr, img);
2480 scr->icon_tile_pixmap = pixmap;
2482 if (scr->def_icon_pixmap) {
2483 XFreePixmap(dpy, scr->def_icon_pixmap);
2484 scr->def_icon_pixmap = None;
2486 if (scr->def_ticon_pixmap) {
2487 XFreePixmap(dpy, scr->def_ticon_pixmap);
2488 scr->def_ticon_pixmap = None;
2491 if (scr->icon_back_texture) {
2492 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2494 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2496 if (scr->clip_balloon)
2497 XSetWindowBackground(dpy, scr->clip_balloon,
2498 (*texture)->any.color.pixel);
2501 * Free the texture as nobody else will use it, nor refer to it.
2503 if (!entry->addr)
2504 wTextureDestroy(scr, *texture);
2506 return (reset ? REFRESH_ICON_TILE : 0);
2511 static int
2512 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2514 if (scr->title_font) {
2515 WMReleaseFont(scr->title_font);
2517 scr->title_font = font;
2519 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2523 static int
2524 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2526 if (scr->menu_title_font) {
2527 WMReleaseFont(scr->menu_title_font);
2530 scr->menu_title_font = font;
2532 return REFRESH_MENU_TITLE_FONT;
2536 static int
2537 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2539 if (scr->menu_entry_font) {
2540 WMReleaseFont(scr->menu_entry_font);
2542 scr->menu_entry_font = font;
2544 return REFRESH_MENU_FONT;
2549 static int
2550 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2552 if (scr->icon_title_font) {
2553 WMReleaseFont(scr->icon_title_font);
2556 scr->icon_title_font = font;
2558 return REFRESH_ICON_FONT;
2562 static int
2563 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2565 if (scr->clip_title_font) {
2566 WMReleaseFont(scr->clip_title_font);
2569 scr->clip_title_font = font;
2571 return REFRESH_ICON_FONT;
2575 static int
2576 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2578 if (scr->workspace_name_font) {
2579 WMReleaseFont(scr->workspace_name_font);
2582 scr->workspace_name_font = font;
2584 return 0;
2588 static int
2589 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2591 if (scr->select_pixel!=scr->white_pixel &&
2592 scr->select_pixel!=scr->black_pixel) {
2593 wFreeColor(scr, scr->select_pixel);
2596 scr->select_pixel = color->pixel;
2598 return REFRESH_MENU_COLOR;
2602 static int
2603 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2605 if (scr->select_text_pixel!=scr->white_pixel &&
2606 scr->select_text_pixel!=scr->black_pixel) {
2607 wFreeColor(scr, scr->select_text_pixel);
2610 scr->select_text_pixel = color->pixel;
2612 return REFRESH_MENU_COLOR;
2616 static int
2617 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2619 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2620 scr->clip_title_pixel[index]!=scr->black_pixel) {
2621 wFreeColor(scr, scr->clip_title_pixel[index]);
2623 scr->clip_title_pixel[index] = color->pixel;
2625 #ifdef GRADIENT_CLIP_ARROW
2626 if (index == CLIP_NORMAL) {
2627 RImage *image;
2628 RColor color1, color2;
2629 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2630 int as = pt - 15; /* 15 = 5+5+5 */
2632 FREE_PIXMAP(scr->clip_arrow_gradient);
2634 color1.red = (color->red >> 8)*6/10;
2635 color1.green = (color->green >> 8)*6/10;
2636 color1.blue = (color->blue >> 8)*6/10;
2638 color2.red = WMIN((color->red >> 8)*20/10, 255);
2639 color2.green = WMIN((color->green >> 8)*20/10, 255);
2640 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2642 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2643 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2644 RDestroyImage(image);
2646 #endif /* GRADIENT_CLIP_ARROW */
2648 return REFRESH_ICON_TITLE_COLOR;
2652 static int
2653 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2655 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2656 scr->window_title_pixel[index]!=scr->black_pixel) {
2657 wFreeColor(scr, scr->window_title_pixel[index]);
2660 scr->window_title_pixel[index] = color->pixel;
2662 if (index == WS_UNFOCUSED)
2663 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2665 return REFRESH_WINDOW_TITLE_COLOR;
2669 static int
2670 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2672 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2673 scr->menu_title_pixel[0]!=scr->black_pixel) {
2674 #ifdef DRAWSTRING_PLUGIN
2675 if(!scr->drawstring_func[W_STRING_MTITLE])
2676 #endif
2677 wFreeColor(scr, scr->menu_title_pixel[0]);
2680 scr->menu_title_pixel[0] = color->pixel;
2681 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2683 return REFRESH_MENU_TITLE_COLOR;
2687 static int
2688 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2690 XGCValues gcv;
2691 #define gcm (GCForeground|GCBackground|GCFillStyle)
2693 if (scr->mtext_pixel!=scr->white_pixel &&
2694 scr->mtext_pixel!=scr->black_pixel) {
2695 wFreeColor(scr, scr->mtext_pixel);
2698 scr->mtext_pixel = color->pixel;
2700 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2703 if (scr->dtext_pixel == scr->mtext_pixel) {
2704 gcv.foreground = scr->white_pixel;
2705 gcv.background = scr->black_pixel;
2706 gcv.fill_style = FillStippled;
2707 } else {
2708 gcv.foreground = scr->dtext_pixel;
2709 gcv.fill_style = FillSolid;
2711 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2713 return REFRESH_MENU_COLOR;
2714 #undef gcm
2718 static int
2719 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2721 XGCValues gcv;
2722 #define gcm (GCForeground|GCBackground|GCFillStyle)
2724 if (scr->dtext_pixel!=scr->white_pixel &&
2725 scr->dtext_pixel!=scr->black_pixel) {
2726 wFreeColor(scr, scr->dtext_pixel);
2729 scr->dtext_pixel = color->pixel;
2731 if (scr->dtext_pixel == scr->mtext_pixel) {
2732 gcv.foreground = scr->white_pixel;
2733 gcv.background = scr->black_pixel;
2734 gcv.fill_style = FillStippled;
2735 } else {
2736 gcv.foreground = scr->dtext_pixel;
2737 gcv.fill_style = FillSolid;
2739 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2741 return REFRESH_MENU_COLOR;
2742 #undef gcm
2745 static int
2746 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2748 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2750 return REFRESH_ICON_TITLE_COLOR;
2754 static int
2755 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2757 if (scr->icon_title_texture) {
2758 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2760 XQueryColor (dpy, scr->w_colormap, color);
2761 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2763 return REFRESH_ICON_TITLE_BACK;
2767 static void
2768 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2770 close(scr->helper_fd);
2771 scr->helper_fd = 0;
2772 scr->helper_pid = 0;
2773 scr->flags.backimage_helper_launched = 0;
2777 static int
2778 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2779 void *bar)
2781 int i;
2782 proplist_t val;
2783 char *str;
2785 if (scr->flags.backimage_helper_launched) {
2786 if (PLGetNumberOfElements(value)==0) {
2787 SendHelperMessage(scr, 'C', 0, NULL);
2788 SendHelperMessage(scr, 'K', 0, NULL);
2790 PLRelease(value);
2791 return 0;
2793 } else {
2794 pid_t pid;
2795 int filedes[2];
2797 if (PLGetNumberOfElements(value) == 0)
2798 return 0;
2800 if (pipe(filedes) < 0) {
2801 wsyserror("pipe() failed:can't set workspace specific background image");
2803 PLRelease(value);
2804 return 0;
2807 pid = fork();
2808 if (pid < 0) {
2809 wsyserror("fork() failed:can't set workspace specific background image");
2810 if (close(filedes[0]) < 0)
2811 wsyserror("could not close pipe");
2812 if (close(filedes[1]) < 0)
2813 wsyserror("could not close pipe");
2815 } else if (pid == 0) {
2816 SetupEnvironment(scr);
2818 if (close(0) < 0)
2819 wsyserror("could not close pipe");
2820 if (dup(filedes[0]) < 0) {
2821 wsyserror("dup() failed:can't set workspace specific background image");
2823 if (wPreferences.smooth_workspace_back)
2824 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
2825 else
2826 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2827 wsyserror("could not execute wmsetbg");
2828 exit(1);
2829 } else {
2831 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2832 wsyserror("error setting close-on-exec flag");
2834 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2835 wsyserror("error setting close-on-exec flag");
2838 scr->helper_fd = filedes[1];
2839 scr->helper_pid = pid;
2840 scr->flags.backimage_helper_launched = 1;
2842 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2844 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2849 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2850 val = PLGetArrayElement(value, i);
2851 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2852 str = PLGetDescription(val);
2854 SendHelperMessage(scr, 'S', i+1, str);
2856 free(str);
2857 } else {
2858 SendHelperMessage(scr, 'U', i+1, NULL);
2861 sleep(1);
2863 PLRelease(value);
2864 return 0;
2868 static int
2869 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2870 void *bar)
2872 if (scr->flags.backimage_helper_launched) {
2873 char *str;
2875 if (PLGetNumberOfElements(value)==0) {
2876 SendHelperMessage(scr, 'U', 0, NULL);
2877 } else {
2878 /* set the default workspace background to this one */
2879 str = PLGetDescription(value);
2880 if (str) {
2881 SendHelperMessage(scr, 'S', 0, str);
2882 free(str);
2883 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2884 } else {
2885 SendHelperMessage(scr, 'U', 0, NULL);
2888 } else {
2889 char *command;
2890 char *text;
2892 SetupEnvironment(scr);
2893 text = PLGetDescription(value);
2894 command = wmalloc(strlen(text)+40);
2895 if (wPreferences.smooth_workspace_back)
2896 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
2897 else
2898 sprintf(command, "wmsetbg -d -p '%s' &", text);
2899 free(text);
2900 system(command);
2901 free(command);
2903 PLRelease(value);
2905 return 0;
2909 static int
2910 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2912 if (scr->widget_texture) {
2913 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2915 scr->widget_texture = *(WTexSolid**)texture;
2917 return 0;
2921 static int
2922 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2924 if (scr->window_title_texture[WS_FOCUSED]) {
2925 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2927 scr->window_title_texture[WS_FOCUSED] = *texture;
2929 return REFRESH_WINDOW_TEXTURES;
2933 static int
2934 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2936 if (scr->window_title_texture[WS_PFOCUSED]) {
2937 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2939 scr->window_title_texture[WS_PFOCUSED] = *texture;
2941 return REFRESH_WINDOW_TEXTURES;
2945 static int
2946 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2948 if (scr->window_title_texture[WS_UNFOCUSED]) {
2949 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2951 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2953 return REFRESH_WINDOW_TEXTURES;
2957 static int
2958 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2960 if (scr->resizebar_texture[0]) {
2961 wTextureDestroy(scr, scr->resizebar_texture[0]);
2963 scr->resizebar_texture[0] = *texture;
2965 return REFRESH_WINDOW_TEXTURES;
2969 static int
2970 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2972 if (scr->menu_title_texture[0]) {
2973 wTextureDestroy(scr, scr->menu_title_texture[0]);
2975 scr->menu_title_texture[0] = *texture;
2977 return REFRESH_MENU_TITLE_TEXTURE;
2981 static int
2982 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2984 if (scr->menu_item_texture) {
2985 wTextureDestroy(scr, scr->menu_item_texture);
2986 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2988 scr->menu_item_texture = *texture;
2990 scr->menu_item_auxtexture
2991 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2993 return REFRESH_MENU_TEXTURE;
2997 static int
2998 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3000 WWindow *wwin;
3001 wKeyBindings[index] = *shortcut;
3003 wwin = scr->focused_window;
3005 while (wwin!=NULL) {
3006 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3008 if (!WFLAGP(wwin, no_bind_keys)) {
3009 wWindowSetKeyGrabs(wwin);
3011 wwin = wwin->prev;
3014 return 0;
3018 static int
3019 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3021 wArrangeIcons(scr, True);
3023 return 0;
3027 static int
3028 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3030 wScreenUpdateUsableArea(scr);
3032 return 0;
3036 static int
3037 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3039 return REFRESH_MENU_TEXTURE;
3044 static int
3045 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3047 return REFRESH_BUTTON_IMAGES;
3052 * Very ugly kluge.
3053 * Need access to the double click variables, so that all widgets in
3054 * wmaker panels will have the same dbl-click values.
3055 * TODO: figure a better way of dealing with it.
3057 #include "WINGsP.h"
3059 static int
3060 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3062 extern _WINGsConfiguration WINGsConfiguration;
3064 if (*value <= 0)
3065 *(int*)foo = 1;
3067 WINGsConfiguration.doubleClickDelay = *value;
3069 return 0;
3074 static int
3075 setMultiByte(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3077 extern _WINGsConfiguration WINGsConfiguration;
3079 WINGsConfiguration.useMultiByte = *value;
3081 return 0;