Removed titlebar drop shadow code and add plugin to draw text on titlebars.
[wmaker-crm.git] / src / defaults.c
blob81853612e62b67da1cd230281d98f9c2cefdec05
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 setDisplayFont();
158 static int setLargeDisplayFont();
159 static int setWTitleColor();
160 static int setFTitleBack();
161 static int setPTitleBack();
162 static int setUTitleBack();
163 static int setResizebarBack();
164 static int setWorkspaceBack();
165 static int setWorkspaceSpecificBack();
166 static int setMenuTitleColor();
167 static int setMenuTextColor();
168 static int setMenuDisabledColor();
169 static int setMenuTitleBack();
170 static int setMenuTextBack();
171 static int setHightlight();
172 static int setHightlightText();
173 static int setKeyGrab();
174 static int setDoubleClick();
175 static int setIconPosition();
177 static int setClipTitleFont();
178 static int setClipTitleColor();
180 static int setMenuStyle();
181 static int setMultiByte();
183 static int updateUsableArea();
188 * Tables to convert strings to enumeration values.
189 * Values stored are char
193 /* WARNING: sum of length of all value strings must not exceed
194 * this value */
195 #define TOTAL_VALUES_LENGTH 80
200 #define REFRESH_WINDOW_TEXTURES (1<<0)
201 #define REFRESH_MENU_TEXTURE (1<<1)
202 #define REFRESH_MENU_FONT (1<<2)
203 #define REFRESH_MENU_COLOR (1<<3)
204 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
205 #define REFRESH_MENU_TITLE_FONT (1<<5)
206 #define REFRESH_MENU_TITLE_COLOR (1<<6)
207 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
208 #define REFRESH_WINDOW_FONT (1<<8)
209 #define REFRESH_ICON_TILE (1<<9)
210 #define REFRESH_ICON_FONT (1<<10)
211 #define REFRESH_WORKSPACE_BACK (1<<11)
213 #define REFRESH_BUTTON_IMAGES (1<<12)
215 #define REFRESH_ICON_TITLE_COLOR (1<<13)
216 #define REFRESH_ICON_TITLE_BACK (1<<14)
220 static WOptionEnumeration seFocusModes[] = {
221 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
222 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
223 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
224 {NULL, 0, 0}
227 static WOptionEnumeration seColormapModes[] = {
228 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
229 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
230 {NULL, 0, 0}
233 static WOptionEnumeration sePlacements[] = {
234 {"Auto", WPM_SMART, 0}, {"Smart", WPM_SMART, 1},
235 {"Cascade", WPM_CASCADE, 0},
236 {"Random", WPM_RANDOM, 0},
237 {"Manual", WPM_MANUAL, 0},
238 {NULL, 0, 0}
241 static WOptionEnumeration seGeomDisplays[] = {
242 {"Center", WDIS_CENTER, 0},
243 {"Corner", WDIS_TOPLEFT, 0},
244 {"Floating", WDIS_FRAME_CENTER, 0},
245 {"Line", WDIS_NEW, 0},
246 {NULL, 0, 0}
249 static WOptionEnumeration seSpeeds[] = {
250 {"UltraFast", SPEED_ULTRAFAST, 0},
251 {"Fast", SPEED_FAST, 0},
252 {"Medium", SPEED_MEDIUM, 0},
253 {"Slow", SPEED_SLOW, 0},
254 {"UltraSlow", SPEED_ULTRASLOW, 0},
255 {NULL, 0, 0}
258 static WOptionEnumeration seMouseButtons[] = {
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 {"StickyIcons", "NO", NULL,
413 &wPreferences.sticky_icons, getBool, setStickyIcons
415 {"SaveSessionOnExit", "NO", NULL,
416 &wPreferences.save_session_on_exit, getBool, NULL
418 {"WrapMenus", "NO", NULL,
419 &wPreferences.wrap_menus, getBool, NULL
421 {"ScrollableMenus", "NO", NULL,
422 &wPreferences.scrollable_menus, getBool, NULL
424 {"MenuScrollSpeed", "medium", seSpeeds,
425 &wPreferences.menu_scroll_speed, getEnum, NULL
427 {"IconSlideSpeed", "medium", seSpeeds,
428 &wPreferences.icon_slide_speed, getEnum, NULL
430 {"ShadeSpeed", "medium", seSpeeds,
431 &wPreferences.shade_speed, getEnum, NULL
433 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
434 &wPreferences.dblclick_time, getInt, setDoubleClick,
436 {"AlignSubmenus", "NO", NULL,
437 &wPreferences.align_menus, getBool, NULL
439 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
440 &wPreferences.open_transients_with_parent, getBool, NULL
442 {"WindowPlacement", "auto", sePlacements,
443 &wPreferences.window_placement, getEnum, NULL
445 {"IgnoreFocusClick","NO", NULL,
446 &wPreferences.ignore_focus_click, getBool, NULL
448 {"UseSaveUnders", "NO", NULL,
449 &wPreferences.use_saveunders, getBool, NULL
451 {"OpaqueMove", "NO", NULL,
452 &wPreferences.opaque_move, getBool, NULL
454 {"DisableSound", "NO", NULL,
455 &wPreferences.no_sound, getBool, NULL
457 {"DisableAnimations", "NO", NULL,
458 &wPreferences.no_animations, getBool, NULL
460 {"DontLinkWorkspaces","NO", NULL,
461 &wPreferences.no_autowrap, getBool, NULL
463 {"AutoArrangeIcons", "NO", NULL,
464 &wPreferences.auto_arrange_icons, getBool, NULL
466 {"NoWindowOverDock", "NO", NULL,
467 &wPreferences.no_window_over_dock, getBool, updateUsableArea
469 {"NoWindowOverIcons", "NO", NULL,
470 &wPreferences.no_window_over_icons, getBool, updateUsableArea
472 {"WindowPlaceOrigin", "(0, 0)", NULL,
473 &wPreferences.window_place_origin, getCoord, NULL
475 {"ResizeDisplay", "corner", seGeomDisplays,
476 &wPreferences.size_display, getEnum, NULL
478 {"MoveDisplay", "corner", seGeomDisplays,
479 &wPreferences.move_display, getEnum, NULL
481 {"DontConfirmKill", "NO", NULL,
482 &wPreferences.dont_confirm_kill, getBool,NULL
484 {"WindowTitleBalloons", "NO", NULL,
485 &wPreferences.window_balloon, getBool, NULL
487 {"MiniwindowTitleBalloons", "NO", NULL,
488 &wPreferences.miniwin_balloon,getBool, NULL
490 {"AppIconBalloons", "NO", NULL,
491 &wPreferences.appicon_balloon,getBool, NULL
493 {"HelpBalloons", "NO", NULL,
494 &wPreferences.help_balloon, getBool, NULL
496 {"EdgeResistance", "30", NULL,
497 &wPreferences.edge_resistance,getInt, NULL
499 {"Attraction", "NO", NULL,
500 &wPreferences.attract, getBool, NULL
502 {"DisableBlinking", "NO", NULL,
503 &wPreferences.dont_blink, getBool, NULL
505 #ifdef WEENDOZE_CYCLE
506 {"WindozeCycling","NO", NULL,
507 &wPreferences.windoze_cycling, getBool, NULL
509 {"PopupSwitchMenu","YES", NULL,
510 &wPreferences.popup_switchmenu, getBool, NULL
512 #endif /* WEENDOZE_CYCLE */
513 /* style options */
514 {"MenuStyle", "normal", seMenuStyles,
515 &wPreferences.menu_style, getEnum, setMenuStyle
517 {"WidgetColor", "(solid, gray)", NULL,
518 NULL, getTexture, setWidgetColor,
520 {"WorkspaceSpecificBack","()", NULL,
521 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
523 /* WorkspaceBack must come after WorkspaceSpecificBack or
524 * WorkspaceBack wont know WorkspaceSpecificBack was also
525 * specified and 2 copies of wmsetbg will be launched */
526 {"WorkspaceBack", "(solid, black)", NULL,
527 NULL, getWSBackground,setWorkspaceBack
529 {"SmoothWorkspaceBack", "NO", NULL,
530 NULL, getBool, NULL
532 {"IconBack", "(solid, gray)", NULL,
533 NULL, getTexture, setIconTile
535 {"TitleJustify", "center", seJustifications,
536 &wPreferences.title_justification, getEnum, setJustify
538 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
539 NULL, getFont, setWinTitleFont,
541 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
542 NULL, getFont, setMenuTitleFont
544 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
545 NULL, getFont, setMenuTextFont
547 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
548 NULL, getFont, setIconTitleFont
550 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
551 NULL, getFont, setClipTitleFont
553 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
554 NULL, getFont, setDisplayFont
556 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
557 NULL, getFont, setLargeDisplayFont
559 {"HighlightColor", "white", NULL,
560 NULL, getColor, setHightlight
562 {"HighlightTextColor", "black", NULL,
563 NULL, getColor, setHightlightText
565 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
566 NULL, getColor, setClipTitleColor
568 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
569 NULL, getColor, setClipTitleColor
571 #ifdef DRAWSTRING_PLUGIN
572 {"FTitleColor", "white", (void*)WS_FOCUSED,
573 NULL, getTextRenderer, setWTitleColor
575 {"PTitleColor", "white", (void*)WS_PFOCUSED,
576 NULL, getTextRenderer, setWTitleColor
578 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
579 NULL, getTextRenderer, setWTitleColor
581 #else
582 {"FTitleColor", "white", (void*)WS_FOCUSED,
583 NULL, getColor, setWTitleColor
585 {"PTitleColor", "white", (void*)WS_PFOCUSED,
586 NULL, getColor, setWTitleColor
588 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
589 NULL, getColor, setWTitleColor
591 #endif
592 {"FTitleBack", "(solid, black)", NULL,
593 NULL, getTexture, setFTitleBack
595 {"PTitleBack", "(solid, \"#616161\")", NULL,
596 NULL, getTexture, setPTitleBack
598 {"UTitleBack", "(solid, gray)", NULL,
599 NULL, getTexture, setUTitleBack
601 {"ResizebarBack", "(solid, gray)", NULL,
602 NULL, getTexture, setResizebarBack
604 #ifdef DRAWSTRING_PLUGIN
605 {"MenuTitleColor", "white", NULL,
606 NULL, getTextRenderer, setMenuTitleColor
608 #else
609 {"MenuTitleColor", "white", NULL,
610 NULL, getColor, setMenuTitleColor
612 #endif
613 {"MenuTextColor", "black", NULL,
614 NULL, getColor, setMenuTextColor
616 {"MenuDisabledColor", "\"#616161\"", NULL,
617 NULL, getColor, setMenuDisabledColor
619 {"MenuTitleBack", "(solid, black)", NULL,
620 NULL, getTexture, setMenuTitleBack
622 {"MenuTextBack", "(solid, gray)", NULL,
623 NULL, getTexture, setMenuTextBack
625 {"IconTitleColor", "white", NULL,
626 NULL, getColor, setIconTitleColor
628 {"IconTitleBack", "black", NULL,
629 NULL, getColor, setIconTitleBack
631 /* keybindings */
632 #ifndef LITE
633 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
634 NULL, getKeybind, setKeyGrab
636 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
637 NULL, getKeybind, setKeyGrab
639 #endif /* LITE */
640 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
641 NULL, getKeybind, setKeyGrab
643 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
644 NULL, getKeybind, setKeyGrab
646 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
647 NULL, getKeybind, setKeyGrab
649 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
650 NULL, getKeybind, setKeyGrab
652 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
653 NULL, getKeybind, setKeyGrab
655 {"HideKey", "None", (void*)WKBD_HIDE,
656 NULL, getKeybind, setKeyGrab
658 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
659 NULL, getKeybind, setKeyGrab
661 {"CloseKey", "None", (void*)WKBD_CLOSE,
662 NULL, getKeybind, setKeyGrab
664 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
665 NULL, getKeybind, setKeyGrab
667 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
668 NULL, getKeybind, setKeyGrab
670 {"RaiseKey", "Meta+Up", (void*)WKBD_RAISE,
671 NULL, getKeybind, setKeyGrab
673 {"LowerKey", "Meta+Down", (void*)WKBD_LOWER,
674 NULL, getKeybind, setKeyGrab
676 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
677 NULL, getKeybind, setKeyGrab
679 {"ShadeKey", "None", (void*)WKBD_SHADE,
680 NULL, getKeybind, setKeyGrab
682 {"SelectKey", "None", (void*)WKBD_SELECT,
683 NULL, getKeybind, setKeyGrab
685 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
686 NULL, getKeybind, setKeyGrab
688 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
689 NULL, getKeybind, setKeyGrab
691 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
692 NULL, getKeybind, setKeyGrab
694 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
695 NULL, getKeybind, setKeyGrab
697 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
698 NULL, getKeybind, setKeyGrab
700 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
701 NULL, getKeybind, setKeyGrab
703 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
704 NULL, getKeybind, setKeyGrab
706 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
707 NULL, getKeybind, setKeyGrab
709 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
710 NULL, getKeybind, setKeyGrab
712 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
713 NULL, getKeybind, setKeyGrab
715 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
716 NULL, getKeybind, setKeyGrab
718 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
719 NULL, getKeybind, setKeyGrab
721 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
722 NULL, getKeybind, setKeyGrab
724 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
725 NULL, getKeybind, setKeyGrab
727 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
728 NULL, getKeybind, setKeyGrab
730 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
731 NULL, getKeybind, setKeyGrab
733 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
734 NULL, getKeybind, setKeyGrab
736 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
737 NULL, getKeybind, setKeyGrab
739 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
740 NULL, getKeybind, setKeyGrab
742 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
743 NULL, getKeybind, setKeyGrab
745 #ifdef EXTEND_WINDOWSHORTCUT
746 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
747 NULL, getKeybind, setKeyGrab
749 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
750 NULL, getKeybind, setKeyGrab
752 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
753 NULL, getKeybind, setKeyGrab
755 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
756 NULL, getKeybind, setKeyGrab
758 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
759 NULL, getKeybind, setKeyGrab
761 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
762 NULL, getKeybind, setKeyGrab
764 #endif /* EXTEND_WINDOWSHORTCUT */
766 #ifdef KEEP_XKB_LOCK_STATUS
767 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
768 NULL, getKeybind, setKeyGrab
770 {"KbdModeLock", "NO", NULL,
771 &wPreferences.modelock, getBool, NULL
773 #endif /* KEEP_XKB_LOCK_STATUS */
777 #if 0
778 static void rereadDefaults(void);
779 #endif
781 #if 0
782 static void
783 rereadDefaults(void)
785 /* must defer the update because accessing X data from a
786 * signal handler can mess up Xlib */
789 #endif
791 static void
792 initDefaults()
794 int i;
795 WDefaultEntry *entry;
797 PLSetStringCmpHook(StringCompareHook);
799 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
800 entry = &optionList[i];
802 entry->plkey = PLMakeString(entry->key);
803 if (entry->default_value)
804 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
805 else
806 entry->plvalue = NULL;
809 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
810 entry = &staticOptionList[i];
812 entry->plkey = PLMakeString(entry->key);
813 if (entry->default_value)
814 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
815 else
816 entry->plvalue = NULL;
820 wDomainName = PLMakeString(WMDOMAIN_NAME);
821 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
823 PLRegister(wDomainName, rereadDefaults);
824 PLRegister(wAttributeDomainName, rereadDefaults);
831 #if 0
832 proplist_t
833 wDefaultsInit(int screen_number)
835 static int defaults_inited = 0;
836 proplist_t dict;
838 if (!defaults_inited) {
839 initDefaults();
842 dict = PLGetDomain(wDomainName);
843 if (!dict) {
844 wwarning(_("could not read domain \"%s\" from defaults database"),
845 PLGetString(wDomainName));
848 return dict;
850 #endif
853 void
854 wDefaultsDestroyDomain(WDDomain *domain)
856 if (domain->dictionary)
857 PLRelease(domain->dictionary);
858 free(domain->path);
859 free(domain);
863 WDDomain*
864 wDefaultsInitDomain(char *domain, Bool requireDictionary)
866 WDDomain *db;
867 struct stat stbuf;
868 static int inited = 0;
869 char path[PATH_MAX];
870 char *the_path;
871 proplist_t shared_dict=NULL;
873 if (!inited) {
874 inited = 1;
875 initDefaults();
878 db = wmalloc(sizeof(WDDomain));
879 memset(db, 0, sizeof(WDDomain));
880 db->domain_name = domain;
881 db->path = wdefaultspathfordomain(domain);
882 the_path = db->path;
884 if (the_path && stat(the_path, &stbuf)>=0) {
885 db->dictionary = ReadProplistFromFile(the_path);
886 if (db->dictionary) {
887 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
888 PLRelease(db->dictionary);
889 db->dictionary = NULL;
890 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
891 domain, the_path);
893 db->timestamp = stbuf.st_mtime;
894 } else {
895 wwarning(_("could not load domain %s from user defaults database"),
896 domain);
900 /* global system dictionary */
901 sprintf(path, "%s/%s", SYSCONFDIR, domain);
902 if (stat(path, &stbuf)>=0) {
903 shared_dict = ReadProplistFromFile(path);
904 if (shared_dict) {
905 if (requireDictionary && !PLIsDictionary(shared_dict)) {
906 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
907 domain, path);
908 PLRelease(shared_dict);
909 shared_dict = NULL;
910 } else {
911 if (db->dictionary && PLIsDictionary(shared_dict) &&
912 PLIsDictionary(db->dictionary)) {
913 PLMergeDictionaries(shared_dict, db->dictionary);
914 PLRelease(db->dictionary);
915 db->dictionary = shared_dict;
916 if (stbuf.st_mtime > db->timestamp)
917 db->timestamp = stbuf.st_mtime;
918 } else if (!db->dictionary) {
919 db->dictionary = shared_dict;
920 if (stbuf.st_mtime > db->timestamp)
921 db->timestamp = stbuf.st_mtime;
924 } else {
925 wwarning(_("could not load domain %s from global defaults database"),
926 domain);
930 /* set to save it in user's directory, no matter from where it was read */
931 if (db->dictionary) {
932 proplist_t tmp = PLMakeString(db->path);
934 PLSetFilename(db->dictionary, tmp);
935 PLRelease(tmp);
938 return db;
942 void
943 wReadStaticDefaults(proplist_t dict)
945 proplist_t plvalue;
946 WDefaultEntry *entry;
947 int i;
948 void *tdata;
951 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
952 entry = &staticOptionList[i];
954 if (dict)
955 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
956 else
957 plvalue = NULL;
959 if (!plvalue) {
960 /* no default in the DB. Use builtin default */
961 plvalue = entry->plvalue;
964 if (plvalue) {
965 /* convert data */
966 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
967 if (entry->update) {
968 (*entry->update)(NULL, entry, tdata, entry->extra_data);
975 void
976 wDefaultsCheckDomains(void *foo)
978 WScreen *scr;
979 struct stat stbuf;
980 proplist_t dict;
981 int i;
982 char path[PATH_MAX];
984 #ifdef HEARTBEAT
985 puts("Checking domains...");
986 #endif
987 if (stat(WDWindowMaker->path, &stbuf)>=0
988 && WDWindowMaker->timestamp < stbuf.st_mtime) {
989 proplist_t shared_dict = NULL;
990 #ifdef HEARTBEAT
991 puts("Checking WindowMaker domain");
992 #endif
993 WDWindowMaker->timestamp = stbuf.st_mtime;
995 /* global dictionary */
996 sprintf(path, "%s/WindowMaker", SYSCONFDIR);
997 if (stat(path, &stbuf)>=0) {
998 shared_dict = ReadProplistFromFile(path);
999 if (shared_dict && !PLIsDictionary(shared_dict)) {
1000 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1001 "WindowMaker", path);
1002 PLRelease(shared_dict);
1003 shared_dict = NULL;
1004 } else if (!shared_dict) {
1005 wwarning(_("could not load domain %s from global defaults database"),
1006 "WindowMaker");
1009 /* user dictionary */
1010 dict = ReadProplistFromFile(WDWindowMaker->path);
1011 if (dict) {
1012 if (!PLIsDictionary(dict)) {
1013 PLRelease(dict);
1014 dict = NULL;
1015 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1016 "WindowMaker", WDWindowMaker->path);
1017 } else {
1018 if (shared_dict) {
1019 PLSetFilename(shared_dict, PLGetFilename(dict));
1020 PLMergeDictionaries(shared_dict, dict);
1021 PLRelease(dict);
1022 dict = shared_dict;
1023 shared_dict = NULL;
1025 for (i=0; i<wScreenCount; i++) {
1026 scr = wScreenWithNumber(i);
1027 if (scr)
1028 wReadDefaults(scr, dict);
1030 if (WDWindowMaker->dictionary) {
1031 PLRelease(WDWindowMaker->dictionary);
1033 WDWindowMaker->dictionary = dict;
1035 } else {
1036 wwarning(_("could not load domain %s from user defaults database"),
1037 "WindowMaker");
1039 if (shared_dict) {
1040 PLRelease(shared_dict);
1044 if (stat(WDWindowAttributes->path, &stbuf)>=0
1045 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1046 #ifdef HEARTBEAT
1047 puts("Checking WMWindowAttributes domain");
1048 #endif
1049 dict = ReadProplistFromFile(WDWindowAttributes->path);
1050 if (dict) {
1051 if (!PLIsDictionary(dict)) {
1052 PLRelease(dict);
1053 dict = NULL;
1054 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1055 "WMWindowAttributes", WDWindowAttributes->path);
1056 } else {
1057 if (WDWindowAttributes->dictionary)
1058 PLRelease(WDWindowAttributes->dictionary);
1059 WDWindowAttributes->dictionary = dict;
1060 for (i=0; i<wScreenCount; i++) {
1061 scr = wScreenWithNumber(i);
1062 if (scr)
1063 wDefaultUpdateIcons(scr);
1066 } else {
1067 wwarning(_("could not load domain %s from user defaults database"),
1068 "WMWindowAttributes");
1070 WDWindowAttributes->timestamp = stbuf.st_mtime;
1073 #ifndef LITE
1074 if (stat(WDRootMenu->path, &stbuf)>=0
1075 && WDRootMenu->timestamp < stbuf.st_mtime) {
1076 dict = ReadProplistFromFile(WDRootMenu->path);
1077 #ifdef HEARTBEAT
1078 puts("Checking WMRootMenu domain");
1079 #endif
1080 if (dict) {
1081 if (!PLIsArray(dict) && !PLIsString(dict)) {
1082 PLRelease(dict);
1083 dict = NULL;
1084 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1085 "WMRootMenu", WDRootMenu->path);
1086 } else {
1087 if (WDRootMenu->dictionary) {
1088 PLRelease(WDRootMenu->dictionary);
1090 WDRootMenu->dictionary = dict;
1092 } else {
1093 wwarning(_("could not load domain %s from user defaults database"),
1094 "WMRootMenu");
1096 WDRootMenu->timestamp = stbuf.st_mtime;
1098 #endif /* !LITE */
1100 if (!foo)
1101 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1105 void
1106 wReadDefaults(WScreen *scr, proplist_t new_dict)
1108 proplist_t plvalue, old_value;
1109 WDefaultEntry *entry;
1110 int i, must_update;
1111 int needs_refresh;
1112 void *tdata;
1113 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1114 ? WDWindowMaker->dictionary : NULL);
1116 must_update = 0;
1118 needs_refresh = 0;
1120 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1121 entry = &optionList[i];
1123 if (new_dict)
1124 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1125 else
1126 plvalue = NULL;
1128 if (!old_dict)
1129 old_value = NULL;
1130 else
1131 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1134 if (!plvalue && !old_value) {
1135 /* no default in the DB. Use builtin default */
1136 plvalue = entry->plvalue;
1137 if (plvalue && new_dict) {
1138 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1139 must_update = 1;
1141 } else if (!plvalue) {
1142 /* value was deleted from DB. Keep current value */
1143 continue;
1144 } else if (!old_value) {
1145 /* set value for the 1st time */
1146 } else if (!PLIsEqual(plvalue, old_value)) {
1147 /* value has changed */
1148 } else {
1149 /* value was not changed since last time */
1150 continue;
1153 if (plvalue) {
1154 #ifdef DEBUG
1155 printf("Updating %s to %s\n", entry->key, PLGetDescription(plvalue));
1156 #endif
1157 /* convert data */
1158 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1159 if (entry->update) {
1160 needs_refresh |=
1161 (*entry->update)(scr, entry, tdata, entry->extra_data);
1167 if (needs_refresh!=0 && !scr->flags.startup) {
1168 int foo;
1170 foo = 0;
1171 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1172 foo |= WTextureSettings;
1173 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1174 foo |= WFontSettings;
1175 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1176 foo |= WColorSettings;
1177 if (foo)
1178 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1179 (void*)foo);
1181 foo = 0;
1182 if (needs_refresh & REFRESH_MENU_TEXTURE)
1183 foo |= WTextureSettings;
1184 if (needs_refresh & REFRESH_MENU_FONT)
1185 foo |= WFontSettings;
1186 if (needs_refresh & REFRESH_MENU_COLOR)
1187 foo |= WColorSettings;
1188 if (foo)
1189 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1190 (void*)foo);
1192 foo = 0;
1193 if (needs_refresh & REFRESH_WINDOW_FONT) {
1194 foo |= WFontSettings;
1196 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1197 foo |= WTextureSettings;
1199 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1200 foo |= WColorSettings;
1202 if (foo)
1203 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1204 (void*)foo);
1206 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1207 foo = 0;
1208 if (needs_refresh & REFRESH_ICON_FONT) {
1209 foo |= WFontSettings;
1211 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1212 foo |= WTextureSettings;
1214 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1215 foo |= WTextureSettings;
1217 if (foo)
1218 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1219 (void*)foo);
1221 if (needs_refresh & REFRESH_ICON_TILE)
1222 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1227 void
1228 wDefaultUpdateIcons(WScreen *scr)
1230 WAppIcon *aicon = scr->app_icon_list;
1231 WWindow *wwin = scr->focused_window;
1232 char *file;
1234 while(aicon) {
1235 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1236 False);
1237 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1238 || (file && !aicon->icon->file)) {
1239 RImage *new_image;
1241 if (aicon->icon->file)
1242 free(aicon->icon->file);
1243 aicon->icon->file = wstrdup(file);
1245 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1246 aicon->wm_class);
1247 if (new_image) {
1248 wIconChangeImage(aicon->icon, new_image);
1249 wAppIconPaint(aicon);
1252 aicon = aicon->next;
1255 if (!wPreferences.flags.noclip)
1256 wClipIconPaint(scr->clip_icon);
1258 while (wwin) {
1259 if (wwin->icon && wwin->flags.miniaturized) {
1260 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1261 False);
1262 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1263 || (file && !wwin->icon->file)) {
1264 RImage *new_image;
1266 if (wwin->icon->file)
1267 free(wwin->icon->file);
1268 wwin->icon->file = wstrdup(file);
1270 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1271 wwin->wm_class);
1272 if (new_image)
1273 wIconChangeImage(wwin->icon, new_image);
1276 wwin = wwin->prev;
1281 /* --------------------------- Local ----------------------- */
1283 #define STRINGP(x) if (!PLIsString(value)) { \
1284 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1285 entry->key, x); \
1286 return False; }
1290 static int
1291 string2index(proplist_t key, proplist_t val, proplist_t def,
1292 WOptionEnumeration *values)
1294 char *str;
1295 WOptionEnumeration *v;
1296 char buffer[TOTAL_VALUES_LENGTH];
1298 if (PLIsString(val) && (str = PLGetString(val))) {
1299 for (v=values; v->string!=NULL; v++) {
1300 if (strcasecmp(v->string, str)==0)
1301 return v->value;
1305 buffer[0] = 0;
1306 for (v=values; v->string!=NULL; v++) {
1307 if (!v->is_alias) {
1308 if (buffer[0]!=0)
1309 strcat(buffer, ", ");
1310 strcat(buffer, v->string);
1313 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1314 PLGetString(key), buffer);
1316 if (def) {
1317 return string2index(key, val, NULL, values);
1320 return -1;
1327 * value - is the value in the defaults DB
1328 * addr - is the address to store the data
1329 * ret - is the address to store a pointer to a temporary buffer. ret
1330 * must not be freed and is used by the set functions
1332 static int
1333 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1334 void **ret)
1336 static char data;
1337 char *val;
1338 int second_pass=0;
1340 STRINGP("Boolean");
1342 val = PLGetString(value);
1344 again:
1345 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1346 || strcasecmp(val, "YES")==0) {
1348 data = 1;
1349 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1350 || strcasecmp(val, "NO")==0) {
1351 data = 0;
1352 } else {
1353 int i;
1354 if (sscanf(val, "%i", &i)==1) {
1355 if (i!=0)
1356 data = 1;
1357 else
1358 data = 0;
1359 } else {
1360 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1361 val, entry->key);
1362 if (second_pass==0) {
1363 val = PLGetString(entry->plvalue);
1364 second_pass = 1;
1365 wwarning(_("using default \"%s\" instead"), val);
1366 goto again;
1368 return False;
1372 if (ret)
1373 *ret = &data;
1375 if (addr) {
1376 *(char*)addr = data;
1379 return True;
1383 static int
1384 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1385 void **ret)
1387 static int data;
1388 char *val;
1391 STRINGP("Integer");
1393 val = PLGetString(value);
1395 if (sscanf(val, "%i", &data)!=1) {
1396 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1397 val, entry->key);
1398 val = PLGetString(entry->plvalue);
1399 wwarning(_("using default \"%s\" instead"), val);
1400 if (sscanf(val, "%i", &data)!=1) {
1401 return False;
1405 if (ret)
1406 *ret = &data;
1408 if (addr) {
1409 *(int*)addr = data;
1411 return True;
1415 static int
1416 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1417 void **ret)
1419 static WCoord data;
1420 char *val_x, *val_y;
1421 int nelem, changed=0;
1422 proplist_t elem_x, elem_y;
1424 again:
1425 if (!PLIsArray(value)) {
1426 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1427 entry->key, "Coordinate");
1428 if (changed==0) {
1429 value = entry->plvalue;
1430 changed = 1;
1431 wwarning(_("using default \"%s\" instead"), entry->default_value);
1432 goto again;
1434 return False;
1437 nelem = PLGetNumberOfElements(value);
1438 if (nelem != 2) {
1439 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1440 entry->key);
1441 if (changed==0) {
1442 value = entry->plvalue;
1443 changed = 1;
1444 wwarning(_("using default \"%s\" instead"), entry->default_value);
1445 goto again;
1447 return False;
1450 elem_x = PLGetArrayElement(value, 0);
1451 elem_y = PLGetArrayElement(value, 1);
1453 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1454 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1455 entry->key);
1456 if (changed==0) {
1457 value = entry->plvalue;
1458 changed = 1;
1459 wwarning(_("using default \"%s\" instead"), entry->default_value);
1460 goto again;
1462 return False;
1465 val_x = PLGetString(elem_x);
1466 val_y = PLGetString(elem_y);
1468 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1469 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1470 if (changed==0) {
1471 value = entry->plvalue;
1472 changed = 1;
1473 wwarning(_("using default \"%s\" instead"), entry->default_value);
1474 goto again;
1476 return False;
1479 if (data.x < 0)
1480 data.x = 0;
1481 else if (data.x > scr->scr_width/3)
1482 data.x = scr->scr_width/3;
1483 if (data.y < 0)
1484 data.y = 0;
1485 else if (data.y > scr->scr_height/3)
1486 data.y = scr->scr_height/3;
1488 if (ret)
1489 *ret = &data;
1491 if (addr) {
1492 *(WCoord*)addr = data;
1495 return True;
1499 #if 0
1500 /* This function is not used at the moment. */
1501 static int
1502 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1503 void **ret)
1505 static char *data;
1507 STRINGP("String");
1509 data = PLGetString(value);
1511 if (!data) {
1512 data = PLGetString(entry->plvalue);
1513 if (!data)
1514 return False;
1517 if (ret)
1518 *ret = &data;
1520 if (addr)
1521 *(char**)addr = wstrdup(data);
1523 return True;
1525 #endif
1528 static int
1529 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1530 void **ret)
1532 static char *data;
1533 int i, count, len;
1534 char *ptr;
1535 proplist_t d;
1536 int changed=0;
1538 again:
1539 if (!PLIsArray(value)) {
1540 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1541 entry->key, "an array of paths");
1542 if (changed==0) {
1543 value = entry->plvalue;
1544 changed = 1;
1545 wwarning(_("using default \"%s\" instead"), entry->default_value);
1546 goto again;
1548 return False;
1551 i = 0;
1552 count = PLGetNumberOfElements(value);
1553 if (count < 1) {
1554 if (changed==0) {
1555 value = entry->plvalue;
1556 changed = 1;
1557 wwarning(_("using default \"%s\" instead"), entry->default_value);
1558 goto again;
1560 return False;
1563 len = 0;
1564 for (i=0; i<count; i++) {
1565 d = PLGetArrayElement(value, i);
1566 if (!d || !PLIsString(d)) {
1567 count = i;
1568 break;
1570 len += strlen(PLGetString(d))+1;
1573 ptr = data = wmalloc(len+1);
1575 for (i=0; i<count; i++) {
1576 d = PLGetArrayElement(value, i);
1577 if (!d || !PLIsString(d)) {
1578 break;
1580 strcpy(ptr, PLGetString(d));
1581 ptr += strlen(PLGetString(d));
1582 *ptr = ':';
1583 ptr++;
1585 ptr--; *(ptr--) = 0;
1587 if (*(char**)addr!=NULL) {
1588 free(*(char**)addr);
1590 *(char**)addr = data;
1592 return True;
1596 static int
1597 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1598 void **ret)
1600 static signed char data;
1602 data = string2index(entry->plkey, value, entry->default_value,
1603 (WOptionEnumeration*)entry->extra_data);
1604 if (data < 0)
1605 return False;
1607 if (ret)
1608 *ret = &data;
1610 if (addr)
1611 *(signed char*)addr = data;
1613 return True;
1619 * (solid <color>)
1620 * (hgradient <color> <color>)
1621 * (vgradient <color> <color>)
1622 * (dgradient <color> <color>)
1623 * (mhgradient <color> <color> ...)
1624 * (mvgradient <color> <color> ...)
1625 * (tpixmap <file> <color>)
1626 * (spixmap <file> <color>)
1627 * (cpixmap <file> <color>)
1628 * (thgradient <file> <opaqueness> <color> <color>)
1629 * (tvgradient <file> <opaqueness> <color> <color>)
1630 * (tdgradient <file> <opaqueness> <color> <color>)
1631 * (function <lib> <function> ...)
1634 static WTexture*
1635 parse_texture(WScreen *scr, proplist_t pl)
1637 proplist_t elem;
1638 char *val;
1639 int nelem;
1640 WTexture *texture=NULL;
1642 nelem = PLGetNumberOfElements(pl);
1643 if (nelem < 1)
1644 return NULL;
1647 elem = PLGetArrayElement(pl, 0);
1648 if (!elem || !PLIsString(elem))
1649 return NULL;
1650 val = PLGetString(elem);
1653 if (strcasecmp(val, "solid")==0) {
1654 XColor color;
1656 if (nelem != 2)
1657 return NULL;
1659 /* get color */
1661 elem = PLGetArrayElement(pl, 1);
1662 if (!elem || !PLIsString(elem))
1663 return NULL;
1664 val = PLGetString(elem);
1666 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1667 wwarning(_("\"%s\" is not a valid color name"), val);
1668 return NULL;
1671 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1672 } else if (strcasecmp(val, "dgradient")==0
1673 || strcasecmp(val, "vgradient")==0
1674 || strcasecmp(val, "hgradient")==0) {
1675 RColor color1, color2;
1676 XColor xcolor;
1677 int type;
1679 if (nelem != 3) {
1680 wwarning(_("bad number of arguments in gradient specification"));
1681 return NULL;
1684 if (val[0]=='d' || val[0]=='D')
1685 type = WTEX_DGRADIENT;
1686 else if (val[0]=='h' || val[0]=='H')
1687 type = WTEX_HGRADIENT;
1688 else
1689 type = WTEX_VGRADIENT;
1692 /* get from color */
1693 elem = PLGetArrayElement(pl, 1);
1694 if (!elem || !PLIsString(elem))
1695 return NULL;
1696 val = PLGetString(elem);
1698 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1699 wwarning(_("\"%s\" is not a valid color name"), val);
1700 return NULL;
1702 color1.alpha = 255;
1703 color1.red = xcolor.red >> 8;
1704 color1.green = xcolor.green >> 8;
1705 color1.blue = xcolor.blue >> 8;
1707 /* get to color */
1708 elem = PLGetArrayElement(pl, 2);
1709 if (!elem || !PLIsString(elem)) {
1710 return NULL;
1712 val = PLGetString(elem);
1714 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1715 wwarning(_("\"%s\" is not a valid color name"), val);
1716 return NULL;
1718 color2.alpha = 255;
1719 color2.red = xcolor.red >> 8;
1720 color2.green = xcolor.green >> 8;
1721 color2.blue = xcolor.blue >> 8;
1723 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1725 } else if (strcasecmp(val, "mhgradient")==0
1726 || strcasecmp(val, "mvgradient")==0
1727 || strcasecmp(val, "mdgradient")==0) {
1728 XColor color;
1729 RColor **colors;
1730 int i, count;
1731 int type;
1733 if (nelem < 3) {
1734 wwarning(_("too few arguments in multicolor gradient specification"));
1735 return NULL;
1738 if (val[1]=='h' || val[1]=='H')
1739 type = WTEX_MHGRADIENT;
1740 else if (val[1]=='v' || val[1]=='V')
1741 type = WTEX_MVGRADIENT;
1742 else
1743 type = WTEX_MDGRADIENT;
1745 count = nelem-1;
1747 colors = wmalloc(sizeof(RColor*)*(count+1));
1749 for (i=0; i<count; i++) {
1750 elem = PLGetArrayElement(pl, i+1);
1751 if (!elem || !PLIsString(elem)) {
1752 for (--i; i>=0; --i) {
1753 free(colors[i]);
1755 free(colors);
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 for (--i; i>=0; --i) {
1763 free(colors[i]);
1765 free(colors);
1766 return NULL;
1767 } else {
1768 colors[i] = wmalloc(sizeof(RColor));
1769 colors[i]->red = color.red >> 8;
1770 colors[i]->green = color.green >> 8;
1771 colors[i]->blue = color.blue >> 8;
1774 colors[i] = NULL;
1776 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1777 } else if (strcasecmp(val, "spixmap")==0 ||
1778 strcasecmp(val, "cpixmap")==0 ||
1779 strcasecmp(val, "tpixmap")==0) {
1780 XColor color;
1781 int type;
1783 if (nelem != 3)
1784 return NULL;
1786 if (val[0] == 's' || val[0] == 'S')
1787 type = WTP_SCALE;
1788 else if (val[0] == 'c' || val[0] == 'C')
1789 type = WTP_CENTER;
1790 else
1791 type = WTP_TILE;
1793 /* get color */
1794 elem = PLGetArrayElement(pl, 2);
1795 if (!elem || !PLIsString(elem)) {
1796 return NULL;
1798 val = PLGetString(elem);
1800 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1801 wwarning(_("\"%s\" is not a valid color name"), val);
1802 return NULL;
1805 /* file name */
1806 elem = PLGetArrayElement(pl, 1);
1807 if (!elem || !PLIsString(elem))
1808 return NULL;
1809 val = PLGetString(elem);
1811 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1812 } else if (strcasecmp(val, "thgradient")==0
1813 || strcasecmp(val, "tvgradient")==0
1814 || strcasecmp(val, "tdgradient")==0) {
1815 RColor color1, color2;
1816 XColor xcolor;
1817 int opacity;
1818 int style;
1820 if (val[1]=='h' || val[1]=='H')
1821 style = WTEX_THGRADIENT;
1822 else if (val[1]=='v' || val[1]=='V')
1823 style = WTEX_TVGRADIENT;
1824 else
1825 style = WTEX_TDGRADIENT;
1827 if (nelem != 5) {
1828 wwarning(_("bad number of arguments in textured gradient specification"));
1829 return NULL;
1832 /* get from color */
1833 elem = PLGetArrayElement(pl, 3);
1834 if (!elem || !PLIsString(elem))
1835 return NULL;
1836 val = PLGetString(elem);
1838 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1839 wwarning(_("\"%s\" is not a valid color name"), val);
1840 return NULL;
1842 color1.alpha = 255;
1843 color1.red = xcolor.red >> 8;
1844 color1.green = xcolor.green >> 8;
1845 color1.blue = xcolor.blue >> 8;
1847 /* get to color */
1848 elem = PLGetArrayElement(pl, 4);
1849 if (!elem || !PLIsString(elem)) {
1850 return NULL;
1852 val = PLGetString(elem);
1854 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1855 wwarning(_("\"%s\" is not a valid color name"), val);
1856 return NULL;
1858 color2.alpha = 255;
1859 color2.red = xcolor.red >> 8;
1860 color2.green = xcolor.green >> 8;
1861 color2.blue = xcolor.blue >> 8;
1863 /* get opacity */
1864 elem = PLGetArrayElement(pl, 2);
1865 if (!elem || !PLIsString(elem))
1866 opacity = 128;
1867 else
1868 val = PLGetString(elem);
1870 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1871 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1872 opacity = 128;
1875 /* get file name */
1876 elem = PLGetArrayElement(pl, 1);
1877 if (!elem || !PLIsString(elem))
1878 return NULL;
1879 val = PLGetString(elem);
1881 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1882 val, opacity);
1884 #ifdef TEXTURE_PLUGIN
1885 else if (strcasecmp(val, "function")==0) {
1886 WTexFunction *function;
1887 void (*initFunc) (Display *, Colormap);
1888 char *lib, *func, **argv;
1889 int i, argc;
1891 if (nelem < 3)
1892 return NULL;
1894 /* get the library name */
1895 elem = PLGetArrayElement(pl, 1);
1896 if (!elem || !PLIsString(elem)) {
1897 return NULL;
1899 lib = PLGetString(elem);
1901 /* get the function name */
1902 elem = PLGetArrayElement(pl, 2);
1903 if (!elem || !PLIsString(elem)) {
1904 return NULL;
1906 func = PLGetString(elem);
1908 argc = nelem - 2;
1909 argv = (char **)wmalloc(argc * sizeof(char *));
1911 /* get the parameters */
1912 argv[0] = wstrdup(func);
1913 for (i = 0; i < argc - 1; i++) {
1914 elem = PLGetArrayElement(pl, 3 + i);
1915 if (!elem || !PLIsString(elem)) {
1916 free(argv);
1918 return NULL;
1920 argv[i+1] = wstrdup(PLGetString(elem));
1923 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1925 #ifdef HAVE_DLFCN_H
1926 if (function) {
1927 initFunc = dlsym(function->handle, "initWindowMaker");
1928 if (initFunc) {
1929 initFunc(dpy, scr->w_colormap);
1930 } else {
1931 wwarning(_("could not initialize library %s"), lib);
1933 } else {
1934 wwarning(_("could not find function %s::%s"), lib, func);
1936 #endif /* HAVE_DLFCN_H */
1937 texture = (WTexture*)function;
1939 #endif /* TEXTURE_PLUGIN */
1940 else {
1941 wwarning(_("invalid texture type %s"), val);
1942 return NULL;
1944 return texture;
1949 static int
1950 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1951 void **ret)
1953 static WTexture *texture;
1954 int changed=0;
1956 again:
1957 if (!PLIsArray(value)) {
1958 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1959 entry->key, "Texture");
1960 if (changed==0) {
1961 value = entry->plvalue;
1962 changed = 1;
1963 wwarning(_("using default \"%s\" instead"), entry->default_value);
1964 goto again;
1966 return False;
1969 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
1970 proplist_t pl;
1972 pl = PLGetArrayElement(value, 0);
1973 if (!pl || !PLIsString(pl) || !PLGetString(pl)
1974 || strcasecmp(PLGetString(pl), "solid")!=0) {
1975 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1976 entry->key, "Solid Texture");
1978 value = entry->plvalue;
1979 changed = 1;
1980 wwarning(_("using default \"%s\" instead"), entry->default_value);
1981 goto again;
1985 texture = parse_texture(scr, value);
1987 if (!texture) {
1988 wwarning(_("Error in texture specification for key \"%s\""),
1989 entry->key);
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 (ret)
2000 *ret = &texture;
2002 if (addr)
2003 *(WTexture**)addr = texture;
2005 return True;
2010 #ifdef DRAWSTRING_PLUGIN
2011 static int
2012 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2013 void *addr, void **ret)
2015 proplist_t elem;
2016 char *val, *lib, *func, **argv;
2017 int argc, i, changed;
2019 if (strcmp(entry->key, "FTitleColor")==0) {
2020 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2021 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2022 } else if (strcmp(entry->key, "UTitleColor")==0) {
2023 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2024 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2025 } else if (strcmp(entry->key, "PTitleColor")==0) {
2026 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2027 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2028 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2029 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2030 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2031 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2032 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2033 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2035 if (PLIsString(value)) {
2036 return getColor(scr,entry,value,addr,ret);
2039 if (PLIsArray(value)) {
2040 if ((argc = PLGetNumberOfElements(value)) < 3) return False;
2041 argc -= 2;
2042 argv = (char **)wmalloc(argc * sizeof(char *));
2044 elem = PLGetArrayElement(value,0);
2045 if (!elem || !PLIsString(elem)) return False;
2046 val = PLGetString(elem);
2047 if (strcasecmp(val, "function")==0) {
2048 elem = PLGetArrayElement(value, 1); /* library name */
2049 if (!elem || !PLIsString(elem)) return False;
2050 lib = PLGetString(elem);
2051 elem = PLGetArrayElement(value, 2); /* function name */
2052 if (!elem || !PLIsString(elem)) return False;
2053 func = PLGetString(elem);
2054 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING, lib, NULL, func, NULL, value, NULL);
2056 if (scr->drawstring_func[changed]) {
2057 void (*initFunc) (Display *, Colormap);
2058 initFunc = dlsym(scr->drawstring_func[changed]->handle, "initWindowMaker");
2059 if (initFunc) {
2060 initFunc(dpy, scr->w_colormap);
2061 } else {
2062 wwarning(_("could not initialize library %s"), lib);
2064 } else {
2065 wwarning(_("could not find function %s::%s"), lib, func);
2070 #endif /* DRAWSTRING_PLUGIN */
2074 static int
2075 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2076 void *addr, void **ret)
2078 proplist_t elem;
2079 int changed = 0;
2080 char *val;
2081 int nelem;
2083 again:
2084 if (!PLIsArray(value)) {
2085 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2086 "WorkspaceBack", "Texture or None");
2087 if (changed==0) {
2088 value = entry->plvalue;
2089 changed = 1;
2090 wwarning(_("using default \"%s\" instead"), entry->default_value);
2091 goto again;
2093 return False;
2096 /* only do basic error checking and verify for None texture */
2098 nelem = PLGetNumberOfElements(value);
2099 if (nelem > 0) {
2100 elem = PLGetArrayElement(value, 0);
2101 if (!elem || !PLIsString(elem)) {
2102 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2103 if (changed==0) {
2104 value = entry->plvalue;
2105 changed = 1;
2106 wwarning(_("using default \"%s\" instead"), entry->default_value);
2107 goto again;
2109 return False;
2111 val = PLGetString(elem);
2113 if (strcasecmp(val, "None")==0)
2114 return True;
2116 *ret = PLRetain(value);
2118 return True;
2122 static int
2123 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2124 void *addr, void **ret)
2126 proplist_t elem;
2127 int nelem;
2128 int changed = 0;
2130 again:
2131 if (!PLIsArray(value)) {
2132 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2133 "WorkspaceSpecificBack", "an array of textures");
2134 if (changed==0) {
2135 value = entry->plvalue;
2136 changed = 1;
2137 wwarning(_("using default \"%s\" instead"), entry->default_value);
2138 goto again;
2140 return False;
2143 /* only do basic error checking and verify for None texture */
2145 nelem = PLGetNumberOfElements(value);
2146 if (nelem > 0) {
2147 while (nelem--) {
2148 elem = PLGetArrayElement(value, nelem);
2149 if (!elem || !PLIsArray(elem)) {
2150 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2151 nelem);
2156 *ret = PLRetain(value);
2158 #ifdef notworking
2160 * Kluge to force wmsetbg helper to set the default background.
2161 * If the WorkspaceSpecificBack is changed once wmaker has started,
2162 * the WorkspaceBack won't be sent to the helper, unless the user
2163 * changes it's value too. So, we must force this by removing the
2164 * value from the defaults DB.
2166 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2167 proplist_t key = PLMakeString("WorkspaceBack");
2169 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2171 PLRelease(key);
2173 #endif
2174 return True;
2178 static int
2179 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2180 void **ret)
2182 static WMFont *font;
2183 char *val;
2185 STRINGP("Font");
2187 val = PLGetString(value);
2189 font = WMCreateFont(scr->wmscreen, val);
2190 if (!font)
2191 font = WMCreateFont(scr->wmscreen, "fixed");
2193 if (!font) {
2194 wfatal(_("could not load any usable font!!!"));
2195 exit(1);
2198 if (ret)
2199 *ret = font;
2201 /* can't assign font value outside update function */
2202 wassertrv(addr == NULL, True);
2204 return True;
2208 static int
2209 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2210 void **ret)
2212 static XColor color;
2213 char *val;
2214 int second_pass=0;
2216 STRINGP("Color");
2218 val = PLGetString(value);
2220 again:
2221 if (!wGetColor(scr, val, &color)) {
2222 wwarning(_("could not get color for key \"%s\""),
2223 entry->key);
2224 if (second_pass==0) {
2225 val = PLGetString(entry->plvalue);
2226 second_pass = 1;
2227 wwarning(_("using default \"%s\" instead"), val);
2228 goto again;
2230 return False;
2233 if (ret)
2234 *ret = &color;
2236 assert(addr==NULL);
2238 if (addr)
2239 *(unsigned long*)addr = pixel;
2242 return True;
2247 static int
2248 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2249 void **ret)
2251 static WShortKey shortcut;
2252 KeySym ksym;
2253 char *val;
2254 char *k;
2255 char buf[128], *b;
2258 STRINGP("Key spec");
2260 val = PLGetString(value);
2262 if (!val || strcasecmp(val, "NONE")==0) {
2263 shortcut.keycode = 0;
2264 shortcut.modifier = 0;
2265 if (ret)
2266 *ret = &shortcut;
2267 return True;
2270 strcpy(buf, val);
2272 b = (char*)buf;
2274 /* get modifiers */
2275 shortcut.modifier = 0;
2276 while ((k = strchr(b, '+'))!=NULL) {
2277 int mod;
2279 *k = 0;
2280 mod = wXModifierFromKey(b);
2281 if (mod<0) {
2282 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2283 return False;
2285 shortcut.modifier |= mod;
2287 b = k+1;
2290 /* get key */
2291 ksym = XStringToKeysym(b);
2293 if (ksym==NoSymbol) {
2294 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2295 val);
2296 return False;
2299 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2300 if (shortcut.keycode==0) {
2301 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2302 return False;
2305 if (ret)
2306 *ret = &shortcut;
2308 return True;
2312 static int
2313 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2314 void **ret)
2316 static unsigned int mask;
2317 char *str;
2319 STRINGP("Modifier Key");
2321 str = PLGetString(value);
2322 if (!str)
2323 return False;
2325 mask = wXModifierFromKey(str);
2326 if (mask < 0) {
2327 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2328 mask = 0;
2329 return False;
2332 if (addr)
2333 *(unsigned int*)addr = mask;
2335 if (ret)
2336 *ret = &mask;
2338 return True;
2342 #ifdef NEWSTUFF
2343 static int
2344 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2345 void *addr, void **ret)
2347 unsigned int mask;
2348 char *str;
2349 RImage *image;
2350 int i, n;
2351 int w, h;
2353 STRINGP("Image File Path");
2355 str = PLGetString(value);
2356 if (!str)
2357 return False;
2359 image = RLoadImage(scr->rcontext, str, 0);
2360 if (!image) {
2361 wwarning(_("could not load image in option %s: %s"), entry->key,
2362 RMessageForError(RErrorCode));
2363 return False;
2366 if (*(RImage**)addr) {
2367 RDestroyImage(*(RImage**)addr);
2369 if (addr)
2370 *(RImage**)addr = image;
2372 assert(ret == NULL);
2374 if (ret)
2375 *(RImage**)ret = image;
2378 return True;
2380 #endif
2383 /* ---------------- value setting functions --------------- */
2384 static int
2385 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2387 return REFRESH_WINDOW_TITLE_COLOR;
2391 static int
2392 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2394 switch (which) {
2395 case WM_DOCK:
2396 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2397 break;
2398 case WM_CLIP:
2399 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2400 break;
2401 default:
2402 break;
2404 return 0;
2408 static int
2409 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2411 if (scr->workspaces) {
2412 wWorkspaceForceChange(scr, scr->current_workspace);
2413 wArrangeIcons(scr, False);
2415 return 0;
2418 #if not_used
2419 static int
2420 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2422 if (*value <= 0)
2423 *(int*)foo = 1;
2425 return 0;
2427 #endif
2431 static int
2432 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2434 Pixmap pixmap;
2435 RImage *img;
2436 int reset = 0;
2438 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2439 wPreferences.icon_size,
2440 ((*texture)->any.type & WREL_BORDER_MASK)
2441 ? WREL_ICON : WREL_FLAT);
2442 if (!img) {
2443 wwarning(_("could not render texture for icon background"));
2444 if (!entry->addr)
2445 wTextureDestroy(scr, *texture);
2446 return 0;
2448 RConvertImage(scr->rcontext, img, &pixmap);
2450 if (scr->icon_tile) {
2451 reset = 1;
2452 RDestroyImage(scr->icon_tile);
2453 XFreePixmap(dpy, scr->icon_tile_pixmap);
2456 scr->icon_tile = img;
2458 if (!wPreferences.flags.noclip) {
2459 if (scr->clip_tile) {
2460 RDestroyImage(scr->clip_tile);
2462 scr->clip_tile = wClipMakeTile(scr, img);
2465 scr->icon_tile_pixmap = pixmap;
2467 if (scr->def_icon_pixmap) {
2468 XFreePixmap(dpy, scr->def_icon_pixmap);
2469 scr->def_icon_pixmap = None;
2471 if (scr->def_ticon_pixmap) {
2472 XFreePixmap(dpy, scr->def_ticon_pixmap);
2473 scr->def_ticon_pixmap = None;
2476 if (scr->icon_back_texture) {
2477 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2479 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2481 if (scr->clip_balloon)
2482 XSetWindowBackground(dpy, scr->clip_balloon,
2483 (*texture)->any.color.pixel);
2486 * Free the texture as nobody else will use it, nor refer to it.
2488 if (!entry->addr)
2489 wTextureDestroy(scr, *texture);
2491 return (reset ? REFRESH_ICON_TILE : 0);
2496 static int
2497 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2499 if (scr->title_font) {
2500 WMReleaseFont(scr->title_font);
2502 scr->title_font = font;
2504 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2508 static int
2509 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2511 if (scr->menu_title_font) {
2512 WMReleaseFont(scr->menu_title_font);
2515 scr->menu_title_font = font;
2517 return REFRESH_MENU_TITLE_FONT;
2521 static int
2522 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2524 if (scr->menu_entry_font) {
2525 WMReleaseFont(scr->menu_entry_font);
2527 scr->menu_entry_font = font;
2529 return REFRESH_MENU_FONT;
2534 static int
2535 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2537 if (scr->icon_title_font) {
2538 WMReleaseFont(scr->icon_title_font);
2541 scr->icon_title_font = font;
2543 return REFRESH_ICON_FONT;
2547 static int
2548 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2550 if (scr->clip_title_font) {
2551 WMReleaseFont(scr->clip_title_font);
2554 scr->clip_title_font = font;
2556 return REFRESH_ICON_FONT;
2560 static int
2561 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2563 if (scr->info_text_font) {
2564 WMReleaseFont(scr->info_text_font);
2567 scr->info_text_font = font;
2569 /* This test works because the scr structure is initially zeroed out
2570 and None = 0. Any other time, the window should be valid. */
2571 if (scr->geometry_display != None) {
2572 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2573 &scr->geometry_display_height);
2574 XResizeWindow(dpy, scr->geometry_display,
2575 scr->geometry_display_width, scr->geometry_display_height);
2578 return 0;
2582 static int
2583 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2585 if (scr->workspace_name_font) {
2586 WMReleaseFont(scr->workspace_name_font);
2589 scr->workspace_name_font = font;
2591 return 0;
2595 static int
2596 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2598 if (scr->select_pixel!=scr->white_pixel &&
2599 scr->select_pixel!=scr->black_pixel) {
2600 wFreeColor(scr, scr->select_pixel);
2603 scr->select_pixel = color->pixel;
2605 return REFRESH_MENU_COLOR;
2609 static int
2610 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2612 if (scr->select_text_pixel!=scr->white_pixel &&
2613 scr->select_text_pixel!=scr->black_pixel) {
2614 wFreeColor(scr, scr->select_text_pixel);
2617 scr->select_text_pixel = color->pixel;
2619 return REFRESH_MENU_COLOR;
2623 static int
2624 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2626 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2627 scr->clip_title_pixel[index]!=scr->black_pixel) {
2628 wFreeColor(scr, scr->clip_title_pixel[index]);
2630 scr->clip_title_pixel[index] = color->pixel;
2632 #ifdef GRADIENT_CLIP_ARROW
2633 if (index == CLIP_NORMAL) {
2634 RImage *image;
2635 RColor color1, color2;
2636 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2637 int as = pt - 15; /* 15 = 5+5+5 */
2639 FREE_PIXMAP(scr->clip_arrow_gradient);
2641 color1.red = (color->red >> 8)*6/10;
2642 color1.green = (color->green >> 8)*6/10;
2643 color1.blue = (color->blue >> 8)*6/10;
2645 color2.red = WMIN((color->red >> 8)*20/10, 255);
2646 color2.green = WMIN((color->green >> 8)*20/10, 255);
2647 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2649 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2650 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2651 RDestroyImage(image);
2653 #endif /* GRADIENT_CLIP_ARROW */
2655 return REFRESH_ICON_TITLE_COLOR;
2659 static int
2660 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2662 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2663 scr->window_title_pixel[index]!=scr->black_pixel) {
2664 wFreeColor(scr, scr->window_title_pixel[index]);
2667 scr->window_title_pixel[index] = color->pixel;
2669 if (index == WS_UNFOCUSED)
2670 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2672 return REFRESH_WINDOW_TITLE_COLOR;
2676 static int
2677 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2679 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2680 scr->menu_title_pixel[0]!=scr->black_pixel) {
2681 wFreeColor(scr, scr->menu_title_pixel[0]);
2684 scr->menu_title_pixel[0] = color->pixel;
2685 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2687 return REFRESH_MENU_TITLE_COLOR;
2691 static int
2692 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2694 XGCValues gcv;
2695 #define gcm (GCForeground|GCBackground|GCFillStyle)
2697 if (scr->mtext_pixel!=scr->white_pixel &&
2698 scr->mtext_pixel!=scr->black_pixel) {
2699 wFreeColor(scr, scr->mtext_pixel);
2702 scr->mtext_pixel = color->pixel;
2704 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2707 if (scr->dtext_pixel == scr->mtext_pixel) {
2708 gcv.foreground = scr->white_pixel;
2709 gcv.background = scr->black_pixel;
2710 gcv.fill_style = FillStippled;
2711 } else {
2712 gcv.foreground = scr->dtext_pixel;
2713 gcv.fill_style = FillSolid;
2715 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2717 return REFRESH_MENU_COLOR;
2718 #undef gcm
2722 static int
2723 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2725 XGCValues gcv;
2726 #define gcm (GCForeground|GCBackground|GCFillStyle)
2728 if (scr->dtext_pixel!=scr->white_pixel &&
2729 scr->dtext_pixel!=scr->black_pixel) {
2730 wFreeColor(scr, scr->dtext_pixel);
2733 scr->dtext_pixel = color->pixel;
2735 if (scr->dtext_pixel == scr->mtext_pixel) {
2736 gcv.foreground = scr->white_pixel;
2737 gcv.background = scr->black_pixel;
2738 gcv.fill_style = FillStippled;
2739 } else {
2740 gcv.foreground = scr->dtext_pixel;
2741 gcv.fill_style = FillSolid;
2743 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2745 return REFRESH_MENU_COLOR;
2746 #undef gcm
2749 static int
2750 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2752 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2754 return REFRESH_ICON_TITLE_COLOR;
2758 static int
2759 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2761 if (scr->icon_title_texture) {
2762 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2764 XQueryColor (dpy, scr->w_colormap, color);
2765 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2767 return REFRESH_ICON_TITLE_BACK;
2771 static void
2772 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2774 close(scr->helper_fd);
2775 scr->helper_fd = 0;
2776 scr->helper_pid = 0;
2777 scr->flags.backimage_helper_launched = 0;
2781 static int
2782 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2783 void *bar)
2785 int i;
2786 proplist_t val;
2787 char *str;
2789 if (scr->flags.backimage_helper_launched) {
2790 if (PLGetNumberOfElements(value)==0) {
2791 SendHelperMessage(scr, 'C', 0, NULL);
2792 SendHelperMessage(scr, 'K', 0, NULL);
2794 PLRelease(value);
2795 return 0;
2797 } else {
2798 pid_t pid;
2799 int filedes[2];
2801 if (PLGetNumberOfElements(value) == 0)
2802 return 0;
2804 if (pipe(filedes) < 0) {
2805 wsyserror("pipe() failed:can't set workspace specific background image");
2807 PLRelease(value);
2808 return 0;
2811 pid = fork();
2812 if (pid < 0) {
2813 wsyserror("fork() failed:can't set workspace specific background image");
2814 if (close(filedes[0]) < 0)
2815 wsyserror("could not close pipe");
2816 if (close(filedes[1]) < 0)
2817 wsyserror("could not close pipe");
2819 } else if (pid == 0) {
2820 SetupEnvironment(scr);
2822 if (close(0) < 0)
2823 wsyserror("could not close pipe");
2824 if (dup(filedes[0]) < 0) {
2825 wsyserror("dup() failed:can't set workspace specific background image");
2827 if (wPreferences.smooth_workspace_back)
2828 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
2829 else
2830 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2831 wsyserror("could not execute wmsetbg");
2832 exit(1);
2833 } else {
2835 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2836 wsyserror("error setting close-on-exec flag");
2838 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2839 wsyserror("error setting close-on-exec flag");
2842 scr->helper_fd = filedes[1];
2843 scr->helper_pid = pid;
2844 scr->flags.backimage_helper_launched = 1;
2846 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2848 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2852 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2853 val = PLGetArrayElement(value, i);
2854 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2855 str = PLGetDescription(val);
2857 SendHelperMessage(scr, 'S', i+1, str);
2859 free(str);
2860 } else {
2861 SendHelperMessage(scr, 'U', i+1, NULL);
2864 sleep(1);
2866 PLRelease(value);
2867 return 0;
2871 static int
2872 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2873 void *bar)
2875 if (scr->flags.backimage_helper_launched) {
2876 char *str;
2878 if (PLGetNumberOfElements(value)==0) {
2879 SendHelperMessage(scr, 'U', 0, NULL);
2880 } else {
2881 /* set the default workspace background to this one */
2882 str = PLGetDescription(value);
2883 if (str) {
2884 SendHelperMessage(scr, 'S', 0, str);
2885 free(str);
2886 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2887 } else {
2888 SendHelperMessage(scr, 'U', 0, NULL);
2891 } else {
2892 char *command;
2893 char *text;
2895 SetupEnvironment(scr);
2896 text = PLGetDescription(value);
2897 command = wmalloc(strlen(text)+40);
2898 if (wPreferences.smooth_workspace_back)
2899 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
2900 else
2901 sprintf(command, "wmsetbg -d -p '%s' &", text);
2902 free(text);
2903 system(command);
2904 free(command);
2906 PLRelease(value);
2908 return 0;
2912 static int
2913 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2915 if (scr->widget_texture) {
2916 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2918 scr->widget_texture = *(WTexSolid**)texture;
2920 if (scr->geometry_display != None)
2921 XSetWindowBackground(dpy, scr->geometry_display,
2922 scr->widget_texture->normal.pixel);
2924 return 0;
2928 static int
2929 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2931 if (scr->window_title_texture[WS_FOCUSED]) {
2932 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2934 scr->window_title_texture[WS_FOCUSED] = *texture;
2936 return REFRESH_WINDOW_TEXTURES;
2940 static int
2941 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2943 if (scr->window_title_texture[WS_PFOCUSED]) {
2944 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2946 scr->window_title_texture[WS_PFOCUSED] = *texture;
2948 return REFRESH_WINDOW_TEXTURES;
2952 static int
2953 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2955 if (scr->window_title_texture[WS_UNFOCUSED]) {
2956 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2958 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2960 return REFRESH_WINDOW_TEXTURES;
2964 static int
2965 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2967 if (scr->resizebar_texture[0]) {
2968 wTextureDestroy(scr, scr->resizebar_texture[0]);
2970 scr->resizebar_texture[0] = *texture;
2972 return REFRESH_WINDOW_TEXTURES;
2976 static int
2977 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2979 if (scr->menu_title_texture[0]) {
2980 wTextureDestroy(scr, scr->menu_title_texture[0]);
2982 scr->menu_title_texture[0] = *texture;
2984 return REFRESH_MENU_TITLE_TEXTURE;
2988 static int
2989 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2991 if (scr->menu_item_texture) {
2992 wTextureDestroy(scr, scr->menu_item_texture);
2993 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2995 scr->menu_item_texture = *texture;
2997 scr->menu_item_auxtexture
2998 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3000 return REFRESH_MENU_TEXTURE;
3004 static int
3005 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3007 WWindow *wwin;
3008 wKeyBindings[index] = *shortcut;
3010 wwin = scr->focused_window;
3012 while (wwin!=NULL) {
3013 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3015 if (!WFLAGP(wwin, no_bind_keys)) {
3016 wWindowSetKeyGrabs(wwin);
3018 wwin = wwin->prev;
3021 return 0;
3025 static int
3026 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3028 wArrangeIcons(scr, True);
3030 return 0;
3034 static int
3035 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3037 wScreenUpdateUsableArea(scr);
3039 return 0;
3043 static int
3044 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3046 return REFRESH_MENU_TEXTURE;
3051 static int
3052 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3054 return REFRESH_BUTTON_IMAGES;
3059 * Very ugly kluge.
3060 * Need access to the double click variables, so that all widgets in
3061 * wmaker panels will have the same dbl-click values.
3062 * TODO: figure a better way of dealing with it.
3064 #include "WINGsP.h"
3066 static int
3067 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3069 extern _WINGsConfiguration WINGsConfiguration;
3071 if (*value <= 0)
3072 *(int*)foo = 1;
3074 WINGsConfiguration.doubleClickDelay = *value;
3076 return 0;
3081 static int
3082 setMultiByte(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3084 extern _WINGsConfiguration WINGsConfiguration;
3086 WINGsConfiguration.useMultiByte = *value;
3088 return 0;