finished removing focusfollowmouse from wprefs
[wmaker-crm.git] / src / defaults.c
blob9136e7bcbc4cdc008e4d45d97b732d3634331244
1 /* defaults.c - manage configuration through defaults db
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998 Dan Pascu
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <time.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <limits.h>
36 #include <signal.h>
38 #ifdef HAVE_DLFCN_H
39 # include <dlfcn.h>
40 #endif
44 #ifndef PATH_MAX
45 #define PATH_MAX DEFAULT_PATH_MAX
46 #endif
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #include <X11/keysym.h>
52 #include <wraster.h>
55 #include "WindowMaker.h"
56 #include "wcore.h"
57 #include "framewin.h"
58 #include "window.h"
59 #include "texture.h"
60 #include "screen.h"
61 #include "resources.h"
62 #include "defaults.h"
63 #include "keybind.h"
64 #include "xmodifier.h"
65 #include "icon.h"
66 #include "funcs.h"
67 #include "actions.h"
68 #include "dock.h"
69 #include "workspace.h"
70 #include "properties.h"
74 * Our own proplist reader parser. This one will not accept any
75 * syntax errors and is more descriptive in the error messages.
76 * It also doesn't seem to crash.
78 extern proplist_t ReadProplistFromFile(char *file);
81 /***** Global *****/
83 extern WDDomain *WDWindowMaker;
84 extern WDDomain *WDWindowAttributes;
85 extern WDDomain *WDRootMenu;
87 extern int wScreenCount;
89 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
90 extern Atom _XA_WINDOWMAKER_ICON_TILE;
93 extern proplist_t wDomainName;
94 extern proplist_t wAttributeDomainName;
96 extern WPreferences wPreferences;
98 extern WShortKey wKeyBindings[WKBD_LAST];
100 typedef struct {
101 char *key;
102 char *default_value;
103 void *extra_data;
104 void *addr;
105 int (*convert)();
106 int (*update)();
107 proplist_t plkey;
108 proplist_t plvalue; /* default value */
109 } WDefaultEntry;
112 /* used to map strings to integers */
113 typedef struct {
114 char *string;
115 short value;
116 char is_alias;
117 } WOptionEnumeration;
120 /* type converters */
121 static int getBool();
122 static int getInt();
123 static int getCoord();
124 #if 0
125 /* this is not used yet */
126 static int getString();
127 #endif
128 static int getPathList();
129 static int getEnum();
130 static int getTexture();
131 static int getWSBackground();
132 static int getWSSpecificBackground();
133 static int getFont();
134 static int getColor();
135 static int getKeybind();
136 static int getModMask();
137 #ifdef NEWSTUFF
138 static int getRImage();
139 #endif
142 /* value setting functions */
143 static int setJustify();
144 static int setClearance();
145 static int setIfDockPresent();
146 static int setStickyIcons();
148 static int setPositive();
150 static int setWidgetColor();
151 static int setIconTile();
152 static int setWinTitleFont();
153 static int setMenuTitleFont();
154 static int setMenuTextFont();
155 static int setIconTitleFont();
156 static int setIconTitleColor();
157 static int setIconTitleBack();
158 static int setLargeDisplayFont();
159 static int setWTitleColor();
160 static int setFTitleBack();
161 static int setPTitleBack();
162 static int setUTitleBack();
163 static int setResizebarBack();
164 static int setWorkspaceBack();
165 static int setWorkspaceSpecificBack();
166 static int setMenuTitleColor();
167 static int setMenuTextColor();
168 static int setMenuDisabledColor();
169 static int setMenuTitleBack();
170 static int setMenuTextBack();
171 static int setHightlight();
172 static int setHightlightText();
173 static int setKeyGrab();
174 static int setDoubleClick();
175 static int setIconPosition();
177 static int setClipTitleFont();
178 static int setClipTitleColor();
180 static int setMenuStyle();
181 #if 0
182 static int setMultiByte();
183 #endif
184 static int updateUsableArea();
186 #ifdef DEFINABLE_CURSOR
187 extern Cursor wCursor[WCUR_LAST];
188 static int getCursor();
189 static int setCursor();
190 #endif
194 * Tables to convert strings to enumeration values.
195 * Values stored are char
199 /* WARNING: sum of length of all value strings must not exceed
200 * this value */
201 #define TOTAL_VALUES_LENGTH 80
206 #define REFRESH_WINDOW_TEXTURES (1<<0)
207 #define REFRESH_MENU_TEXTURE (1<<1)
208 #define REFRESH_MENU_FONT (1<<2)
209 #define REFRESH_MENU_COLOR (1<<3)
210 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
211 #define REFRESH_MENU_TITLE_FONT (1<<5)
212 #define REFRESH_MENU_TITLE_COLOR (1<<6)
213 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
214 #define REFRESH_WINDOW_FONT (1<<8)
215 #define REFRESH_ICON_TILE (1<<9)
216 #define REFRESH_ICON_FONT (1<<10)
217 #define REFRESH_WORKSPACE_BACK (1<<11)
219 #define REFRESH_BUTTON_IMAGES (1<<12)
221 #define REFRESH_ICON_TITLE_COLOR (1<<13)
222 #define REFRESH_ICON_TITLE_BACK (1<<14)
226 static WOptionEnumeration seFocusModes[] = {
227 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
228 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
229 {NULL, 0, 0}
232 static WOptionEnumeration seColormapModes[] = {
233 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
234 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
235 {NULL, 0, 0}
238 static WOptionEnumeration sePlacements[] = {
239 {"Auto", WPM_AUTO, 0},
240 {"Smart", WPM_SMART, 0},
241 {"Cascade", WPM_CASCADE, 0},
242 {"Random", WPM_RANDOM, 0},
243 {"Manual", WPM_MANUAL, 0},
244 {NULL, 0, 0}
247 static WOptionEnumeration seGeomDisplays[] = {
248 {"Center", WDIS_CENTER, 0},
249 {"Corner", WDIS_TOPLEFT, 0},
250 {"Floating", WDIS_FRAME_CENTER, 0},
251 {"Line", WDIS_NEW, 0},
252 {NULL, 0, 0}
255 static WOptionEnumeration seSpeeds[] = {
256 {"UltraFast", SPEED_ULTRAFAST, 0},
257 {"Fast", SPEED_FAST, 0},
258 {"Medium", SPEED_MEDIUM, 0},
259 {"Slow", SPEED_SLOW, 0},
260 {"UltraSlow", SPEED_ULTRASLOW, 0},
261 {NULL, 0, 0}
264 static WOptionEnumeration seMouseButtonActions[] = {
265 {"None", WA_NONE, 0},
266 {"SelectWindows", WA_SELECT_WINDOWS, 0},
267 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
268 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
269 {NULL, 0, 0}
272 static WOptionEnumeration seMouseWheelActions[] = {
273 {"None", WA_NONE, 0},
274 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
275 {NULL, 0, 0}
278 static WOptionEnumeration seIconificationStyles[] = {
279 {"Zoom", WIS_ZOOM, 0},
280 {"Twist", WIS_TWIST, 0},
281 {"Flip", WIS_FLIP, 0},
282 {"None", WIS_NONE, 0},
283 {"random", WIS_RANDOM, 0},
284 {NULL, 0, 0}
287 static WOptionEnumeration seJustifications[] = {
288 {"Left", WTJ_LEFT, 0},
289 {"Center", WTJ_CENTER, 0},
290 {"Right", WTJ_RIGHT, 0},
291 {NULL, 0, 0}
294 static WOptionEnumeration seIconPositions[] = {
295 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
296 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
297 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
298 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
299 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
300 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
301 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
302 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
303 {NULL, 0, 0}
306 static WOptionEnumeration seMenuStyles[] = {
307 {"normal", MS_NORMAL, 0},
308 {"singletexture", MS_SINGLE_TEXTURE, 0},
309 {"flat", MS_FLAT, 0},
310 {NULL, 0, 0}
314 static WOptionEnumeration seDisplayPositions[] = {
315 {"none", WD_NONE, 0},
316 {"center", WD_CENTER, 0},
317 {"top", WD_TOP, 0},
318 {"bottom", WD_BOTTOM, 0},
319 {"topleft", WD_TOPLEFT, 0},
320 {"topright", WD_TOPRIGHT, 0},
321 {"bottomleft", WD_BOTTOMLEFT, 0},
322 {"bottomright", WD_BOTTOMRIGHT, 0},
323 {NULL, 0, 0}
326 static WOptionEnumeration seWorkspaceBorder[] = {
327 {"None", WB_NONE, 0},
328 {"LeftRight", WB_LEFTRIGHT, 0},
329 {"TopBottom", WB_TOPBOTTOM, 0},
330 {"AllDirections", WB_ALLDIRS, 0},
331 {NULL, 0, 0}
336 * ALL entries in the tables bellow, NEED to have a default value
337 * defined, and this value needs to be correct.
340 /* these options will only affect the window manager on startup
342 * static defaults can't access the screen data, because it is
343 * created after these defaults are read
345 WDefaultEntry staticOptionList[] = {
347 {"ColormapSize", "4", NULL,
348 &wPreferences.cmap_size, getInt, NULL
350 {"DisableDithering", "NO", NULL,
351 &wPreferences.no_dithering, getBool, NULL
353 /* static by laziness */
354 {"IconSize", "64", NULL,
355 &wPreferences.icon_size, getInt, NULL
357 {"ModifierKey", "Mod1", NULL,
358 &wPreferences.modifier_mask, getModMask, NULL
360 {"DisableWSMouseActions", "NO", NULL,
361 &wPreferences.disable_root_mouse, getBool, NULL
363 {"FocusMode", "manual", seFocusModes,
364 &wPreferences.focus_mode, getEnum, NULL
365 }, /* have a problem when switching from manual to sloppy without restart */
366 {"NewStyle", "NO", NULL,
367 &wPreferences.new_style, getBool, NULL
369 {"DisableDock", "NO", (void*) WM_DOCK,
370 NULL, getBool, setIfDockPresent
372 {"DisableClip", "NO", (void*) WM_CLIP,
373 NULL, getBool, setIfDockPresent
375 {"DisableMiniwindows", "NO", NULL,
376 &wPreferences.disable_miniwindows, getBool, NULL
378 #if 0
379 ,{"MultiByteText", "NO", NULL,
380 &wPreferences.multi_byte_text, getBool, setMultiByte
382 #endif
387 WDefaultEntry optionList[] = {
388 /* dynamic options */
389 {"IconPosition", "blh", seIconPositions,
390 &wPreferences.icon_yard, getEnum, setIconPosition
392 {"IconificationStyle", "Zoom", seIconificationStyles,
393 &wPreferences.iconification_style, getEnum, NULL
395 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
396 &wPreferences.mouse_button1, getEnum, NULL
398 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
399 &wPreferences.mouse_button2, getEnum, NULL
401 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
402 &wPreferences.mouse_button3, getEnum, NULL
404 {"MouseWheelAction", "None", seMouseWheelActions,
405 &wPreferences.mouse_wheel, getEnum, NULL
407 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
408 &wPreferences.pixmap_path, getPathList, NULL
410 {"IconPath", DEF_ICON_PATHS, NULL,
411 &wPreferences.icon_path, getPathList, NULL
413 {"ColormapMode", "auto", seColormapModes,
414 &wPreferences.colormap_mode, getEnum, NULL
416 {"AutoFocus", "NO", NULL,
417 &wPreferences.auto_focus, getBool, NULL
419 {"RaiseDelay", "0", NULL,
420 &wPreferences.raise_delay, getInt, NULL
422 {"WindozeCycling", "NO", NULL,
423 &wPreferences.windows_cycling,getBool, NULL
425 {"CirculateRaise", "NO", NULL,
426 &wPreferences.circ_raise, getBool, NULL
428 {"Superfluous", "NO", NULL,
429 &wPreferences.superfluous, getBool, NULL
431 {"AdvanceToNewWorkspace", "NO", NULL,
432 &wPreferences.ws_advance, getBool, NULL
434 {"CycleWorkspaces", "NO", NULL,
435 &wPreferences.ws_cycle, getBool, NULL
437 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
438 &wPreferences.workspace_name_display_position, getEnum, NULL
440 {"WorkspaceBorder", "None", seWorkspaceBorder,
441 &wPreferences.workspace_border_position, getEnum, updateUsableArea
443 {"WorkspaceBorderSize", "0", NULL,
444 &wPreferences.workspace_border_size, getInt, updateUsableArea
446 #ifdef VIRTUAL_DESKTOP
447 {"VirtualEdgeThickness", "1", NULL,
448 &wPreferences.vedge_thickness, getInt, NULL
450 {"VirtualEdgeExtendSpace", "0", NULL,
451 &wPreferences.vedge_bordersize, getInt, NULL
453 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
454 &wPreferences.vedge_hscrollspeed, getInt, NULL
456 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
457 &wPreferences.vedge_vscrollspeed, getInt, NULL
459 {"VirtualEdgeMaximumWidth", "3000", NULL,
460 &wPreferences.vedge_maxwidth, getInt, NULL
462 {"VirtualEdgeMaximumHeight", "3000", NULL,
463 &wPreferences.vedge_maxheight, getInt, NULL
465 #endif
466 {"StickyIcons", "NO", NULL,
467 &wPreferences.sticky_icons, getBool, setStickyIcons
469 {"SaveSessionOnExit", "NO", NULL,
470 &wPreferences.save_session_on_exit, getBool, NULL
472 {"WrapMenus", "NO", NULL,
473 &wPreferences.wrap_menus, getBool, NULL
475 {"ScrollableMenus", "NO", NULL,
476 &wPreferences.scrollable_menus, getBool, NULL
478 {"MenuScrollSpeed", "medium", seSpeeds,
479 &wPreferences.menu_scroll_speed, getEnum, NULL
481 {"IconSlideSpeed", "medium", seSpeeds,
482 &wPreferences.icon_slide_speed, getEnum, NULL
484 {"ShadeSpeed", "medium", seSpeeds,
485 &wPreferences.shade_speed, getEnum, NULL
487 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
488 &wPreferences.dblclick_time, getInt, setDoubleClick,
490 {"AlignSubmenus", "NO", NULL,
491 &wPreferences.align_menus, getBool, NULL
493 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
494 &wPreferences.open_transients_with_parent, getBool, NULL
496 {"WindowPlacement", "auto", sePlacements,
497 &wPreferences.window_placement, getEnum, NULL
499 {"IgnoreFocusClick","NO", NULL,
500 &wPreferences.ignore_focus_click, getBool, NULL
502 {"UseSaveUnders", "NO", NULL,
503 &wPreferences.use_saveunders, getBool, NULL
505 {"OpaqueMove", "NO", NULL,
506 &wPreferences.opaque_move, getBool, NULL
508 {"DisableSound", "NO", NULL,
509 &wPreferences.no_sound, getBool, NULL
511 {"DisableAnimations", "NO", NULL,
512 &wPreferences.no_animations, getBool, NULL
514 {"DontLinkWorkspaces","NO", NULL,
515 &wPreferences.no_autowrap, getBool, NULL
517 {"AutoArrangeIcons", "NO", NULL,
518 &wPreferences.auto_arrange_icons, getBool, NULL
520 {"NoWindowOverDock", "NO", NULL,
521 &wPreferences.no_window_over_dock, getBool, updateUsableArea
523 {"NoWindowOverIcons", "NO", NULL,
524 &wPreferences.no_window_over_icons, getBool, updateUsableArea
526 {"WindowPlaceOrigin", "(0, 0)", NULL,
527 &wPreferences.window_place_origin, getCoord, NULL
529 {"ResizeDisplay", "corner", seGeomDisplays,
530 &wPreferences.size_display, getEnum, NULL
532 {"MoveDisplay", "corner", seGeomDisplays,
533 &wPreferences.move_display, getEnum, NULL
535 {"DontConfirmKill", "NO", NULL,
536 &wPreferences.dont_confirm_kill, getBool,NULL
538 {"WindowTitleBalloons", "NO", NULL,
539 &wPreferences.window_balloon, getBool, NULL
541 {"MiniwindowTitleBalloons", "NO", NULL,
542 &wPreferences.miniwin_balloon,getBool, NULL
544 {"AppIconBalloons", "NO", NULL,
545 &wPreferences.appicon_balloon,getBool, NULL
547 {"HelpBalloons", "NO", NULL,
548 &wPreferences.help_balloon, getBool, NULL
550 {"EdgeResistance", "30", NULL,
551 &wPreferences.edge_resistance,getInt, NULL
553 {"Attraction", "NO", NULL,
554 &wPreferences.attract, getBool, NULL
556 {"DisableBlinking", "NO", NULL,
557 &wPreferences.dont_blink, getBool, NULL
559 /* style options */
560 {"MenuStyle", "normal", seMenuStyles,
561 &wPreferences.menu_style, getEnum, setMenuStyle
563 {"WidgetColor", "(solid, gray)", NULL,
564 NULL, getTexture, setWidgetColor,
566 {"WorkspaceSpecificBack","()", NULL,
567 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
569 /* WorkspaceBack must come after WorkspaceSpecificBack or
570 * WorkspaceBack wont know WorkspaceSpecificBack was also
571 * specified and 2 copies of wmsetbg will be launched */
572 {"WorkspaceBack", "(solid, black)", NULL,
573 NULL, getWSBackground,setWorkspaceBack
575 {"SmoothWorkspaceBack", "NO", NULL,
576 NULL, getBool, NULL
578 {"IconBack", "(solid, gray)", NULL,
579 NULL, getTexture, setIconTile
581 {"TitleJustify", "center", seJustifications,
582 &wPreferences.title_justification, getEnum, setJustify
584 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
585 NULL, getFont, setWinTitleFont,
587 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
588 &wPreferences.window_title_clearance, getInt, setClearance
590 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
591 &wPreferences.menu_title_clearance, getInt, setClearance
593 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
594 &wPreferences.menu_text_clearance, getInt, setClearance
596 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
597 NULL, getFont, setMenuTitleFont
599 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
600 NULL, getFont, setMenuTextFont
602 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
603 NULL, getFont, setIconTitleFont
605 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
606 NULL, getFont, setClipTitleFont
608 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
609 NULL, getFont, setLargeDisplayFont
611 {"HighlightColor", "white", NULL,
612 NULL, getColor, setHightlight
614 {"HighlightTextColor", "black", NULL,
615 NULL, getColor, setHightlightText
617 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
618 NULL, getColor, setClipTitleColor
620 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
621 NULL, getColor, setClipTitleColor
623 {"FTitleColor", "white", (void*)WS_FOCUSED,
624 NULL, getColor, setWTitleColor
626 {"PTitleColor", "white", (void*)WS_PFOCUSED,
627 NULL, getColor, setWTitleColor
629 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
630 NULL, getColor, setWTitleColor
632 {"FTitleBack", "(solid, black)", NULL,
633 NULL, getTexture, setFTitleBack
635 {"PTitleBack", "(solid, \"#616161\")", NULL,
636 NULL, getTexture, setPTitleBack
638 {"UTitleBack", "(solid, gray)", NULL,
639 NULL, getTexture, setUTitleBack
641 {"ResizebarBack", "(solid, gray)", NULL,
642 NULL, getTexture, setResizebarBack
644 {"MenuTitleColor", "white", NULL,
645 NULL, getColor, setMenuTitleColor
647 {"MenuTextColor", "black", NULL,
648 NULL, getColor, setMenuTextColor
650 {"MenuDisabledColor", "\"#616161\"", NULL,
651 NULL, getColor, setMenuDisabledColor
653 {"MenuTitleBack", "(solid, black)", NULL,
654 NULL, getTexture, setMenuTitleBack
656 {"MenuTextBack", "(solid, gray)", NULL,
657 NULL, getTexture, setMenuTextBack
659 {"IconTitleColor", "white", NULL,
660 NULL, getColor, setIconTitleColor
662 {"IconTitleBack", "black", NULL,
663 NULL, getColor, setIconTitleBack
665 /* keybindings */
666 #ifndef LITE
667 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
668 NULL, getKeybind, setKeyGrab
670 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
671 NULL, getKeybind, setKeyGrab
673 #endif /* LITE */
674 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
675 NULL, getKeybind, setKeyGrab
677 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
678 NULL, getKeybind, setKeyGrab
680 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
681 NULL, getKeybind, setKeyGrab
683 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
684 NULL, getKeybind, setKeyGrab
686 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
687 NULL, getKeybind, setKeyGrab
689 {"HideKey", "None", (void*)WKBD_HIDE,
690 NULL, getKeybind, setKeyGrab
692 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
693 NULL, getKeybind, setKeyGrab
695 {"CloseKey", "None", (void*)WKBD_CLOSE,
696 NULL, getKeybind, setKeyGrab
698 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
699 NULL, getKeybind, setKeyGrab
701 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
702 NULL, getKeybind, setKeyGrab
704 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
705 NULL, getKeybind, setKeyGrab
707 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
708 NULL, getKeybind, setKeyGrab
710 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
711 NULL, getKeybind, setKeyGrab
713 {"ShadeKey", "None", (void*)WKBD_SHADE,
714 NULL, getKeybind, setKeyGrab
716 {"SelectKey", "None", (void*)WKBD_SELECT,
717 NULL, getKeybind, setKeyGrab
719 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
720 NULL, getKeybind, setKeyGrab
722 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
723 NULL, getKeybind, setKeyGrab
725 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
726 NULL, getKeybind, setKeyGrab
728 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
729 NULL, getKeybind, setKeyGrab
731 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
732 NULL, getKeybind, setKeyGrab
734 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
735 NULL, getKeybind, setKeyGrab
737 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
738 NULL, getKeybind, setKeyGrab
740 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
741 NULL, getKeybind, setKeyGrab
743 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
744 NULL, getKeybind, setKeyGrab
746 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
747 NULL, getKeybind, setKeyGrab
749 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
750 NULL, getKeybind, setKeyGrab
752 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
753 NULL, getKeybind, setKeyGrab
755 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
756 NULL, getKeybind, setKeyGrab
758 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
759 NULL, getKeybind, setKeyGrab
761 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
762 NULL, getKeybind, setKeyGrab
764 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
765 NULL, getKeybind, setKeyGrab
767 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
768 NULL, getKeybind, setKeyGrab
770 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
771 NULL, getKeybind, setKeyGrab
773 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
774 NULL, getKeybind, setKeyGrab
776 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
777 NULL, getKeybind, setKeyGrab
779 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
780 NULL, getKeybind, setKeyGrab
782 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
783 NULL, getKeybind, setKeyGrab
785 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
786 NULL, getKeybind, setKeyGrab
788 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
789 NULL, getKeybind, setKeyGrab
791 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
792 NULL, getKeybind, setKeyGrab
794 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
795 NULL, getKeybind, setKeyGrab
797 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
798 NULL, getKeybind, setKeyGrab
801 #ifdef KEEP_XKB_LOCK_STATUS
802 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
803 NULL, getKeybind, setKeyGrab
805 {"KbdModeLock", "NO", NULL,
806 &wPreferences.modelock, getBool, NULL
808 #endif /* KEEP_XKB_LOCK_STATUS */
809 #ifdef DEFINABLE_CURSOR
810 ,{"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
811 NULL, getCursor, setCursor
813 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
814 NULL, getCursor, setCursor
816 #if 0
817 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
818 NULL, getCursor, setCursor
820 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
821 NULL, getCursor, setCursor
823 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
824 NULL, getCursor, setCursor
826 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
827 NULL, getCursor, setCursor
829 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
830 NULL, getCursor, setCursor
832 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
833 NULL, getCursor, setCursor
835 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
836 NULL, getCursor, setCursor
838 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
839 NULL, getCursor, setCursor
841 #endif
842 #endif /* DEFINABLE_CURSOR */
846 #if 0
847 static void rereadDefaults(void);
848 #endif
850 #if 0
851 static void
852 rereadDefaults(void)
854 /* must defer the update because accessing X data from a
855 * signal handler can mess up Xlib */
858 #endif
860 static void
861 initDefaults()
863 int i;
864 WDefaultEntry *entry;
866 PLSetStringCmpHook(StringCompareHook);
868 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
869 entry = &optionList[i];
871 entry->plkey = PLMakeString(entry->key);
872 if (entry->default_value)
873 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
874 else
875 entry->plvalue = NULL;
878 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
879 entry = &staticOptionList[i];
881 entry->plkey = PLMakeString(entry->key);
882 if (entry->default_value)
883 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
884 else
885 entry->plvalue = NULL;
889 wDomainName = PLMakeString(WMDOMAIN_NAME);
890 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
892 PLRegister(wDomainName, rereadDefaults);
893 PLRegister(wAttributeDomainName, rereadDefaults);
900 #if 0
901 proplist_t
902 wDefaultsInit(int screen_number)
904 static int defaults_inited = 0;
905 proplist_t dict;
907 if (!defaults_inited) {
908 initDefaults();
911 dict = PLGetDomain(wDomainName);
912 if (!dict) {
913 wwarning(_("could not read domain \"%s\" from defaults database"),
914 PLGetString(wDomainName));
917 return dict;
919 #endif
922 void
923 wDefaultsDestroyDomain(WDDomain *domain)
925 if (domain->dictionary)
926 PLRelease(domain->dictionary);
927 wfree(domain->path);
928 wfree(domain);
932 WDDomain*
933 wDefaultsInitDomain(char *domain, Bool requireDictionary)
935 WDDomain *db;
936 struct stat stbuf;
937 static int inited = 0;
938 char path[PATH_MAX];
939 char *the_path;
940 proplist_t shared_dict=NULL;
942 if (!inited) {
943 inited = 1;
944 initDefaults();
947 db = wmalloc(sizeof(WDDomain));
948 memset(db, 0, sizeof(WDDomain));
949 db->domain_name = domain;
950 db->path = wdefaultspathfordomain(domain);
951 the_path = db->path;
953 if (the_path && stat(the_path, &stbuf)>=0) {
954 db->dictionary = ReadProplistFromFile(the_path);
955 if (db->dictionary) {
956 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
957 PLRelease(db->dictionary);
958 db->dictionary = NULL;
959 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
960 domain, the_path);
962 db->timestamp = stbuf.st_mtime;
963 } else {
964 wwarning(_("could not load domain %s from user defaults database"),
965 domain);
969 /* global system dictionary */
970 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
971 if (stat(path, &stbuf)>=0) {
972 shared_dict = ReadProplistFromFile(path);
973 if (shared_dict) {
974 if (requireDictionary && !PLIsDictionary(shared_dict)) {
975 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
976 domain, path);
977 PLRelease(shared_dict);
978 shared_dict = NULL;
979 } else {
980 if (db->dictionary && PLIsDictionary(shared_dict) &&
981 PLIsDictionary(db->dictionary)) {
982 PLMergeDictionaries(shared_dict, db->dictionary);
983 PLRelease(db->dictionary);
984 db->dictionary = shared_dict;
985 if (stbuf.st_mtime > db->timestamp)
986 db->timestamp = stbuf.st_mtime;
987 } else if (!db->dictionary) {
988 db->dictionary = shared_dict;
989 if (stbuf.st_mtime > db->timestamp)
990 db->timestamp = stbuf.st_mtime;
993 } else {
994 wwarning(_("could not load domain %s from global defaults database (%s)"),
995 domain, path);
999 /* set to save it in user's directory, no matter from where it was read */
1000 if (db->dictionary) {
1001 proplist_t tmp = PLMakeString(db->path);
1003 PLSetFilename(db->dictionary, tmp);
1004 PLRelease(tmp);
1007 return db;
1011 void
1012 wReadStaticDefaults(proplist_t dict)
1014 proplist_t plvalue;
1015 WDefaultEntry *entry;
1016 int i;
1017 void *tdata;
1020 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1021 entry = &staticOptionList[i];
1023 if (dict)
1024 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1025 else
1026 plvalue = NULL;
1028 if (!plvalue) {
1029 /* no default in the DB. Use builtin default */
1030 plvalue = entry->plvalue;
1033 if (plvalue) {
1034 /* convert data */
1035 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1036 if (entry->update) {
1037 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1044 void
1045 wDefaultsCheckDomains(void *foo)
1047 WScreen *scr;
1048 struct stat stbuf;
1049 proplist_t dict;
1050 int i;
1051 char path[PATH_MAX];
1053 #ifdef HEARTBEAT
1054 puts("Checking domains...");
1055 #endif
1056 if (stat(WDWindowMaker->path, &stbuf)>=0
1057 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1058 proplist_t shared_dict = NULL;
1059 #ifdef HEARTBEAT
1060 puts("Checking WindowMaker domain");
1061 #endif
1062 WDWindowMaker->timestamp = stbuf.st_mtime;
1064 /* global dictionary */
1065 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1066 if (stat(path, &stbuf)>=0) {
1067 shared_dict = ReadProplistFromFile(path);
1068 if (shared_dict && !PLIsDictionary(shared_dict)) {
1069 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1070 "WindowMaker", path);
1071 PLRelease(shared_dict);
1072 shared_dict = NULL;
1073 } else if (!shared_dict) {
1074 wwarning(_("could not load domain %s from global defaults database"),
1075 "WindowMaker");
1078 /* user dictionary */
1079 dict = ReadProplistFromFile(WDWindowMaker->path);
1080 if (dict) {
1081 if (!PLIsDictionary(dict)) {
1082 PLRelease(dict);
1083 dict = NULL;
1084 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1085 "WindowMaker", WDWindowMaker->path);
1086 } else {
1087 if (shared_dict) {
1088 PLSetFilename(shared_dict, PLGetFilename(dict));
1089 PLMergeDictionaries(shared_dict, dict);
1090 PLRelease(dict);
1091 dict = shared_dict;
1092 shared_dict = NULL;
1094 for (i=0; i<wScreenCount; i++) {
1095 scr = wScreenWithNumber(i);
1096 if (scr)
1097 wReadDefaults(scr, dict);
1099 if (WDWindowMaker->dictionary) {
1100 PLRelease(WDWindowMaker->dictionary);
1102 WDWindowMaker->dictionary = dict;
1104 } else {
1105 wwarning(_("could not load domain %s from user defaults database"),
1106 "WindowMaker");
1108 if (shared_dict) {
1109 PLRelease(shared_dict);
1113 if (stat(WDWindowAttributes->path, &stbuf)>=0
1114 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1115 #ifdef HEARTBEAT
1116 puts("Checking WMWindowAttributes domain");
1117 #endif
1118 dict = ReadProplistFromFile(WDWindowAttributes->path);
1119 if (dict) {
1120 if (!PLIsDictionary(dict)) {
1121 PLRelease(dict);
1122 dict = NULL;
1123 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1124 "WMWindowAttributes", WDWindowAttributes->path);
1125 } else {
1126 if (WDWindowAttributes->dictionary)
1127 PLRelease(WDWindowAttributes->dictionary);
1128 WDWindowAttributes->dictionary = dict;
1129 for (i=0; i<wScreenCount; i++) {
1130 scr = wScreenWithNumber(i);
1131 if (scr) {
1132 RImage *image;
1134 wDefaultUpdateIcons(scr);
1136 /* Update the panel image if changed */
1137 /* Don't worry. If the image is the same these
1138 * functions will have no performance impact. */
1139 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1141 if (!image) {
1142 wwarning(_("could not load logo image for panels: %s"),
1143 RMessageForError(RErrorCode));
1144 } else {
1145 WMSetApplicationIconImage(scr->wmscreen, image);
1146 RReleaseImage(image);
1151 } else {
1152 wwarning(_("could not load domain %s from user defaults database"),
1153 "WMWindowAttributes");
1155 WDWindowAttributes->timestamp = stbuf.st_mtime;
1158 #ifndef LITE
1159 if (stat(WDRootMenu->path, &stbuf)>=0
1160 && WDRootMenu->timestamp < stbuf.st_mtime) {
1161 dict = ReadProplistFromFile(WDRootMenu->path);
1162 #ifdef HEARTBEAT
1163 puts("Checking WMRootMenu domain");
1164 #endif
1165 if (dict) {
1166 if (!PLIsArray(dict) && !PLIsString(dict)) {
1167 PLRelease(dict);
1168 dict = NULL;
1169 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1170 "WMRootMenu", WDRootMenu->path);
1171 } else {
1172 if (WDRootMenu->dictionary) {
1173 PLRelease(WDRootMenu->dictionary);
1175 WDRootMenu->dictionary = dict;
1177 } else {
1178 wwarning(_("could not load domain %s from user defaults database"),
1179 "WMRootMenu");
1181 WDRootMenu->timestamp = stbuf.st_mtime;
1183 #endif /* !LITE */
1185 if (!foo)
1186 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1190 void
1191 wReadDefaults(WScreen *scr, proplist_t new_dict)
1193 proplist_t plvalue, old_value;
1194 WDefaultEntry *entry;
1195 int i, must_update;
1196 int update_workspace_back = 0; /* kluge :/ */
1197 int needs_refresh;
1198 void *tdata;
1199 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1200 ? WDWindowMaker->dictionary : NULL);
1202 must_update = 0;
1204 needs_refresh = 0;
1206 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1207 entry = &optionList[i];
1209 if (new_dict)
1210 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1211 else
1212 plvalue = NULL;
1214 if (!old_dict)
1215 old_value = NULL;
1216 else
1217 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1220 if (!plvalue && !old_value) {
1221 /* no default in the DB. Use builtin default */
1222 plvalue = entry->plvalue;
1223 if (plvalue && new_dict) {
1224 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1225 must_update = 1;
1227 } else if (!plvalue) {
1228 /* value was deleted from DB. Keep current value */
1229 continue;
1230 } else if (!old_value) {
1231 /* set value for the 1st time */
1232 } else if (!PLIsEqual(plvalue, old_value)) {
1233 /* value has changed */
1234 } else {
1236 if (strcmp(entry->key, "WorkspaceBack") == 0
1237 && update_workspace_back
1238 && scr->flags.backimage_helper_launched) {
1239 } else {
1240 /* value was not changed since last time */
1241 continue;
1245 if (plvalue) {
1246 #ifdef DEBUG
1247 printf("Updating %s to %s\n", entry->key,
1248 PLGetDescription(plvalue));
1249 #endif
1250 /* convert data */
1251 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1253 * If the WorkspaceSpecificBack data has been changed
1254 * so that the helper will be launched now, we must be
1255 * sure to send the default background texture config
1256 * to the helper.
1258 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1259 && !scr->flags.backimage_helper_launched) {
1260 update_workspace_back = 1;
1262 if (entry->update) {
1263 needs_refresh |=
1264 (*entry->update)(scr, entry, tdata, entry->extra_data);
1270 if (needs_refresh!=0 && !scr->flags.startup) {
1271 int foo;
1273 foo = 0;
1274 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1275 foo |= WTextureSettings;
1276 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1277 foo |= WFontSettings;
1278 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1279 foo |= WColorSettings;
1280 if (foo)
1281 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1282 (void*)foo);
1284 foo = 0;
1285 if (needs_refresh & REFRESH_MENU_TEXTURE)
1286 foo |= WTextureSettings;
1287 if (needs_refresh & REFRESH_MENU_FONT)
1288 foo |= WFontSettings;
1289 if (needs_refresh & REFRESH_MENU_COLOR)
1290 foo |= WColorSettings;
1291 if (foo)
1292 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1293 (void*)foo);
1295 foo = 0;
1296 if (needs_refresh & REFRESH_WINDOW_FONT) {
1297 foo |= WFontSettings;
1299 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1300 foo |= WTextureSettings;
1302 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1303 foo |= WColorSettings;
1305 if (foo)
1306 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1307 (void*)foo);
1309 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1310 foo = 0;
1311 if (needs_refresh & REFRESH_ICON_FONT) {
1312 foo |= WFontSettings;
1314 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1315 foo |= WTextureSettings;
1317 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1318 foo |= WTextureSettings;
1320 if (foo)
1321 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1322 (void*)foo);
1324 if (needs_refresh & REFRESH_ICON_TILE)
1325 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1330 void
1331 wDefaultUpdateIcons(WScreen *scr)
1333 WAppIcon *aicon = scr->app_icon_list;
1334 WWindow *wwin = scr->focused_window;
1335 char *file;
1337 while(aicon) {
1338 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1339 False);
1340 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1341 || (file && !aicon->icon->file)) {
1342 RImage *new_image;
1344 if (aicon->icon->file)
1345 wfree(aicon->icon->file);
1346 aicon->icon->file = wstrdup(file);
1348 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1349 aicon->wm_class);
1350 if (new_image) {
1351 wIconChangeImage(aicon->icon, new_image);
1352 wAppIconPaint(aicon);
1355 aicon = aicon->next;
1358 if (!wPreferences.flags.noclip)
1359 wClipIconPaint(scr->clip_icon);
1361 while (wwin) {
1362 if (wwin->icon && wwin->flags.miniaturized) {
1363 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1364 False);
1365 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1366 || (file && !wwin->icon->file)) {
1367 RImage *new_image;
1369 if (wwin->icon->file)
1370 wfree(wwin->icon->file);
1371 wwin->icon->file = wstrdup(file);
1373 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1374 wwin->wm_class);
1375 if (new_image)
1376 wIconChangeImage(wwin->icon, new_image);
1379 wwin = wwin->prev;
1384 /* --------------------------- Local ----------------------- */
1386 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1387 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1388 entry->key, x); \
1389 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1390 var = entry->default_value;\
1391 } else var = PLGetString(value)\
1397 static int
1398 string2index(proplist_t key, proplist_t val, proplist_t def,
1399 WOptionEnumeration *values)
1401 char *str;
1402 WOptionEnumeration *v;
1403 char buffer[TOTAL_VALUES_LENGTH];
1405 if (PLIsString(val) && (str = PLGetString(val))) {
1406 for (v=values; v->string!=NULL; v++) {
1407 if (strcasecmp(v->string, str)==0)
1408 return v->value;
1412 buffer[0] = 0;
1413 for (v=values; v->string!=NULL; v++) {
1414 if (!v->is_alias) {
1415 if (buffer[0]!=0)
1416 strcat(buffer, ", ");
1417 strcat(buffer, v->string);
1420 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1421 PLGetString(key), buffer);
1423 if (def) {
1424 return string2index(key, val, NULL, values);
1427 return -1;
1434 * value - is the value in the defaults DB
1435 * addr - is the address to store the data
1436 * ret - is the address to store a pointer to a temporary buffer. ret
1437 * must not be freed and is used by the set functions
1439 static int
1440 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1441 void **ret)
1443 static char data;
1444 char *val;
1445 int second_pass=0;
1447 GET_STRING_OR_DEFAULT("Boolean", val);
1449 again:
1450 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1451 || strcasecmp(val, "YES")==0) {
1453 data = 1;
1454 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1455 || strcasecmp(val, "NO")==0) {
1456 data = 0;
1457 } else {
1458 int i;
1459 if (sscanf(val, "%i", &i)==1) {
1460 if (i!=0)
1461 data = 1;
1462 else
1463 data = 0;
1464 } else {
1465 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1466 val, entry->key);
1467 if (second_pass==0) {
1468 val = PLGetString(entry->plvalue);
1469 second_pass = 1;
1470 wwarning(_("using default \"%s\" instead"), val);
1471 goto again;
1473 return False;
1477 if (ret)
1478 *ret = &data;
1480 if (addr) {
1481 *(char*)addr = data;
1484 return True;
1488 static int
1489 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1490 void **ret)
1492 static int data;
1493 char *val;
1496 GET_STRING_OR_DEFAULT("Integer", val);
1498 if (sscanf(val, "%i", &data)!=1) {
1499 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1500 val, entry->key);
1501 val = PLGetString(entry->plvalue);
1502 wwarning(_("using default \"%s\" instead"), val);
1503 if (sscanf(val, "%i", &data)!=1) {
1504 return False;
1508 if (ret)
1509 *ret = &data;
1511 if (addr) {
1512 *(int*)addr = data;
1514 return True;
1518 static int
1519 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1520 void **ret)
1522 static WCoord data;
1523 char *val_x, *val_y;
1524 int nelem, changed=0;
1525 proplist_t elem_x, elem_y;
1527 again:
1528 if (!PLIsArray(value)) {
1529 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1530 entry->key, "Coordinate");
1531 if (changed==0) {
1532 value = entry->plvalue;
1533 changed = 1;
1534 wwarning(_("using default \"%s\" instead"), entry->default_value);
1535 goto again;
1537 return False;
1540 nelem = PLGetNumberOfElements(value);
1541 if (nelem != 2) {
1542 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1543 entry->key);
1544 if (changed==0) {
1545 value = entry->plvalue;
1546 changed = 1;
1547 wwarning(_("using default \"%s\" instead"), entry->default_value);
1548 goto again;
1550 return False;
1553 elem_x = PLGetArrayElement(value, 0);
1554 elem_y = PLGetArrayElement(value, 1);
1556 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1557 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1558 entry->key);
1559 if (changed==0) {
1560 value = entry->plvalue;
1561 changed = 1;
1562 wwarning(_("using default \"%s\" instead"), entry->default_value);
1563 goto again;
1565 return False;
1568 val_x = PLGetString(elem_x);
1569 val_y = PLGetString(elem_y);
1571 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1572 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1573 if (changed==0) {
1574 value = entry->plvalue;
1575 changed = 1;
1576 wwarning(_("using default \"%s\" instead"), entry->default_value);
1577 goto again;
1579 return False;
1582 if (data.x < 0)
1583 data.x = 0;
1584 else if (data.x > scr->scr_width/3)
1585 data.x = scr->scr_width/3;
1586 if (data.y < 0)
1587 data.y = 0;
1588 else if (data.y > scr->scr_height/3)
1589 data.y = scr->scr_height/3;
1591 if (ret)
1592 *ret = &data;
1594 if (addr) {
1595 *(WCoord*)addr = data;
1598 return True;
1602 #if 0
1603 /* This function is not used at the moment. */
1604 static int
1605 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1606 void **ret)
1608 static char *data;
1610 GET_STRING_OR_DEFAULT("String", data);
1612 if (!data) {
1613 data = PLGetString(entry->plvalue);
1614 if (!data)
1615 return False;
1618 if (ret)
1619 *ret = &data;
1621 if (addr)
1622 *(char**)addr = wstrdup(data);
1624 return True;
1626 #endif
1629 static int
1630 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1631 void **ret)
1633 static char *data;
1634 int i, count, len;
1635 char *ptr;
1636 proplist_t d;
1637 int changed=0;
1639 again:
1640 if (!PLIsArray(value)) {
1641 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1642 entry->key, "an array of paths");
1643 if (changed==0) {
1644 value = entry->plvalue;
1645 changed = 1;
1646 wwarning(_("using default \"%s\" instead"), entry->default_value);
1647 goto again;
1649 return False;
1652 i = 0;
1653 count = PLGetNumberOfElements(value);
1654 if (count < 1) {
1655 if (changed==0) {
1656 value = entry->plvalue;
1657 changed = 1;
1658 wwarning(_("using default \"%s\" instead"), entry->default_value);
1659 goto again;
1661 return False;
1664 len = 0;
1665 for (i=0; i<count; i++) {
1666 d = PLGetArrayElement(value, i);
1667 if (!d || !PLIsString(d)) {
1668 count = i;
1669 break;
1671 len += strlen(PLGetString(d))+1;
1674 ptr = data = wmalloc(len+1);
1676 for (i=0; i<count; i++) {
1677 d = PLGetArrayElement(value, i);
1678 if (!d || !PLIsString(d)) {
1679 break;
1681 strcpy(ptr, PLGetString(d));
1682 ptr += strlen(PLGetString(d));
1683 *ptr = ':';
1684 ptr++;
1686 ptr--; *(ptr--) = 0;
1688 if (*(char**)addr!=NULL) {
1689 wfree(*(char**)addr);
1691 *(char**)addr = data;
1693 return True;
1697 static int
1698 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1699 void **ret)
1701 static signed char data;
1703 data = string2index(entry->plkey, value, entry->default_value,
1704 (WOptionEnumeration*)entry->extra_data);
1705 if (data < 0)
1706 return False;
1708 if (ret)
1709 *ret = &data;
1711 if (addr)
1712 *(signed char*)addr = data;
1714 return True;
1720 * (solid <color>)
1721 * (hgradient <color> <color>)
1722 * (vgradient <color> <color>)
1723 * (dgradient <color> <color>)
1724 * (mhgradient <color> <color> ...)
1725 * (mvgradient <color> <color> ...)
1726 * (mdgradient <color> <color> ...)
1727 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1728 * (tpixmap <file> <color>)
1729 * (spixmap <file> <color>)
1730 * (cpixmap <file> <color>)
1731 * (thgradient <file> <opaqueness> <color> <color>)
1732 * (tvgradient <file> <opaqueness> <color> <color>)
1733 * (tdgradient <file> <opaqueness> <color> <color>)
1734 * (function <lib> <function> ...)
1737 static WTexture*
1738 parse_texture(WScreen *scr, proplist_t pl)
1740 proplist_t elem;
1741 char *val;
1742 int nelem;
1743 WTexture *texture=NULL;
1745 nelem = PLGetNumberOfElements(pl);
1746 if (nelem < 1)
1747 return NULL;
1750 elem = PLGetArrayElement(pl, 0);
1751 if (!elem || !PLIsString(elem))
1752 return NULL;
1753 val = PLGetString(elem);
1756 if (strcasecmp(val, "solid")==0) {
1757 XColor color;
1759 if (nelem != 2)
1760 return NULL;
1762 /* get color */
1764 elem = PLGetArrayElement(pl, 1);
1765 if (!elem || !PLIsString(elem))
1766 return NULL;
1767 val = PLGetString(elem);
1769 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1770 wwarning(_("\"%s\" is not a valid color name"), val);
1771 return NULL;
1774 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1775 } else if (strcasecmp(val, "dgradient")==0
1776 || strcasecmp(val, "vgradient")==0
1777 || strcasecmp(val, "hgradient")==0) {
1778 RColor color1, color2;
1779 XColor xcolor;
1780 int type;
1782 if (nelem != 3) {
1783 wwarning(_("bad number of arguments in gradient specification"));
1784 return NULL;
1787 if (val[0]=='d' || val[0]=='D')
1788 type = WTEX_DGRADIENT;
1789 else if (val[0]=='h' || val[0]=='H')
1790 type = WTEX_HGRADIENT;
1791 else
1792 type = WTEX_VGRADIENT;
1795 /* get from color */
1796 elem = PLGetArrayElement(pl, 1);
1797 if (!elem || !PLIsString(elem))
1798 return NULL;
1799 val = PLGetString(elem);
1801 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1802 wwarning(_("\"%s\" is not a valid color name"), val);
1803 return NULL;
1805 color1.alpha = 255;
1806 color1.red = xcolor.red >> 8;
1807 color1.green = xcolor.green >> 8;
1808 color1.blue = xcolor.blue >> 8;
1810 /* get to color */
1811 elem = PLGetArrayElement(pl, 2);
1812 if (!elem || !PLIsString(elem)) {
1813 return NULL;
1815 val = PLGetString(elem);
1817 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1818 wwarning(_("\"%s\" is not a valid color name"), val);
1819 return NULL;
1821 color2.alpha = 255;
1822 color2.red = xcolor.red >> 8;
1823 color2.green = xcolor.green >> 8;
1824 color2.blue = xcolor.blue >> 8;
1826 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1828 } else if (strcasecmp(val, "igradient")==0) {
1829 RColor colors1[2], colors2[2];
1830 int th1, th2;
1831 XColor xcolor;
1832 int i;
1834 if (nelem != 7) {
1835 wwarning(_("bad number of arguments in gradient specification"));
1836 return NULL;
1839 /* get from color */
1840 for (i = 0; i < 2; i++) {
1841 elem = PLGetArrayElement(pl, 1+i);
1842 if (!elem || !PLIsString(elem))
1843 return NULL;
1844 val = PLGetString(elem);
1846 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1847 wwarning(_("\"%s\" is not a valid color name"), val);
1848 return NULL;
1850 colors1[i].alpha = 255;
1851 colors1[i].red = xcolor.red >> 8;
1852 colors1[i].green = xcolor.green >> 8;
1853 colors1[i].blue = xcolor.blue >> 8;
1855 elem = PLGetArrayElement(pl, 3);
1856 if (!elem || !PLIsString(elem))
1857 return NULL;
1858 val = PLGetString(elem);
1859 th1 = atoi(val);
1862 /* get from color */
1863 for (i = 0; i < 2; i++) {
1864 elem = PLGetArrayElement(pl, 4+i);
1865 if (!elem || !PLIsString(elem))
1866 return NULL;
1867 val = PLGetString(elem);
1869 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1870 wwarning(_("\"%s\" is not a valid color name"), val);
1871 return NULL;
1873 colors2[i].alpha = 255;
1874 colors2[i].red = xcolor.red >> 8;
1875 colors2[i].green = xcolor.green >> 8;
1876 colors2[i].blue = xcolor.blue >> 8;
1878 elem = PLGetArrayElement(pl, 6);
1879 if (!elem || !PLIsString(elem))
1880 return NULL;
1881 val = PLGetString(elem);
1882 th2 = atoi(val);
1884 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1885 th2, colors2);
1887 } else if (strcasecmp(val, "mhgradient")==0
1888 || strcasecmp(val, "mvgradient")==0
1889 || strcasecmp(val, "mdgradient")==0) {
1890 XColor color;
1891 RColor **colors;
1892 int i, count;
1893 int type;
1895 if (nelem < 3) {
1896 wwarning(_("too few arguments in multicolor gradient specification"));
1897 return NULL;
1900 if (val[1]=='h' || val[1]=='H')
1901 type = WTEX_MHGRADIENT;
1902 else if (val[1]=='v' || val[1]=='V')
1903 type = WTEX_MVGRADIENT;
1904 else
1905 type = WTEX_MDGRADIENT;
1907 count = nelem-1;
1909 colors = wmalloc(sizeof(RColor*)*(count+1));
1911 for (i=0; i<count; i++) {
1912 elem = PLGetArrayElement(pl, i+1);
1913 if (!elem || !PLIsString(elem)) {
1914 for (--i; i>=0; --i) {
1915 wfree(colors[i]);
1917 wfree(colors);
1918 return NULL;
1920 val = PLGetString(elem);
1922 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1923 wwarning(_("\"%s\" is not a valid color name"), val);
1924 for (--i; i>=0; --i) {
1925 wfree(colors[i]);
1927 wfree(colors);
1928 return NULL;
1929 } else {
1930 colors[i] = wmalloc(sizeof(RColor));
1931 colors[i]->red = color.red >> 8;
1932 colors[i]->green = color.green >> 8;
1933 colors[i]->blue = color.blue >> 8;
1936 colors[i] = NULL;
1938 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1939 } else if (strcasecmp(val, "spixmap")==0 ||
1940 strcasecmp(val, "cpixmap")==0 ||
1941 strcasecmp(val, "tpixmap")==0) {
1942 XColor color;
1943 int type;
1945 if (nelem != 3)
1946 return NULL;
1948 if (val[0] == 's' || val[0] == 'S')
1949 type = WTP_SCALE;
1950 else if (val[0] == 'c' || val[0] == 'C')
1951 type = WTP_CENTER;
1952 else
1953 type = WTP_TILE;
1955 /* get color */
1956 elem = PLGetArrayElement(pl, 2);
1957 if (!elem || !PLIsString(elem)) {
1958 return NULL;
1960 val = PLGetString(elem);
1962 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1963 wwarning(_("\"%s\" is not a valid color name"), val);
1964 return NULL;
1967 /* file name */
1968 elem = PLGetArrayElement(pl, 1);
1969 if (!elem || !PLIsString(elem))
1970 return NULL;
1971 val = PLGetString(elem);
1973 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1974 } else if (strcasecmp(val, "thgradient")==0
1975 || strcasecmp(val, "tvgradient")==0
1976 || strcasecmp(val, "tdgradient")==0) {
1977 RColor color1, color2;
1978 XColor xcolor;
1979 int opacity;
1980 int style;
1982 if (val[1]=='h' || val[1]=='H')
1983 style = WTEX_THGRADIENT;
1984 else if (val[1]=='v' || val[1]=='V')
1985 style = WTEX_TVGRADIENT;
1986 else
1987 style = WTEX_TDGRADIENT;
1989 if (nelem != 5) {
1990 wwarning(_("bad number of arguments in textured gradient specification"));
1991 return NULL;
1994 /* get from color */
1995 elem = PLGetArrayElement(pl, 3);
1996 if (!elem || !PLIsString(elem))
1997 return NULL;
1998 val = PLGetString(elem);
2000 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2001 wwarning(_("\"%s\" is not a valid color name"), val);
2002 return NULL;
2004 color1.alpha = 255;
2005 color1.red = xcolor.red >> 8;
2006 color1.green = xcolor.green >> 8;
2007 color1.blue = xcolor.blue >> 8;
2009 /* get to color */
2010 elem = PLGetArrayElement(pl, 4);
2011 if (!elem || !PLIsString(elem)) {
2012 return NULL;
2014 val = PLGetString(elem);
2016 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2017 wwarning(_("\"%s\" is not a valid color name"), val);
2018 return NULL;
2020 color2.alpha = 255;
2021 color2.red = xcolor.red >> 8;
2022 color2.green = xcolor.green >> 8;
2023 color2.blue = xcolor.blue >> 8;
2025 /* get opacity */
2026 elem = PLGetArrayElement(pl, 2);
2027 if (!elem || !PLIsString(elem))
2028 opacity = 128;
2029 else
2030 val = PLGetString(elem);
2032 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2033 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2034 opacity = 128;
2037 /* get file name */
2038 elem = PLGetArrayElement(pl, 1);
2039 if (!elem || !PLIsString(elem))
2040 return NULL;
2041 val = PLGetString(elem);
2043 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2044 val, opacity);
2046 #ifdef TEXTURE_PLUGIN
2047 else if (strcasecmp(val, "function")==0) {
2048 WTexFunction *function;
2049 void (*initFunc) (Display *, Colormap);
2050 char *lib, *func, **argv;
2051 int i, argc;
2053 if (nelem < 3)
2054 return NULL;
2056 /* get the library name */
2057 elem = PLGetArrayElement(pl, 1);
2058 if (!elem || !PLIsString(elem)) {
2059 return NULL;
2061 lib = PLGetString(elem);
2063 /* get the function name */
2064 elem = PLGetArrayElement(pl, 2);
2065 if (!elem || !PLIsString(elem)) {
2066 return NULL;
2068 func = PLGetString(elem);
2070 argc = nelem - 2;
2071 argv = (char **)wmalloc(argc * sizeof(char *));
2073 /* get the parameters */
2074 argv[0] = wstrdup(func);
2075 for (i = 0; i < argc - 1; i++) {
2076 elem = PLGetArrayElement(pl, 3 + i);
2077 if (!elem || !PLIsString(elem)) {
2078 wfree(argv);
2080 return NULL;
2082 argv[i+1] = wstrdup(PLGetString(elem));
2085 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2087 #ifdef HAVE_DLFCN_H
2088 if (function) {
2089 initFunc = dlsym(function->handle, "initWindowMaker");
2090 if (initFunc) {
2091 initFunc(dpy, scr->w_colormap);
2092 } else {
2093 wwarning(_("could not initialize library %s"), lib);
2095 } else {
2096 wwarning(_("could not find function %s::%s"), lib, func);
2098 #endif /* HAVE_DLFCN_H */
2099 texture = (WTexture*)function;
2101 #endif /* TEXTURE_PLUGIN */
2102 else {
2103 wwarning(_("invalid texture type %s"), val);
2104 return NULL;
2106 return texture;
2111 static int
2112 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2113 void **ret)
2115 static WTexture *texture;
2116 int changed=0;
2118 again:
2119 if (!PLIsArray(value)) {
2120 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2121 entry->key, "Texture");
2122 if (changed==0) {
2123 value = entry->plvalue;
2124 changed = 1;
2125 wwarning(_("using default \"%s\" instead"), entry->default_value);
2126 goto again;
2128 return False;
2131 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2132 proplist_t pl;
2134 pl = PLGetArrayElement(value, 0);
2135 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2136 || strcasecmp(PLGetString(pl), "solid")!=0) {
2137 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2138 entry->key, "Solid Texture");
2140 value = entry->plvalue;
2141 changed = 1;
2142 wwarning(_("using default \"%s\" instead"), entry->default_value);
2143 goto again;
2147 texture = parse_texture(scr, value);
2149 if (!texture) {
2150 wwarning(_("Error in texture specification for key \"%s\""),
2151 entry->key);
2152 if (changed==0) {
2153 value = entry->plvalue;
2154 changed = 1;
2155 wwarning(_("using default \"%s\" instead"), entry->default_value);
2156 goto again;
2158 return False;
2161 if (ret)
2162 *ret = &texture;
2164 if (addr)
2165 *(WTexture**)addr = texture;
2167 return True;
2171 static int
2172 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2173 void *addr, void **ret)
2175 proplist_t elem;
2176 int changed = 0;
2177 char *val;
2178 int nelem;
2180 again:
2181 if (!PLIsArray(value)) {
2182 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2183 "WorkspaceBack", "Texture or None");
2184 if (changed==0) {
2185 value = entry->plvalue;
2186 changed = 1;
2187 wwarning(_("using default \"%s\" instead"), entry->default_value);
2188 goto again;
2190 return False;
2193 /* only do basic error checking and verify for None texture */
2195 nelem = PLGetNumberOfElements(value);
2196 if (nelem > 0) {
2197 elem = PLGetArrayElement(value, 0);
2198 if (!elem || !PLIsString(elem)) {
2199 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2200 if (changed==0) {
2201 value = entry->plvalue;
2202 changed = 1;
2203 wwarning(_("using default \"%s\" instead"), entry->default_value);
2204 goto again;
2206 return False;
2208 val = PLGetString(elem);
2210 if (strcasecmp(val, "None")==0)
2211 return True;
2213 *ret = PLRetain(value);
2215 return True;
2219 static int
2220 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2221 void *addr, void **ret)
2223 proplist_t elem;
2224 int nelem;
2225 int changed = 0;
2227 again:
2228 if (!PLIsArray(value)) {
2229 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2230 "WorkspaceSpecificBack", "an array of textures");
2231 if (changed==0) {
2232 value = entry->plvalue;
2233 changed = 1;
2234 wwarning(_("using default \"%s\" instead"), entry->default_value);
2235 goto again;
2237 return False;
2240 /* only do basic error checking and verify for None texture */
2242 nelem = PLGetNumberOfElements(value);
2243 if (nelem > 0) {
2244 while (nelem--) {
2245 elem = PLGetArrayElement(value, nelem);
2246 if (!elem || !PLIsArray(elem)) {
2247 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2248 nelem);
2253 *ret = PLRetain(value);
2255 #ifdef notworking
2257 * Kluge to force wmsetbg helper to set the default background.
2258 * If the WorkspaceSpecificBack is changed once wmaker has started,
2259 * the WorkspaceBack won't be sent to the helper, unless the user
2260 * changes it's value too. So, we must force this by removing the
2261 * value from the defaults DB.
2263 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2264 proplist_t key = PLMakeString("WorkspaceBack");
2266 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2268 PLRelease(key);
2270 #endif
2271 return True;
2275 static int
2276 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2277 void **ret)
2279 static WMFont *font;
2280 char *val;
2282 GET_STRING_OR_DEFAULT("Font", val);
2284 font = WMCreateFont(scr->wmscreen, val);
2285 if (!font)
2286 font = WMCreateFont(scr->wmscreen, "fixed");
2288 if (!font) {
2289 wfatal(_("could not load any usable font!!!"));
2290 exit(1);
2293 if (ret)
2294 *ret = font;
2296 /* can't assign font value outside update function */
2297 wassertrv(addr == NULL, True);
2299 return True;
2303 static int
2304 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2305 void **ret)
2307 static XColor color;
2308 char *val;
2309 int second_pass=0;
2311 GET_STRING_OR_DEFAULT("Color", val);
2314 again:
2315 if (!wGetColor(scr, val, &color)) {
2316 wwarning(_("could not get color for key \"%s\""),
2317 entry->key);
2318 if (second_pass==0) {
2319 val = PLGetString(entry->plvalue);
2320 second_pass = 1;
2321 wwarning(_("using default \"%s\" instead"), val);
2322 goto again;
2324 return False;
2327 if (ret)
2328 *ret = &color;
2330 assert(addr==NULL);
2332 if (addr)
2333 *(unsigned long*)addr = pixel;
2336 return True;
2341 static int
2342 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2343 void **ret)
2345 static WShortKey shortcut;
2346 KeySym ksym;
2347 char *val;
2348 char *k;
2349 char buf[128], *b;
2352 GET_STRING_OR_DEFAULT("Key spec", val);
2354 if (!val || strcasecmp(val, "NONE")==0) {
2355 shortcut.keycode = 0;
2356 shortcut.modifier = 0;
2357 if (ret)
2358 *ret = &shortcut;
2359 return True;
2362 strcpy(buf, val);
2364 b = (char*)buf;
2366 /* get modifiers */
2367 shortcut.modifier = 0;
2368 while ((k = strchr(b, '+'))!=NULL) {
2369 int mod;
2371 *k = 0;
2372 mod = wXModifierFromKey(b);
2373 if (mod<0) {
2374 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2375 return False;
2377 shortcut.modifier |= mod;
2379 b = k+1;
2382 /* get key */
2383 ksym = XStringToKeysym(b);
2385 if (ksym==NoSymbol) {
2386 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2387 val);
2388 return False;
2391 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2392 if (shortcut.keycode==0) {
2393 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2394 return False;
2397 if (ret)
2398 *ret = &shortcut;
2400 return True;
2404 static int
2405 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2406 void **ret)
2408 static unsigned int mask;
2409 char *str;
2411 GET_STRING_OR_DEFAULT("Modifier Key", str);
2413 if (!str)
2414 return False;
2416 mask = wXModifierFromKey(str);
2417 if (mask < 0) {
2418 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2419 mask = 0;
2420 return False;
2423 if (addr)
2424 *(unsigned int*)addr = mask;
2426 if (ret)
2427 *ret = &mask;
2429 return True;
2433 #ifdef NEWSTUFF
2434 static int
2435 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2436 void *addr, void **ret)
2438 unsigned int mask;
2439 char *str;
2440 RImage *image;
2441 int i, n;
2442 int w, h;
2444 GET_STRING_OR_DEFAULT("Image File Path", str);
2445 if (!str)
2446 return False;
2448 image = RLoadImage(scr->rcontext, str, 0);
2449 if (!image) {
2450 wwarning(_("could not load image in option %s: %s"), entry->key,
2451 RMessageForError(RErrorCode));
2452 return False;
2455 if (*(RImage**)addr) {
2456 RReleaseImage(*(RImage**)addr);
2458 if (addr)
2459 *(RImage**)addr = image;
2461 assert(ret == NULL);
2463 if (ret)
2464 *(RImage**)ret = image;
2467 return True;
2469 #endif
2471 #ifdef DEFINABLE_CURSOR
2473 # include <X11/cursorfont.h>
2474 typedef struct
2476 char *name;
2477 int id;
2478 } WCursorLookup;
2480 #define CURSOR_ID_NONE (XC_num_glyphs)
2482 static WCursorLookup cursor_table[] =
2484 { "X_cursor", XC_X_cursor },
2485 { "arrow", XC_arrow },
2486 { "based_arrow_down", XC_based_arrow_down },
2487 { "based_arrow_up", XC_based_arrow_up },
2488 { "boat", XC_boat },
2489 { "bogosity", XC_bogosity },
2490 { "bottom_left_corner", XC_bottom_left_corner },
2491 { "bottom_right_corner", XC_bottom_right_corner },
2492 { "bottom_side", XC_bottom_side },
2493 { "bottom_tee", XC_bottom_tee },
2494 { "box_spiral", XC_box_spiral },
2495 { "center_ptr", XC_center_ptr },
2496 { "circle", XC_circle },
2497 { "clock", XC_clock },
2498 { "coffee_mug", XC_coffee_mug },
2499 { "cross", XC_cross },
2500 { "cross_reverse", XC_cross_reverse },
2501 { "crosshair", XC_crosshair },
2502 { "diamond_cross", XC_diamond_cross },
2503 { "dot", XC_dot },
2504 { "dotbox", XC_dotbox },
2505 { "double_arrow", XC_double_arrow },
2506 { "draft_large", XC_draft_large },
2507 { "draft_small", XC_draft_small },
2508 { "draped_box", XC_draped_box },
2509 { "exchange", XC_exchange },
2510 { "fleur", XC_fleur },
2511 { "gobbler", XC_gobbler },
2512 { "gumby", XC_gumby },
2513 { "hand1", XC_hand1 },
2514 { "hand2", XC_hand2 },
2515 { "heart", XC_heart },
2516 { "icon", XC_icon },
2517 { "iron_cross", XC_iron_cross },
2518 { "left_ptr", XC_left_ptr },
2519 { "left_side", XC_left_side },
2520 { "left_tee", XC_left_tee },
2521 { "leftbutton", XC_leftbutton },
2522 { "ll_angle", XC_ll_angle },
2523 { "lr_angle", XC_lr_angle },
2524 { "man", XC_man },
2525 { "middlebutton", XC_middlebutton },
2526 { "mouse", XC_mouse },
2527 { "pencil", XC_pencil },
2528 { "pirate", XC_pirate },
2529 { "plus", XC_plus },
2530 { "question_arrow", XC_question_arrow },
2531 { "right_ptr", XC_right_ptr },
2532 { "right_side", XC_right_side },
2533 { "right_tee", XC_right_tee },
2534 { "rightbutton", XC_rightbutton },
2535 { "rtl_logo", XC_rtl_logo },
2536 { "sailboat", XC_sailboat },
2537 { "sb_down_arrow", XC_sb_down_arrow },
2538 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2539 { "sb_left_arrow", XC_sb_left_arrow },
2540 { "sb_right_arrow", XC_sb_right_arrow },
2541 { "sb_up_arrow", XC_sb_up_arrow },
2542 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2543 { "shuttle", XC_shuttle },
2544 { "sizing", XC_sizing },
2545 { "spider", XC_spider },
2546 { "spraycan", XC_spraycan },
2547 { "star", XC_star },
2548 { "target", XC_target },
2549 { "tcross", XC_tcross },
2550 { "top_left_arrow", XC_top_left_arrow },
2551 { "top_left_corner", XC_top_left_corner },
2552 { "top_right_corner", XC_top_right_corner },
2553 { "top_side", XC_top_side },
2554 { "top_tee", XC_top_tee },
2555 { "trek", XC_trek },
2556 { "ul_angle", XC_ul_angle },
2557 { "umbrella", XC_umbrella },
2558 { "ur_angle", XC_ur_angle },
2559 { "watch", XC_watch },
2560 { "xterm", XC_xterm },
2561 { NULL, CURSOR_ID_NONE }
2564 static void
2565 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2567 switch(status) {
2568 case BitmapOpenFailed:
2569 wwarning(_("failed to open bitmap file \"%s\""), filename);
2570 break;
2571 case BitmapFileInvalid:
2572 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2573 break;
2574 case BitmapNoMemory:
2575 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2576 break;
2577 case BitmapSuccess:
2578 XFreePixmap(dpy, bitmap);
2579 break;
2584 * (none)
2585 * (builtin, <cursor_name>)
2586 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2588 static int
2589 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2591 proplist_t elem;
2592 char *val;
2593 int nelem;
2594 int status = 0;
2596 nelem = PLGetNumberOfElements(pl);
2597 if (nelem < 1) {
2598 return(status);
2600 elem = PLGetArrayElement(pl, 0);
2601 if (!elem || !PLIsString(elem)) {
2602 return(status);
2604 val = PLGetString(elem);
2606 if (0 == strcasecmp(val, "none")) {
2607 status = 1;
2608 *cursor = None;
2609 } else if (0 == strcasecmp(val, "builtin")) {
2610 int i;
2611 int cursor_id = CURSOR_ID_NONE;
2613 if (2 != nelem) {
2614 wwarning(_("bad number of arguments in cursor specification"));
2615 return(status);
2617 elem = PLGetArrayElement(pl, 1);
2618 if (!elem || !PLIsString(elem)) {
2619 return(status);
2621 val = PLGetString(elem);
2623 for (i = 0; NULL != cursor_table[i].name; i++) {
2624 if (0 == strcasecmp(val, cursor_table[i].name)) {
2625 cursor_id = cursor_table[i].id;
2626 break;
2629 if (CURSOR_ID_NONE == cursor_id) {
2630 wwarning(_("unknown builtin cursor name \"%s\""), val);
2631 } else {
2632 *cursor = XCreateFontCursor(dpy, cursor_id);
2633 status = 1;
2635 } else if (0 == strcasecmp(val, "bitmap")) {
2636 char *bitmap_name;
2637 char *mask_name;
2638 int bitmap_status;
2639 int mask_status;
2640 Pixmap bitmap;
2641 Pixmap mask;
2642 unsigned int w, h;
2643 int x, y;
2644 XColor fg, bg;
2646 if (3 != nelem) {
2647 wwarning(_("bad number of arguments in cursor specification"));
2648 return(status);
2650 elem = PLGetArrayElement(pl, 1);
2651 if (!elem || !PLIsString(elem)) {
2652 return(status);
2654 val = PLGetString(elem);
2655 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2656 if (!bitmap_name) {
2657 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2658 return(status);
2660 elem = PLGetArrayElement(pl, 2);
2661 if (!elem || !PLIsString(elem)) {
2662 wfree(bitmap_name);
2663 return(status);
2665 val = PLGetString(elem);
2666 mask_name = FindImage(wPreferences.pixmap_path, val);
2667 if (!mask_name) {
2668 wfree(bitmap_name);
2669 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2670 return(status);
2672 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2673 &mask, &x, &y);
2674 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2675 &bitmap, &x, &y);
2676 if ((BitmapSuccess == bitmap_status) &&
2677 (BitmapSuccess == mask_status)) {
2678 fg.pixel = scr->black_pixel;
2679 bg.pixel = scr->white_pixel;
2680 XQueryColor(dpy, scr->w_colormap, &fg);
2681 XQueryColor(dpy, scr->w_colormap, &bg);
2682 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2683 status = 1;
2685 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2686 check_bitmap_status(mask_status, mask_name, mask);
2687 wfree(bitmap_name);
2688 wfree(mask_name);
2690 return(status);
2694 static int
2695 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2696 void **ret)
2698 static Cursor cursor;
2699 int status;
2700 int changed = 0;
2702 again:
2703 if (!PLIsArray(value)) {
2704 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2705 entry->key, "cursor specification");
2706 if (!changed) {
2707 value = entry->plvalue;
2708 changed = 1;
2709 wwarning(_("using default \"%s\" instead"), entry->default_value);
2710 goto again;
2712 return(False);
2714 status = parse_cursor(scr, value, &cursor);
2715 if (!status) {
2716 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2717 if (!changed) {
2718 value = entry->plvalue;
2719 changed = 1;
2720 wwarning(_("using default \"%s\" instead"), entry->default_value);
2721 goto again;
2723 return(False);
2725 if (ret) {
2726 *ret = &cursor;
2728 if (addr) {
2729 *(Cursor *)addr = cursor;
2731 return(True);
2733 #undef CURSOR_ID_NONE
2735 #endif /* DEFINABLE_CURSOR */
2738 /* ---------------- value setting functions --------------- */
2739 static int
2740 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2742 return REFRESH_WINDOW_TITLE_COLOR;
2745 static int
2746 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2748 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2751 static int
2752 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2754 switch (which) {
2755 case WM_DOCK:
2756 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2757 break;
2758 case WM_CLIP:
2759 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2760 break;
2761 default:
2762 break;
2764 return 0;
2768 static int
2769 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2771 if (scr->workspaces) {
2772 wWorkspaceForceChange(scr, scr->current_workspace);
2773 wArrangeIcons(scr, False);
2775 return 0;
2778 #if not_used
2779 static int
2780 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2782 if (*value <= 0)
2783 *(int*)foo = 1;
2785 return 0;
2787 #endif
2791 static int
2792 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2794 Pixmap pixmap;
2795 RImage *img;
2796 int reset = 0;
2798 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2799 wPreferences.icon_size,
2800 ((*texture)->any.type & WREL_BORDER_MASK)
2801 ? WREL_ICON : WREL_FLAT);
2802 if (!img) {
2803 wwarning(_("could not render texture for icon background"));
2804 if (!entry->addr)
2805 wTextureDestroy(scr, *texture);
2806 return 0;
2808 RConvertImage(scr->rcontext, img, &pixmap);
2810 if (scr->icon_tile) {
2811 reset = 1;
2812 RReleaseImage(scr->icon_tile);
2813 XFreePixmap(dpy, scr->icon_tile_pixmap);
2816 scr->icon_tile = img;
2819 /* put the icon in the noticeboard hint */
2820 PropSetIconTileHint(scr, img);
2823 if (!wPreferences.flags.noclip) {
2824 if (scr->clip_tile) {
2825 RReleaseImage(scr->clip_tile);
2827 scr->clip_tile = wClipMakeTile(scr, img);
2830 scr->icon_tile_pixmap = pixmap;
2832 if (scr->def_icon_pixmap) {
2833 XFreePixmap(dpy, scr->def_icon_pixmap);
2834 scr->def_icon_pixmap = None;
2836 if (scr->def_ticon_pixmap) {
2837 XFreePixmap(dpy, scr->def_ticon_pixmap);
2838 scr->def_ticon_pixmap = None;
2841 if (scr->icon_back_texture) {
2842 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2844 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2846 if (scr->clip_balloon)
2847 XSetWindowBackground(dpy, scr->clip_balloon,
2848 (*texture)->any.color.pixel);
2851 * Free the texture as nobody else will use it, nor refer to it.
2853 if (!entry->addr)
2854 wTextureDestroy(scr, *texture);
2856 return (reset ? REFRESH_ICON_TILE : 0);
2861 static int
2862 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2864 if (scr->title_font) {
2865 WMReleaseFont(scr->title_font);
2867 scr->title_font = font;
2869 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2873 static int
2874 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2876 if (scr->menu_title_font) {
2877 WMReleaseFont(scr->menu_title_font);
2880 scr->menu_title_font = font;
2882 return REFRESH_MENU_TITLE_FONT;
2886 static int
2887 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2889 if (scr->menu_entry_font) {
2890 WMReleaseFont(scr->menu_entry_font);
2892 scr->menu_entry_font = font;
2894 return REFRESH_MENU_FONT;
2899 static int
2900 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2902 if (scr->icon_title_font) {
2903 WMReleaseFont(scr->icon_title_font);
2906 scr->icon_title_font = font;
2908 return REFRESH_ICON_FONT;
2912 static int
2913 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2915 if (scr->clip_title_font) {
2916 WMReleaseFont(scr->clip_title_font);
2919 scr->clip_title_font = font;
2921 return REFRESH_ICON_FONT;
2925 static int
2926 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2928 if (scr->workspace_name_font) {
2929 WMReleaseFont(scr->workspace_name_font);
2932 scr->workspace_name_font = font;
2934 return 0;
2938 static int
2939 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2941 if (scr->select_pixel!=scr->white_pixel &&
2942 scr->select_pixel!=scr->black_pixel) {
2943 wFreeColor(scr, scr->select_pixel);
2946 scr->select_pixel = color->pixel;
2948 return REFRESH_MENU_COLOR;
2952 static int
2953 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2955 if (scr->select_text_pixel!=scr->white_pixel &&
2956 scr->select_text_pixel!=scr->black_pixel) {
2957 wFreeColor(scr, scr->select_text_pixel);
2960 scr->select_text_pixel = color->pixel;
2962 return REFRESH_MENU_COLOR;
2966 static int
2967 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2969 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2970 scr->clip_title_pixel[index]!=scr->black_pixel) {
2971 wFreeColor(scr, scr->clip_title_pixel[index]);
2973 scr->clip_title_pixel[index] = color->pixel;
2975 #ifdef GRADIENT_CLIP_ARROW
2976 if (index == CLIP_NORMAL) {
2977 RImage *image;
2978 RColor color1, color2;
2979 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2980 int as = pt - 15; /* 15 = 5+5+5 */
2982 FREE_PIXMAP(scr->clip_arrow_gradient);
2984 color1.red = (color->red >> 8)*6/10;
2985 color1.green = (color->green >> 8)*6/10;
2986 color1.blue = (color->blue >> 8)*6/10;
2988 color2.red = WMIN((color->red >> 8)*20/10, 255);
2989 color2.green = WMIN((color->green >> 8)*20/10, 255);
2990 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2992 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2993 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2994 RReleaseImage(image);
2996 #endif /* GRADIENT_CLIP_ARROW */
2998 return REFRESH_ICON_TITLE_COLOR;
3002 static int
3003 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3005 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3006 scr->window_title_pixel[index]!=scr->black_pixel) {
3007 wFreeColor(scr, scr->window_title_pixel[index]);
3010 scr->window_title_pixel[index] = color->pixel;
3012 if (index == WS_UNFOCUSED)
3013 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3015 return REFRESH_WINDOW_TITLE_COLOR;
3019 static int
3020 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3022 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3023 scr->menu_title_pixel[0]!=scr->black_pixel) {
3024 wFreeColor(scr, scr->menu_title_pixel[0]);
3027 scr->menu_title_pixel[0] = color->pixel;
3028 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3030 return REFRESH_MENU_TITLE_COLOR;
3034 static int
3035 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3037 XGCValues gcv;
3038 #define gcm (GCForeground|GCBackground|GCFillStyle)
3040 if (scr->mtext_pixel!=scr->white_pixel &&
3041 scr->mtext_pixel!=scr->black_pixel) {
3042 wFreeColor(scr, scr->mtext_pixel);
3045 scr->mtext_pixel = color->pixel;
3047 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3050 if (scr->dtext_pixel == scr->mtext_pixel) {
3051 gcv.foreground = scr->white_pixel;
3052 gcv.background = scr->black_pixel;
3053 gcv.fill_style = FillStippled;
3054 } else {
3055 gcv.foreground = scr->dtext_pixel;
3056 gcv.fill_style = FillSolid;
3058 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3060 return REFRESH_MENU_COLOR;
3061 #undef gcm
3065 static int
3066 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3068 XGCValues gcv;
3069 #define gcm (GCForeground|GCBackground|GCFillStyle)
3071 if (scr->dtext_pixel!=scr->white_pixel &&
3072 scr->dtext_pixel!=scr->black_pixel) {
3073 wFreeColor(scr, scr->dtext_pixel);
3076 scr->dtext_pixel = color->pixel;
3078 if (scr->dtext_pixel == scr->mtext_pixel) {
3079 gcv.foreground = scr->white_pixel;
3080 gcv.background = scr->black_pixel;
3081 gcv.fill_style = FillStippled;
3082 } else {
3083 gcv.foreground = scr->dtext_pixel;
3084 gcv.fill_style = FillSolid;
3086 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3088 return REFRESH_MENU_COLOR;
3089 #undef gcm
3092 static int
3093 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3095 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3097 return REFRESH_ICON_TITLE_COLOR;
3101 static int
3102 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3104 if (scr->icon_title_texture) {
3105 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3107 XQueryColor (dpy, scr->w_colormap, color);
3108 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3110 return REFRESH_ICON_TITLE_BACK;
3114 static void
3115 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3117 close(scr->helper_fd);
3118 scr->helper_fd = 0;
3119 scr->helper_pid = 0;
3120 scr->flags.backimage_helper_launched = 0;
3124 static int
3125 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3126 void *bar)
3128 int i;
3129 proplist_t val;
3130 char *str;
3132 if (scr->flags.backimage_helper_launched) {
3133 if (PLGetNumberOfElements(value)==0) {
3134 SendHelperMessage(scr, 'C', 0, NULL);
3135 SendHelperMessage(scr, 'K', 0, NULL);
3137 PLRelease(value);
3138 return 0;
3140 } else {
3141 pid_t pid;
3142 int filedes[2];
3144 if (PLGetNumberOfElements(value) == 0)
3145 return 0;
3147 if (pipe(filedes) < 0) {
3148 wsyserror("pipe() failed:can't set workspace specific background image");
3150 PLRelease(value);
3151 return 0;
3154 pid = fork();
3155 if (pid < 0) {
3156 wsyserror("fork() failed:can't set workspace specific background image");
3157 if (close(filedes[0]) < 0)
3158 wsyserror("could not close pipe");
3159 if (close(filedes[1]) < 0)
3160 wsyserror("could not close pipe");
3162 } else if (pid == 0) {
3163 char *dither;
3165 SetupEnvironment(scr);
3167 if (close(0) < 0)
3168 wsyserror("could not close pipe");
3169 if (dup(filedes[0]) < 0) {
3170 wsyserror("dup() failed:can't set workspace specific background image");
3172 dither = wPreferences.no_dithering ? "-m" : "-d";
3173 if (wPreferences.smooth_workspace_back)
3174 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3175 else
3176 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3177 wsyserror("could not execute wmsetbg");
3178 exit(1);
3179 } else {
3181 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3182 wsyserror("error setting close-on-exec flag");
3184 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3185 wsyserror("error setting close-on-exec flag");
3188 scr->helper_fd = filedes[1];
3189 scr->helper_pid = pid;
3190 scr->flags.backimage_helper_launched = 1;
3192 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3194 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3199 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3200 val = PLGetArrayElement(value, i);
3201 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3202 str = PLGetDescription(val);
3204 SendHelperMessage(scr, 'S', i+1, str);
3206 wfree(str);
3207 } else {
3208 SendHelperMessage(scr, 'U', i+1, NULL);
3211 sleep(1);
3213 PLRelease(value);
3214 return 0;
3218 static int
3219 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3220 void *bar)
3222 if (scr->flags.backimage_helper_launched) {
3223 char *str;
3225 if (PLGetNumberOfElements(value)==0) {
3226 SendHelperMessage(scr, 'U', 0, NULL);
3227 } else {
3228 /* set the default workspace background to this one */
3229 str = PLGetDescription(value);
3230 if (str) {
3231 SendHelperMessage(scr, 'S', 0, str);
3232 wfree(str);
3233 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3234 } else {
3235 SendHelperMessage(scr, 'U', 0, NULL);
3238 } else if (PLGetNumberOfElements(value) > 0) {
3239 char *command;
3240 char *text;
3241 char *dither;
3243 SetupEnvironment(scr);
3244 text = PLGetDescription(value);
3245 command = wmalloc(strlen(text)+40);
3246 dither = wPreferences.no_dithering ? "-m" : "-d";
3247 if (wPreferences.smooth_workspace_back)
3248 sprintf(command, "wmsetbg %s -S -p '%s' &", dither, text);
3249 else
3250 sprintf(command, "wmsetbg %s -p '%s' &", dither, text);
3251 wfree(text);
3252 system(command);
3253 wfree(command);
3255 PLRelease(value);
3257 return 0;
3261 static int
3262 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3264 if (scr->widget_texture) {
3265 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3267 scr->widget_texture = *(WTexSolid**)texture;
3269 return 0;
3273 static int
3274 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3276 if (scr->window_title_texture[WS_FOCUSED]) {
3277 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3279 scr->window_title_texture[WS_FOCUSED] = *texture;
3281 return REFRESH_WINDOW_TEXTURES;
3285 static int
3286 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3288 if (scr->window_title_texture[WS_PFOCUSED]) {
3289 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3291 scr->window_title_texture[WS_PFOCUSED] = *texture;
3293 return REFRESH_WINDOW_TEXTURES;
3297 static int
3298 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3300 if (scr->window_title_texture[WS_UNFOCUSED]) {
3301 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3303 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3305 return REFRESH_WINDOW_TEXTURES;
3309 static int
3310 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3312 if (scr->resizebar_texture[0]) {
3313 wTextureDestroy(scr, scr->resizebar_texture[0]);
3315 scr->resizebar_texture[0] = *texture;
3317 return REFRESH_WINDOW_TEXTURES;
3321 static int
3322 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3324 if (scr->menu_title_texture[0]) {
3325 wTextureDestroy(scr, scr->menu_title_texture[0]);
3327 scr->menu_title_texture[0] = *texture;
3329 return REFRESH_MENU_TITLE_TEXTURE;
3333 static int
3334 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3336 if (scr->menu_item_texture) {
3337 wTextureDestroy(scr, scr->menu_item_texture);
3338 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3340 scr->menu_item_texture = *texture;
3342 scr->menu_item_auxtexture
3343 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3345 return REFRESH_MENU_TEXTURE;
3349 static int
3350 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3352 WWindow *wwin;
3353 wKeyBindings[index] = *shortcut;
3355 wwin = scr->focused_window;
3357 while (wwin!=NULL) {
3358 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3360 if (!WFLAGP(wwin, no_bind_keys)) {
3361 wWindowSetKeyGrabs(wwin);
3363 wwin = wwin->prev;
3366 return 0;
3370 static int
3371 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3373 wArrangeIcons(scr, True);
3375 return 0;
3379 static int
3380 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3382 wScreenUpdateUsableArea(scr);
3384 return 0;
3388 static int
3389 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3391 return REFRESH_MENU_TEXTURE;
3396 static int
3397 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3399 return REFRESH_BUTTON_IMAGES;
3404 * Very ugly kluge.
3405 * Need access to the double click variables, so that all widgets in
3406 * wmaker panels will have the same dbl-click values.
3407 * TODO: figure a better way of dealing with it.
3409 #include <WINGs/WINGsP.h>
3411 static int
3412 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3414 extern _WINGsConfiguration WINGsConfiguration;
3416 if (*value <= 0)
3417 *(int*)foo = 1;
3419 WINGsConfiguration.doubleClickDelay = *value;
3421 return 0;
3425 #if 0
3426 static int
3427 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3429 extern _WINGsConfiguration WINGsConfiguration;
3431 WINGsConfiguration.useMultiByte = *value;
3433 return 0;
3435 #endif
3437 #ifdef DEFINABLE_CURSOR
3438 static int
3439 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3441 if (None != wCursor[index])
3443 XFreeCursor(dpy, wCursor[index]);
3446 wCursor[index] = *cursor;
3448 if ((WCUR_ROOT == index) && (None != *cursor))
3450 XDefineCursor(dpy, scr->root_win, *cursor);
3453 return 0;
3455 #endif /* DEFINABLE_CURSOR*/