- s/sprintf/snprintf
[wmaker-crm.git] / src / defaults.c
blobe7b19963ba893dc5e9710b17917cfb5fafafe083
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 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
229 {NULL, 0, 0}
232 static WOptionEnumeration seColormapModes[] = {
233 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
234 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
235 {NULL, 0, 0}
238 static WOptionEnumeration sePlacements[] = {
239 {"Auto", WPM_AUTO, 0},
240 {"Smart", WPM_SMART, 0},
241 {"Cascade", WPM_CASCADE, 0},
242 {"Random", WPM_RANDOM, 0},
243 {"Manual", WPM_MANUAL, 0},
244 {NULL, 0, 0}
247 static WOptionEnumeration seGeomDisplays[] = {
248 {"None", WDIS_NONE, 0},
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 seMouseButtonActions[] = {
266 {"None", WA_NONE, 0},
267 {"SelectWindows", WA_SELECT_WINDOWS, 0},
268 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
269 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
270 {NULL, 0, 0}
273 static WOptionEnumeration seMouseWheelActions[] = {
274 {"None", WA_NONE, 0},
275 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
276 {NULL, 0, 0}
279 static WOptionEnumeration seIconificationStyles[] = {
280 {"Zoom", WIS_ZOOM, 0},
281 {"Twist", WIS_TWIST, 0},
282 {"Flip", WIS_FLIP, 0},
283 {"None", WIS_NONE, 0},
284 {"random", WIS_RANDOM, 0},
285 {NULL, 0, 0}
288 static WOptionEnumeration seJustifications[] = {
289 {"Left", WTJ_LEFT, 0},
290 {"Center", WTJ_CENTER, 0},
291 {"Right", WTJ_RIGHT, 0},
292 {NULL, 0, 0}
295 static WOptionEnumeration seIconPositions[] = {
296 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
297 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
298 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
299 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
300 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
301 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
302 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
303 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
304 {NULL, 0, 0}
307 static WOptionEnumeration seMenuStyles[] = {
308 {"normal", MS_NORMAL, 0},
309 {"singletexture", MS_SINGLE_TEXTURE, 0},
310 {"flat", MS_FLAT, 0},
311 {NULL, 0, 0}
315 static WOptionEnumeration seDisplayPositions[] = {
316 {"none", WD_NONE, 0},
317 {"center", WD_CENTER, 0},
318 {"top", WD_TOP, 0},
319 {"bottom", WD_BOTTOM, 0},
320 {"topleft", WD_TOPLEFT, 0},
321 {"topright", WD_TOPRIGHT, 0},
322 {"bottomleft", WD_BOTTOMLEFT, 0},
323 {"bottomright", WD_BOTTOMRIGHT, 0},
324 {NULL, 0, 0}
327 static WOptionEnumeration seWorkspaceBorder[] = {
328 {"None", WB_NONE, 0},
329 {"LeftRight", WB_LEFTRIGHT, 0},
330 {"TopBottom", WB_TOPBOTTOM, 0},
331 {"AllDirections", WB_ALLDIRS, 0},
332 {NULL, 0, 0}
337 * ALL entries in the tables bellow, NEED to have a default value
338 * defined, and this value needs to be correct.
341 /* these options will only affect the window manager on startup
343 * static defaults can't access the screen data, because it is
344 * created after these defaults are read
346 WDefaultEntry staticOptionList[] = {
348 {"ColormapSize", "4", NULL,
349 &wPreferences.cmap_size, getInt, NULL
351 {"DisableDithering", "NO", NULL,
352 &wPreferences.no_dithering, getBool, NULL
354 /* static by laziness */
355 {"IconSize", "64", NULL,
356 &wPreferences.icon_size, getInt, NULL
358 {"ModifierKey", "Mod1", NULL,
359 &wPreferences.modifier_mask, getModMask, NULL
361 {"DisableWSMouseActions", "NO", NULL,
362 &wPreferences.disable_root_mouse, getBool, NULL
364 {"FocusMode", "manual", seFocusModes,
365 &wPreferences.focus_mode, getEnum, NULL
366 }, /* have a problem when switching from manual to sloppy without restart */
367 {"NewStyle", "NO", NULL,
368 &wPreferences.new_style, getBool, NULL
370 {"DisableDock", "NO", (void*) WM_DOCK,
371 NULL, getBool, setIfDockPresent
373 {"DisableClip", "NO", (void*) WM_CLIP,
374 NULL, getBool, setIfDockPresent
376 {"DisableMiniwindows", "NO", NULL,
377 &wPreferences.disable_miniwindows, getBool, NULL
379 #if 0
380 ,{"MultiByteText", "NO", NULL,
381 &wPreferences.multi_byte_text, getBool, setMultiByte
383 #endif
388 WDefaultEntry optionList[] = {
389 /* dynamic options */
390 {"IconPosition", "blh", seIconPositions,
391 &wPreferences.icon_yard, getEnum, setIconPosition
393 {"IconificationStyle", "Zoom", seIconificationStyles,
394 &wPreferences.iconification_style, getEnum, NULL
396 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
397 &wPreferences.mouse_button1, getEnum, NULL
399 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
400 &wPreferences.mouse_button2, getEnum, NULL
402 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
403 &wPreferences.mouse_button3, getEnum, NULL
405 {"MouseWheelAction", "None", seMouseWheelActions,
406 &wPreferences.mouse_wheel, getEnum, NULL
408 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
409 &wPreferences.pixmap_path, getPathList, NULL
411 {"IconPath", DEF_ICON_PATHS, NULL,
412 &wPreferences.icon_path, getPathList, NULL
414 {"ColormapMode", "auto", seColormapModes,
415 &wPreferences.colormap_mode, getEnum, NULL
417 {"AutoFocus", "NO", NULL,
418 &wPreferences.auto_focus, getBool, NULL
420 {"RaiseDelay", "0", NULL,
421 &wPreferences.raise_delay, getInt, NULL
423 {"WindozeCycling", "NO", NULL,
424 &wPreferences.windows_cycling,getBool, NULL
426 {"CirculateRaise", "NO", NULL,
427 &wPreferences.circ_raise, getBool, NULL
429 {"Superfluous", "NO", NULL,
430 &wPreferences.superfluous, getBool, NULL
432 {"AdvanceToNewWorkspace", "NO", NULL,
433 &wPreferences.ws_advance, getBool, NULL
435 {"CycleWorkspaces", "NO", NULL,
436 &wPreferences.ws_cycle, getBool, NULL
438 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
439 &wPreferences.workspace_name_display_position, getEnum, NULL
441 {"WorkspaceBorder", "None", seWorkspaceBorder,
442 &wPreferences.workspace_border_position, getEnum, updateUsableArea
444 {"WorkspaceBorderSize", "0", NULL,
445 &wPreferences.workspace_border_size, getInt, updateUsableArea
447 #ifdef VIRTUAL_DESKTOP
448 {"VirtualEdgeThickness", "1", NULL,
449 &wPreferences.vedge_thickness, getInt, NULL
451 {"VirtualEdgeExtendSpace", "0", NULL,
452 &wPreferences.vedge_bordersize, getInt, NULL
454 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
455 &wPreferences.vedge_hscrollspeed, getInt, NULL
457 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
458 &wPreferences.vedge_vscrollspeed, getInt, NULL
460 {"VirtualEdgeMaximumWidth", "3000", NULL,
461 &wPreferences.vedge_maxwidth, getInt, NULL
463 {"VirtualEdgeMaximumHeight", "3000", NULL,
464 &wPreferences.vedge_maxheight, getInt, NULL
466 #endif
467 {"StickyIcons", "NO", NULL,
468 &wPreferences.sticky_icons, getBool, setStickyIcons
470 {"SaveSessionOnExit", "NO", NULL,
471 &wPreferences.save_session_on_exit, getBool, NULL
473 {"WrapMenus", "NO", NULL,
474 &wPreferences.wrap_menus, getBool, NULL
476 {"ScrollableMenus", "NO", NULL,
477 &wPreferences.scrollable_menus, getBool, NULL
479 {"MenuScrollSpeed", "medium", seSpeeds,
480 &wPreferences.menu_scroll_speed, getEnum, NULL
482 {"IconSlideSpeed", "medium", seSpeeds,
483 &wPreferences.icon_slide_speed, getEnum, NULL
485 {"ShadeSpeed", "medium", seSpeeds,
486 &wPreferences.shade_speed, getEnum, NULL
488 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
489 &wPreferences.dblclick_time, getInt, setDoubleClick,
491 {"AlignSubmenus", "NO", NULL,
492 &wPreferences.align_menus, getBool, NULL
494 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
495 &wPreferences.open_transients_with_parent, getBool, NULL
497 {"WindowPlacement", "auto", sePlacements,
498 &wPreferences.window_placement, getEnum, NULL
500 {"IgnoreFocusClick","NO", NULL,
501 &wPreferences.ignore_focus_click, getBool, NULL
503 {"UseSaveUnders", "NO", NULL,
504 &wPreferences.use_saveunders, getBool, NULL
506 {"OpaqueMove", "NO", NULL,
507 &wPreferences.opaque_move, getBool, NULL
509 {"DisableSound", "NO", NULL,
510 &wPreferences.no_sound, getBool, NULL
512 {"DisableAnimations", "NO", NULL,
513 &wPreferences.no_animations, getBool, NULL
515 {"DontLinkWorkspaces","NO", NULL,
516 &wPreferences.no_autowrap, getBool, NULL
518 {"AutoArrangeIcons", "NO", NULL,
519 &wPreferences.auto_arrange_icons, getBool, NULL
521 {"NoWindowOverDock", "NO", NULL,
522 &wPreferences.no_window_over_dock, getBool, updateUsableArea
524 {"NoWindowOverIcons", "NO", NULL,
525 &wPreferences.no_window_over_icons, getBool, updateUsableArea
527 {"WindowPlaceOrigin", "(0, 0)", NULL,
528 &wPreferences.window_place_origin, getCoord, NULL
530 {"ResizeDisplay", "corner", seGeomDisplays,
531 &wPreferences.size_display, getEnum, NULL
533 {"MoveDisplay", "corner", seGeomDisplays,
534 &wPreferences.move_display, getEnum, NULL
536 {"DontConfirmKill", "NO", NULL,
537 &wPreferences.dont_confirm_kill, getBool,NULL
539 {"WindowTitleBalloons", "NO", NULL,
540 &wPreferences.window_balloon, getBool, NULL
542 {"MiniwindowTitleBalloons", "NO", NULL,
543 &wPreferences.miniwin_balloon,getBool, NULL
545 {"AppIconBalloons", "NO", NULL,
546 &wPreferences.appicon_balloon,getBool, NULL
548 {"HelpBalloons", "NO", NULL,
549 &wPreferences.help_balloon, getBool, NULL
551 {"EdgeResistance", "30", NULL,
552 &wPreferences.edge_resistance,getInt, NULL
554 {"Attraction", "NO", NULL,
555 &wPreferences.attract, getBool, NULL
557 {"DisableBlinking", "NO", NULL,
558 &wPreferences.dont_blink, getBool, NULL
560 /* style options */
561 {"MenuStyle", "normal", seMenuStyles,
562 &wPreferences.menu_style, getEnum, setMenuStyle
564 {"WidgetColor", "(solid, gray)", NULL,
565 NULL, getTexture, setWidgetColor,
567 {"WorkspaceSpecificBack","()", NULL,
568 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
570 /* WorkspaceBack must come after WorkspaceSpecificBack or
571 * WorkspaceBack wont know WorkspaceSpecificBack was also
572 * specified and 2 copies of wmsetbg will be launched */
573 {"WorkspaceBack", "(solid, black)", NULL,
574 NULL, getWSBackground,setWorkspaceBack
576 {"SmoothWorkspaceBack", "NO", NULL,
577 NULL, getBool, NULL
579 {"IconBack", "(solid, gray)", NULL,
580 NULL, getTexture, setIconTile
582 {"TitleJustify", "center", seJustifications,
583 &wPreferences.title_justification, getEnum, setJustify
585 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
586 NULL, getFont, setWinTitleFont,
588 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
589 &wPreferences.window_title_clearance, getInt, setClearance
591 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
592 &wPreferences.menu_title_clearance, getInt, setClearance
594 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
595 &wPreferences.menu_text_clearance, getInt, setClearance
597 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
598 NULL, getFont, setMenuTitleFont
600 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
601 NULL, getFont, setMenuTextFont
603 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
604 NULL, getFont, setIconTitleFont
606 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
607 NULL, getFont, setClipTitleFont
609 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
610 NULL, getFont, setLargeDisplayFont
612 {"HighlightColor", "white", NULL,
613 NULL, getColor, setHightlight
615 {"HighlightTextColor", "black", NULL,
616 NULL, getColor, setHightlightText
618 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
619 NULL, getColor, setClipTitleColor
621 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
622 NULL, getColor, setClipTitleColor
624 {"FTitleColor", "white", (void*)WS_FOCUSED,
625 NULL, getColor, setWTitleColor
627 {"PTitleColor", "white", (void*)WS_PFOCUSED,
628 NULL, getColor, setWTitleColor
630 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
631 NULL, getColor, setWTitleColor
633 {"FTitleBack", "(solid, black)", NULL,
634 NULL, getTexture, setFTitleBack
636 {"PTitleBack", "(solid, \"#616161\")", NULL,
637 NULL, getTexture, setPTitleBack
639 {"UTitleBack", "(solid, gray)", NULL,
640 NULL, getTexture, setUTitleBack
642 {"ResizebarBack", "(solid, gray)", NULL,
643 NULL, getTexture, setResizebarBack
645 {"MenuTitleColor", "white", NULL,
646 NULL, getColor, setMenuTitleColor
648 {"MenuTextColor", "black", NULL,
649 NULL, getColor, setMenuTextColor
651 {"MenuDisabledColor", "\"#616161\"", NULL,
652 NULL, getColor, setMenuDisabledColor
654 {"MenuTitleBack", "(solid, black)", NULL,
655 NULL, getTexture, setMenuTitleBack
657 {"MenuTextBack", "(solid, gray)", NULL,
658 NULL, getTexture, setMenuTextBack
660 {"IconTitleColor", "white", NULL,
661 NULL, getColor, setIconTitleColor
663 {"IconTitleBack", "black", NULL,
664 NULL, getColor, setIconTitleBack
666 /* keybindings */
667 #ifndef LITE
668 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
669 NULL, getKeybind, setKeyGrab
671 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
672 NULL, getKeybind, setKeyGrab
674 #endif /* LITE */
675 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
676 NULL, getKeybind, setKeyGrab
678 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
679 NULL, getKeybind, setKeyGrab
681 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
682 NULL, getKeybind, setKeyGrab
684 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
685 NULL, getKeybind, setKeyGrab
687 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
688 NULL, getKeybind, setKeyGrab
690 {"HideKey", "None", (void*)WKBD_HIDE,
691 NULL, getKeybind, setKeyGrab
693 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
694 NULL, getKeybind, setKeyGrab
696 {"CloseKey", "None", (void*)WKBD_CLOSE,
697 NULL, getKeybind, setKeyGrab
699 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
700 NULL, getKeybind, setKeyGrab
702 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
703 NULL, getKeybind, setKeyGrab
705 {"HMaximizeKey", "None", (void*)WKBD_HMAXIMIZE,
706 NULL, getKeybind, setKeyGrab
708 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
709 NULL, getKeybind, setKeyGrab
711 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
712 NULL, getKeybind, setKeyGrab
714 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
715 NULL, getKeybind, setKeyGrab
717 {"ShadeKey", "None", (void*)WKBD_SHADE,
718 NULL, getKeybind, setKeyGrab
720 {"SelectKey", "None", (void*)WKBD_SELECT,
721 NULL, getKeybind, setKeyGrab
723 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
724 NULL, getKeybind, setKeyGrab
726 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
727 NULL, getKeybind, setKeyGrab
729 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
730 NULL, getKeybind, setKeyGrab
732 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
733 NULL, getKeybind, setKeyGrab
735 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
736 NULL, getKeybind, setKeyGrab
738 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
739 NULL, getKeybind, setKeyGrab
741 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
742 NULL, getKeybind, setKeyGrab
744 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
745 NULL, getKeybind, setKeyGrab
747 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
760 NULL, getKeybind, setKeyGrab
762 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
763 NULL, getKeybind, setKeyGrab
765 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
766 NULL, getKeybind, setKeyGrab
768 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
769 NULL, getKeybind, setKeyGrab
771 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
772 NULL, getKeybind, setKeyGrab
774 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
775 NULL, getKeybind, setKeyGrab
777 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
778 NULL, getKeybind, setKeyGrab
780 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
781 NULL, getKeybind, setKeyGrab
783 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
784 NULL, getKeybind, setKeyGrab
786 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
787 NULL, getKeybind, setKeyGrab
789 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
790 NULL, getKeybind, setKeyGrab
792 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
793 NULL, getKeybind, setKeyGrab
795 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
796 NULL, getKeybind, setKeyGrab
798 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
799 NULL, getKeybind, setKeyGrab
801 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
802 NULL, getKeybind, setKeyGrab
805 #ifdef KEEP_XKB_LOCK_STATUS
806 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
807 NULL, getKeybind, setKeyGrab
809 {"KbdModeLock", "NO", NULL,
810 &wPreferences.modelock, getBool, NULL
812 #endif /* KEEP_XKB_LOCK_STATUS */
813 #ifdef DEFINABLE_CURSOR
814 ,{"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
815 NULL, getCursor, setCursor
817 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
818 NULL, getCursor, setCursor
820 #if 0
821 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
822 NULL, getCursor, setCursor
824 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
825 NULL, getCursor, setCursor
827 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
828 NULL, getCursor, setCursor
830 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
831 NULL, getCursor, setCursor
833 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
834 NULL, getCursor, setCursor
836 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
837 NULL, getCursor, setCursor
839 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
840 NULL, getCursor, setCursor
842 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
843 NULL, getCursor, setCursor
845 #endif
846 #endif /* DEFINABLE_CURSOR */
850 #if 0
851 static void rereadDefaults(void);
852 #endif
854 #if 0
855 static void
856 rereadDefaults(void)
858 /* must defer the update because accessing X data from a
859 * signal handler can mess up Xlib */
862 #endif
864 static void
865 initDefaults()
867 int i;
868 WDefaultEntry *entry;
870 PLSetStringCmpHook(StringCompareHook);
872 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
873 entry = &optionList[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;
882 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
883 entry = &staticOptionList[i];
885 entry->plkey = PLMakeString(entry->key);
886 if (entry->default_value)
887 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
888 else
889 entry->plvalue = NULL;
893 wDomainName = PLMakeString(WMDOMAIN_NAME);
894 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
896 PLRegister(wDomainName, rereadDefaults);
897 PLRegister(wAttributeDomainName, rereadDefaults);
904 #if 0
905 proplist_t
906 wDefaultsInit(int screen_number)
908 static int defaults_inited = 0;
909 proplist_t dict;
911 if (!defaults_inited) {
912 initDefaults();
915 dict = PLGetDomain(wDomainName);
916 if (!dict) {
917 wwarning(_("could not read domain \"%s\" from defaults database"),
918 PLGetString(wDomainName));
921 return dict;
923 #endif
926 void
927 wDefaultsDestroyDomain(WDDomain *domain)
929 if (domain->dictionary)
930 PLRelease(domain->dictionary);
931 wfree(domain->path);
932 wfree(domain);
936 WDDomain*
937 wDefaultsInitDomain(char *domain, Bool requireDictionary)
939 WDDomain *db;
940 struct stat stbuf;
941 static int inited = 0;
942 char path[PATH_MAX];
943 char *the_path;
944 proplist_t shared_dict=NULL;
946 if (!inited) {
947 inited = 1;
948 initDefaults();
951 db = wmalloc(sizeof(WDDomain));
952 memset(db, 0, sizeof(WDDomain));
953 db->domain_name = domain;
954 db->path = wdefaultspathfordomain(domain);
955 the_path = db->path;
957 if (the_path && stat(the_path, &stbuf)>=0) {
958 db->dictionary = ReadProplistFromFile(the_path);
959 if (db->dictionary) {
960 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
961 PLRelease(db->dictionary);
962 db->dictionary = NULL;
963 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
964 domain, the_path);
966 db->timestamp = stbuf.st_mtime;
967 } else {
968 wwarning(_("could not load domain %s from user defaults database"),
969 domain);
973 /* global system dictionary */
974 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
975 if (stat(path, &stbuf)>=0) {
976 shared_dict = ReadProplistFromFile(path);
977 if (shared_dict) {
978 if (requireDictionary && !PLIsDictionary(shared_dict)) {
979 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
980 domain, path);
981 PLRelease(shared_dict);
982 shared_dict = NULL;
983 } else {
984 if (db->dictionary && PLIsDictionary(shared_dict) &&
985 PLIsDictionary(db->dictionary)) {
986 PLMergeDictionaries(shared_dict, db->dictionary);
987 PLRelease(db->dictionary);
988 db->dictionary = shared_dict;
989 if (stbuf.st_mtime > db->timestamp)
990 db->timestamp = stbuf.st_mtime;
991 } else if (!db->dictionary) {
992 db->dictionary = shared_dict;
993 if (stbuf.st_mtime > db->timestamp)
994 db->timestamp = stbuf.st_mtime;
997 } else {
998 wwarning(_("could not load domain %s from global defaults database (%s)"),
999 domain, path);
1003 /* set to save it in user's directory, no matter from where it was read */
1004 if (db->dictionary) {
1005 proplist_t tmp = PLMakeString(db->path);
1007 PLSetFilename(db->dictionary, tmp);
1008 PLRelease(tmp);
1011 return db;
1015 void
1016 wReadStaticDefaults(proplist_t dict)
1018 proplist_t plvalue;
1019 WDefaultEntry *entry;
1020 int i;
1021 void *tdata;
1024 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1025 entry = &staticOptionList[i];
1027 if (dict)
1028 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1029 else
1030 plvalue = NULL;
1032 if (!plvalue) {
1033 /* no default in the DB. Use builtin default */
1034 plvalue = entry->plvalue;
1037 if (plvalue) {
1038 /* convert data */
1039 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1040 if (entry->update) {
1041 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1048 void
1049 wDefaultsCheckDomains(void *foo)
1051 WScreen *scr;
1052 struct stat stbuf;
1053 proplist_t dict;
1054 int i;
1055 char path[PATH_MAX];
1057 #ifdef HEARTBEAT
1058 puts("Checking domains...");
1059 #endif
1060 if (stat(WDWindowMaker->path, &stbuf)>=0
1061 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1062 proplist_t shared_dict = NULL;
1063 #ifdef HEARTBEAT
1064 puts("Checking WindowMaker domain");
1065 #endif
1066 WDWindowMaker->timestamp = stbuf.st_mtime;
1068 /* global dictionary */
1069 snprintf(path, sizeof(path), "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1070 if (stat(path, &stbuf)>=0) {
1071 shared_dict = ReadProplistFromFile(path);
1072 if (shared_dict && !PLIsDictionary(shared_dict)) {
1073 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1074 "WindowMaker", path);
1075 PLRelease(shared_dict);
1076 shared_dict = NULL;
1077 } else if (!shared_dict) {
1078 wwarning(_("could not load domain %s from global defaults database"),
1079 "WindowMaker");
1082 /* user dictionary */
1083 dict = ReadProplistFromFile(WDWindowMaker->path);
1084 if (dict) {
1085 if (!PLIsDictionary(dict)) {
1086 PLRelease(dict);
1087 dict = NULL;
1088 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1089 "WindowMaker", WDWindowMaker->path);
1090 } else {
1091 if (shared_dict) {
1092 PLSetFilename(shared_dict, PLGetFilename(dict));
1093 PLMergeDictionaries(shared_dict, dict);
1094 PLRelease(dict);
1095 dict = shared_dict;
1096 shared_dict = NULL;
1098 for (i=0; i<wScreenCount; i++) {
1099 scr = wScreenWithNumber(i);
1100 if (scr)
1101 wReadDefaults(scr, dict);
1103 if (WDWindowMaker->dictionary) {
1104 PLRelease(WDWindowMaker->dictionary);
1106 WDWindowMaker->dictionary = dict;
1108 } else {
1109 wwarning(_("could not load domain %s from user defaults database"),
1110 "WindowMaker");
1112 if (shared_dict) {
1113 PLRelease(shared_dict);
1117 if (stat(WDWindowAttributes->path, &stbuf)>=0
1118 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1119 #ifdef HEARTBEAT
1120 puts("Checking WMWindowAttributes domain");
1121 #endif
1122 dict = ReadProplistFromFile(WDWindowAttributes->path);
1123 if (dict) {
1124 if (!PLIsDictionary(dict)) {
1125 PLRelease(dict);
1126 dict = NULL;
1127 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1128 "WMWindowAttributes", WDWindowAttributes->path);
1129 } else {
1130 if (WDWindowAttributes->dictionary)
1131 PLRelease(WDWindowAttributes->dictionary);
1132 WDWindowAttributes->dictionary = dict;
1133 for (i=0; i<wScreenCount; i++) {
1134 scr = wScreenWithNumber(i);
1135 if (scr) {
1136 RImage *image;
1138 wDefaultUpdateIcons(scr);
1140 /* Update the panel image if changed */
1141 /* Don't worry. If the image is the same these
1142 * functions will have no performance impact. */
1143 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1145 if (!image) {
1146 wwarning(_("could not load logo image for panels: %s"),
1147 RMessageForError(RErrorCode));
1148 } else {
1149 WMSetApplicationIconImage(scr->wmscreen, image);
1150 RReleaseImage(image);
1155 } else {
1156 wwarning(_("could not load domain %s from user defaults database"),
1157 "WMWindowAttributes");
1159 WDWindowAttributes->timestamp = stbuf.st_mtime;
1162 #ifndef LITE
1163 if (stat(WDRootMenu->path, &stbuf)>=0
1164 && WDRootMenu->timestamp < stbuf.st_mtime) {
1165 dict = ReadProplistFromFile(WDRootMenu->path);
1166 #ifdef HEARTBEAT
1167 puts("Checking WMRootMenu domain");
1168 #endif
1169 if (dict) {
1170 if (!PLIsArray(dict) && !PLIsString(dict)) {
1171 PLRelease(dict);
1172 dict = NULL;
1173 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1174 "WMRootMenu", WDRootMenu->path);
1175 } else {
1176 if (WDRootMenu->dictionary) {
1177 PLRelease(WDRootMenu->dictionary);
1179 WDRootMenu->dictionary = dict;
1181 } else {
1182 wwarning(_("could not load domain %s from user defaults database"),
1183 "WMRootMenu");
1185 WDRootMenu->timestamp = stbuf.st_mtime;
1187 #endif /* !LITE */
1189 if (!foo)
1190 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1194 void
1195 wReadDefaults(WScreen *scr, proplist_t new_dict)
1197 proplist_t plvalue, old_value;
1198 WDefaultEntry *entry;
1199 int i, must_update;
1200 int update_workspace_back = 0; /* kluge :/ */
1201 int needs_refresh;
1202 void *tdata;
1203 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1204 ? WDWindowMaker->dictionary : NULL);
1206 must_update = 0;
1208 needs_refresh = 0;
1210 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1211 entry = &optionList[i];
1213 if (new_dict)
1214 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1215 else
1216 plvalue = NULL;
1218 if (!old_dict)
1219 old_value = NULL;
1220 else
1221 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1224 if (!plvalue && !old_value) {
1225 /* no default in the DB. Use builtin default */
1226 plvalue = entry->plvalue;
1227 if (plvalue && new_dict) {
1228 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1229 must_update = 1;
1231 } else if (!plvalue) {
1232 /* value was deleted from DB. Keep current value */
1233 continue;
1234 } else if (!old_value) {
1235 /* set value for the 1st time */
1236 } else if (!PLIsEqual(plvalue, old_value)) {
1237 /* value has changed */
1238 } else {
1240 if (strcmp(entry->key, "WorkspaceBack") == 0
1241 && update_workspace_back
1242 && scr->flags.backimage_helper_launched) {
1243 } else {
1244 /* value was not changed since last time */
1245 continue;
1249 if (plvalue) {
1250 #ifdef DEBUG
1251 printf("Updating %s to %s\n", entry->key,
1252 PLGetDescription(plvalue));
1253 #endif
1254 /* convert data */
1255 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1257 * If the WorkspaceSpecificBack data has been changed
1258 * so that the helper will be launched now, we must be
1259 * sure to send the default background texture config
1260 * to the helper.
1262 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1263 && !scr->flags.backimage_helper_launched) {
1264 update_workspace_back = 1;
1266 if (entry->update) {
1267 needs_refresh |=
1268 (*entry->update)(scr, entry, tdata, entry->extra_data);
1274 if (needs_refresh!=0 && !scr->flags.startup) {
1275 int foo;
1277 foo = 0;
1278 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1279 foo |= WTextureSettings;
1280 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1281 foo |= WFontSettings;
1282 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1283 foo |= WColorSettings;
1284 if (foo)
1285 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1286 (void*)foo);
1288 foo = 0;
1289 if (needs_refresh & REFRESH_MENU_TEXTURE)
1290 foo |= WTextureSettings;
1291 if (needs_refresh & REFRESH_MENU_FONT)
1292 foo |= WFontSettings;
1293 if (needs_refresh & REFRESH_MENU_COLOR)
1294 foo |= WColorSettings;
1295 if (foo)
1296 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1297 (void*)foo);
1299 foo = 0;
1300 if (needs_refresh & REFRESH_WINDOW_FONT) {
1301 foo |= WFontSettings;
1303 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1304 foo |= WTextureSettings;
1306 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1307 foo |= WColorSettings;
1309 if (foo)
1310 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1311 (void*)foo);
1313 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1314 foo = 0;
1315 if (needs_refresh & REFRESH_ICON_FONT) {
1316 foo |= WFontSettings;
1318 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1319 foo |= WTextureSettings;
1321 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1322 foo |= WTextureSettings;
1324 if (foo)
1325 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1326 (void*)foo);
1328 if (needs_refresh & REFRESH_ICON_TILE)
1329 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1334 void
1335 wDefaultUpdateIcons(WScreen *scr)
1337 WAppIcon *aicon = scr->app_icon_list;
1338 WWindow *wwin = scr->focused_window;
1339 char *file;
1341 while(aicon) {
1342 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1343 False);
1344 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1345 || (file && !aicon->icon->file)) {
1346 RImage *new_image;
1348 if (aicon->icon->file)
1349 wfree(aicon->icon->file);
1350 aicon->icon->file = wstrdup(file);
1352 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1353 aicon->wm_class);
1354 if (new_image) {
1355 wIconChangeImage(aicon->icon, new_image);
1356 wAppIconPaint(aicon);
1359 aicon = aicon->next;
1362 if (!wPreferences.flags.noclip)
1363 wClipIconPaint(scr->clip_icon);
1365 while (wwin) {
1366 if (wwin->icon && wwin->flags.miniaturized) {
1367 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1368 False);
1369 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1370 || (file && !wwin->icon->file)) {
1371 RImage *new_image;
1373 if (wwin->icon->file)
1374 wfree(wwin->icon->file);
1375 wwin->icon->file = wstrdup(file);
1377 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1378 wwin->wm_class);
1379 if (new_image)
1380 wIconChangeImage(wwin->icon, new_image);
1383 wwin = wwin->prev;
1388 /* --------------------------- Local ----------------------- */
1390 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1391 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1392 entry->key, x); \
1393 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1394 var = entry->default_value;\
1395 } else var = PLGetString(value)\
1401 static int
1402 string2index(proplist_t key, proplist_t val, proplist_t def,
1403 WOptionEnumeration *values)
1405 char *str;
1406 WOptionEnumeration *v;
1407 char buffer[TOTAL_VALUES_LENGTH];
1409 if (PLIsString(val) && (str = PLGetString(val))) {
1410 for (v=values; v->string!=NULL; v++) {
1411 if (strcasecmp(v->string, str)==0)
1412 return v->value;
1416 buffer[0] = 0;
1417 for (v=values; v->string!=NULL; v++) {
1418 if (!v->is_alias) {
1419 if (buffer[0]!=0)
1420 strcat(buffer, ", ");
1421 strcat(buffer, v->string);
1424 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1425 PLGetString(key), buffer);
1427 if (def) {
1428 return string2index(key, val, NULL, values);
1431 return -1;
1438 * value - is the value in the defaults DB
1439 * addr - is the address to store the data
1440 * ret - is the address to store a pointer to a temporary buffer. ret
1441 * must not be freed and is used by the set functions
1443 static int
1444 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1445 void **ret)
1447 static char data;
1448 char *val;
1449 int second_pass=0;
1451 GET_STRING_OR_DEFAULT("Boolean", val);
1453 again:
1454 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1455 || strcasecmp(val, "YES")==0) {
1457 data = 1;
1458 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1459 || strcasecmp(val, "NO")==0) {
1460 data = 0;
1461 } else {
1462 int i;
1463 if (sscanf(val, "%i", &i)==1) {
1464 if (i!=0)
1465 data = 1;
1466 else
1467 data = 0;
1468 } else {
1469 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1470 val, entry->key);
1471 if (second_pass==0) {
1472 val = PLGetString(entry->plvalue);
1473 second_pass = 1;
1474 wwarning(_("using default \"%s\" instead"), val);
1475 goto again;
1477 return False;
1481 if (ret)
1482 *ret = &data;
1484 if (addr) {
1485 *(char*)addr = data;
1488 return True;
1492 static int
1493 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1494 void **ret)
1496 static int data;
1497 char *val;
1500 GET_STRING_OR_DEFAULT("Integer", val);
1502 if (sscanf(val, "%i", &data)!=1) {
1503 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1504 val, entry->key);
1505 val = PLGetString(entry->plvalue);
1506 wwarning(_("using default \"%s\" instead"), val);
1507 if (sscanf(val, "%i", &data)!=1) {
1508 return False;
1512 if (ret)
1513 *ret = &data;
1515 if (addr) {
1516 *(int*)addr = data;
1518 return True;
1522 static int
1523 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1524 void **ret)
1526 static WCoord data;
1527 char *val_x, *val_y;
1528 int nelem, changed=0;
1529 proplist_t elem_x, elem_y;
1531 again:
1532 if (!PLIsArray(value)) {
1533 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1534 entry->key, "Coordinate");
1535 if (changed==0) {
1536 value = entry->plvalue;
1537 changed = 1;
1538 wwarning(_("using default \"%s\" instead"), entry->default_value);
1539 goto again;
1541 return False;
1544 nelem = PLGetNumberOfElements(value);
1545 if (nelem != 2) {
1546 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1547 entry->key);
1548 if (changed==0) {
1549 value = entry->plvalue;
1550 changed = 1;
1551 wwarning(_("using default \"%s\" instead"), entry->default_value);
1552 goto again;
1554 return False;
1557 elem_x = PLGetArrayElement(value, 0);
1558 elem_y = PLGetArrayElement(value, 1);
1560 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1561 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1562 entry->key);
1563 if (changed==0) {
1564 value = entry->plvalue;
1565 changed = 1;
1566 wwarning(_("using default \"%s\" instead"), entry->default_value);
1567 goto again;
1569 return False;
1572 val_x = PLGetString(elem_x);
1573 val_y = PLGetString(elem_y);
1575 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1576 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1577 if (changed==0) {
1578 value = entry->plvalue;
1579 changed = 1;
1580 wwarning(_("using default \"%s\" instead"), entry->default_value);
1581 goto again;
1583 return False;
1586 if (data.x < 0)
1587 data.x = 0;
1588 else if (data.x > scr->scr_width/3)
1589 data.x = scr->scr_width/3;
1590 if (data.y < 0)
1591 data.y = 0;
1592 else if (data.y > scr->scr_height/3)
1593 data.y = scr->scr_height/3;
1595 if (ret)
1596 *ret = &data;
1598 if (addr) {
1599 *(WCoord*)addr = data;
1602 return True;
1606 #if 0
1607 /* This function is not used at the moment. */
1608 static int
1609 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1610 void **ret)
1612 static char *data;
1614 GET_STRING_OR_DEFAULT("String", data);
1616 if (!data) {
1617 data = PLGetString(entry->plvalue);
1618 if (!data)
1619 return False;
1622 if (ret)
1623 *ret = &data;
1625 if (addr)
1626 *(char**)addr = wstrdup(data);
1628 return True;
1630 #endif
1633 static int
1634 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1635 void **ret)
1637 static char *data;
1638 int i, count, len;
1639 char *ptr;
1640 proplist_t d;
1641 int changed=0;
1643 again:
1644 if (!PLIsArray(value)) {
1645 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1646 entry->key, "an array of paths");
1647 if (changed==0) {
1648 value = entry->plvalue;
1649 changed = 1;
1650 wwarning(_("using default \"%s\" instead"), entry->default_value);
1651 goto again;
1653 return False;
1656 i = 0;
1657 count = PLGetNumberOfElements(value);
1658 if (count < 1) {
1659 if (changed==0) {
1660 value = entry->plvalue;
1661 changed = 1;
1662 wwarning(_("using default \"%s\" instead"), entry->default_value);
1663 goto again;
1665 return False;
1668 len = 0;
1669 for (i=0; i<count; i++) {
1670 d = PLGetArrayElement(value, i);
1671 if (!d || !PLIsString(d)) {
1672 count = i;
1673 break;
1675 len += strlen(PLGetString(d))+1;
1678 ptr = data = wmalloc(len+1);
1680 for (i=0; i<count; i++) {
1681 d = PLGetArrayElement(value, i);
1682 if (!d || !PLIsString(d)) {
1683 break;
1685 strcpy(ptr, PLGetString(d));
1686 ptr += strlen(PLGetString(d));
1687 *ptr = ':';
1688 ptr++;
1690 ptr--; *(ptr--) = 0;
1692 if (*(char**)addr!=NULL) {
1693 wfree(*(char**)addr);
1695 *(char**)addr = data;
1697 return True;
1701 static int
1702 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1703 void **ret)
1705 static signed char data;
1707 data = string2index(entry->plkey, value, entry->default_value,
1708 (WOptionEnumeration*)entry->extra_data);
1709 if (data < 0)
1710 return False;
1712 if (ret)
1713 *ret = &data;
1715 if (addr)
1716 *(signed char*)addr = data;
1718 return True;
1724 * (solid <color>)
1725 * (hgradient <color> <color>)
1726 * (vgradient <color> <color>)
1727 * (dgradient <color> <color>)
1728 * (mhgradient <color> <color> ...)
1729 * (mvgradient <color> <color> ...)
1730 * (mdgradient <color> <color> ...)
1731 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1732 * (tpixmap <file> <color>)
1733 * (spixmap <file> <color>)
1734 * (cpixmap <file> <color>)
1735 * (thgradient <file> <opaqueness> <color> <color>)
1736 * (tvgradient <file> <opaqueness> <color> <color>)
1737 * (tdgradient <file> <opaqueness> <color> <color>)
1738 * (function <lib> <function> ...)
1741 static WTexture*
1742 parse_texture(WScreen *scr, proplist_t pl)
1744 proplist_t elem;
1745 char *val;
1746 int nelem;
1747 WTexture *texture=NULL;
1749 nelem = PLGetNumberOfElements(pl);
1750 if (nelem < 1)
1751 return NULL;
1754 elem = PLGetArrayElement(pl, 0);
1755 if (!elem || !PLIsString(elem))
1756 return NULL;
1757 val = PLGetString(elem);
1760 if (strcasecmp(val, "solid")==0) {
1761 XColor color;
1763 if (nelem != 2)
1764 return NULL;
1766 /* get color */
1768 elem = PLGetArrayElement(pl, 1);
1769 if (!elem || !PLIsString(elem))
1770 return NULL;
1771 val = PLGetString(elem);
1773 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1774 wwarning(_("\"%s\" is not a valid color name"), val);
1775 return NULL;
1778 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1779 } else if (strcasecmp(val, "dgradient")==0
1780 || strcasecmp(val, "vgradient")==0
1781 || strcasecmp(val, "hgradient")==0) {
1782 RColor color1, color2;
1783 XColor xcolor;
1784 int type;
1786 if (nelem != 3) {
1787 wwarning(_("bad number of arguments in gradient specification"));
1788 return NULL;
1791 if (val[0]=='d' || val[0]=='D')
1792 type = WTEX_DGRADIENT;
1793 else if (val[0]=='h' || val[0]=='H')
1794 type = WTEX_HGRADIENT;
1795 else
1796 type = WTEX_VGRADIENT;
1799 /* get from color */
1800 elem = PLGetArrayElement(pl, 1);
1801 if (!elem || !PLIsString(elem))
1802 return NULL;
1803 val = PLGetString(elem);
1805 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1806 wwarning(_("\"%s\" is not a valid color name"), val);
1807 return NULL;
1809 color1.alpha = 255;
1810 color1.red = xcolor.red >> 8;
1811 color1.green = xcolor.green >> 8;
1812 color1.blue = xcolor.blue >> 8;
1814 /* get to color */
1815 elem = PLGetArrayElement(pl, 2);
1816 if (!elem || !PLIsString(elem)) {
1817 return NULL;
1819 val = PLGetString(elem);
1821 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1822 wwarning(_("\"%s\" is not a valid color name"), val);
1823 return NULL;
1825 color2.alpha = 255;
1826 color2.red = xcolor.red >> 8;
1827 color2.green = xcolor.green >> 8;
1828 color2.blue = xcolor.blue >> 8;
1830 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1832 } else if (strcasecmp(val, "igradient")==0) {
1833 RColor colors1[2], colors2[2];
1834 int th1, th2;
1835 XColor xcolor;
1836 int i;
1838 if (nelem != 7) {
1839 wwarning(_("bad number of arguments in gradient specification"));
1840 return NULL;
1843 /* get from color */
1844 for (i = 0; i < 2; i++) {
1845 elem = PLGetArrayElement(pl, 1+i);
1846 if (!elem || !PLIsString(elem))
1847 return NULL;
1848 val = PLGetString(elem);
1850 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1851 wwarning(_("\"%s\" is not a valid color name"), val);
1852 return NULL;
1854 colors1[i].alpha = 255;
1855 colors1[i].red = xcolor.red >> 8;
1856 colors1[i].green = xcolor.green >> 8;
1857 colors1[i].blue = xcolor.blue >> 8;
1859 elem = PLGetArrayElement(pl, 3);
1860 if (!elem || !PLIsString(elem))
1861 return NULL;
1862 val = PLGetString(elem);
1863 th1 = atoi(val);
1866 /* get from color */
1867 for (i = 0; i < 2; i++) {
1868 elem = PLGetArrayElement(pl, 4+i);
1869 if (!elem || !PLIsString(elem))
1870 return NULL;
1871 val = PLGetString(elem);
1873 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1874 wwarning(_("\"%s\" is not a valid color name"), val);
1875 return NULL;
1877 colors2[i].alpha = 255;
1878 colors2[i].red = xcolor.red >> 8;
1879 colors2[i].green = xcolor.green >> 8;
1880 colors2[i].blue = xcolor.blue >> 8;
1882 elem = PLGetArrayElement(pl, 6);
1883 if (!elem || !PLIsString(elem))
1884 return NULL;
1885 val = PLGetString(elem);
1886 th2 = atoi(val);
1888 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1889 th2, colors2);
1891 } else if (strcasecmp(val, "mhgradient")==0
1892 || strcasecmp(val, "mvgradient")==0
1893 || strcasecmp(val, "mdgradient")==0) {
1894 XColor color;
1895 RColor **colors;
1896 int i, count;
1897 int type;
1899 if (nelem < 3) {
1900 wwarning(_("too few arguments in multicolor gradient specification"));
1901 return NULL;
1904 if (val[1]=='h' || val[1]=='H')
1905 type = WTEX_MHGRADIENT;
1906 else if (val[1]=='v' || val[1]=='V')
1907 type = WTEX_MVGRADIENT;
1908 else
1909 type = WTEX_MDGRADIENT;
1911 count = nelem-1;
1913 colors = wmalloc(sizeof(RColor*)*(count+1));
1915 for (i=0; i<count; i++) {
1916 elem = PLGetArrayElement(pl, i+1);
1917 if (!elem || !PLIsString(elem)) {
1918 for (--i; i>=0; --i) {
1919 wfree(colors[i]);
1921 wfree(colors);
1922 return NULL;
1924 val = PLGetString(elem);
1926 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1927 wwarning(_("\"%s\" is not a valid color name"), val);
1928 for (--i; i>=0; --i) {
1929 wfree(colors[i]);
1931 wfree(colors);
1932 return NULL;
1933 } else {
1934 colors[i] = wmalloc(sizeof(RColor));
1935 colors[i]->red = color.red >> 8;
1936 colors[i]->green = color.green >> 8;
1937 colors[i]->blue = color.blue >> 8;
1940 colors[i] = NULL;
1942 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1943 } else if (strcasecmp(val, "spixmap")==0 ||
1944 strcasecmp(val, "cpixmap")==0 ||
1945 strcasecmp(val, "tpixmap")==0) {
1946 XColor color;
1947 int type;
1949 if (nelem != 3)
1950 return NULL;
1952 if (val[0] == 's' || val[0] == 'S')
1953 type = WTP_SCALE;
1954 else if (val[0] == 'c' || val[0] == 'C')
1955 type = WTP_CENTER;
1956 else
1957 type = WTP_TILE;
1959 /* get color */
1960 elem = PLGetArrayElement(pl, 2);
1961 if (!elem || !PLIsString(elem)) {
1962 return NULL;
1964 val = PLGetString(elem);
1966 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1967 wwarning(_("\"%s\" is not a valid color name"), val);
1968 return NULL;
1971 /* file name */
1972 elem = PLGetArrayElement(pl, 1);
1973 if (!elem || !PLIsString(elem))
1974 return NULL;
1975 val = PLGetString(elem);
1977 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1978 } else if (strcasecmp(val, "thgradient")==0
1979 || strcasecmp(val, "tvgradient")==0
1980 || strcasecmp(val, "tdgradient")==0) {
1981 RColor color1, color2;
1982 XColor xcolor;
1983 int opacity;
1984 int style;
1986 if (val[1]=='h' || val[1]=='H')
1987 style = WTEX_THGRADIENT;
1988 else if (val[1]=='v' || val[1]=='V')
1989 style = WTEX_TVGRADIENT;
1990 else
1991 style = WTEX_TDGRADIENT;
1993 if (nelem != 5) {
1994 wwarning(_("bad number of arguments in textured gradient specification"));
1995 return NULL;
1998 /* get from color */
1999 elem = PLGetArrayElement(pl, 3);
2000 if (!elem || !PLIsString(elem))
2001 return NULL;
2002 val = PLGetString(elem);
2004 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2005 wwarning(_("\"%s\" is not a valid color name"), val);
2006 return NULL;
2008 color1.alpha = 255;
2009 color1.red = xcolor.red >> 8;
2010 color1.green = xcolor.green >> 8;
2011 color1.blue = xcolor.blue >> 8;
2013 /* get to color */
2014 elem = PLGetArrayElement(pl, 4);
2015 if (!elem || !PLIsString(elem)) {
2016 return NULL;
2018 val = PLGetString(elem);
2020 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2021 wwarning(_("\"%s\" is not a valid color name"), val);
2022 return NULL;
2024 color2.alpha = 255;
2025 color2.red = xcolor.red >> 8;
2026 color2.green = xcolor.green >> 8;
2027 color2.blue = xcolor.blue >> 8;
2029 /* get opacity */
2030 elem = PLGetArrayElement(pl, 2);
2031 if (!elem || !PLIsString(elem))
2032 opacity = 128;
2033 else
2034 val = PLGetString(elem);
2036 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2037 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2038 opacity = 128;
2041 /* get file name */
2042 elem = PLGetArrayElement(pl, 1);
2043 if (!elem || !PLIsString(elem))
2044 return NULL;
2045 val = PLGetString(elem);
2047 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2048 val, opacity);
2050 #ifdef TEXTURE_PLUGIN
2051 else if (strcasecmp(val, "function")==0) {
2052 WTexFunction *function;
2053 void (*initFunc) (Display *, Colormap);
2054 char *lib, *func, **argv;
2055 int i, argc;
2057 if (nelem < 3)
2058 return NULL;
2060 /* get the library name */
2061 elem = PLGetArrayElement(pl, 1);
2062 if (!elem || !PLIsString(elem)) {
2063 return NULL;
2065 lib = PLGetString(elem);
2067 /* get the function name */
2068 elem = PLGetArrayElement(pl, 2);
2069 if (!elem || !PLIsString(elem)) {
2070 return NULL;
2072 func = PLGetString(elem);
2074 argc = nelem - 2;
2075 argv = (char **)wmalloc(argc * sizeof(char *));
2077 /* get the parameters */
2078 argv[0] = wstrdup(func);
2079 for (i = 0; i < argc - 1; i++) {
2080 elem = PLGetArrayElement(pl, 3 + i);
2081 if (!elem || !PLIsString(elem)) {
2082 wfree(argv);
2084 return NULL;
2086 argv[i+1] = wstrdup(PLGetString(elem));
2089 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2091 #ifdef HAVE_DLFCN_H
2092 if (function) {
2093 initFunc = dlsym(function->handle, "initWindowMaker");
2094 if (initFunc) {
2095 initFunc(dpy, scr->w_colormap);
2096 } else {
2097 wwarning(_("could not initialize library %s"), lib);
2099 } else {
2100 wwarning(_("could not find function %s::%s"), lib, func);
2102 #endif /* HAVE_DLFCN_H */
2103 texture = (WTexture*)function;
2105 #endif /* TEXTURE_PLUGIN */
2106 else {
2107 wwarning(_("invalid texture type %s"), val);
2108 return NULL;
2110 return texture;
2115 static int
2116 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2117 void **ret)
2119 static WTexture *texture;
2120 int changed=0;
2122 again:
2123 if (!PLIsArray(value)) {
2124 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2125 entry->key, "Texture");
2126 if (changed==0) {
2127 value = entry->plvalue;
2128 changed = 1;
2129 wwarning(_("using default \"%s\" instead"), entry->default_value);
2130 goto again;
2132 return False;
2135 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2136 proplist_t pl;
2138 pl = PLGetArrayElement(value, 0);
2139 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2140 || strcasecmp(PLGetString(pl), "solid")!=0) {
2141 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2142 entry->key, "Solid Texture");
2144 value = entry->plvalue;
2145 changed = 1;
2146 wwarning(_("using default \"%s\" instead"), entry->default_value);
2147 goto again;
2151 texture = parse_texture(scr, value);
2153 if (!texture) {
2154 wwarning(_("Error in texture specification for key \"%s\""),
2155 entry->key);
2156 if (changed==0) {
2157 value = entry->plvalue;
2158 changed = 1;
2159 wwarning(_("using default \"%s\" instead"), entry->default_value);
2160 goto again;
2162 return False;
2165 if (ret)
2166 *ret = &texture;
2168 if (addr)
2169 *(WTexture**)addr = texture;
2171 return True;
2175 static int
2176 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2177 void *addr, void **ret)
2179 proplist_t elem;
2180 int changed = 0;
2181 char *val;
2182 int nelem;
2184 again:
2185 if (!PLIsArray(value)) {
2186 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2187 "WorkspaceBack", "Texture or None");
2188 if (changed==0) {
2189 value = entry->plvalue;
2190 changed = 1;
2191 wwarning(_("using default \"%s\" instead"), entry->default_value);
2192 goto again;
2194 return False;
2197 /* only do basic error checking and verify for None texture */
2199 nelem = PLGetNumberOfElements(value);
2200 if (nelem > 0) {
2201 elem = PLGetArrayElement(value, 0);
2202 if (!elem || !PLIsString(elem)) {
2203 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2204 if (changed==0) {
2205 value = entry->plvalue;
2206 changed = 1;
2207 wwarning(_("using default \"%s\" instead"), entry->default_value);
2208 goto again;
2210 return False;
2212 val = PLGetString(elem);
2214 if (strcasecmp(val, "None")==0)
2215 return True;
2217 *ret = PLRetain(value);
2219 return True;
2223 static int
2224 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2225 void *addr, void **ret)
2227 proplist_t elem;
2228 int nelem;
2229 int changed = 0;
2231 again:
2232 if (!PLIsArray(value)) {
2233 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2234 "WorkspaceSpecificBack", "an array of textures");
2235 if (changed==0) {
2236 value = entry->plvalue;
2237 changed = 1;
2238 wwarning(_("using default \"%s\" instead"), entry->default_value);
2239 goto again;
2241 return False;
2244 /* only do basic error checking and verify for None texture */
2246 nelem = PLGetNumberOfElements(value);
2247 if (nelem > 0) {
2248 while (nelem--) {
2249 elem = PLGetArrayElement(value, nelem);
2250 if (!elem || !PLIsArray(elem)) {
2251 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2252 nelem);
2257 *ret = PLRetain(value);
2259 #ifdef notworking
2261 * Kluge to force wmsetbg helper to set the default background.
2262 * If the WorkspaceSpecificBack is changed once wmaker has started,
2263 * the WorkspaceBack won't be sent to the helper, unless the user
2264 * changes it's value too. So, we must force this by removing the
2265 * value from the defaults DB.
2267 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2268 proplist_t key = PLMakeString("WorkspaceBack");
2270 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2272 PLRelease(key);
2274 #endif
2275 return True;
2279 static int
2280 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2281 void **ret)
2283 static WMFont *font;
2284 char *val;
2286 GET_STRING_OR_DEFAULT("Font", val);
2288 font = WMCreateFont(scr->wmscreen, val);
2289 if (!font)
2290 font = WMCreateFont(scr->wmscreen, "fixed");
2292 if (!font) {
2293 wfatal(_("could not load any usable font!!!"));
2294 exit(1);
2297 if (ret)
2298 *ret = font;
2300 /* can't assign font value outside update function */
2301 wassertrv(addr == NULL, True);
2303 return True;
2307 static int
2308 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2309 void **ret)
2311 static XColor color;
2312 char *val;
2313 int second_pass=0;
2315 GET_STRING_OR_DEFAULT("Color", val);
2318 again:
2319 if (!wGetColor(scr, val, &color)) {
2320 wwarning(_("could not get color for key \"%s\""),
2321 entry->key);
2322 if (second_pass==0) {
2323 val = PLGetString(entry->plvalue);
2324 second_pass = 1;
2325 wwarning(_("using default \"%s\" instead"), val);
2326 goto again;
2328 return False;
2331 if (ret)
2332 *ret = &color;
2334 assert(addr==NULL);
2336 if (addr)
2337 *(unsigned long*)addr = pixel;
2340 return True;
2345 static int
2346 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2347 void **ret)
2349 static WShortKey shortcut;
2350 KeySym ksym;
2351 char *val;
2352 char *k;
2353 char buf[128], *b;
2356 GET_STRING_OR_DEFAULT("Key spec", val);
2358 if (!val || strcasecmp(val, "NONE")==0) {
2359 shortcut.keycode = 0;
2360 shortcut.modifier = 0;
2361 if (ret)
2362 *ret = &shortcut;
2363 return True;
2366 strcpy(buf, val);
2368 b = (char*)buf;
2370 /* get modifiers */
2371 shortcut.modifier = 0;
2372 while ((k = strchr(b, '+'))!=NULL) {
2373 int mod;
2375 *k = 0;
2376 mod = wXModifierFromKey(b);
2377 if (mod<0) {
2378 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2379 return False;
2381 shortcut.modifier |= mod;
2383 b = k+1;
2386 /* get key */
2387 ksym = XStringToKeysym(b);
2389 if (ksym==NoSymbol) {
2390 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2391 val);
2392 return False;
2395 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2396 if (shortcut.keycode==0) {
2397 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2398 return False;
2401 if (ret)
2402 *ret = &shortcut;
2404 return True;
2408 static int
2409 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2410 void **ret)
2412 static unsigned int mask;
2413 char *str;
2415 GET_STRING_OR_DEFAULT("Modifier Key", str);
2417 if (!str)
2418 return False;
2420 mask = wXModifierFromKey(str);
2421 if (mask < 0) {
2422 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2423 mask = 0;
2424 return False;
2427 if (addr)
2428 *(unsigned int*)addr = mask;
2430 if (ret)
2431 *ret = &mask;
2433 return True;
2437 #ifdef NEWSTUFF
2438 static int
2439 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2440 void *addr, void **ret)
2442 unsigned int mask;
2443 char *str;
2444 RImage *image;
2445 int i, n;
2446 int w, h;
2448 GET_STRING_OR_DEFAULT("Image File Path", str);
2449 if (!str)
2450 return False;
2452 image = RLoadImage(scr->rcontext, str, 0);
2453 if (!image) {
2454 wwarning(_("could not load image in option %s: %s"), entry->key,
2455 RMessageForError(RErrorCode));
2456 return False;
2459 if (*(RImage**)addr) {
2460 RReleaseImage(*(RImage**)addr);
2462 if (addr)
2463 *(RImage**)addr = image;
2465 assert(ret == NULL);
2467 if (ret)
2468 *(RImage**)ret = image;
2471 return True;
2473 #endif
2475 #ifdef DEFINABLE_CURSOR
2477 # include <X11/cursorfont.h>
2478 typedef struct
2480 char *name;
2481 int id;
2482 } WCursorLookup;
2484 #define CURSOR_ID_NONE (XC_num_glyphs)
2486 static WCursorLookup cursor_table[] =
2488 { "X_cursor", XC_X_cursor },
2489 { "arrow", XC_arrow },
2490 { "based_arrow_down", XC_based_arrow_down },
2491 { "based_arrow_up", XC_based_arrow_up },
2492 { "boat", XC_boat },
2493 { "bogosity", XC_bogosity },
2494 { "bottom_left_corner", XC_bottom_left_corner },
2495 { "bottom_right_corner", XC_bottom_right_corner },
2496 { "bottom_side", XC_bottom_side },
2497 { "bottom_tee", XC_bottom_tee },
2498 { "box_spiral", XC_box_spiral },
2499 { "center_ptr", XC_center_ptr },
2500 { "circle", XC_circle },
2501 { "clock", XC_clock },
2502 { "coffee_mug", XC_coffee_mug },
2503 { "cross", XC_cross },
2504 { "cross_reverse", XC_cross_reverse },
2505 { "crosshair", XC_crosshair },
2506 { "diamond_cross", XC_diamond_cross },
2507 { "dot", XC_dot },
2508 { "dotbox", XC_dotbox },
2509 { "double_arrow", XC_double_arrow },
2510 { "draft_large", XC_draft_large },
2511 { "draft_small", XC_draft_small },
2512 { "draped_box", XC_draped_box },
2513 { "exchange", XC_exchange },
2514 { "fleur", XC_fleur },
2515 { "gobbler", XC_gobbler },
2516 { "gumby", XC_gumby },
2517 { "hand1", XC_hand1 },
2518 { "hand2", XC_hand2 },
2519 { "heart", XC_heart },
2520 { "icon", XC_icon },
2521 { "iron_cross", XC_iron_cross },
2522 { "left_ptr", XC_left_ptr },
2523 { "left_side", XC_left_side },
2524 { "left_tee", XC_left_tee },
2525 { "leftbutton", XC_leftbutton },
2526 { "ll_angle", XC_ll_angle },
2527 { "lr_angle", XC_lr_angle },
2528 { "man", XC_man },
2529 { "middlebutton", XC_middlebutton },
2530 { "mouse", XC_mouse },
2531 { "pencil", XC_pencil },
2532 { "pirate", XC_pirate },
2533 { "plus", XC_plus },
2534 { "question_arrow", XC_question_arrow },
2535 { "right_ptr", XC_right_ptr },
2536 { "right_side", XC_right_side },
2537 { "right_tee", XC_right_tee },
2538 { "rightbutton", XC_rightbutton },
2539 { "rtl_logo", XC_rtl_logo },
2540 { "sailboat", XC_sailboat },
2541 { "sb_down_arrow", XC_sb_down_arrow },
2542 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2543 { "sb_left_arrow", XC_sb_left_arrow },
2544 { "sb_right_arrow", XC_sb_right_arrow },
2545 { "sb_up_arrow", XC_sb_up_arrow },
2546 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2547 { "shuttle", XC_shuttle },
2548 { "sizing", XC_sizing },
2549 { "spider", XC_spider },
2550 { "spraycan", XC_spraycan },
2551 { "star", XC_star },
2552 { "target", XC_target },
2553 { "tcross", XC_tcross },
2554 { "top_left_arrow", XC_top_left_arrow },
2555 { "top_left_corner", XC_top_left_corner },
2556 { "top_right_corner", XC_top_right_corner },
2557 { "top_side", XC_top_side },
2558 { "top_tee", XC_top_tee },
2559 { "trek", XC_trek },
2560 { "ul_angle", XC_ul_angle },
2561 { "umbrella", XC_umbrella },
2562 { "ur_angle", XC_ur_angle },
2563 { "watch", XC_watch },
2564 { "xterm", XC_xterm },
2565 { NULL, CURSOR_ID_NONE }
2568 static void
2569 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2571 switch(status) {
2572 case BitmapOpenFailed:
2573 wwarning(_("failed to open bitmap file \"%s\""), filename);
2574 break;
2575 case BitmapFileInvalid:
2576 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2577 break;
2578 case BitmapNoMemory:
2579 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2580 break;
2581 case BitmapSuccess:
2582 XFreePixmap(dpy, bitmap);
2583 break;
2588 * (none)
2589 * (builtin, <cursor_name>)
2590 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2592 static int
2593 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2595 proplist_t elem;
2596 char *val;
2597 int nelem;
2598 int status = 0;
2600 nelem = PLGetNumberOfElements(pl);
2601 if (nelem < 1) {
2602 return(status);
2604 elem = PLGetArrayElement(pl, 0);
2605 if (!elem || !PLIsString(elem)) {
2606 return(status);
2608 val = PLGetString(elem);
2610 if (0 == strcasecmp(val, "none")) {
2611 status = 1;
2612 *cursor = None;
2613 } else if (0 == strcasecmp(val, "builtin")) {
2614 int i;
2615 int cursor_id = CURSOR_ID_NONE;
2617 if (2 != nelem) {
2618 wwarning(_("bad number of arguments in cursor specification"));
2619 return(status);
2621 elem = PLGetArrayElement(pl, 1);
2622 if (!elem || !PLIsString(elem)) {
2623 return(status);
2625 val = PLGetString(elem);
2627 for (i = 0; NULL != cursor_table[i].name; i++) {
2628 if (0 == strcasecmp(val, cursor_table[i].name)) {
2629 cursor_id = cursor_table[i].id;
2630 break;
2633 if (CURSOR_ID_NONE == cursor_id) {
2634 wwarning(_("unknown builtin cursor name \"%s\""), val);
2635 } else {
2636 *cursor = XCreateFontCursor(dpy, cursor_id);
2637 status = 1;
2639 } else if (0 == strcasecmp(val, "bitmap")) {
2640 char *bitmap_name;
2641 char *mask_name;
2642 int bitmap_status;
2643 int mask_status;
2644 Pixmap bitmap;
2645 Pixmap mask;
2646 unsigned int w, h;
2647 int x, y;
2648 XColor fg, bg;
2650 if (3 != nelem) {
2651 wwarning(_("bad number of arguments in cursor specification"));
2652 return(status);
2654 elem = PLGetArrayElement(pl, 1);
2655 if (!elem || !PLIsString(elem)) {
2656 return(status);
2658 val = PLGetString(elem);
2659 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2660 if (!bitmap_name) {
2661 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2662 return(status);
2664 elem = PLGetArrayElement(pl, 2);
2665 if (!elem || !PLIsString(elem)) {
2666 wfree(bitmap_name);
2667 return(status);
2669 val = PLGetString(elem);
2670 mask_name = FindImage(wPreferences.pixmap_path, val);
2671 if (!mask_name) {
2672 wfree(bitmap_name);
2673 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2674 return(status);
2676 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2677 &mask, &x, &y);
2678 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2679 &bitmap, &x, &y);
2680 if ((BitmapSuccess == bitmap_status) &&
2681 (BitmapSuccess == mask_status)) {
2682 fg.pixel = scr->black_pixel;
2683 bg.pixel = scr->white_pixel;
2684 XQueryColor(dpy, scr->w_colormap, &fg);
2685 XQueryColor(dpy, scr->w_colormap, &bg);
2686 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2687 status = 1;
2689 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2690 check_bitmap_status(mask_status, mask_name, mask);
2691 wfree(bitmap_name);
2692 wfree(mask_name);
2694 return(status);
2698 static int
2699 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2700 void **ret)
2702 static Cursor cursor;
2703 int status;
2704 int changed = 0;
2706 again:
2707 if (!PLIsArray(value)) {
2708 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2709 entry->key, "cursor specification");
2710 if (!changed) {
2711 value = entry->plvalue;
2712 changed = 1;
2713 wwarning(_("using default \"%s\" instead"), entry->default_value);
2714 goto again;
2716 return(False);
2718 status = parse_cursor(scr, value, &cursor);
2719 if (!status) {
2720 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2721 if (!changed) {
2722 value = entry->plvalue;
2723 changed = 1;
2724 wwarning(_("using default \"%s\" instead"), entry->default_value);
2725 goto again;
2727 return(False);
2729 if (ret) {
2730 *ret = &cursor;
2732 if (addr) {
2733 *(Cursor *)addr = cursor;
2735 return(True);
2737 #undef CURSOR_ID_NONE
2739 #endif /* DEFINABLE_CURSOR */
2742 /* ---------------- value setting functions --------------- */
2743 static int
2744 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2746 return REFRESH_WINDOW_TITLE_COLOR;
2749 static int
2750 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2752 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2755 static int
2756 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2758 switch (which) {
2759 case WM_DOCK:
2760 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2761 break;
2762 case WM_CLIP:
2763 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2764 break;
2765 default:
2766 break;
2768 return 0;
2772 static int
2773 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2775 if (scr->workspaces) {
2776 wWorkspaceForceChange(scr, scr->current_workspace);
2777 wArrangeIcons(scr, False);
2779 return 0;
2782 #if not_used
2783 static int
2784 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2786 if (*value <= 0)
2787 *(int*)foo = 1;
2789 return 0;
2791 #endif
2795 static int
2796 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2798 Pixmap pixmap;
2799 RImage *img;
2800 int reset = 0;
2802 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2803 wPreferences.icon_size,
2804 ((*texture)->any.type & WREL_BORDER_MASK)
2805 ? WREL_ICON : WREL_FLAT);
2806 if (!img) {
2807 wwarning(_("could not render texture for icon background"));
2808 if (!entry->addr)
2809 wTextureDestroy(scr, *texture);
2810 return 0;
2812 RConvertImage(scr->rcontext, img, &pixmap);
2814 if (scr->icon_tile) {
2815 reset = 1;
2816 RReleaseImage(scr->icon_tile);
2817 XFreePixmap(dpy, scr->icon_tile_pixmap);
2820 scr->icon_tile = img;
2823 /* put the icon in the noticeboard hint */
2824 PropSetIconTileHint(scr, img);
2827 if (!wPreferences.flags.noclip) {
2828 if (scr->clip_tile) {
2829 RReleaseImage(scr->clip_tile);
2831 scr->clip_tile = wClipMakeTile(scr, img);
2834 scr->icon_tile_pixmap = pixmap;
2836 if (scr->def_icon_pixmap) {
2837 XFreePixmap(dpy, scr->def_icon_pixmap);
2838 scr->def_icon_pixmap = None;
2840 if (scr->def_ticon_pixmap) {
2841 XFreePixmap(dpy, scr->def_ticon_pixmap);
2842 scr->def_ticon_pixmap = None;
2845 if (scr->icon_back_texture) {
2846 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2848 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2850 if (scr->clip_balloon)
2851 XSetWindowBackground(dpy, scr->clip_balloon,
2852 (*texture)->any.color.pixel);
2855 * Free the texture as nobody else will use it, nor refer to it.
2857 if (!entry->addr)
2858 wTextureDestroy(scr, *texture);
2860 return (reset ? REFRESH_ICON_TILE : 0);
2865 static int
2866 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2868 if (scr->title_font) {
2869 WMReleaseFont(scr->title_font);
2871 scr->title_font = font;
2873 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2877 static int
2878 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2880 if (scr->menu_title_font) {
2881 WMReleaseFont(scr->menu_title_font);
2884 scr->menu_title_font = font;
2886 return REFRESH_MENU_TITLE_FONT;
2890 static int
2891 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2893 if (scr->menu_entry_font) {
2894 WMReleaseFont(scr->menu_entry_font);
2896 scr->menu_entry_font = font;
2898 return REFRESH_MENU_FONT;
2903 static int
2904 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2906 if (scr->icon_title_font) {
2907 WMReleaseFont(scr->icon_title_font);
2910 scr->icon_title_font = font;
2912 return REFRESH_ICON_FONT;
2916 static int
2917 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2919 if (scr->clip_title_font) {
2920 WMReleaseFont(scr->clip_title_font);
2923 scr->clip_title_font = font;
2925 return REFRESH_ICON_FONT;
2929 static int
2930 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2932 if (scr->workspace_name_font) {
2933 WMReleaseFont(scr->workspace_name_font);
2936 scr->workspace_name_font = font;
2938 return 0;
2942 static int
2943 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2945 if (scr->select_pixel!=scr->white_pixel &&
2946 scr->select_pixel!=scr->black_pixel) {
2947 wFreeColor(scr, scr->select_pixel);
2950 scr->select_pixel = color->pixel;
2952 return REFRESH_MENU_COLOR;
2956 static int
2957 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2959 if (scr->select_text_pixel!=scr->white_pixel &&
2960 scr->select_text_pixel!=scr->black_pixel) {
2961 wFreeColor(scr, scr->select_text_pixel);
2964 scr->select_text_pixel = color->pixel;
2966 return REFRESH_MENU_COLOR;
2970 static int
2971 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2973 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2974 scr->clip_title_pixel[index]!=scr->black_pixel) {
2975 wFreeColor(scr, scr->clip_title_pixel[index]);
2977 scr->clip_title_pixel[index] = color->pixel;
2979 #ifdef GRADIENT_CLIP_ARROW
2980 if (index == CLIP_NORMAL) {
2981 RImage *image;
2982 RColor color1, color2;
2983 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2984 int as = pt - 15; /* 15 = 5+5+5 */
2986 FREE_PIXMAP(scr->clip_arrow_gradient);
2988 color1.red = (color->red >> 8)*6/10;
2989 color1.green = (color->green >> 8)*6/10;
2990 color1.blue = (color->blue >> 8)*6/10;
2992 color2.red = WMIN((color->red >> 8)*20/10, 255);
2993 color2.green = WMIN((color->green >> 8)*20/10, 255);
2994 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2996 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2997 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2998 RReleaseImage(image);
3000 #endif /* GRADIENT_CLIP_ARROW */
3002 return REFRESH_ICON_TITLE_COLOR;
3006 static int
3007 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3009 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3010 scr->window_title_pixel[index]!=scr->black_pixel) {
3011 wFreeColor(scr, scr->window_title_pixel[index]);
3014 scr->window_title_pixel[index] = color->pixel;
3016 if (index == WS_UNFOCUSED)
3017 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3019 return REFRESH_WINDOW_TITLE_COLOR;
3023 static int
3024 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3026 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3027 scr->menu_title_pixel[0]!=scr->black_pixel) {
3028 wFreeColor(scr, scr->menu_title_pixel[0]);
3031 scr->menu_title_pixel[0] = color->pixel;
3032 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3034 return REFRESH_MENU_TITLE_COLOR;
3038 static int
3039 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3041 XGCValues gcv;
3042 #define gcm (GCForeground|GCBackground|GCFillStyle)
3044 if (scr->mtext_pixel!=scr->white_pixel &&
3045 scr->mtext_pixel!=scr->black_pixel) {
3046 wFreeColor(scr, scr->mtext_pixel);
3049 scr->mtext_pixel = color->pixel;
3051 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3054 if (scr->dtext_pixel == scr->mtext_pixel) {
3055 gcv.foreground = scr->white_pixel;
3056 gcv.background = scr->black_pixel;
3057 gcv.fill_style = FillStippled;
3058 } else {
3059 gcv.foreground = scr->dtext_pixel;
3060 gcv.fill_style = FillSolid;
3062 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3064 return REFRESH_MENU_COLOR;
3065 #undef gcm
3069 static int
3070 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3072 XGCValues gcv;
3073 #define gcm (GCForeground|GCBackground|GCFillStyle)
3075 if (scr->dtext_pixel!=scr->white_pixel &&
3076 scr->dtext_pixel!=scr->black_pixel) {
3077 wFreeColor(scr, scr->dtext_pixel);
3080 scr->dtext_pixel = color->pixel;
3082 if (scr->dtext_pixel == scr->mtext_pixel) {
3083 gcv.foreground = scr->white_pixel;
3084 gcv.background = scr->black_pixel;
3085 gcv.fill_style = FillStippled;
3086 } else {
3087 gcv.foreground = scr->dtext_pixel;
3088 gcv.fill_style = FillSolid;
3090 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3092 return REFRESH_MENU_COLOR;
3093 #undef gcm
3096 static int
3097 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3099 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3101 return REFRESH_ICON_TITLE_COLOR;
3105 static int
3106 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3108 if (scr->icon_title_texture) {
3109 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3111 XQueryColor (dpy, scr->w_colormap, color);
3112 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3114 return REFRESH_ICON_TITLE_BACK;
3118 static void
3119 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3121 close(scr->helper_fd);
3122 scr->helper_fd = 0;
3123 scr->helper_pid = 0;
3124 scr->flags.backimage_helper_launched = 0;
3128 static int
3129 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3130 void *bar)
3132 int i;
3133 proplist_t val;
3134 char *str;
3136 if (scr->flags.backimage_helper_launched) {
3137 if (PLGetNumberOfElements(value)==0) {
3138 SendHelperMessage(scr, 'C', 0, NULL);
3139 SendHelperMessage(scr, 'K', 0, NULL);
3141 PLRelease(value);
3142 return 0;
3144 } else {
3145 pid_t pid;
3146 int filedes[2];
3148 if (PLGetNumberOfElements(value) == 0)
3149 return 0;
3151 if (pipe(filedes) < 0) {
3152 wsyserror("pipe() failed:can't set workspace specific background image");
3154 PLRelease(value);
3155 return 0;
3158 pid = fork();
3159 if (pid < 0) {
3160 wsyserror("fork() failed:can't set workspace specific background image");
3161 if (close(filedes[0]) < 0)
3162 wsyserror("could not close pipe");
3163 if (close(filedes[1]) < 0)
3164 wsyserror("could not close pipe");
3166 } else if (pid == 0) {
3167 char *dither;
3169 SetupEnvironment(scr);
3171 if (close(0) < 0)
3172 wsyserror("could not close pipe");
3173 if (dup(filedes[0]) < 0) {
3174 wsyserror("dup() failed:can't set workspace specific background image");
3176 dither = wPreferences.no_dithering ? "-m" : "-d";
3177 if (wPreferences.smooth_workspace_back)
3178 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3179 else
3180 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3181 wsyserror("could not execute wmsetbg");
3182 exit(1);
3183 } else {
3185 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3186 wsyserror("error setting close-on-exec flag");
3188 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3189 wsyserror("error setting close-on-exec flag");
3192 scr->helper_fd = filedes[1];
3193 scr->helper_pid = pid;
3194 scr->flags.backimage_helper_launched = 1;
3196 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3198 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3203 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3204 val = PLGetArrayElement(value, i);
3205 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3206 str = PLGetDescription(val);
3208 SendHelperMessage(scr, 'S', i+1, str);
3210 wfree(str);
3211 } else {
3212 SendHelperMessage(scr, 'U', i+1, NULL);
3215 sleep(1);
3217 PLRelease(value);
3218 return 0;
3222 static int
3223 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3224 void *bar)
3226 if (scr->flags.backimage_helper_launched) {
3227 char *str;
3229 if (PLGetNumberOfElements(value)==0) {
3230 SendHelperMessage(scr, 'U', 0, NULL);
3231 } else {
3232 /* set the default workspace background to this one */
3233 str = PLGetDescription(value);
3234 if (str) {
3235 SendHelperMessage(scr, 'S', 0, str);
3236 wfree(str);
3237 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3238 } else {
3239 SendHelperMessage(scr, 'U', 0, NULL);
3242 } else if (PLGetNumberOfElements(value) > 0) {
3243 char *command;
3244 char *text;
3245 char *dither;
3246 int len;
3248 SetupEnvironment(scr);
3249 text = PLGetDescription(value);
3250 len = strlen(text)+40;
3251 command = wmalloc(len);
3252 dither = wPreferences.no_dithering ? "-m" : "-d";
3253 if (wPreferences.smooth_workspace_back)
3254 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3255 else
3256 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3257 wfree(text);
3258 system(command);
3259 wfree(command);
3261 PLRelease(value);
3263 return 0;
3267 static int
3268 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3270 if (scr->widget_texture) {
3271 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3273 scr->widget_texture = *(WTexSolid**)texture;
3275 return 0;
3279 static int
3280 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3282 if (scr->window_title_texture[WS_FOCUSED]) {
3283 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3285 scr->window_title_texture[WS_FOCUSED] = *texture;
3287 return REFRESH_WINDOW_TEXTURES;
3291 static int
3292 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3294 if (scr->window_title_texture[WS_PFOCUSED]) {
3295 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3297 scr->window_title_texture[WS_PFOCUSED] = *texture;
3299 return REFRESH_WINDOW_TEXTURES;
3303 static int
3304 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3306 if (scr->window_title_texture[WS_UNFOCUSED]) {
3307 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3309 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3311 return REFRESH_WINDOW_TEXTURES;
3315 static int
3316 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3318 if (scr->resizebar_texture[0]) {
3319 wTextureDestroy(scr, scr->resizebar_texture[0]);
3321 scr->resizebar_texture[0] = *texture;
3323 return REFRESH_WINDOW_TEXTURES;
3327 static int
3328 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3330 if (scr->menu_title_texture[0]) {
3331 wTextureDestroy(scr, scr->menu_title_texture[0]);
3333 scr->menu_title_texture[0] = *texture;
3335 return REFRESH_MENU_TITLE_TEXTURE;
3339 static int
3340 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3342 if (scr->menu_item_texture) {
3343 wTextureDestroy(scr, scr->menu_item_texture);
3344 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3346 scr->menu_item_texture = *texture;
3348 scr->menu_item_auxtexture
3349 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3351 return REFRESH_MENU_TEXTURE;
3355 static int
3356 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3358 WWindow *wwin;
3359 wKeyBindings[index] = *shortcut;
3361 wwin = scr->focused_window;
3363 while (wwin!=NULL) {
3364 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3366 if (!WFLAGP(wwin, no_bind_keys)) {
3367 wWindowSetKeyGrabs(wwin);
3369 wwin = wwin->prev;
3372 return 0;
3376 static int
3377 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3379 wArrangeIcons(scr, True);
3381 return 0;
3385 static int
3386 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3388 wScreenUpdateUsableArea(scr);
3390 return 0;
3394 static int
3395 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3397 return REFRESH_MENU_TEXTURE;
3402 static int
3403 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3405 return REFRESH_BUTTON_IMAGES;
3410 * Very ugly kluge.
3411 * Need access to the double click variables, so that all widgets in
3412 * wmaker panels will have the same dbl-click values.
3413 * TODO: figure a better way of dealing with it.
3415 #include <WINGs/WINGsP.h>
3417 static int
3418 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3420 extern _WINGsConfiguration WINGsConfiguration;
3422 if (*value <= 0)
3423 *(int*)foo = 1;
3425 WINGsConfiguration.doubleClickDelay = *value;
3427 return 0;
3431 #if 0
3432 static int
3433 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3435 extern _WINGsConfiguration WINGsConfiguration;
3437 WINGsConfiguration.useMultiByte = *value;
3439 return 0;
3441 #endif
3443 #ifdef DEFINABLE_CURSOR
3444 static int
3445 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3447 if (None != wCursor[index])
3449 XFreeCursor(dpy, wCursor[index]);
3452 wCursor[index] = *cursor;
3454 if ((WCUR_ROOT == index) && (None != *cursor))
3456 XDefineCursor(dpy, scr->root_win, *cursor);
3459 return 0;
3461 #endif /* DEFINABLE_CURSOR*/