- Put back DisplayFont in defaults.c. It either was removed by error, or the
[wmaker-crm.git] / src / defaults.c
blob8ff4d9d34e63deef9d82e4a3bda8d3406b62ba63
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},
235 {"Smart", WPM_SMART, 0},
236 {"Cascade", WPM_CASCADE, 0},
237 {"Random", WPM_RANDOM, 0},
238 {"Manual", WPM_MANUAL, 0},
239 {NULL, 0, 0}
242 static WOptionEnumeration seGeomDisplays[] = {
243 {"Center", WDIS_CENTER, 0},
244 {"Corner", WDIS_TOPLEFT, 0},
245 {"Floating", WDIS_FRAME_CENTER, 0},
246 {"Line", WDIS_NEW, 0},
247 {NULL, 0, 0}
250 static WOptionEnumeration seSpeeds[] = {
251 {"UltraFast", SPEED_ULTRAFAST, 0},
252 {"Fast", SPEED_FAST, 0},
253 {"Medium", SPEED_MEDIUM, 0},
254 {"Slow", SPEED_SLOW, 0},
255 {"UltraSlow", SPEED_ULTRASLOW, 0},
256 {NULL, 0, 0}
259 static WOptionEnumeration seMouseButtons[] = {
260 {"None", -1, 0},
261 {"Left", Button1, 0}, {"Button1", Button1, 1},
262 {"Middle", Button2, 0}, {"Button2", Button2, 1},
263 {"Right", Button3, 0}, {"Button3", Button3, 1},
264 {"Button4", Button4, 0},
265 {"Button5", Button5, 0},
266 {NULL, 0, 0}
269 static WOptionEnumeration seIconificationStyles[] = {
270 {"Zoom", WIS_ZOOM, 0},
271 {"Twist", WIS_TWIST, 0},
272 {"Flip", WIS_FLIP, 0},
273 {"None", WIS_NONE, 0},
274 {"random", WIS_RANDOM, 0},
275 {NULL, 0, 0}
278 static WOptionEnumeration seJustifications[] = {
279 {"Left", WTJ_LEFT, 0},
280 {"Center", WTJ_CENTER, 0},
281 {"Right", WTJ_RIGHT, 0},
282 {NULL, 0, 0}
285 static WOptionEnumeration seIconPositions[] = {
286 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
287 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
288 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
289 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
290 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
291 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
292 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
293 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
294 {NULL, 0, 0}
297 static WOptionEnumeration seMenuStyles[] = {
298 {"normal", MS_NORMAL, 0},
299 {"singletexture", MS_SINGLE_TEXTURE, 0},
300 {"flat", MS_FLAT, 0},
301 {NULL, 0, 0}
305 static WOptionEnumeration seDisplayPositions[] = {
306 {"none", WD_NONE, 0},
307 {"center", WD_CENTER, 0},
308 {"top", WD_TOP, 0},
309 {"bottom", WD_BOTTOM, 0},
310 {"topleft", WD_TOPLEFT, 0},
311 {"topright", WD_TOPRIGHT, 0},
312 {"bottomleft", WD_BOTTOMLEFT, 0},
313 {"bottomright", WD_BOTTOMRIGHT, 0}
318 * ALL entries in the tables bellow, NEED to have a default value
319 * defined, and this value needs to be correct.
322 /* these options will only affect the window manager on startup
324 * static defaults can't access the screen data, because it is
325 * created after these defaults are read
327 WDefaultEntry staticOptionList[] = {
329 {"DisableDithering", "NO", NULL,
330 &wPreferences.no_dithering, getBool, NULL
332 {"ColormapSize", "4", NULL,
333 &wPreferences.cmap_size, getInt, NULL
335 /* static by laziness */
336 {"IconSize", "64", NULL,
337 &wPreferences.icon_size, getInt, NULL
339 {"ModifierKey", "Mod1", NULL,
340 &wPreferences.modifier_mask, getModMask, NULL
342 {"DisableWSMouseActions", "NO", NULL,
343 &wPreferences.disable_root_mouse, getBool, NULL
345 {"FocusMode", "manual", seFocusModes,
346 &wPreferences.focus_mode, getEnum, NULL
347 }, /* have a problem when switching from manual to sloppy without restart */
348 {"NewStyle", "NO", NULL,
349 &wPreferences.new_style, getBool, NULL
351 {"DisableDock", "NO", (void*) WM_DOCK,
352 NULL, getBool, setIfDockPresent
354 {"DisableClip", "NO", (void*) WM_CLIP,
355 NULL, getBool, setIfDockPresent
357 {"DisableMiniwindows", "NO", NULL,
358 &wPreferences.disable_miniwindows, getBool, NULL
360 {"MultiByteText", "NO", NULL,
361 &wPreferences.multi_byte_text, getBool, setMultiByte
367 WDefaultEntry optionList[] = {
368 /* dynamic options */
369 {"IconPosition", "blh", seIconPositions,
370 &wPreferences.icon_yard, getEnum, setIconPosition
372 {"IconificationStyle", "Zoom", seIconificationStyles,
373 &wPreferences.iconification_style, getEnum, NULL
375 {"SelectWindowsMouseButton", "Left", seMouseButtons,
376 &wPreferences.select_button, getEnum, NULL
378 {"WindowListMouseButton", "Middle", seMouseButtons,
379 &wPreferences.windowl_button, getEnum, NULL
381 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
382 &wPreferences.menu_button, getEnum, NULL
384 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
385 &wPreferences.pixmap_path, getPathList, NULL
387 {"IconPath", DEF_ICON_PATHS, NULL,
388 &wPreferences.icon_path, getPathList, NULL
390 {"ColormapMode", "auto", seColormapModes,
391 &wPreferences.colormap_mode, getEnum, NULL
393 {"AutoFocus", "NO", NULL,
394 &wPreferences.auto_focus, getBool, NULL
396 {"RaiseDelay", "0", NULL,
397 &wPreferences.raise_delay, getInt, NULL
399 {"CirculateRaise", "NO", NULL,
400 &wPreferences.circ_raise, getBool, NULL
402 {"Superfluous", "NO", NULL,
403 &wPreferences.superfluous, getBool, NULL
405 {"AdvanceToNewWorkspace", "NO", NULL,
406 &wPreferences.ws_advance, getBool, NULL
408 {"CycleWorkspaces", "NO", NULL,
409 &wPreferences.ws_cycle, getBool, NULL
411 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
412 &wPreferences.workspace_name_display_position, getEnum, NULL
414 #ifdef VIRTUAL_DESKTOP
415 {"VirtualEdgeThickness", "1", NULL,
416 &wPreferences.vedge_thickness, getInt, NULL
418 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
419 &wPreferences.vedge_hscrollspeed, getInt, NULL
421 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
422 &wPreferences.vedge_vscrollspeed, getInt, NULL
424 {"VirtualEdgeWidth", "2000", NULL,
425 &wPreferences.vedge_width, getInt, NULL
427 {"VirtualEdgeHeight", "2000", NULL,
428 &wPreferences.vedge_height, getInt, NULL
430 #endif
431 {"StickyIcons", "NO", NULL,
432 &wPreferences.sticky_icons, getBool, setStickyIcons
434 {"SaveSessionOnExit", "NO", NULL,
435 &wPreferences.save_session_on_exit, getBool, NULL
437 {"WrapMenus", "NO", NULL,
438 &wPreferences.wrap_menus, getBool, NULL
440 {"ScrollableMenus", "NO", NULL,
441 &wPreferences.scrollable_menus, getBool, NULL
443 {"MenuScrollSpeed", "medium", seSpeeds,
444 &wPreferences.menu_scroll_speed, getEnum, NULL
446 {"IconSlideSpeed", "medium", seSpeeds,
447 &wPreferences.icon_slide_speed, getEnum, NULL
449 {"ShadeSpeed", "medium", seSpeeds,
450 &wPreferences.shade_speed, getEnum, NULL
452 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
453 &wPreferences.dblclick_time, getInt, setDoubleClick,
455 {"AlignSubmenus", "NO", NULL,
456 &wPreferences.align_menus, getBool, NULL
458 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
459 &wPreferences.open_transients_with_parent, getBool, NULL
461 {"WindowPlacement", "auto", sePlacements,
462 &wPreferences.window_placement, getEnum, NULL
464 {"IgnoreFocusClick","NO", NULL,
465 &wPreferences.ignore_focus_click, getBool, NULL
467 {"UseSaveUnders", "NO", NULL,
468 &wPreferences.use_saveunders, getBool, NULL
470 {"OpaqueMove", "NO", NULL,
471 &wPreferences.opaque_move, getBool, NULL
473 {"DisableSound", "NO", NULL,
474 &wPreferences.no_sound, getBool, NULL
476 {"DisableAnimations", "NO", NULL,
477 &wPreferences.no_animations, getBool, NULL
479 {"DontLinkWorkspaces","NO", NULL,
480 &wPreferences.no_autowrap, getBool, NULL
482 {"AutoArrangeIcons", "NO", NULL,
483 &wPreferences.auto_arrange_icons, getBool, NULL
485 {"NoWindowOverDock", "NO", NULL,
486 &wPreferences.no_window_over_dock, getBool, updateUsableArea
488 {"NoWindowOverIcons", "NO", NULL,
489 &wPreferences.no_window_over_icons, getBool, updateUsableArea
491 {"WindowPlaceOrigin", "(0, 0)", NULL,
492 &wPreferences.window_place_origin, getCoord, NULL
494 {"ResizeDisplay", "corner", seGeomDisplays,
495 &wPreferences.size_display, getEnum, NULL
497 {"MoveDisplay", "corner", seGeomDisplays,
498 &wPreferences.move_display, getEnum, NULL
500 {"DontConfirmKill", "NO", NULL,
501 &wPreferences.dont_confirm_kill, getBool,NULL
503 {"WindowTitleBalloons", "NO", NULL,
504 &wPreferences.window_balloon, getBool, NULL
506 {"MiniwindowTitleBalloons", "NO", NULL,
507 &wPreferences.miniwin_balloon,getBool, NULL
509 {"AppIconBalloons", "NO", NULL,
510 &wPreferences.appicon_balloon,getBool, NULL
512 {"HelpBalloons", "NO", NULL,
513 &wPreferences.help_balloon, getBool, NULL
515 {"EdgeResistance", "30", NULL,
516 &wPreferences.edge_resistance,getInt, NULL
518 {"Attraction", "NO", NULL,
519 &wPreferences.attract, getBool, NULL
521 {"DisableBlinking", "NO", NULL,
522 &wPreferences.dont_blink, getBool, NULL
524 #ifdef WEENDOZE_CYCLE
525 {"WindozeCycling","NO", NULL,
526 &wPreferences.windoze_cycling, getBool, NULL
528 {"PopupSwitchMenu","YES", NULL,
529 &wPreferences.popup_switchmenu, getBool, NULL
531 #endif /* WEENDOZE_CYCLE */
532 /* style options */
533 {"MenuStyle", "normal", seMenuStyles,
534 &wPreferences.menu_style, getEnum, setMenuStyle
536 {"WidgetColor", "(solid, gray)", NULL,
537 NULL, getTexture, setWidgetColor,
539 {"WorkspaceSpecificBack","()", NULL,
540 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
542 /* WorkspaceBack must come after WorkspaceSpecificBack or
543 * WorkspaceBack wont know WorkspaceSpecificBack was also
544 * specified and 2 copies of wmsetbg will be launched */
545 {"WorkspaceBack", "(solid, black)", NULL,
546 NULL, getWSBackground,setWorkspaceBack
548 {"SmoothWorkspaceBack", "NO", NULL,
549 NULL, getBool, NULL
551 {"IconBack", "(solid, gray)", NULL,
552 NULL, getTexture, setIconTile
554 {"TitleJustify", "center", seJustifications,
555 &wPreferences.title_justification, getEnum, setJustify
557 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
558 NULL, getFont, setWinTitleFont,
560 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
561 NULL, getFont, setMenuTitleFont
563 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
564 NULL, getFont, setMenuTextFont
566 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
567 NULL, getFont, setIconTitleFont
569 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
570 NULL, getFont, setClipTitleFont
572 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
573 NULL, getFont, setDisplayFont
575 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
576 NULL, getFont, setLargeDisplayFont
578 {"HighlightColor", "white", NULL,
579 NULL, getColor, setHightlight
581 {"HighlightTextColor", "black", NULL,
582 NULL, getColor, setHightlightText
584 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
585 NULL, getColor, setClipTitleColor
587 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
588 NULL, getColor, setClipTitleColor
590 #ifdef DRAWSTRING_PLUGIN
591 {"FTitleColor", "white", (void*)WS_FOCUSED,
592 NULL, getTextRenderer, setWTitleColor
594 {"PTitleColor", "white", (void*)WS_PFOCUSED,
595 NULL, getTextRenderer, setWTitleColor
597 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
598 NULL, getTextRenderer, setWTitleColor
600 #else
601 {"FTitleColor", "white", (void*)WS_FOCUSED,
602 NULL, getColor, setWTitleColor
604 {"PTitleColor", "white", (void*)WS_PFOCUSED,
605 NULL, getColor, setWTitleColor
607 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
608 NULL, getColor, setWTitleColor
610 #endif
611 {"FTitleBack", "(solid, black)", NULL,
612 NULL, getTexture, setFTitleBack
614 {"PTitleBack", "(solid, \"#616161\")", NULL,
615 NULL, getTexture, setPTitleBack
617 {"UTitleBack", "(solid, gray)", NULL,
618 NULL, getTexture, setUTitleBack
620 {"ResizebarBack", "(solid, gray)", NULL,
621 NULL, getTexture, setResizebarBack
623 #ifdef DRAWSTRING_PLUGIN
624 {"MenuTitleColor", "white", NULL,
625 NULL, getTextRenderer, setMenuTitleColor
627 #else
628 {"MenuTitleColor", "white", NULL,
629 NULL, getColor, setMenuTitleColor
631 #endif
632 {"MenuTextColor", "black", NULL,
633 NULL, getColor, setMenuTextColor
635 {"MenuDisabledColor", "\"#616161\"", NULL,
636 NULL, getColor, setMenuDisabledColor
638 {"MenuTitleBack", "(solid, black)", NULL,
639 NULL, getTexture, setMenuTitleBack
641 {"MenuTextBack", "(solid, gray)", NULL,
642 NULL, getTexture, setMenuTextBack
644 {"IconTitleColor", "white", NULL,
645 NULL, getColor, setIconTitleColor
647 {"IconTitleBack", "black", NULL,
648 NULL, getColor, setIconTitleBack
650 /* keybindings */
651 #ifndef LITE
652 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
653 NULL, getKeybind, setKeyGrab
655 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
656 NULL, getKeybind, setKeyGrab
658 #endif /* LITE */
659 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
660 NULL, getKeybind, setKeyGrab
662 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
663 NULL, getKeybind, setKeyGrab
665 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
666 NULL, getKeybind, setKeyGrab
668 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
669 NULL, getKeybind, setKeyGrab
671 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
672 NULL, getKeybind, setKeyGrab
674 {"HideKey", "None", (void*)WKBD_HIDE,
675 NULL, getKeybind, setKeyGrab
677 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
678 NULL, getKeybind, setKeyGrab
680 {"CloseKey", "None", (void*)WKBD_CLOSE,
681 NULL, getKeybind, setKeyGrab
683 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
684 NULL, getKeybind, setKeyGrab
686 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
687 NULL, getKeybind, setKeyGrab
689 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
690 NULL, getKeybind, setKeyGrab
692 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
693 NULL, getKeybind, setKeyGrab
695 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
696 NULL, getKeybind, setKeyGrab
698 {"ShadeKey", "None", (void*)WKBD_SHADE,
699 NULL, getKeybind, setKeyGrab
701 {"SelectKey", "None", (void*)WKBD_SELECT,
702 NULL, getKeybind, setKeyGrab
704 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
705 NULL, getKeybind, setKeyGrab
707 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
708 NULL, getKeybind, setKeyGrab
710 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
711 NULL, getKeybind, setKeyGrab
713 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
714 NULL, getKeybind, setKeyGrab
716 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
717 NULL, getKeybind, setKeyGrab
719 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
720 NULL, getKeybind, setKeyGrab
722 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
723 NULL, getKeybind, setKeyGrab
725 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
726 NULL, getKeybind, setKeyGrab
728 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
729 NULL, getKeybind, setKeyGrab
731 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
732 NULL, getKeybind, setKeyGrab
734 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
735 NULL, getKeybind, setKeyGrab
737 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
738 NULL, getKeybind, setKeyGrab
740 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
741 NULL, getKeybind, setKeyGrab
743 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
744 NULL, getKeybind, setKeyGrab
746 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
747 NULL, getKeybind, setKeyGrab
749 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
750 NULL, getKeybind, setKeyGrab
752 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
753 NULL, getKeybind, setKeyGrab
755 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
756 NULL, getKeybind, setKeyGrab
758 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
759 NULL, getKeybind, setKeyGrab
761 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
762 NULL, getKeybind, setKeyGrab
764 #ifdef EXTEND_WINDOWSHORTCUT
765 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
766 NULL, getKeybind, setKeyGrab
768 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
769 NULL, getKeybind, setKeyGrab
771 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
772 NULL, getKeybind, setKeyGrab
774 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
775 NULL, getKeybind, setKeyGrab
777 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
778 NULL, getKeybind, setKeyGrab
780 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
781 NULL, getKeybind, setKeyGrab
783 #endif /* EXTEND_WINDOWSHORTCUT */
785 #ifdef KEEP_XKB_LOCK_STATUS
786 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
787 NULL, getKeybind, setKeyGrab
789 {"KbdModeLock", "NO", NULL,
790 &wPreferences.modelock, getBool, NULL
792 #endif /* KEEP_XKB_LOCK_STATUS */
796 #if 0
797 static void rereadDefaults(void);
798 #endif
800 #if 0
801 static void
802 rereadDefaults(void)
804 /* must defer the update because accessing X data from a
805 * signal handler can mess up Xlib */
808 #endif
810 static void
811 initDefaults()
813 int i;
814 WDefaultEntry *entry;
816 PLSetStringCmpHook(StringCompareHook);
818 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
819 entry = &optionList[i];
821 entry->plkey = PLMakeString(entry->key);
822 if (entry->default_value)
823 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
824 else
825 entry->plvalue = NULL;
828 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
829 entry = &staticOptionList[i];
831 entry->plkey = PLMakeString(entry->key);
832 if (entry->default_value)
833 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
834 else
835 entry->plvalue = NULL;
839 wDomainName = PLMakeString(WMDOMAIN_NAME);
840 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
842 PLRegister(wDomainName, rereadDefaults);
843 PLRegister(wAttributeDomainName, rereadDefaults);
850 #if 0
851 proplist_t
852 wDefaultsInit(int screen_number)
854 static int defaults_inited = 0;
855 proplist_t dict;
857 if (!defaults_inited) {
858 initDefaults();
861 dict = PLGetDomain(wDomainName);
862 if (!dict) {
863 wwarning(_("could not read domain \"%s\" from defaults database"),
864 PLGetString(wDomainName));
867 return dict;
869 #endif
872 void
873 wDefaultsDestroyDomain(WDDomain *domain)
875 if (domain->dictionary)
876 PLRelease(domain->dictionary);
877 free(domain->path);
878 free(domain);
882 WDDomain*
883 wDefaultsInitDomain(char *domain, Bool requireDictionary)
885 WDDomain *db;
886 struct stat stbuf;
887 static int inited = 0;
888 char path[PATH_MAX];
889 char *the_path;
890 proplist_t shared_dict=NULL;
892 if (!inited) {
893 inited = 1;
894 initDefaults();
897 db = wmalloc(sizeof(WDDomain));
898 memset(db, 0, sizeof(WDDomain));
899 db->domain_name = domain;
900 db->path = wdefaultspathfordomain(domain);
901 the_path = db->path;
903 if (the_path && stat(the_path, &stbuf)>=0) {
904 db->dictionary = ReadProplistFromFile(the_path);
905 if (db->dictionary) {
906 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
907 PLRelease(db->dictionary);
908 db->dictionary = NULL;
909 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
910 domain, the_path);
912 db->timestamp = stbuf.st_mtime;
913 } else {
914 wwarning(_("could not load domain %s from user defaults database"),
915 domain);
919 /* global system dictionary */
920 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
921 if (stat(path, &stbuf)>=0) {
922 shared_dict = ReadProplistFromFile(path);
923 if (shared_dict) {
924 if (requireDictionary && !PLIsDictionary(shared_dict)) {
925 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
926 domain, path);
927 PLRelease(shared_dict);
928 shared_dict = NULL;
929 } else {
930 if (db->dictionary && PLIsDictionary(shared_dict) &&
931 PLIsDictionary(db->dictionary)) {
932 PLMergeDictionaries(shared_dict, db->dictionary);
933 PLRelease(db->dictionary);
934 db->dictionary = shared_dict;
935 if (stbuf.st_mtime > db->timestamp)
936 db->timestamp = stbuf.st_mtime;
937 } else if (!db->dictionary) {
938 db->dictionary = shared_dict;
939 if (stbuf.st_mtime > db->timestamp)
940 db->timestamp = stbuf.st_mtime;
943 } else {
944 wwarning(_("could not load domain %s from global defaults database (%s)"),
945 domain, path);
949 /* set to save it in user's directory, no matter from where it was read */
950 if (db->dictionary) {
951 proplist_t tmp = PLMakeString(db->path);
953 PLSetFilename(db->dictionary, tmp);
954 PLRelease(tmp);
957 return db;
961 void
962 wReadStaticDefaults(proplist_t dict)
964 proplist_t plvalue;
965 WDefaultEntry *entry;
966 int i;
967 void *tdata;
970 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
971 entry = &staticOptionList[i];
973 if (dict)
974 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
975 else
976 plvalue = NULL;
978 if (!plvalue) {
979 /* no default in the DB. Use builtin default */
980 plvalue = entry->plvalue;
983 if (plvalue) {
984 /* convert data */
985 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
986 if (entry->update) {
987 (*entry->update)(NULL, entry, tdata, entry->extra_data);
994 void
995 wDefaultsCheckDomains(void *foo)
997 WScreen *scr;
998 struct stat stbuf;
999 proplist_t dict;
1000 int i;
1001 char path[PATH_MAX];
1003 #ifdef HEARTBEAT
1004 puts("Checking domains...");
1005 #endif
1006 if (stat(WDWindowMaker->path, &stbuf)>=0
1007 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1008 proplist_t shared_dict = NULL;
1009 #ifdef HEARTBEAT
1010 puts("Checking WindowMaker domain");
1011 #endif
1012 WDWindowMaker->timestamp = stbuf.st_mtime;
1014 /* global dictionary */
1015 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1016 if (stat(path, &stbuf)>=0) {
1017 shared_dict = ReadProplistFromFile(path);
1018 if (shared_dict && !PLIsDictionary(shared_dict)) {
1019 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1020 "WindowMaker", path);
1021 PLRelease(shared_dict);
1022 shared_dict = NULL;
1023 } else if (!shared_dict) {
1024 wwarning(_("could not load domain %s from global defaults database"),
1025 "WindowMaker");
1028 /* user dictionary */
1029 dict = ReadProplistFromFile(WDWindowMaker->path);
1030 if (dict) {
1031 if (!PLIsDictionary(dict)) {
1032 PLRelease(dict);
1033 dict = NULL;
1034 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1035 "WindowMaker", WDWindowMaker->path);
1036 } else {
1037 if (shared_dict) {
1038 PLSetFilename(shared_dict, PLGetFilename(dict));
1039 PLMergeDictionaries(shared_dict, dict);
1040 PLRelease(dict);
1041 dict = shared_dict;
1042 shared_dict = NULL;
1044 for (i=0; i<wScreenCount; i++) {
1045 scr = wScreenWithNumber(i);
1046 if (scr)
1047 wReadDefaults(scr, dict);
1049 if (WDWindowMaker->dictionary) {
1050 PLRelease(WDWindowMaker->dictionary);
1052 WDWindowMaker->dictionary = dict;
1054 } else {
1055 wwarning(_("could not load domain %s from user defaults database"),
1056 "WindowMaker");
1058 if (shared_dict) {
1059 PLRelease(shared_dict);
1063 if (stat(WDWindowAttributes->path, &stbuf)>=0
1064 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1065 #ifdef HEARTBEAT
1066 puts("Checking WMWindowAttributes domain");
1067 #endif
1068 dict = ReadProplistFromFile(WDWindowAttributes->path);
1069 if (dict) {
1070 if (!PLIsDictionary(dict)) {
1071 PLRelease(dict);
1072 dict = NULL;
1073 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1074 "WMWindowAttributes", WDWindowAttributes->path);
1075 } else {
1076 if (WDWindowAttributes->dictionary)
1077 PLRelease(WDWindowAttributes->dictionary);
1078 WDWindowAttributes->dictionary = dict;
1079 for (i=0; i<wScreenCount; i++) {
1080 scr = wScreenWithNumber(i);
1081 if (scr)
1082 wDefaultUpdateIcons(scr);
1085 } else {
1086 wwarning(_("could not load domain %s from user defaults database"),
1087 "WMWindowAttributes");
1089 WDWindowAttributes->timestamp = stbuf.st_mtime;
1092 #ifndef LITE
1093 if (stat(WDRootMenu->path, &stbuf)>=0
1094 && WDRootMenu->timestamp < stbuf.st_mtime) {
1095 dict = ReadProplistFromFile(WDRootMenu->path);
1096 #ifdef HEARTBEAT
1097 puts("Checking WMRootMenu domain");
1098 #endif
1099 if (dict) {
1100 if (!PLIsArray(dict) && !PLIsString(dict)) {
1101 PLRelease(dict);
1102 dict = NULL;
1103 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1104 "WMRootMenu", WDRootMenu->path);
1105 } else {
1106 if (WDRootMenu->dictionary) {
1107 PLRelease(WDRootMenu->dictionary);
1109 WDRootMenu->dictionary = dict;
1111 } else {
1112 wwarning(_("could not load domain %s from user defaults database"),
1113 "WMRootMenu");
1115 WDRootMenu->timestamp = stbuf.st_mtime;
1117 #endif /* !LITE */
1119 if (!foo)
1120 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1124 void
1125 wReadDefaults(WScreen *scr, proplist_t new_dict)
1127 proplist_t plvalue, old_value;
1128 WDefaultEntry *entry;
1129 int i, must_update;
1130 int update_workspace_back = 0; /* kluge :/ */
1131 int needs_refresh;
1132 void *tdata;
1133 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1134 ? WDWindowMaker->dictionary : NULL);
1136 must_update = 0;
1138 needs_refresh = 0;
1140 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1141 entry = &optionList[i];
1143 if (new_dict)
1144 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1145 else
1146 plvalue = NULL;
1148 if (!old_dict)
1149 old_value = NULL;
1150 else
1151 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1154 if (!plvalue && !old_value) {
1155 /* no default in the DB. Use builtin default */
1156 plvalue = entry->plvalue;
1157 if (plvalue && new_dict) {
1158 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1159 must_update = 1;
1161 } else if (!plvalue) {
1162 /* value was deleted from DB. Keep current value */
1163 continue;
1164 } else if (!old_value) {
1165 /* set value for the 1st time */
1166 } else if (!PLIsEqual(plvalue, old_value)) {
1167 /* value has changed */
1168 } else {
1170 if (strcmp(entry->key, "WorkspaceBack") == 0
1171 && update_workspace_back
1172 && scr->flags.backimage_helper_launched) {
1173 } else {
1174 /* value was not changed since last time */
1175 continue;
1179 if (plvalue) {
1180 #ifdef DEBUG
1181 printf("Updating %s to %s\n", entry->key,
1182 PLGetDescription(plvalue));
1183 #endif
1184 /* convert data */
1185 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1187 * If the WorkspaceSpecificBack data has been changed
1188 * so that the helper will be launched now, we must be
1189 * sure to send the default background texture config
1190 * to the helper.
1192 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1193 && !scr->flags.backimage_helper_launched) {
1194 update_workspace_back = 1;
1196 if (entry->update) {
1197 needs_refresh |=
1198 (*entry->update)(scr, entry, tdata, entry->extra_data);
1204 if (needs_refresh!=0 && !scr->flags.startup) {
1205 int foo;
1207 foo = 0;
1208 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1209 foo |= WTextureSettings;
1210 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1211 foo |= WFontSettings;
1212 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1213 foo |= WColorSettings;
1214 if (foo)
1215 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1216 (void*)foo);
1218 foo = 0;
1219 if (needs_refresh & REFRESH_MENU_TEXTURE)
1220 foo |= WTextureSettings;
1221 if (needs_refresh & REFRESH_MENU_FONT)
1222 foo |= WFontSettings;
1223 if (needs_refresh & REFRESH_MENU_COLOR)
1224 foo |= WColorSettings;
1225 if (foo)
1226 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1227 (void*)foo);
1229 foo = 0;
1230 if (needs_refresh & REFRESH_WINDOW_FONT) {
1231 foo |= WFontSettings;
1233 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1234 foo |= WTextureSettings;
1236 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1237 foo |= WColorSettings;
1239 if (foo)
1240 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1241 (void*)foo);
1243 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1244 foo = 0;
1245 if (needs_refresh & REFRESH_ICON_FONT) {
1246 foo |= WFontSettings;
1248 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1249 foo |= WTextureSettings;
1251 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1252 foo |= WTextureSettings;
1254 if (foo)
1255 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1256 (void*)foo);
1258 if (needs_refresh & REFRESH_ICON_TILE)
1259 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1264 void
1265 wDefaultUpdateIcons(WScreen *scr)
1267 WAppIcon *aicon = scr->app_icon_list;
1268 WWindow *wwin = scr->focused_window;
1269 char *file;
1271 while(aicon) {
1272 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1273 False);
1274 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1275 || (file && !aicon->icon->file)) {
1276 RImage *new_image;
1278 if (aicon->icon->file)
1279 free(aicon->icon->file);
1280 aicon->icon->file = wstrdup(file);
1282 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1283 aicon->wm_class);
1284 if (new_image) {
1285 wIconChangeImage(aicon->icon, new_image);
1286 wAppIconPaint(aicon);
1289 aicon = aicon->next;
1292 if (!wPreferences.flags.noclip)
1293 wClipIconPaint(scr->clip_icon);
1295 while (wwin) {
1296 if (wwin->icon && wwin->flags.miniaturized) {
1297 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1298 False);
1299 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1300 || (file && !wwin->icon->file)) {
1301 RImage *new_image;
1303 if (wwin->icon->file)
1304 free(wwin->icon->file);
1305 wwin->icon->file = wstrdup(file);
1307 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1308 wwin->wm_class);
1309 if (new_image)
1310 wIconChangeImage(wwin->icon, new_image);
1313 wwin = wwin->prev;
1318 /* --------------------------- Local ----------------------- */
1320 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1321 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1322 entry->key, x); \
1323 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1324 var = entry->default_value;\
1325 } else var = PLGetString(value)\
1331 static int
1332 string2index(proplist_t key, proplist_t val, proplist_t def,
1333 WOptionEnumeration *values)
1335 char *str;
1336 WOptionEnumeration *v;
1337 char buffer[TOTAL_VALUES_LENGTH];
1339 if (PLIsString(val) && (str = PLGetString(val))) {
1340 for (v=values; v->string!=NULL; v++) {
1341 if (strcasecmp(v->string, str)==0)
1342 return v->value;
1346 buffer[0] = 0;
1347 for (v=values; v->string!=NULL; v++) {
1348 if (!v->is_alias) {
1349 if (buffer[0]!=0)
1350 strcat(buffer, ", ");
1351 strcat(buffer, v->string);
1354 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1355 PLGetString(key), buffer);
1357 if (def) {
1358 return string2index(key, val, NULL, values);
1361 return -1;
1368 * value - is the value in the defaults DB
1369 * addr - is the address to store the data
1370 * ret - is the address to store a pointer to a temporary buffer. ret
1371 * must not be freed and is used by the set functions
1373 static int
1374 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1375 void **ret)
1377 static char data;
1378 char *val;
1379 int second_pass=0;
1381 GET_STRING_OR_DEFAULT("Boolean", val);
1383 again:
1384 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1385 || strcasecmp(val, "YES")==0) {
1387 data = 1;
1388 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1389 || strcasecmp(val, "NO")==0) {
1390 data = 0;
1391 } else {
1392 int i;
1393 if (sscanf(val, "%i", &i)==1) {
1394 if (i!=0)
1395 data = 1;
1396 else
1397 data = 0;
1398 } else {
1399 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1400 val, entry->key);
1401 if (second_pass==0) {
1402 val = PLGetString(entry->plvalue);
1403 second_pass = 1;
1404 wwarning(_("using default \"%s\" instead"), val);
1405 goto again;
1407 return False;
1411 if (ret)
1412 *ret = &data;
1414 if (addr) {
1415 *(char*)addr = data;
1418 return True;
1422 static int
1423 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1424 void **ret)
1426 static int data;
1427 char *val;
1430 GET_STRING_OR_DEFAULT("Integer", val);
1432 if (sscanf(val, "%i", &data)!=1) {
1433 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1434 val, entry->key);
1435 val = PLGetString(entry->plvalue);
1436 wwarning(_("using default \"%s\" instead"), val);
1437 if (sscanf(val, "%i", &data)!=1) {
1438 return False;
1442 if (ret)
1443 *ret = &data;
1445 if (addr) {
1446 *(int*)addr = data;
1448 return True;
1452 static int
1453 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1454 void **ret)
1456 static WCoord data;
1457 char *val_x, *val_y;
1458 int nelem, changed=0;
1459 proplist_t elem_x, elem_y;
1461 again:
1462 if (!PLIsArray(value)) {
1463 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1464 entry->key, "Coordinate");
1465 if (changed==0) {
1466 value = entry->plvalue;
1467 changed = 1;
1468 wwarning(_("using default \"%s\" instead"), entry->default_value);
1469 goto again;
1471 return False;
1474 nelem = PLGetNumberOfElements(value);
1475 if (nelem != 2) {
1476 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1477 entry->key);
1478 if (changed==0) {
1479 value = entry->plvalue;
1480 changed = 1;
1481 wwarning(_("using default \"%s\" instead"), entry->default_value);
1482 goto again;
1484 return False;
1487 elem_x = PLGetArrayElement(value, 0);
1488 elem_y = PLGetArrayElement(value, 1);
1490 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1491 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1492 entry->key);
1493 if (changed==0) {
1494 value = entry->plvalue;
1495 changed = 1;
1496 wwarning(_("using default \"%s\" instead"), entry->default_value);
1497 goto again;
1499 return False;
1502 val_x = PLGetString(elem_x);
1503 val_y = PLGetString(elem_y);
1505 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1506 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1507 if (changed==0) {
1508 value = entry->plvalue;
1509 changed = 1;
1510 wwarning(_("using default \"%s\" instead"), entry->default_value);
1511 goto again;
1513 return False;
1516 if (data.x < 0)
1517 data.x = 0;
1518 else if (data.x > scr->scr_width/3)
1519 data.x = scr->scr_width/3;
1520 if (data.y < 0)
1521 data.y = 0;
1522 else if (data.y > scr->scr_height/3)
1523 data.y = scr->scr_height/3;
1525 if (ret)
1526 *ret = &data;
1528 if (addr) {
1529 *(WCoord*)addr = data;
1532 return True;
1536 #if 0
1537 /* This function is not used at the moment. */
1538 static int
1539 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1540 void **ret)
1542 static char *data;
1544 GET_STRING_OR_DEFAULT("String", data);
1546 if (!data) {
1547 data = PLGetString(entry->plvalue);
1548 if (!data)
1549 return False;
1552 if (ret)
1553 *ret = &data;
1555 if (addr)
1556 *(char**)addr = wstrdup(data);
1558 return True;
1560 #endif
1563 static int
1564 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1565 void **ret)
1567 static char *data;
1568 int i, count, len;
1569 char *ptr;
1570 proplist_t d;
1571 int changed=0;
1573 again:
1574 if (!PLIsArray(value)) {
1575 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1576 entry->key, "an array of paths");
1577 if (changed==0) {
1578 value = entry->plvalue;
1579 changed = 1;
1580 wwarning(_("using default \"%s\" instead"), entry->default_value);
1581 goto again;
1583 return False;
1586 i = 0;
1587 count = PLGetNumberOfElements(value);
1588 if (count < 1) {
1589 if (changed==0) {
1590 value = entry->plvalue;
1591 changed = 1;
1592 wwarning(_("using default \"%s\" instead"), entry->default_value);
1593 goto again;
1595 return False;
1598 len = 0;
1599 for (i=0; i<count; i++) {
1600 d = PLGetArrayElement(value, i);
1601 if (!d || !PLIsString(d)) {
1602 count = i;
1603 break;
1605 len += strlen(PLGetString(d))+1;
1608 ptr = data = wmalloc(len+1);
1610 for (i=0; i<count; i++) {
1611 d = PLGetArrayElement(value, i);
1612 if (!d || !PLIsString(d)) {
1613 break;
1615 strcpy(ptr, PLGetString(d));
1616 ptr += strlen(PLGetString(d));
1617 *ptr = ':';
1618 ptr++;
1620 ptr--; *(ptr--) = 0;
1622 if (*(char**)addr!=NULL) {
1623 free(*(char**)addr);
1625 *(char**)addr = data;
1627 return True;
1631 static int
1632 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1633 void **ret)
1635 static signed char data;
1637 data = string2index(entry->plkey, value, entry->default_value,
1638 (WOptionEnumeration*)entry->extra_data);
1639 if (data < 0)
1640 return False;
1642 if (ret)
1643 *ret = &data;
1645 if (addr)
1646 *(signed char*)addr = data;
1648 return True;
1654 * (solid <color>)
1655 * (hgradient <color> <color>)
1656 * (vgradient <color> <color>)
1657 * (dgradient <color> <color>)
1658 * (mhgradient <color> <color> ...)
1659 * (mvgradient <color> <color> ...)
1660 * (tpixmap <file> <color>)
1661 * (spixmap <file> <color>)
1662 * (cpixmap <file> <color>)
1663 * (thgradient <file> <opaqueness> <color> <color>)
1664 * (tvgradient <file> <opaqueness> <color> <color>)
1665 * (tdgradient <file> <opaqueness> <color> <color>)
1666 * (function <lib> <function> ...)
1669 static WTexture*
1670 parse_texture(WScreen *scr, proplist_t pl)
1672 proplist_t elem;
1673 char *val;
1674 int nelem;
1675 WTexture *texture=NULL;
1677 nelem = PLGetNumberOfElements(pl);
1678 if (nelem < 1)
1679 return NULL;
1682 elem = PLGetArrayElement(pl, 0);
1683 if (!elem || !PLIsString(elem))
1684 return NULL;
1685 val = PLGetString(elem);
1688 if (strcasecmp(val, "solid")==0) {
1689 XColor color;
1691 if (nelem != 2)
1692 return NULL;
1694 /* get color */
1696 elem = PLGetArrayElement(pl, 1);
1697 if (!elem || !PLIsString(elem))
1698 return NULL;
1699 val = PLGetString(elem);
1701 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1702 wwarning(_("\"%s\" is not a valid color name"), val);
1703 return NULL;
1706 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1707 } else if (strcasecmp(val, "dgradient")==0
1708 || strcasecmp(val, "vgradient")==0
1709 || strcasecmp(val, "hgradient")==0) {
1710 RColor color1, color2;
1711 XColor xcolor;
1712 int type;
1714 if (nelem != 3) {
1715 wwarning(_("bad number of arguments in gradient specification"));
1716 return NULL;
1719 if (val[0]=='d' || val[0]=='D')
1720 type = WTEX_DGRADIENT;
1721 else if (val[0]=='h' || val[0]=='H')
1722 type = WTEX_HGRADIENT;
1723 else
1724 type = WTEX_VGRADIENT;
1727 /* get from color */
1728 elem = PLGetArrayElement(pl, 1);
1729 if (!elem || !PLIsString(elem))
1730 return NULL;
1731 val = PLGetString(elem);
1733 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1734 wwarning(_("\"%s\" is not a valid color name"), val);
1735 return NULL;
1737 color1.alpha = 255;
1738 color1.red = xcolor.red >> 8;
1739 color1.green = xcolor.green >> 8;
1740 color1.blue = xcolor.blue >> 8;
1742 /* get to color */
1743 elem = PLGetArrayElement(pl, 2);
1744 if (!elem || !PLIsString(elem)) {
1745 return NULL;
1747 val = PLGetString(elem);
1749 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1750 wwarning(_("\"%s\" is not a valid color name"), val);
1751 return NULL;
1753 color2.alpha = 255;
1754 color2.red = xcolor.red >> 8;
1755 color2.green = xcolor.green >> 8;
1756 color2.blue = xcolor.blue >> 8;
1758 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1760 } else if (strcasecmp(val, "mhgradient")==0
1761 || strcasecmp(val, "mvgradient")==0
1762 || strcasecmp(val, "mdgradient")==0) {
1763 XColor color;
1764 RColor **colors;
1765 int i, count;
1766 int type;
1768 if (nelem < 3) {
1769 wwarning(_("too few arguments in multicolor gradient specification"));
1770 return NULL;
1773 if (val[1]=='h' || val[1]=='H')
1774 type = WTEX_MHGRADIENT;
1775 else if (val[1]=='v' || val[1]=='V')
1776 type = WTEX_MVGRADIENT;
1777 else
1778 type = WTEX_MDGRADIENT;
1780 count = nelem-1;
1782 colors = wmalloc(sizeof(RColor*)*(count+1));
1784 for (i=0; i<count; i++) {
1785 elem = PLGetArrayElement(pl, i+1);
1786 if (!elem || !PLIsString(elem)) {
1787 for (--i; i>=0; --i) {
1788 free(colors[i]);
1790 free(colors);
1791 return NULL;
1793 val = PLGetString(elem);
1795 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1796 wwarning(_("\"%s\" is not a valid color name"), val);
1797 for (--i; i>=0; --i) {
1798 free(colors[i]);
1800 free(colors);
1801 return NULL;
1802 } else {
1803 colors[i] = wmalloc(sizeof(RColor));
1804 colors[i]->red = color.red >> 8;
1805 colors[i]->green = color.green >> 8;
1806 colors[i]->blue = color.blue >> 8;
1809 colors[i] = NULL;
1811 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1812 } else if (strcasecmp(val, "spixmap")==0 ||
1813 strcasecmp(val, "cpixmap")==0 ||
1814 strcasecmp(val, "tpixmap")==0) {
1815 XColor color;
1816 int type;
1818 if (nelem != 3)
1819 return NULL;
1821 if (val[0] == 's' || val[0] == 'S')
1822 type = WTP_SCALE;
1823 else if (val[0] == 'c' || val[0] == 'C')
1824 type = WTP_CENTER;
1825 else
1826 type = WTP_TILE;
1828 /* get color */
1829 elem = PLGetArrayElement(pl, 2);
1830 if (!elem || !PLIsString(elem)) {
1831 return NULL;
1833 val = PLGetString(elem);
1835 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1836 wwarning(_("\"%s\" is not a valid color name"), val);
1837 return NULL;
1840 /* file name */
1841 elem = PLGetArrayElement(pl, 1);
1842 if (!elem || !PLIsString(elem))
1843 return NULL;
1844 val = PLGetString(elem);
1846 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1847 } else if (strcasecmp(val, "thgradient")==0
1848 || strcasecmp(val, "tvgradient")==0
1849 || strcasecmp(val, "tdgradient")==0) {
1850 RColor color1, color2;
1851 XColor xcolor;
1852 int opacity;
1853 int style;
1855 if (val[1]=='h' || val[1]=='H')
1856 style = WTEX_THGRADIENT;
1857 else if (val[1]=='v' || val[1]=='V')
1858 style = WTEX_TVGRADIENT;
1859 else
1860 style = WTEX_TDGRADIENT;
1862 if (nelem != 5) {
1863 wwarning(_("bad number of arguments in textured gradient specification"));
1864 return NULL;
1867 /* get from color */
1868 elem = PLGetArrayElement(pl, 3);
1869 if (!elem || !PLIsString(elem))
1870 return NULL;
1871 val = PLGetString(elem);
1873 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1874 wwarning(_("\"%s\" is not a valid color name"), val);
1875 return NULL;
1877 color1.alpha = 255;
1878 color1.red = xcolor.red >> 8;
1879 color1.green = xcolor.green >> 8;
1880 color1.blue = xcolor.blue >> 8;
1882 /* get to color */
1883 elem = PLGetArrayElement(pl, 4);
1884 if (!elem || !PLIsString(elem)) {
1885 return NULL;
1887 val = PLGetString(elem);
1889 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1890 wwarning(_("\"%s\" is not a valid color name"), val);
1891 return NULL;
1893 color2.alpha = 255;
1894 color2.red = xcolor.red >> 8;
1895 color2.green = xcolor.green >> 8;
1896 color2.blue = xcolor.blue >> 8;
1898 /* get opacity */
1899 elem = PLGetArrayElement(pl, 2);
1900 if (!elem || !PLIsString(elem))
1901 opacity = 128;
1902 else
1903 val = PLGetString(elem);
1905 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1906 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1907 opacity = 128;
1910 /* get file name */
1911 elem = PLGetArrayElement(pl, 1);
1912 if (!elem || !PLIsString(elem))
1913 return NULL;
1914 val = PLGetString(elem);
1916 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1917 val, opacity);
1919 #ifdef TEXTURE_PLUGIN
1920 else if (strcasecmp(val, "function")==0) {
1921 WTexFunction *function;
1922 void (*initFunc) (Display *, Colormap);
1923 char *lib, *func, **argv;
1924 int i, argc;
1926 if (nelem < 3)
1927 return NULL;
1929 /* get the library name */
1930 elem = PLGetArrayElement(pl, 1);
1931 if (!elem || !PLIsString(elem)) {
1932 return NULL;
1934 lib = PLGetString(elem);
1936 /* get the function name */
1937 elem = PLGetArrayElement(pl, 2);
1938 if (!elem || !PLIsString(elem)) {
1939 return NULL;
1941 func = PLGetString(elem);
1943 argc = nelem - 2;
1944 argv = (char **)wmalloc(argc * sizeof(char *));
1946 /* get the parameters */
1947 argv[0] = wstrdup(func);
1948 for (i = 0; i < argc - 1; i++) {
1949 elem = PLGetArrayElement(pl, 3 + i);
1950 if (!elem || !PLIsString(elem)) {
1951 free(argv);
1953 return NULL;
1955 argv[i+1] = wstrdup(PLGetString(elem));
1958 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1960 #ifdef HAVE_DLFCN_H
1961 if (function) {
1962 initFunc = dlsym(function->handle, "initWindowMaker");
1963 if (initFunc) {
1964 initFunc(dpy, scr->w_colormap);
1965 } else {
1966 wwarning(_("could not initialize library %s"), lib);
1968 } else {
1969 wwarning(_("could not find function %s::%s"), lib, func);
1971 #endif /* HAVE_DLFCN_H */
1972 texture = (WTexture*)function;
1974 #endif /* TEXTURE_PLUGIN */
1975 else {
1976 wwarning(_("invalid texture type %s"), val);
1977 return NULL;
1979 return texture;
1984 static int
1985 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1986 void **ret)
1988 static WTexture *texture;
1989 int changed=0;
1991 again:
1992 if (!PLIsArray(value)) {
1993 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1994 entry->key, "Texture");
1995 if (changed==0) {
1996 value = entry->plvalue;
1997 changed = 1;
1998 wwarning(_("using default \"%s\" instead"), entry->default_value);
1999 goto again;
2001 return False;
2004 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2005 proplist_t pl;
2007 pl = PLGetArrayElement(value, 0);
2008 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2009 || strcasecmp(PLGetString(pl), "solid")!=0) {
2010 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2011 entry->key, "Solid Texture");
2013 value = entry->plvalue;
2014 changed = 1;
2015 wwarning(_("using default \"%s\" instead"), entry->default_value);
2016 goto again;
2020 texture = parse_texture(scr, value);
2022 if (!texture) {
2023 wwarning(_("Error in texture specification for key \"%s\""),
2024 entry->key);
2025 if (changed==0) {
2026 value = entry->plvalue;
2027 changed = 1;
2028 wwarning(_("using default \"%s\" instead"), entry->default_value);
2029 goto again;
2031 return False;
2034 if (ret)
2035 *ret = &texture;
2037 if (addr)
2038 *(WTexture**)addr = texture;
2040 return True;
2045 #ifdef DRAWSTRING_PLUGIN
2046 static int
2047 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2048 void *addr, void **ret)
2050 proplist_t elem;
2051 char *val, *lib, *func, **argv;
2052 int argc, changed;
2054 if (strcmp(entry->key, "FTitleColor")==0) {
2055 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2056 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2057 } else if (strcmp(entry->key, "UTitleColor")==0) {
2058 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2059 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2060 } else if (strcmp(entry->key, "PTitleColor")==0) {
2061 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2062 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2063 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2064 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2065 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2066 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2067 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2068 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2071 if (PLIsArray(value)) {
2072 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2073 argc -= 2;
2074 argv = (char **)wmalloc(argc * sizeof(char *));
2076 elem = PLGetArrayElement(value,0);
2077 if (!elem || !PLIsString(elem)) return False;
2078 val = PLGetString(elem);
2079 if (strcasecmp(val, "function")==0) {
2080 elem = PLGetArrayElement(value, 1); /* library name */
2081 if (!elem || !PLIsString(elem)) return False;
2082 lib = PLGetString(elem);
2083 elem = PLGetArrayElement(value, 2); /* function name */
2084 if (!elem || !PLIsString(elem)) return False;
2085 func = PLGetString(elem);
2086 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2087 lib, "initDrawString", func, NULL, value,
2088 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2091 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2092 } else if (PLIsString(value)) {
2093 return getColor(scr, entry, value, addr, ret);
2096 return False;
2098 #endif /* DRAWSTRING_PLUGIN */
2102 static int
2103 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2104 void *addr, void **ret)
2106 proplist_t elem;
2107 int changed = 0;
2108 char *val;
2109 int nelem;
2111 again:
2112 if (!PLIsArray(value)) {
2113 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2114 "WorkspaceBack", "Texture or None");
2115 if (changed==0) {
2116 value = entry->plvalue;
2117 changed = 1;
2118 wwarning(_("using default \"%s\" instead"), entry->default_value);
2119 goto again;
2121 return False;
2124 /* only do basic error checking and verify for None texture */
2126 nelem = PLGetNumberOfElements(value);
2127 if (nelem > 0) {
2128 elem = PLGetArrayElement(value, 0);
2129 if (!elem || !PLIsString(elem)) {
2130 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2131 if (changed==0) {
2132 value = entry->plvalue;
2133 changed = 1;
2134 wwarning(_("using default \"%s\" instead"), entry->default_value);
2135 goto again;
2137 return False;
2139 val = PLGetString(elem);
2141 if (strcasecmp(val, "None")==0)
2142 return True;
2144 *ret = PLRetain(value);
2146 return True;
2150 static int
2151 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2152 void *addr, void **ret)
2154 proplist_t elem;
2155 int nelem;
2156 int changed = 0;
2158 again:
2159 if (!PLIsArray(value)) {
2160 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2161 "WorkspaceSpecificBack", "an array of textures");
2162 if (changed==0) {
2163 value = entry->plvalue;
2164 changed = 1;
2165 wwarning(_("using default \"%s\" instead"), entry->default_value);
2166 goto again;
2168 return False;
2171 /* only do basic error checking and verify for None texture */
2173 nelem = PLGetNumberOfElements(value);
2174 if (nelem > 0) {
2175 while (nelem--) {
2176 elem = PLGetArrayElement(value, nelem);
2177 if (!elem || !PLIsArray(elem)) {
2178 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2179 nelem);
2184 *ret = PLRetain(value);
2186 #ifdef notworking
2188 * Kluge to force wmsetbg helper to set the default background.
2189 * If the WorkspaceSpecificBack is changed once wmaker has started,
2190 * the WorkspaceBack won't be sent to the helper, unless the user
2191 * changes it's value too. So, we must force this by removing the
2192 * value from the defaults DB.
2194 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2195 proplist_t key = PLMakeString("WorkspaceBack");
2197 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2199 PLRelease(key);
2201 #endif
2202 return True;
2206 static int
2207 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2208 void **ret)
2210 static WMFont *font;
2211 char *val;
2213 GET_STRING_OR_DEFAULT("Font", val);
2215 font = WMCreateFont(scr->wmscreen, val);
2216 if (!font)
2217 font = WMCreateFont(scr->wmscreen, "fixed");
2219 if (!font) {
2220 wfatal(_("could not load any usable font!!!"));
2221 exit(1);
2224 if (ret)
2225 *ret = font;
2227 /* can't assign font value outside update function */
2228 wassertrv(addr == NULL, True);
2230 return True;
2234 static int
2235 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2236 void **ret)
2238 static XColor color;
2239 char *val;
2240 int second_pass=0;
2242 GET_STRING_OR_DEFAULT("Color", val);
2245 again:
2246 if (!wGetColor(scr, val, &color)) {
2247 wwarning(_("could not get color for key \"%s\""),
2248 entry->key);
2249 if (second_pass==0) {
2250 val = PLGetString(entry->plvalue);
2251 second_pass = 1;
2252 wwarning(_("using default \"%s\" instead"), val);
2253 goto again;
2255 return False;
2258 if (ret)
2259 *ret = &color;
2261 assert(addr==NULL);
2263 if (addr)
2264 *(unsigned long*)addr = pixel;
2267 return True;
2272 static int
2273 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2274 void **ret)
2276 static WShortKey shortcut;
2277 KeySym ksym;
2278 char *val;
2279 char *k;
2280 char buf[128], *b;
2283 GET_STRING_OR_DEFAULT("Key spec", val);
2285 if (!val || strcasecmp(val, "NONE")==0) {
2286 shortcut.keycode = 0;
2287 shortcut.modifier = 0;
2288 if (ret)
2289 *ret = &shortcut;
2290 return True;
2293 strcpy(buf, val);
2295 b = (char*)buf;
2297 /* get modifiers */
2298 shortcut.modifier = 0;
2299 while ((k = strchr(b, '+'))!=NULL) {
2300 int mod;
2302 *k = 0;
2303 mod = wXModifierFromKey(b);
2304 if (mod<0) {
2305 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2306 return False;
2308 shortcut.modifier |= mod;
2310 b = k+1;
2313 /* get key */
2314 ksym = XStringToKeysym(b);
2316 if (ksym==NoSymbol) {
2317 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2318 val);
2319 return False;
2322 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2323 if (shortcut.keycode==0) {
2324 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2325 return False;
2328 if (ret)
2329 *ret = &shortcut;
2331 return True;
2335 static int
2336 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2337 void **ret)
2339 static unsigned int mask;
2340 char *str;
2342 GET_STRING_OR_DEFAULT("Modifier Key", str);
2344 if (!str)
2345 return False;
2347 mask = wXModifierFromKey(str);
2348 if (mask < 0) {
2349 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2350 mask = 0;
2351 return False;
2354 if (addr)
2355 *(unsigned int*)addr = mask;
2357 if (ret)
2358 *ret = &mask;
2360 return True;
2364 #ifdef NEWSTUFF
2365 static int
2366 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2367 void *addr, void **ret)
2369 unsigned int mask;
2370 char *str;
2371 RImage *image;
2372 int i, n;
2373 int w, h;
2375 GET_STRING_OR_DEFAULT("Image File Path", str);
2376 if (!str)
2377 return False;
2379 image = RLoadImage(scr->rcontext, str, 0);
2380 if (!image) {
2381 wwarning(_("could not load image in option %s: %s"), entry->key,
2382 RMessageForError(RErrorCode));
2383 return False;
2386 if (*(RImage**)addr) {
2387 RDestroyImage(*(RImage**)addr);
2389 if (addr)
2390 *(RImage**)addr = image;
2392 assert(ret == NULL);
2394 if (ret)
2395 *(RImage**)ret = image;
2398 return True;
2400 #endif
2403 /* ---------------- value setting functions --------------- */
2404 static int
2405 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2407 return REFRESH_WINDOW_TITLE_COLOR;
2411 static int
2412 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2414 switch (which) {
2415 case WM_DOCK:
2416 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2417 break;
2418 case WM_CLIP:
2419 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2420 break;
2421 default:
2422 break;
2424 return 0;
2428 static int
2429 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2431 if (scr->workspaces) {
2432 wWorkspaceForceChange(scr, scr->current_workspace);
2433 wArrangeIcons(scr, False);
2435 return 0;
2438 #if not_used
2439 static int
2440 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2442 if (*value <= 0)
2443 *(int*)foo = 1;
2445 return 0;
2447 #endif
2451 static int
2452 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2454 Pixmap pixmap;
2455 RImage *img;
2456 int reset = 0;
2458 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2459 wPreferences.icon_size,
2460 ((*texture)->any.type & WREL_BORDER_MASK)
2461 ? WREL_ICON : WREL_FLAT);
2462 if (!img) {
2463 wwarning(_("could not render texture for icon background"));
2464 if (!entry->addr)
2465 wTextureDestroy(scr, *texture);
2466 return 0;
2468 RConvertImage(scr->rcontext, img, &pixmap);
2470 if (scr->icon_tile) {
2471 reset = 1;
2472 RDestroyImage(scr->icon_tile);
2473 XFreePixmap(dpy, scr->icon_tile_pixmap);
2476 scr->icon_tile = img;
2478 if (!wPreferences.flags.noclip) {
2479 if (scr->clip_tile) {
2480 RDestroyImage(scr->clip_tile);
2482 scr->clip_tile = wClipMakeTile(scr, img);
2485 scr->icon_tile_pixmap = pixmap;
2487 if (scr->def_icon_pixmap) {
2488 XFreePixmap(dpy, scr->def_icon_pixmap);
2489 scr->def_icon_pixmap = None;
2491 if (scr->def_ticon_pixmap) {
2492 XFreePixmap(dpy, scr->def_ticon_pixmap);
2493 scr->def_ticon_pixmap = None;
2496 if (scr->icon_back_texture) {
2497 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2499 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2501 if (scr->clip_balloon)
2502 XSetWindowBackground(dpy, scr->clip_balloon,
2503 (*texture)->any.color.pixel);
2506 * Free the texture as nobody else will use it, nor refer to it.
2508 if (!entry->addr)
2509 wTextureDestroy(scr, *texture);
2511 return (reset ? REFRESH_ICON_TILE : 0);
2516 static int
2517 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2519 if (scr->title_font) {
2520 WMReleaseFont(scr->title_font);
2522 scr->title_font = font;
2524 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2528 static int
2529 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2531 if (scr->menu_title_font) {
2532 WMReleaseFont(scr->menu_title_font);
2535 scr->menu_title_font = font;
2537 return REFRESH_MENU_TITLE_FONT;
2541 static int
2542 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2544 if (scr->menu_entry_font) {
2545 WMReleaseFont(scr->menu_entry_font);
2547 scr->menu_entry_font = font;
2549 return REFRESH_MENU_FONT;
2554 static int
2555 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2557 if (scr->icon_title_font) {
2558 WMReleaseFont(scr->icon_title_font);
2561 scr->icon_title_font = font;
2563 return REFRESH_ICON_FONT;
2567 static int
2568 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2570 if (scr->clip_title_font) {
2571 WMReleaseFont(scr->clip_title_font);
2574 scr->clip_title_font = font;
2576 return REFRESH_ICON_FONT;
2580 static int
2581 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2583 if (scr->info_text_font) {
2584 WMReleaseFont(scr->info_text_font);
2587 scr->info_text_font = font;
2589 /* This test works because the scr structure is initially zeroed out
2590 and None = 0. Any other time, the window should be valid. */
2591 if (scr->geometry_display != None) {
2592 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2593 &scr->geometry_display_height);
2594 XResizeWindow(dpy, scr->geometry_display,
2595 scr->geometry_display_width, scr->geometry_display_height);
2598 return 0;
2602 static int
2603 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2605 if (scr->workspace_name_font) {
2606 WMReleaseFont(scr->workspace_name_font);
2609 scr->workspace_name_font = font;
2611 return 0;
2615 static int
2616 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2618 if (scr->select_pixel!=scr->white_pixel &&
2619 scr->select_pixel!=scr->black_pixel) {
2620 wFreeColor(scr, scr->select_pixel);
2623 scr->select_pixel = color->pixel;
2625 return REFRESH_MENU_COLOR;
2629 static int
2630 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2632 if (scr->select_text_pixel!=scr->white_pixel &&
2633 scr->select_text_pixel!=scr->black_pixel) {
2634 wFreeColor(scr, scr->select_text_pixel);
2637 scr->select_text_pixel = color->pixel;
2639 return REFRESH_MENU_COLOR;
2643 static int
2644 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2646 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2647 scr->clip_title_pixel[index]!=scr->black_pixel) {
2648 wFreeColor(scr, scr->clip_title_pixel[index]);
2650 scr->clip_title_pixel[index] = color->pixel;
2652 #ifdef GRADIENT_CLIP_ARROW
2653 if (index == CLIP_NORMAL) {
2654 RImage *image;
2655 RColor color1, color2;
2656 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2657 int as = pt - 15; /* 15 = 5+5+5 */
2659 FREE_PIXMAP(scr->clip_arrow_gradient);
2661 color1.red = (color->red >> 8)*6/10;
2662 color1.green = (color->green >> 8)*6/10;
2663 color1.blue = (color->blue >> 8)*6/10;
2665 color2.red = WMIN((color->red >> 8)*20/10, 255);
2666 color2.green = WMIN((color->green >> 8)*20/10, 255);
2667 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2669 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2670 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2671 RDestroyImage(image);
2673 #endif /* GRADIENT_CLIP_ARROW */
2675 return REFRESH_ICON_TITLE_COLOR;
2679 static int
2680 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2682 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2683 scr->window_title_pixel[index]!=scr->black_pixel) {
2684 wFreeColor(scr, scr->window_title_pixel[index]);
2687 scr->window_title_pixel[index] = color->pixel;
2689 if (index == WS_UNFOCUSED)
2690 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2692 return REFRESH_WINDOW_TITLE_COLOR;
2696 static int
2697 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2699 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2700 scr->menu_title_pixel[0]!=scr->black_pixel) {
2701 #ifdef DRAWSTRING_PLUGIN
2702 if(!scr->drawstring_func[W_STRING_MTITLE])
2703 #endif
2704 wFreeColor(scr, scr->menu_title_pixel[0]);
2707 scr->menu_title_pixel[0] = color->pixel;
2708 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2710 return REFRESH_MENU_TITLE_COLOR;
2714 static int
2715 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2717 XGCValues gcv;
2718 #define gcm (GCForeground|GCBackground|GCFillStyle)
2720 if (scr->mtext_pixel!=scr->white_pixel &&
2721 scr->mtext_pixel!=scr->black_pixel) {
2722 wFreeColor(scr, scr->mtext_pixel);
2725 scr->mtext_pixel = color->pixel;
2727 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2730 if (scr->dtext_pixel == scr->mtext_pixel) {
2731 gcv.foreground = scr->white_pixel;
2732 gcv.background = scr->black_pixel;
2733 gcv.fill_style = FillStippled;
2734 } else {
2735 gcv.foreground = scr->dtext_pixel;
2736 gcv.fill_style = FillSolid;
2738 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2740 return REFRESH_MENU_COLOR;
2741 #undef gcm
2745 static int
2746 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2748 XGCValues gcv;
2749 #define gcm (GCForeground|GCBackground|GCFillStyle)
2751 if (scr->dtext_pixel!=scr->white_pixel &&
2752 scr->dtext_pixel!=scr->black_pixel) {
2753 wFreeColor(scr, scr->dtext_pixel);
2756 scr->dtext_pixel = color->pixel;
2758 if (scr->dtext_pixel == scr->mtext_pixel) {
2759 gcv.foreground = scr->white_pixel;
2760 gcv.background = scr->black_pixel;
2761 gcv.fill_style = FillStippled;
2762 } else {
2763 gcv.foreground = scr->dtext_pixel;
2764 gcv.fill_style = FillSolid;
2766 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2768 return REFRESH_MENU_COLOR;
2769 #undef gcm
2772 static int
2773 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2775 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2777 return REFRESH_ICON_TITLE_COLOR;
2781 static int
2782 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2784 if (scr->icon_title_texture) {
2785 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2787 XQueryColor (dpy, scr->w_colormap, color);
2788 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2790 return REFRESH_ICON_TITLE_BACK;
2794 static void
2795 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2797 close(scr->helper_fd);
2798 scr->helper_fd = 0;
2799 scr->helper_pid = 0;
2800 scr->flags.backimage_helper_launched = 0;
2804 static int
2805 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2806 void *bar)
2808 int i;
2809 proplist_t val;
2810 char *str;
2812 if (scr->flags.backimage_helper_launched) {
2813 if (PLGetNumberOfElements(value)==0) {
2814 SendHelperMessage(scr, 'C', 0, NULL);
2815 SendHelperMessage(scr, 'K', 0, NULL);
2817 PLRelease(value);
2818 return 0;
2820 } else {
2821 pid_t pid;
2822 int filedes[2];
2824 if (PLGetNumberOfElements(value) == 0)
2825 return 0;
2827 if (pipe(filedes) < 0) {
2828 wsyserror("pipe() failed:can't set workspace specific background image");
2830 PLRelease(value);
2831 return 0;
2834 pid = fork();
2835 if (pid < 0) {
2836 wsyserror("fork() failed:can't set workspace specific background image");
2837 if (close(filedes[0]) < 0)
2838 wsyserror("could not close pipe");
2839 if (close(filedes[1]) < 0)
2840 wsyserror("could not close pipe");
2842 } else if (pid == 0) {
2843 SetupEnvironment(scr);
2845 if (close(0) < 0)
2846 wsyserror("could not close pipe");
2847 if (dup(filedes[0]) < 0) {
2848 wsyserror("dup() failed:can't set workspace specific background image");
2850 if (wPreferences.smooth_workspace_back)
2851 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
2852 else
2853 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2854 wsyserror("could not execute wmsetbg");
2855 exit(1);
2856 } else {
2858 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2859 wsyserror("error setting close-on-exec flag");
2861 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2862 wsyserror("error setting close-on-exec flag");
2865 scr->helper_fd = filedes[1];
2866 scr->helper_pid = pid;
2867 scr->flags.backimage_helper_launched = 1;
2869 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2871 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2876 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2877 val = PLGetArrayElement(value, i);
2878 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2879 str = PLGetDescription(val);
2881 SendHelperMessage(scr, 'S', i+1, str);
2883 free(str);
2884 } else {
2885 SendHelperMessage(scr, 'U', i+1, NULL);
2888 sleep(1);
2890 PLRelease(value);
2891 return 0;
2895 static int
2896 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2897 void *bar)
2899 if (scr->flags.backimage_helper_launched) {
2900 char *str;
2902 if (PLGetNumberOfElements(value)==0) {
2903 SendHelperMessage(scr, 'U', 0, NULL);
2904 } else {
2905 /* set the default workspace background to this one */
2906 str = PLGetDescription(value);
2907 if (str) {
2908 SendHelperMessage(scr, 'S', 0, str);
2909 free(str);
2910 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2911 } else {
2912 SendHelperMessage(scr, 'U', 0, NULL);
2915 } else {
2916 char *command;
2917 char *text;
2919 SetupEnvironment(scr);
2920 text = PLGetDescription(value);
2921 command = wmalloc(strlen(text)+40);
2922 if (wPreferences.smooth_workspace_back)
2923 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
2924 else
2925 sprintf(command, "wmsetbg -d -p '%s' &", text);
2926 free(text);
2927 system(command);
2928 free(command);
2930 PLRelease(value);
2932 return 0;
2936 static int
2937 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2939 if (scr->widget_texture) {
2940 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2942 scr->widget_texture = *(WTexSolid**)texture;
2944 if (scr->geometry_display != None)
2945 XSetWindowBackground(dpy, scr->geometry_display,
2946 scr->widget_texture->normal.pixel);
2948 return 0;
2952 static int
2953 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2955 if (scr->window_title_texture[WS_FOCUSED]) {
2956 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2958 scr->window_title_texture[WS_FOCUSED] = *texture;
2960 return REFRESH_WINDOW_TEXTURES;
2964 static int
2965 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2967 if (scr->window_title_texture[WS_PFOCUSED]) {
2968 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2970 scr->window_title_texture[WS_PFOCUSED] = *texture;
2972 return REFRESH_WINDOW_TEXTURES;
2976 static int
2977 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2979 if (scr->window_title_texture[WS_UNFOCUSED]) {
2980 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2982 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2984 return REFRESH_WINDOW_TEXTURES;
2988 static int
2989 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2991 if (scr->resizebar_texture[0]) {
2992 wTextureDestroy(scr, scr->resizebar_texture[0]);
2994 scr->resizebar_texture[0] = *texture;
2996 return REFRESH_WINDOW_TEXTURES;
3000 static int
3001 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3003 if (scr->menu_title_texture[0]) {
3004 wTextureDestroy(scr, scr->menu_title_texture[0]);
3006 scr->menu_title_texture[0] = *texture;
3008 return REFRESH_MENU_TITLE_TEXTURE;
3012 static int
3013 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3015 if (scr->menu_item_texture) {
3016 wTextureDestroy(scr, scr->menu_item_texture);
3017 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3019 scr->menu_item_texture = *texture;
3021 scr->menu_item_auxtexture
3022 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3024 return REFRESH_MENU_TEXTURE;
3028 static int
3029 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3031 WWindow *wwin;
3032 wKeyBindings[index] = *shortcut;
3034 wwin = scr->focused_window;
3036 while (wwin!=NULL) {
3037 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3039 if (!WFLAGP(wwin, no_bind_keys)) {
3040 wWindowSetKeyGrabs(wwin);
3042 wwin = wwin->prev;
3045 return 0;
3049 static int
3050 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3052 wArrangeIcons(scr, True);
3054 return 0;
3058 static int
3059 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3061 wScreenUpdateUsableArea(scr);
3063 return 0;
3067 static int
3068 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3070 return REFRESH_MENU_TEXTURE;
3075 static int
3076 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3078 return REFRESH_BUTTON_IMAGES;
3083 * Very ugly kluge.
3084 * Need access to the double click variables, so that all widgets in
3085 * wmaker panels will have the same dbl-click values.
3086 * TODO: figure a better way of dealing with it.
3088 #include "WINGsP.h"
3090 static int
3091 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3093 extern _WINGsConfiguration WINGsConfiguration;
3095 if (*value <= 0)
3096 *(int*)foo = 1;
3098 WINGsConfiguration.doubleClickDelay = *value;
3100 return 0;
3105 static int
3106 setMultiByte(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3108 extern _WINGsConfiguration WINGsConfiguration;
3110 WINGsConfiguration.useMultiByte = *value;
3112 return 0;