For libwraster:
[wmaker-crm.git] / src / defaults.c
blobfbd62fc3dcb4070e010cb59eb76eca258a716196
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"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <time.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <limits.h>
36 #include <signal.h>
38 #ifdef HAVE_DLFCN_H
39 # include <dlfcn.h>
40 #endif
44 #ifndef PATH_MAX
45 #define PATH_MAX DEFAULT_PATH_MAX
46 #endif
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #include <X11/keysym.h>
52 #include <wraster.h>
55 #include "WindowMaker.h"
56 #include "wcore.h"
57 #include "framewin.h"
58 #include "window.h"
59 #include "texture.h"
60 #include "screen.h"
61 #include "resources.h"
62 #include "defaults.h"
63 #include "keybind.h"
64 #include "xmodifier.h"
65 #include "icon.h"
66 #include "funcs.h"
67 #include "actions.h"
68 #include "dock.h"
69 #include "workspace.h"
70 #include "properties.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;
89 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
90 extern Atom _XA_WINDOWMAKER_ICON_TILE;
93 extern proplist_t wDomainName;
94 extern proplist_t wAttributeDomainName;
96 extern WPreferences wPreferences;
98 extern WShortKey wKeyBindings[WKBD_LAST];
100 typedef struct {
101 char *key;
102 char *default_value;
103 void *extra_data;
104 void *addr;
105 int (*convert)();
106 int (*update)();
107 proplist_t plkey;
108 proplist_t plvalue; /* default value */
109 } WDefaultEntry;
112 /* used to map strings to integers */
113 typedef struct {
114 char *string;
115 short value;
116 char is_alias;
117 } WOptionEnumeration;
120 /* type converters */
121 static int getBool();
122 static int getInt();
123 static int getCoord();
124 #if 0
125 /* this is not used yet */
126 static int getString();
127 #endif
128 static int getPathList();
129 static int getEnum();
130 static int getTexture();
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 setClearance();
145 static int setIfDockPresent();
146 static int setStickyIcons();
148 static int setPositive();
150 static int setWidgetColor();
151 static int setIconTile();
152 static int setWinTitleFont();
153 static int setMenuTitleFont();
154 static int setMenuTextFont();
155 static int setIconTitleFont();
156 static int setIconTitleColor();
157 static int setIconTitleBack();
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 #if 0
182 static int setMultiByte();
183 #endif
184 static int updateUsableArea();
186 #ifdef DEFINABLE_CURSOR
187 extern Cursor wCursor[WCUR_LAST];
188 static int getCursor();
189 static int setCursor();
190 #endif
194 * Tables to convert strings to enumeration values.
195 * Values stored are char
199 /* WARNING: sum of length of all value strings must not exceed
200 * this value */
201 #define TOTAL_VALUES_LENGTH 80
206 #define REFRESH_WINDOW_TEXTURES (1<<0)
207 #define REFRESH_MENU_TEXTURE (1<<1)
208 #define REFRESH_MENU_FONT (1<<2)
209 #define REFRESH_MENU_COLOR (1<<3)
210 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
211 #define REFRESH_MENU_TITLE_FONT (1<<5)
212 #define REFRESH_MENU_TITLE_COLOR (1<<6)
213 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
214 #define REFRESH_WINDOW_FONT (1<<8)
215 #define REFRESH_ICON_TILE (1<<9)
216 #define REFRESH_ICON_FONT (1<<10)
217 #define REFRESH_WORKSPACE_BACK (1<<11)
219 #define REFRESH_BUTTON_IMAGES (1<<12)
221 #define REFRESH_ICON_TITLE_COLOR (1<<13)
222 #define REFRESH_ICON_TITLE_BACK (1<<14)
226 static WOptionEnumeration seFocusModes[] = {
227 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
228 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
229 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
230 {NULL, 0, 0}
233 static WOptionEnumeration seColormapModes[] = {
234 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
235 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
236 {NULL, 0, 0}
239 static WOptionEnumeration sePlacements[] = {
240 {"Auto", WPM_AUTO, 0},
241 {"Smart", WPM_SMART, 0},
242 {"Cascade", WPM_CASCADE, 0},
243 {"Random", WPM_RANDOM, 0},
244 {"Manual", WPM_MANUAL, 0},
245 {NULL, 0, 0}
248 static WOptionEnumeration seGeomDisplays[] = {
249 {"Center", WDIS_CENTER, 0},
250 {"Corner", WDIS_TOPLEFT, 0},
251 {"Floating", WDIS_FRAME_CENTER, 0},
252 {"Line", WDIS_NEW, 0},
253 {NULL, 0, 0}
256 static WOptionEnumeration seSpeeds[] = {
257 {"UltraFast", SPEED_ULTRAFAST, 0},
258 {"Fast", SPEED_FAST, 0},
259 {"Medium", SPEED_MEDIUM, 0},
260 {"Slow", SPEED_SLOW, 0},
261 {"UltraSlow", SPEED_ULTRASLOW, 0},
262 {NULL, 0, 0}
265 static WOptionEnumeration seMouseButtons[] = {
266 {"None", -1, 0},
267 {"Left", Button1, 0}, {"Button1", Button1, 1},
268 {"Middle", Button2, 0}, {"Button2", Button2, 1},
269 {"Right", Button3, 0}, {"Button3", Button3, 1},
270 {"Button4", Button4, 0},
271 {"Button5", Button5, 0},
272 {NULL, 0, 0}
275 static WOptionEnumeration seIconificationStyles[] = {
276 {"Zoom", WIS_ZOOM, 0},
277 {"Twist", WIS_TWIST, 0},
278 {"Flip", WIS_FLIP, 0},
279 {"None", WIS_NONE, 0},
280 {"random", WIS_RANDOM, 0},
281 {NULL, 0, 0}
284 static WOptionEnumeration seJustifications[] = {
285 {"Left", WTJ_LEFT, 0},
286 {"Center", WTJ_CENTER, 0},
287 {"Right", WTJ_RIGHT, 0},
288 {NULL, 0, 0}
291 static WOptionEnumeration seIconPositions[] = {
292 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
293 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
294 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
295 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
296 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
297 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
298 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
299 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
300 {NULL, 0, 0}
303 static WOptionEnumeration seMenuStyles[] = {
304 {"normal", MS_NORMAL, 0},
305 {"singletexture", MS_SINGLE_TEXTURE, 0},
306 {"flat", MS_FLAT, 0},
307 {NULL, 0, 0}
311 static WOptionEnumeration seDisplayPositions[] = {
312 {"none", WD_NONE, 0},
313 {"center", WD_CENTER, 0},
314 {"top", WD_TOP, 0},
315 {"bottom", WD_BOTTOM, 0},
316 {"topleft", WD_TOPLEFT, 0},
317 {"topright", WD_TOPRIGHT, 0},
318 {"bottomleft", WD_BOTTOMLEFT, 0},
319 {"bottomright", WD_BOTTOMRIGHT, 0},
320 {NULL, 0, 0}
323 static WOptionEnumeration seWorkspaceBorder[] = {
324 {"None", WB_NONE, 0},
325 {"LeftRight", WB_LEFTRIGHT, 0},
326 {"TopBottom", WB_TOPBOTTOM, 0},
327 {"AllDirections", WB_ALLDIRS, 0},
328 {NULL, 0, 0}
333 * ALL entries in the tables bellow, NEED to have a default value
334 * defined, and this value needs to be correct.
337 /* these options will only affect the window manager on startup
339 * static defaults can't access the screen data, because it is
340 * created after these defaults are read
342 WDefaultEntry staticOptionList[] = {
344 {"ColormapSize", "4", NULL,
345 &wPreferences.cmap_size, getInt, NULL
347 {"DisableDithering", "NO", NULL,
348 &wPreferences.no_dithering, getBool, NULL
350 /* static by laziness */
351 {"IconSize", "64", NULL,
352 &wPreferences.icon_size, getInt, NULL
354 {"ModifierKey", "Mod1", NULL,
355 &wPreferences.modifier_mask, getModMask, NULL
357 {"DisableWSMouseActions", "NO", NULL,
358 &wPreferences.disable_root_mouse, getBool, NULL
360 {"FocusMode", "manual", seFocusModes,
361 &wPreferences.focus_mode, getEnum, NULL
362 }, /* have a problem when switching from manual to sloppy without restart */
363 {"NewStyle", "NO", NULL,
364 &wPreferences.new_style, getBool, NULL
366 {"DisableDock", "NO", (void*) WM_DOCK,
367 NULL, getBool, setIfDockPresent
369 {"DisableClip", "NO", (void*) WM_CLIP,
370 NULL, getBool, setIfDockPresent
372 {"DisableMiniwindows", "NO", NULL,
373 &wPreferences.disable_miniwindows, getBool, NULL
375 #if 0
376 ,{"MultiByteText", "NO", NULL,
377 &wPreferences.multi_byte_text, getBool, setMultiByte
379 #endif
384 WDefaultEntry optionList[] = {
385 /* dynamic options */
386 {"IconPosition", "blh", seIconPositions,
387 &wPreferences.icon_yard, getEnum, setIconPosition
389 {"IconificationStyle", "Zoom", seIconificationStyles,
390 &wPreferences.iconification_style, getEnum, NULL
392 {"SelectWindowsMouseButton", "Left", seMouseButtons,
393 &wPreferences.select_button, getEnum, NULL
395 {"WindowListMouseButton", "Middle", seMouseButtons,
396 &wPreferences.windowl_button, getEnum, NULL
398 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
399 &wPreferences.menu_button, getEnum, NULL
401 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
402 &wPreferences.pixmap_path, getPathList, NULL
404 {"IconPath", DEF_ICON_PATHS, NULL,
405 &wPreferences.icon_path, getPathList, NULL
407 {"ColormapMode", "auto", seColormapModes,
408 &wPreferences.colormap_mode, getEnum, NULL
410 {"AutoFocus", "NO", NULL,
411 &wPreferences.auto_focus, getBool, NULL
413 {"RaiseDelay", "0", NULL,
414 &wPreferences.raise_delay, getInt, NULL
416 {"WindozeCycling", "YES", NULL,
417 &wPreferences.windows_cycling,getBool, NULL
419 {"CirculateRaise", "NO", NULL,
420 &wPreferences.circ_raise, getBool, NULL
422 {"Superfluous", "NO", NULL,
423 &wPreferences.superfluous, getBool, NULL
425 {"AdvanceToNewWorkspace", "NO", NULL,
426 &wPreferences.ws_advance, getBool, NULL
428 {"CycleWorkspaces", "NO", NULL,
429 &wPreferences.ws_cycle, getBool, NULL
431 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
432 &wPreferences.workspace_name_display_position, getEnum, NULL
434 {"WorkspaceBorder", "None", seWorkspaceBorder,
435 &wPreferences.workspace_border_position, getEnum, updateUsableArea
437 {"WorkspaceBorderSize", "0", NULL,
438 &wPreferences.workspace_border_size, getInt, updateUsableArea
440 #ifdef VIRTUAL_DESKTOP
441 {"VirtualEdgeThickness", "1", NULL,
442 &wPreferences.vedge_thickness, getInt, NULL
444 {"VirtualEdgeExtendSpace", "0", NULL,
445 &wPreferences.vedge_bordersize, getInt, NULL
447 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
448 &wPreferences.vedge_hscrollspeed, getInt, NULL
450 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
451 &wPreferences.vedge_vscrollspeed, getInt, NULL
453 {"VirtualEdgeMaximumWidth", "3000", NULL,
454 &wPreferences.vedge_maxwidth, getInt, NULL
456 {"VirtualEdgeMaximumHeight", "3000", NULL,
457 &wPreferences.vedge_maxheight, getInt, NULL
459 #endif
460 {"StickyIcons", "NO", NULL,
461 &wPreferences.sticky_icons, getBool, setStickyIcons
463 {"SaveSessionOnExit", "NO", NULL,
464 &wPreferences.save_session_on_exit, getBool, NULL
466 {"WrapMenus", "NO", NULL,
467 &wPreferences.wrap_menus, getBool, NULL
469 {"ScrollableMenus", "NO", NULL,
470 &wPreferences.scrollable_menus, getBool, NULL
472 {"MenuScrollSpeed", "medium", seSpeeds,
473 &wPreferences.menu_scroll_speed, getEnum, NULL
475 {"IconSlideSpeed", "medium", seSpeeds,
476 &wPreferences.icon_slide_speed, getEnum, NULL
478 {"ShadeSpeed", "medium", seSpeeds,
479 &wPreferences.shade_speed, getEnum, NULL
481 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
482 &wPreferences.dblclick_time, getInt, setDoubleClick,
484 {"AlignSubmenus", "NO", NULL,
485 &wPreferences.align_menus, getBool, NULL
487 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
488 &wPreferences.open_transients_with_parent, getBool, NULL
490 {"WindowPlacement", "auto", sePlacements,
491 &wPreferences.window_placement, getEnum, NULL
493 {"IgnoreFocusClick","NO", NULL,
494 &wPreferences.ignore_focus_click, getBool, NULL
496 {"UseSaveUnders", "NO", NULL,
497 &wPreferences.use_saveunders, getBool, NULL
499 {"OpaqueMove", "NO", NULL,
500 &wPreferences.opaque_move, getBool, NULL
502 {"DisableSound", "NO", NULL,
503 &wPreferences.no_sound, getBool, NULL
505 {"DisableAnimations", "NO", NULL,
506 &wPreferences.no_animations, getBool, NULL
508 {"DontLinkWorkspaces","NO", NULL,
509 &wPreferences.no_autowrap, getBool, NULL
511 {"AutoArrangeIcons", "NO", NULL,
512 &wPreferences.auto_arrange_icons, getBool, NULL
514 {"NoWindowOverDock", "NO", NULL,
515 &wPreferences.no_window_over_dock, getBool, updateUsableArea
517 {"NoWindowOverIcons", "NO", NULL,
518 &wPreferences.no_window_over_icons, getBool, updateUsableArea
520 {"WindowPlaceOrigin", "(0, 0)", NULL,
521 &wPreferences.window_place_origin, getCoord, NULL
523 {"ResizeDisplay", "corner", seGeomDisplays,
524 &wPreferences.size_display, getEnum, NULL
526 {"MoveDisplay", "corner", seGeomDisplays,
527 &wPreferences.move_display, getEnum, NULL
529 {"DontConfirmKill", "NO", NULL,
530 &wPreferences.dont_confirm_kill, getBool,NULL
532 {"WindowTitleBalloons", "NO", NULL,
533 &wPreferences.window_balloon, getBool, NULL
535 {"MiniwindowTitleBalloons", "NO", NULL,
536 &wPreferences.miniwin_balloon,getBool, NULL
538 {"AppIconBalloons", "NO", NULL,
539 &wPreferences.appicon_balloon,getBool, NULL
541 {"HelpBalloons", "NO", NULL,
542 &wPreferences.help_balloon, getBool, NULL
544 {"EdgeResistance", "30", NULL,
545 &wPreferences.edge_resistance,getInt, NULL
547 {"Attraction", "NO", NULL,
548 &wPreferences.attract, getBool, NULL
550 {"DisableBlinking", "NO", NULL,
551 &wPreferences.dont_blink, getBool, NULL
553 /* style options */
554 {"MenuStyle", "normal", seMenuStyles,
555 &wPreferences.menu_style, getEnum, setMenuStyle
557 {"WidgetColor", "(solid, gray)", NULL,
558 NULL, getTexture, setWidgetColor,
560 {"WorkspaceSpecificBack","()", NULL,
561 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
563 /* WorkspaceBack must come after WorkspaceSpecificBack or
564 * WorkspaceBack wont know WorkspaceSpecificBack was also
565 * specified and 2 copies of wmsetbg will be launched */
566 {"WorkspaceBack", "(solid, black)", NULL,
567 NULL, getWSBackground,setWorkspaceBack
569 {"SmoothWorkspaceBack", "NO", NULL,
570 NULL, getBool, NULL
572 {"IconBack", "(solid, gray)", NULL,
573 NULL, getTexture, setIconTile
575 {"TitleJustify", "center", seJustifications,
576 &wPreferences.title_justification, getEnum, setJustify
578 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
579 NULL, getFont, setWinTitleFont,
581 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
582 &wPreferences.window_title_clearance, getInt, setClearance
584 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
585 &wPreferences.menu_title_clearance, getInt, setClearance
587 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
588 &wPreferences.menu_text_clearance, getInt, setClearance
590 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
591 NULL, getFont, setMenuTitleFont
593 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
594 NULL, getFont, setMenuTextFont
596 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
597 NULL, getFont, setIconTitleFont
599 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
600 NULL, getFont, setClipTitleFont
602 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
603 NULL, getFont, setLargeDisplayFont
605 {"HighlightColor", "white", NULL,
606 NULL, getColor, setHightlight
608 {"HighlightTextColor", "black", NULL,
609 NULL, getColor, setHightlightText
611 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
612 NULL, getColor, setClipTitleColor
614 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
615 NULL, getColor, setClipTitleColor
617 {"FTitleColor", "white", (void*)WS_FOCUSED,
618 NULL, getColor, setWTitleColor
620 {"PTitleColor", "white", (void*)WS_PFOCUSED,
621 NULL, getColor, setWTitleColor
623 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
624 NULL, getColor, setWTitleColor
626 {"FTitleBack", "(solid, black)", NULL,
627 NULL, getTexture, setFTitleBack
629 {"PTitleBack", "(solid, \"#616161\")", NULL,
630 NULL, getTexture, setPTitleBack
632 {"UTitleBack", "(solid, gray)", NULL,
633 NULL, getTexture, setUTitleBack
635 {"ResizebarBack", "(solid, gray)", NULL,
636 NULL, getTexture, setResizebarBack
638 {"MenuTitleColor", "white", NULL,
639 NULL, getColor, setMenuTitleColor
641 {"MenuTextColor", "black", NULL,
642 NULL, getColor, setMenuTextColor
644 {"MenuDisabledColor", "\"#616161\"", NULL,
645 NULL, getColor, setMenuDisabledColor
647 {"MenuTitleBack", "(solid, black)", NULL,
648 NULL, getTexture, setMenuTitleBack
650 {"MenuTextBack", "(solid, gray)", NULL,
651 NULL, getTexture, setMenuTextBack
653 {"IconTitleColor", "white", NULL,
654 NULL, getColor, setIconTitleColor
656 {"IconTitleBack", "black", NULL,
657 NULL, getColor, setIconTitleBack
659 /* keybindings */
660 #ifndef LITE
661 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
662 NULL, getKeybind, setKeyGrab
664 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
665 NULL, getKeybind, setKeyGrab
667 #endif /* LITE */
668 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
669 NULL, getKeybind, setKeyGrab
671 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
672 NULL, getKeybind, setKeyGrab
674 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
675 NULL, getKeybind, setKeyGrab
677 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
678 NULL, getKeybind, setKeyGrab
680 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
681 NULL, getKeybind, setKeyGrab
683 {"HideKey", "None", (void*)WKBD_HIDE,
684 NULL, getKeybind, setKeyGrab
686 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
687 NULL, getKeybind, setKeyGrab
689 {"CloseKey", "None", (void*)WKBD_CLOSE,
690 NULL, getKeybind, setKeyGrab
692 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
693 NULL, getKeybind, setKeyGrab
695 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
696 NULL, getKeybind, setKeyGrab
698 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
699 NULL, getKeybind, setKeyGrab
701 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
702 NULL, getKeybind, setKeyGrab
704 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
705 NULL, getKeybind, setKeyGrab
707 {"ShadeKey", "None", (void*)WKBD_SHADE,
708 NULL, getKeybind, setKeyGrab
710 {"SelectKey", "None", (void*)WKBD_SELECT,
711 NULL, getKeybind, setKeyGrab
713 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
714 NULL, getKeybind, setKeyGrab
716 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
717 NULL, getKeybind, setKeyGrab
719 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
720 NULL, getKeybind, setKeyGrab
722 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
723 NULL, getKeybind, setKeyGrab
725 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
726 NULL, getKeybind, setKeyGrab
728 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
729 NULL, getKeybind, setKeyGrab
731 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
732 NULL, getKeybind, setKeyGrab
734 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
735 NULL, getKeybind, setKeyGrab
737 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
738 NULL, getKeybind, setKeyGrab
740 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
741 NULL, getKeybind, setKeyGrab
743 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
744 NULL, getKeybind, setKeyGrab
746 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
747 NULL, getKeybind, setKeyGrab
749 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
750 NULL, getKeybind, setKeyGrab
752 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
753 NULL, getKeybind, setKeyGrab
755 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
756 NULL, getKeybind, setKeyGrab
758 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
759 NULL, getKeybind, setKeyGrab
761 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
762 NULL, getKeybind, setKeyGrab
764 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
765 NULL, getKeybind, setKeyGrab
767 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
768 NULL, getKeybind, setKeyGrab
770 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
771 NULL, getKeybind, setKeyGrab
773 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
774 NULL, getKeybind, setKeyGrab
776 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
777 NULL, getKeybind, setKeyGrab
779 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
780 NULL, getKeybind, setKeyGrab
782 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
783 NULL, getKeybind, setKeyGrab
785 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
786 NULL, getKeybind, setKeyGrab
788 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
789 NULL, getKeybind, setKeyGrab
791 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
792 NULL, getKeybind, setKeyGrab
795 #ifdef KEEP_XKB_LOCK_STATUS
796 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
797 NULL, getKeybind, setKeyGrab
799 {"KbdModeLock", "NO", NULL,
800 &wPreferences.modelock, getBool, NULL
802 #endif /* KEEP_XKB_LOCK_STATUS */
803 #ifdef DEFINABLE_CURSOR
804 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
805 NULL, getCursor, setCursor
807 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
808 NULL, getCursor, setCursor
810 #if 0
811 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
812 NULL, getCursor, setCursor
814 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
815 NULL, getCursor, setCursor
817 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
818 NULL, getCursor, setCursor
820 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
821 NULL, getCursor, setCursor
823 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
824 NULL, getCursor, setCursor
826 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
827 NULL, getCursor, setCursor
829 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
830 NULL, getCursor, setCursor
832 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
833 NULL, getCursor, setCursor
835 #endif
836 #endif /* DEFINABLE_CURSOR */
840 #if 0
841 static void rereadDefaults(void);
842 #endif
844 #if 0
845 static void
846 rereadDefaults(void)
848 /* must defer the update because accessing X data from a
849 * signal handler can mess up Xlib */
852 #endif
854 static void
855 initDefaults()
857 int i;
858 WDefaultEntry *entry;
860 PLSetStringCmpHook(StringCompareHook);
862 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
863 entry = &optionList[i];
865 entry->plkey = PLMakeString(entry->key);
866 if (entry->default_value)
867 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
868 else
869 entry->plvalue = NULL;
872 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
873 entry = &staticOptionList[i];
875 entry->plkey = PLMakeString(entry->key);
876 if (entry->default_value)
877 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
878 else
879 entry->plvalue = NULL;
883 wDomainName = PLMakeString(WMDOMAIN_NAME);
884 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
886 PLRegister(wDomainName, rereadDefaults);
887 PLRegister(wAttributeDomainName, rereadDefaults);
894 #if 0
895 proplist_t
896 wDefaultsInit(int screen_number)
898 static int defaults_inited = 0;
899 proplist_t dict;
901 if (!defaults_inited) {
902 initDefaults();
905 dict = PLGetDomain(wDomainName);
906 if (!dict) {
907 wwarning(_("could not read domain \"%s\" from defaults database"),
908 PLGetString(wDomainName));
911 return dict;
913 #endif
916 void
917 wDefaultsDestroyDomain(WDDomain *domain)
919 if (domain->dictionary)
920 PLRelease(domain->dictionary);
921 wfree(domain->path);
922 wfree(domain);
926 WDDomain*
927 wDefaultsInitDomain(char *domain, Bool requireDictionary)
929 WDDomain *db;
930 struct stat stbuf;
931 static int inited = 0;
932 char path[PATH_MAX];
933 char *the_path;
934 proplist_t shared_dict=NULL;
936 if (!inited) {
937 inited = 1;
938 initDefaults();
941 db = wmalloc(sizeof(WDDomain));
942 memset(db, 0, sizeof(WDDomain));
943 db->domain_name = domain;
944 db->path = wdefaultspathfordomain(domain);
945 the_path = db->path;
947 if (the_path && stat(the_path, &stbuf)>=0) {
948 db->dictionary = ReadProplistFromFile(the_path);
949 if (db->dictionary) {
950 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
951 PLRelease(db->dictionary);
952 db->dictionary = NULL;
953 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
954 domain, the_path);
956 db->timestamp = stbuf.st_mtime;
957 } else {
958 wwarning(_("could not load domain %s from user defaults database"),
959 domain);
963 /* global system dictionary */
964 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
965 if (stat(path, &stbuf)>=0) {
966 shared_dict = ReadProplistFromFile(path);
967 if (shared_dict) {
968 if (requireDictionary && !PLIsDictionary(shared_dict)) {
969 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
970 domain, path);
971 PLRelease(shared_dict);
972 shared_dict = NULL;
973 } else {
974 if (db->dictionary && PLIsDictionary(shared_dict) &&
975 PLIsDictionary(db->dictionary)) {
976 PLMergeDictionaries(shared_dict, db->dictionary);
977 PLRelease(db->dictionary);
978 db->dictionary = shared_dict;
979 if (stbuf.st_mtime > db->timestamp)
980 db->timestamp = stbuf.st_mtime;
981 } else if (!db->dictionary) {
982 db->dictionary = shared_dict;
983 if (stbuf.st_mtime > db->timestamp)
984 db->timestamp = stbuf.st_mtime;
987 } else {
988 wwarning(_("could not load domain %s from global defaults database (%s)"),
989 domain, path);
993 /* set to save it in user's directory, no matter from where it was read */
994 if (db->dictionary) {
995 proplist_t tmp = PLMakeString(db->path);
997 PLSetFilename(db->dictionary, tmp);
998 PLRelease(tmp);
1001 return db;
1005 void
1006 wReadStaticDefaults(proplist_t dict)
1008 proplist_t plvalue;
1009 WDefaultEntry *entry;
1010 int i;
1011 void *tdata;
1014 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1015 entry = &staticOptionList[i];
1017 if (dict)
1018 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1019 else
1020 plvalue = NULL;
1022 if (!plvalue) {
1023 /* no default in the DB. Use builtin default */
1024 plvalue = entry->plvalue;
1027 if (plvalue) {
1028 /* convert data */
1029 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1030 if (entry->update) {
1031 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1038 void
1039 wDefaultsCheckDomains(void *foo)
1041 WScreen *scr;
1042 struct stat stbuf;
1043 proplist_t dict;
1044 int i;
1045 char path[PATH_MAX];
1047 #ifdef HEARTBEAT
1048 puts("Checking domains...");
1049 #endif
1050 if (stat(WDWindowMaker->path, &stbuf)>=0
1051 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1052 proplist_t shared_dict = NULL;
1053 #ifdef HEARTBEAT
1054 puts("Checking WindowMaker domain");
1055 #endif
1056 WDWindowMaker->timestamp = stbuf.st_mtime;
1058 /* global dictionary */
1059 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1060 if (stat(path, &stbuf)>=0) {
1061 shared_dict = ReadProplistFromFile(path);
1062 if (shared_dict && !PLIsDictionary(shared_dict)) {
1063 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1064 "WindowMaker", path);
1065 PLRelease(shared_dict);
1066 shared_dict = NULL;
1067 } else if (!shared_dict) {
1068 wwarning(_("could not load domain %s from global defaults database"),
1069 "WindowMaker");
1072 /* user dictionary */
1073 dict = ReadProplistFromFile(WDWindowMaker->path);
1074 if (dict) {
1075 if (!PLIsDictionary(dict)) {
1076 PLRelease(dict);
1077 dict = NULL;
1078 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1079 "WindowMaker", WDWindowMaker->path);
1080 } else {
1081 if (shared_dict) {
1082 PLSetFilename(shared_dict, PLGetFilename(dict));
1083 PLMergeDictionaries(shared_dict, dict);
1084 PLRelease(dict);
1085 dict = shared_dict;
1086 shared_dict = NULL;
1088 for (i=0; i<wScreenCount; i++) {
1089 scr = wScreenWithNumber(i);
1090 if (scr)
1091 wReadDefaults(scr, dict);
1093 if (WDWindowMaker->dictionary) {
1094 PLRelease(WDWindowMaker->dictionary);
1096 WDWindowMaker->dictionary = dict;
1098 } else {
1099 wwarning(_("could not load domain %s from user defaults database"),
1100 "WindowMaker");
1102 if (shared_dict) {
1103 PLRelease(shared_dict);
1107 if (stat(WDWindowAttributes->path, &stbuf)>=0
1108 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1109 #ifdef HEARTBEAT
1110 puts("Checking WMWindowAttributes domain");
1111 #endif
1112 dict = ReadProplistFromFile(WDWindowAttributes->path);
1113 if (dict) {
1114 if (!PLIsDictionary(dict)) {
1115 PLRelease(dict);
1116 dict = NULL;
1117 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1118 "WMWindowAttributes", WDWindowAttributes->path);
1119 } else {
1120 if (WDWindowAttributes->dictionary)
1121 PLRelease(WDWindowAttributes->dictionary);
1122 WDWindowAttributes->dictionary = dict;
1123 for (i=0; i<wScreenCount; i++) {
1124 scr = wScreenWithNumber(i);
1125 if (scr) {
1126 RImage *image;
1128 wDefaultUpdateIcons(scr);
1130 /* Update the panel image if changed */
1131 /* Don't worry. If the image is the same these
1132 * functions will have no performance impact. */
1133 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1135 if (!image) {
1136 wwarning(_("could not load logo image for panels: %s"),
1137 RMessageForError(RErrorCode));
1138 } else {
1139 WMSetApplicationIconImage(scr->wmscreen, image);
1140 RReleaseImage(image);
1145 } else {
1146 wwarning(_("could not load domain %s from user defaults database"),
1147 "WMWindowAttributes");
1149 WDWindowAttributes->timestamp = stbuf.st_mtime;
1152 #ifndef LITE
1153 if (stat(WDRootMenu->path, &stbuf)>=0
1154 && WDRootMenu->timestamp < stbuf.st_mtime) {
1155 dict = ReadProplistFromFile(WDRootMenu->path);
1156 #ifdef HEARTBEAT
1157 puts("Checking WMRootMenu domain");
1158 #endif
1159 if (dict) {
1160 if (!PLIsArray(dict) && !PLIsString(dict)) {
1161 PLRelease(dict);
1162 dict = NULL;
1163 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1164 "WMRootMenu", WDRootMenu->path);
1165 } else {
1166 if (WDRootMenu->dictionary) {
1167 PLRelease(WDRootMenu->dictionary);
1169 WDRootMenu->dictionary = dict;
1171 } else {
1172 wwarning(_("could not load domain %s from user defaults database"),
1173 "WMRootMenu");
1175 WDRootMenu->timestamp = stbuf.st_mtime;
1177 #endif /* !LITE */
1179 if (!foo)
1180 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1184 void
1185 wReadDefaults(WScreen *scr, proplist_t new_dict)
1187 proplist_t plvalue, old_value;
1188 WDefaultEntry *entry;
1189 int i, must_update;
1190 int update_workspace_back = 0; /* kluge :/ */
1191 int needs_refresh;
1192 void *tdata;
1193 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1194 ? WDWindowMaker->dictionary : NULL);
1196 must_update = 0;
1198 needs_refresh = 0;
1200 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1201 entry = &optionList[i];
1203 if (new_dict)
1204 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1205 else
1206 plvalue = NULL;
1208 if (!old_dict)
1209 old_value = NULL;
1210 else
1211 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1214 if (!plvalue && !old_value) {
1215 /* no default in the DB. Use builtin default */
1216 plvalue = entry->plvalue;
1217 if (plvalue && new_dict) {
1218 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1219 must_update = 1;
1221 } else if (!plvalue) {
1222 /* value was deleted from DB. Keep current value */
1223 continue;
1224 } else if (!old_value) {
1225 /* set value for the 1st time */
1226 } else if (!PLIsEqual(plvalue, old_value)) {
1227 /* value has changed */
1228 } else {
1230 if (strcmp(entry->key, "WorkspaceBack") == 0
1231 && update_workspace_back
1232 && scr->flags.backimage_helper_launched) {
1233 } else {
1234 /* value was not changed since last time */
1235 continue;
1239 if (plvalue) {
1240 #ifdef DEBUG
1241 printf("Updating %s to %s\n", entry->key,
1242 PLGetDescription(plvalue));
1243 #endif
1244 /* convert data */
1245 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1247 * If the WorkspaceSpecificBack data has been changed
1248 * so that the helper will be launched now, we must be
1249 * sure to send the default background texture config
1250 * to the helper.
1252 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1253 && !scr->flags.backimage_helper_launched) {
1254 update_workspace_back = 1;
1256 if (entry->update) {
1257 needs_refresh |=
1258 (*entry->update)(scr, entry, tdata, entry->extra_data);
1264 if (needs_refresh!=0 && !scr->flags.startup) {
1265 int foo;
1267 foo = 0;
1268 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1269 foo |= WTextureSettings;
1270 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1271 foo |= WFontSettings;
1272 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1273 foo |= WColorSettings;
1274 if (foo)
1275 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1276 (void*)foo);
1278 foo = 0;
1279 if (needs_refresh & REFRESH_MENU_TEXTURE)
1280 foo |= WTextureSettings;
1281 if (needs_refresh & REFRESH_MENU_FONT)
1282 foo |= WFontSettings;
1283 if (needs_refresh & REFRESH_MENU_COLOR)
1284 foo |= WColorSettings;
1285 if (foo)
1286 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1287 (void*)foo);
1289 foo = 0;
1290 if (needs_refresh & REFRESH_WINDOW_FONT) {
1291 foo |= WFontSettings;
1293 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1294 foo |= WTextureSettings;
1296 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1297 foo |= WColorSettings;
1299 if (foo)
1300 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1301 (void*)foo);
1303 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1304 foo = 0;
1305 if (needs_refresh & REFRESH_ICON_FONT) {
1306 foo |= WFontSettings;
1308 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1309 foo |= WTextureSettings;
1311 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1312 foo |= WTextureSettings;
1314 if (foo)
1315 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1316 (void*)foo);
1318 if (needs_refresh & REFRESH_ICON_TILE)
1319 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1324 void
1325 wDefaultUpdateIcons(WScreen *scr)
1327 WAppIcon *aicon = scr->app_icon_list;
1328 WWindow *wwin = scr->focused_window;
1329 char *file;
1331 while(aicon) {
1332 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1333 False);
1334 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1335 || (file && !aicon->icon->file)) {
1336 RImage *new_image;
1338 if (aicon->icon->file)
1339 wfree(aicon->icon->file);
1340 aicon->icon->file = wstrdup(file);
1342 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1343 aicon->wm_class);
1344 if (new_image) {
1345 wIconChangeImage(aicon->icon, new_image);
1346 wAppIconPaint(aicon);
1349 aicon = aicon->next;
1352 if (!wPreferences.flags.noclip)
1353 wClipIconPaint(scr->clip_icon);
1355 while (wwin) {
1356 if (wwin->icon && wwin->flags.miniaturized) {
1357 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1358 False);
1359 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1360 || (file && !wwin->icon->file)) {
1361 RImage *new_image;
1363 if (wwin->icon->file)
1364 wfree(wwin->icon->file);
1365 wwin->icon->file = wstrdup(file);
1367 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1368 wwin->wm_class);
1369 if (new_image)
1370 wIconChangeImage(wwin->icon, new_image);
1373 wwin = wwin->prev;
1378 /* --------------------------- Local ----------------------- */
1380 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1381 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1382 entry->key, x); \
1383 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1384 var = entry->default_value;\
1385 } else var = PLGetString(value)\
1391 static int
1392 string2index(proplist_t key, proplist_t val, proplist_t def,
1393 WOptionEnumeration *values)
1395 char *str;
1396 WOptionEnumeration *v;
1397 char buffer[TOTAL_VALUES_LENGTH];
1399 if (PLIsString(val) && (str = PLGetString(val))) {
1400 for (v=values; v->string!=NULL; v++) {
1401 if (strcasecmp(v->string, str)==0)
1402 return v->value;
1406 buffer[0] = 0;
1407 for (v=values; v->string!=NULL; v++) {
1408 if (!v->is_alias) {
1409 if (buffer[0]!=0)
1410 strcat(buffer, ", ");
1411 strcat(buffer, v->string);
1414 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1415 PLGetString(key), buffer);
1417 if (def) {
1418 return string2index(key, val, NULL, values);
1421 return -1;
1428 * value - is the value in the defaults DB
1429 * addr - is the address to store the data
1430 * ret - is the address to store a pointer to a temporary buffer. ret
1431 * must not be freed and is used by the set functions
1433 static int
1434 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1435 void **ret)
1437 static char data;
1438 char *val;
1439 int second_pass=0;
1441 GET_STRING_OR_DEFAULT("Boolean", val);
1443 again:
1444 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1445 || strcasecmp(val, "YES")==0) {
1447 data = 1;
1448 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1449 || strcasecmp(val, "NO")==0) {
1450 data = 0;
1451 } else {
1452 int i;
1453 if (sscanf(val, "%i", &i)==1) {
1454 if (i!=0)
1455 data = 1;
1456 else
1457 data = 0;
1458 } else {
1459 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1460 val, entry->key);
1461 if (second_pass==0) {
1462 val = PLGetString(entry->plvalue);
1463 second_pass = 1;
1464 wwarning(_("using default \"%s\" instead"), val);
1465 goto again;
1467 return False;
1471 if (ret)
1472 *ret = &data;
1474 if (addr) {
1475 *(char*)addr = data;
1478 return True;
1482 static int
1483 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1484 void **ret)
1486 static int data;
1487 char *val;
1490 GET_STRING_OR_DEFAULT("Integer", val);
1492 if (sscanf(val, "%i", &data)!=1) {
1493 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1494 val, entry->key);
1495 val = PLGetString(entry->plvalue);
1496 wwarning(_("using default \"%s\" instead"), val);
1497 if (sscanf(val, "%i", &data)!=1) {
1498 return False;
1502 if (ret)
1503 *ret = &data;
1505 if (addr) {
1506 *(int*)addr = data;
1508 return True;
1512 static int
1513 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1514 void **ret)
1516 static WCoord data;
1517 char *val_x, *val_y;
1518 int nelem, changed=0;
1519 proplist_t elem_x, elem_y;
1521 again:
1522 if (!PLIsArray(value)) {
1523 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1524 entry->key, "Coordinate");
1525 if (changed==0) {
1526 value = entry->plvalue;
1527 changed = 1;
1528 wwarning(_("using default \"%s\" instead"), entry->default_value);
1529 goto again;
1531 return False;
1534 nelem = PLGetNumberOfElements(value);
1535 if (nelem != 2) {
1536 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1537 entry->key);
1538 if (changed==0) {
1539 value = entry->plvalue;
1540 changed = 1;
1541 wwarning(_("using default \"%s\" instead"), entry->default_value);
1542 goto again;
1544 return False;
1547 elem_x = PLGetArrayElement(value, 0);
1548 elem_y = PLGetArrayElement(value, 1);
1550 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1551 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1552 entry->key);
1553 if (changed==0) {
1554 value = entry->plvalue;
1555 changed = 1;
1556 wwarning(_("using default \"%s\" instead"), entry->default_value);
1557 goto again;
1559 return False;
1562 val_x = PLGetString(elem_x);
1563 val_y = PLGetString(elem_y);
1565 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1566 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1567 if (changed==0) {
1568 value = entry->plvalue;
1569 changed = 1;
1570 wwarning(_("using default \"%s\" instead"), entry->default_value);
1571 goto again;
1573 return False;
1576 if (data.x < 0)
1577 data.x = 0;
1578 else if (data.x > scr->scr_width/3)
1579 data.x = scr->scr_width/3;
1580 if (data.y < 0)
1581 data.y = 0;
1582 else if (data.y > scr->scr_height/3)
1583 data.y = scr->scr_height/3;
1585 if (ret)
1586 *ret = &data;
1588 if (addr) {
1589 *(WCoord*)addr = data;
1592 return True;
1596 #if 0
1597 /* This function is not used at the moment. */
1598 static int
1599 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1600 void **ret)
1602 static char *data;
1604 GET_STRING_OR_DEFAULT("String", data);
1606 if (!data) {
1607 data = PLGetString(entry->plvalue);
1608 if (!data)
1609 return False;
1612 if (ret)
1613 *ret = &data;
1615 if (addr)
1616 *(char**)addr = wstrdup(data);
1618 return True;
1620 #endif
1623 static int
1624 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1625 void **ret)
1627 static char *data;
1628 int i, count, len;
1629 char *ptr;
1630 proplist_t d;
1631 int changed=0;
1633 again:
1634 if (!PLIsArray(value)) {
1635 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1636 entry->key, "an array of paths");
1637 if (changed==0) {
1638 value = entry->plvalue;
1639 changed = 1;
1640 wwarning(_("using default \"%s\" instead"), entry->default_value);
1641 goto again;
1643 return False;
1646 i = 0;
1647 count = PLGetNumberOfElements(value);
1648 if (count < 1) {
1649 if (changed==0) {
1650 value = entry->plvalue;
1651 changed = 1;
1652 wwarning(_("using default \"%s\" instead"), entry->default_value);
1653 goto again;
1655 return False;
1658 len = 0;
1659 for (i=0; i<count; i++) {
1660 d = PLGetArrayElement(value, i);
1661 if (!d || !PLIsString(d)) {
1662 count = i;
1663 break;
1665 len += strlen(PLGetString(d))+1;
1668 ptr = data = wmalloc(len+1);
1670 for (i=0; i<count; i++) {
1671 d = PLGetArrayElement(value, i);
1672 if (!d || !PLIsString(d)) {
1673 break;
1675 strcpy(ptr, PLGetString(d));
1676 ptr += strlen(PLGetString(d));
1677 *ptr = ':';
1678 ptr++;
1680 ptr--; *(ptr--) = 0;
1682 if (*(char**)addr!=NULL) {
1683 wfree(*(char**)addr);
1685 *(char**)addr = data;
1687 return True;
1691 static int
1692 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1693 void **ret)
1695 static signed char data;
1697 data = string2index(entry->plkey, value, entry->default_value,
1698 (WOptionEnumeration*)entry->extra_data);
1699 if (data < 0)
1700 return False;
1702 if (ret)
1703 *ret = &data;
1705 if (addr)
1706 *(signed char*)addr = data;
1708 return True;
1714 * (solid <color>)
1715 * (hgradient <color> <color>)
1716 * (vgradient <color> <color>)
1717 * (dgradient <color> <color>)
1718 * (mhgradient <color> <color> ...)
1719 * (mvgradient <color> <color> ...)
1720 * (mdgradient <color> <color> ...)
1721 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1722 * (tpixmap <file> <color>)
1723 * (spixmap <file> <color>)
1724 * (cpixmap <file> <color>)
1725 * (thgradient <file> <opaqueness> <color> <color>)
1726 * (tvgradient <file> <opaqueness> <color> <color>)
1727 * (tdgradient <file> <opaqueness> <color> <color>)
1728 * (function <lib> <function> ...)
1731 static WTexture*
1732 parse_texture(WScreen *scr, proplist_t pl)
1734 proplist_t elem;
1735 char *val;
1736 int nelem;
1737 WTexture *texture=NULL;
1739 nelem = PLGetNumberOfElements(pl);
1740 if (nelem < 1)
1741 return NULL;
1744 elem = PLGetArrayElement(pl, 0);
1745 if (!elem || !PLIsString(elem))
1746 return NULL;
1747 val = PLGetString(elem);
1750 if (strcasecmp(val, "solid")==0) {
1751 XColor color;
1753 if (nelem != 2)
1754 return NULL;
1756 /* get color */
1758 elem = PLGetArrayElement(pl, 1);
1759 if (!elem || !PLIsString(elem))
1760 return NULL;
1761 val = PLGetString(elem);
1763 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1764 wwarning(_("\"%s\" is not a valid color name"), val);
1765 return NULL;
1768 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1769 } else if (strcasecmp(val, "dgradient")==0
1770 || strcasecmp(val, "vgradient")==0
1771 || strcasecmp(val, "hgradient")==0) {
1772 RColor color1, color2;
1773 XColor xcolor;
1774 int type;
1776 if (nelem != 3) {
1777 wwarning(_("bad number of arguments in gradient specification"));
1778 return NULL;
1781 if (val[0]=='d' || val[0]=='D')
1782 type = WTEX_DGRADIENT;
1783 else if (val[0]=='h' || val[0]=='H')
1784 type = WTEX_HGRADIENT;
1785 else
1786 type = WTEX_VGRADIENT;
1789 /* get from color */
1790 elem = PLGetArrayElement(pl, 1);
1791 if (!elem || !PLIsString(elem))
1792 return NULL;
1793 val = PLGetString(elem);
1795 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1796 wwarning(_("\"%s\" is not a valid color name"), val);
1797 return NULL;
1799 color1.alpha = 255;
1800 color1.red = xcolor.red >> 8;
1801 color1.green = xcolor.green >> 8;
1802 color1.blue = xcolor.blue >> 8;
1804 /* get to color */
1805 elem = PLGetArrayElement(pl, 2);
1806 if (!elem || !PLIsString(elem)) {
1807 return NULL;
1809 val = PLGetString(elem);
1811 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1812 wwarning(_("\"%s\" is not a valid color name"), val);
1813 return NULL;
1815 color2.alpha = 255;
1816 color2.red = xcolor.red >> 8;
1817 color2.green = xcolor.green >> 8;
1818 color2.blue = xcolor.blue >> 8;
1820 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1822 } else if (strcasecmp(val, "igradient")==0) {
1823 RColor colors1[2], colors2[2];
1824 int th1, th2;
1825 XColor xcolor;
1826 int i;
1828 if (nelem != 7) {
1829 wwarning(_("bad number of arguments in gradient specification"));
1830 return NULL;
1833 /* get from color */
1834 for (i = 0; i < 2; i++) {
1835 elem = PLGetArrayElement(pl, 1+i);
1836 if (!elem || !PLIsString(elem))
1837 return NULL;
1838 val = PLGetString(elem);
1840 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1841 wwarning(_("\"%s\" is not a valid color name"), val);
1842 return NULL;
1844 colors1[i].alpha = 255;
1845 colors1[i].red = xcolor.red >> 8;
1846 colors1[i].green = xcolor.green >> 8;
1847 colors1[i].blue = xcolor.blue >> 8;
1849 elem = PLGetArrayElement(pl, 3);
1850 if (!elem || !PLIsString(elem))
1851 return NULL;
1852 val = PLGetString(elem);
1853 th1 = atoi(val);
1856 /* get from color */
1857 for (i = 0; i < 2; i++) {
1858 elem = PLGetArrayElement(pl, 4+i);
1859 if (!elem || !PLIsString(elem))
1860 return NULL;
1861 val = PLGetString(elem);
1863 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1864 wwarning(_("\"%s\" is not a valid color name"), val);
1865 return NULL;
1867 colors2[i].alpha = 255;
1868 colors2[i].red = xcolor.red >> 8;
1869 colors2[i].green = xcolor.green >> 8;
1870 colors2[i].blue = xcolor.blue >> 8;
1872 elem = PLGetArrayElement(pl, 6);
1873 if (!elem || !PLIsString(elem))
1874 return NULL;
1875 val = PLGetString(elem);
1876 th2 = atoi(val);
1878 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1879 th2, colors2);
1881 } else if (strcasecmp(val, "mhgradient")==0
1882 || strcasecmp(val, "mvgradient")==0
1883 || strcasecmp(val, "mdgradient")==0) {
1884 XColor color;
1885 RColor **colors;
1886 int i, count;
1887 int type;
1889 if (nelem < 3) {
1890 wwarning(_("too few arguments in multicolor gradient specification"));
1891 return NULL;
1894 if (val[1]=='h' || val[1]=='H')
1895 type = WTEX_MHGRADIENT;
1896 else if (val[1]=='v' || val[1]=='V')
1897 type = WTEX_MVGRADIENT;
1898 else
1899 type = WTEX_MDGRADIENT;
1901 count = nelem-1;
1903 colors = wmalloc(sizeof(RColor*)*(count+1));
1905 for (i=0; i<count; i++) {
1906 elem = PLGetArrayElement(pl, i+1);
1907 if (!elem || !PLIsString(elem)) {
1908 for (--i; i>=0; --i) {
1909 wfree(colors[i]);
1911 wfree(colors);
1912 return NULL;
1914 val = PLGetString(elem);
1916 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1917 wwarning(_("\"%s\" is not a valid color name"), val);
1918 for (--i; i>=0; --i) {
1919 wfree(colors[i]);
1921 wfree(colors);
1922 return NULL;
1923 } else {
1924 colors[i] = wmalloc(sizeof(RColor));
1925 colors[i]->red = color.red >> 8;
1926 colors[i]->green = color.green >> 8;
1927 colors[i]->blue = color.blue >> 8;
1930 colors[i] = NULL;
1932 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1933 } else if (strcasecmp(val, "spixmap")==0 ||
1934 strcasecmp(val, "cpixmap")==0 ||
1935 strcasecmp(val, "tpixmap")==0) {
1936 XColor color;
1937 int type;
1939 if (nelem != 3)
1940 return NULL;
1942 if (val[0] == 's' || val[0] == 'S')
1943 type = WTP_SCALE;
1944 else if (val[0] == 'c' || val[0] == 'C')
1945 type = WTP_CENTER;
1946 else
1947 type = WTP_TILE;
1949 /* get color */
1950 elem = PLGetArrayElement(pl, 2);
1951 if (!elem || !PLIsString(elem)) {
1952 return NULL;
1954 val = PLGetString(elem);
1956 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1957 wwarning(_("\"%s\" is not a valid color name"), val);
1958 return NULL;
1961 /* file name */
1962 elem = PLGetArrayElement(pl, 1);
1963 if (!elem || !PLIsString(elem))
1964 return NULL;
1965 val = PLGetString(elem);
1967 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1968 } else if (strcasecmp(val, "thgradient")==0
1969 || strcasecmp(val, "tvgradient")==0
1970 || strcasecmp(val, "tdgradient")==0) {
1971 RColor color1, color2;
1972 XColor xcolor;
1973 int opacity;
1974 int style;
1976 if (val[1]=='h' || val[1]=='H')
1977 style = WTEX_THGRADIENT;
1978 else if (val[1]=='v' || val[1]=='V')
1979 style = WTEX_TVGRADIENT;
1980 else
1981 style = WTEX_TDGRADIENT;
1983 if (nelem != 5) {
1984 wwarning(_("bad number of arguments in textured gradient specification"));
1985 return NULL;
1988 /* get from color */
1989 elem = PLGetArrayElement(pl, 3);
1990 if (!elem || !PLIsString(elem))
1991 return NULL;
1992 val = PLGetString(elem);
1994 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1995 wwarning(_("\"%s\" is not a valid color name"), val);
1996 return NULL;
1998 color1.alpha = 255;
1999 color1.red = xcolor.red >> 8;
2000 color1.green = xcolor.green >> 8;
2001 color1.blue = xcolor.blue >> 8;
2003 /* get to color */
2004 elem = PLGetArrayElement(pl, 4);
2005 if (!elem || !PLIsString(elem)) {
2006 return NULL;
2008 val = PLGetString(elem);
2010 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2011 wwarning(_("\"%s\" is not a valid color name"), val);
2012 return NULL;
2014 color2.alpha = 255;
2015 color2.red = xcolor.red >> 8;
2016 color2.green = xcolor.green >> 8;
2017 color2.blue = xcolor.blue >> 8;
2019 /* get opacity */
2020 elem = PLGetArrayElement(pl, 2);
2021 if (!elem || !PLIsString(elem))
2022 opacity = 128;
2023 else
2024 val = PLGetString(elem);
2026 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2027 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2028 opacity = 128;
2031 /* get file name */
2032 elem = PLGetArrayElement(pl, 1);
2033 if (!elem || !PLIsString(elem))
2034 return NULL;
2035 val = PLGetString(elem);
2037 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2038 val, opacity);
2040 #ifdef TEXTURE_PLUGIN
2041 else if (strcasecmp(val, "function")==0) {
2042 WTexFunction *function;
2043 void (*initFunc) (Display *, Colormap);
2044 char *lib, *func, **argv;
2045 int i, argc;
2047 if (nelem < 3)
2048 return NULL;
2050 /* get the library name */
2051 elem = PLGetArrayElement(pl, 1);
2052 if (!elem || !PLIsString(elem)) {
2053 return NULL;
2055 lib = PLGetString(elem);
2057 /* get the function name */
2058 elem = PLGetArrayElement(pl, 2);
2059 if (!elem || !PLIsString(elem)) {
2060 return NULL;
2062 func = PLGetString(elem);
2064 argc = nelem - 2;
2065 argv = (char **)wmalloc(argc * sizeof(char *));
2067 /* get the parameters */
2068 argv[0] = wstrdup(func);
2069 for (i = 0; i < argc - 1; i++) {
2070 elem = PLGetArrayElement(pl, 3 + i);
2071 if (!elem || !PLIsString(elem)) {
2072 wfree(argv);
2074 return NULL;
2076 argv[i+1] = wstrdup(PLGetString(elem));
2079 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2081 #ifdef HAVE_DLFCN_H
2082 if (function) {
2083 initFunc = dlsym(function->handle, "initWindowMaker");
2084 if (initFunc) {
2085 initFunc(dpy, scr->w_colormap);
2086 } else {
2087 wwarning(_("could not initialize library %s"), lib);
2089 } else {
2090 wwarning(_("could not find function %s::%s"), lib, func);
2092 #endif /* HAVE_DLFCN_H */
2093 texture = (WTexture*)function;
2095 #endif /* TEXTURE_PLUGIN */
2096 else {
2097 wwarning(_("invalid texture type %s"), val);
2098 return NULL;
2100 return texture;
2105 static int
2106 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2107 void **ret)
2109 static WTexture *texture;
2110 int changed=0;
2112 again:
2113 if (!PLIsArray(value)) {
2114 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2115 entry->key, "Texture");
2116 if (changed==0) {
2117 value = entry->plvalue;
2118 changed = 1;
2119 wwarning(_("using default \"%s\" instead"), entry->default_value);
2120 goto again;
2122 return False;
2125 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2126 proplist_t pl;
2128 pl = PLGetArrayElement(value, 0);
2129 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2130 || strcasecmp(PLGetString(pl), "solid")!=0) {
2131 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2132 entry->key, "Solid Texture");
2134 value = entry->plvalue;
2135 changed = 1;
2136 wwarning(_("using default \"%s\" instead"), entry->default_value);
2137 goto again;
2141 texture = parse_texture(scr, value);
2143 if (!texture) {
2144 wwarning(_("Error in texture specification for key \"%s\""),
2145 entry->key);
2146 if (changed==0) {
2147 value = entry->plvalue;
2148 changed = 1;
2149 wwarning(_("using default \"%s\" instead"), entry->default_value);
2150 goto again;
2152 return False;
2155 if (ret)
2156 *ret = &texture;
2158 if (addr)
2159 *(WTexture**)addr = texture;
2161 return True;
2165 static int
2166 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2167 void *addr, void **ret)
2169 proplist_t elem;
2170 int changed = 0;
2171 char *val;
2172 int nelem;
2174 again:
2175 if (!PLIsArray(value)) {
2176 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2177 "WorkspaceBack", "Texture or None");
2178 if (changed==0) {
2179 value = entry->plvalue;
2180 changed = 1;
2181 wwarning(_("using default \"%s\" instead"), entry->default_value);
2182 goto again;
2184 return False;
2187 /* only do basic error checking and verify for None texture */
2189 nelem = PLGetNumberOfElements(value);
2190 if (nelem > 0) {
2191 elem = PLGetArrayElement(value, 0);
2192 if (!elem || !PLIsString(elem)) {
2193 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2194 if (changed==0) {
2195 value = entry->plvalue;
2196 changed = 1;
2197 wwarning(_("using default \"%s\" instead"), entry->default_value);
2198 goto again;
2200 return False;
2202 val = PLGetString(elem);
2204 if (strcasecmp(val, "None")==0)
2205 return True;
2207 *ret = PLRetain(value);
2209 return True;
2213 static int
2214 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2215 void *addr, void **ret)
2217 proplist_t elem;
2218 int nelem;
2219 int changed = 0;
2221 again:
2222 if (!PLIsArray(value)) {
2223 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2224 "WorkspaceSpecificBack", "an array of textures");
2225 if (changed==0) {
2226 value = entry->plvalue;
2227 changed = 1;
2228 wwarning(_("using default \"%s\" instead"), entry->default_value);
2229 goto again;
2231 return False;
2234 /* only do basic error checking and verify for None texture */
2236 nelem = PLGetNumberOfElements(value);
2237 if (nelem > 0) {
2238 while (nelem--) {
2239 elem = PLGetArrayElement(value, nelem);
2240 if (!elem || !PLIsArray(elem)) {
2241 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2242 nelem);
2247 *ret = PLRetain(value);
2249 #ifdef notworking
2251 * Kluge to force wmsetbg helper to set the default background.
2252 * If the WorkspaceSpecificBack is changed once wmaker has started,
2253 * the WorkspaceBack won't be sent to the helper, unless the user
2254 * changes it's value too. So, we must force this by removing the
2255 * value from the defaults DB.
2257 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2258 proplist_t key = PLMakeString("WorkspaceBack");
2260 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2262 PLRelease(key);
2264 #endif
2265 return True;
2269 static int
2270 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2271 void **ret)
2273 static WMFont *font;
2274 char *val;
2276 GET_STRING_OR_DEFAULT("Font", val);
2278 font = WMCreateFont(scr->wmscreen, val);
2279 if (!font)
2280 font = WMCreateFont(scr->wmscreen, "fixed");
2282 if (!font) {
2283 wfatal(_("could not load any usable font!!!"));
2284 exit(1);
2287 if (ret)
2288 *ret = font;
2290 /* can't assign font value outside update function */
2291 wassertrv(addr == NULL, True);
2293 return True;
2297 static int
2298 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2299 void **ret)
2301 static XColor color;
2302 char *val;
2303 int second_pass=0;
2305 GET_STRING_OR_DEFAULT("Color", val);
2308 again:
2309 if (!wGetColor(scr, val, &color)) {
2310 wwarning(_("could not get color for key \"%s\""),
2311 entry->key);
2312 if (second_pass==0) {
2313 val = PLGetString(entry->plvalue);
2314 second_pass = 1;
2315 wwarning(_("using default \"%s\" instead"), val);
2316 goto again;
2318 return False;
2321 if (ret)
2322 *ret = &color;
2324 assert(addr==NULL);
2326 if (addr)
2327 *(unsigned long*)addr = pixel;
2330 return True;
2335 static int
2336 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2337 void **ret)
2339 static WShortKey shortcut;
2340 KeySym ksym;
2341 char *val;
2342 char *k;
2343 char buf[128], *b;
2346 GET_STRING_OR_DEFAULT("Key spec", val);
2348 if (!val || strcasecmp(val, "NONE")==0) {
2349 shortcut.keycode = 0;
2350 shortcut.modifier = 0;
2351 if (ret)
2352 *ret = &shortcut;
2353 return True;
2356 strcpy(buf, val);
2358 b = (char*)buf;
2360 /* get modifiers */
2361 shortcut.modifier = 0;
2362 while ((k = strchr(b, '+'))!=NULL) {
2363 int mod;
2365 *k = 0;
2366 mod = wXModifierFromKey(b);
2367 if (mod<0) {
2368 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2369 return False;
2371 shortcut.modifier |= mod;
2373 b = k+1;
2376 /* get key */
2377 ksym = XStringToKeysym(b);
2379 if (ksym==NoSymbol) {
2380 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2381 val);
2382 return False;
2385 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2386 if (shortcut.keycode==0) {
2387 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2388 return False;
2391 if (ret)
2392 *ret = &shortcut;
2394 return True;
2398 static int
2399 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2400 void **ret)
2402 static unsigned int mask;
2403 char *str;
2405 GET_STRING_OR_DEFAULT("Modifier Key", str);
2407 if (!str)
2408 return False;
2410 mask = wXModifierFromKey(str);
2411 if (mask < 0) {
2412 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2413 mask = 0;
2414 return False;
2417 if (addr)
2418 *(unsigned int*)addr = mask;
2420 if (ret)
2421 *ret = &mask;
2423 return True;
2427 #ifdef NEWSTUFF
2428 static int
2429 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2430 void *addr, void **ret)
2432 unsigned int mask;
2433 char *str;
2434 RImage *image;
2435 int i, n;
2436 int w, h;
2438 GET_STRING_OR_DEFAULT("Image File Path", str);
2439 if (!str)
2440 return False;
2442 image = RLoadImage(scr->rcontext, str, 0);
2443 if (!image) {
2444 wwarning(_("could not load image in option %s: %s"), entry->key,
2445 RMessageForError(RErrorCode));
2446 return False;
2449 if (*(RImage**)addr) {
2450 RReleaseImage(*(RImage**)addr);
2452 if (addr)
2453 *(RImage**)addr = image;
2455 assert(ret == NULL);
2457 if (ret)
2458 *(RImage**)ret = image;
2461 return True;
2463 #endif
2465 #ifdef DEFINABLE_CURSOR
2467 # include <X11/cursorfont.h>
2468 typedef struct
2470 char *name;
2471 int id;
2472 } WCursorLookup;
2474 #define CURSOR_ID_NONE (XC_num_glyphs)
2476 static WCursorLookup cursor_table[] =
2478 { "X_cursor", XC_X_cursor },
2479 { "arrow", XC_arrow },
2480 { "based_arrow_down", XC_based_arrow_down },
2481 { "based_arrow_up", XC_based_arrow_up },
2482 { "boat", XC_boat },
2483 { "bogosity", XC_bogosity },
2484 { "bottom_left_corner", XC_bottom_left_corner },
2485 { "bottom_right_corner", XC_bottom_right_corner },
2486 { "bottom_side", XC_bottom_side },
2487 { "bottom_tee", XC_bottom_tee },
2488 { "box_spiral", XC_box_spiral },
2489 { "center_ptr", XC_center_ptr },
2490 { "circle", XC_circle },
2491 { "clock", XC_clock },
2492 { "coffee_mug", XC_coffee_mug },
2493 { "cross", XC_cross },
2494 { "cross_reverse", XC_cross_reverse },
2495 { "crosshair", XC_crosshair },
2496 { "diamond_cross", XC_diamond_cross },
2497 { "dot", XC_dot },
2498 { "dotbox", XC_dotbox },
2499 { "double_arrow", XC_double_arrow },
2500 { "draft_large", XC_draft_large },
2501 { "draft_small", XC_draft_small },
2502 { "draped_box", XC_draped_box },
2503 { "exchange", XC_exchange },
2504 { "fleur", XC_fleur },
2505 { "gobbler", XC_gobbler },
2506 { "gumby", XC_gumby },
2507 { "hand1", XC_hand1 },
2508 { "hand2", XC_hand2 },
2509 { "heart", XC_heart },
2510 { "icon", XC_icon },
2511 { "iron_cross", XC_iron_cross },
2512 { "left_ptr", XC_left_ptr },
2513 { "left_side", XC_left_side },
2514 { "left_tee", XC_left_tee },
2515 { "leftbutton", XC_leftbutton },
2516 { "ll_angle", XC_ll_angle },
2517 { "lr_angle", XC_lr_angle },
2518 { "man", XC_man },
2519 { "middlebutton", XC_middlebutton },
2520 { "mouse", XC_mouse },
2521 { "pencil", XC_pencil },
2522 { "pirate", XC_pirate },
2523 { "plus", XC_plus },
2524 { "question_arrow", XC_question_arrow },
2525 { "right_ptr", XC_right_ptr },
2526 { "right_side", XC_right_side },
2527 { "right_tee", XC_right_tee },
2528 { "rightbutton", XC_rightbutton },
2529 { "rtl_logo", XC_rtl_logo },
2530 { "sailboat", XC_sailboat },
2531 { "sb_down_arrow", XC_sb_down_arrow },
2532 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2533 { "sb_left_arrow", XC_sb_left_arrow },
2534 { "sb_right_arrow", XC_sb_right_arrow },
2535 { "sb_up_arrow", XC_sb_up_arrow },
2536 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2537 { "shuttle", XC_shuttle },
2538 { "sizing", XC_sizing },
2539 { "spider", XC_spider },
2540 { "spraycan", XC_spraycan },
2541 { "star", XC_star },
2542 { "target", XC_target },
2543 { "tcross", XC_tcross },
2544 { "top_left_arrow", XC_top_left_arrow },
2545 { "top_left_corner", XC_top_left_corner },
2546 { "top_right_corner", XC_top_right_corner },
2547 { "top_side", XC_top_side },
2548 { "top_tee", XC_top_tee },
2549 { "trek", XC_trek },
2550 { "ul_angle", XC_ul_angle },
2551 { "umbrella", XC_umbrella },
2552 { "ur_angle", XC_ur_angle },
2553 { "watch", XC_watch },
2554 { "xterm", XC_xterm },
2555 { NULL, CURSOR_ID_NONE }
2558 static void
2559 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2561 switch(status) {
2562 case BitmapOpenFailed:
2563 wwarning(_("failed to open bitmap file \"%s\""), filename);
2564 break;
2565 case BitmapFileInvalid:
2566 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2567 break;
2568 case BitmapNoMemory:
2569 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2570 break;
2571 case BitmapSuccess:
2572 XFreePixmap(dpy, bitmap);
2573 break;
2578 * (none)
2579 * (builtin, <cursor_name>)
2580 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2582 static int
2583 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2585 proplist_t elem;
2586 char *val;
2587 int nelem;
2588 int status = 0;
2590 nelem = PLGetNumberOfElements(pl);
2591 if (nelem < 1) {
2592 return(status);
2594 elem = PLGetArrayElement(pl, 0);
2595 if (!elem || !PLIsString(elem)) {
2596 return(status);
2598 val = PLGetString(elem);
2600 if (0 == strcasecmp(val, "none")) {
2601 status = 1;
2602 *cursor = None;
2603 } else if (0 == strcasecmp(val, "builtin")) {
2604 int i;
2605 int cursor_id = CURSOR_ID_NONE;
2607 if (2 != nelem) {
2608 wwarning(_("bad number of arguments in cursor specification"));
2609 return(status);
2611 elem = PLGetArrayElement(pl, 1);
2612 if (!elem || !PLIsString(elem)) {
2613 return(status);
2615 val = PLGetString(elem);
2617 for (i = 0; NULL != cursor_table[i].name; i++) {
2618 if (0 == strcasecmp(val, cursor_table[i].name)) {
2619 cursor_id = cursor_table[i].id;
2620 break;
2623 if (CURSOR_ID_NONE == cursor_id) {
2624 wwarning(_("unknown builtin cursor name \"%s\""), val);
2625 } else {
2626 *cursor = XCreateFontCursor(dpy, cursor_id);
2627 status = 1;
2629 } else if (0 == strcasecmp(val, "bitmap")) {
2630 char *bitmap_name;
2631 char *mask_name;
2632 int bitmap_status;
2633 int mask_status;
2634 Pixmap bitmap;
2635 Pixmap mask;
2636 unsigned int w, h;
2637 int x, y;
2638 XColor fg, bg;
2640 if (3 != nelem) {
2641 wwarning(_("bad number of arguments in cursor specification"));
2642 return(status);
2644 elem = PLGetArrayElement(pl, 1);
2645 if (!elem || !PLIsString(elem)) {
2646 return(status);
2648 val = PLGetString(elem);
2649 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2650 if (!bitmap_name) {
2651 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2652 return(status);
2654 elem = PLGetArrayElement(pl, 2);
2655 if (!elem || !PLIsString(elem)) {
2656 wfree(bitmap_name);
2657 return(status);
2659 val = PLGetString(elem);
2660 mask_name = FindImage(wPreferences.pixmap_path, val);
2661 if (!mask_name) {
2662 wfree(bitmap_name);
2663 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2664 return(status);
2666 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2667 &mask, &x, &y);
2668 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2669 &bitmap, &x, &y);
2670 if ((BitmapSuccess == bitmap_status) &&
2671 (BitmapSuccess == mask_status)) {
2672 fg.pixel = scr->black_pixel;
2673 bg.pixel = scr->white_pixel;
2674 XQueryColor(dpy, scr->w_colormap, &fg);
2675 XQueryColor(dpy, scr->w_colormap, &bg);
2676 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2677 status = 1;
2679 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2680 check_bitmap_status(mask_status, mask_name, mask);
2681 wfree(bitmap_name);
2682 wfree(mask_name);
2684 return(status);
2688 static int
2689 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2690 void **ret)
2692 static Cursor cursor;
2693 int status;
2694 int changed = 0;
2696 again:
2697 if (!PLIsArray(value)) {
2698 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2699 entry->key, "cursor specification");
2700 if (!changed) {
2701 value = entry->plvalue;
2702 changed = 1;
2703 wwarning(_("using default \"%s\" instead"), entry->default_value);
2704 goto again;
2706 return(False);
2708 status = parse_cursor(scr, value, &cursor);
2709 if (!status) {
2710 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2711 if (!changed) {
2712 value = entry->plvalue;
2713 changed = 1;
2714 wwarning(_("using default \"%s\" instead"), entry->default_value);
2715 goto again;
2717 return(False);
2719 if (ret) {
2720 *ret = &cursor;
2722 if (addr) {
2723 *(Cursor *)addr = cursor;
2725 return(True);
2727 #undef CURSOR_ID_NONE
2729 #endif /* DEFINABLE_CURSOR */
2732 /* ---------------- value setting functions --------------- */
2733 static int
2734 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2736 return REFRESH_WINDOW_TITLE_COLOR;
2739 static int
2740 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2742 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2745 static int
2746 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2748 switch (which) {
2749 case WM_DOCK:
2750 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2751 break;
2752 case WM_CLIP:
2753 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2754 break;
2755 default:
2756 break;
2758 return 0;
2762 static int
2763 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2765 if (scr->workspaces) {
2766 wWorkspaceForceChange(scr, scr->current_workspace);
2767 wArrangeIcons(scr, False);
2769 return 0;
2772 #if not_used
2773 static int
2774 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2776 if (*value <= 0)
2777 *(int*)foo = 1;
2779 return 0;
2781 #endif
2785 static int
2786 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2788 Pixmap pixmap;
2789 RImage *img;
2790 int reset = 0;
2792 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2793 wPreferences.icon_size,
2794 ((*texture)->any.type & WREL_BORDER_MASK)
2795 ? WREL_ICON : WREL_FLAT);
2796 if (!img) {
2797 wwarning(_("could not render texture for icon background"));
2798 if (!entry->addr)
2799 wTextureDestroy(scr, *texture);
2800 return 0;
2802 RConvertImage(scr->rcontext, img, &pixmap);
2804 if (scr->icon_tile) {
2805 reset = 1;
2806 RReleaseImage(scr->icon_tile);
2807 XFreePixmap(dpy, scr->icon_tile_pixmap);
2810 scr->icon_tile = img;
2813 /* put the icon in the noticeboard hint */
2814 PropSetIconTileHint(scr, img);
2817 if (!wPreferences.flags.noclip) {
2818 if (scr->clip_tile) {
2819 RReleaseImage(scr->clip_tile);
2821 scr->clip_tile = wClipMakeTile(scr, img);
2824 scr->icon_tile_pixmap = pixmap;
2826 if (scr->def_icon_pixmap) {
2827 XFreePixmap(dpy, scr->def_icon_pixmap);
2828 scr->def_icon_pixmap = None;
2830 if (scr->def_ticon_pixmap) {
2831 XFreePixmap(dpy, scr->def_ticon_pixmap);
2832 scr->def_ticon_pixmap = None;
2835 if (scr->icon_back_texture) {
2836 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2838 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2840 if (scr->clip_balloon)
2841 XSetWindowBackground(dpy, scr->clip_balloon,
2842 (*texture)->any.color.pixel);
2845 * Free the texture as nobody else will use it, nor refer to it.
2847 if (!entry->addr)
2848 wTextureDestroy(scr, *texture);
2850 return (reset ? REFRESH_ICON_TILE : 0);
2855 static int
2856 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2858 if (scr->title_font) {
2859 WMReleaseFont(scr->title_font);
2861 scr->title_font = font;
2863 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2867 static int
2868 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2870 if (scr->menu_title_font) {
2871 WMReleaseFont(scr->menu_title_font);
2874 scr->menu_title_font = font;
2876 return REFRESH_MENU_TITLE_FONT;
2880 static int
2881 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2883 if (scr->menu_entry_font) {
2884 WMReleaseFont(scr->menu_entry_font);
2886 scr->menu_entry_font = font;
2888 return REFRESH_MENU_FONT;
2893 static int
2894 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2896 if (scr->icon_title_font) {
2897 WMReleaseFont(scr->icon_title_font);
2900 scr->icon_title_font = font;
2902 return REFRESH_ICON_FONT;
2906 static int
2907 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2909 if (scr->clip_title_font) {
2910 WMReleaseFont(scr->clip_title_font);
2913 scr->clip_title_font = font;
2915 return REFRESH_ICON_FONT;
2919 static int
2920 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2922 if (scr->workspace_name_font) {
2923 WMReleaseFont(scr->workspace_name_font);
2926 scr->workspace_name_font = font;
2928 return 0;
2932 static int
2933 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2935 if (scr->select_pixel!=scr->white_pixel &&
2936 scr->select_pixel!=scr->black_pixel) {
2937 wFreeColor(scr, scr->select_pixel);
2940 scr->select_pixel = color->pixel;
2942 return REFRESH_MENU_COLOR;
2946 static int
2947 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2949 if (scr->select_text_pixel!=scr->white_pixel &&
2950 scr->select_text_pixel!=scr->black_pixel) {
2951 wFreeColor(scr, scr->select_text_pixel);
2954 scr->select_text_pixel = color->pixel;
2956 return REFRESH_MENU_COLOR;
2960 static int
2961 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2963 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2964 scr->clip_title_pixel[index]!=scr->black_pixel) {
2965 wFreeColor(scr, scr->clip_title_pixel[index]);
2967 scr->clip_title_pixel[index] = color->pixel;
2969 #ifdef GRADIENT_CLIP_ARROW
2970 if (index == CLIP_NORMAL) {
2971 RImage *image;
2972 RColor color1, color2;
2973 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2974 int as = pt - 15; /* 15 = 5+5+5 */
2976 FREE_PIXMAP(scr->clip_arrow_gradient);
2978 color1.red = (color->red >> 8)*6/10;
2979 color1.green = (color->green >> 8)*6/10;
2980 color1.blue = (color->blue >> 8)*6/10;
2982 color2.red = WMIN((color->red >> 8)*20/10, 255);
2983 color2.green = WMIN((color->green >> 8)*20/10, 255);
2984 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2986 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2987 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2988 RReleaseImage(image);
2990 #endif /* GRADIENT_CLIP_ARROW */
2992 return REFRESH_ICON_TITLE_COLOR;
2996 static int
2997 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2999 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3000 scr->window_title_pixel[index]!=scr->black_pixel) {
3001 wFreeColor(scr, scr->window_title_pixel[index]);
3004 scr->window_title_pixel[index] = color->pixel;
3006 if (index == WS_UNFOCUSED)
3007 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3009 return REFRESH_WINDOW_TITLE_COLOR;
3013 static int
3014 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3016 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3017 scr->menu_title_pixel[0]!=scr->black_pixel) {
3018 wFreeColor(scr, scr->menu_title_pixel[0]);
3021 scr->menu_title_pixel[0] = color->pixel;
3022 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3024 return REFRESH_MENU_TITLE_COLOR;
3028 static int
3029 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3031 XGCValues gcv;
3032 #define gcm (GCForeground|GCBackground|GCFillStyle)
3034 if (scr->mtext_pixel!=scr->white_pixel &&
3035 scr->mtext_pixel!=scr->black_pixel) {
3036 wFreeColor(scr, scr->mtext_pixel);
3039 scr->mtext_pixel = color->pixel;
3041 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3044 if (scr->dtext_pixel == scr->mtext_pixel) {
3045 gcv.foreground = scr->white_pixel;
3046 gcv.background = scr->black_pixel;
3047 gcv.fill_style = FillStippled;
3048 } else {
3049 gcv.foreground = scr->dtext_pixel;
3050 gcv.fill_style = FillSolid;
3052 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3054 return REFRESH_MENU_COLOR;
3055 #undef gcm
3059 static int
3060 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3062 XGCValues gcv;
3063 #define gcm (GCForeground|GCBackground|GCFillStyle)
3065 if (scr->dtext_pixel!=scr->white_pixel &&
3066 scr->dtext_pixel!=scr->black_pixel) {
3067 wFreeColor(scr, scr->dtext_pixel);
3070 scr->dtext_pixel = color->pixel;
3072 if (scr->dtext_pixel == scr->mtext_pixel) {
3073 gcv.foreground = scr->white_pixel;
3074 gcv.background = scr->black_pixel;
3075 gcv.fill_style = FillStippled;
3076 } else {
3077 gcv.foreground = scr->dtext_pixel;
3078 gcv.fill_style = FillSolid;
3080 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3082 return REFRESH_MENU_COLOR;
3083 #undef gcm
3086 static int
3087 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3089 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3091 return REFRESH_ICON_TITLE_COLOR;
3095 static int
3096 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3098 if (scr->icon_title_texture) {
3099 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3101 XQueryColor (dpy, scr->w_colormap, color);
3102 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3104 return REFRESH_ICON_TITLE_BACK;
3108 static void
3109 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3111 close(scr->helper_fd);
3112 scr->helper_fd = 0;
3113 scr->helper_pid = 0;
3114 scr->flags.backimage_helper_launched = 0;
3118 static int
3119 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3120 void *bar)
3122 int i;
3123 proplist_t val;
3124 char *str;
3126 if (scr->flags.backimage_helper_launched) {
3127 if (PLGetNumberOfElements(value)==0) {
3128 SendHelperMessage(scr, 'C', 0, NULL);
3129 SendHelperMessage(scr, 'K', 0, NULL);
3131 PLRelease(value);
3132 return 0;
3134 } else {
3135 pid_t pid;
3136 int filedes[2];
3138 if (PLGetNumberOfElements(value) == 0)
3139 return 0;
3141 if (pipe(filedes) < 0) {
3142 wsyserror("pipe() failed:can't set workspace specific background image");
3144 PLRelease(value);
3145 return 0;
3148 pid = fork();
3149 if (pid < 0) {
3150 wsyserror("fork() failed:can't set workspace specific background image");
3151 if (close(filedes[0]) < 0)
3152 wsyserror("could not close pipe");
3153 if (close(filedes[1]) < 0)
3154 wsyserror("could not close pipe");
3156 } else if (pid == 0) {
3157 char *dither;
3159 SetupEnvironment(scr);
3161 if (close(0) < 0)
3162 wsyserror("could not close pipe");
3163 if (dup(filedes[0]) < 0) {
3164 wsyserror("dup() failed:can't set workspace specific background image");
3166 dither = wPreferences.no_dithering ? "-m" : "-d";
3167 if (wPreferences.smooth_workspace_back)
3168 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3169 else
3170 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3171 wsyserror("could not execute wmsetbg");
3172 exit(1);
3173 } else {
3175 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3176 wsyserror("error setting close-on-exec flag");
3178 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3179 wsyserror("error setting close-on-exec flag");
3182 scr->helper_fd = filedes[1];
3183 scr->helper_pid = pid;
3184 scr->flags.backimage_helper_launched = 1;
3186 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3188 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3193 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3194 val = PLGetArrayElement(value, i);
3195 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3196 str = PLGetDescription(val);
3198 SendHelperMessage(scr, 'S', i+1, str);
3200 wfree(str);
3201 } else {
3202 SendHelperMessage(scr, 'U', i+1, NULL);
3205 sleep(1);
3207 PLRelease(value);
3208 return 0;
3212 static int
3213 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3214 void *bar)
3216 if (scr->flags.backimage_helper_launched) {
3217 char *str;
3219 if (PLGetNumberOfElements(value)==0) {
3220 SendHelperMessage(scr, 'U', 0, NULL);
3221 } else {
3222 /* set the default workspace background to this one */
3223 str = PLGetDescription(value);
3224 if (str) {
3225 SendHelperMessage(scr, 'S', 0, str);
3226 wfree(str);
3227 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3228 } else {
3229 SendHelperMessage(scr, 'U', 0, NULL);
3232 } else if (PLGetNumberOfElements(value) > 0) {
3233 char *command;
3234 char *text;
3235 char *dither;
3237 SetupEnvironment(scr);
3238 text = PLGetDescription(value);
3239 command = wmalloc(strlen(text)+40);
3240 dither = wPreferences.no_dithering ? "-m" : "-d";
3241 if (wPreferences.smooth_workspace_back)
3242 sprintf(command, "wmsetbg %s -S -p '%s' &", dither, text);
3243 else
3244 sprintf(command, "wmsetbg %s -p '%s' &", dither, text);
3245 wfree(text);
3246 system(command);
3247 wfree(command);
3249 PLRelease(value);
3251 return 0;
3255 static int
3256 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3258 if (scr->widget_texture) {
3259 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3261 scr->widget_texture = *(WTexSolid**)texture;
3263 return 0;
3267 static int
3268 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3270 if (scr->window_title_texture[WS_FOCUSED]) {
3271 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3273 scr->window_title_texture[WS_FOCUSED] = *texture;
3275 return REFRESH_WINDOW_TEXTURES;
3279 static int
3280 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3282 if (scr->window_title_texture[WS_PFOCUSED]) {
3283 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3285 scr->window_title_texture[WS_PFOCUSED] = *texture;
3287 return REFRESH_WINDOW_TEXTURES;
3291 static int
3292 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3294 if (scr->window_title_texture[WS_UNFOCUSED]) {
3295 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3297 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3299 return REFRESH_WINDOW_TEXTURES;
3303 static int
3304 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3306 if (scr->resizebar_texture[0]) {
3307 wTextureDestroy(scr, scr->resizebar_texture[0]);
3309 scr->resizebar_texture[0] = *texture;
3311 return REFRESH_WINDOW_TEXTURES;
3315 static int
3316 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3318 if (scr->menu_title_texture[0]) {
3319 wTextureDestroy(scr, scr->menu_title_texture[0]);
3321 scr->menu_title_texture[0] = *texture;
3323 return REFRESH_MENU_TITLE_TEXTURE;
3327 static int
3328 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3330 if (scr->menu_item_texture) {
3331 wTextureDestroy(scr, scr->menu_item_texture);
3332 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3334 scr->menu_item_texture = *texture;
3336 scr->menu_item_auxtexture
3337 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3339 return REFRESH_MENU_TEXTURE;
3343 static int
3344 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3346 WWindow *wwin;
3347 wKeyBindings[index] = *shortcut;
3349 wwin = scr->focused_window;
3351 while (wwin!=NULL) {
3352 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3354 if (!WFLAGP(wwin, no_bind_keys)) {
3355 wWindowSetKeyGrabs(wwin);
3357 wwin = wwin->prev;
3360 return 0;
3364 static int
3365 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3367 wArrangeIcons(scr, True);
3369 return 0;
3373 static int
3374 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3376 wScreenUpdateUsableArea(scr);
3378 return 0;
3382 static int
3383 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3385 return REFRESH_MENU_TEXTURE;
3390 static int
3391 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3393 return REFRESH_BUTTON_IMAGES;
3398 * Very ugly kluge.
3399 * Need access to the double click variables, so that all widgets in
3400 * wmaker panels will have the same dbl-click values.
3401 * TODO: figure a better way of dealing with it.
3403 #include <WINGs/WINGsP.h>
3405 static int
3406 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3408 extern _WINGsConfiguration WINGsConfiguration;
3410 if (*value <= 0)
3411 *(int*)foo = 1;
3413 WINGsConfiguration.doubleClickDelay = *value;
3415 return 0;
3419 #if 0
3420 static int
3421 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3423 extern _WINGsConfiguration WINGsConfiguration;
3425 WINGsConfiguration.useMultiByte = *value;
3427 return 0;
3429 #endif
3431 #ifdef DEFINABLE_CURSOR
3432 static int
3433 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3435 if (None != wCursor[index])
3437 XFreeCursor(dpy, wCursor[index]);
3440 wCursor[index] = *cursor;
3442 if ((WCUR_ROOT == index) && (None != *cursor))
3444 XDefineCursor(dpy, scr->root_win, *cursor);
3447 return 0;
3449 #endif /* DEFINABLE_CURSOR*/