Virtual desktop code (very experiment!!!!!)
[wmaker-crm.git] / src / defaults.c
blobb0c14d742d607bb92275d9986aa0a4a90f303b17
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_AUTO, 0}, {"Smart", WPM_SMART, 0},
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 {"None", -1, 0},
260 {"Left", Button1, 0}, {"Button1", Button1, 1},
261 {"Middle", Button2, 0}, {"Button2", Button2, 1},
262 {"Right", Button3, 0}, {"Button3", Button3, 1},
263 {"Button4", Button4, 0},
264 {"Button5", Button5, 0},
265 {NULL, 0, 0}
268 static WOptionEnumeration seIconificationStyles[] = {
269 {"Zoom", WIS_ZOOM, 0},
270 {"Twist", WIS_TWIST, 0},
271 {"Flip", WIS_FLIP, 0},
272 {"None", WIS_NONE, 0},
273 {"random", WIS_RANDOM, 0},
274 {NULL, 0, 0}
277 static WOptionEnumeration seJustifications[] = {
278 {"Left", WTJ_LEFT, 0},
279 {"Center", WTJ_CENTER, 0},
280 {"Right", WTJ_RIGHT, 0},
281 {NULL, 0, 0}
284 static WOptionEnumeration seIconPositions[] = {
285 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
286 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
287 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
288 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
289 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
290 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
291 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
292 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
293 {NULL, 0, 0}
296 static WOptionEnumeration seMenuStyles[] = {
297 {"normal", MS_NORMAL, 0},
298 {"singletexture", MS_SINGLE_TEXTURE, 0},
299 {"flat", MS_FLAT, 0},
300 {NULL, 0, 0}
304 static WOptionEnumeration seDisplayPositions[] = {
305 {"none", WD_NONE, 0},
306 {"center", WD_CENTER, 0},
307 {"top", WD_TOP, 0},
308 {"bottom", WD_BOTTOM, 0},
309 {"topleft", WD_TOPLEFT, 0},
310 {"topright", WD_TOPRIGHT, 0},
311 {"bottomleft", WD_BOTTOMLEFT, 0},
312 {"bottomright", WD_BOTTOMRIGHT, 0}
317 * ALL entries in the tables bellow, NEED to have a default value
318 * defined, and this value needs to be correct.
321 /* these options will only affect the window manager on startup
323 * static defaults can't access the screen data, because it is
324 * created after these defaults are read
326 WDefaultEntry staticOptionList[] = {
328 {"DisableDithering", "NO", NULL,
329 &wPreferences.no_dithering, getBool, NULL
331 {"ColormapSize", "4", NULL,
332 &wPreferences.cmap_size, getInt, NULL
334 /* static by laziness */
335 {"IconSize", "64", NULL,
336 &wPreferences.icon_size, getInt, NULL
338 {"ModifierKey", "Mod1", NULL,
339 &wPreferences.modifier_mask, getModMask, NULL
341 {"DisableWSMouseActions", "NO", NULL,
342 &wPreferences.disable_root_mouse, getBool, NULL
344 {"FocusMode", "manual", seFocusModes,
345 &wPreferences.focus_mode, getEnum, NULL
346 }, /* have a problem when switching from manual to sloppy without restart */
347 {"NewStyle", "NO", NULL,
348 &wPreferences.new_style, getBool, NULL
350 {"DisableDock", "NO", (void*) WM_DOCK,
351 NULL, getBool, setIfDockPresent
353 {"DisableClip", "NO", (void*) WM_CLIP,
354 NULL, getBool, setIfDockPresent
356 {"DisableMiniwindows", "NO", NULL,
357 &wPreferences.disable_miniwindows, getBool, NULL
359 {"MultiByteText", "NO", NULL,
360 &wPreferences.multi_byte_text, getBool, setMultiByte
366 WDefaultEntry optionList[] = {
367 /* dynamic options */
368 {"IconPosition", "blh", seIconPositions,
369 &wPreferences.icon_yard, getEnum, setIconPosition
371 {"IconificationStyle", "Zoom", seIconificationStyles,
372 &wPreferences.iconification_style, getEnum, NULL
374 {"SelectWindowsMouseButton", "Left", seMouseButtons,
375 &wPreferences.select_button, getEnum, NULL
377 {"WindowListMouseButton", "Middle", seMouseButtons,
378 &wPreferences.windowl_button, getEnum, NULL
380 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
381 &wPreferences.menu_button, getEnum, NULL
383 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
384 &wPreferences.pixmap_path, getPathList, NULL
386 {"IconPath", DEF_ICON_PATHS, NULL,
387 &wPreferences.icon_path, getPathList, NULL
389 {"ColormapMode", "auto", seColormapModes,
390 &wPreferences.colormap_mode, getEnum, NULL
392 {"AutoFocus", "NO", NULL,
393 &wPreferences.auto_focus, getBool, NULL
395 {"RaiseDelay", "0", NULL,
396 &wPreferences.raise_delay, getInt, NULL
398 {"CirculateRaise", "NO", NULL,
399 &wPreferences.circ_raise, getBool, NULL
401 {"Superfluous", "NO", NULL,
402 &wPreferences.superfluous, getBool, NULL
404 {"AdvanceToNewWorkspace", "NO", NULL,
405 &wPreferences.ws_advance, getBool, NULL
407 {"CycleWorkspaces", "NO", NULL,
408 &wPreferences.ws_cycle, getBool, NULL
410 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
411 &wPreferences.workspace_name_display_position, getEnum, NULL
413 #ifdef VIRTUAL_DESKTOP
414 {"VirtualEdgeThickness", "1", NULL,
415 &wPreferences.vedge_thickness, getInt, NULL
417 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
418 &wPreferences.vedge_hscrollspeed, getInt, NULL
420 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
421 &wPreferences.vedge_vscrollspeed, getInt, NULL
423 {"VirtualEdgeWidth", "2000", NULL,
424 &wPreferences.vedge_width, getInt, NULL
426 {"VirtualEdgeHeight", "2000", NULL,
427 &wPreferences.vedge_height, getInt, NULL
429 #endif
430 {"StickyIcons", "NO", NULL,
431 &wPreferences.sticky_icons, getBool, setStickyIcons
433 {"SaveSessionOnExit", "NO", NULL,
434 &wPreferences.save_session_on_exit, getBool, NULL
436 {"WrapMenus", "NO", NULL,
437 &wPreferences.wrap_menus, getBool, NULL
439 {"ScrollableMenus", "NO", NULL,
440 &wPreferences.scrollable_menus, getBool, NULL
442 {"MenuScrollSpeed", "medium", seSpeeds,
443 &wPreferences.menu_scroll_speed, getEnum, NULL
445 {"IconSlideSpeed", "medium", seSpeeds,
446 &wPreferences.icon_slide_speed, getEnum, NULL
448 {"ShadeSpeed", "medium", seSpeeds,
449 &wPreferences.shade_speed, getEnum, NULL
451 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
452 &wPreferences.dblclick_time, getInt, setDoubleClick,
454 {"AlignSubmenus", "NO", NULL,
455 &wPreferences.align_menus, getBool, NULL
457 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
458 &wPreferences.open_transients_with_parent, getBool, NULL
460 {"WindowPlacement", "auto", sePlacements,
461 &wPreferences.window_placement, getEnum, NULL
463 {"IgnoreFocusClick","NO", NULL,
464 &wPreferences.ignore_focus_click, getBool, NULL
466 {"UseSaveUnders", "NO", NULL,
467 &wPreferences.use_saveunders, getBool, NULL
469 {"OpaqueMove", "NO", NULL,
470 &wPreferences.opaque_move, getBool, NULL
472 {"DisableSound", "NO", NULL,
473 &wPreferences.no_sound, getBool, NULL
475 {"DisableAnimations", "NO", NULL,
476 &wPreferences.no_animations, getBool, NULL
478 {"DontLinkWorkspaces","NO", NULL,
479 &wPreferences.no_autowrap, getBool, NULL
481 {"AutoArrangeIcons", "NO", NULL,
482 &wPreferences.auto_arrange_icons, getBool, NULL
484 {"NoWindowOverDock", "NO", NULL,
485 &wPreferences.no_window_over_dock, getBool, updateUsableArea
487 {"NoWindowOverIcons", "NO", NULL,
488 &wPreferences.no_window_over_icons, getBool, updateUsableArea
490 {"WindowPlaceOrigin", "(0, 0)", NULL,
491 &wPreferences.window_place_origin, getCoord, NULL
493 {"ResizeDisplay", "corner", seGeomDisplays,
494 &wPreferences.size_display, getEnum, NULL
496 {"MoveDisplay", "corner", seGeomDisplays,
497 &wPreferences.move_display, getEnum, NULL
499 {"DontConfirmKill", "NO", NULL,
500 &wPreferences.dont_confirm_kill, getBool,NULL
502 {"WindowTitleBalloons", "NO", NULL,
503 &wPreferences.window_balloon, getBool, NULL
505 {"MiniwindowTitleBalloons", "NO", NULL,
506 &wPreferences.miniwin_balloon,getBool, NULL
508 {"AppIconBalloons", "NO", NULL,
509 &wPreferences.appicon_balloon,getBool, NULL
511 {"HelpBalloons", "NO", NULL,
512 &wPreferences.help_balloon, getBool, NULL
514 {"EdgeResistance", "30", NULL,
515 &wPreferences.edge_resistance,getInt, NULL
517 {"Attraction", "NO", NULL,
518 &wPreferences.attract, getBool, NULL
520 {"DisableBlinking", "NO", NULL,
521 &wPreferences.dont_blink, getBool, NULL
523 #ifdef WEENDOZE_CYCLE
524 {"WindozeCycling","NO", NULL,
525 &wPreferences.windoze_cycling, getBool, NULL
527 {"PopupSwitchMenu","YES", NULL,
528 &wPreferences.popup_switchmenu, getBool, NULL
530 #endif /* WEENDOZE_CYCLE */
531 /* style options */
532 {"MenuStyle", "normal", seMenuStyles,
533 &wPreferences.menu_style, getEnum, setMenuStyle
535 {"WidgetColor", "(solid, gray)", NULL,
536 NULL, getTexture, setWidgetColor,
538 {"WorkspaceSpecificBack","()", NULL,
539 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
541 /* WorkspaceBack must come after WorkspaceSpecificBack or
542 * WorkspaceBack wont know WorkspaceSpecificBack was also
543 * specified and 2 copies of wmsetbg will be launched */
544 {"WorkspaceBack", "(solid, black)", NULL,
545 NULL, getWSBackground,setWorkspaceBack
547 {"SmoothWorkspaceBack", "NO", NULL,
548 NULL, getBool, NULL
550 {"IconBack", "(solid, gray)", NULL,
551 NULL, getTexture, setIconTile
553 {"TitleJustify", "center", seJustifications,
554 &wPreferences.title_justification, getEnum, setJustify
556 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
557 NULL, getFont, setWinTitleFont,
559 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
560 NULL, getFont, setMenuTitleFont
562 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
563 NULL, getFont, setMenuTextFont
565 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
566 NULL, getFont, setIconTitleFont
568 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
569 NULL, getFont, setClipTitleFont
571 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
572 NULL, getFont, setDisplayFont
574 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
575 NULL, getFont, setLargeDisplayFont
577 {"HighlightColor", "white", NULL,
578 NULL, getColor, setHightlight
580 {"HighlightTextColor", "black", NULL,
581 NULL, getColor, setHightlightText
583 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
584 NULL, getColor, setClipTitleColor
586 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
587 NULL, getColor, setClipTitleColor
589 #ifdef DRAWSTRING_PLUGIN
590 {"FTitleColor", "white", (void*)WS_FOCUSED,
591 NULL, getTextRenderer, setWTitleColor
593 {"PTitleColor", "white", (void*)WS_PFOCUSED,
594 NULL, getTextRenderer, setWTitleColor
596 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
597 NULL, getTextRenderer, setWTitleColor
599 #else
600 {"FTitleColor", "white", (void*)WS_FOCUSED,
601 NULL, getColor, setWTitleColor
603 {"PTitleColor", "white", (void*)WS_PFOCUSED,
604 NULL, getColor, setWTitleColor
606 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
607 NULL, getColor, setWTitleColor
609 #endif
610 {"FTitleBack", "(solid, black)", NULL,
611 NULL, getTexture, setFTitleBack
613 {"PTitleBack", "(solid, \"#616161\")", NULL,
614 NULL, getTexture, setPTitleBack
616 {"UTitleBack", "(solid, gray)", NULL,
617 NULL, getTexture, setUTitleBack
619 {"ResizebarBack", "(solid, gray)", NULL,
620 NULL, getTexture, setResizebarBack
622 #ifdef DRAWSTRING_PLUGIN
623 {"MenuTitleColor", "white", NULL,
624 NULL, getTextRenderer, setMenuTitleColor
626 #else
627 {"MenuTitleColor", "white", NULL,
628 NULL, getColor, setMenuTitleColor
630 #endif
631 {"MenuTextColor", "black", NULL,
632 NULL, getColor, setMenuTextColor
634 {"MenuDisabledColor", "\"#616161\"", NULL,
635 NULL, getColor, setMenuDisabledColor
637 {"MenuTitleBack", "(solid, black)", NULL,
638 NULL, getTexture, setMenuTitleBack
640 {"MenuTextBack", "(solid, gray)", NULL,
641 NULL, getTexture, setMenuTextBack
643 {"IconTitleColor", "white", NULL,
644 NULL, getColor, setIconTitleColor
646 {"IconTitleBack", "black", NULL,
647 NULL, getColor, setIconTitleBack
649 /* keybindings */
650 #ifndef LITE
651 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
652 NULL, getKeybind, setKeyGrab
654 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
655 NULL, getKeybind, setKeyGrab
657 #endif /* LITE */
658 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
659 NULL, getKeybind, setKeyGrab
661 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
662 NULL, getKeybind, setKeyGrab
664 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
665 NULL, getKeybind, setKeyGrab
667 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
668 NULL, getKeybind, setKeyGrab
670 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
671 NULL, getKeybind, setKeyGrab
673 {"HideKey", "None", (void*)WKBD_HIDE,
674 NULL, getKeybind, setKeyGrab
676 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
677 NULL, getKeybind, setKeyGrab
679 {"CloseKey", "None", (void*)WKBD_CLOSE,
680 NULL, getKeybind, setKeyGrab
682 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
683 NULL, getKeybind, setKeyGrab
685 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
686 NULL, getKeybind, setKeyGrab
688 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
689 NULL, getKeybind, setKeyGrab
691 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
692 NULL, getKeybind, setKeyGrab
694 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
695 NULL, getKeybind, setKeyGrab
697 {"ShadeKey", "None", (void*)WKBD_SHADE,
698 NULL, getKeybind, setKeyGrab
700 {"SelectKey", "None", (void*)WKBD_SELECT,
701 NULL, getKeybind, setKeyGrab
703 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
704 NULL, getKeybind, setKeyGrab
706 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
707 NULL, getKeybind, setKeyGrab
709 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
710 NULL, getKeybind, setKeyGrab
712 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
713 NULL, getKeybind, setKeyGrab
715 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
716 NULL, getKeybind, setKeyGrab
718 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
719 NULL, getKeybind, setKeyGrab
721 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
722 NULL, getKeybind, setKeyGrab
724 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
725 NULL, getKeybind, setKeyGrab
727 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
728 NULL, getKeybind, setKeyGrab
730 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
731 NULL, getKeybind, setKeyGrab
733 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
734 NULL, getKeybind, setKeyGrab
736 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
737 NULL, getKeybind, setKeyGrab
739 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
740 NULL, getKeybind, setKeyGrab
742 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
743 NULL, getKeybind, setKeyGrab
745 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
746 NULL, getKeybind, setKeyGrab
748 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
749 NULL, getKeybind, setKeyGrab
751 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
752 NULL, getKeybind, setKeyGrab
754 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
755 NULL, getKeybind, setKeyGrab
757 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
758 NULL, getKeybind, setKeyGrab
760 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
761 NULL, getKeybind, setKeyGrab
763 #ifdef EXTEND_WINDOWSHORTCUT
764 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
765 NULL, getKeybind, setKeyGrab
767 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
768 NULL, getKeybind, setKeyGrab
770 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
771 NULL, getKeybind, setKeyGrab
773 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
774 NULL, getKeybind, setKeyGrab
776 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
777 NULL, getKeybind, setKeyGrab
779 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
780 NULL, getKeybind, setKeyGrab
782 #endif /* EXTEND_WINDOWSHORTCUT */
784 #ifdef KEEP_XKB_LOCK_STATUS
785 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
786 NULL, getKeybind, setKeyGrab
788 {"KbdModeLock", "NO", NULL,
789 &wPreferences.modelock, getBool, NULL
791 #endif /* KEEP_XKB_LOCK_STATUS */
795 #if 0
796 static void rereadDefaults(void);
797 #endif
799 #if 0
800 static void
801 rereadDefaults(void)
803 /* must defer the update because accessing X data from a
804 * signal handler can mess up Xlib */
807 #endif
809 static void
810 initDefaults()
812 int i;
813 WDefaultEntry *entry;
815 PLSetStringCmpHook(StringCompareHook);
817 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
818 entry = &optionList[i];
820 entry->plkey = PLMakeString(entry->key);
821 if (entry->default_value)
822 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
823 else
824 entry->plvalue = NULL;
827 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
828 entry = &staticOptionList[i];
830 entry->plkey = PLMakeString(entry->key);
831 if (entry->default_value)
832 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
833 else
834 entry->plvalue = NULL;
838 wDomainName = PLMakeString(WMDOMAIN_NAME);
839 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
841 PLRegister(wDomainName, rereadDefaults);
842 PLRegister(wAttributeDomainName, rereadDefaults);
849 #if 0
850 proplist_t
851 wDefaultsInit(int screen_number)
853 static int defaults_inited = 0;
854 proplist_t dict;
856 if (!defaults_inited) {
857 initDefaults();
860 dict = PLGetDomain(wDomainName);
861 if (!dict) {
862 wwarning(_("could not read domain \"%s\" from defaults database"),
863 PLGetString(wDomainName));
866 return dict;
868 #endif
871 void
872 wDefaultsDestroyDomain(WDDomain *domain)
874 if (domain->dictionary)
875 PLRelease(domain->dictionary);
876 free(domain->path);
877 free(domain);
881 WDDomain*
882 wDefaultsInitDomain(char *domain, Bool requireDictionary)
884 WDDomain *db;
885 struct stat stbuf;
886 static int inited = 0;
887 char path[PATH_MAX];
888 char *the_path;
889 proplist_t shared_dict=NULL;
891 if (!inited) {
892 inited = 1;
893 initDefaults();
896 db = wmalloc(sizeof(WDDomain));
897 memset(db, 0, sizeof(WDDomain));
898 db->domain_name = domain;
899 db->path = wdefaultspathfordomain(domain);
900 the_path = db->path;
902 if (the_path && stat(the_path, &stbuf)>=0) {
903 db->dictionary = ReadProplistFromFile(the_path);
904 if (db->dictionary) {
905 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
906 PLRelease(db->dictionary);
907 db->dictionary = NULL;
908 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
909 domain, the_path);
911 db->timestamp = stbuf.st_mtime;
912 } else {
913 wwarning(_("could not load domain %s from user defaults database"),
914 domain);
918 /* global system dictionary */
919 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
920 if (stat(path, &stbuf)>=0) {
921 shared_dict = ReadProplistFromFile(path);
922 if (shared_dict) {
923 if (requireDictionary && !PLIsDictionary(shared_dict)) {
924 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
925 domain, path);
926 PLRelease(shared_dict);
927 shared_dict = NULL;
928 } else {
929 if (db->dictionary && PLIsDictionary(shared_dict) &&
930 PLIsDictionary(db->dictionary)) {
931 PLMergeDictionaries(shared_dict, db->dictionary);
932 PLRelease(db->dictionary);
933 db->dictionary = shared_dict;
934 if (stbuf.st_mtime > db->timestamp)
935 db->timestamp = stbuf.st_mtime;
936 } else if (!db->dictionary) {
937 db->dictionary = shared_dict;
938 if (stbuf.st_mtime > db->timestamp)
939 db->timestamp = stbuf.st_mtime;
942 } else {
943 wwarning(_("could not load domain %s from global defaults database (%s)"),
944 domain, path);
948 /* set to save it in user's directory, no matter from where it was read */
949 if (db->dictionary) {
950 proplist_t tmp = PLMakeString(db->path);
952 PLSetFilename(db->dictionary, tmp);
953 PLRelease(tmp);
956 return db;
960 void
961 wReadStaticDefaults(proplist_t dict)
963 proplist_t plvalue;
964 WDefaultEntry *entry;
965 int i;
966 void *tdata;
969 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
970 entry = &staticOptionList[i];
972 if (dict)
973 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
974 else
975 plvalue = NULL;
977 if (!plvalue) {
978 /* no default in the DB. Use builtin default */
979 plvalue = entry->plvalue;
982 if (plvalue) {
983 /* convert data */
984 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
985 if (entry->update) {
986 (*entry->update)(NULL, entry, tdata, entry->extra_data);
993 void
994 wDefaultsCheckDomains(void *foo)
996 WScreen *scr;
997 struct stat stbuf;
998 proplist_t dict;
999 int i;
1000 char path[PATH_MAX];
1002 #ifdef HEARTBEAT
1003 puts("Checking domains...");
1004 #endif
1005 if (stat(WDWindowMaker->path, &stbuf)>=0
1006 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1007 proplist_t shared_dict = NULL;
1008 #ifdef HEARTBEAT
1009 puts("Checking WindowMaker domain");
1010 #endif
1011 WDWindowMaker->timestamp = stbuf.st_mtime;
1013 /* global dictionary */
1014 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1015 if (stat(path, &stbuf)>=0) {
1016 shared_dict = ReadProplistFromFile(path);
1017 if (shared_dict && !PLIsDictionary(shared_dict)) {
1018 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1019 "WindowMaker", path);
1020 PLRelease(shared_dict);
1021 shared_dict = NULL;
1022 } else if (!shared_dict) {
1023 wwarning(_("could not load domain %s from global defaults database"),
1024 "WindowMaker");
1027 /* user dictionary */
1028 dict = ReadProplistFromFile(WDWindowMaker->path);
1029 if (dict) {
1030 if (!PLIsDictionary(dict)) {
1031 PLRelease(dict);
1032 dict = NULL;
1033 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1034 "WindowMaker", WDWindowMaker->path);
1035 } else {
1036 if (shared_dict) {
1037 PLSetFilename(shared_dict, PLGetFilename(dict));
1038 PLMergeDictionaries(shared_dict, dict);
1039 PLRelease(dict);
1040 dict = shared_dict;
1041 shared_dict = NULL;
1043 for (i=0; i<wScreenCount; i++) {
1044 scr = wScreenWithNumber(i);
1045 if (scr)
1046 wReadDefaults(scr, dict);
1048 if (WDWindowMaker->dictionary) {
1049 PLRelease(WDWindowMaker->dictionary);
1051 WDWindowMaker->dictionary = dict;
1053 } else {
1054 wwarning(_("could not load domain %s from user defaults database"),
1055 "WindowMaker");
1057 if (shared_dict) {
1058 PLRelease(shared_dict);
1062 if (stat(WDWindowAttributes->path, &stbuf)>=0
1063 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1064 #ifdef HEARTBEAT
1065 puts("Checking WMWindowAttributes domain");
1066 #endif
1067 dict = ReadProplistFromFile(WDWindowAttributes->path);
1068 if (dict) {
1069 if (!PLIsDictionary(dict)) {
1070 PLRelease(dict);
1071 dict = NULL;
1072 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1073 "WMWindowAttributes", WDWindowAttributes->path);
1074 } else {
1075 if (WDWindowAttributes->dictionary)
1076 PLRelease(WDWindowAttributes->dictionary);
1077 WDWindowAttributes->dictionary = dict;
1078 for (i=0; i<wScreenCount; i++) {
1079 scr = wScreenWithNumber(i);
1080 if (scr)
1081 wDefaultUpdateIcons(scr);
1084 } else {
1085 wwarning(_("could not load domain %s from user defaults database"),
1086 "WMWindowAttributes");
1088 WDWindowAttributes->timestamp = stbuf.st_mtime;
1091 #ifndef LITE
1092 if (stat(WDRootMenu->path, &stbuf)>=0
1093 && WDRootMenu->timestamp < stbuf.st_mtime) {
1094 dict = ReadProplistFromFile(WDRootMenu->path);
1095 #ifdef HEARTBEAT
1096 puts("Checking WMRootMenu domain");
1097 #endif
1098 if (dict) {
1099 if (!PLIsArray(dict) && !PLIsString(dict)) {
1100 PLRelease(dict);
1101 dict = NULL;
1102 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1103 "WMRootMenu", WDRootMenu->path);
1104 } else {
1105 if (WDRootMenu->dictionary) {
1106 PLRelease(WDRootMenu->dictionary);
1108 WDRootMenu->dictionary = dict;
1110 } else {
1111 wwarning(_("could not load domain %s from user defaults database"),
1112 "WMRootMenu");
1114 WDRootMenu->timestamp = stbuf.st_mtime;
1116 #endif /* !LITE */
1118 if (!foo)
1119 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1123 void
1124 wReadDefaults(WScreen *scr, proplist_t new_dict)
1126 proplist_t plvalue, old_value;
1127 WDefaultEntry *entry;
1128 int i, must_update;
1129 int update_workspace_back = 0; /* kluge :/ */
1130 int needs_refresh;
1131 void *tdata;
1132 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1133 ? WDWindowMaker->dictionary : NULL);
1135 must_update = 0;
1137 needs_refresh = 0;
1139 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1140 entry = &optionList[i];
1142 if (new_dict)
1143 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1144 else
1145 plvalue = NULL;
1147 if (!old_dict)
1148 old_value = NULL;
1149 else
1150 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1153 if (!plvalue && !old_value) {
1154 /* no default in the DB. Use builtin default */
1155 plvalue = entry->plvalue;
1156 if (plvalue && new_dict) {
1157 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1158 must_update = 1;
1160 } else if (!plvalue) {
1161 /* value was deleted from DB. Keep current value */
1162 continue;
1163 } else if (!old_value) {
1164 /* set value for the 1st time */
1165 } else if (!PLIsEqual(plvalue, old_value)) {
1166 /* value has changed */
1167 } else {
1169 if (strcmp(entry->key, "WorkspaceBack") == 0
1170 && update_workspace_back
1171 && scr->flags.backimage_helper_launched) {
1172 } else {
1173 /* value was not changed since last time */
1174 continue;
1178 if (plvalue) {
1179 #ifdef DEBUG
1180 printf("Updating %s to %s\n", entry->key,
1181 PLGetDescription(plvalue));
1182 #endif
1183 /* convert data */
1184 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1186 * If the WorkspaceSpecificBack data has been changed
1187 * so that the helper will be launched now, we must be
1188 * sure to send the default background texture config
1189 * to the helper.
1191 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1192 && !scr->flags.backimage_helper_launched) {
1193 update_workspace_back = 1;
1195 if (entry->update) {
1196 needs_refresh |=
1197 (*entry->update)(scr, entry, tdata, entry->extra_data);
1203 if (needs_refresh!=0 && !scr->flags.startup) {
1204 int foo;
1206 foo = 0;
1207 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1208 foo |= WTextureSettings;
1209 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1210 foo |= WFontSettings;
1211 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1212 foo |= WColorSettings;
1213 if (foo)
1214 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1215 (void*)foo);
1217 foo = 0;
1218 if (needs_refresh & REFRESH_MENU_TEXTURE)
1219 foo |= WTextureSettings;
1220 if (needs_refresh & REFRESH_MENU_FONT)
1221 foo |= WFontSettings;
1222 if (needs_refresh & REFRESH_MENU_COLOR)
1223 foo |= WColorSettings;
1224 if (foo)
1225 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1226 (void*)foo);
1228 foo = 0;
1229 if (needs_refresh & REFRESH_WINDOW_FONT) {
1230 foo |= WFontSettings;
1232 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1233 foo |= WTextureSettings;
1235 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1236 foo |= WColorSettings;
1238 if (foo)
1239 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1240 (void*)foo);
1242 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1243 foo = 0;
1244 if (needs_refresh & REFRESH_ICON_FONT) {
1245 foo |= WFontSettings;
1247 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1248 foo |= WTextureSettings;
1250 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1251 foo |= WTextureSettings;
1253 if (foo)
1254 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1255 (void*)foo);
1257 if (needs_refresh & REFRESH_ICON_TILE)
1258 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1263 void
1264 wDefaultUpdateIcons(WScreen *scr)
1266 WAppIcon *aicon = scr->app_icon_list;
1267 WWindow *wwin = scr->focused_window;
1268 char *file;
1270 while(aicon) {
1271 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1272 False);
1273 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1274 || (file && !aicon->icon->file)) {
1275 RImage *new_image;
1277 if (aicon->icon->file)
1278 free(aicon->icon->file);
1279 aicon->icon->file = wstrdup(file);
1281 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1282 aicon->wm_class);
1283 if (new_image) {
1284 wIconChangeImage(aicon->icon, new_image);
1285 wAppIconPaint(aicon);
1288 aicon = aicon->next;
1291 if (!wPreferences.flags.noclip)
1292 wClipIconPaint(scr->clip_icon);
1294 while (wwin) {
1295 if (wwin->icon && wwin->flags.miniaturized) {
1296 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1297 False);
1298 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1299 || (file && !wwin->icon->file)) {
1300 RImage *new_image;
1302 if (wwin->icon->file)
1303 free(wwin->icon->file);
1304 wwin->icon->file = wstrdup(file);
1306 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1307 wwin->wm_class);
1308 if (new_image)
1309 wIconChangeImage(wwin->icon, new_image);
1312 wwin = wwin->prev;
1317 /* --------------------------- Local ----------------------- */
1319 #define STRINGP(x) if (!PLIsString(value)) { \
1320 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1321 entry->key, x); \
1322 return False; }
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 STRINGP("Boolean");
1378 val = PLGetString(value);
1380 again:
1381 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1382 || strcasecmp(val, "YES")==0) {
1384 data = 1;
1385 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1386 || strcasecmp(val, "NO")==0) {
1387 data = 0;
1388 } else {
1389 int i;
1390 if (sscanf(val, "%i", &i)==1) {
1391 if (i!=0)
1392 data = 1;
1393 else
1394 data = 0;
1395 } else {
1396 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1397 val, entry->key);
1398 if (second_pass==0) {
1399 val = PLGetString(entry->plvalue);
1400 second_pass = 1;
1401 wwarning(_("using default \"%s\" instead"), val);
1402 goto again;
1404 return False;
1408 if (ret)
1409 *ret = &data;
1411 if (addr) {
1412 *(char*)addr = data;
1415 return True;
1419 static int
1420 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1421 void **ret)
1423 static int data;
1424 char *val;
1427 STRINGP("Integer");
1429 val = PLGetString(value);
1431 if (sscanf(val, "%i", &data)!=1) {
1432 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1433 val, entry->key);
1434 val = PLGetString(entry->plvalue);
1435 wwarning(_("using default \"%s\" instead"), val);
1436 if (sscanf(val, "%i", &data)!=1) {
1437 return False;
1441 if (ret)
1442 *ret = &data;
1444 if (addr) {
1445 *(int*)addr = data;
1447 return True;
1451 static int
1452 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1453 void **ret)
1455 static WCoord data;
1456 char *val_x, *val_y;
1457 int nelem, changed=0;
1458 proplist_t elem_x, elem_y;
1460 again:
1461 if (!PLIsArray(value)) {
1462 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1463 entry->key, "Coordinate");
1464 if (changed==0) {
1465 value = entry->plvalue;
1466 changed = 1;
1467 wwarning(_("using default \"%s\" instead"), entry->default_value);
1468 goto again;
1470 return False;
1473 nelem = PLGetNumberOfElements(value);
1474 if (nelem != 2) {
1475 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1476 entry->key);
1477 if (changed==0) {
1478 value = entry->plvalue;
1479 changed = 1;
1480 wwarning(_("using default \"%s\" instead"), entry->default_value);
1481 goto again;
1483 return False;
1486 elem_x = PLGetArrayElement(value, 0);
1487 elem_y = PLGetArrayElement(value, 1);
1489 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1490 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1491 entry->key);
1492 if (changed==0) {
1493 value = entry->plvalue;
1494 changed = 1;
1495 wwarning(_("using default \"%s\" instead"), entry->default_value);
1496 goto again;
1498 return False;
1501 val_x = PLGetString(elem_x);
1502 val_y = PLGetString(elem_y);
1504 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1505 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1506 if (changed==0) {
1507 value = entry->plvalue;
1508 changed = 1;
1509 wwarning(_("using default \"%s\" instead"), entry->default_value);
1510 goto again;
1512 return False;
1515 if (data.x < 0)
1516 data.x = 0;
1517 else if (data.x > scr->scr_width/3)
1518 data.x = scr->scr_width/3;
1519 if (data.y < 0)
1520 data.y = 0;
1521 else if (data.y > scr->scr_height/3)
1522 data.y = scr->scr_height/3;
1524 if (ret)
1525 *ret = &data;
1527 if (addr) {
1528 *(WCoord*)addr = data;
1531 return True;
1535 #if 0
1536 /* This function is not used at the moment. */
1537 static int
1538 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1539 void **ret)
1541 static char *data;
1543 STRINGP("String");
1545 data = PLGetString(value);
1547 if (!data) {
1548 data = PLGetString(entry->plvalue);
1549 if (!data)
1550 return False;
1553 if (ret)
1554 *ret = &data;
1556 if (addr)
1557 *(char**)addr = wstrdup(data);
1559 return True;
1561 #endif
1564 static int
1565 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1566 void **ret)
1568 static char *data;
1569 int i, count, len;
1570 char *ptr;
1571 proplist_t d;
1572 int changed=0;
1574 again:
1575 if (!PLIsArray(value)) {
1576 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1577 entry->key, "an array of paths");
1578 if (changed==0) {
1579 value = entry->plvalue;
1580 changed = 1;
1581 wwarning(_("using default \"%s\" instead"), entry->default_value);
1582 goto again;
1584 return False;
1587 i = 0;
1588 count = PLGetNumberOfElements(value);
1589 if (count < 1) {
1590 if (changed==0) {
1591 value = entry->plvalue;
1592 changed = 1;
1593 wwarning(_("using default \"%s\" instead"), entry->default_value);
1594 goto again;
1596 return False;
1599 len = 0;
1600 for (i=0; i<count; i++) {
1601 d = PLGetArrayElement(value, i);
1602 if (!d || !PLIsString(d)) {
1603 count = i;
1604 break;
1606 len += strlen(PLGetString(d))+1;
1609 ptr = data = wmalloc(len+1);
1611 for (i=0; i<count; i++) {
1612 d = PLGetArrayElement(value, i);
1613 if (!d || !PLIsString(d)) {
1614 break;
1616 strcpy(ptr, PLGetString(d));
1617 ptr += strlen(PLGetString(d));
1618 *ptr = ':';
1619 ptr++;
1621 ptr--; *(ptr--) = 0;
1623 if (*(char**)addr!=NULL) {
1624 free(*(char**)addr);
1626 *(char**)addr = data;
1628 return True;
1632 static int
1633 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1634 void **ret)
1636 static signed char data;
1638 data = string2index(entry->plkey, value, entry->default_value,
1639 (WOptionEnumeration*)entry->extra_data);
1640 if (data < 0)
1641 return False;
1643 if (ret)
1644 *ret = &data;
1646 if (addr)
1647 *(signed char*)addr = data;
1649 return True;
1655 * (solid <color>)
1656 * (hgradient <color> <color>)
1657 * (vgradient <color> <color>)
1658 * (dgradient <color> <color>)
1659 * (mhgradient <color> <color> ...)
1660 * (mvgradient <color> <color> ...)
1661 * (tpixmap <file> <color>)
1662 * (spixmap <file> <color>)
1663 * (cpixmap <file> <color>)
1664 * (thgradient <file> <opaqueness> <color> <color>)
1665 * (tvgradient <file> <opaqueness> <color> <color>)
1666 * (tdgradient <file> <opaqueness> <color> <color>)
1667 * (function <lib> <function> ...)
1670 static WTexture*
1671 parse_texture(WScreen *scr, proplist_t pl)
1673 proplist_t elem;
1674 char *val;
1675 int nelem;
1676 WTexture *texture=NULL;
1678 nelem = PLGetNumberOfElements(pl);
1679 if (nelem < 1)
1680 return NULL;
1683 elem = PLGetArrayElement(pl, 0);
1684 if (!elem || !PLIsString(elem))
1685 return NULL;
1686 val = PLGetString(elem);
1689 if (strcasecmp(val, "solid")==0) {
1690 XColor color;
1692 if (nelem != 2)
1693 return NULL;
1695 /* get color */
1697 elem = PLGetArrayElement(pl, 1);
1698 if (!elem || !PLIsString(elem))
1699 return NULL;
1700 val = PLGetString(elem);
1702 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1703 wwarning(_("\"%s\" is not a valid color name"), val);
1704 return NULL;
1707 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1708 } else if (strcasecmp(val, "dgradient")==0
1709 || strcasecmp(val, "vgradient")==0
1710 || strcasecmp(val, "hgradient")==0) {
1711 RColor color1, color2;
1712 XColor xcolor;
1713 int type;
1715 if (nelem != 3) {
1716 wwarning(_("bad number of arguments in gradient specification"));
1717 return NULL;
1720 if (val[0]=='d' || val[0]=='D')
1721 type = WTEX_DGRADIENT;
1722 else if (val[0]=='h' || val[0]=='H')
1723 type = WTEX_HGRADIENT;
1724 else
1725 type = WTEX_VGRADIENT;
1728 /* get from color */
1729 elem = PLGetArrayElement(pl, 1);
1730 if (!elem || !PLIsString(elem))
1731 return NULL;
1732 val = PLGetString(elem);
1734 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1735 wwarning(_("\"%s\" is not a valid color name"), val);
1736 return NULL;
1738 color1.alpha = 255;
1739 color1.red = xcolor.red >> 8;
1740 color1.green = xcolor.green >> 8;
1741 color1.blue = xcolor.blue >> 8;
1743 /* get to color */
1744 elem = PLGetArrayElement(pl, 2);
1745 if (!elem || !PLIsString(elem)) {
1746 return NULL;
1748 val = PLGetString(elem);
1750 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1751 wwarning(_("\"%s\" is not a valid color name"), val);
1752 return NULL;
1754 color2.alpha = 255;
1755 color2.red = xcolor.red >> 8;
1756 color2.green = xcolor.green >> 8;
1757 color2.blue = xcolor.blue >> 8;
1759 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1761 } else if (strcasecmp(val, "mhgradient")==0
1762 || strcasecmp(val, "mvgradient")==0
1763 || strcasecmp(val, "mdgradient")==0) {
1764 XColor color;
1765 RColor **colors;
1766 int i, count;
1767 int type;
1769 if (nelem < 3) {
1770 wwarning(_("too few arguments in multicolor gradient specification"));
1771 return NULL;
1774 if (val[1]=='h' || val[1]=='H')
1775 type = WTEX_MHGRADIENT;
1776 else if (val[1]=='v' || val[1]=='V')
1777 type = WTEX_MVGRADIENT;
1778 else
1779 type = WTEX_MDGRADIENT;
1781 count = nelem-1;
1783 colors = wmalloc(sizeof(RColor*)*(count+1));
1785 for (i=0; i<count; i++) {
1786 elem = PLGetArrayElement(pl, i+1);
1787 if (!elem || !PLIsString(elem)) {
1788 for (--i; i>=0; --i) {
1789 free(colors[i]);
1791 free(colors);
1792 return NULL;
1794 val = PLGetString(elem);
1796 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1797 wwarning(_("\"%s\" is not a valid color name"), val);
1798 for (--i; i>=0; --i) {
1799 free(colors[i]);
1801 free(colors);
1802 return NULL;
1803 } else {
1804 colors[i] = wmalloc(sizeof(RColor));
1805 colors[i]->red = color.red >> 8;
1806 colors[i]->green = color.green >> 8;
1807 colors[i]->blue = color.blue >> 8;
1810 colors[i] = NULL;
1812 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1813 } else if (strcasecmp(val, "spixmap")==0 ||
1814 strcasecmp(val, "cpixmap")==0 ||
1815 strcasecmp(val, "tpixmap")==0) {
1816 XColor color;
1817 int type;
1819 if (nelem != 3)
1820 return NULL;
1822 if (val[0] == 's' || val[0] == 'S')
1823 type = WTP_SCALE;
1824 else if (val[0] == 'c' || val[0] == 'C')
1825 type = WTP_CENTER;
1826 else
1827 type = WTP_TILE;
1829 /* get color */
1830 elem = PLGetArrayElement(pl, 2);
1831 if (!elem || !PLIsString(elem)) {
1832 return NULL;
1834 val = PLGetString(elem);
1836 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1837 wwarning(_("\"%s\" is not a valid color name"), val);
1838 return NULL;
1841 /* file name */
1842 elem = PLGetArrayElement(pl, 1);
1843 if (!elem || !PLIsString(elem))
1844 return NULL;
1845 val = PLGetString(elem);
1847 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1848 } else if (strcasecmp(val, "thgradient")==0
1849 || strcasecmp(val, "tvgradient")==0
1850 || strcasecmp(val, "tdgradient")==0) {
1851 RColor color1, color2;
1852 XColor xcolor;
1853 int opacity;
1854 int style;
1856 if (val[1]=='h' || val[1]=='H')
1857 style = WTEX_THGRADIENT;
1858 else if (val[1]=='v' || val[1]=='V')
1859 style = WTEX_TVGRADIENT;
1860 else
1861 style = WTEX_TDGRADIENT;
1863 if (nelem != 5) {
1864 wwarning(_("bad number of arguments in textured gradient specification"));
1865 return NULL;
1868 /* get from color */
1869 elem = PLGetArrayElement(pl, 3);
1870 if (!elem || !PLIsString(elem))
1871 return NULL;
1872 val = PLGetString(elem);
1874 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1875 wwarning(_("\"%s\" is not a valid color name"), val);
1876 return NULL;
1878 color1.alpha = 255;
1879 color1.red = xcolor.red >> 8;
1880 color1.green = xcolor.green >> 8;
1881 color1.blue = xcolor.blue >> 8;
1883 /* get to color */
1884 elem = PLGetArrayElement(pl, 4);
1885 if (!elem || !PLIsString(elem)) {
1886 return NULL;
1888 val = PLGetString(elem);
1890 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1891 wwarning(_("\"%s\" is not a valid color name"), val);
1892 return NULL;
1894 color2.alpha = 255;
1895 color2.red = xcolor.red >> 8;
1896 color2.green = xcolor.green >> 8;
1897 color2.blue = xcolor.blue >> 8;
1899 /* get opacity */
1900 elem = PLGetArrayElement(pl, 2);
1901 if (!elem || !PLIsString(elem))
1902 opacity = 128;
1903 else
1904 val = PLGetString(elem);
1906 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1907 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1908 opacity = 128;
1911 /* get file name */
1912 elem = PLGetArrayElement(pl, 1);
1913 if (!elem || !PLIsString(elem))
1914 return NULL;
1915 val = PLGetString(elem);
1917 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1918 val, opacity);
1920 #ifdef TEXTURE_PLUGIN
1921 else if (strcasecmp(val, "function")==0) {
1922 WTexFunction *function;
1923 void (*initFunc) (Display *, Colormap);
1924 char *lib, *func, **argv;
1925 int i, argc;
1927 if (nelem < 3)
1928 return NULL;
1930 /* get the library name */
1931 elem = PLGetArrayElement(pl, 1);
1932 if (!elem || !PLIsString(elem)) {
1933 return NULL;
1935 lib = PLGetString(elem);
1937 /* get the function name */
1938 elem = PLGetArrayElement(pl, 2);
1939 if (!elem || !PLIsString(elem)) {
1940 return NULL;
1942 func = PLGetString(elem);
1944 argc = nelem - 2;
1945 argv = (char **)wmalloc(argc * sizeof(char *));
1947 /* get the parameters */
1948 argv[0] = wstrdup(func);
1949 for (i = 0; i < argc - 1; i++) {
1950 elem = PLGetArrayElement(pl, 3 + i);
1951 if (!elem || !PLIsString(elem)) {
1952 free(argv);
1954 return NULL;
1956 argv[i+1] = wstrdup(PLGetString(elem));
1959 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1961 #ifdef HAVE_DLFCN_H
1962 if (function) {
1963 initFunc = dlsym(function->handle, "initWindowMaker");
1964 if (initFunc) {
1965 initFunc(dpy, scr->w_colormap);
1966 } else {
1967 wwarning(_("could not initialize library %s"), lib);
1969 } else {
1970 wwarning(_("could not find function %s::%s"), lib, func);
1972 #endif /* HAVE_DLFCN_H */
1973 texture = (WTexture*)function;
1975 #endif /* TEXTURE_PLUGIN */
1976 else {
1977 wwarning(_("invalid texture type %s"), val);
1978 return NULL;
1980 return texture;
1985 static int
1986 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1987 void **ret)
1989 static WTexture *texture;
1990 int changed=0;
1992 again:
1993 if (!PLIsArray(value)) {
1994 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1995 entry->key, "Texture");
1996 if (changed==0) {
1997 value = entry->plvalue;
1998 changed = 1;
1999 wwarning(_("using default \"%s\" instead"), entry->default_value);
2000 goto again;
2002 return False;
2005 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2006 proplist_t pl;
2008 pl = PLGetArrayElement(value, 0);
2009 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2010 || strcasecmp(PLGetString(pl), "solid")!=0) {
2011 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2012 entry->key, "Solid Texture");
2014 value = entry->plvalue;
2015 changed = 1;
2016 wwarning(_("using default \"%s\" instead"), entry->default_value);
2017 goto again;
2021 texture = parse_texture(scr, value);
2023 if (!texture) {
2024 wwarning(_("Error in texture specification for key \"%s\""),
2025 entry->key);
2026 if (changed==0) {
2027 value = entry->plvalue;
2028 changed = 1;
2029 wwarning(_("using default \"%s\" instead"), entry->default_value);
2030 goto again;
2032 return False;
2035 if (ret)
2036 *ret = &texture;
2038 if (addr)
2039 *(WTexture**)addr = texture;
2041 return True;
2046 #ifdef DRAWSTRING_PLUGIN
2047 static int
2048 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2049 void *addr, void **ret)
2051 proplist_t elem;
2052 char *val, *lib, *func, **argv;
2053 int argc, changed;
2055 if (strcmp(entry->key, "FTitleColor")==0) {
2056 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2057 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2058 } else if (strcmp(entry->key, "UTitleColor")==0) {
2059 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2060 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2061 } else if (strcmp(entry->key, "PTitleColor")==0) {
2062 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2063 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2064 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2065 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2066 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2067 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2068 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2069 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2072 if (PLIsArray(value)) {
2073 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2074 argc -= 2;
2075 argv = (char **)wmalloc(argc * sizeof(char *));
2077 elem = PLGetArrayElement(value,0);
2078 if (!elem || !PLIsString(elem)) return False;
2079 val = PLGetString(elem);
2080 if (strcasecmp(val, "function")==0) {
2081 elem = PLGetArrayElement(value, 1); /* library name */
2082 if (!elem || !PLIsString(elem)) return False;
2083 lib = PLGetString(elem);
2084 elem = PLGetArrayElement(value, 2); /* function name */
2085 if (!elem || !PLIsString(elem)) return False;
2086 func = PLGetString(elem);
2087 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2088 lib, "initDrawString", func, NULL, value,
2089 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2092 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2093 } else if (PLIsString(value)) {
2094 return getColor(scr, entry, value, addr, ret);
2097 return False;
2099 #endif /* DRAWSTRING_PLUGIN */
2103 static int
2104 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2105 void *addr, void **ret)
2107 proplist_t elem;
2108 int changed = 0;
2109 char *val;
2110 int nelem;
2112 again:
2113 if (!PLIsArray(value)) {
2114 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2115 "WorkspaceBack", "Texture or None");
2116 if (changed==0) {
2117 value = entry->plvalue;
2118 changed = 1;
2119 wwarning(_("using default \"%s\" instead"), entry->default_value);
2120 goto again;
2122 return False;
2125 /* only do basic error checking and verify for None texture */
2127 nelem = PLGetNumberOfElements(value);
2128 if (nelem > 0) {
2129 elem = PLGetArrayElement(value, 0);
2130 if (!elem || !PLIsString(elem)) {
2131 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2132 if (changed==0) {
2133 value = entry->plvalue;
2134 changed = 1;
2135 wwarning(_("using default \"%s\" instead"), entry->default_value);
2136 goto again;
2138 return False;
2140 val = PLGetString(elem);
2142 if (strcasecmp(val, "None")==0)
2143 return True;
2145 *ret = PLRetain(value);
2147 return True;
2151 static int
2152 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2153 void *addr, void **ret)
2155 proplist_t elem;
2156 int nelem;
2157 int changed = 0;
2159 again:
2160 if (!PLIsArray(value)) {
2161 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2162 "WorkspaceSpecificBack", "an array of textures");
2163 if (changed==0) {
2164 value = entry->plvalue;
2165 changed = 1;
2166 wwarning(_("using default \"%s\" instead"), entry->default_value);
2167 goto again;
2169 return False;
2172 /* only do basic error checking and verify for None texture */
2174 nelem = PLGetNumberOfElements(value);
2175 if (nelem > 0) {
2176 while (nelem--) {
2177 elem = PLGetArrayElement(value, nelem);
2178 if (!elem || !PLIsArray(elem)) {
2179 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2180 nelem);
2185 *ret = PLRetain(value);
2187 #ifdef notworking
2189 * Kluge to force wmsetbg helper to set the default background.
2190 * If the WorkspaceSpecificBack is changed once wmaker has started,
2191 * the WorkspaceBack won't be sent to the helper, unless the user
2192 * changes it's value too. So, we must force this by removing the
2193 * value from the defaults DB.
2195 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2196 proplist_t key = PLMakeString("WorkspaceBack");
2198 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2200 PLRelease(key);
2202 #endif
2203 return True;
2207 static int
2208 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2209 void **ret)
2211 static WMFont *font;
2212 char *val;
2214 STRINGP("Font");
2216 val = PLGetString(value);
2218 font = WMCreateFont(scr->wmscreen, val);
2219 if (!font)
2220 font = WMCreateFont(scr->wmscreen, "fixed");
2222 if (!font) {
2223 wfatal(_("could not load any usable font!!!"));
2224 exit(1);
2227 if (ret)
2228 *ret = font;
2230 /* can't assign font value outside update function */
2231 wassertrv(addr == NULL, True);
2233 return True;
2237 static int
2238 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2239 void **ret)
2241 static XColor color;
2242 char *val;
2243 int second_pass=0;
2245 STRINGP("Color");
2247 val = PLGetString(value);
2249 again:
2250 if (!wGetColor(scr, val, &color)) {
2251 wwarning(_("could not get color for key \"%s\""),
2252 entry->key);
2253 if (second_pass==0) {
2254 val = PLGetString(entry->plvalue);
2255 second_pass = 1;
2256 wwarning(_("using default \"%s\" instead"), val);
2257 goto again;
2259 return False;
2262 if (ret)
2263 *ret = &color;
2265 assert(addr==NULL);
2267 if (addr)
2268 *(unsigned long*)addr = pixel;
2271 return True;
2276 static int
2277 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2278 void **ret)
2280 static WShortKey shortcut;
2281 KeySym ksym;
2282 char *val;
2283 char *k;
2284 char buf[128], *b;
2287 STRINGP("Key spec");
2289 val = PLGetString(value);
2291 if (!val || strcasecmp(val, "NONE")==0) {
2292 shortcut.keycode = 0;
2293 shortcut.modifier = 0;
2294 if (ret)
2295 *ret = &shortcut;
2296 return True;
2299 strcpy(buf, val);
2301 b = (char*)buf;
2303 /* get modifiers */
2304 shortcut.modifier = 0;
2305 while ((k = strchr(b, '+'))!=NULL) {
2306 int mod;
2308 *k = 0;
2309 mod = wXModifierFromKey(b);
2310 if (mod<0) {
2311 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2312 return False;
2314 shortcut.modifier |= mod;
2316 b = k+1;
2319 /* get key */
2320 ksym = XStringToKeysym(b);
2322 if (ksym==NoSymbol) {
2323 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2324 val);
2325 return False;
2328 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2329 if (shortcut.keycode==0) {
2330 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2331 return False;
2334 if (ret)
2335 *ret = &shortcut;
2337 return True;
2341 static int
2342 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2343 void **ret)
2345 static unsigned int mask;
2346 char *str;
2348 STRINGP("Modifier Key");
2350 str = PLGetString(value);
2351 if (!str)
2352 return False;
2354 mask = wXModifierFromKey(str);
2355 if (mask < 0) {
2356 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2357 mask = 0;
2358 return False;
2361 if (addr)
2362 *(unsigned int*)addr = mask;
2364 if (ret)
2365 *ret = &mask;
2367 return True;
2371 #ifdef NEWSTUFF
2372 static int
2373 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2374 void *addr, void **ret)
2376 unsigned int mask;
2377 char *str;
2378 RImage *image;
2379 int i, n;
2380 int w, h;
2382 STRINGP("Image File Path");
2384 str = PLGetString(value);
2385 if (!str)
2386 return False;
2388 image = RLoadImage(scr->rcontext, str, 0);
2389 if (!image) {
2390 wwarning(_("could not load image in option %s: %s"), entry->key,
2391 RMessageForError(RErrorCode));
2392 return False;
2395 if (*(RImage**)addr) {
2396 RDestroyImage(*(RImage**)addr);
2398 if (addr)
2399 *(RImage**)addr = image;
2401 assert(ret == NULL);
2403 if (ret)
2404 *(RImage**)ret = image;
2407 return True;
2409 #endif
2412 /* ---------------- value setting functions --------------- */
2413 static int
2414 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2416 return REFRESH_WINDOW_TITLE_COLOR;
2420 static int
2421 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2423 switch (which) {
2424 case WM_DOCK:
2425 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2426 break;
2427 case WM_CLIP:
2428 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2429 break;
2430 default:
2431 break;
2433 return 0;
2437 static int
2438 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2440 if (scr->workspaces) {
2441 wWorkspaceForceChange(scr, scr->current_workspace);
2442 wArrangeIcons(scr, False);
2444 return 0;
2447 #if not_used
2448 static int
2449 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2451 if (*value <= 0)
2452 *(int*)foo = 1;
2454 return 0;
2456 #endif
2460 static int
2461 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2463 Pixmap pixmap;
2464 RImage *img;
2465 int reset = 0;
2467 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2468 wPreferences.icon_size,
2469 ((*texture)->any.type & WREL_BORDER_MASK)
2470 ? WREL_ICON : WREL_FLAT);
2471 if (!img) {
2472 wwarning(_("could not render texture for icon background"));
2473 if (!entry->addr)
2474 wTextureDestroy(scr, *texture);
2475 return 0;
2477 RConvertImage(scr->rcontext, img, &pixmap);
2479 if (scr->icon_tile) {
2480 reset = 1;
2481 RDestroyImage(scr->icon_tile);
2482 XFreePixmap(dpy, scr->icon_tile_pixmap);
2485 scr->icon_tile = img;
2487 if (!wPreferences.flags.noclip) {
2488 if (scr->clip_tile) {
2489 RDestroyImage(scr->clip_tile);
2491 scr->clip_tile = wClipMakeTile(scr, img);
2494 scr->icon_tile_pixmap = pixmap;
2496 if (scr->def_icon_pixmap) {
2497 XFreePixmap(dpy, scr->def_icon_pixmap);
2498 scr->def_icon_pixmap = None;
2500 if (scr->def_ticon_pixmap) {
2501 XFreePixmap(dpy, scr->def_ticon_pixmap);
2502 scr->def_ticon_pixmap = None;
2505 if (scr->icon_back_texture) {
2506 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2508 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2510 if (scr->clip_balloon)
2511 XSetWindowBackground(dpy, scr->clip_balloon,
2512 (*texture)->any.color.pixel);
2515 * Free the texture as nobody else will use it, nor refer to it.
2517 if (!entry->addr)
2518 wTextureDestroy(scr, *texture);
2520 return (reset ? REFRESH_ICON_TILE : 0);
2525 static int
2526 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2528 if (scr->title_font) {
2529 WMReleaseFont(scr->title_font);
2531 scr->title_font = font;
2533 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2537 static int
2538 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2540 if (scr->menu_title_font) {
2541 WMReleaseFont(scr->menu_title_font);
2544 scr->menu_title_font = font;
2546 return REFRESH_MENU_TITLE_FONT;
2550 static int
2551 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2553 if (scr->menu_entry_font) {
2554 WMReleaseFont(scr->menu_entry_font);
2556 scr->menu_entry_font = font;
2558 return REFRESH_MENU_FONT;
2563 static int
2564 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2566 if (scr->icon_title_font) {
2567 WMReleaseFont(scr->icon_title_font);
2570 scr->icon_title_font = font;
2572 return REFRESH_ICON_FONT;
2576 static int
2577 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2579 if (scr->clip_title_font) {
2580 WMReleaseFont(scr->clip_title_font);
2583 scr->clip_title_font = font;
2585 return REFRESH_ICON_FONT;
2589 static int
2590 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2592 if (scr->info_text_font) {
2593 WMReleaseFont(scr->info_text_font);
2596 scr->info_text_font = font;
2598 /* This test works because the scr structure is initially zeroed out
2599 and None = 0. Any other time, the window should be valid. */
2600 if (scr->geometry_display != None) {
2601 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2602 &scr->geometry_display_height);
2603 XResizeWindow(dpy, scr->geometry_display,
2604 scr->geometry_display_width, scr->geometry_display_height);
2607 return 0;
2611 static int
2612 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2614 if (scr->workspace_name_font) {
2615 WMReleaseFont(scr->workspace_name_font);
2618 scr->workspace_name_font = font;
2620 return 0;
2624 static int
2625 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2627 if (scr->select_pixel!=scr->white_pixel &&
2628 scr->select_pixel!=scr->black_pixel) {
2629 wFreeColor(scr, scr->select_pixel);
2632 scr->select_pixel = color->pixel;
2634 return REFRESH_MENU_COLOR;
2638 static int
2639 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2641 if (scr->select_text_pixel!=scr->white_pixel &&
2642 scr->select_text_pixel!=scr->black_pixel) {
2643 wFreeColor(scr, scr->select_text_pixel);
2646 scr->select_text_pixel = color->pixel;
2648 return REFRESH_MENU_COLOR;
2652 static int
2653 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2655 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2656 scr->clip_title_pixel[index]!=scr->black_pixel) {
2657 wFreeColor(scr, scr->clip_title_pixel[index]);
2659 scr->clip_title_pixel[index] = color->pixel;
2661 #ifdef GRADIENT_CLIP_ARROW
2662 if (index == CLIP_NORMAL) {
2663 RImage *image;
2664 RColor color1, color2;
2665 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2666 int as = pt - 15; /* 15 = 5+5+5 */
2668 FREE_PIXMAP(scr->clip_arrow_gradient);
2670 color1.red = (color->red >> 8)*6/10;
2671 color1.green = (color->green >> 8)*6/10;
2672 color1.blue = (color->blue >> 8)*6/10;
2674 color2.red = WMIN((color->red >> 8)*20/10, 255);
2675 color2.green = WMIN((color->green >> 8)*20/10, 255);
2676 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2678 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2679 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2680 RDestroyImage(image);
2682 #endif /* GRADIENT_CLIP_ARROW */
2684 return REFRESH_ICON_TITLE_COLOR;
2688 static int
2689 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2691 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2692 scr->window_title_pixel[index]!=scr->black_pixel) {
2693 wFreeColor(scr, scr->window_title_pixel[index]);
2696 scr->window_title_pixel[index] = color->pixel;
2698 if (index == WS_UNFOCUSED)
2699 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2701 return REFRESH_WINDOW_TITLE_COLOR;
2705 static int
2706 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2708 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2709 scr->menu_title_pixel[0]!=scr->black_pixel) {
2710 #ifdef DRAWSTRING_PLUGIN
2711 if(!scr->drawstring_func[W_STRING_MTITLE])
2712 #endif
2713 wFreeColor(scr, scr->menu_title_pixel[0]);
2716 scr->menu_title_pixel[0] = color->pixel;
2717 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2719 return REFRESH_MENU_TITLE_COLOR;
2723 static int
2724 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2726 XGCValues gcv;
2727 #define gcm (GCForeground|GCBackground|GCFillStyle)
2729 if (scr->mtext_pixel!=scr->white_pixel &&
2730 scr->mtext_pixel!=scr->black_pixel) {
2731 wFreeColor(scr, scr->mtext_pixel);
2734 scr->mtext_pixel = color->pixel;
2736 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2739 if (scr->dtext_pixel == scr->mtext_pixel) {
2740 gcv.foreground = scr->white_pixel;
2741 gcv.background = scr->black_pixel;
2742 gcv.fill_style = FillStippled;
2743 } else {
2744 gcv.foreground = scr->dtext_pixel;
2745 gcv.fill_style = FillSolid;
2747 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2749 return REFRESH_MENU_COLOR;
2750 #undef gcm
2754 static int
2755 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2757 XGCValues gcv;
2758 #define gcm (GCForeground|GCBackground|GCFillStyle)
2760 if (scr->dtext_pixel!=scr->white_pixel &&
2761 scr->dtext_pixel!=scr->black_pixel) {
2762 wFreeColor(scr, scr->dtext_pixel);
2765 scr->dtext_pixel = color->pixel;
2767 if (scr->dtext_pixel == scr->mtext_pixel) {
2768 gcv.foreground = scr->white_pixel;
2769 gcv.background = scr->black_pixel;
2770 gcv.fill_style = FillStippled;
2771 } else {
2772 gcv.foreground = scr->dtext_pixel;
2773 gcv.fill_style = FillSolid;
2775 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2777 return REFRESH_MENU_COLOR;
2778 #undef gcm
2781 static int
2782 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2784 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2786 return REFRESH_ICON_TITLE_COLOR;
2790 static int
2791 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2793 if (scr->icon_title_texture) {
2794 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2796 XQueryColor (dpy, scr->w_colormap, color);
2797 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2799 return REFRESH_ICON_TITLE_BACK;
2803 static void
2804 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2806 close(scr->helper_fd);
2807 scr->helper_fd = 0;
2808 scr->helper_pid = 0;
2809 scr->flags.backimage_helper_launched = 0;
2813 static int
2814 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2815 void *bar)
2817 int i;
2818 proplist_t val;
2819 char *str;
2821 if (scr->flags.backimage_helper_launched) {
2822 if (PLGetNumberOfElements(value)==0) {
2823 SendHelperMessage(scr, 'C', 0, NULL);
2824 SendHelperMessage(scr, 'K', 0, NULL);
2826 PLRelease(value);
2827 return 0;
2829 } else {
2830 pid_t pid;
2831 int filedes[2];
2833 if (PLGetNumberOfElements(value) == 0)
2834 return 0;
2836 if (pipe(filedes) < 0) {
2837 wsyserror("pipe() failed:can't set workspace specific background image");
2839 PLRelease(value);
2840 return 0;
2843 pid = fork();
2844 if (pid < 0) {
2845 wsyserror("fork() failed:can't set workspace specific background image");
2846 if (close(filedes[0]) < 0)
2847 wsyserror("could not close pipe");
2848 if (close(filedes[1]) < 0)
2849 wsyserror("could not close pipe");
2851 } else if (pid == 0) {
2852 SetupEnvironment(scr);
2854 if (close(0) < 0)
2855 wsyserror("could not close pipe");
2856 if (dup(filedes[0]) < 0) {
2857 wsyserror("dup() failed:can't set workspace specific background image");
2859 if (wPreferences.smooth_workspace_back)
2860 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
2861 else
2862 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2863 wsyserror("could not execute wmsetbg");
2864 exit(1);
2865 } else {
2867 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2868 wsyserror("error setting close-on-exec flag");
2870 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2871 wsyserror("error setting close-on-exec flag");
2874 scr->helper_fd = filedes[1];
2875 scr->helper_pid = pid;
2876 scr->flags.backimage_helper_launched = 1;
2878 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2880 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2885 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2886 val = PLGetArrayElement(value, i);
2887 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2888 str = PLGetDescription(val);
2890 SendHelperMessage(scr, 'S', i+1, str);
2892 free(str);
2893 } else {
2894 SendHelperMessage(scr, 'U', i+1, NULL);
2897 sleep(1);
2899 PLRelease(value);
2900 return 0;
2904 static int
2905 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2906 void *bar)
2908 if (scr->flags.backimage_helper_launched) {
2909 char *str;
2911 if (PLGetNumberOfElements(value)==0) {
2912 SendHelperMessage(scr, 'U', 0, NULL);
2913 } else {
2914 /* set the default workspace background to this one */
2915 str = PLGetDescription(value);
2916 if (str) {
2917 SendHelperMessage(scr, 'S', 0, str);
2918 free(str);
2919 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2920 } else {
2921 SendHelperMessage(scr, 'U', 0, NULL);
2924 } else {
2925 char *command;
2926 char *text;
2928 SetupEnvironment(scr);
2929 text = PLGetDescription(value);
2930 command = wmalloc(strlen(text)+40);
2931 if (wPreferences.smooth_workspace_back)
2932 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
2933 else
2934 sprintf(command, "wmsetbg -d -p '%s' &", text);
2935 free(text);
2936 system(command);
2937 free(command);
2939 PLRelease(value);
2941 return 0;
2945 static int
2946 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2948 if (scr->widget_texture) {
2949 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2951 scr->widget_texture = *(WTexSolid**)texture;
2953 if (scr->geometry_display != None)
2954 XSetWindowBackground(dpy, scr->geometry_display,
2955 scr->widget_texture->normal.pixel);
2957 return 0;
2961 static int
2962 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2964 if (scr->window_title_texture[WS_FOCUSED]) {
2965 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2967 scr->window_title_texture[WS_FOCUSED] = *texture;
2969 return REFRESH_WINDOW_TEXTURES;
2973 static int
2974 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2976 if (scr->window_title_texture[WS_PFOCUSED]) {
2977 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2979 scr->window_title_texture[WS_PFOCUSED] = *texture;
2981 return REFRESH_WINDOW_TEXTURES;
2985 static int
2986 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2988 if (scr->window_title_texture[WS_UNFOCUSED]) {
2989 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2991 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2993 return REFRESH_WINDOW_TEXTURES;
2997 static int
2998 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3000 if (scr->resizebar_texture[0]) {
3001 wTextureDestroy(scr, scr->resizebar_texture[0]);
3003 scr->resizebar_texture[0] = *texture;
3005 return REFRESH_WINDOW_TEXTURES;
3009 static int
3010 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3012 if (scr->menu_title_texture[0]) {
3013 wTextureDestroy(scr, scr->menu_title_texture[0]);
3015 scr->menu_title_texture[0] = *texture;
3017 return REFRESH_MENU_TITLE_TEXTURE;
3021 static int
3022 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3024 if (scr->menu_item_texture) {
3025 wTextureDestroy(scr, scr->menu_item_texture);
3026 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3028 scr->menu_item_texture = *texture;
3030 scr->menu_item_auxtexture
3031 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3033 return REFRESH_MENU_TEXTURE;
3037 static int
3038 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3040 WWindow *wwin;
3041 wKeyBindings[index] = *shortcut;
3043 wwin = scr->focused_window;
3045 while (wwin!=NULL) {
3046 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3048 if (!WFLAGP(wwin, no_bind_keys)) {
3049 wWindowSetKeyGrabs(wwin);
3051 wwin = wwin->prev;
3054 return 0;
3058 static int
3059 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3061 wArrangeIcons(scr, True);
3063 return 0;
3067 static int
3068 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3070 wScreenUpdateUsableArea(scr);
3072 return 0;
3076 static int
3077 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3079 return REFRESH_MENU_TEXTURE;
3084 static int
3085 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3087 return REFRESH_BUTTON_IMAGES;
3092 * Very ugly kluge.
3093 * Need access to the double click variables, so that all widgets in
3094 * wmaker panels will have the same dbl-click values.
3095 * TODO: figure a better way of dealing with it.
3097 #include "WINGsP.h"
3099 static int
3100 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3102 extern _WINGsConfiguration WINGsConfiguration;
3104 if (*value <= 0)
3105 *(int*)foo = 1;
3107 WINGsConfiguration.doubleClickDelay = *value;
3109 return 0;
3114 static int
3115 setMultiByte(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3117 extern _WINGsConfiguration WINGsConfiguration;
3119 WINGsConfiguration.useMultiByte = *value;
3121 return 0;