a small update
[wmaker-crm.git] / src / defaults.c
blob1e529aec88a43a7b504fd3bce9094ed998078c27
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 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 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
706 NULL, getKeybind, setKeyGrab
708 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
709 NULL, getKeybind, setKeyGrab
711 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
712 NULL, getKeybind, setKeyGrab
714 {"ShadeKey", "None", (void*)WKBD_SHADE,
715 NULL, getKeybind, setKeyGrab
717 {"SelectKey", "None", (void*)WKBD_SELECT,
718 NULL, getKeybind, setKeyGrab
720 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
721 NULL, getKeybind, setKeyGrab
723 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
724 NULL, getKeybind, setKeyGrab
726 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
727 NULL, getKeybind, setKeyGrab
729 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
730 NULL, getKeybind, setKeyGrab
732 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
733 NULL, getKeybind, setKeyGrab
735 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
736 NULL, getKeybind, setKeyGrab
738 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
739 NULL, getKeybind, setKeyGrab
741 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
742 NULL, getKeybind, setKeyGrab
744 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
745 NULL, getKeybind, setKeyGrab
747 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
760 NULL, getKeybind, setKeyGrab
762 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
763 NULL, getKeybind, setKeyGrab
765 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
766 NULL, getKeybind, setKeyGrab
768 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
769 NULL, getKeybind, setKeyGrab
771 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
772 NULL, getKeybind, setKeyGrab
774 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
775 NULL, getKeybind, setKeyGrab
777 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
778 NULL, getKeybind, setKeyGrab
780 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
781 NULL, getKeybind, setKeyGrab
783 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
784 NULL, getKeybind, setKeyGrab
786 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
787 NULL, getKeybind, setKeyGrab
789 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
790 NULL, getKeybind, setKeyGrab
792 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
793 NULL, getKeybind, setKeyGrab
795 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
796 NULL, getKeybind, setKeyGrab
798 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
799 NULL, getKeybind, setKeyGrab
802 #ifdef KEEP_XKB_LOCK_STATUS
803 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
804 NULL, getKeybind, setKeyGrab
806 {"KbdModeLock", "NO", NULL,
807 &wPreferences.modelock, getBool, NULL
809 #endif /* KEEP_XKB_LOCK_STATUS */
810 #ifdef DEFINABLE_CURSOR
811 ,{"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
812 NULL, getCursor, setCursor
814 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
815 NULL, getCursor, setCursor
817 #if 0
818 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
819 NULL, getCursor, setCursor
821 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
822 NULL, getCursor, setCursor
824 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
825 NULL, getCursor, setCursor
827 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
828 NULL, getCursor, setCursor
830 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
831 NULL, getCursor, setCursor
833 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
834 NULL, getCursor, setCursor
836 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
837 NULL, getCursor, setCursor
839 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
840 NULL, getCursor, setCursor
842 #endif
843 #endif /* DEFINABLE_CURSOR */
847 #if 0
848 static void rereadDefaults(void);
849 #endif
851 #if 0
852 static void
853 rereadDefaults(void)
855 /* must defer the update because accessing X data from a
856 * signal handler can mess up Xlib */
859 #endif
861 static void
862 initDefaults()
864 int i;
865 WDefaultEntry *entry;
867 PLSetStringCmpHook(StringCompareHook);
869 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
870 entry = &optionList[i];
872 entry->plkey = PLMakeString(entry->key);
873 if (entry->default_value)
874 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
875 else
876 entry->plvalue = NULL;
879 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
880 entry = &staticOptionList[i];
882 entry->plkey = PLMakeString(entry->key);
883 if (entry->default_value)
884 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
885 else
886 entry->plvalue = NULL;
890 wDomainName = PLMakeString(WMDOMAIN_NAME);
891 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
893 PLRegister(wDomainName, rereadDefaults);
894 PLRegister(wAttributeDomainName, rereadDefaults);
901 #if 0
902 proplist_t
903 wDefaultsInit(int screen_number)
905 static int defaults_inited = 0;
906 proplist_t dict;
908 if (!defaults_inited) {
909 initDefaults();
912 dict = PLGetDomain(wDomainName);
913 if (!dict) {
914 wwarning(_("could not read domain \"%s\" from defaults database"),
915 PLGetString(wDomainName));
918 return dict;
920 #endif
923 void
924 wDefaultsDestroyDomain(WDDomain *domain)
926 if (domain->dictionary)
927 PLRelease(domain->dictionary);
928 wfree(domain->path);
929 wfree(domain);
933 WDDomain*
934 wDefaultsInitDomain(char *domain, Bool requireDictionary)
936 WDDomain *db;
937 struct stat stbuf;
938 static int inited = 0;
939 char path[PATH_MAX];
940 char *the_path;
941 proplist_t shared_dict=NULL;
943 if (!inited) {
944 inited = 1;
945 initDefaults();
948 db = wmalloc(sizeof(WDDomain));
949 memset(db, 0, sizeof(WDDomain));
950 db->domain_name = domain;
951 db->path = wdefaultspathfordomain(domain);
952 the_path = db->path;
954 if (the_path && stat(the_path, &stbuf)>=0) {
955 db->dictionary = ReadProplistFromFile(the_path);
956 if (db->dictionary) {
957 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
958 PLRelease(db->dictionary);
959 db->dictionary = NULL;
960 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
961 domain, the_path);
963 db->timestamp = stbuf.st_mtime;
964 } else {
965 wwarning(_("could not load domain %s from user defaults database"),
966 domain);
970 /* global system dictionary */
971 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
972 if (stat(path, &stbuf)>=0) {
973 shared_dict = ReadProplistFromFile(path);
974 if (shared_dict) {
975 if (requireDictionary && !PLIsDictionary(shared_dict)) {
976 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
977 domain, path);
978 PLRelease(shared_dict);
979 shared_dict = NULL;
980 } else {
981 if (db->dictionary && PLIsDictionary(shared_dict) &&
982 PLIsDictionary(db->dictionary)) {
983 PLMergeDictionaries(shared_dict, db->dictionary);
984 PLRelease(db->dictionary);
985 db->dictionary = shared_dict;
986 if (stbuf.st_mtime > db->timestamp)
987 db->timestamp = stbuf.st_mtime;
988 } else if (!db->dictionary) {
989 db->dictionary = shared_dict;
990 if (stbuf.st_mtime > db->timestamp)
991 db->timestamp = stbuf.st_mtime;
994 } else {
995 wwarning(_("could not load domain %s from global defaults database (%s)"),
996 domain, path);
1000 /* set to save it in user's directory, no matter from where it was read */
1001 if (db->dictionary) {
1002 proplist_t tmp = PLMakeString(db->path);
1004 PLSetFilename(db->dictionary, tmp);
1005 PLRelease(tmp);
1008 return db;
1012 void
1013 wReadStaticDefaults(proplist_t dict)
1015 proplist_t plvalue;
1016 WDefaultEntry *entry;
1017 int i;
1018 void *tdata;
1021 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1022 entry = &staticOptionList[i];
1024 if (dict)
1025 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1026 else
1027 plvalue = NULL;
1029 if (!plvalue) {
1030 /* no default in the DB. Use builtin default */
1031 plvalue = entry->plvalue;
1034 if (plvalue) {
1035 /* convert data */
1036 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1037 if (entry->update) {
1038 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1045 void
1046 wDefaultsCheckDomains(void *foo)
1048 WScreen *scr;
1049 struct stat stbuf;
1050 proplist_t dict;
1051 int i;
1052 char path[PATH_MAX];
1054 #ifdef HEARTBEAT
1055 puts("Checking domains...");
1056 #endif
1057 if (stat(WDWindowMaker->path, &stbuf)>=0
1058 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1059 proplist_t shared_dict = NULL;
1060 #ifdef HEARTBEAT
1061 puts("Checking WindowMaker domain");
1062 #endif
1063 WDWindowMaker->timestamp = stbuf.st_mtime;
1065 /* global dictionary */
1066 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1067 if (stat(path, &stbuf)>=0) {
1068 shared_dict = ReadProplistFromFile(path);
1069 if (shared_dict && !PLIsDictionary(shared_dict)) {
1070 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1071 "WindowMaker", path);
1072 PLRelease(shared_dict);
1073 shared_dict = NULL;
1074 } else if (!shared_dict) {
1075 wwarning(_("could not load domain %s from global defaults database"),
1076 "WindowMaker");
1079 /* user dictionary */
1080 dict = ReadProplistFromFile(WDWindowMaker->path);
1081 if (dict) {
1082 if (!PLIsDictionary(dict)) {
1083 PLRelease(dict);
1084 dict = NULL;
1085 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1086 "WindowMaker", WDWindowMaker->path);
1087 } else {
1088 if (shared_dict) {
1089 PLSetFilename(shared_dict, PLGetFilename(dict));
1090 PLMergeDictionaries(shared_dict, dict);
1091 PLRelease(dict);
1092 dict = shared_dict;
1093 shared_dict = NULL;
1095 for (i=0; i<wScreenCount; i++) {
1096 scr = wScreenWithNumber(i);
1097 if (scr)
1098 wReadDefaults(scr, dict);
1100 if (WDWindowMaker->dictionary) {
1101 PLRelease(WDWindowMaker->dictionary);
1103 WDWindowMaker->dictionary = dict;
1105 } else {
1106 wwarning(_("could not load domain %s from user defaults database"),
1107 "WindowMaker");
1109 if (shared_dict) {
1110 PLRelease(shared_dict);
1114 if (stat(WDWindowAttributes->path, &stbuf)>=0
1115 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1116 #ifdef HEARTBEAT
1117 puts("Checking WMWindowAttributes domain");
1118 #endif
1119 dict = ReadProplistFromFile(WDWindowAttributes->path);
1120 if (dict) {
1121 if (!PLIsDictionary(dict)) {
1122 PLRelease(dict);
1123 dict = NULL;
1124 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1125 "WMWindowAttributes", WDWindowAttributes->path);
1126 } else {
1127 if (WDWindowAttributes->dictionary)
1128 PLRelease(WDWindowAttributes->dictionary);
1129 WDWindowAttributes->dictionary = dict;
1130 for (i=0; i<wScreenCount; i++) {
1131 scr = wScreenWithNumber(i);
1132 if (scr) {
1133 RImage *image;
1135 wDefaultUpdateIcons(scr);
1137 /* Update the panel image if changed */
1138 /* Don't worry. If the image is the same these
1139 * functions will have no performance impact. */
1140 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1142 if (!image) {
1143 wwarning(_("could not load logo image for panels: %s"),
1144 RMessageForError(RErrorCode));
1145 } else {
1146 WMSetApplicationIconImage(scr->wmscreen, image);
1147 RReleaseImage(image);
1152 } else {
1153 wwarning(_("could not load domain %s from user defaults database"),
1154 "WMWindowAttributes");
1156 WDWindowAttributes->timestamp = stbuf.st_mtime;
1159 #ifndef LITE
1160 if (stat(WDRootMenu->path, &stbuf)>=0
1161 && WDRootMenu->timestamp < stbuf.st_mtime) {
1162 dict = ReadProplistFromFile(WDRootMenu->path);
1163 #ifdef HEARTBEAT
1164 puts("Checking WMRootMenu domain");
1165 #endif
1166 if (dict) {
1167 if (!PLIsArray(dict) && !PLIsString(dict)) {
1168 PLRelease(dict);
1169 dict = NULL;
1170 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1171 "WMRootMenu", WDRootMenu->path);
1172 } else {
1173 if (WDRootMenu->dictionary) {
1174 PLRelease(WDRootMenu->dictionary);
1176 WDRootMenu->dictionary = dict;
1178 } else {
1179 wwarning(_("could not load domain %s from user defaults database"),
1180 "WMRootMenu");
1182 WDRootMenu->timestamp = stbuf.st_mtime;
1184 #endif /* !LITE */
1186 if (!foo)
1187 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1191 void
1192 wReadDefaults(WScreen *scr, proplist_t new_dict)
1194 proplist_t plvalue, old_value;
1195 WDefaultEntry *entry;
1196 int i, must_update;
1197 int update_workspace_back = 0; /* kluge :/ */
1198 int needs_refresh;
1199 void *tdata;
1200 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1201 ? WDWindowMaker->dictionary : NULL);
1203 must_update = 0;
1205 needs_refresh = 0;
1207 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1208 entry = &optionList[i];
1210 if (new_dict)
1211 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1212 else
1213 plvalue = NULL;
1215 if (!old_dict)
1216 old_value = NULL;
1217 else
1218 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1221 if (!plvalue && !old_value) {
1222 /* no default in the DB. Use builtin default */
1223 plvalue = entry->plvalue;
1224 if (plvalue && new_dict) {
1225 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1226 must_update = 1;
1228 } else if (!plvalue) {
1229 /* value was deleted from DB. Keep current value */
1230 continue;
1231 } else if (!old_value) {
1232 /* set value for the 1st time */
1233 } else if (!PLIsEqual(plvalue, old_value)) {
1234 /* value has changed */
1235 } else {
1237 if (strcmp(entry->key, "WorkspaceBack") == 0
1238 && update_workspace_back
1239 && scr->flags.backimage_helper_launched) {
1240 } else {
1241 /* value was not changed since last time */
1242 continue;
1246 if (plvalue) {
1247 #ifdef DEBUG
1248 printf("Updating %s to %s\n", entry->key,
1249 PLGetDescription(plvalue));
1250 #endif
1251 /* convert data */
1252 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1254 * If the WorkspaceSpecificBack data has been changed
1255 * so that the helper will be launched now, we must be
1256 * sure to send the default background texture config
1257 * to the helper.
1259 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1260 && !scr->flags.backimage_helper_launched) {
1261 update_workspace_back = 1;
1263 if (entry->update) {
1264 needs_refresh |=
1265 (*entry->update)(scr, entry, tdata, entry->extra_data);
1271 if (needs_refresh!=0 && !scr->flags.startup) {
1272 int foo;
1274 foo = 0;
1275 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1276 foo |= WTextureSettings;
1277 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1278 foo |= WFontSettings;
1279 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1280 foo |= WColorSettings;
1281 if (foo)
1282 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1283 (void*)foo);
1285 foo = 0;
1286 if (needs_refresh & REFRESH_MENU_TEXTURE)
1287 foo |= WTextureSettings;
1288 if (needs_refresh & REFRESH_MENU_FONT)
1289 foo |= WFontSettings;
1290 if (needs_refresh & REFRESH_MENU_COLOR)
1291 foo |= WColorSettings;
1292 if (foo)
1293 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1294 (void*)foo);
1296 foo = 0;
1297 if (needs_refresh & REFRESH_WINDOW_FONT) {
1298 foo |= WFontSettings;
1300 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1301 foo |= WTextureSettings;
1303 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1304 foo |= WColorSettings;
1306 if (foo)
1307 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1308 (void*)foo);
1310 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1311 foo = 0;
1312 if (needs_refresh & REFRESH_ICON_FONT) {
1313 foo |= WFontSettings;
1315 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1316 foo |= WTextureSettings;
1318 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1319 foo |= WTextureSettings;
1321 if (foo)
1322 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1323 (void*)foo);
1325 if (needs_refresh & REFRESH_ICON_TILE)
1326 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1331 void
1332 wDefaultUpdateIcons(WScreen *scr)
1334 WAppIcon *aicon = scr->app_icon_list;
1335 WWindow *wwin = scr->focused_window;
1336 char *file;
1338 while(aicon) {
1339 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1340 False);
1341 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1342 || (file && !aicon->icon->file)) {
1343 RImage *new_image;
1345 if (aicon->icon->file)
1346 wfree(aicon->icon->file);
1347 aicon->icon->file = wstrdup(file);
1349 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1350 aicon->wm_class);
1351 if (new_image) {
1352 wIconChangeImage(aicon->icon, new_image);
1353 wAppIconPaint(aicon);
1356 aicon = aicon->next;
1359 if (!wPreferences.flags.noclip)
1360 wClipIconPaint(scr->clip_icon);
1362 while (wwin) {
1363 if (wwin->icon && wwin->flags.miniaturized) {
1364 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1365 False);
1366 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1367 || (file && !wwin->icon->file)) {
1368 RImage *new_image;
1370 if (wwin->icon->file)
1371 wfree(wwin->icon->file);
1372 wwin->icon->file = wstrdup(file);
1374 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1375 wwin->wm_class);
1376 if (new_image)
1377 wIconChangeImage(wwin->icon, new_image);
1380 wwin = wwin->prev;
1385 /* --------------------------- Local ----------------------- */
1387 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1388 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1389 entry->key, x); \
1390 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1391 var = entry->default_value;\
1392 } else var = PLGetString(value)\
1398 static int
1399 string2index(proplist_t key, proplist_t val, proplist_t def,
1400 WOptionEnumeration *values)
1402 char *str;
1403 WOptionEnumeration *v;
1404 char buffer[TOTAL_VALUES_LENGTH];
1406 if (PLIsString(val) && (str = PLGetString(val))) {
1407 for (v=values; v->string!=NULL; v++) {
1408 if (strcasecmp(v->string, str)==0)
1409 return v->value;
1413 buffer[0] = 0;
1414 for (v=values; v->string!=NULL; v++) {
1415 if (!v->is_alias) {
1416 if (buffer[0]!=0)
1417 strcat(buffer, ", ");
1418 strcat(buffer, v->string);
1421 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1422 PLGetString(key), buffer);
1424 if (def) {
1425 return string2index(key, val, NULL, values);
1428 return -1;
1435 * value - is the value in the defaults DB
1436 * addr - is the address to store the data
1437 * ret - is the address to store a pointer to a temporary buffer. ret
1438 * must not be freed and is used by the set functions
1440 static int
1441 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1442 void **ret)
1444 static char data;
1445 char *val;
1446 int second_pass=0;
1448 GET_STRING_OR_DEFAULT("Boolean", val);
1450 again:
1451 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1452 || strcasecmp(val, "YES")==0) {
1454 data = 1;
1455 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1456 || strcasecmp(val, "NO")==0) {
1457 data = 0;
1458 } else {
1459 int i;
1460 if (sscanf(val, "%i", &i)==1) {
1461 if (i!=0)
1462 data = 1;
1463 else
1464 data = 0;
1465 } else {
1466 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1467 val, entry->key);
1468 if (second_pass==0) {
1469 val = PLGetString(entry->plvalue);
1470 second_pass = 1;
1471 wwarning(_("using default \"%s\" instead"), val);
1472 goto again;
1474 return False;
1478 if (ret)
1479 *ret = &data;
1481 if (addr) {
1482 *(char*)addr = data;
1485 return True;
1489 static int
1490 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1491 void **ret)
1493 static int data;
1494 char *val;
1497 GET_STRING_OR_DEFAULT("Integer", val);
1499 if (sscanf(val, "%i", &data)!=1) {
1500 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1501 val, entry->key);
1502 val = PLGetString(entry->plvalue);
1503 wwarning(_("using default \"%s\" instead"), val);
1504 if (sscanf(val, "%i", &data)!=1) {
1505 return False;
1509 if (ret)
1510 *ret = &data;
1512 if (addr) {
1513 *(int*)addr = data;
1515 return True;
1519 static int
1520 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1521 void **ret)
1523 static WCoord data;
1524 char *val_x, *val_y;
1525 int nelem, changed=0;
1526 proplist_t elem_x, elem_y;
1528 again:
1529 if (!PLIsArray(value)) {
1530 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1531 entry->key, "Coordinate");
1532 if (changed==0) {
1533 value = entry->plvalue;
1534 changed = 1;
1535 wwarning(_("using default \"%s\" instead"), entry->default_value);
1536 goto again;
1538 return False;
1541 nelem = PLGetNumberOfElements(value);
1542 if (nelem != 2) {
1543 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1544 entry->key);
1545 if (changed==0) {
1546 value = entry->plvalue;
1547 changed = 1;
1548 wwarning(_("using default \"%s\" instead"), entry->default_value);
1549 goto again;
1551 return False;
1554 elem_x = PLGetArrayElement(value, 0);
1555 elem_y = PLGetArrayElement(value, 1);
1557 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1558 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1559 entry->key);
1560 if (changed==0) {
1561 value = entry->plvalue;
1562 changed = 1;
1563 wwarning(_("using default \"%s\" instead"), entry->default_value);
1564 goto again;
1566 return False;
1569 val_x = PLGetString(elem_x);
1570 val_y = PLGetString(elem_y);
1572 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1573 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1574 if (changed==0) {
1575 value = entry->plvalue;
1576 changed = 1;
1577 wwarning(_("using default \"%s\" instead"), entry->default_value);
1578 goto again;
1580 return False;
1583 if (data.x < 0)
1584 data.x = 0;
1585 else if (data.x > scr->scr_width/3)
1586 data.x = scr->scr_width/3;
1587 if (data.y < 0)
1588 data.y = 0;
1589 else if (data.y > scr->scr_height/3)
1590 data.y = scr->scr_height/3;
1592 if (ret)
1593 *ret = &data;
1595 if (addr) {
1596 *(WCoord*)addr = data;
1599 return True;
1603 #if 0
1604 /* This function is not used at the moment. */
1605 static int
1606 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1607 void **ret)
1609 static char *data;
1611 GET_STRING_OR_DEFAULT("String", data);
1613 if (!data) {
1614 data = PLGetString(entry->plvalue);
1615 if (!data)
1616 return False;
1619 if (ret)
1620 *ret = &data;
1622 if (addr)
1623 *(char**)addr = wstrdup(data);
1625 return True;
1627 #endif
1630 static int
1631 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1632 void **ret)
1634 static char *data;
1635 int i, count, len;
1636 char *ptr;
1637 proplist_t d;
1638 int changed=0;
1640 again:
1641 if (!PLIsArray(value)) {
1642 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1643 entry->key, "an array of paths");
1644 if (changed==0) {
1645 value = entry->plvalue;
1646 changed = 1;
1647 wwarning(_("using default \"%s\" instead"), entry->default_value);
1648 goto again;
1650 return False;
1653 i = 0;
1654 count = PLGetNumberOfElements(value);
1655 if (count < 1) {
1656 if (changed==0) {
1657 value = entry->plvalue;
1658 changed = 1;
1659 wwarning(_("using default \"%s\" instead"), entry->default_value);
1660 goto again;
1662 return False;
1665 len = 0;
1666 for (i=0; i<count; i++) {
1667 d = PLGetArrayElement(value, i);
1668 if (!d || !PLIsString(d)) {
1669 count = i;
1670 break;
1672 len += strlen(PLGetString(d))+1;
1675 ptr = data = wmalloc(len+1);
1677 for (i=0; i<count; i++) {
1678 d = PLGetArrayElement(value, i);
1679 if (!d || !PLIsString(d)) {
1680 break;
1682 strcpy(ptr, PLGetString(d));
1683 ptr += strlen(PLGetString(d));
1684 *ptr = ':';
1685 ptr++;
1687 ptr--; *(ptr--) = 0;
1689 if (*(char**)addr!=NULL) {
1690 wfree(*(char**)addr);
1692 *(char**)addr = data;
1694 return True;
1698 static int
1699 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1700 void **ret)
1702 static signed char data;
1704 data = string2index(entry->plkey, value, entry->default_value,
1705 (WOptionEnumeration*)entry->extra_data);
1706 if (data < 0)
1707 return False;
1709 if (ret)
1710 *ret = &data;
1712 if (addr)
1713 *(signed char*)addr = data;
1715 return True;
1721 * (solid <color>)
1722 * (hgradient <color> <color>)
1723 * (vgradient <color> <color>)
1724 * (dgradient <color> <color>)
1725 * (mhgradient <color> <color> ...)
1726 * (mvgradient <color> <color> ...)
1727 * (mdgradient <color> <color> ...)
1728 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1729 * (tpixmap <file> <color>)
1730 * (spixmap <file> <color>)
1731 * (cpixmap <file> <color>)
1732 * (thgradient <file> <opaqueness> <color> <color>)
1733 * (tvgradient <file> <opaqueness> <color> <color>)
1734 * (tdgradient <file> <opaqueness> <color> <color>)
1735 * (function <lib> <function> ...)
1738 static WTexture*
1739 parse_texture(WScreen *scr, proplist_t pl)
1741 proplist_t elem;
1742 char *val;
1743 int nelem;
1744 WTexture *texture=NULL;
1746 nelem = PLGetNumberOfElements(pl);
1747 if (nelem < 1)
1748 return NULL;
1751 elem = PLGetArrayElement(pl, 0);
1752 if (!elem || !PLIsString(elem))
1753 return NULL;
1754 val = PLGetString(elem);
1757 if (strcasecmp(val, "solid")==0) {
1758 XColor color;
1760 if (nelem != 2)
1761 return NULL;
1763 /* get color */
1765 elem = PLGetArrayElement(pl, 1);
1766 if (!elem || !PLIsString(elem))
1767 return NULL;
1768 val = PLGetString(elem);
1770 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1771 wwarning(_("\"%s\" is not a valid color name"), val);
1772 return NULL;
1775 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1776 } else if (strcasecmp(val, "dgradient")==0
1777 || strcasecmp(val, "vgradient")==0
1778 || strcasecmp(val, "hgradient")==0) {
1779 RColor color1, color2;
1780 XColor xcolor;
1781 int type;
1783 if (nelem != 3) {
1784 wwarning(_("bad number of arguments in gradient specification"));
1785 return NULL;
1788 if (val[0]=='d' || val[0]=='D')
1789 type = WTEX_DGRADIENT;
1790 else if (val[0]=='h' || val[0]=='H')
1791 type = WTEX_HGRADIENT;
1792 else
1793 type = WTEX_VGRADIENT;
1796 /* get from color */
1797 elem = PLGetArrayElement(pl, 1);
1798 if (!elem || !PLIsString(elem))
1799 return NULL;
1800 val = PLGetString(elem);
1802 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1803 wwarning(_("\"%s\" is not a valid color name"), val);
1804 return NULL;
1806 color1.alpha = 255;
1807 color1.red = xcolor.red >> 8;
1808 color1.green = xcolor.green >> 8;
1809 color1.blue = xcolor.blue >> 8;
1811 /* get to color */
1812 elem = PLGetArrayElement(pl, 2);
1813 if (!elem || !PLIsString(elem)) {
1814 return NULL;
1816 val = PLGetString(elem);
1818 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1819 wwarning(_("\"%s\" is not a valid color name"), val);
1820 return NULL;
1822 color2.alpha = 255;
1823 color2.red = xcolor.red >> 8;
1824 color2.green = xcolor.green >> 8;
1825 color2.blue = xcolor.blue >> 8;
1827 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1829 } else if (strcasecmp(val, "igradient")==0) {
1830 RColor colors1[2], colors2[2];
1831 int th1, th2;
1832 XColor xcolor;
1833 int i;
1835 if (nelem != 7) {
1836 wwarning(_("bad number of arguments in gradient specification"));
1837 return NULL;
1840 /* get from color */
1841 for (i = 0; i < 2; i++) {
1842 elem = PLGetArrayElement(pl, 1+i);
1843 if (!elem || !PLIsString(elem))
1844 return NULL;
1845 val = PLGetString(elem);
1847 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1848 wwarning(_("\"%s\" is not a valid color name"), val);
1849 return NULL;
1851 colors1[i].alpha = 255;
1852 colors1[i].red = xcolor.red >> 8;
1853 colors1[i].green = xcolor.green >> 8;
1854 colors1[i].blue = xcolor.blue >> 8;
1856 elem = PLGetArrayElement(pl, 3);
1857 if (!elem || !PLIsString(elem))
1858 return NULL;
1859 val = PLGetString(elem);
1860 th1 = atoi(val);
1863 /* get from color */
1864 for (i = 0; i < 2; i++) {
1865 elem = PLGetArrayElement(pl, 4+i);
1866 if (!elem || !PLIsString(elem))
1867 return NULL;
1868 val = PLGetString(elem);
1870 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1871 wwarning(_("\"%s\" is not a valid color name"), val);
1872 return NULL;
1874 colors2[i].alpha = 255;
1875 colors2[i].red = xcolor.red >> 8;
1876 colors2[i].green = xcolor.green >> 8;
1877 colors2[i].blue = xcolor.blue >> 8;
1879 elem = PLGetArrayElement(pl, 6);
1880 if (!elem || !PLIsString(elem))
1881 return NULL;
1882 val = PLGetString(elem);
1883 th2 = atoi(val);
1885 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1886 th2, colors2);
1888 } else if (strcasecmp(val, "mhgradient")==0
1889 || strcasecmp(val, "mvgradient")==0
1890 || strcasecmp(val, "mdgradient")==0) {
1891 XColor color;
1892 RColor **colors;
1893 int i, count;
1894 int type;
1896 if (nelem < 3) {
1897 wwarning(_("too few arguments in multicolor gradient specification"));
1898 return NULL;
1901 if (val[1]=='h' || val[1]=='H')
1902 type = WTEX_MHGRADIENT;
1903 else if (val[1]=='v' || val[1]=='V')
1904 type = WTEX_MVGRADIENT;
1905 else
1906 type = WTEX_MDGRADIENT;
1908 count = nelem-1;
1910 colors = wmalloc(sizeof(RColor*)*(count+1));
1912 for (i=0; i<count; i++) {
1913 elem = PLGetArrayElement(pl, i+1);
1914 if (!elem || !PLIsString(elem)) {
1915 for (--i; i>=0; --i) {
1916 wfree(colors[i]);
1918 wfree(colors);
1919 return NULL;
1921 val = PLGetString(elem);
1923 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1924 wwarning(_("\"%s\" is not a valid color name"), val);
1925 for (--i; i>=0; --i) {
1926 wfree(colors[i]);
1928 wfree(colors);
1929 return NULL;
1930 } else {
1931 colors[i] = wmalloc(sizeof(RColor));
1932 colors[i]->red = color.red >> 8;
1933 colors[i]->green = color.green >> 8;
1934 colors[i]->blue = color.blue >> 8;
1937 colors[i] = NULL;
1939 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1940 } else if (strcasecmp(val, "spixmap")==0 ||
1941 strcasecmp(val, "cpixmap")==0 ||
1942 strcasecmp(val, "tpixmap")==0) {
1943 XColor color;
1944 int type;
1946 if (nelem != 3)
1947 return NULL;
1949 if (val[0] == 's' || val[0] == 'S')
1950 type = WTP_SCALE;
1951 else if (val[0] == 'c' || val[0] == 'C')
1952 type = WTP_CENTER;
1953 else
1954 type = WTP_TILE;
1956 /* get color */
1957 elem = PLGetArrayElement(pl, 2);
1958 if (!elem || !PLIsString(elem)) {
1959 return NULL;
1961 val = PLGetString(elem);
1963 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1964 wwarning(_("\"%s\" is not a valid color name"), val);
1965 return NULL;
1968 /* file name */
1969 elem = PLGetArrayElement(pl, 1);
1970 if (!elem || !PLIsString(elem))
1971 return NULL;
1972 val = PLGetString(elem);
1974 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1975 } else if (strcasecmp(val, "thgradient")==0
1976 || strcasecmp(val, "tvgradient")==0
1977 || strcasecmp(val, "tdgradient")==0) {
1978 RColor color1, color2;
1979 XColor xcolor;
1980 int opacity;
1981 int style;
1983 if (val[1]=='h' || val[1]=='H')
1984 style = WTEX_THGRADIENT;
1985 else if (val[1]=='v' || val[1]=='V')
1986 style = WTEX_TVGRADIENT;
1987 else
1988 style = WTEX_TDGRADIENT;
1990 if (nelem != 5) {
1991 wwarning(_("bad number of arguments in textured gradient specification"));
1992 return NULL;
1995 /* get from color */
1996 elem = PLGetArrayElement(pl, 3);
1997 if (!elem || !PLIsString(elem))
1998 return NULL;
1999 val = PLGetString(elem);
2001 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2002 wwarning(_("\"%s\" is not a valid color name"), val);
2003 return NULL;
2005 color1.alpha = 255;
2006 color1.red = xcolor.red >> 8;
2007 color1.green = xcolor.green >> 8;
2008 color1.blue = xcolor.blue >> 8;
2010 /* get to color */
2011 elem = PLGetArrayElement(pl, 4);
2012 if (!elem || !PLIsString(elem)) {
2013 return NULL;
2015 val = PLGetString(elem);
2017 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2018 wwarning(_("\"%s\" is not a valid color name"), val);
2019 return NULL;
2021 color2.alpha = 255;
2022 color2.red = xcolor.red >> 8;
2023 color2.green = xcolor.green >> 8;
2024 color2.blue = xcolor.blue >> 8;
2026 /* get opacity */
2027 elem = PLGetArrayElement(pl, 2);
2028 if (!elem || !PLIsString(elem))
2029 opacity = 128;
2030 else
2031 val = PLGetString(elem);
2033 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2034 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2035 opacity = 128;
2038 /* get file name */
2039 elem = PLGetArrayElement(pl, 1);
2040 if (!elem || !PLIsString(elem))
2041 return NULL;
2042 val = PLGetString(elem);
2044 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2045 val, opacity);
2047 #ifdef TEXTURE_PLUGIN
2048 else if (strcasecmp(val, "function")==0) {
2049 WTexFunction *function;
2050 void (*initFunc) (Display *, Colormap);
2051 char *lib, *func, **argv;
2052 int i, argc;
2054 if (nelem < 3)
2055 return NULL;
2057 /* get the library name */
2058 elem = PLGetArrayElement(pl, 1);
2059 if (!elem || !PLIsString(elem)) {
2060 return NULL;
2062 lib = PLGetString(elem);
2064 /* get the function name */
2065 elem = PLGetArrayElement(pl, 2);
2066 if (!elem || !PLIsString(elem)) {
2067 return NULL;
2069 func = PLGetString(elem);
2071 argc = nelem - 2;
2072 argv = (char **)wmalloc(argc * sizeof(char *));
2074 /* get the parameters */
2075 argv[0] = wstrdup(func);
2076 for (i = 0; i < argc - 1; i++) {
2077 elem = PLGetArrayElement(pl, 3 + i);
2078 if (!elem || !PLIsString(elem)) {
2079 wfree(argv);
2081 return NULL;
2083 argv[i+1] = wstrdup(PLGetString(elem));
2086 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2088 #ifdef HAVE_DLFCN_H
2089 if (function) {
2090 initFunc = dlsym(function->handle, "initWindowMaker");
2091 if (initFunc) {
2092 initFunc(dpy, scr->w_colormap);
2093 } else {
2094 wwarning(_("could not initialize library %s"), lib);
2096 } else {
2097 wwarning(_("could not find function %s::%s"), lib, func);
2099 #endif /* HAVE_DLFCN_H */
2100 texture = (WTexture*)function;
2102 #endif /* TEXTURE_PLUGIN */
2103 else {
2104 wwarning(_("invalid texture type %s"), val);
2105 return NULL;
2107 return texture;
2112 static int
2113 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2114 void **ret)
2116 static WTexture *texture;
2117 int changed=0;
2119 again:
2120 if (!PLIsArray(value)) {
2121 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2122 entry->key, "Texture");
2123 if (changed==0) {
2124 value = entry->plvalue;
2125 changed = 1;
2126 wwarning(_("using default \"%s\" instead"), entry->default_value);
2127 goto again;
2129 return False;
2132 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2133 proplist_t pl;
2135 pl = PLGetArrayElement(value, 0);
2136 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2137 || strcasecmp(PLGetString(pl), "solid")!=0) {
2138 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2139 entry->key, "Solid Texture");
2141 value = entry->plvalue;
2142 changed = 1;
2143 wwarning(_("using default \"%s\" instead"), entry->default_value);
2144 goto again;
2148 texture = parse_texture(scr, value);
2150 if (!texture) {
2151 wwarning(_("Error in texture specification for key \"%s\""),
2152 entry->key);
2153 if (changed==0) {
2154 value = entry->plvalue;
2155 changed = 1;
2156 wwarning(_("using default \"%s\" instead"), entry->default_value);
2157 goto again;
2159 return False;
2162 if (ret)
2163 *ret = &texture;
2165 if (addr)
2166 *(WTexture**)addr = texture;
2168 return True;
2172 static int
2173 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2174 void *addr, void **ret)
2176 proplist_t elem;
2177 int changed = 0;
2178 char *val;
2179 int nelem;
2181 again:
2182 if (!PLIsArray(value)) {
2183 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2184 "WorkspaceBack", "Texture or None");
2185 if (changed==0) {
2186 value = entry->plvalue;
2187 changed = 1;
2188 wwarning(_("using default \"%s\" instead"), entry->default_value);
2189 goto again;
2191 return False;
2194 /* only do basic error checking and verify for None texture */
2196 nelem = PLGetNumberOfElements(value);
2197 if (nelem > 0) {
2198 elem = PLGetArrayElement(value, 0);
2199 if (!elem || !PLIsString(elem)) {
2200 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2201 if (changed==0) {
2202 value = entry->plvalue;
2203 changed = 1;
2204 wwarning(_("using default \"%s\" instead"), entry->default_value);
2205 goto again;
2207 return False;
2209 val = PLGetString(elem);
2211 if (strcasecmp(val, "None")==0)
2212 return True;
2214 *ret = PLRetain(value);
2216 return True;
2220 static int
2221 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2222 void *addr, void **ret)
2224 proplist_t elem;
2225 int nelem;
2226 int changed = 0;
2228 again:
2229 if (!PLIsArray(value)) {
2230 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2231 "WorkspaceSpecificBack", "an array of textures");
2232 if (changed==0) {
2233 value = entry->plvalue;
2234 changed = 1;
2235 wwarning(_("using default \"%s\" instead"), entry->default_value);
2236 goto again;
2238 return False;
2241 /* only do basic error checking and verify for None texture */
2243 nelem = PLGetNumberOfElements(value);
2244 if (nelem > 0) {
2245 while (nelem--) {
2246 elem = PLGetArrayElement(value, nelem);
2247 if (!elem || !PLIsArray(elem)) {
2248 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2249 nelem);
2254 *ret = PLRetain(value);
2256 #ifdef notworking
2258 * Kluge to force wmsetbg helper to set the default background.
2259 * If the WorkspaceSpecificBack is changed once wmaker has started,
2260 * the WorkspaceBack won't be sent to the helper, unless the user
2261 * changes it's value too. So, we must force this by removing the
2262 * value from the defaults DB.
2264 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2265 proplist_t key = PLMakeString("WorkspaceBack");
2267 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2269 PLRelease(key);
2271 #endif
2272 return True;
2276 static int
2277 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2278 void **ret)
2280 static WMFont *font;
2281 char *val;
2283 GET_STRING_OR_DEFAULT("Font", val);
2285 font = WMCreateFont(scr->wmscreen, val);
2286 if (!font)
2287 font = WMCreateFont(scr->wmscreen, "fixed");
2289 if (!font) {
2290 wfatal(_("could not load any usable font!!!"));
2291 exit(1);
2294 if (ret)
2295 *ret = font;
2297 /* can't assign font value outside update function */
2298 wassertrv(addr == NULL, True);
2300 return True;
2304 static int
2305 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2306 void **ret)
2308 static XColor color;
2309 char *val;
2310 int second_pass=0;
2312 GET_STRING_OR_DEFAULT("Color", val);
2315 again:
2316 if (!wGetColor(scr, val, &color)) {
2317 wwarning(_("could not get color for key \"%s\""),
2318 entry->key);
2319 if (second_pass==0) {
2320 val = PLGetString(entry->plvalue);
2321 second_pass = 1;
2322 wwarning(_("using default \"%s\" instead"), val);
2323 goto again;
2325 return False;
2328 if (ret)
2329 *ret = &color;
2331 assert(addr==NULL);
2333 if (addr)
2334 *(unsigned long*)addr = pixel;
2337 return True;
2342 static int
2343 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2344 void **ret)
2346 static WShortKey shortcut;
2347 KeySym ksym;
2348 char *val;
2349 char *k;
2350 char buf[128], *b;
2353 GET_STRING_OR_DEFAULT("Key spec", val);
2355 if (!val || strcasecmp(val, "NONE")==0) {
2356 shortcut.keycode = 0;
2357 shortcut.modifier = 0;
2358 if (ret)
2359 *ret = &shortcut;
2360 return True;
2363 strcpy(buf, val);
2365 b = (char*)buf;
2367 /* get modifiers */
2368 shortcut.modifier = 0;
2369 while ((k = strchr(b, '+'))!=NULL) {
2370 int mod;
2372 *k = 0;
2373 mod = wXModifierFromKey(b);
2374 if (mod<0) {
2375 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2376 return False;
2378 shortcut.modifier |= mod;
2380 b = k+1;
2383 /* get key */
2384 ksym = XStringToKeysym(b);
2386 if (ksym==NoSymbol) {
2387 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2388 val);
2389 return False;
2392 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2393 if (shortcut.keycode==0) {
2394 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2395 return False;
2398 if (ret)
2399 *ret = &shortcut;
2401 return True;
2405 static int
2406 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2407 void **ret)
2409 static unsigned int mask;
2410 char *str;
2412 GET_STRING_OR_DEFAULT("Modifier Key", str);
2414 if (!str)
2415 return False;
2417 mask = wXModifierFromKey(str);
2418 if (mask < 0) {
2419 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2420 mask = 0;
2421 return False;
2424 if (addr)
2425 *(unsigned int*)addr = mask;
2427 if (ret)
2428 *ret = &mask;
2430 return True;
2434 #ifdef NEWSTUFF
2435 static int
2436 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2437 void *addr, void **ret)
2439 unsigned int mask;
2440 char *str;
2441 RImage *image;
2442 int i, n;
2443 int w, h;
2445 GET_STRING_OR_DEFAULT("Image File Path", str);
2446 if (!str)
2447 return False;
2449 image = RLoadImage(scr->rcontext, str, 0);
2450 if (!image) {
2451 wwarning(_("could not load image in option %s: %s"), entry->key,
2452 RMessageForError(RErrorCode));
2453 return False;
2456 if (*(RImage**)addr) {
2457 RReleaseImage(*(RImage**)addr);
2459 if (addr)
2460 *(RImage**)addr = image;
2462 assert(ret == NULL);
2464 if (ret)
2465 *(RImage**)ret = image;
2468 return True;
2470 #endif
2472 #ifdef DEFINABLE_CURSOR
2474 # include <X11/cursorfont.h>
2475 typedef struct
2477 char *name;
2478 int id;
2479 } WCursorLookup;
2481 #define CURSOR_ID_NONE (XC_num_glyphs)
2483 static WCursorLookup cursor_table[] =
2485 { "X_cursor", XC_X_cursor },
2486 { "arrow", XC_arrow },
2487 { "based_arrow_down", XC_based_arrow_down },
2488 { "based_arrow_up", XC_based_arrow_up },
2489 { "boat", XC_boat },
2490 { "bogosity", XC_bogosity },
2491 { "bottom_left_corner", XC_bottom_left_corner },
2492 { "bottom_right_corner", XC_bottom_right_corner },
2493 { "bottom_side", XC_bottom_side },
2494 { "bottom_tee", XC_bottom_tee },
2495 { "box_spiral", XC_box_spiral },
2496 { "center_ptr", XC_center_ptr },
2497 { "circle", XC_circle },
2498 { "clock", XC_clock },
2499 { "coffee_mug", XC_coffee_mug },
2500 { "cross", XC_cross },
2501 { "cross_reverse", XC_cross_reverse },
2502 { "crosshair", XC_crosshair },
2503 { "diamond_cross", XC_diamond_cross },
2504 { "dot", XC_dot },
2505 { "dotbox", XC_dotbox },
2506 { "double_arrow", XC_double_arrow },
2507 { "draft_large", XC_draft_large },
2508 { "draft_small", XC_draft_small },
2509 { "draped_box", XC_draped_box },
2510 { "exchange", XC_exchange },
2511 { "fleur", XC_fleur },
2512 { "gobbler", XC_gobbler },
2513 { "gumby", XC_gumby },
2514 { "hand1", XC_hand1 },
2515 { "hand2", XC_hand2 },
2516 { "heart", XC_heart },
2517 { "icon", XC_icon },
2518 { "iron_cross", XC_iron_cross },
2519 { "left_ptr", XC_left_ptr },
2520 { "left_side", XC_left_side },
2521 { "left_tee", XC_left_tee },
2522 { "leftbutton", XC_leftbutton },
2523 { "ll_angle", XC_ll_angle },
2524 { "lr_angle", XC_lr_angle },
2525 { "man", XC_man },
2526 { "middlebutton", XC_middlebutton },
2527 { "mouse", XC_mouse },
2528 { "pencil", XC_pencil },
2529 { "pirate", XC_pirate },
2530 { "plus", XC_plus },
2531 { "question_arrow", XC_question_arrow },
2532 { "right_ptr", XC_right_ptr },
2533 { "right_side", XC_right_side },
2534 { "right_tee", XC_right_tee },
2535 { "rightbutton", XC_rightbutton },
2536 { "rtl_logo", XC_rtl_logo },
2537 { "sailboat", XC_sailboat },
2538 { "sb_down_arrow", XC_sb_down_arrow },
2539 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2540 { "sb_left_arrow", XC_sb_left_arrow },
2541 { "sb_right_arrow", XC_sb_right_arrow },
2542 { "sb_up_arrow", XC_sb_up_arrow },
2543 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2544 { "shuttle", XC_shuttle },
2545 { "sizing", XC_sizing },
2546 { "spider", XC_spider },
2547 { "spraycan", XC_spraycan },
2548 { "star", XC_star },
2549 { "target", XC_target },
2550 { "tcross", XC_tcross },
2551 { "top_left_arrow", XC_top_left_arrow },
2552 { "top_left_corner", XC_top_left_corner },
2553 { "top_right_corner", XC_top_right_corner },
2554 { "top_side", XC_top_side },
2555 { "top_tee", XC_top_tee },
2556 { "trek", XC_trek },
2557 { "ul_angle", XC_ul_angle },
2558 { "umbrella", XC_umbrella },
2559 { "ur_angle", XC_ur_angle },
2560 { "watch", XC_watch },
2561 { "xterm", XC_xterm },
2562 { NULL, CURSOR_ID_NONE }
2565 static void
2566 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2568 switch(status) {
2569 case BitmapOpenFailed:
2570 wwarning(_("failed to open bitmap file \"%s\""), filename);
2571 break;
2572 case BitmapFileInvalid:
2573 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2574 break;
2575 case BitmapNoMemory:
2576 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2577 break;
2578 case BitmapSuccess:
2579 XFreePixmap(dpy, bitmap);
2580 break;
2585 * (none)
2586 * (builtin, <cursor_name>)
2587 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2589 static int
2590 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2592 proplist_t elem;
2593 char *val;
2594 int nelem;
2595 int status = 0;
2597 nelem = PLGetNumberOfElements(pl);
2598 if (nelem < 1) {
2599 return(status);
2601 elem = PLGetArrayElement(pl, 0);
2602 if (!elem || !PLIsString(elem)) {
2603 return(status);
2605 val = PLGetString(elem);
2607 if (0 == strcasecmp(val, "none")) {
2608 status = 1;
2609 *cursor = None;
2610 } else if (0 == strcasecmp(val, "builtin")) {
2611 int i;
2612 int cursor_id = CURSOR_ID_NONE;
2614 if (2 != nelem) {
2615 wwarning(_("bad number of arguments in cursor specification"));
2616 return(status);
2618 elem = PLGetArrayElement(pl, 1);
2619 if (!elem || !PLIsString(elem)) {
2620 return(status);
2622 val = PLGetString(elem);
2624 for (i = 0; NULL != cursor_table[i].name; i++) {
2625 if (0 == strcasecmp(val, cursor_table[i].name)) {
2626 cursor_id = cursor_table[i].id;
2627 break;
2630 if (CURSOR_ID_NONE == cursor_id) {
2631 wwarning(_("unknown builtin cursor name \"%s\""), val);
2632 } else {
2633 *cursor = XCreateFontCursor(dpy, cursor_id);
2634 status = 1;
2636 } else if (0 == strcasecmp(val, "bitmap")) {
2637 char *bitmap_name;
2638 char *mask_name;
2639 int bitmap_status;
2640 int mask_status;
2641 Pixmap bitmap;
2642 Pixmap mask;
2643 unsigned int w, h;
2644 int x, y;
2645 XColor fg, bg;
2647 if (3 != nelem) {
2648 wwarning(_("bad number of arguments in cursor specification"));
2649 return(status);
2651 elem = PLGetArrayElement(pl, 1);
2652 if (!elem || !PLIsString(elem)) {
2653 return(status);
2655 val = PLGetString(elem);
2656 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2657 if (!bitmap_name) {
2658 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2659 return(status);
2661 elem = PLGetArrayElement(pl, 2);
2662 if (!elem || !PLIsString(elem)) {
2663 wfree(bitmap_name);
2664 return(status);
2666 val = PLGetString(elem);
2667 mask_name = FindImage(wPreferences.pixmap_path, val);
2668 if (!mask_name) {
2669 wfree(bitmap_name);
2670 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2671 return(status);
2673 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2674 &mask, &x, &y);
2675 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2676 &bitmap, &x, &y);
2677 if ((BitmapSuccess == bitmap_status) &&
2678 (BitmapSuccess == mask_status)) {
2679 fg.pixel = scr->black_pixel;
2680 bg.pixel = scr->white_pixel;
2681 XQueryColor(dpy, scr->w_colormap, &fg);
2682 XQueryColor(dpy, scr->w_colormap, &bg);
2683 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2684 status = 1;
2686 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2687 check_bitmap_status(mask_status, mask_name, mask);
2688 wfree(bitmap_name);
2689 wfree(mask_name);
2691 return(status);
2695 static int
2696 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2697 void **ret)
2699 static Cursor cursor;
2700 int status;
2701 int changed = 0;
2703 again:
2704 if (!PLIsArray(value)) {
2705 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2706 entry->key, "cursor specification");
2707 if (!changed) {
2708 value = entry->plvalue;
2709 changed = 1;
2710 wwarning(_("using default \"%s\" instead"), entry->default_value);
2711 goto again;
2713 return(False);
2715 status = parse_cursor(scr, value, &cursor);
2716 if (!status) {
2717 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2718 if (!changed) {
2719 value = entry->plvalue;
2720 changed = 1;
2721 wwarning(_("using default \"%s\" instead"), entry->default_value);
2722 goto again;
2724 return(False);
2726 if (ret) {
2727 *ret = &cursor;
2729 if (addr) {
2730 *(Cursor *)addr = cursor;
2732 return(True);
2734 #undef CURSOR_ID_NONE
2736 #endif /* DEFINABLE_CURSOR */
2739 /* ---------------- value setting functions --------------- */
2740 static int
2741 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2743 return REFRESH_WINDOW_TITLE_COLOR;
2746 static int
2747 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2749 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2752 static int
2753 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2755 switch (which) {
2756 case WM_DOCK:
2757 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2758 break;
2759 case WM_CLIP:
2760 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2761 break;
2762 default:
2763 break;
2765 return 0;
2769 static int
2770 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2772 if (scr->workspaces) {
2773 wWorkspaceForceChange(scr, scr->current_workspace);
2774 wArrangeIcons(scr, False);
2776 return 0;
2779 #if not_used
2780 static int
2781 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2783 if (*value <= 0)
2784 *(int*)foo = 1;
2786 return 0;
2788 #endif
2792 static int
2793 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2795 Pixmap pixmap;
2796 RImage *img;
2797 int reset = 0;
2799 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2800 wPreferences.icon_size,
2801 ((*texture)->any.type & WREL_BORDER_MASK)
2802 ? WREL_ICON : WREL_FLAT);
2803 if (!img) {
2804 wwarning(_("could not render texture for icon background"));
2805 if (!entry->addr)
2806 wTextureDestroy(scr, *texture);
2807 return 0;
2809 RConvertImage(scr->rcontext, img, &pixmap);
2811 if (scr->icon_tile) {
2812 reset = 1;
2813 RReleaseImage(scr->icon_tile);
2814 XFreePixmap(dpy, scr->icon_tile_pixmap);
2817 scr->icon_tile = img;
2820 /* put the icon in the noticeboard hint */
2821 PropSetIconTileHint(scr, img);
2824 if (!wPreferences.flags.noclip) {
2825 if (scr->clip_tile) {
2826 RReleaseImage(scr->clip_tile);
2828 scr->clip_tile = wClipMakeTile(scr, img);
2831 scr->icon_tile_pixmap = pixmap;
2833 if (scr->def_icon_pixmap) {
2834 XFreePixmap(dpy, scr->def_icon_pixmap);
2835 scr->def_icon_pixmap = None;
2837 if (scr->def_ticon_pixmap) {
2838 XFreePixmap(dpy, scr->def_ticon_pixmap);
2839 scr->def_ticon_pixmap = None;
2842 if (scr->icon_back_texture) {
2843 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2845 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2847 if (scr->clip_balloon)
2848 XSetWindowBackground(dpy, scr->clip_balloon,
2849 (*texture)->any.color.pixel);
2852 * Free the texture as nobody else will use it, nor refer to it.
2854 if (!entry->addr)
2855 wTextureDestroy(scr, *texture);
2857 return (reset ? REFRESH_ICON_TILE : 0);
2862 static int
2863 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2865 if (scr->title_font) {
2866 WMReleaseFont(scr->title_font);
2868 scr->title_font = font;
2870 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2874 static int
2875 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2877 if (scr->menu_title_font) {
2878 WMReleaseFont(scr->menu_title_font);
2881 scr->menu_title_font = font;
2883 return REFRESH_MENU_TITLE_FONT;
2887 static int
2888 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2890 if (scr->menu_entry_font) {
2891 WMReleaseFont(scr->menu_entry_font);
2893 scr->menu_entry_font = font;
2895 return REFRESH_MENU_FONT;
2900 static int
2901 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2903 if (scr->icon_title_font) {
2904 WMReleaseFont(scr->icon_title_font);
2907 scr->icon_title_font = font;
2909 return REFRESH_ICON_FONT;
2913 static int
2914 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2916 if (scr->clip_title_font) {
2917 WMReleaseFont(scr->clip_title_font);
2920 scr->clip_title_font = font;
2922 return REFRESH_ICON_FONT;
2926 static int
2927 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2929 if (scr->workspace_name_font) {
2930 WMReleaseFont(scr->workspace_name_font);
2933 scr->workspace_name_font = font;
2935 return 0;
2939 static int
2940 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2942 if (scr->select_pixel!=scr->white_pixel &&
2943 scr->select_pixel!=scr->black_pixel) {
2944 wFreeColor(scr, scr->select_pixel);
2947 scr->select_pixel = color->pixel;
2949 return REFRESH_MENU_COLOR;
2953 static int
2954 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2956 if (scr->select_text_pixel!=scr->white_pixel &&
2957 scr->select_text_pixel!=scr->black_pixel) {
2958 wFreeColor(scr, scr->select_text_pixel);
2961 scr->select_text_pixel = color->pixel;
2963 return REFRESH_MENU_COLOR;
2967 static int
2968 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2970 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2971 scr->clip_title_pixel[index]!=scr->black_pixel) {
2972 wFreeColor(scr, scr->clip_title_pixel[index]);
2974 scr->clip_title_pixel[index] = color->pixel;
2976 #ifdef GRADIENT_CLIP_ARROW
2977 if (index == CLIP_NORMAL) {
2978 RImage *image;
2979 RColor color1, color2;
2980 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2981 int as = pt - 15; /* 15 = 5+5+5 */
2983 FREE_PIXMAP(scr->clip_arrow_gradient);
2985 color1.red = (color->red >> 8)*6/10;
2986 color1.green = (color->green >> 8)*6/10;
2987 color1.blue = (color->blue >> 8)*6/10;
2989 color2.red = WMIN((color->red >> 8)*20/10, 255);
2990 color2.green = WMIN((color->green >> 8)*20/10, 255);
2991 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2993 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2994 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2995 RReleaseImage(image);
2997 #endif /* GRADIENT_CLIP_ARROW */
2999 return REFRESH_ICON_TITLE_COLOR;
3003 static int
3004 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3006 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3007 scr->window_title_pixel[index]!=scr->black_pixel) {
3008 wFreeColor(scr, scr->window_title_pixel[index]);
3011 scr->window_title_pixel[index] = color->pixel;
3013 if (index == WS_UNFOCUSED)
3014 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3016 return REFRESH_WINDOW_TITLE_COLOR;
3020 static int
3021 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3023 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3024 scr->menu_title_pixel[0]!=scr->black_pixel) {
3025 wFreeColor(scr, scr->menu_title_pixel[0]);
3028 scr->menu_title_pixel[0] = color->pixel;
3029 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3031 return REFRESH_MENU_TITLE_COLOR;
3035 static int
3036 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3038 XGCValues gcv;
3039 #define gcm (GCForeground|GCBackground|GCFillStyle)
3041 if (scr->mtext_pixel!=scr->white_pixel &&
3042 scr->mtext_pixel!=scr->black_pixel) {
3043 wFreeColor(scr, scr->mtext_pixel);
3046 scr->mtext_pixel = color->pixel;
3048 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3051 if (scr->dtext_pixel == scr->mtext_pixel) {
3052 gcv.foreground = scr->white_pixel;
3053 gcv.background = scr->black_pixel;
3054 gcv.fill_style = FillStippled;
3055 } else {
3056 gcv.foreground = scr->dtext_pixel;
3057 gcv.fill_style = FillSolid;
3059 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3061 return REFRESH_MENU_COLOR;
3062 #undef gcm
3066 static int
3067 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3069 XGCValues gcv;
3070 #define gcm (GCForeground|GCBackground|GCFillStyle)
3072 if (scr->dtext_pixel!=scr->white_pixel &&
3073 scr->dtext_pixel!=scr->black_pixel) {
3074 wFreeColor(scr, scr->dtext_pixel);
3077 scr->dtext_pixel = color->pixel;
3079 if (scr->dtext_pixel == scr->mtext_pixel) {
3080 gcv.foreground = scr->white_pixel;
3081 gcv.background = scr->black_pixel;
3082 gcv.fill_style = FillStippled;
3083 } else {
3084 gcv.foreground = scr->dtext_pixel;
3085 gcv.fill_style = FillSolid;
3087 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3089 return REFRESH_MENU_COLOR;
3090 #undef gcm
3093 static int
3094 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3096 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3098 return REFRESH_ICON_TITLE_COLOR;
3102 static int
3103 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3105 if (scr->icon_title_texture) {
3106 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3108 XQueryColor (dpy, scr->w_colormap, color);
3109 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3111 return REFRESH_ICON_TITLE_BACK;
3115 static void
3116 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3118 close(scr->helper_fd);
3119 scr->helper_fd = 0;
3120 scr->helper_pid = 0;
3121 scr->flags.backimage_helper_launched = 0;
3125 static int
3126 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3127 void *bar)
3129 int i;
3130 proplist_t val;
3131 char *str;
3133 if (scr->flags.backimage_helper_launched) {
3134 if (PLGetNumberOfElements(value)==0) {
3135 SendHelperMessage(scr, 'C', 0, NULL);
3136 SendHelperMessage(scr, 'K', 0, NULL);
3138 PLRelease(value);
3139 return 0;
3141 } else {
3142 pid_t pid;
3143 int filedes[2];
3145 if (PLGetNumberOfElements(value) == 0)
3146 return 0;
3148 if (pipe(filedes) < 0) {
3149 wsyserror("pipe() failed:can't set workspace specific background image");
3151 PLRelease(value);
3152 return 0;
3155 pid = fork();
3156 if (pid < 0) {
3157 wsyserror("fork() failed:can't set workspace specific background image");
3158 if (close(filedes[0]) < 0)
3159 wsyserror("could not close pipe");
3160 if (close(filedes[1]) < 0)
3161 wsyserror("could not close pipe");
3163 } else if (pid == 0) {
3164 char *dither;
3166 SetupEnvironment(scr);
3168 if (close(0) < 0)
3169 wsyserror("could not close pipe");
3170 if (dup(filedes[0]) < 0) {
3171 wsyserror("dup() failed:can't set workspace specific background image");
3173 dither = wPreferences.no_dithering ? "-m" : "-d";
3174 if (wPreferences.smooth_workspace_back)
3175 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3176 else
3177 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3178 wsyserror("could not execute wmsetbg");
3179 exit(1);
3180 } else {
3182 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3183 wsyserror("error setting close-on-exec flag");
3185 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3186 wsyserror("error setting close-on-exec flag");
3189 scr->helper_fd = filedes[1];
3190 scr->helper_pid = pid;
3191 scr->flags.backimage_helper_launched = 1;
3193 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3195 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3200 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3201 val = PLGetArrayElement(value, i);
3202 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3203 str = PLGetDescription(val);
3205 SendHelperMessage(scr, 'S', i+1, str);
3207 wfree(str);
3208 } else {
3209 SendHelperMessage(scr, 'U', i+1, NULL);
3212 sleep(1);
3214 PLRelease(value);
3215 return 0;
3219 static int
3220 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3221 void *bar)
3223 if (scr->flags.backimage_helper_launched) {
3224 char *str;
3226 if (PLGetNumberOfElements(value)==0) {
3227 SendHelperMessage(scr, 'U', 0, NULL);
3228 } else {
3229 /* set the default workspace background to this one */
3230 str = PLGetDescription(value);
3231 if (str) {
3232 SendHelperMessage(scr, 'S', 0, str);
3233 wfree(str);
3234 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3235 } else {
3236 SendHelperMessage(scr, 'U', 0, NULL);
3239 } else if (PLGetNumberOfElements(value) > 0) {
3240 char *command;
3241 char *text;
3242 char *dither;
3244 SetupEnvironment(scr);
3245 text = PLGetDescription(value);
3246 command = wmalloc(strlen(text)+40);
3247 dither = wPreferences.no_dithering ? "-m" : "-d";
3248 if (wPreferences.smooth_workspace_back)
3249 sprintf(command, "wmsetbg %s -S -p '%s' &", dither, text);
3250 else
3251 sprintf(command, "wmsetbg %s -p '%s' &", dither, text);
3252 wfree(text);
3253 system(command);
3254 wfree(command);
3256 PLRelease(value);
3258 return 0;
3262 static int
3263 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3265 if (scr->widget_texture) {
3266 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3268 scr->widget_texture = *(WTexSolid**)texture;
3270 return 0;
3274 static int
3275 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3277 if (scr->window_title_texture[WS_FOCUSED]) {
3278 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3280 scr->window_title_texture[WS_FOCUSED] = *texture;
3282 return REFRESH_WINDOW_TEXTURES;
3286 static int
3287 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3289 if (scr->window_title_texture[WS_PFOCUSED]) {
3290 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3292 scr->window_title_texture[WS_PFOCUSED] = *texture;
3294 return REFRESH_WINDOW_TEXTURES;
3298 static int
3299 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3301 if (scr->window_title_texture[WS_UNFOCUSED]) {
3302 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3304 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3306 return REFRESH_WINDOW_TEXTURES;
3310 static int
3311 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3313 if (scr->resizebar_texture[0]) {
3314 wTextureDestroy(scr, scr->resizebar_texture[0]);
3316 scr->resizebar_texture[0] = *texture;
3318 return REFRESH_WINDOW_TEXTURES;
3322 static int
3323 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3325 if (scr->menu_title_texture[0]) {
3326 wTextureDestroy(scr, scr->menu_title_texture[0]);
3328 scr->menu_title_texture[0] = *texture;
3330 return REFRESH_MENU_TITLE_TEXTURE;
3334 static int
3335 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3337 if (scr->menu_item_texture) {
3338 wTextureDestroy(scr, scr->menu_item_texture);
3339 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3341 scr->menu_item_texture = *texture;
3343 scr->menu_item_auxtexture
3344 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3346 return REFRESH_MENU_TEXTURE;
3350 static int
3351 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3353 WWindow *wwin;
3354 wKeyBindings[index] = *shortcut;
3356 wwin = scr->focused_window;
3358 while (wwin!=NULL) {
3359 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3361 if (!WFLAGP(wwin, no_bind_keys)) {
3362 wWindowSetKeyGrabs(wwin);
3364 wwin = wwin->prev;
3367 return 0;
3371 static int
3372 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3374 wArrangeIcons(scr, True);
3376 return 0;
3380 static int
3381 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3383 wScreenUpdateUsableArea(scr);
3385 return 0;
3389 static int
3390 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3392 return REFRESH_MENU_TEXTURE;
3397 static int
3398 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3400 return REFRESH_BUTTON_IMAGES;
3405 * Very ugly kluge.
3406 * Need access to the double click variables, so that all widgets in
3407 * wmaker panels will have the same dbl-click values.
3408 * TODO: figure a better way of dealing with it.
3410 #include <WINGs/WINGsP.h>
3412 static int
3413 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3415 extern _WINGsConfiguration WINGsConfiguration;
3417 if (*value <= 0)
3418 *(int*)foo = 1;
3420 WINGsConfiguration.doubleClickDelay = *value;
3422 return 0;
3426 #if 0
3427 static int
3428 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3430 extern _WINGsConfiguration WINGsConfiguration;
3432 WINGsConfiguration.useMultiByte = *value;
3434 return 0;
3436 #endif
3438 #ifdef DEFINABLE_CURSOR
3439 static int
3440 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3442 if (None != wCursor[index])
3444 XFreeCursor(dpy, wCursor[index]);
3447 wCursor[index] = *cursor;
3449 if ((WCUR_ROOT == index) && (None != *cursor))
3451 XDefineCursor(dpy, scr->root_win, *cursor);
3454 return 0;
3456 #endif /* DEFINABLE_CURSOR*/