- improved behaviour for the shared appicon thing.
[wmaker-crm.git] / src / defaults.c
blobc074f98bc534fd8567e66e4f5d7c691a6c370cae
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 /***** Global *****/
76 extern WDDomain *WDWindowMaker;
77 extern WDDomain *WDWindowAttributes;
78 extern WDDomain *WDRootMenu;
80 extern int wScreenCount;
82 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
83 extern Atom _XA_WINDOWMAKER_ICON_TILE;
86 extern WMPropList *wDomainName;
87 extern WMPropList *wAttributeDomainName;
89 extern WPreferences wPreferences;
91 extern WShortKey wKeyBindings[WKBD_LAST];
93 typedef struct {
94 char *key;
95 char *default_value;
96 void *extra_data;
97 void *addr;
98 int (*convert)();
99 int (*update)();
100 WMPropList *plkey;
101 WMPropList *plvalue; /* default value */
102 } WDefaultEntry;
105 /* used to map strings to integers */
106 typedef struct {
107 char *string;
108 short value;
109 char is_alias;
110 } WOptionEnumeration;
113 /* type converters */
114 static int getBool();
115 static int getInt();
116 static int getCoord();
117 #if 0
118 /* this is not used yet */
119 static int getString();
120 #endif
121 static int getPathList();
122 static int getEnum();
123 static int getTexture();
124 static int getWSBackground();
125 static int getWSSpecificBackground();
126 static int getFont();
127 static int getColor();
128 static int getKeybind();
129 static int getModMask();
130 #ifdef NEWSTUFF
131 static int getRImage();
132 #endif
135 /* value setting functions */
136 static int setJustify();
137 static int setClearance();
138 static int setIfDockPresent();
139 static int setStickyIcons();
141 static int setPositive();
143 static int setWidgetColor();
144 static int setIconTile();
145 static int setWinTitleFont();
146 static int setMenuTitleFont();
147 static int setMenuTextFont();
148 static int setIconTitleFont();
149 static int setIconTitleColor();
150 static int setIconTitleBack();
151 static int setLargeDisplayFont();
152 static int setWTitleColor();
153 static int setFTitleBack();
154 static int setPTitleBack();
155 static int setUTitleBack();
156 static int setResizebarBack();
157 static int setWorkspaceBack();
158 static int setWorkspaceSpecificBack();
159 static int setMenuTitleColor();
160 static int setMenuTextColor();
161 static int setMenuDisabledColor();
162 static int setMenuTitleBack();
163 static int setMenuTextBack();
164 static int setHightlight();
165 static int setHightlightText();
166 static int setKeyGrab();
167 static int setDoubleClick();
168 static int setIconPosition();
170 static int setClipTitleFont();
171 static int setClipTitleColor();
173 static int setMenuStyle();
174 #if 0
175 static int setMultiByte();
176 #endif
177 static int updateUsableArea();
179 extern Cursor wCursor[WCUR_LAST];
180 static int getCursor();
181 static int setCursor();
185 * Tables to convert strings to enumeration values.
186 * Values stored are char
190 /* WARNING: sum of length of all value strings must not exceed
191 * this value */
192 #define TOTAL_VALUES_LENGTH 80
197 #define REFRESH_WINDOW_TEXTURES (1<<0)
198 #define REFRESH_MENU_TEXTURE (1<<1)
199 #define REFRESH_MENU_FONT (1<<2)
200 #define REFRESH_MENU_COLOR (1<<3)
201 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
202 #define REFRESH_MENU_TITLE_FONT (1<<5)
203 #define REFRESH_MENU_TITLE_COLOR (1<<6)
204 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
205 #define REFRESH_WINDOW_FONT (1<<8)
206 #define REFRESH_ICON_TILE (1<<9)
207 #define REFRESH_ICON_FONT (1<<10)
208 #define REFRESH_WORKSPACE_BACK (1<<11)
210 #define REFRESH_BUTTON_IMAGES (1<<12)
212 #define REFRESH_ICON_TITLE_COLOR (1<<13)
213 #define REFRESH_ICON_TITLE_BACK (1<<14)
217 static WOptionEnumeration seFocusModes[] = {
218 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
219 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
220 {NULL, 0, 0}
223 static WOptionEnumeration seColormapModes[] = {
224 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
225 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
226 {NULL, 0, 0}
229 static WOptionEnumeration sePlacements[] = {
230 {"Auto", WPM_AUTO, 0},
231 {"Smart", WPM_SMART, 0},
232 {"Cascade", WPM_CASCADE, 0},
233 {"Random", WPM_RANDOM, 0},
234 {"Manual", WPM_MANUAL, 0},
235 {NULL, 0, 0}
238 static WOptionEnumeration seGeomDisplays[] = {
239 {"None", WDIS_NONE, 0},
240 {"Center", WDIS_CENTER, 0},
241 {"Corner", WDIS_TOPLEFT, 0},
242 {"Floating", WDIS_FRAME_CENTER, 0},
243 {"Line", WDIS_NEW, 0},
244 {NULL, 0, 0}
247 static WOptionEnumeration seSpeeds[] = {
248 {"UltraFast", SPEED_ULTRAFAST, 0},
249 {"Fast", SPEED_FAST, 0},
250 {"Medium", SPEED_MEDIUM, 0},
251 {"Slow", SPEED_SLOW, 0},
252 {"UltraSlow", SPEED_ULTRASLOW, 0},
253 {NULL, 0, 0}
256 static WOptionEnumeration seMouseButtonActions[] = {
257 {"None", WA_NONE, 0},
258 {"SelectWindows", WA_SELECT_WINDOWS, 0},
259 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
260 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
261 {NULL, 0, 0}
264 static WOptionEnumeration seMouseWheelActions[] = {
265 {"None", WA_NONE, 0},
266 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
267 {NULL, 0, 0}
270 static WOptionEnumeration seIconificationStyles[] = {
271 {"Zoom", WIS_ZOOM, 0},
272 {"Twist", WIS_TWIST, 0},
273 {"Flip", WIS_FLIP, 0},
274 {"None", WIS_NONE, 0},
275 {"random", WIS_RANDOM, 0},
276 {NULL, 0, 0}
279 static WOptionEnumeration seJustifications[] = {
280 {"Left", WTJ_LEFT, 0},
281 {"Center", WTJ_CENTER, 0},
282 {"Right", WTJ_RIGHT, 0},
283 {NULL, 0, 0}
286 static WOptionEnumeration seIconPositions[] = {
287 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
288 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
289 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
290 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
291 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
292 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
293 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
294 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
295 {NULL, 0, 0}
298 static WOptionEnumeration seMenuStyles[] = {
299 {"normal", MS_NORMAL, 0},
300 {"singletexture", MS_SINGLE_TEXTURE, 0},
301 {"flat", MS_FLAT, 0},
302 {NULL, 0, 0}
306 static WOptionEnumeration seDisplayPositions[] = {
307 {"none", WD_NONE, 0},
308 {"center", WD_CENTER, 0},
309 {"top", WD_TOP, 0},
310 {"bottom", WD_BOTTOM, 0},
311 {"topleft", WD_TOPLEFT, 0},
312 {"topright", WD_TOPRIGHT, 0},
313 {"bottomleft", WD_BOTTOMLEFT, 0},
314 {"bottomright", WD_BOTTOMRIGHT, 0},
315 {NULL, 0, 0}
318 static WOptionEnumeration seWorkspaceBorder[] = {
319 {"None", WB_NONE, 0},
320 {"LeftRight", WB_LEFTRIGHT, 0},
321 {"TopBottom", WB_TOPBOTTOM, 0},
322 {"AllDirections", WB_ALLDIRS, 0},
323 {NULL, 0, 0}
328 * ALL entries in the tables bellow, NEED to have a default value
329 * defined, and this value needs to be correct.
332 /* these options will only affect the window manager on startup
334 * static defaults can't access the screen data, because it is
335 * created after these defaults are read
337 WDefaultEntry staticOptionList[] = {
339 {"ColormapSize", "4", NULL,
340 &wPreferences.cmap_size, getInt, NULL
342 {"DisableDithering", "NO", NULL,
343 &wPreferences.no_dithering, getBool, NULL
345 /* static by laziness */
346 {"IconSize", "64", NULL,
347 &wPreferences.icon_size, getInt, NULL
349 {"ModifierKey", "Mod1", NULL,
350 &wPreferences.modifier_mask, getModMask, NULL
352 {"DisableWSMouseActions", "NO", NULL,
353 &wPreferences.disable_root_mouse, getBool, NULL
355 {"FocusMode", "manual", seFocusModes,
356 &wPreferences.focus_mode, getEnum, NULL
357 }, /* have a problem when switching from manual to sloppy without restart */
358 {"NewStyle", "NO", NULL,
359 &wPreferences.new_style, getBool, NULL
361 {"DisableDock", "NO", (void*) WM_DOCK,
362 NULL, getBool, setIfDockPresent
364 {"DisableClip", "NO", (void*) WM_CLIP,
365 NULL, getBool, setIfDockPresent
367 {"DisableMiniwindows", "NO", NULL,
368 &wPreferences.disable_miniwindows, getBool, NULL
370 #if 0
371 ,{"MultiByteText", "NO", NULL,
372 &wPreferences.multi_byte_text, getBool, setMultiByte
374 #endif
379 WDefaultEntry optionList[] = {
380 /* dynamic options */
381 {"IconPosition", "blh", seIconPositions,
382 &wPreferences.icon_yard, getEnum, setIconPosition
384 {"IconificationStyle", "Zoom", seIconificationStyles,
385 &wPreferences.iconification_style, getEnum, NULL
387 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
388 &wPreferences.mouse_button1, getEnum, NULL
390 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
391 &wPreferences.mouse_button2, getEnum, NULL
393 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
394 &wPreferences.mouse_button3, getEnum, NULL
396 {"MouseWheelAction", "None", seMouseWheelActions,
397 &wPreferences.mouse_wheel, getEnum, NULL
399 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
400 &wPreferences.pixmap_path, getPathList, NULL
402 {"IconPath", DEF_ICON_PATHS, NULL,
403 &wPreferences.icon_path, getPathList, NULL
405 {"ColormapMode", "auto", seColormapModes,
406 &wPreferences.colormap_mode, getEnum, NULL
408 {"AutoFocus", "NO", NULL,
409 &wPreferences.auto_focus, getBool, NULL
411 {"RaiseDelay", "0", NULL,
412 &wPreferences.raise_delay, getInt, NULL
414 {"WindozeCycling", "NO", NULL,
415 &wPreferences.windows_cycling,getBool, NULL
417 {"CirculateRaise", "NO", NULL,
418 &wPreferences.circ_raise, getBool, NULL
420 {"Superfluous", "NO", NULL,
421 &wPreferences.superfluous, getBool, NULL
423 {"AdvanceToNewWorkspace", "NO", NULL,
424 &wPreferences.ws_advance, getBool, NULL
426 {"CycleWorkspaces", "NO", NULL,
427 &wPreferences.ws_cycle, getBool, NULL
429 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
430 &wPreferences.workspace_name_display_position, getEnum, NULL
432 {"WorkspaceBorder", "None", seWorkspaceBorder,
433 &wPreferences.workspace_border_position, getEnum, updateUsableArea
435 {"WorkspaceBorderSize", "0", NULL,
436 &wPreferences.workspace_border_size, getInt, updateUsableArea
438 #ifdef VIRTUAL_DESKTOP
439 {"VirtualEdgeThickness", "1", NULL,
440 &wPreferences.vedge_thickness, getInt, NULL
442 {"VirtualEdgeExtendSpace", "0", NULL,
443 &wPreferences.vedge_bordersize, getInt, NULL
445 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
446 &wPreferences.vedge_hscrollspeed, getInt, NULL
448 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
449 &wPreferences.vedge_vscrollspeed, getInt, NULL
451 {"VirtualEdgeMaximumWidth", "3000", NULL,
452 &wPreferences.vedge_maxwidth, getInt, NULL
454 {"VirtualEdgeMaximumHeight", "3000", NULL,
455 &wPreferences.vedge_maxheight, getInt, NULL
457 #endif
458 {"StickyIcons", "NO", NULL,
459 &wPreferences.sticky_icons, getBool, setStickyIcons
461 {"SaveSessionOnExit", "NO", NULL,
462 &wPreferences.save_session_on_exit, getBool, NULL
464 {"WrapMenus", "NO", NULL,
465 &wPreferences.wrap_menus, getBool, NULL
467 {"ScrollableMenus", "NO", NULL,
468 &wPreferences.scrollable_menus, getBool, NULL
470 {"MenuScrollSpeed", "medium", seSpeeds,
471 &wPreferences.menu_scroll_speed, getEnum, NULL
473 {"IconSlideSpeed", "medium", seSpeeds,
474 &wPreferences.icon_slide_speed, getEnum, NULL
476 {"ShadeSpeed", "medium", seSpeeds,
477 &wPreferences.shade_speed, getEnum, NULL
479 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
480 &wPreferences.dblclick_time, getInt, setDoubleClick,
482 {"AlignSubmenus", "NO", NULL,
483 &wPreferences.align_menus, getBool, NULL
485 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
486 &wPreferences.open_transients_with_parent, getBool, NULL
488 {"WindowPlacement", "auto", sePlacements,
489 &wPreferences.window_placement, getEnum, NULL
491 {"IgnoreFocusClick","NO", NULL,
492 &wPreferences.ignore_focus_click, getBool, NULL
494 {"UseSaveUnders", "NO", NULL,
495 &wPreferences.use_saveunders, getBool, NULL
497 {"OpaqueMove", "NO", NULL,
498 &wPreferences.opaque_move, getBool, NULL
500 {"DisableSound", "NO", NULL,
501 &wPreferences.no_sound, getBool, NULL
503 {"DisableAnimations", "NO", NULL,
504 &wPreferences.no_animations, getBool, NULL
506 {"DontLinkWorkspaces","NO", NULL,
507 &wPreferences.no_autowrap, getBool, NULL
509 {"AutoArrangeIcons", "NO", NULL,
510 &wPreferences.auto_arrange_icons, getBool, NULL
512 {"NoWindowOverDock", "NO", NULL,
513 &wPreferences.no_window_over_dock, getBool, updateUsableArea
515 {"NoWindowOverIcons", "NO", NULL,
516 &wPreferences.no_window_over_icons, getBool, updateUsableArea
518 {"WindowPlaceOrigin", "(0, 0)", NULL,
519 &wPreferences.window_place_origin, getCoord, NULL
521 {"ResizeDisplay", "corner", seGeomDisplays,
522 &wPreferences.size_display, getEnum, NULL
524 {"MoveDisplay", "corner", seGeomDisplays,
525 &wPreferences.move_display, getEnum, NULL
527 {"DontConfirmKill", "NO", NULL,
528 &wPreferences.dont_confirm_kill, getBool,NULL
530 {"WindowTitleBalloons", "NO", NULL,
531 &wPreferences.window_balloon, getBool, NULL
533 {"MiniwindowTitleBalloons", "NO", NULL,
534 &wPreferences.miniwin_balloon,getBool, NULL
536 {"AppIconBalloons", "NO", NULL,
537 &wPreferences.appicon_balloon,getBool, NULL
539 {"HelpBalloons", "NO", NULL,
540 &wPreferences.help_balloon, getBool, NULL
542 {"EdgeResistance", "30", NULL,
543 &wPreferences.edge_resistance,getInt, NULL
545 {"Attraction", "NO", NULL,
546 &wPreferences.attract, getBool, NULL
548 {"DisableBlinking", "NO", NULL,
549 &wPreferences.dont_blink, getBool, NULL
551 /* style options */
552 {"MenuStyle", "normal", seMenuStyles,
553 &wPreferences.menu_style, getEnum, setMenuStyle
555 {"WidgetColor", "(solid, gray)", NULL,
556 NULL, getTexture, setWidgetColor,
558 {"WorkspaceSpecificBack","()", NULL,
559 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
561 /* WorkspaceBack must come after WorkspaceSpecificBack or
562 * WorkspaceBack wont know WorkspaceSpecificBack was also
563 * specified and 2 copies of wmsetbg will be launched */
564 {"WorkspaceBack", "(solid, black)", NULL,
565 NULL, getWSBackground,setWorkspaceBack
567 {"SmoothWorkspaceBack", "NO", NULL,
568 NULL, getBool, NULL
570 {"IconBack", "(solid, gray)", NULL,
571 NULL, getTexture, setIconTile
573 {"TitleJustify", "center", seJustifications,
574 &wPreferences.title_justification, getEnum, setJustify
576 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
577 NULL, getFont, setWinTitleFont,
579 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
580 &wPreferences.window_title_clearance, getInt, setClearance
582 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
583 &wPreferences.menu_title_clearance, getInt, setClearance
585 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
586 &wPreferences.menu_text_clearance, getInt, setClearance
588 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
589 NULL, getFont, setMenuTitleFont
591 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
592 NULL, getFont, setMenuTextFont
594 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
595 NULL, getFont, setIconTitleFont
597 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
598 NULL, getFont, setClipTitleFont
600 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
601 NULL, getFont, setLargeDisplayFont
603 {"HighlightColor", "white", NULL,
604 NULL, getColor, setHightlight
606 {"HighlightTextColor", "black", NULL,
607 NULL, getColor, setHightlightText
609 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
610 NULL, getColor, setClipTitleColor
612 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
613 NULL, getColor, setClipTitleColor
615 {"FTitleColor", "white", (void*)WS_FOCUSED,
616 NULL, getColor, setWTitleColor
618 {"PTitleColor", "white", (void*)WS_PFOCUSED,
619 NULL, getColor, setWTitleColor
621 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
622 NULL, getColor, setWTitleColor
624 {"FTitleBack", "(solid, black)", NULL,
625 NULL, getTexture, setFTitleBack
627 {"PTitleBack", "(solid, \"#616161\")", NULL,
628 NULL, getTexture, setPTitleBack
630 {"UTitleBack", "(solid, gray)", NULL,
631 NULL, getTexture, setUTitleBack
633 {"ResizebarBack", "(solid, gray)", NULL,
634 NULL, getTexture, setResizebarBack
636 {"MenuTitleColor", "white", NULL,
637 NULL, getColor, setMenuTitleColor
639 {"MenuTextColor", "black", NULL,
640 NULL, getColor, setMenuTextColor
642 {"MenuDisabledColor", "\"#616161\"", NULL,
643 NULL, getColor, setMenuDisabledColor
645 {"MenuTitleBack", "(solid, black)", NULL,
646 NULL, getTexture, setMenuTitleBack
648 {"MenuTextBack", "(solid, gray)", NULL,
649 NULL, getTexture, setMenuTextBack
651 {"IconTitleColor", "white", NULL,
652 NULL, getColor, setIconTitleColor
654 {"IconTitleBack", "black", NULL,
655 NULL, getColor, setIconTitleBack
657 /* keybindings */
658 #ifndef LITE
659 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
660 NULL, getKeybind, setKeyGrab
662 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
663 NULL, getKeybind, setKeyGrab
665 #endif /* LITE */
666 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
667 NULL, getKeybind, setKeyGrab
669 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
670 NULL, getKeybind, setKeyGrab
672 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
673 NULL, getKeybind, setKeyGrab
675 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
676 NULL, getKeybind, setKeyGrab
678 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
679 NULL, getKeybind, setKeyGrab
681 {"HideKey", "None", (void*)WKBD_HIDE,
682 NULL, getKeybind, setKeyGrab
684 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
685 NULL, getKeybind, setKeyGrab
687 {"CloseKey", "None", (void*)WKBD_CLOSE,
688 NULL, getKeybind, setKeyGrab
690 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
691 NULL, getKeybind, setKeyGrab
693 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
694 NULL, getKeybind, setKeyGrab
696 {"HMaximizeKey", "None", (void*)WKBD_HMAXIMIZE,
697 NULL, getKeybind, setKeyGrab
699 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
700 NULL, getKeybind, setKeyGrab
702 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
703 NULL, getKeybind, setKeyGrab
705 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
706 NULL, getKeybind, setKeyGrab
708 {"ShadeKey", "None", (void*)WKBD_SHADE,
709 NULL, getKeybind, setKeyGrab
711 {"SelectKey", "None", (void*)WKBD_SELECT,
712 NULL, getKeybind, setKeyGrab
714 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
715 NULL, getKeybind, setKeyGrab
717 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
718 NULL, getKeybind, setKeyGrab
720 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
721 NULL, getKeybind, setKeyGrab
723 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
724 NULL, getKeybind, setKeyGrab
726 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
727 NULL, getKeybind, setKeyGrab
729 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
730 NULL, getKeybind, setKeyGrab
732 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
733 NULL, getKeybind, setKeyGrab
735 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
736 NULL, getKeybind, setKeyGrab
738 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
739 NULL, getKeybind, setKeyGrab
741 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
742 NULL, getKeybind, setKeyGrab
744 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
745 NULL, getKeybind, setKeyGrab
747 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
760 NULL, getKeybind, setKeyGrab
762 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
763 NULL, getKeybind, setKeyGrab
765 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
766 NULL, getKeybind, setKeyGrab
768 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
769 NULL, getKeybind, setKeyGrab
771 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
772 NULL, getKeybind, setKeyGrab
774 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
775 NULL, getKeybind, setKeyGrab
777 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
778 NULL, getKeybind, setKeyGrab
780 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
781 NULL, getKeybind, setKeyGrab
783 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
784 NULL, getKeybind, setKeyGrab
786 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
787 NULL, getKeybind, setKeyGrab
789 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
790 NULL, getKeybind, setKeyGrab
792 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
793 NULL, getKeybind, setKeyGrab
796 #ifdef KEEP_XKB_LOCK_STATUS
797 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
798 NULL, getKeybind, setKeyGrab
800 {"KbdModeLock", "NO", NULL,
801 &wPreferences.modelock, getBool, NULL
803 #endif /* KEEP_XKB_LOCK_STATUS */
805 ,{"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
806 NULL, getCursor, setCursor
808 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
809 NULL, getCursor, setCursor
811 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
812 NULL, getCursor, setCursor
814 {"ResizeCursor", "(builtin, sizing)", (void*)WCUR_RESIZE,
815 NULL, getCursor, setCursor
817 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
818 (void*)WCUR_TOPLEFTRESIZE,
819 NULL, getCursor, setCursor
821 {"TopRightResizeCursor", "(builtin, top_right_corner)",
822 (void*)WCUR_TOPRIGHTRESIZE,
823 NULL, getCursor, setCursor
825 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
826 (void*)WCUR_BOTTOMLEFTRESIZE,
827 NULL, getCursor, setCursor
829 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
830 (void*)WCUR_BOTTOMRIGHTRESIZE,
831 NULL, getCursor, setCursor
833 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
834 (void*)WCUR_VERTICALRESIZE,
835 NULL, getCursor, setCursor
837 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
838 (void*)WCUR_HORIZONRESIZE,
839 NULL, getCursor, setCursor
841 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
842 NULL, getCursor, setCursor
844 {"QuestionCursor", "(builtin, question_arrow)", (void*)WCUR_QUESTION,
845 NULL, getCursor, setCursor
847 {"TextCursor", "(builtin, xterm)", (void*)WCUR_TEXT,
848 NULL, getCursor, setCursor
850 {"SelectCursor", "(builtin, cross)", (void*)WCUR_SELECT,
851 NULL, getCursor, setCursor
856 #if 0
857 static void rereadDefaults(void);
858 #endif
860 #if 0
861 static void
862 rereadDefaults(void)
864 /* must defer the update because accessing X data from a
865 * signal handler can mess up Xlib */
868 #endif
870 static void
871 initDefaults()
873 int i;
874 WDefaultEntry *entry;
876 WMPLSetCaseSensitive(False);
878 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
879 entry = &optionList[i];
881 entry->plkey = WMCreatePLString(entry->key);
882 if (entry->default_value)
883 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
884 else
885 entry->plvalue = NULL;
888 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
889 entry = &staticOptionList[i];
891 entry->plkey = WMCreatePLString(entry->key);
892 if (entry->default_value)
893 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
894 else
895 entry->plvalue = NULL;
899 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
900 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
902 PLRegister(wDomainName, rereadDefaults);
903 PLRegister(wAttributeDomainName, rereadDefaults);
910 #if 0
911 WMPropList*
912 wDefaultsInit(int screen_number)
914 static int defaults_inited = 0;
915 WMPropList *dict;
917 if (!defaults_inited) {
918 initDefaults();
921 dict = PLGetDomain(wDomainName);
922 if (!dict) {
923 wwarning(_("could not read domain \"%s\" from defaults database"),
924 WMGetFromPLString(wDomainName));
927 return dict;
929 #endif
932 void
933 wDefaultsDestroyDomain(WDDomain *domain)
935 if (domain->dictionary)
936 WMReleasePropList(domain->dictionary);
937 wfree(domain->path);
938 wfree(domain);
942 WDDomain*
943 wDefaultsInitDomain(char *domain, Bool requireDictionary)
945 WDDomain *db;
946 struct stat stbuf;
947 static int inited = 0;
948 char path[PATH_MAX];
949 char *the_path;
950 WMPropList *shared_dict=NULL;
952 if (!inited) {
953 inited = 1;
954 initDefaults();
957 db = wmalloc(sizeof(WDDomain));
958 memset(db, 0, sizeof(WDDomain));
959 db->domain_name = domain;
960 db->path = wdefaultspathfordomain(domain);
961 the_path = db->path;
963 if (the_path && stat(the_path, &stbuf)>=0) {
964 db->dictionary = WMReadPropListFromFile(the_path);
965 if (db->dictionary) {
966 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
967 WMReleasePropList(db->dictionary);
968 db->dictionary = NULL;
969 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
970 domain, the_path);
972 db->timestamp = stbuf.st_mtime;
973 } else {
974 wwarning(_("could not load domain %s from user defaults database"),
975 domain);
979 /* global system dictionary */
980 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
981 if (stat(path, &stbuf)>=0) {
982 shared_dict = WMReadPropListFromFile(path);
983 if (shared_dict) {
984 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
985 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
986 domain, path);
987 WMReleasePropList(shared_dict);
988 shared_dict = NULL;
989 } else {
990 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
991 WMIsPLDictionary(db->dictionary)) {
992 WMMergePLDictionaries(shared_dict, db->dictionary, True);
993 WMReleasePropList(db->dictionary);
994 db->dictionary = shared_dict;
995 if (stbuf.st_mtime > db->timestamp)
996 db->timestamp = stbuf.st_mtime;
997 } else if (!db->dictionary) {
998 db->dictionary = shared_dict;
999 if (stbuf.st_mtime > db->timestamp)
1000 db->timestamp = stbuf.st_mtime;
1003 } else {
1004 wwarning(_("could not load domain %s from global defaults database (%s)"),
1005 domain, path);
1009 return db;
1013 void
1014 wReadStaticDefaults(WMPropList *dict)
1016 WMPropList *plvalue;
1017 WDefaultEntry *entry;
1018 int i;
1019 void *tdata;
1022 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1023 entry = &staticOptionList[i];
1025 if (dict)
1026 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
1027 else
1028 plvalue = NULL;
1030 if (!plvalue) {
1031 /* no default in the DB. Use builtin default */
1032 plvalue = entry->plvalue;
1035 if (plvalue) {
1036 /* convert data */
1037 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1038 if (entry->update) {
1039 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1046 void
1047 wDefaultsCheckDomains(void *foo)
1049 WScreen *scr;
1050 struct stat stbuf;
1051 WMPropList *dict;
1052 int i;
1053 char path[PATH_MAX];
1055 #ifdef HEARTBEAT
1056 puts("Checking domains...");
1057 #endif
1058 if (stat(WDWindowMaker->path, &stbuf)>=0
1059 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1060 WMPropList *shared_dict = NULL;
1061 #ifdef HEARTBEAT
1062 puts("Checking WindowMaker domain");
1063 #endif
1064 WDWindowMaker->timestamp = stbuf.st_mtime;
1066 /* global dictionary */
1067 snprintf(path, sizeof(path), "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1068 if (stat(path, &stbuf)>=0) {
1069 shared_dict = WMReadPropListFromFile(path);
1070 if (shared_dict && !WMIsPLDictionary(shared_dict)) {
1071 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1072 "WindowMaker", path);
1073 WMReleasePropList(shared_dict);
1074 shared_dict = NULL;
1075 } else if (!shared_dict) {
1076 wwarning(_("could not load domain %s from global defaults database"),
1077 "WindowMaker");
1080 /* user dictionary */
1081 dict = WMReadPropListFromFile(WDWindowMaker->path);
1082 if (dict) {
1083 if (!WMIsPLDictionary(dict)) {
1084 WMReleasePropList(dict);
1085 dict = NULL;
1086 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1087 "WindowMaker", WDWindowMaker->path);
1088 } else {
1089 if (shared_dict) {
1090 WMMergePLDictionaries(shared_dict, dict, True);
1091 WMReleasePropList(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 WMReleasePropList(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 WMReleasePropList(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 = WMReadPropListFromFile(WDWindowAttributes->path);
1120 if (dict) {
1121 if (!WMIsPLDictionary(dict)) {
1122 WMReleasePropList(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 WMReleasePropList(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 = WMReadPropListFromFile(WDRootMenu->path);
1163 #ifdef HEARTBEAT
1164 puts("Checking WMRootMenu domain");
1165 #endif
1166 if (dict) {
1167 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1168 WMReleasePropList(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 WMReleasePropList(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, WMPropList *new_dict)
1194 WMPropList *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 WMPropList *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 = WMGetFromPLDictionary(new_dict, entry->plkey);
1212 else
1213 plvalue = NULL;
1215 if (!old_dict)
1216 old_value = NULL;
1217 else
1218 old_value = WMGetFromPLDictionary(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 WMPutInPLDictionary(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 (!WMIsPropListEqualTo(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 WMGetPropListDescription(plvalue, False));
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 (!WMIsPLString(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 = WMGetFromPLString(value)\
1398 static int
1399 string2index(WMPropList *key, WMPropList *val, char *def,
1400 WOptionEnumeration *values)
1402 char *str;
1403 WOptionEnumeration *v;
1404 char buffer[TOTAL_VALUES_LENGTH];
1406 if (WMIsPLString(val) && (str = WMGetFromPLString(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 WMGetFromPLString(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, WMPropList *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 = WMGetFromPLString(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, WMPropList *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 = WMGetFromPLString(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, WMPropList *value, void *addr,
1521 void **ret)
1523 static WCoord data;
1524 char *val_x, *val_y;
1525 int nelem, changed=0;
1526 WMPropList *elem_x, *elem_y;
1528 again:
1529 if (!WMIsPLArray(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 = WMGetPropListItemCount(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 = WMGetFromPLArray(value, 0);
1555 elem_y = WMGetFromPLArray(value, 1);
1557 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(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 = WMGetFromPLString(elem_x);
1570 val_y = WMGetFromPLString(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, WMPropList *value, void *addr,
1607 void **ret)
1609 static char *data;
1611 GET_STRING_OR_DEFAULT("String", data);
1613 if (!data) {
1614 data = WMGetFromPLString(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, WMPropList *value, void *addr,
1632 void **ret)
1634 static char *data;
1635 int i, count, len;
1636 char *ptr;
1637 WMPropList *d;
1638 int changed=0;
1640 again:
1641 if (!WMIsPLArray(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 = WMGetPropListItemCount(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 = WMGetFromPLArray(value, i);
1668 if (!d || !WMIsPLString(d)) {
1669 count = i;
1670 break;
1672 len += strlen(WMGetFromPLString(d))+1;
1675 ptr = data = wmalloc(len+1);
1677 for (i=0; i<count; i++) {
1678 d = WMGetFromPLArray(value, i);
1679 if (!d || !WMIsPLString(d)) {
1680 break;
1682 strcpy(ptr, WMGetFromPLString(d));
1683 ptr += strlen(WMGetFromPLString(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, WMPropList *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, WMPropList *pl)
1741 WMPropList *elem;
1742 char *val;
1743 int nelem;
1744 WTexture *texture=NULL;
1746 nelem = WMGetPropListItemCount(pl);
1747 if (nelem < 1)
1748 return NULL;
1751 elem = WMGetFromPLArray(pl, 0);
1752 if (!elem || !WMIsPLString(elem))
1753 return NULL;
1754 val = WMGetFromPLString(elem);
1757 if (strcasecmp(val, "solid")==0) {
1758 XColor color;
1760 if (nelem != 2)
1761 return NULL;
1763 /* get color */
1765 elem = WMGetFromPLArray(pl, 1);
1766 if (!elem || !WMIsPLString(elem))
1767 return NULL;
1768 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 1);
1798 if (!elem || !WMIsPLString(elem))
1799 return NULL;
1800 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 2);
1813 if (!elem || !WMIsPLString(elem)) {
1814 return NULL;
1816 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 1+i);
1843 if (!elem || !WMIsPLString(elem))
1844 return NULL;
1845 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 3);
1857 if (!elem || !WMIsPLString(elem))
1858 return NULL;
1859 val = WMGetFromPLString(elem);
1860 th1 = atoi(val);
1863 /* get from color */
1864 for (i = 0; i < 2; i++) {
1865 elem = WMGetFromPLArray(pl, 4+i);
1866 if (!elem || !WMIsPLString(elem))
1867 return NULL;
1868 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 6);
1880 if (!elem || !WMIsPLString(elem))
1881 return NULL;
1882 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, i+1);
1914 if (!elem || !WMIsPLString(elem)) {
1915 for (--i; i>=0; --i) {
1916 wfree(colors[i]);
1918 wfree(colors);
1919 return NULL;
1921 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 2);
1958 if (!elem || !WMIsPLString(elem)) {
1959 return NULL;
1961 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 1);
1970 if (!elem || !WMIsPLString(elem))
1971 return NULL;
1972 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 3);
1997 if (!elem || !WMIsPLString(elem))
1998 return NULL;
1999 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 4);
2012 if (!elem || !WMIsPLString(elem)) {
2013 return NULL;
2015 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 2);
2028 if (!elem || !WMIsPLString(elem))
2029 opacity = 128;
2030 else
2031 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 1);
2040 if (!elem || !WMIsPLString(elem))
2041 return NULL;
2042 val = WMGetFromPLString(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 = WMGetFromPLArray(pl, 1);
2059 if (!elem || !WMIsPLString(elem)) {
2060 return NULL;
2062 lib = WMGetFromPLString(elem);
2064 /* get the function name */
2065 elem = WMGetFromPLArray(pl, 2);
2066 if (!elem || !WMIsPLString(elem)) {
2067 return NULL;
2069 func = WMGetFromPLString(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 = WMGetFromPLArray(pl, 3 + i);
2078 if (!elem || !WMIsPLString(elem)) {
2079 wfree(argv);
2081 return NULL;
2083 argv[i+1] = wstrdup(WMGetFromPLString(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, WMPropList *value, void *addr,
2114 void **ret)
2116 static WTexture *texture;
2117 int changed=0;
2119 again:
2120 if (!WMIsPLArray(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 WMPropList *pl;
2135 pl = WMGetFromPLArray(value, 0);
2136 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2137 || strcasecmp(WMGetFromPLString(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, WMPropList *value,
2174 void *addr, void **ret)
2176 WMPropList *elem;
2177 int changed = 0;
2178 char *val;
2179 int nelem;
2181 again:
2182 if (!WMIsPLArray(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 = WMGetPropListItemCount(value);
2197 if (nelem > 0) {
2198 elem = WMGetFromPLArray(value, 0);
2199 if (!elem || !WMIsPLString(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 = WMGetFromPLString(elem);
2211 if (strcasecmp(val, "None")==0)
2212 return True;
2214 *ret = WMRetainPropList(value);
2216 return True;
2220 static int
2221 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2222 void *addr, void **ret)
2224 WMPropList *elem;
2225 int nelem;
2226 int changed = 0;
2228 again:
2229 if (!WMIsPLArray(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 = WMGetPropListItemCount(value);
2244 if (nelem > 0) {
2245 while (nelem--) {
2246 elem = WMGetFromPLArray(value, nelem);
2247 if (!elem || !WMIsPLArray(elem)) {
2248 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2249 nelem);
2254 *ret = WMRetainPropList(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 WMPropList *key = WMCreatePLString("WorkspaceBack");
2267 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2269 WMReleasePropList(key);
2271 #endif
2272 return True;
2276 static int
2277 getFont(WScreen *scr, WDefaultEntry *entry, WMPropList *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, WMPropList *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 = WMGetFromPLString(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, WMPropList *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, WMPropList *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, WMPropList *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 # include <X11/cursorfont.h>
2473 typedef struct
2475 char *name;
2476 int id;
2477 } WCursorLookup;
2479 #define CURSOR_ID_NONE (XC_num_glyphs)
2481 static WCursorLookup cursor_table[] =
2483 { "X_cursor", XC_X_cursor },
2484 { "arrow", XC_arrow },
2485 { "based_arrow_down", XC_based_arrow_down },
2486 { "based_arrow_up", XC_based_arrow_up },
2487 { "boat", XC_boat },
2488 { "bogosity", XC_bogosity },
2489 { "bottom_left_corner", XC_bottom_left_corner },
2490 { "bottom_right_corner", XC_bottom_right_corner },
2491 { "bottom_side", XC_bottom_side },
2492 { "bottom_tee", XC_bottom_tee },
2493 { "box_spiral", XC_box_spiral },
2494 { "center_ptr", XC_center_ptr },
2495 { "circle", XC_circle },
2496 { "clock", XC_clock },
2497 { "coffee_mug", XC_coffee_mug },
2498 { "cross", XC_cross },
2499 { "cross_reverse", XC_cross_reverse },
2500 { "crosshair", XC_crosshair },
2501 { "diamond_cross", XC_diamond_cross },
2502 { "dot", XC_dot },
2503 { "dotbox", XC_dotbox },
2504 { "double_arrow", XC_double_arrow },
2505 { "draft_large", XC_draft_large },
2506 { "draft_small", XC_draft_small },
2507 { "draped_box", XC_draped_box },
2508 { "exchange", XC_exchange },
2509 { "fleur", XC_fleur },
2510 { "gobbler", XC_gobbler },
2511 { "gumby", XC_gumby },
2512 { "hand1", XC_hand1 },
2513 { "hand2", XC_hand2 },
2514 { "heart", XC_heart },
2515 { "icon", XC_icon },
2516 { "iron_cross", XC_iron_cross },
2517 { "left_ptr", XC_left_ptr },
2518 { "left_side", XC_left_side },
2519 { "left_tee", XC_left_tee },
2520 { "leftbutton", XC_leftbutton },
2521 { "ll_angle", XC_ll_angle },
2522 { "lr_angle", XC_lr_angle },
2523 { "man", XC_man },
2524 { "middlebutton", XC_middlebutton },
2525 { "mouse", XC_mouse },
2526 { "pencil", XC_pencil },
2527 { "pirate", XC_pirate },
2528 { "plus", XC_plus },
2529 { "question_arrow", XC_question_arrow },
2530 { "right_ptr", XC_right_ptr },
2531 { "right_side", XC_right_side },
2532 { "right_tee", XC_right_tee },
2533 { "rightbutton", XC_rightbutton },
2534 { "rtl_logo", XC_rtl_logo },
2535 { "sailboat", XC_sailboat },
2536 { "sb_down_arrow", XC_sb_down_arrow },
2537 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2538 { "sb_left_arrow", XC_sb_left_arrow },
2539 { "sb_right_arrow", XC_sb_right_arrow },
2540 { "sb_up_arrow", XC_sb_up_arrow },
2541 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2542 { "shuttle", XC_shuttle },
2543 { "sizing", XC_sizing },
2544 { "spider", XC_spider },
2545 { "spraycan", XC_spraycan },
2546 { "star", XC_star },
2547 { "target", XC_target },
2548 { "tcross", XC_tcross },
2549 { "top_left_arrow", XC_top_left_arrow },
2550 { "top_left_corner", XC_top_left_corner },
2551 { "top_right_corner", XC_top_right_corner },
2552 { "top_side", XC_top_side },
2553 { "top_tee", XC_top_tee },
2554 { "trek", XC_trek },
2555 { "ul_angle", XC_ul_angle },
2556 { "umbrella", XC_umbrella },
2557 { "ur_angle", XC_ur_angle },
2558 { "watch", XC_watch },
2559 { "xterm", XC_xterm },
2560 { NULL, CURSOR_ID_NONE }
2563 static void
2564 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2566 switch(status) {
2567 case BitmapOpenFailed:
2568 wwarning(_("failed to open bitmap file \"%s\""), filename);
2569 break;
2570 case BitmapFileInvalid:
2571 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2572 break;
2573 case BitmapNoMemory:
2574 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2575 break;
2576 case BitmapSuccess:
2577 XFreePixmap(dpy, bitmap);
2578 break;
2583 * (none)
2584 * (builtin, <cursor_name>)
2585 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2587 static int
2588 parse_cursor(WScreen *scr, WMPropList *pl, Cursor *cursor)
2590 WMPropList *elem;
2591 char *val;
2592 int nelem;
2593 int status = 0;
2595 nelem = WMGetPropListItemCount(pl);
2596 if (nelem < 1) {
2597 return(status);
2599 elem = WMGetFromPLArray(pl, 0);
2600 if (!elem || !WMIsPLString(elem)) {
2601 return(status);
2603 val = WMGetFromPLString(elem);
2605 if (0 == strcasecmp(val, "none")) {
2606 status = 1;
2607 *cursor = None;
2608 } else if (0 == strcasecmp(val, "builtin")) {
2609 int i;
2610 int cursor_id = CURSOR_ID_NONE;
2612 if (2 != nelem) {
2613 wwarning(_("bad number of arguments in cursor specification"));
2614 return(status);
2616 elem = WMGetFromPLArray(pl, 1);
2617 if (!elem || !WMIsPLString(elem)) {
2618 return(status);
2620 val = WMGetFromPLString(elem);
2622 for (i = 0; NULL != cursor_table[i].name; i++) {
2623 if (0 == strcasecmp(val, cursor_table[i].name)) {
2624 cursor_id = cursor_table[i].id;
2625 break;
2628 if (CURSOR_ID_NONE == cursor_id) {
2629 wwarning(_("unknown builtin cursor name \"%s\""), val);
2630 } else {
2631 *cursor = XCreateFontCursor(dpy, cursor_id);
2632 status = 1;
2634 } else if (0 == strcasecmp(val, "bitmap")) {
2635 char *bitmap_name;
2636 char *mask_name;
2637 int bitmap_status;
2638 int mask_status;
2639 Pixmap bitmap;
2640 Pixmap mask;
2641 unsigned int w, h;
2642 int x, y;
2643 XColor fg, bg;
2645 if (3 != nelem) {
2646 wwarning(_("bad number of arguments in cursor specification"));
2647 return(status);
2649 elem = WMGetFromPLArray(pl, 1);
2650 if (!elem || !WMIsPLString(elem)) {
2651 return(status);
2653 val = WMGetFromPLString(elem);
2654 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2655 if (!bitmap_name) {
2656 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2657 return(status);
2659 elem = WMGetFromPLArray(pl, 2);
2660 if (!elem || !WMIsPLString(elem)) {
2661 wfree(bitmap_name);
2662 return(status);
2664 val = WMGetFromPLString(elem);
2665 mask_name = FindImage(wPreferences.pixmap_path, val);
2666 if (!mask_name) {
2667 wfree(bitmap_name);
2668 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2669 return(status);
2671 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2672 &mask, &x, &y);
2673 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2674 &bitmap, &x, &y);
2675 if ((BitmapSuccess == bitmap_status) &&
2676 (BitmapSuccess == mask_status)) {
2677 fg.pixel = scr->black_pixel;
2678 bg.pixel = scr->white_pixel;
2679 XQueryColor(dpy, scr->w_colormap, &fg);
2680 XQueryColor(dpy, scr->w_colormap, &bg);
2681 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2682 status = 1;
2684 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2685 check_bitmap_status(mask_status, mask_name, mask);
2686 wfree(bitmap_name);
2687 wfree(mask_name);
2689 return(status);
2693 static int
2694 getCursor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2695 void **ret)
2697 static Cursor cursor;
2698 int status;
2699 int changed = 0;
2701 again:
2702 if (!WMIsPLArray(value)) {
2703 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2704 entry->key, "cursor specification");
2705 if (!changed) {
2706 value = entry->plvalue;
2707 changed = 1;
2708 wwarning(_("using default \"%s\" instead"), entry->default_value);
2709 goto again;
2711 return(False);
2713 status = parse_cursor(scr, value, &cursor);
2714 if (!status) {
2715 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2716 if (!changed) {
2717 value = entry->plvalue;
2718 changed = 1;
2719 wwarning(_("using default \"%s\" instead"), entry->default_value);
2720 goto again;
2722 return(False);
2724 if (ret) {
2725 *ret = &cursor;
2727 if (addr) {
2728 *(Cursor *)addr = cursor;
2730 return(True);
2732 #undef CURSOR_ID_NONE
2735 /* ---------------- value setting functions --------------- */
2736 static int
2737 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2739 return REFRESH_WINDOW_TITLE_COLOR;
2742 static int
2743 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2745 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2748 static int
2749 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2751 switch (which) {
2752 case WM_DOCK:
2753 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2754 break;
2755 case WM_CLIP:
2756 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2757 break;
2758 default:
2759 break;
2761 return 0;
2765 static int
2766 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2768 if (scr->workspaces) {
2769 wWorkspaceForceChange(scr, scr->current_workspace);
2770 wArrangeIcons(scr, False);
2772 return 0;
2775 #if not_used
2776 static int
2777 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2779 if (*value <= 0)
2780 *(int*)foo = 1;
2782 return 0;
2784 #endif
2788 static int
2789 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2791 Pixmap pixmap;
2792 RImage *img;
2793 int reset = 0;
2795 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2796 wPreferences.icon_size,
2797 ((*texture)->any.type & WREL_BORDER_MASK)
2798 ? WREL_ICON : WREL_FLAT);
2799 if (!img) {
2800 wwarning(_("could not render texture for icon background"));
2801 if (!entry->addr)
2802 wTextureDestroy(scr, *texture);
2803 return 0;
2805 RConvertImage(scr->rcontext, img, &pixmap);
2807 if (scr->icon_tile) {
2808 reset = 1;
2809 RReleaseImage(scr->icon_tile);
2810 XFreePixmap(dpy, scr->icon_tile_pixmap);
2813 scr->icon_tile = img;
2816 /* put the icon in the noticeboard hint */
2817 PropSetIconTileHint(scr, img);
2820 if (!wPreferences.flags.noclip) {
2821 if (scr->clip_tile) {
2822 RReleaseImage(scr->clip_tile);
2824 scr->clip_tile = wClipMakeTile(scr, img);
2827 scr->icon_tile_pixmap = pixmap;
2829 if (scr->def_icon_pixmap) {
2830 XFreePixmap(dpy, scr->def_icon_pixmap);
2831 scr->def_icon_pixmap = None;
2833 if (scr->def_ticon_pixmap) {
2834 XFreePixmap(dpy, scr->def_ticon_pixmap);
2835 scr->def_ticon_pixmap = None;
2838 if (scr->icon_back_texture) {
2839 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2841 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2843 if (scr->clip_balloon)
2844 XSetWindowBackground(dpy, scr->clip_balloon,
2845 (*texture)->any.color.pixel);
2848 * Free the texture as nobody else will use it, nor refer to it.
2850 if (!entry->addr)
2851 wTextureDestroy(scr, *texture);
2853 return (reset ? REFRESH_ICON_TILE : 0);
2858 static int
2859 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2861 if (scr->title_font) {
2862 WMReleaseFont(scr->title_font);
2864 scr->title_font = font;
2866 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2870 static int
2871 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2873 if (scr->menu_title_font) {
2874 WMReleaseFont(scr->menu_title_font);
2877 scr->menu_title_font = font;
2879 return REFRESH_MENU_TITLE_FONT;
2883 static int
2884 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2886 if (scr->menu_entry_font) {
2887 WMReleaseFont(scr->menu_entry_font);
2889 scr->menu_entry_font = font;
2891 return REFRESH_MENU_FONT;
2896 static int
2897 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2899 if (scr->icon_title_font) {
2900 WMReleaseFont(scr->icon_title_font);
2903 scr->icon_title_font = font;
2905 return REFRESH_ICON_FONT;
2909 static int
2910 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2912 if (scr->clip_title_font) {
2913 WMReleaseFont(scr->clip_title_font);
2916 scr->clip_title_font = font;
2918 return REFRESH_ICON_FONT;
2922 static int
2923 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2925 if (scr->workspace_name_font) {
2926 WMReleaseFont(scr->workspace_name_font);
2929 scr->workspace_name_font = font;
2931 return 0;
2935 static int
2936 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2938 if (scr->select_pixel!=scr->white_pixel &&
2939 scr->select_pixel!=scr->black_pixel) {
2940 wFreeColor(scr, scr->select_pixel);
2943 scr->select_pixel = color->pixel;
2945 return REFRESH_MENU_COLOR;
2949 static int
2950 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2952 if (scr->select_text_pixel!=scr->white_pixel &&
2953 scr->select_text_pixel!=scr->black_pixel) {
2954 wFreeColor(scr, scr->select_text_pixel);
2957 scr->select_text_pixel = color->pixel;
2959 return REFRESH_MENU_COLOR;
2963 static int
2964 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2966 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2967 scr->clip_title_pixel[index]!=scr->black_pixel) {
2968 wFreeColor(scr, scr->clip_title_pixel[index]);
2970 scr->clip_title_pixel[index] = color->pixel;
2972 #ifdef GRADIENT_CLIP_ARROW
2973 if (index == CLIP_NORMAL) {
2974 RImage *image;
2975 RColor color1, color2;
2976 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2977 int as = pt - 15; /* 15 = 5+5+5 */
2979 FREE_PIXMAP(scr->clip_arrow_gradient);
2981 color1.red = (color->red >> 8)*6/10;
2982 color1.green = (color->green >> 8)*6/10;
2983 color1.blue = (color->blue >> 8)*6/10;
2985 color2.red = WMIN((color->red >> 8)*20/10, 255);
2986 color2.green = WMIN((color->green >> 8)*20/10, 255);
2987 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2989 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2990 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2991 RReleaseImage(image);
2993 #endif /* GRADIENT_CLIP_ARROW */
2995 return REFRESH_ICON_TITLE_COLOR;
2999 static int
3000 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3002 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3003 scr->window_title_pixel[index]!=scr->black_pixel) {
3004 wFreeColor(scr, scr->window_title_pixel[index]);
3007 scr->window_title_pixel[index] = color->pixel;
3009 if (index == WS_UNFOCUSED)
3010 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3012 return REFRESH_WINDOW_TITLE_COLOR;
3016 static int
3017 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3019 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3020 scr->menu_title_pixel[0]!=scr->black_pixel) {
3021 wFreeColor(scr, scr->menu_title_pixel[0]);
3024 scr->menu_title_pixel[0] = color->pixel;
3025 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3027 return REFRESH_MENU_TITLE_COLOR;
3031 static int
3032 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3034 XGCValues gcv;
3035 #define gcm (GCForeground|GCBackground|GCFillStyle)
3037 if (scr->mtext_pixel!=scr->white_pixel &&
3038 scr->mtext_pixel!=scr->black_pixel) {
3039 wFreeColor(scr, scr->mtext_pixel);
3042 scr->mtext_pixel = color->pixel;
3044 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3047 if (scr->dtext_pixel == scr->mtext_pixel) {
3048 gcv.foreground = scr->white_pixel;
3049 gcv.background = scr->black_pixel;
3050 gcv.fill_style = FillStippled;
3051 } else {
3052 gcv.foreground = scr->dtext_pixel;
3053 gcv.fill_style = FillSolid;
3055 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3057 return REFRESH_MENU_COLOR;
3058 #undef gcm
3062 static int
3063 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3065 XGCValues gcv;
3066 #define gcm (GCForeground|GCBackground|GCFillStyle)
3068 if (scr->dtext_pixel!=scr->white_pixel &&
3069 scr->dtext_pixel!=scr->black_pixel) {
3070 wFreeColor(scr, scr->dtext_pixel);
3073 scr->dtext_pixel = color->pixel;
3075 if (scr->dtext_pixel == scr->mtext_pixel) {
3076 gcv.foreground = scr->white_pixel;
3077 gcv.background = scr->black_pixel;
3078 gcv.fill_style = FillStippled;
3079 } else {
3080 gcv.foreground = scr->dtext_pixel;
3081 gcv.fill_style = FillSolid;
3083 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3085 return REFRESH_MENU_COLOR;
3086 #undef gcm
3089 static int
3090 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3092 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3094 return REFRESH_ICON_TITLE_COLOR;
3098 static int
3099 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3101 if (scr->icon_title_texture) {
3102 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3104 XQueryColor (dpy, scr->w_colormap, color);
3105 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3107 return REFRESH_ICON_TITLE_BACK;
3111 static void
3112 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3114 close(scr->helper_fd);
3115 scr->helper_fd = 0;
3116 scr->helper_pid = 0;
3117 scr->flags.backimage_helper_launched = 0;
3121 static int
3122 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3123 void *bar)
3125 WMPropList *val;
3126 char *str;
3127 int i;
3129 if (scr->flags.backimage_helper_launched) {
3130 if (WMGetPropListItemCount(value)==0) {
3131 SendHelperMessage(scr, 'C', 0, NULL);
3132 SendHelperMessage(scr, 'K', 0, NULL);
3134 WMReleasePropList(value);
3135 return 0;
3137 } else {
3138 pid_t pid;
3139 int filedes[2];
3141 if (WMGetPropListItemCount(value) == 0)
3142 return 0;
3144 if (pipe(filedes) < 0) {
3145 wsyserror("pipe() failed:can't set workspace specific background image");
3147 WMReleasePropList(value);
3148 return 0;
3151 pid = fork();
3152 if (pid < 0) {
3153 wsyserror("fork() failed:can't set workspace specific background image");
3154 if (close(filedes[0]) < 0)
3155 wsyserror("could not close pipe");
3156 if (close(filedes[1]) < 0)
3157 wsyserror("could not close pipe");
3159 } else if (pid == 0) {
3160 char *dither;
3162 SetupEnvironment(scr);
3164 if (close(0) < 0)
3165 wsyserror("could not close pipe");
3166 if (dup(filedes[0]) < 0) {
3167 wsyserror("dup() failed:can't set workspace specific background image");
3169 dither = wPreferences.no_dithering ? "-m" : "-d";
3170 if (wPreferences.smooth_workspace_back)
3171 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3172 else
3173 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3174 wsyserror("could not execute wmsetbg");
3175 exit(1);
3176 } else {
3178 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3179 wsyserror("error setting close-on-exec flag");
3181 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3182 wsyserror("error setting close-on-exec flag");
3185 scr->helper_fd = filedes[1];
3186 scr->helper_pid = pid;
3187 scr->flags.backimage_helper_launched = 1;
3189 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3191 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3196 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3197 val = WMGetFromPLArray(value, i);
3198 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val)>0) {
3199 str = WMGetPropListDescription(val, False);
3201 SendHelperMessage(scr, 'S', i+1, str);
3203 wfree(str);
3204 } else {
3205 SendHelperMessage(scr, 'U', i+1, NULL);
3208 sleep(1);
3210 WMReleasePropList(value);
3211 return 0;
3215 static int
3216 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3217 void *bar)
3219 if (scr->flags.backimage_helper_launched) {
3220 char *str;
3222 if (WMGetPropListItemCount(value)==0) {
3223 SendHelperMessage(scr, 'U', 0, NULL);
3224 } else {
3225 /* set the default workspace background to this one */
3226 str = WMGetPropListDescription(value, False);
3227 if (str) {
3228 SendHelperMessage(scr, 'S', 0, str);
3229 wfree(str);
3230 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3231 } else {
3232 SendHelperMessage(scr, 'U', 0, NULL);
3235 } else if (WMGetPropListItemCount(value) > 0) {
3236 char *command;
3237 char *text;
3238 char *dither;
3239 int len;
3241 SetupEnvironment(scr);
3242 text = WMGetPropListDescription(value, False);
3243 len = strlen(text)+40;
3244 command = wmalloc(len);
3245 dither = wPreferences.no_dithering ? "-m" : "-d";
3246 if (wPreferences.smooth_workspace_back)
3247 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3248 else
3249 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3250 wfree(text);
3251 system(command);
3252 wfree(command);
3254 WMReleasePropList(value);
3256 return 0;
3260 static int
3261 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3263 if (scr->widget_texture) {
3264 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3266 scr->widget_texture = *(WTexSolid**)texture;
3268 return 0;
3272 static int
3273 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3275 if (scr->window_title_texture[WS_FOCUSED]) {
3276 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3278 scr->window_title_texture[WS_FOCUSED] = *texture;
3280 return REFRESH_WINDOW_TEXTURES;
3284 static int
3285 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3287 if (scr->window_title_texture[WS_PFOCUSED]) {
3288 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3290 scr->window_title_texture[WS_PFOCUSED] = *texture;
3292 return REFRESH_WINDOW_TEXTURES;
3296 static int
3297 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3299 if (scr->window_title_texture[WS_UNFOCUSED]) {
3300 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3302 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3304 return REFRESH_WINDOW_TEXTURES;
3308 static int
3309 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3311 if (scr->resizebar_texture[0]) {
3312 wTextureDestroy(scr, scr->resizebar_texture[0]);
3314 scr->resizebar_texture[0] = *texture;
3316 return REFRESH_WINDOW_TEXTURES;
3320 static int
3321 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3323 if (scr->menu_title_texture[0]) {
3324 wTextureDestroy(scr, scr->menu_title_texture[0]);
3326 scr->menu_title_texture[0] = *texture;
3328 return REFRESH_MENU_TITLE_TEXTURE;
3332 static int
3333 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3335 if (scr->menu_item_texture) {
3336 wTextureDestroy(scr, scr->menu_item_texture);
3337 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3339 scr->menu_item_texture = *texture;
3341 scr->menu_item_auxtexture
3342 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3344 return REFRESH_MENU_TEXTURE;
3348 static int
3349 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3351 WWindow *wwin;
3352 wKeyBindings[index] = *shortcut;
3354 wwin = scr->focused_window;
3356 while (wwin!=NULL) {
3357 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3359 if (!WFLAGP(wwin, no_bind_keys)) {
3360 wWindowSetKeyGrabs(wwin);
3362 wwin = wwin->prev;
3365 return 0;
3369 static int
3370 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3372 wArrangeIcons(scr, True);
3374 return 0;
3378 static int
3379 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3381 wScreenUpdateUsableArea(scr);
3383 return 0;
3387 static int
3388 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3390 return REFRESH_MENU_TEXTURE;
3395 static int
3396 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3398 return REFRESH_BUTTON_IMAGES;
3403 * Very ugly kluge.
3404 * Need access to the double click variables, so that all widgets in
3405 * wmaker panels will have the same dbl-click values.
3406 * TODO: figure a better way of dealing with it.
3408 #include <WINGs/WINGsP.h>
3410 static int
3411 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3413 extern _WINGsConfiguration WINGsConfiguration;
3415 if (*value <= 0)
3416 *(int*)foo = 1;
3418 WINGsConfiguration.doubleClickDelay = *value;
3420 return 0;
3424 #if 0
3425 static int
3426 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3428 extern _WINGsConfiguration WINGsConfiguration;
3430 WINGsConfiguration.useMultiByte = *value;
3432 return 0;
3434 #endif
3437 static int
3438 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3440 if (None != wCursor[index]) {
3441 XFreeCursor(dpy, wCursor[index]);
3444 wCursor[index] = *cursor;
3446 if ((WCUR_ROOT == index) && (None != *cursor)) {
3447 XDefineCursor(dpy, scr->root_win, *cursor);
3450 return 0;