added icon tile hint
[wmaker-crm.git] / src / defaults.c
blobc5063f2d1dd2ed10cdc05adda3f81181e311fe9b
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"
71 #include "properties.h"
75 * Our own proplist reader parser. This one will not accept any
76 * syntax errors and is more descriptive in the error messages.
77 * It also doesn't seem to crash.
79 extern proplist_t ReadProplistFromFile(char *file);
82 /***** Global *****/
84 extern WDDomain *WDWindowMaker;
85 extern WDDomain *WDWindowAttributes;
86 extern WDDomain *WDRootMenu;
88 extern int wScreenCount;
90 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
91 extern Atom _XA_WINDOWMAKER_ICON_TILE;
94 extern proplist_t wDomainName;
95 extern proplist_t wAttributeDomainName;
97 extern WPreferences wPreferences;
99 extern WShortKey wKeyBindings[WKBD_LAST];
101 typedef struct {
102 char *key;
103 char *default_value;
104 void *extra_data;
105 void *addr;
106 int (*convert)();
107 int (*update)();
108 proplist_t plkey;
109 proplist_t plvalue; /* default value */
110 } WDefaultEntry;
113 /* used to map strings to integers */
114 typedef struct {
115 char *string;
116 short value;
117 char is_alias;
118 } WOptionEnumeration;
121 /* type converters */
122 static int getBool();
123 static int getInt();
124 static int getCoord();
125 #if 0
126 /* this is not used yet */
127 static int getString();
128 #endif
129 static int getPathList();
130 static int getEnum();
131 static int getTexture();
132 #ifdef DRAWSTRING_PLUGIN
133 static int getTextRenderer();
134 #endif
135 static int getWSBackground();
136 static int getWSSpecificBackground();
137 static int getFont();
138 static int getColor();
139 static int getKeybind();
140 static int getModMask();
141 #ifdef NEWSTUFF
142 static int getRImage();
143 #endif
146 /* value setting functions */
147 static int setJustify();
148 static int setClearance();
149 static int setIfDockPresent();
150 static int setStickyIcons();
152 static int setPositive();
154 static int setWidgetColor();
155 static int setIconTile();
156 static int setWinTitleFont();
157 static int setMenuTitleFont();
158 static int setMenuTextFont();
159 static int setIconTitleFont();
160 static int setIconTitleColor();
161 static int setIconTitleBack();
162 static int setLargeDisplayFont();
163 static int setWTitleColor();
164 static int setFTitleBack();
165 static int setPTitleBack();
166 static int setUTitleBack();
167 static int setResizebarBack();
168 static int setWorkspaceBack();
169 static int setWorkspaceSpecificBack();
170 static int setMenuTitleColor();
171 static int setMenuTextColor();
172 static int setMenuDisabledColor();
173 static int setMenuTitleBack();
174 static int setMenuTextBack();
175 static int setHightlight();
176 static int setHightlightText();
177 static int setKeyGrab();
178 static int setDoubleClick();
179 static int setIconPosition();
181 static int setClipTitleFont();
182 static int setClipTitleColor();
184 static int setMenuStyle();
185 static int setMultiByte();
187 static int updateUsableArea();
192 * Tables to convert strings to enumeration values.
193 * Values stored are char
197 /* WARNING: sum of length of all value strings must not exceed
198 * this value */
199 #define TOTAL_VALUES_LENGTH 80
204 #define REFRESH_WINDOW_TEXTURES (1<<0)
205 #define REFRESH_MENU_TEXTURE (1<<1)
206 #define REFRESH_MENU_FONT (1<<2)
207 #define REFRESH_MENU_COLOR (1<<3)
208 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
209 #define REFRESH_MENU_TITLE_FONT (1<<5)
210 #define REFRESH_MENU_TITLE_COLOR (1<<6)
211 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
212 #define REFRESH_WINDOW_FONT (1<<8)
213 #define REFRESH_ICON_TILE (1<<9)
214 #define REFRESH_ICON_FONT (1<<10)
215 #define REFRESH_WORKSPACE_BACK (1<<11)
217 #define REFRESH_BUTTON_IMAGES (1<<12)
219 #define REFRESH_ICON_TITLE_COLOR (1<<13)
220 #define REFRESH_ICON_TITLE_BACK (1<<14)
224 static WOptionEnumeration seFocusModes[] = {
225 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
226 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
227 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
228 {NULL, 0, 0}
231 static WOptionEnumeration seColormapModes[] = {
232 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
233 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
234 {NULL, 0, 0}
237 static WOptionEnumeration sePlacements[] = {
238 {"Auto", WPM_AUTO, 0},
239 {"Smart", WPM_SMART, 0},
240 {"Cascade", WPM_CASCADE, 0},
241 {"Random", WPM_RANDOM, 0},
242 {"Manual", WPM_MANUAL, 0},
243 {NULL, 0, 0}
246 static WOptionEnumeration seGeomDisplays[] = {
247 {"Center", WDIS_CENTER, 0},
248 {"Corner", WDIS_TOPLEFT, 0},
249 {"Floating", WDIS_FRAME_CENTER, 0},
250 {"Line", WDIS_NEW, 0},
251 {NULL, 0, 0}
254 static WOptionEnumeration seSpeeds[] = {
255 {"UltraFast", SPEED_ULTRAFAST, 0},
256 {"Fast", SPEED_FAST, 0},
257 {"Medium", SPEED_MEDIUM, 0},
258 {"Slow", SPEED_SLOW, 0},
259 {"UltraSlow", SPEED_ULTRASLOW, 0},
260 {NULL, 0, 0}
263 static WOptionEnumeration seMouseButtons[] = {
264 {"None", -1, 0},
265 {"Left", Button1, 0}, {"Button1", Button1, 1},
266 {"Middle", Button2, 0}, {"Button2", Button2, 1},
267 {"Right", Button3, 0}, {"Button3", Button3, 1},
268 {"Button4", Button4, 0},
269 {"Button5", Button5, 0},
270 {NULL, 0, 0}
273 static WOptionEnumeration seIconificationStyles[] = {
274 {"Zoom", WIS_ZOOM, 0},
275 {"Twist", WIS_TWIST, 0},
276 {"Flip", WIS_FLIP, 0},
277 {"None", WIS_NONE, 0},
278 {"random", WIS_RANDOM, 0},
279 {NULL, 0, 0}
282 static WOptionEnumeration seJustifications[] = {
283 {"Left", WTJ_LEFT, 0},
284 {"Center", WTJ_CENTER, 0},
285 {"Right", WTJ_RIGHT, 0},
286 {NULL, 0, 0}
289 static WOptionEnumeration seIconPositions[] = {
290 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
291 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
292 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
293 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
294 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
295 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
296 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
297 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
298 {NULL, 0, 0}
301 static WOptionEnumeration seMenuStyles[] = {
302 {"normal", MS_NORMAL, 0},
303 {"singletexture", MS_SINGLE_TEXTURE, 0},
304 {"flat", MS_FLAT, 0},
305 {NULL, 0, 0}
309 static WOptionEnumeration seDisplayPositions[] = {
310 {"none", WD_NONE, 0},
311 {"center", WD_CENTER, 0},
312 {"top", WD_TOP, 0},
313 {"bottom", WD_BOTTOM, 0},
314 {"topleft", WD_TOPLEFT, 0},
315 {"topright", WD_TOPRIGHT, 0},
316 {"bottomleft", WD_BOTTOMLEFT, 0},
317 {"bottomright", WD_BOTTOMRIGHT, 0}
322 * ALL entries in the tables bellow, NEED to have a default value
323 * defined, and this value needs to be correct.
326 /* these options will only affect the window manager on startup
328 * static defaults can't access the screen data, because it is
329 * created after these defaults are read
331 WDefaultEntry staticOptionList[] = {
333 {"ColormapSize", "4", NULL,
334 &wPreferences.cmap_size, getInt, NULL
336 {"DisableDithering", "NO", NULL,
337 &wPreferences.no_dithering, getBool, NULL
339 /* static by laziness */
340 {"IconSize", "64", NULL,
341 &wPreferences.icon_size, getInt, NULL
343 {"ModifierKey", "Mod1", NULL,
344 &wPreferences.modifier_mask, getModMask, NULL
346 {"DisableWSMouseActions", "NO", NULL,
347 &wPreferences.disable_root_mouse, getBool, NULL
349 {"FocusMode", "manual", seFocusModes,
350 &wPreferences.focus_mode, getEnum, NULL
351 }, /* have a problem when switching from manual to sloppy without restart */
352 {"NewStyle", "NO", NULL,
353 &wPreferences.new_style, getBool, NULL
355 {"DisableDock", "NO", (void*) WM_DOCK,
356 NULL, getBool, setIfDockPresent
358 {"DisableClip", "NO", (void*) WM_CLIP,
359 NULL, getBool, setIfDockPresent
361 {"DisableMiniwindows", "NO", NULL,
362 &wPreferences.disable_miniwindows, getBool, NULL
364 {"MultiByteText", "NO", NULL,
365 &wPreferences.multi_byte_text, getBool, setMultiByte
371 WDefaultEntry optionList[] = {
372 /* dynamic options */
373 {"IconPosition", "blh", seIconPositions,
374 &wPreferences.icon_yard, getEnum, setIconPosition
376 {"IconificationStyle", "Zoom", seIconificationStyles,
377 &wPreferences.iconification_style, getEnum, NULL
379 {"SelectWindowsMouseButton", "Left", seMouseButtons,
380 &wPreferences.select_button, getEnum, NULL
382 {"WindowListMouseButton", "Middle", seMouseButtons,
383 &wPreferences.windowl_button, getEnum, NULL
385 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
386 &wPreferences.menu_button, getEnum, NULL
388 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
389 &wPreferences.pixmap_path, getPathList, NULL
391 {"IconPath", DEF_ICON_PATHS, NULL,
392 &wPreferences.icon_path, getPathList, NULL
394 {"ColormapMode", "auto", seColormapModes,
395 &wPreferences.colormap_mode, getEnum, NULL
397 {"AutoFocus", "NO", NULL,
398 &wPreferences.auto_focus, getBool, NULL
400 {"RaiseDelay", "0", NULL,
401 &wPreferences.raise_delay, getInt, NULL
403 {"CirculateRaise", "NO", NULL,
404 &wPreferences.circ_raise, getBool, NULL
406 {"Superfluous", "NO", NULL,
407 &wPreferences.superfluous, getBool, NULL
409 {"AdvanceToNewWorkspace", "NO", NULL,
410 &wPreferences.ws_advance, getBool, NULL
412 {"CycleWorkspaces", "NO", NULL,
413 &wPreferences.ws_cycle, getBool, NULL
415 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
416 &wPreferences.workspace_name_display_position, getEnum, NULL
418 #ifdef VIRTUAL_DESKTOP
419 {"VirtualEdgeThickness", "1", NULL,
420 &wPreferences.vedge_thickness, getInt, NULL
422 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
423 &wPreferences.vedge_hscrollspeed, getInt, NULL
425 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
426 &wPreferences.vedge_vscrollspeed, getInt, NULL
428 {"VirtualEdgeWidth", "2000", NULL,
429 &wPreferences.vedge_width, getInt, NULL
431 {"VirtualEdgeHeight", "2000", NULL,
432 &wPreferences.vedge_height, getInt, NULL
434 #endif
435 {"StickyIcons", "NO", NULL,
436 &wPreferences.sticky_icons, getBool, setStickyIcons
438 {"SaveSessionOnExit", "NO", NULL,
439 &wPreferences.save_session_on_exit, getBool, NULL
441 {"WrapMenus", "NO", NULL,
442 &wPreferences.wrap_menus, getBool, NULL
444 {"ScrollableMenus", "NO", NULL,
445 &wPreferences.scrollable_menus, getBool, NULL
447 {"MenuScrollSpeed", "medium", seSpeeds,
448 &wPreferences.menu_scroll_speed, getEnum, NULL
450 {"IconSlideSpeed", "medium", seSpeeds,
451 &wPreferences.icon_slide_speed, getEnum, NULL
453 {"ShadeSpeed", "medium", seSpeeds,
454 &wPreferences.shade_speed, getEnum, NULL
456 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
457 &wPreferences.dblclick_time, getInt, setDoubleClick,
459 {"AlignSubmenus", "NO", NULL,
460 &wPreferences.align_menus, getBool, NULL
462 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
463 &wPreferences.open_transients_with_parent, getBool, NULL
465 {"WindowPlacement", "auto", sePlacements,
466 &wPreferences.window_placement, getEnum, NULL
468 {"IgnoreFocusClick","NO", NULL,
469 &wPreferences.ignore_focus_click, getBool, NULL
471 {"UseSaveUnders", "NO", NULL,
472 &wPreferences.use_saveunders, getBool, NULL
474 {"OpaqueMove", "NO", NULL,
475 &wPreferences.opaque_move, getBool, NULL
477 {"DisableSound", "NO", NULL,
478 &wPreferences.no_sound, getBool, NULL
480 {"DisableAnimations", "NO", NULL,
481 &wPreferences.no_animations, getBool, NULL
483 {"DontLinkWorkspaces","NO", NULL,
484 &wPreferences.no_autowrap, getBool, NULL
486 {"AutoArrangeIcons", "NO", NULL,
487 &wPreferences.auto_arrange_icons, getBool, NULL
489 {"NoWindowOverDock", "NO", NULL,
490 &wPreferences.no_window_over_dock, getBool, updateUsableArea
492 {"NoWindowOverIcons", "NO", NULL,
493 &wPreferences.no_window_over_icons, getBool, updateUsableArea
495 {"WindowPlaceOrigin", "(0, 0)", NULL,
496 &wPreferences.window_place_origin, getCoord, NULL
498 {"ResizeDisplay", "corner", seGeomDisplays,
499 &wPreferences.size_display, getEnum, NULL
501 {"MoveDisplay", "corner", seGeomDisplays,
502 &wPreferences.move_display, getEnum, NULL
504 {"DontConfirmKill", "NO", NULL,
505 &wPreferences.dont_confirm_kill, getBool,NULL
507 {"WindowTitleBalloons", "NO", NULL,
508 &wPreferences.window_balloon, getBool, NULL
510 {"MiniwindowTitleBalloons", "NO", NULL,
511 &wPreferences.miniwin_balloon,getBool, NULL
513 {"AppIconBalloons", "NO", NULL,
514 &wPreferences.appicon_balloon,getBool, NULL
516 {"HelpBalloons", "NO", NULL,
517 &wPreferences.help_balloon, getBool, NULL
519 {"EdgeResistance", "30", NULL,
520 &wPreferences.edge_resistance,getInt, NULL
522 {"Attraction", "NO", NULL,
523 &wPreferences.attract, getBool, NULL
525 {"DisableBlinking", "NO", NULL,
526 &wPreferences.dont_blink, getBool, NULL
528 /* style options */
529 {"MenuStyle", "normal", seMenuStyles,
530 &wPreferences.menu_style, getEnum, setMenuStyle
532 {"WidgetColor", "(solid, gray)", NULL,
533 NULL, getTexture, setWidgetColor,
535 {"WorkspaceSpecificBack","()", NULL,
536 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
538 /* WorkspaceBack must come after WorkspaceSpecificBack or
539 * WorkspaceBack wont know WorkspaceSpecificBack was also
540 * specified and 2 copies of wmsetbg will be launched */
541 {"WorkspaceBack", "(solid, black)", NULL,
542 NULL, getWSBackground,setWorkspaceBack
544 {"SmoothWorkspaceBack", "NO", NULL,
545 NULL, getBool, NULL
547 {"IconBack", "(solid, gray)", NULL,
548 NULL, getTexture, setIconTile
550 {"TitleJustify", "center", seJustifications,
551 &wPreferences.title_justification, getEnum, setJustify
553 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
554 NULL, getFont, setWinTitleFont,
556 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
557 &wPreferences.window_title_clearance, getInt, setClearance
559 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
560 &wPreferences.menu_title_clearance, getInt, setClearance
562 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
563 &wPreferences.menu_text_clearance, getInt, setClearance
565 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
566 NULL, getFont, setMenuTitleFont
568 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
569 NULL, getFont, setMenuTextFont
571 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
572 NULL, getFont, setIconTitleFont
574 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
575 NULL, getFont, setClipTitleFont
577 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
578 NULL, getFont, setLargeDisplayFont
580 {"HighlightColor", "white", NULL,
581 NULL, getColor, setHightlight
583 {"HighlightTextColor", "black", NULL,
584 NULL, getColor, setHightlightText
586 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
587 NULL, getColor, setClipTitleColor
589 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
590 NULL, getColor, setClipTitleColor
592 #ifdef DRAWSTRING_PLUGIN
593 {"FTitleColor", "white", (void*)WS_FOCUSED,
594 NULL, getTextRenderer, setWTitleColor
596 {"PTitleColor", "white", (void*)WS_PFOCUSED,
597 NULL, getTextRenderer, setWTitleColor
599 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
600 NULL, getTextRenderer, setWTitleColor
602 #else
603 {"FTitleColor", "white", (void*)WS_FOCUSED,
604 NULL, getColor, setWTitleColor
606 {"PTitleColor", "white", (void*)WS_PFOCUSED,
607 NULL, getColor, setWTitleColor
609 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
610 NULL, getColor, setWTitleColor
612 #endif
613 {"FTitleBack", "(solid, black)", NULL,
614 NULL, getTexture, setFTitleBack
616 {"PTitleBack", "(solid, \"#616161\")", NULL,
617 NULL, getTexture, setPTitleBack
619 {"UTitleBack", "(solid, gray)", NULL,
620 NULL, getTexture, setUTitleBack
622 {"ResizebarBack", "(solid, gray)", NULL,
623 NULL, getTexture, setResizebarBack
625 #ifdef DRAWSTRING_PLUGIN
626 {"MenuTitleColor", "white", NULL,
627 NULL, getTextRenderer, setMenuTitleColor
629 #else
630 {"MenuTitleColor", "white", NULL,
631 NULL, getColor, setMenuTitleColor
633 #endif
634 {"MenuTextColor", "black", NULL,
635 NULL, getColor, setMenuTextColor
637 {"MenuDisabledColor", "\"#616161\"", NULL,
638 NULL, getColor, setMenuDisabledColor
640 {"MenuTitleBack", "(solid, black)", NULL,
641 NULL, getTexture, setMenuTitleBack
643 {"MenuTextBack", "(solid, gray)", NULL,
644 NULL, getTexture, setMenuTextBack
646 {"IconTitleColor", "white", NULL,
647 NULL, getColor, setIconTitleColor
649 {"IconTitleBack", "black", NULL,
650 NULL, getColor, setIconTitleBack
652 /* keybindings */
653 #ifndef LITE
654 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
655 NULL, getKeybind, setKeyGrab
657 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
658 NULL, getKeybind, setKeyGrab
660 #endif /* LITE */
661 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
662 NULL, getKeybind, setKeyGrab
664 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
665 NULL, getKeybind, setKeyGrab
667 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
668 NULL, getKeybind, setKeyGrab
670 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
671 NULL, getKeybind, setKeyGrab
673 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
674 NULL, getKeybind, setKeyGrab
676 {"HideKey", "None", (void*)WKBD_HIDE,
677 NULL, getKeybind, setKeyGrab
679 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
680 NULL, getKeybind, setKeyGrab
682 {"CloseKey", "None", (void*)WKBD_CLOSE,
683 NULL, getKeybind, setKeyGrab
685 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
686 NULL, getKeybind, setKeyGrab
688 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
689 NULL, getKeybind, setKeyGrab
691 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
692 NULL, getKeybind, setKeyGrab
694 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
695 NULL, getKeybind, setKeyGrab
697 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
698 NULL, getKeybind, setKeyGrab
700 {"ShadeKey", "None", (void*)WKBD_SHADE,
701 NULL, getKeybind, setKeyGrab
703 {"SelectKey", "None", (void*)WKBD_SELECT,
704 NULL, getKeybind, setKeyGrab
706 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
707 NULL, getKeybind, setKeyGrab
709 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
710 NULL, getKeybind, setKeyGrab
712 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
713 NULL, getKeybind, setKeyGrab
715 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
716 NULL, getKeybind, setKeyGrab
718 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
719 NULL, getKeybind, setKeyGrab
721 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
722 NULL, getKeybind, setKeyGrab
724 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
725 NULL, getKeybind, setKeyGrab
727 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
728 NULL, getKeybind, setKeyGrab
730 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
731 NULL, getKeybind, setKeyGrab
733 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
734 NULL, getKeybind, setKeyGrab
736 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
737 NULL, getKeybind, setKeyGrab
739 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
740 NULL, getKeybind, setKeyGrab
742 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
743 NULL, getKeybind, setKeyGrab
745 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
746 NULL, getKeybind, setKeyGrab
748 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
749 NULL, getKeybind, setKeyGrab
751 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
752 NULL, getKeybind, setKeyGrab
754 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
755 NULL, getKeybind, setKeyGrab
757 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
758 NULL, getKeybind, setKeyGrab
760 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
761 NULL, getKeybind, setKeyGrab
763 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
764 NULL, getKeybind, setKeyGrab
766 #ifdef EXTEND_WINDOWSHORTCUT
767 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
768 NULL, getKeybind, setKeyGrab
770 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
771 NULL, getKeybind, setKeyGrab
773 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
774 NULL, getKeybind, setKeyGrab
776 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
777 NULL, getKeybind, setKeyGrab
779 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
780 NULL, getKeybind, setKeyGrab
782 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
783 NULL, getKeybind, setKeyGrab
785 #endif /* EXTEND_WINDOWSHORTCUT */
787 #ifdef KEEP_XKB_LOCK_STATUS
788 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
789 NULL, getKeybind, setKeyGrab
791 {"KbdModeLock", "NO", NULL,
792 &wPreferences.modelock, getBool, NULL
794 #endif /* KEEP_XKB_LOCK_STATUS */
798 #if 0
799 static void rereadDefaults(void);
800 #endif
802 #if 0
803 static void
804 rereadDefaults(void)
806 /* must defer the update because accessing X data from a
807 * signal handler can mess up Xlib */
810 #endif
812 static void
813 initDefaults()
815 int i;
816 WDefaultEntry *entry;
818 PLSetStringCmpHook(StringCompareHook);
820 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
821 entry = &optionList[i];
823 entry->plkey = PLMakeString(entry->key);
824 if (entry->default_value)
825 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
826 else
827 entry->plvalue = NULL;
830 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
831 entry = &staticOptionList[i];
833 entry->plkey = PLMakeString(entry->key);
834 if (entry->default_value)
835 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
836 else
837 entry->plvalue = NULL;
841 wDomainName = PLMakeString(WMDOMAIN_NAME);
842 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
844 PLRegister(wDomainName, rereadDefaults);
845 PLRegister(wAttributeDomainName, rereadDefaults);
852 #if 0
853 proplist_t
854 wDefaultsInit(int screen_number)
856 static int defaults_inited = 0;
857 proplist_t dict;
859 if (!defaults_inited) {
860 initDefaults();
863 dict = PLGetDomain(wDomainName);
864 if (!dict) {
865 wwarning(_("could not read domain \"%s\" from defaults database"),
866 PLGetString(wDomainName));
869 return dict;
871 #endif
874 void
875 wDefaultsDestroyDomain(WDDomain *domain)
877 if (domain->dictionary)
878 PLRelease(domain->dictionary);
879 free(domain->path);
880 free(domain);
884 WDDomain*
885 wDefaultsInitDomain(char *domain, Bool requireDictionary)
887 WDDomain *db;
888 struct stat stbuf;
889 static int inited = 0;
890 char path[PATH_MAX];
891 char *the_path;
892 proplist_t shared_dict=NULL;
894 if (!inited) {
895 inited = 1;
896 initDefaults();
899 db = wmalloc(sizeof(WDDomain));
900 memset(db, 0, sizeof(WDDomain));
901 db->domain_name = domain;
902 db->path = wdefaultspathfordomain(domain);
903 the_path = db->path;
905 if (the_path && stat(the_path, &stbuf)>=0) {
906 db->dictionary = ReadProplistFromFile(the_path);
907 if (db->dictionary) {
908 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
909 PLRelease(db->dictionary);
910 db->dictionary = NULL;
911 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
912 domain, the_path);
914 db->timestamp = stbuf.st_mtime;
915 } else {
916 wwarning(_("could not load domain %s from user defaults database"),
917 domain);
921 /* global system dictionary */
922 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
923 if (stat(path, &stbuf)>=0) {
924 shared_dict = ReadProplistFromFile(path);
925 if (shared_dict) {
926 if (requireDictionary && !PLIsDictionary(shared_dict)) {
927 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
928 domain, path);
929 PLRelease(shared_dict);
930 shared_dict = NULL;
931 } else {
932 if (db->dictionary && PLIsDictionary(shared_dict) &&
933 PLIsDictionary(db->dictionary)) {
934 PLMergeDictionaries(shared_dict, db->dictionary);
935 PLRelease(db->dictionary);
936 db->dictionary = shared_dict;
937 if (stbuf.st_mtime > db->timestamp)
938 db->timestamp = stbuf.st_mtime;
939 } else if (!db->dictionary) {
940 db->dictionary = shared_dict;
941 if (stbuf.st_mtime > db->timestamp)
942 db->timestamp = stbuf.st_mtime;
945 } else {
946 wwarning(_("could not load domain %s from global defaults database (%s)"),
947 domain, path);
951 /* set to save it in user's directory, no matter from where it was read */
952 if (db->dictionary) {
953 proplist_t tmp = PLMakeString(db->path);
955 PLSetFilename(db->dictionary, tmp);
956 PLRelease(tmp);
959 return db;
963 void
964 wReadStaticDefaults(proplist_t dict)
966 proplist_t plvalue;
967 WDefaultEntry *entry;
968 int i;
969 void *tdata;
972 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
973 entry = &staticOptionList[i];
975 if (dict)
976 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
977 else
978 plvalue = NULL;
980 if (!plvalue) {
981 /* no default in the DB. Use builtin default */
982 plvalue = entry->plvalue;
985 if (plvalue) {
986 /* convert data */
987 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
988 if (entry->update) {
989 (*entry->update)(NULL, entry, tdata, entry->extra_data);
996 void
997 wDefaultsCheckDomains(void *foo)
999 WScreen *scr;
1000 struct stat stbuf;
1001 proplist_t dict;
1002 int i;
1003 char path[PATH_MAX];
1005 #ifdef HEARTBEAT
1006 puts("Checking domains...");
1007 #endif
1008 if (stat(WDWindowMaker->path, &stbuf)>=0
1009 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1010 proplist_t shared_dict = NULL;
1011 #ifdef HEARTBEAT
1012 puts("Checking WindowMaker domain");
1013 #endif
1014 WDWindowMaker->timestamp = stbuf.st_mtime;
1016 /* global dictionary */
1017 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1018 if (stat(path, &stbuf)>=0) {
1019 shared_dict = ReadProplistFromFile(path);
1020 if (shared_dict && !PLIsDictionary(shared_dict)) {
1021 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1022 "WindowMaker", path);
1023 PLRelease(shared_dict);
1024 shared_dict = NULL;
1025 } else if (!shared_dict) {
1026 wwarning(_("could not load domain %s from global defaults database"),
1027 "WindowMaker");
1030 /* user dictionary */
1031 dict = ReadProplistFromFile(WDWindowMaker->path);
1032 if (dict) {
1033 if (!PLIsDictionary(dict)) {
1034 PLRelease(dict);
1035 dict = NULL;
1036 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1037 "WindowMaker", WDWindowMaker->path);
1038 } else {
1039 if (shared_dict) {
1040 PLSetFilename(shared_dict, PLGetFilename(dict));
1041 PLMergeDictionaries(shared_dict, dict);
1042 PLRelease(dict);
1043 dict = shared_dict;
1044 shared_dict = NULL;
1046 for (i=0; i<wScreenCount; i++) {
1047 scr = wScreenWithNumber(i);
1048 if (scr)
1049 wReadDefaults(scr, dict);
1051 if (WDWindowMaker->dictionary) {
1052 PLRelease(WDWindowMaker->dictionary);
1054 WDWindowMaker->dictionary = dict;
1056 } else {
1057 wwarning(_("could not load domain %s from user defaults database"),
1058 "WindowMaker");
1060 if (shared_dict) {
1061 PLRelease(shared_dict);
1065 if (stat(WDWindowAttributes->path, &stbuf)>=0
1066 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1067 #ifdef HEARTBEAT
1068 puts("Checking WMWindowAttributes domain");
1069 #endif
1070 dict = ReadProplistFromFile(WDWindowAttributes->path);
1071 if (dict) {
1072 if (!PLIsDictionary(dict)) {
1073 PLRelease(dict);
1074 dict = NULL;
1075 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1076 "WMWindowAttributes", WDWindowAttributes->path);
1077 } else {
1078 if (WDWindowAttributes->dictionary)
1079 PLRelease(WDWindowAttributes->dictionary);
1080 WDWindowAttributes->dictionary = dict;
1081 for (i=0; i<wScreenCount; i++) {
1082 scr = wScreenWithNumber(i);
1083 if (scr)
1084 wDefaultUpdateIcons(scr);
1087 } else {
1088 wwarning(_("could not load domain %s from user defaults database"),
1089 "WMWindowAttributes");
1091 WDWindowAttributes->timestamp = stbuf.st_mtime;
1094 #ifndef LITE
1095 if (stat(WDRootMenu->path, &stbuf)>=0
1096 && WDRootMenu->timestamp < stbuf.st_mtime) {
1097 dict = ReadProplistFromFile(WDRootMenu->path);
1098 #ifdef HEARTBEAT
1099 puts("Checking WMRootMenu domain");
1100 #endif
1101 if (dict) {
1102 if (!PLIsArray(dict) && !PLIsString(dict)) {
1103 PLRelease(dict);
1104 dict = NULL;
1105 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1106 "WMRootMenu", WDRootMenu->path);
1107 } else {
1108 if (WDRootMenu->dictionary) {
1109 PLRelease(WDRootMenu->dictionary);
1111 WDRootMenu->dictionary = dict;
1113 } else {
1114 wwarning(_("could not load domain %s from user defaults database"),
1115 "WMRootMenu");
1117 WDRootMenu->timestamp = stbuf.st_mtime;
1119 #endif /* !LITE */
1121 if (!foo)
1122 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1126 void
1127 wReadDefaults(WScreen *scr, proplist_t new_dict)
1129 proplist_t plvalue, old_value;
1130 WDefaultEntry *entry;
1131 int i, must_update;
1132 int update_workspace_back = 0; /* kluge :/ */
1133 int needs_refresh;
1134 void *tdata;
1135 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1136 ? WDWindowMaker->dictionary : NULL);
1138 must_update = 0;
1140 needs_refresh = 0;
1142 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1143 entry = &optionList[i];
1145 if (new_dict)
1146 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1147 else
1148 plvalue = NULL;
1150 if (!old_dict)
1151 old_value = NULL;
1152 else
1153 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1156 if (!plvalue && !old_value) {
1157 /* no default in the DB. Use builtin default */
1158 plvalue = entry->plvalue;
1159 if (plvalue && new_dict) {
1160 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1161 must_update = 1;
1163 } else if (!plvalue) {
1164 /* value was deleted from DB. Keep current value */
1165 continue;
1166 } else if (!old_value) {
1167 /* set value for the 1st time */
1168 } else if (!PLIsEqual(plvalue, old_value)) {
1169 /* value has changed */
1170 } else {
1172 if (strcmp(entry->key, "WorkspaceBack") == 0
1173 && update_workspace_back
1174 && scr->flags.backimage_helper_launched) {
1175 } else {
1176 /* value was not changed since last time */
1177 continue;
1181 if (plvalue) {
1182 #ifdef DEBUG
1183 printf("Updating %s to %s\n", entry->key,
1184 PLGetDescription(plvalue));
1185 #endif
1186 /* convert data */
1187 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1189 * If the WorkspaceSpecificBack data has been changed
1190 * so that the helper will be launched now, we must be
1191 * sure to send the default background texture config
1192 * to the helper.
1194 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1195 && !scr->flags.backimage_helper_launched) {
1196 update_workspace_back = 1;
1198 if (entry->update) {
1199 needs_refresh |=
1200 (*entry->update)(scr, entry, tdata, entry->extra_data);
1206 if (needs_refresh!=0 && !scr->flags.startup) {
1207 int foo;
1209 foo = 0;
1210 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1211 foo |= WTextureSettings;
1212 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1213 foo |= WFontSettings;
1214 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1215 foo |= WColorSettings;
1216 if (foo)
1217 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1218 (void*)foo);
1220 foo = 0;
1221 if (needs_refresh & REFRESH_MENU_TEXTURE)
1222 foo |= WTextureSettings;
1223 if (needs_refresh & REFRESH_MENU_FONT)
1224 foo |= WFontSettings;
1225 if (needs_refresh & REFRESH_MENU_COLOR)
1226 foo |= WColorSettings;
1227 if (foo)
1228 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1229 (void*)foo);
1231 foo = 0;
1232 if (needs_refresh & REFRESH_WINDOW_FONT) {
1233 foo |= WFontSettings;
1235 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1236 foo |= WTextureSettings;
1238 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1239 foo |= WColorSettings;
1241 if (foo)
1242 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1243 (void*)foo);
1245 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1246 foo = 0;
1247 if (needs_refresh & REFRESH_ICON_FONT) {
1248 foo |= WFontSettings;
1250 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1251 foo |= WTextureSettings;
1253 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1254 foo |= WTextureSettings;
1256 if (foo)
1257 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1258 (void*)foo);
1260 if (needs_refresh & REFRESH_ICON_TILE)
1261 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1266 void
1267 wDefaultUpdateIcons(WScreen *scr)
1269 WAppIcon *aicon = scr->app_icon_list;
1270 WWindow *wwin = scr->focused_window;
1271 char *file;
1273 while(aicon) {
1274 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1275 False);
1276 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1277 || (file && !aicon->icon->file)) {
1278 RImage *new_image;
1280 if (aicon->icon->file)
1281 free(aicon->icon->file);
1282 aicon->icon->file = wstrdup(file);
1284 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1285 aicon->wm_class);
1286 if (new_image) {
1287 wIconChangeImage(aicon->icon, new_image);
1288 wAppIconPaint(aicon);
1291 aicon = aicon->next;
1294 if (!wPreferences.flags.noclip)
1295 wClipIconPaint(scr->clip_icon);
1297 while (wwin) {
1298 if (wwin->icon && wwin->flags.miniaturized) {
1299 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1300 False);
1301 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1302 || (file && !wwin->icon->file)) {
1303 RImage *new_image;
1305 if (wwin->icon->file)
1306 free(wwin->icon->file);
1307 wwin->icon->file = wstrdup(file);
1309 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1310 wwin->wm_class);
1311 if (new_image)
1312 wIconChangeImage(wwin->icon, new_image);
1315 wwin = wwin->prev;
1320 /* --------------------------- Local ----------------------- */
1322 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1323 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1324 entry->key, x); \
1325 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1326 var = entry->default_value;\
1327 } else var = PLGetString(value)\
1333 static int
1334 string2index(proplist_t key, proplist_t val, proplist_t def,
1335 WOptionEnumeration *values)
1337 char *str;
1338 WOptionEnumeration *v;
1339 char buffer[TOTAL_VALUES_LENGTH];
1341 if (PLIsString(val) && (str = PLGetString(val))) {
1342 for (v=values; v->string!=NULL; v++) {
1343 if (strcasecmp(v->string, str)==0)
1344 return v->value;
1348 buffer[0] = 0;
1349 for (v=values; v->string!=NULL; v++) {
1350 if (!v->is_alias) {
1351 if (buffer[0]!=0)
1352 strcat(buffer, ", ");
1353 strcat(buffer, v->string);
1356 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1357 PLGetString(key), buffer);
1359 if (def) {
1360 return string2index(key, val, NULL, values);
1363 return -1;
1370 * value - is the value in the defaults DB
1371 * addr - is the address to store the data
1372 * ret - is the address to store a pointer to a temporary buffer. ret
1373 * must not be freed and is used by the set functions
1375 static int
1376 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1377 void **ret)
1379 static char data;
1380 char *val;
1381 int second_pass=0;
1383 GET_STRING_OR_DEFAULT("Boolean", val);
1385 again:
1386 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1387 || strcasecmp(val, "YES")==0) {
1389 data = 1;
1390 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1391 || strcasecmp(val, "NO")==0) {
1392 data = 0;
1393 } else {
1394 int i;
1395 if (sscanf(val, "%i", &i)==1) {
1396 if (i!=0)
1397 data = 1;
1398 else
1399 data = 0;
1400 } else {
1401 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1402 val, entry->key);
1403 if (second_pass==0) {
1404 val = PLGetString(entry->plvalue);
1405 second_pass = 1;
1406 wwarning(_("using default \"%s\" instead"), val);
1407 goto again;
1409 return False;
1413 if (ret)
1414 *ret = &data;
1416 if (addr) {
1417 *(char*)addr = data;
1420 return True;
1424 static int
1425 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1426 void **ret)
1428 static int data;
1429 char *val;
1432 GET_STRING_OR_DEFAULT("Integer", val);
1434 if (sscanf(val, "%i", &data)!=1) {
1435 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1436 val, entry->key);
1437 val = PLGetString(entry->plvalue);
1438 wwarning(_("using default \"%s\" instead"), val);
1439 if (sscanf(val, "%i", &data)!=1) {
1440 return False;
1444 if (ret)
1445 *ret = &data;
1447 if (addr) {
1448 *(int*)addr = data;
1450 return True;
1454 static int
1455 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1456 void **ret)
1458 static WCoord data;
1459 char *val_x, *val_y;
1460 int nelem, changed=0;
1461 proplist_t elem_x, elem_y;
1463 again:
1464 if (!PLIsArray(value)) {
1465 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1466 entry->key, "Coordinate");
1467 if (changed==0) {
1468 value = entry->plvalue;
1469 changed = 1;
1470 wwarning(_("using default \"%s\" instead"), entry->default_value);
1471 goto again;
1473 return False;
1476 nelem = PLGetNumberOfElements(value);
1477 if (nelem != 2) {
1478 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1479 entry->key);
1480 if (changed==0) {
1481 value = entry->plvalue;
1482 changed = 1;
1483 wwarning(_("using default \"%s\" instead"), entry->default_value);
1484 goto again;
1486 return False;
1489 elem_x = PLGetArrayElement(value, 0);
1490 elem_y = PLGetArrayElement(value, 1);
1492 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1493 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1494 entry->key);
1495 if (changed==0) {
1496 value = entry->plvalue;
1497 changed = 1;
1498 wwarning(_("using default \"%s\" instead"), entry->default_value);
1499 goto again;
1501 return False;
1504 val_x = PLGetString(elem_x);
1505 val_y = PLGetString(elem_y);
1507 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1508 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1509 if (changed==0) {
1510 value = entry->plvalue;
1511 changed = 1;
1512 wwarning(_("using default \"%s\" instead"), entry->default_value);
1513 goto again;
1515 return False;
1518 if (data.x < 0)
1519 data.x = 0;
1520 else if (data.x > scr->scr_width/3)
1521 data.x = scr->scr_width/3;
1522 if (data.y < 0)
1523 data.y = 0;
1524 else if (data.y > scr->scr_height/3)
1525 data.y = scr->scr_height/3;
1527 if (ret)
1528 *ret = &data;
1530 if (addr) {
1531 *(WCoord*)addr = data;
1534 return True;
1538 #if 0
1539 /* This function is not used at the moment. */
1540 static int
1541 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1542 void **ret)
1544 static char *data;
1546 GET_STRING_OR_DEFAULT("String", data);
1548 if (!data) {
1549 data = PLGetString(entry->plvalue);
1550 if (!data)
1551 return False;
1554 if (ret)
1555 *ret = &data;
1557 if (addr)
1558 *(char**)addr = wstrdup(data);
1560 return True;
1562 #endif
1565 static int
1566 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1567 void **ret)
1569 static char *data;
1570 int i, count, len;
1571 char *ptr;
1572 proplist_t d;
1573 int changed=0;
1575 again:
1576 if (!PLIsArray(value)) {
1577 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1578 entry->key, "an array of paths");
1579 if (changed==0) {
1580 value = entry->plvalue;
1581 changed = 1;
1582 wwarning(_("using default \"%s\" instead"), entry->default_value);
1583 goto again;
1585 return False;
1588 i = 0;
1589 count = PLGetNumberOfElements(value);
1590 if (count < 1) {
1591 if (changed==0) {
1592 value = entry->plvalue;
1593 changed = 1;
1594 wwarning(_("using default \"%s\" instead"), entry->default_value);
1595 goto again;
1597 return False;
1600 len = 0;
1601 for (i=0; i<count; i++) {
1602 d = PLGetArrayElement(value, i);
1603 if (!d || !PLIsString(d)) {
1604 count = i;
1605 break;
1607 len += strlen(PLGetString(d))+1;
1610 ptr = data = wmalloc(len+1);
1612 for (i=0; i<count; i++) {
1613 d = PLGetArrayElement(value, i);
1614 if (!d || !PLIsString(d)) {
1615 break;
1617 strcpy(ptr, PLGetString(d));
1618 ptr += strlen(PLGetString(d));
1619 *ptr = ':';
1620 ptr++;
1622 ptr--; *(ptr--) = 0;
1624 if (*(char**)addr!=NULL) {
1625 free(*(char**)addr);
1627 *(char**)addr = data;
1629 return True;
1633 static int
1634 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1635 void **ret)
1637 static signed char data;
1639 data = string2index(entry->plkey, value, entry->default_value,
1640 (WOptionEnumeration*)entry->extra_data);
1641 if (data < 0)
1642 return False;
1644 if (ret)
1645 *ret = &data;
1647 if (addr)
1648 *(signed char*)addr = data;
1650 return True;
1656 * (solid <color>)
1657 * (hgradient <color> <color>)
1658 * (vgradient <color> <color>)
1659 * (dgradient <color> <color>)
1660 * (mhgradient <color> <color> ...)
1661 * (mvgradient <color> <color> ...)
1662 * (tpixmap <file> <color>)
1663 * (spixmap <file> <color>)
1664 * (cpixmap <file> <color>)
1665 * (thgradient <file> <opaqueness> <color> <color>)
1666 * (tvgradient <file> <opaqueness> <color> <color>)
1667 * (tdgradient <file> <opaqueness> <color> <color>)
1668 * (function <lib> <function> ...)
1671 static WTexture*
1672 parse_texture(WScreen *scr, proplist_t pl)
1674 proplist_t elem;
1675 char *val;
1676 int nelem;
1677 WTexture *texture=NULL;
1679 nelem = PLGetNumberOfElements(pl);
1680 if (nelem < 1)
1681 return NULL;
1684 elem = PLGetArrayElement(pl, 0);
1685 if (!elem || !PLIsString(elem))
1686 return NULL;
1687 val = PLGetString(elem);
1690 if (strcasecmp(val, "solid")==0) {
1691 XColor color;
1693 if (nelem != 2)
1694 return NULL;
1696 /* get color */
1698 elem = PLGetArrayElement(pl, 1);
1699 if (!elem || !PLIsString(elem))
1700 return NULL;
1701 val = PLGetString(elem);
1703 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1704 wwarning(_("\"%s\" is not a valid color name"), val);
1705 return NULL;
1708 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1709 } else if (strcasecmp(val, "dgradient")==0
1710 || strcasecmp(val, "vgradient")==0
1711 || strcasecmp(val, "hgradient")==0) {
1712 RColor color1, color2;
1713 XColor xcolor;
1714 int type;
1716 if (nelem != 3) {
1717 wwarning(_("bad number of arguments in gradient specification"));
1718 return NULL;
1721 if (val[0]=='d' || val[0]=='D')
1722 type = WTEX_DGRADIENT;
1723 else if (val[0]=='h' || val[0]=='H')
1724 type = WTEX_HGRADIENT;
1725 else
1726 type = WTEX_VGRADIENT;
1729 /* get from color */
1730 elem = PLGetArrayElement(pl, 1);
1731 if (!elem || !PLIsString(elem))
1732 return NULL;
1733 val = PLGetString(elem);
1735 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1736 wwarning(_("\"%s\" is not a valid color name"), val);
1737 return NULL;
1739 color1.alpha = 255;
1740 color1.red = xcolor.red >> 8;
1741 color1.green = xcolor.green >> 8;
1742 color1.blue = xcolor.blue >> 8;
1744 /* get to color */
1745 elem = PLGetArrayElement(pl, 2);
1746 if (!elem || !PLIsString(elem)) {
1747 return NULL;
1749 val = PLGetString(elem);
1751 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1752 wwarning(_("\"%s\" is not a valid color name"), val);
1753 return NULL;
1755 color2.alpha = 255;
1756 color2.red = xcolor.red >> 8;
1757 color2.green = xcolor.green >> 8;
1758 color2.blue = xcolor.blue >> 8;
1760 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1762 } else if (strcasecmp(val, "mhgradient")==0
1763 || strcasecmp(val, "mvgradient")==0
1764 || strcasecmp(val, "mdgradient")==0) {
1765 XColor color;
1766 RColor **colors;
1767 int i, count;
1768 int type;
1770 if (nelem < 3) {
1771 wwarning(_("too few arguments in multicolor gradient specification"));
1772 return NULL;
1775 if (val[1]=='h' || val[1]=='H')
1776 type = WTEX_MHGRADIENT;
1777 else if (val[1]=='v' || val[1]=='V')
1778 type = WTEX_MVGRADIENT;
1779 else
1780 type = WTEX_MDGRADIENT;
1782 count = nelem-1;
1784 colors = wmalloc(sizeof(RColor*)*(count+1));
1786 for (i=0; i<count; i++) {
1787 elem = PLGetArrayElement(pl, i+1);
1788 if (!elem || !PLIsString(elem)) {
1789 for (--i; i>=0; --i) {
1790 free(colors[i]);
1792 free(colors);
1793 return NULL;
1795 val = PLGetString(elem);
1797 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1798 wwarning(_("\"%s\" is not a valid color name"), val);
1799 for (--i; i>=0; --i) {
1800 free(colors[i]);
1802 free(colors);
1803 return NULL;
1804 } else {
1805 colors[i] = wmalloc(sizeof(RColor));
1806 colors[i]->red = color.red >> 8;
1807 colors[i]->green = color.green >> 8;
1808 colors[i]->blue = color.blue >> 8;
1811 colors[i] = NULL;
1813 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1814 } else if (strcasecmp(val, "spixmap")==0 ||
1815 strcasecmp(val, "cpixmap")==0 ||
1816 strcasecmp(val, "tpixmap")==0) {
1817 XColor color;
1818 int type;
1820 if (nelem != 3)
1821 return NULL;
1823 if (val[0] == 's' || val[0] == 'S')
1824 type = WTP_SCALE;
1825 else if (val[0] == 'c' || val[0] == 'C')
1826 type = WTP_CENTER;
1827 else
1828 type = WTP_TILE;
1830 /* get color */
1831 elem = PLGetArrayElement(pl, 2);
1832 if (!elem || !PLIsString(elem)) {
1833 return NULL;
1835 val = PLGetString(elem);
1837 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1838 wwarning(_("\"%s\" is not a valid color name"), val);
1839 return NULL;
1842 /* file name */
1843 elem = PLGetArrayElement(pl, 1);
1844 if (!elem || !PLIsString(elem))
1845 return NULL;
1846 val = PLGetString(elem);
1848 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1849 } else if (strcasecmp(val, "thgradient")==0
1850 || strcasecmp(val, "tvgradient")==0
1851 || strcasecmp(val, "tdgradient")==0) {
1852 RColor color1, color2;
1853 XColor xcolor;
1854 int opacity;
1855 int style;
1857 if (val[1]=='h' || val[1]=='H')
1858 style = WTEX_THGRADIENT;
1859 else if (val[1]=='v' || val[1]=='V')
1860 style = WTEX_TVGRADIENT;
1861 else
1862 style = WTEX_TDGRADIENT;
1864 if (nelem != 5) {
1865 wwarning(_("bad number of arguments in textured gradient specification"));
1866 return NULL;
1869 /* get from color */
1870 elem = PLGetArrayElement(pl, 3);
1871 if (!elem || !PLIsString(elem))
1872 return NULL;
1873 val = PLGetString(elem);
1875 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1876 wwarning(_("\"%s\" is not a valid color name"), val);
1877 return NULL;
1879 color1.alpha = 255;
1880 color1.red = xcolor.red >> 8;
1881 color1.green = xcolor.green >> 8;
1882 color1.blue = xcolor.blue >> 8;
1884 /* get to color */
1885 elem = PLGetArrayElement(pl, 4);
1886 if (!elem || !PLIsString(elem)) {
1887 return NULL;
1889 val = PLGetString(elem);
1891 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1892 wwarning(_("\"%s\" is not a valid color name"), val);
1893 return NULL;
1895 color2.alpha = 255;
1896 color2.red = xcolor.red >> 8;
1897 color2.green = xcolor.green >> 8;
1898 color2.blue = xcolor.blue >> 8;
1900 /* get opacity */
1901 elem = PLGetArrayElement(pl, 2);
1902 if (!elem || !PLIsString(elem))
1903 opacity = 128;
1904 else
1905 val = PLGetString(elem);
1907 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1908 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1909 opacity = 128;
1912 /* get file name */
1913 elem = PLGetArrayElement(pl, 1);
1914 if (!elem || !PLIsString(elem))
1915 return NULL;
1916 val = PLGetString(elem);
1918 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1919 val, opacity);
1921 #ifdef TEXTURE_PLUGIN
1922 else if (strcasecmp(val, "function")==0) {
1923 WTexFunction *function;
1924 void (*initFunc) (Display *, Colormap);
1925 char *lib, *func, **argv;
1926 int i, argc;
1928 if (nelem < 3)
1929 return NULL;
1931 /* get the library name */
1932 elem = PLGetArrayElement(pl, 1);
1933 if (!elem || !PLIsString(elem)) {
1934 return NULL;
1936 lib = PLGetString(elem);
1938 /* get the function name */
1939 elem = PLGetArrayElement(pl, 2);
1940 if (!elem || !PLIsString(elem)) {
1941 return NULL;
1943 func = PLGetString(elem);
1945 argc = nelem - 2;
1946 argv = (char **)wmalloc(argc * sizeof(char *));
1948 /* get the parameters */
1949 argv[0] = wstrdup(func);
1950 for (i = 0; i < argc - 1; i++) {
1951 elem = PLGetArrayElement(pl, 3 + i);
1952 if (!elem || !PLIsString(elem)) {
1953 free(argv);
1955 return NULL;
1957 argv[i+1] = wstrdup(PLGetString(elem));
1960 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1962 #ifdef HAVE_DLFCN_H
1963 if (function) {
1964 initFunc = dlsym(function->handle, "initWindowMaker");
1965 if (initFunc) {
1966 initFunc(dpy, scr->w_colormap);
1967 } else {
1968 wwarning(_("could not initialize library %s"), lib);
1970 } else {
1971 wwarning(_("could not find function %s::%s"), lib, func);
1973 #endif /* HAVE_DLFCN_H */
1974 texture = (WTexture*)function;
1976 #endif /* TEXTURE_PLUGIN */
1977 else {
1978 wwarning(_("invalid texture type %s"), val);
1979 return NULL;
1981 return texture;
1986 static int
1987 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1988 void **ret)
1990 static WTexture *texture;
1991 int changed=0;
1993 again:
1994 if (!PLIsArray(value)) {
1995 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1996 entry->key, "Texture");
1997 if (changed==0) {
1998 value = entry->plvalue;
1999 changed = 1;
2000 wwarning(_("using default \"%s\" instead"), entry->default_value);
2001 goto again;
2003 return False;
2006 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2007 proplist_t pl;
2009 pl = PLGetArrayElement(value, 0);
2010 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2011 || strcasecmp(PLGetString(pl), "solid")!=0) {
2012 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2013 entry->key, "Solid Texture");
2015 value = entry->plvalue;
2016 changed = 1;
2017 wwarning(_("using default \"%s\" instead"), entry->default_value);
2018 goto again;
2022 texture = parse_texture(scr, value);
2024 if (!texture) {
2025 wwarning(_("Error in texture specification for key \"%s\""),
2026 entry->key);
2027 if (changed==0) {
2028 value = entry->plvalue;
2029 changed = 1;
2030 wwarning(_("using default \"%s\" instead"), entry->default_value);
2031 goto again;
2033 return False;
2036 if (ret)
2037 *ret = &texture;
2039 if (addr)
2040 *(WTexture**)addr = texture;
2042 return True;
2047 #ifdef DRAWSTRING_PLUGIN
2048 static int
2049 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2050 void *addr, void **ret)
2052 proplist_t elem;
2053 char *val, *lib, *func, **argv;
2054 int argc, changed;
2056 if (strcmp(entry->key, "FTitleColor")==0) {
2057 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2058 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2059 } else if (strcmp(entry->key, "UTitleColor")==0) {
2060 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2061 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2062 } else if (strcmp(entry->key, "PTitleColor")==0) {
2063 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2064 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2065 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2066 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2067 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2068 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2069 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2070 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2073 if (PLIsArray(value)) {
2074 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2075 argc -= 2;
2076 argv = (char **)wmalloc(argc * sizeof(char *));
2078 elem = PLGetArrayElement(value,0);
2079 if (!elem || !PLIsString(elem)) return False;
2080 val = PLGetString(elem);
2081 if (strcasecmp(val, "function")==0) {
2082 elem = PLGetArrayElement(value, 1); /* library name */
2083 if (!elem || !PLIsString(elem)) return False;
2084 lib = PLGetString(elem);
2085 elem = PLGetArrayElement(value, 2); /* function name */
2086 if (!elem || !PLIsString(elem)) return False;
2087 func = PLGetString(elem);
2088 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2089 lib, "initDrawString", func, NULL, value,
2090 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2093 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2094 } else if (PLIsString(value)) {
2095 return getColor(scr, entry, value, addr, ret);
2098 return False;
2100 #endif /* DRAWSTRING_PLUGIN */
2104 static int
2105 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2106 void *addr, void **ret)
2108 proplist_t elem;
2109 int changed = 0;
2110 char *val;
2111 int nelem;
2113 again:
2114 if (!PLIsArray(value)) {
2115 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2116 "WorkspaceBack", "Texture or None");
2117 if (changed==0) {
2118 value = entry->plvalue;
2119 changed = 1;
2120 wwarning(_("using default \"%s\" instead"), entry->default_value);
2121 goto again;
2123 return False;
2126 /* only do basic error checking and verify for None texture */
2128 nelem = PLGetNumberOfElements(value);
2129 if (nelem > 0) {
2130 elem = PLGetArrayElement(value, 0);
2131 if (!elem || !PLIsString(elem)) {
2132 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2133 if (changed==0) {
2134 value = entry->plvalue;
2135 changed = 1;
2136 wwarning(_("using default \"%s\" instead"), entry->default_value);
2137 goto again;
2139 return False;
2141 val = PLGetString(elem);
2143 if (strcasecmp(val, "None")==0)
2144 return True;
2146 *ret = PLRetain(value);
2148 return True;
2152 static int
2153 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2154 void *addr, void **ret)
2156 proplist_t elem;
2157 int nelem;
2158 int changed = 0;
2160 again:
2161 if (!PLIsArray(value)) {
2162 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2163 "WorkspaceSpecificBack", "an array of textures");
2164 if (changed==0) {
2165 value = entry->plvalue;
2166 changed = 1;
2167 wwarning(_("using default \"%s\" instead"), entry->default_value);
2168 goto again;
2170 return False;
2173 /* only do basic error checking and verify for None texture */
2175 nelem = PLGetNumberOfElements(value);
2176 if (nelem > 0) {
2177 while (nelem--) {
2178 elem = PLGetArrayElement(value, nelem);
2179 if (!elem || !PLIsArray(elem)) {
2180 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2181 nelem);
2186 *ret = PLRetain(value);
2188 #ifdef notworking
2190 * Kluge to force wmsetbg helper to set the default background.
2191 * If the WorkspaceSpecificBack is changed once wmaker has started,
2192 * the WorkspaceBack won't be sent to the helper, unless the user
2193 * changes it's value too. So, we must force this by removing the
2194 * value from the defaults DB.
2196 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2197 proplist_t key = PLMakeString("WorkspaceBack");
2199 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2201 PLRelease(key);
2203 #endif
2204 return True;
2208 static int
2209 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2210 void **ret)
2212 static WMFont *font;
2213 char *val;
2215 GET_STRING_OR_DEFAULT("Font", val);
2217 font = WMCreateFont(scr->wmscreen, val);
2218 if (!font)
2219 font = WMCreateFont(scr->wmscreen, "fixed");
2221 if (!font) {
2222 wfatal(_("could not load any usable font!!!"));
2223 exit(1);
2226 if (ret)
2227 *ret = font;
2229 /* can't assign font value outside update function */
2230 wassertrv(addr == NULL, True);
2232 return True;
2236 static int
2237 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2238 void **ret)
2240 static XColor color;
2241 char *val;
2242 int second_pass=0;
2244 GET_STRING_OR_DEFAULT("Color", val);
2247 again:
2248 if (!wGetColor(scr, val, &color)) {
2249 wwarning(_("could not get color for key \"%s\""),
2250 entry->key);
2251 if (second_pass==0) {
2252 val = PLGetString(entry->plvalue);
2253 second_pass = 1;
2254 wwarning(_("using default \"%s\" instead"), val);
2255 goto again;
2257 return False;
2260 if (ret)
2261 *ret = &color;
2263 assert(addr==NULL);
2265 if (addr)
2266 *(unsigned long*)addr = pixel;
2269 return True;
2274 static int
2275 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2276 void **ret)
2278 static WShortKey shortcut;
2279 KeySym ksym;
2280 char *val;
2281 char *k;
2282 char buf[128], *b;
2285 GET_STRING_OR_DEFAULT("Key spec", val);
2287 if (!val || strcasecmp(val, "NONE")==0) {
2288 shortcut.keycode = 0;
2289 shortcut.modifier = 0;
2290 if (ret)
2291 *ret = &shortcut;
2292 return True;
2295 strcpy(buf, val);
2297 b = (char*)buf;
2299 /* get modifiers */
2300 shortcut.modifier = 0;
2301 while ((k = strchr(b, '+'))!=NULL) {
2302 int mod;
2304 *k = 0;
2305 mod = wXModifierFromKey(b);
2306 if (mod<0) {
2307 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2308 return False;
2310 shortcut.modifier |= mod;
2312 b = k+1;
2315 /* get key */
2316 ksym = XStringToKeysym(b);
2318 if (ksym==NoSymbol) {
2319 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2320 val);
2321 return False;
2324 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2325 if (shortcut.keycode==0) {
2326 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2327 return False;
2330 if (ret)
2331 *ret = &shortcut;
2333 return True;
2337 static int
2338 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2339 void **ret)
2341 static unsigned int mask;
2342 char *str;
2344 GET_STRING_OR_DEFAULT("Modifier Key", str);
2346 if (!str)
2347 return False;
2349 mask = wXModifierFromKey(str);
2350 if (mask < 0) {
2351 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2352 mask = 0;
2353 return False;
2356 if (addr)
2357 *(unsigned int*)addr = mask;
2359 if (ret)
2360 *ret = &mask;
2362 return True;
2366 #ifdef NEWSTUFF
2367 static int
2368 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2369 void *addr, void **ret)
2371 unsigned int mask;
2372 char *str;
2373 RImage *image;
2374 int i, n;
2375 int w, h;
2377 GET_STRING_OR_DEFAULT("Image File Path", str);
2378 if (!str)
2379 return False;
2381 image = RLoadImage(scr->rcontext, str, 0);
2382 if (!image) {
2383 wwarning(_("could not load image in option %s: %s"), entry->key,
2384 RMessageForError(RErrorCode));
2385 return False;
2388 if (*(RImage**)addr) {
2389 RDestroyImage(*(RImage**)addr);
2391 if (addr)
2392 *(RImage**)addr = image;
2394 assert(ret == NULL);
2396 if (ret)
2397 *(RImage**)ret = image;
2400 return True;
2402 #endif
2405 /* ---------------- value setting functions --------------- */
2406 static int
2407 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2409 return REFRESH_WINDOW_TITLE_COLOR;
2412 static int
2413 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2415 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2418 static int
2419 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2421 switch (which) {
2422 case WM_DOCK:
2423 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2424 break;
2425 case WM_CLIP:
2426 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2427 break;
2428 default:
2429 break;
2431 return 0;
2435 static int
2436 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2438 if (scr->workspaces) {
2439 wWorkspaceForceChange(scr, scr->current_workspace);
2440 wArrangeIcons(scr, False);
2442 return 0;
2445 #if not_used
2446 static int
2447 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2449 if (*value <= 0)
2450 *(int*)foo = 1;
2452 return 0;
2454 #endif
2458 static int
2459 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2461 Pixmap pixmap;
2462 RImage *img;
2463 int reset = 0;
2465 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2466 wPreferences.icon_size,
2467 ((*texture)->any.type & WREL_BORDER_MASK)
2468 ? WREL_ICON : WREL_FLAT);
2469 if (!img) {
2470 wwarning(_("could not render texture for icon background"));
2471 if (!entry->addr)
2472 wTextureDestroy(scr, *texture);
2473 return 0;
2475 RConvertImage(scr->rcontext, img, &pixmap);
2477 if (scr->icon_tile) {
2478 reset = 1;
2479 RDestroyImage(scr->icon_tile);
2480 XFreePixmap(dpy, scr->icon_tile_pixmap);
2483 scr->icon_tile = img;
2486 /* put the icon in the noticeboard hint */
2487 PropSetIconTileHint(scr, img);
2490 if (!wPreferences.flags.noclip) {
2491 if (scr->clip_tile) {
2492 RDestroyImage(scr->clip_tile);
2494 scr->clip_tile = wClipMakeTile(scr, img);
2497 scr->icon_tile_pixmap = pixmap;
2499 if (scr->def_icon_pixmap) {
2500 XFreePixmap(dpy, scr->def_icon_pixmap);
2501 scr->def_icon_pixmap = None;
2503 if (scr->def_ticon_pixmap) {
2504 XFreePixmap(dpy, scr->def_ticon_pixmap);
2505 scr->def_ticon_pixmap = None;
2508 if (scr->icon_back_texture) {
2509 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2511 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2513 if (scr->clip_balloon)
2514 XSetWindowBackground(dpy, scr->clip_balloon,
2515 (*texture)->any.color.pixel);
2518 * Free the texture as nobody else will use it, nor refer to it.
2520 if (!entry->addr)
2521 wTextureDestroy(scr, *texture);
2523 return (reset ? REFRESH_ICON_TILE : 0);
2528 static int
2529 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2531 if (scr->title_font) {
2532 WMReleaseFont(scr->title_font);
2534 scr->title_font = font;
2536 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2540 static int
2541 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2543 if (scr->menu_title_font) {
2544 WMReleaseFont(scr->menu_title_font);
2547 scr->menu_title_font = font;
2549 return REFRESH_MENU_TITLE_FONT;
2553 static int
2554 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2556 if (scr->menu_entry_font) {
2557 WMReleaseFont(scr->menu_entry_font);
2559 scr->menu_entry_font = font;
2561 return REFRESH_MENU_FONT;
2566 static int
2567 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2569 if (scr->icon_title_font) {
2570 WMReleaseFont(scr->icon_title_font);
2573 scr->icon_title_font = font;
2575 return REFRESH_ICON_FONT;
2579 static int
2580 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2582 if (scr->clip_title_font) {
2583 WMReleaseFont(scr->clip_title_font);
2586 scr->clip_title_font = font;
2588 return REFRESH_ICON_FONT;
2592 static int
2593 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2595 if (scr->workspace_name_font) {
2596 WMReleaseFont(scr->workspace_name_font);
2599 scr->workspace_name_font = font;
2601 return 0;
2605 static int
2606 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2608 if (scr->select_pixel!=scr->white_pixel &&
2609 scr->select_pixel!=scr->black_pixel) {
2610 wFreeColor(scr, scr->select_pixel);
2613 scr->select_pixel = color->pixel;
2615 return REFRESH_MENU_COLOR;
2619 static int
2620 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2622 if (scr->select_text_pixel!=scr->white_pixel &&
2623 scr->select_text_pixel!=scr->black_pixel) {
2624 wFreeColor(scr, scr->select_text_pixel);
2627 scr->select_text_pixel = color->pixel;
2629 return REFRESH_MENU_COLOR;
2633 static int
2634 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2636 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2637 scr->clip_title_pixel[index]!=scr->black_pixel) {
2638 wFreeColor(scr, scr->clip_title_pixel[index]);
2640 scr->clip_title_pixel[index] = color->pixel;
2642 #ifdef GRADIENT_CLIP_ARROW
2643 if (index == CLIP_NORMAL) {
2644 RImage *image;
2645 RColor color1, color2;
2646 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2647 int as = pt - 15; /* 15 = 5+5+5 */
2649 FREE_PIXMAP(scr->clip_arrow_gradient);
2651 color1.red = (color->red >> 8)*6/10;
2652 color1.green = (color->green >> 8)*6/10;
2653 color1.blue = (color->blue >> 8)*6/10;
2655 color2.red = WMIN((color->red >> 8)*20/10, 255);
2656 color2.green = WMIN((color->green >> 8)*20/10, 255);
2657 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2659 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2660 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2661 RDestroyImage(image);
2663 #endif /* GRADIENT_CLIP_ARROW */
2665 return REFRESH_ICON_TITLE_COLOR;
2669 static int
2670 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2672 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2673 scr->window_title_pixel[index]!=scr->black_pixel) {
2674 wFreeColor(scr, scr->window_title_pixel[index]);
2677 scr->window_title_pixel[index] = color->pixel;
2679 if (index == WS_UNFOCUSED)
2680 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2682 return REFRESH_WINDOW_TITLE_COLOR;
2686 static int
2687 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2689 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2690 scr->menu_title_pixel[0]!=scr->black_pixel) {
2691 #ifdef DRAWSTRING_PLUGIN
2692 if(!scr->drawstring_func[W_STRING_MTITLE])
2693 #endif
2694 wFreeColor(scr, scr->menu_title_pixel[0]);
2697 scr->menu_title_pixel[0] = color->pixel;
2698 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2700 return REFRESH_MENU_TITLE_COLOR;
2704 static int
2705 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2707 XGCValues gcv;
2708 #define gcm (GCForeground|GCBackground|GCFillStyle)
2710 if (scr->mtext_pixel!=scr->white_pixel &&
2711 scr->mtext_pixel!=scr->black_pixel) {
2712 wFreeColor(scr, scr->mtext_pixel);
2715 scr->mtext_pixel = color->pixel;
2717 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2720 if (scr->dtext_pixel == scr->mtext_pixel) {
2721 gcv.foreground = scr->white_pixel;
2722 gcv.background = scr->black_pixel;
2723 gcv.fill_style = FillStippled;
2724 } else {
2725 gcv.foreground = scr->dtext_pixel;
2726 gcv.fill_style = FillSolid;
2728 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2730 return REFRESH_MENU_COLOR;
2731 #undef gcm
2735 static int
2736 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2738 XGCValues gcv;
2739 #define gcm (GCForeground|GCBackground|GCFillStyle)
2741 if (scr->dtext_pixel!=scr->white_pixel &&
2742 scr->dtext_pixel!=scr->black_pixel) {
2743 wFreeColor(scr, scr->dtext_pixel);
2746 scr->dtext_pixel = color->pixel;
2748 if (scr->dtext_pixel == scr->mtext_pixel) {
2749 gcv.foreground = scr->white_pixel;
2750 gcv.background = scr->black_pixel;
2751 gcv.fill_style = FillStippled;
2752 } else {
2753 gcv.foreground = scr->dtext_pixel;
2754 gcv.fill_style = FillSolid;
2756 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2758 return REFRESH_MENU_COLOR;
2759 #undef gcm
2762 static int
2763 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2765 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2767 return REFRESH_ICON_TITLE_COLOR;
2771 static int
2772 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2774 if (scr->icon_title_texture) {
2775 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2777 XQueryColor (dpy, scr->w_colormap, color);
2778 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2780 return REFRESH_ICON_TITLE_BACK;
2784 static void
2785 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2787 close(scr->helper_fd);
2788 scr->helper_fd = 0;
2789 scr->helper_pid = 0;
2790 scr->flags.backimage_helper_launched = 0;
2794 static int
2795 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2796 void *bar)
2798 int i;
2799 proplist_t val;
2800 char *str;
2802 if (scr->flags.backimage_helper_launched) {
2803 if (PLGetNumberOfElements(value)==0) {
2804 SendHelperMessage(scr, 'C', 0, NULL);
2805 SendHelperMessage(scr, 'K', 0, NULL);
2807 PLRelease(value);
2808 return 0;
2810 } else {
2811 pid_t pid;
2812 int filedes[2];
2814 if (PLGetNumberOfElements(value) == 0)
2815 return 0;
2817 if (pipe(filedes) < 0) {
2818 wsyserror("pipe() failed:can't set workspace specific background image");
2820 PLRelease(value);
2821 return 0;
2824 pid = fork();
2825 if (pid < 0) {
2826 wsyserror("fork() failed:can't set workspace specific background image");
2827 if (close(filedes[0]) < 0)
2828 wsyserror("could not close pipe");
2829 if (close(filedes[1]) < 0)
2830 wsyserror("could not close pipe");
2832 } else if (pid == 0) {
2833 SetupEnvironment(scr);
2835 if (close(0) < 0)
2836 wsyserror("could not close pipe");
2837 if (dup(filedes[0]) < 0) {
2838 wsyserror("dup() failed:can't set workspace specific background image");
2840 if (wPreferences.smooth_workspace_back)
2841 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
2842 else
2843 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2844 wsyserror("could not execute wmsetbg");
2845 exit(1);
2846 } else {
2848 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2849 wsyserror("error setting close-on-exec flag");
2851 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2852 wsyserror("error setting close-on-exec flag");
2855 scr->helper_fd = filedes[1];
2856 scr->helper_pid = pid;
2857 scr->flags.backimage_helper_launched = 1;
2859 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2861 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2866 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2867 val = PLGetArrayElement(value, i);
2868 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2869 str = PLGetDescription(val);
2871 SendHelperMessage(scr, 'S', i+1, str);
2873 free(str);
2874 } else {
2875 SendHelperMessage(scr, 'U', i+1, NULL);
2878 sleep(1);
2880 PLRelease(value);
2881 return 0;
2885 static int
2886 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2887 void *bar)
2889 if (scr->flags.backimage_helper_launched) {
2890 char *str;
2892 if (PLGetNumberOfElements(value)==0) {
2893 SendHelperMessage(scr, 'U', 0, NULL);
2894 } else {
2895 /* set the default workspace background to this one */
2896 str = PLGetDescription(value);
2897 if (str) {
2898 SendHelperMessage(scr, 'S', 0, str);
2899 free(str);
2900 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2901 } else {
2902 SendHelperMessage(scr, 'U', 0, NULL);
2905 } else {
2906 char *command;
2907 char *text;
2909 SetupEnvironment(scr);
2910 text = PLGetDescription(value);
2911 command = wmalloc(strlen(text)+40);
2912 if (wPreferences.smooth_workspace_back)
2913 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
2914 else
2915 sprintf(command, "wmsetbg -d -p '%s' &", text);
2916 free(text);
2917 system(command);
2918 free(command);
2920 PLRelease(value);
2922 return 0;
2926 static int
2927 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2929 if (scr->widget_texture) {
2930 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2932 scr->widget_texture = *(WTexSolid**)texture;
2934 return 0;
2938 static int
2939 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2941 if (scr->window_title_texture[WS_FOCUSED]) {
2942 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2944 scr->window_title_texture[WS_FOCUSED] = *texture;
2946 return REFRESH_WINDOW_TEXTURES;
2950 static int
2951 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2953 if (scr->window_title_texture[WS_PFOCUSED]) {
2954 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2956 scr->window_title_texture[WS_PFOCUSED] = *texture;
2958 return REFRESH_WINDOW_TEXTURES;
2962 static int
2963 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2965 if (scr->window_title_texture[WS_UNFOCUSED]) {
2966 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2968 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2970 return REFRESH_WINDOW_TEXTURES;
2974 static int
2975 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2977 if (scr->resizebar_texture[0]) {
2978 wTextureDestroy(scr, scr->resizebar_texture[0]);
2980 scr->resizebar_texture[0] = *texture;
2982 return REFRESH_WINDOW_TEXTURES;
2986 static int
2987 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2989 if (scr->menu_title_texture[0]) {
2990 wTextureDestroy(scr, scr->menu_title_texture[0]);
2992 scr->menu_title_texture[0] = *texture;
2994 return REFRESH_MENU_TITLE_TEXTURE;
2998 static int
2999 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3001 if (scr->menu_item_texture) {
3002 wTextureDestroy(scr, scr->menu_item_texture);
3003 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3005 scr->menu_item_texture = *texture;
3007 scr->menu_item_auxtexture
3008 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3010 return REFRESH_MENU_TEXTURE;
3014 static int
3015 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3017 WWindow *wwin;
3018 wKeyBindings[index] = *shortcut;
3020 wwin = scr->focused_window;
3022 while (wwin!=NULL) {
3023 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3025 if (!WFLAGP(wwin, no_bind_keys)) {
3026 wWindowSetKeyGrabs(wwin);
3028 wwin = wwin->prev;
3031 return 0;
3035 static int
3036 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3038 wArrangeIcons(scr, True);
3040 return 0;
3044 static int
3045 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3047 wScreenUpdateUsableArea(scr);
3049 return 0;
3053 static int
3054 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3056 return REFRESH_MENU_TEXTURE;
3061 static int
3062 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3064 return REFRESH_BUTTON_IMAGES;
3069 * Very ugly kluge.
3070 * Need access to the double click variables, so that all widgets in
3071 * wmaker panels will have the same dbl-click values.
3072 * TODO: figure a better way of dealing with it.
3074 #include "WINGsP.h"
3076 static int
3077 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3079 extern _WINGsConfiguration WINGsConfiguration;
3081 if (*value <= 0)
3082 *(int*)foo = 1;
3084 WINGsConfiguration.doubleClickDelay = *value;
3086 return 0;
3091 static int
3092 setMultiByte(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3094 extern _WINGsConfiguration WINGsConfiguration;
3096 WINGsConfiguration.useMultiByte = *value;
3098 return 0;