Prevent crash when switchpanel is not initialised.
[wmaker-crm.git] / src / defaults.c
blob25d7feecc5f9d5d118f627e2ee63f7d559e5137e
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
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 along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <strings.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifndef PATH_MAX
40 #define PATH_MAX DEFAULT_PATH_MAX
41 #endif
43 #include <X11/Xlib.h>
44 #include <X11/Xutil.h>
45 #include <X11/keysym.h>
47 #include <wraster.h>
49 #include "WindowMaker.h"
50 #include "framewin.h"
51 #include "window.h"
52 #include "texture.h"
53 #include "screen.h"
54 #include "resources.h"
55 #include "defaults.h"
56 #include "keybind.h"
57 #include "xmodifier.h"
58 #include "icon.h"
59 #include "main.h"
60 #include "actions.h"
61 #include "dock.h"
62 #include "workspace.h"
63 #include "properties.h"
64 #include "misc.h"
66 #define MAX_SHORTCUT_LENGTH 32
68 #ifndef GLOBAL_DEFAULTS_SUBDIR
69 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
70 #endif
72 /***** Global *****/
73 extern WDDomain *WDWindowMaker;
74 extern WDDomain *WDWindowAttributes;
75 extern WDDomain *WDRootMenu;
76 extern int wScreenCount;
77 extern WPreferences wPreferences;
78 extern WShortKey wKeyBindings[WKBD_LAST];
80 typedef struct {
81 char *key;
82 char *default_value;
83 void *extra_data;
84 void *addr;
85 int (*convert) ();
86 int (*update) ();
87 WMPropList *plkey;
88 WMPropList *plvalue; /* default value */
89 } WDefaultEntry;
91 /* used to map strings to integers */
92 typedef struct {
93 char *string;
94 short value;
95 char is_alias;
96 } WOptionEnumeration;
98 /* type converters */
99 static int getBool();
100 static int getInt();
101 static int getCoord();
102 static int getPathList();
103 static int getEnum();
104 static int getTexture();
105 static int getWSBackground();
106 static int getWSSpecificBackground();
107 static int getFont();
108 static int getColor();
109 static int getKeybind();
110 static int getModMask();
111 static int getPropList();
113 /* value setting functions */
114 static int setJustify();
115 static int setClearance();
116 static int setIfDockPresent();
117 static int setClipMergedInDock();
118 static int setWrapAppiconsInDock();
119 static int setStickyIcons();
120 static int setWidgetColor();
121 static int setIconTile();
122 static int setWinTitleFont();
123 static int setMenuTitleFont();
124 static int setMenuTextFont();
125 static int setIconTitleFont();
126 static int setIconTitleColor();
127 static int setIconTitleBack();
128 static int setFrameBorderWidth();
129 static int setFrameBorderColor();
130 static int setFrameSelectedBorderColor();
131 static int setLargeDisplayFont();
132 static int setWTitleColor();
133 static int setFTitleBack();
134 static int setPTitleBack();
135 static int setUTitleBack();
136 static int setResizebarBack();
137 static int setWorkspaceBack();
138 static int setWorkspaceSpecificBack();
139 static int setMenuTitleColor();
140 static int setMenuTextColor();
141 static int setMenuDisabledColor();
142 static int setMenuTitleBack();
143 static int setMenuTextBack();
144 static int setHightlight();
145 static int setHightlightText();
146 static int setKeyGrab();
147 static int setDoubleClick();
148 static int setIconPosition();
150 static int setClipTitleFont();
151 static int setClipTitleColor();
153 static int setMenuStyle();
154 static int setSwPOptions();
155 static int updateUsableArea();
157 static int setModifierKeyLabels();
159 extern Cursor wCursor[WCUR_LAST];
160 static int getCursor();
161 static int setCursor();
164 * Tables to convert strings to enumeration values.
165 * Values stored are char
168 /* WARNING: sum of length of all value strings must not exceed
169 * this value */
170 #define TOTAL_VALUES_LENGTH 80
172 #define REFRESH_WINDOW_TEXTURES (1<<0)
173 #define REFRESH_MENU_TEXTURE (1<<1)
174 #define REFRESH_MENU_FONT (1<<2)
175 #define REFRESH_MENU_COLOR (1<<3)
176 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
177 #define REFRESH_MENU_TITLE_FONT (1<<5)
178 #define REFRESH_MENU_TITLE_COLOR (1<<6)
179 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
180 #define REFRESH_WINDOW_FONT (1<<8)
181 #define REFRESH_ICON_TILE (1<<9)
182 #define REFRESH_ICON_FONT (1<<10)
183 #define REFRESH_WORKSPACE_BACK (1<<11)
185 #define REFRESH_BUTTON_IMAGES (1<<12)
187 #define REFRESH_ICON_TITLE_COLOR (1<<13)
188 #define REFRESH_ICON_TITLE_BACK (1<<14)
190 #define REFRESH_WORKSPACE_MENU (1<<15)
192 #define REFRESH_FRAME_BORDER REFRESH_MENU_FONT|REFRESH_WINDOW_FONT
194 static WOptionEnumeration seFocusModes[] = {
195 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
196 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
197 {NULL, 0, 0}
200 static WOptionEnumeration seTitlebarModes[] = {
201 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
202 {"next", TS_NEXT, 0}, {NULL, 0, 0}
205 static WOptionEnumeration seColormapModes[] = {
206 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
207 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
208 {NULL, 0, 0}
211 static WOptionEnumeration sePlacements[] = {
212 {"Auto", WPM_AUTO, 0},
213 {"Smart", WPM_SMART, 0},
214 {"Cascade", WPM_CASCADE, 0},
215 {"Random", WPM_RANDOM, 0},
216 {"Manual", WPM_MANUAL, 0},
217 {"Center", WPM_CENTER, 0},
218 {NULL, 0, 0}
221 static WOptionEnumeration seGeomDisplays[] = {
222 {"None", WDIS_NONE, 0},
223 {"Center", WDIS_CENTER, 0},
224 {"Corner", WDIS_TOPLEFT, 0},
225 {"Floating", WDIS_FRAME_CENTER, 0},
226 {"Line", WDIS_NEW, 0},
227 {NULL, 0, 0}
230 static WOptionEnumeration seSpeeds[] = {
231 {"UltraFast", SPEED_ULTRAFAST, 0},
232 {"Fast", SPEED_FAST, 0},
233 {"Medium", SPEED_MEDIUM, 0},
234 {"Slow", SPEED_SLOW, 0},
235 {"UltraSlow", SPEED_ULTRASLOW, 0},
236 {NULL, 0, 0}
239 static WOptionEnumeration seMouseButtonActions[] = {
240 {"None", WA_NONE, 0},
241 {"SelectWindows", WA_SELECT_WINDOWS, 0},
242 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
243 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
244 {NULL, 0, 0}
247 static WOptionEnumeration seMouseWheelActions[] = {
248 {"None", WA_NONE, 0},
249 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
250 {NULL, 0, 0}
253 static WOptionEnumeration seIconificationStyles[] = {
254 {"Zoom", WIS_ZOOM, 0},
255 {"Twist", WIS_TWIST, 0},
256 {"Flip", WIS_FLIP, 0},
257 {"None", WIS_NONE, 0},
258 {"random", WIS_RANDOM, 0},
259 {NULL, 0, 0}
262 static WOptionEnumeration seJustifications[] = {
263 {"Left", WTJ_LEFT, 0},
264 {"Center", WTJ_CENTER, 0},
265 {"Right", WTJ_RIGHT, 0},
266 {NULL, 0, 0}
269 static WOptionEnumeration seIconPositions[] = {
270 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
271 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
272 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
273 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
274 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
275 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
276 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
277 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
278 {NULL, 0, 0}
281 static WOptionEnumeration seMenuStyles[] = {
282 {"normal", MS_NORMAL, 0},
283 {"singletexture", MS_SINGLE_TEXTURE, 0},
284 {"flat", MS_FLAT, 0},
285 {NULL, 0, 0}
288 static WOptionEnumeration seDisplayPositions[] = {
289 {"none", WD_NONE, 0},
290 {"center", WD_CENTER, 0},
291 {"top", WD_TOP, 0},
292 {"bottom", WD_BOTTOM, 0},
293 {"topleft", WD_TOPLEFT, 0},
294 {"topright", WD_TOPRIGHT, 0},
295 {"bottomleft", WD_BOTTOMLEFT, 0},
296 {"bottomright", WD_BOTTOMRIGHT, 0},
297 {NULL, 0, 0}
300 static WOptionEnumeration seWorkspaceBorder[] = {
301 {"None", WB_NONE, 0},
302 {"LeftRight", WB_LEFTRIGHT, 0},
303 {"TopBottom", WB_TOPBOTTOM, 0},
304 {"AllDirections", WB_ALLDIRS, 0},
305 {NULL, 0, 0}
309 * ALL entries in the tables bellow, NEED to have a default value
310 * defined, and this value needs to be correct.
313 /* these options will only affect the window manager on startup
315 * static defaults can't access the screen data, because it is
316 * created after these defaults are read
318 WDefaultEntry staticOptionList[] = {
320 {"ColormapSize", "4", NULL,
321 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
322 {"DisableDithering", "NO", NULL,
323 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
324 {"IconSize", "64", NULL,
325 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
326 {"ModifierKey", "Mod1", NULL,
327 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
328 {"DisableWSMouseActions", "NO", NULL,
329 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
330 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
331 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
332 {"NewStyle", "new", seTitlebarModes,
333 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
334 {"DisableDock", "NO", (void *)WM_DOCK,
335 NULL, getBool, setIfDockPresent, NULL, NULL},
336 {"DisableClip", "NO", (void *)WM_CLIP,
337 NULL, getBool, setIfDockPresent, NULL, NULL},
338 {"DisableDrawers", "NO", (void *)WM_DRAWER,
339 NULL, getBool, setIfDockPresent, NULL, NULL},
340 {"ClipMergedInDock", "NO", NULL,
341 NULL, getBool, setClipMergedInDock, NULL, NULL},
342 {"DisableMiniwindows", "NO", NULL,
343 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
346 #define NUM2STRING_(x) #x
347 #define NUM2STRING(x) NUM2STRING_(x)
349 WDefaultEntry optionList[] = {
351 /* dynamic options */
353 {"IconPosition", "blh", seIconPositions,
354 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
355 {"IconificationStyle", "Zoom", seIconificationStyles,
356 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
357 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
358 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
359 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
360 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
361 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
362 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
363 {"MouseWheelAction", "None", seMouseWheelActions,
364 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
365 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
366 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
367 {"IconPath", DEF_ICON_PATHS, NULL,
368 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
369 {"ColormapMode", "auto", seColormapModes,
370 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
371 {"AutoFocus", "NO", NULL,
372 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
373 {"RaiseDelay", "0", NULL,
374 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
375 {"CirculateRaise", "NO", NULL,
376 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
377 {"Superfluous", "NO", NULL,
378 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
379 {"AdvanceToNewWorkspace", "NO", NULL,
380 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
381 {"CycleWorkspaces", "NO", NULL,
382 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
383 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
384 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
385 {"WorkspaceBorder", "None", seWorkspaceBorder,
386 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
387 {"WorkspaceBorderSize", "0", NULL,
388 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
389 {"StickyIcons", "NO", NULL,
390 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
391 {"SaveSessionOnExit", "NO", NULL,
392 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
393 {"WrapMenus", "NO", NULL,
394 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
395 {"ScrollableMenus", "NO", NULL,
396 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
397 {"MenuScrollSpeed", "medium", seSpeeds,
398 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
399 {"IconSlideSpeed", "medium", seSpeeds,
400 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
401 {"ShadeSpeed", "medium", seSpeeds,
402 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
403 {"BounceAppIconsWhenUrgent", "YES", NULL,
404 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
405 {"RaiseAppIconsWhenBouncing", "NO", NULL,
406 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
407 {"DoNotMakeAppIconsBounce", "NO", NULL,
408 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
409 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
410 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
411 {"ClipAutoraiseDelay", "600", NULL,
412 &wPreferences.clip_auto_raise_delay, getInt, NULL, NULL, NULL},
413 {"ClipAutolowerDelay", "1000", NULL,
414 &wPreferences.clip_auto_lower_delay, getInt, NULL, NULL, NULL},
415 {"ClipAutoexpandDelay", "600", NULL,
416 &wPreferences.clip_auto_expand_delay, getInt, NULL, NULL, NULL},
417 {"ClipAutocollapseDelay", "1000", NULL,
418 &wPreferences.clip_auto_collapse_delay, getInt, NULL, NULL, NULL},
419 {"WrapAppiconsInDock", "YES", NULL,
420 NULL, getBool, setWrapAppiconsInDock, NULL, NULL},
421 {"AlignSubmenus", "NO", NULL,
422 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
423 {"ViKeyMenus", "NO", NULL,
424 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
425 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
426 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
427 {"WindowPlacement", "auto", sePlacements,
428 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
429 {"IgnoreFocusClick", "NO", NULL,
430 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
431 {"UseSaveUnders", "NO", NULL,
432 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
433 {"OpaqueMove", "NO", NULL,
434 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
435 {"OpaqueResize", "NO", NULL,
436 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
437 {"OpaqueMoveResizeKeyboard", "NO", NULL,
438 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
439 {"DisableAnimations", "NO", NULL,
440 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
441 {"DontLinkWorkspaces", "NO", NULL,
442 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
443 {"HighlightActiveApp", "YES", NULL,
444 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
445 {"AutoArrangeIcons", "NO", NULL,
446 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
447 {"NoWindowOverDock", "NO", NULL,
448 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
449 {"NoWindowOverIcons", "NO", NULL,
450 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
451 {"WindowPlaceOrigin", "(0, 0)", NULL,
452 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
453 {"ResizeDisplay", "corner", seGeomDisplays,
454 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
455 {"MoveDisplay", "corner", seGeomDisplays,
456 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
457 {"DontConfirmKill", "NO", NULL,
458 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
459 {"WindowTitleBalloons", "NO", NULL,
460 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
461 {"MiniwindowTitleBalloons", "NO", NULL,
462 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
463 {"AppIconBalloons", "NO", NULL,
464 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
465 {"HelpBalloons", "NO", NULL,
466 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
467 {"EdgeResistance", "30", NULL,
468 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
469 {"ResizeIncrement", "0", NULL,
470 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
471 {"Attraction", "NO", NULL,
472 &wPreferences.attract, getBool, NULL, NULL, NULL},
473 {"DisableBlinking", "NO", NULL,
474 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
475 {"SingleClickLaunch", "NO", NULL,
476 &wPreferences.single_click, getBool, NULL, NULL, NULL},
477 {"StrictWindozeCycle", "YES", NULL,
478 &wPreferences.strict_windoze_cycle, getBool, NULL, NULL, NULL},
480 /* style options */
482 {"MenuStyle", "normal", seMenuStyles,
483 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
484 {"WidgetColor", "(solid, gray)", NULL,
485 NULL, getTexture, setWidgetColor, NULL, NULL},
486 {"WorkspaceSpecificBack", "()", NULL,
487 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
488 /* WorkspaceBack must come after WorkspaceSpecificBack or
489 * WorkspaceBack wont know WorkspaceSpecificBack was also
490 * specified and 2 copies of wmsetbg will be launched */
491 {"WorkspaceBack", "(solid, black)", NULL,
492 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
493 {"SmoothWorkspaceBack", "NO", NULL,
494 NULL, getBool, NULL, NULL, NULL},
495 {"IconBack", "(solid, gray)", NULL,
496 NULL, getTexture, setIconTile, NULL, NULL},
497 {"TitleJustify", "center", seJustifications,
498 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
499 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
500 NULL, getFont, setWinTitleFont, NULL, NULL},
501 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
502 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
503 {"WindowTitleMinHeight", "0", NULL,
504 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
505 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
506 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
507 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
508 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
509 {"MenuTitleMinHeight", "0", NULL,
510 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
511 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
512 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
513 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
514 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
515 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
516 NULL, getFont, setMenuTitleFont, NULL, NULL},
517 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
518 NULL, getFont, setMenuTextFont, NULL, NULL},
519 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
520 NULL, getFont, setIconTitleFont, NULL, NULL},
521 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
522 NULL, getFont, setClipTitleFont, NULL, NULL},
523 {"ShowClipTitle", "YES", NULL,
524 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
525 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
526 NULL, getFont, setLargeDisplayFont, NULL, NULL},
527 {"HighlightColor", "white", NULL,
528 NULL, getColor, setHightlight, NULL, NULL},
529 {"HighlightTextColor", "black", NULL,
530 NULL, getColor, setHightlightText, NULL, NULL},
531 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
532 NULL, getColor, setClipTitleColor, NULL, NULL},
533 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
534 NULL, getColor, setClipTitleColor, NULL, NULL},
535 {"FTitleColor", "white", (void *)WS_FOCUSED,
536 NULL, getColor, setWTitleColor, NULL, NULL},
537 {"PTitleColor", "white", (void *)WS_PFOCUSED,
538 NULL, getColor, setWTitleColor, NULL, NULL},
539 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
540 NULL, getColor, setWTitleColor, NULL, NULL},
541 {"FTitleBack", "(solid, black)", NULL,
542 NULL, getTexture, setFTitleBack, NULL, NULL},
543 {"PTitleBack", "(solid, \"#616161\")", NULL,
544 NULL, getTexture, setPTitleBack, NULL, NULL},
545 {"UTitleBack", "(solid, gray)", NULL,
546 NULL, getTexture, setUTitleBack, NULL, NULL},
547 {"ResizebarBack", "(solid, gray)", NULL,
548 NULL, getTexture, setResizebarBack, NULL, NULL},
549 {"MenuTitleColor", "white", NULL,
550 NULL, getColor, setMenuTitleColor, NULL, NULL},
551 {"MenuTextColor", "black", NULL,
552 NULL, getColor, setMenuTextColor, NULL, NULL},
553 {"MenuDisabledColor", "\"#616161\"", NULL,
554 NULL, getColor, setMenuDisabledColor, NULL, NULL},
555 {"MenuTitleBack", "(solid, black)", NULL,
556 NULL, getTexture, setMenuTitleBack, NULL, NULL},
557 {"MenuTextBack", "(solid, gray)", NULL,
558 NULL, getTexture, setMenuTextBack, NULL, NULL},
559 {"IconTitleColor", "white", NULL,
560 NULL, getColor, setIconTitleColor, NULL, NULL},
561 {"IconTitleBack", "black", NULL,
562 NULL, getColor, setIconTitleBack, NULL, NULL},
563 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
564 NULL, getPropList, setSwPOptions, NULL, NULL},
565 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
566 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
567 {"FrameBorderWidth", "1", NULL,
568 NULL, getInt, setFrameBorderWidth, NULL, NULL},
569 {"FrameBorderColor", "black", NULL,
570 NULL, getColor, setFrameBorderColor, NULL, NULL},
571 {"FrameSelectedBorderColor", "white", NULL,
572 NULL, getColor, setFrameSelectedBorderColor, NULL, NULL},
574 /* keybindings */
576 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
577 NULL, getKeybind, setKeyGrab, NULL, NULL},
578 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
579 NULL, getKeybind, setKeyGrab, NULL, NULL},
580 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
581 NULL, getKeybind, setKeyGrab, NULL, NULL},
582 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
583 NULL, getKeybind, setKeyGrab, NULL, NULL},
584 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
585 NULL, getKeybind, setKeyGrab, NULL, NULL},
586 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
587 NULL, getKeybind, setKeyGrab, NULL, NULL},
588 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
589 NULL, getKeybind, setKeyGrab, NULL, NULL },
590 {"HideKey", "None", (void *)WKBD_HIDE,
591 NULL, getKeybind, setKeyGrab, NULL, NULL},
592 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
593 NULL, getKeybind, setKeyGrab, NULL, NULL},
594 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
595 NULL, getKeybind, setKeyGrab, NULL, NULL},
596 {"CloseKey", "None", (void *)WKBD_CLOSE,
597 NULL, getKeybind, setKeyGrab, NULL, NULL},
598 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
599 NULL, getKeybind, setKeyGrab, NULL, NULL},
600 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
601 NULL, getKeybind, setKeyGrab, NULL, NULL},
602 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
603 NULL, getKeybind, setKeyGrab, NULL, NULL},
604 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
605 NULL, getKeybind, setKeyGrab, NULL, NULL},
606 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
607 NULL, getKeybind, setKeyGrab, NULL, NULL},
608 {"THMaximizeKey", "None", (void*)WKBD_THMAXIMIZE,
609 NULL, getKeybind, setKeyGrab, NULL, NULL},
610 {"BHMaximizeKey", "None", (void*)WKBD_BHMAXIMIZE,
611 NULL, getKeybind, setKeyGrab, NULL, NULL},
612 {"LTCMaximizeKey", "None", (void*)WKBD_LTCMAXIMIZE,
613 NULL, getKeybind, setKeyGrab, NULL, NULL},
614 {"RTCMaximizeKey", "None", (void*)WKBD_RTCMAXIMIZE,
615 NULL, getKeybind, setKeyGrab, NULL, NULL},
616 {"LBCMaximizeKey", "None", (void*)WKBD_LBCMAXIMIZE,
617 NULL, getKeybind, setKeyGrab, NULL, NULL},
618 {"RBCMaximizeKey", "None", (void*)WKBD_RBCMAXIMIZE,
619 NULL, getKeybind, setKeyGrab, NULL, NULL},
620 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
621 NULL, getKeybind, setKeyGrab, NULL, NULL},
622 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
623 NULL, getKeybind, setKeyGrab, NULL, NULL},
624 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
625 NULL, getKeybind, setKeyGrab, NULL, NULL},
626 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
627 NULL, getKeybind, setKeyGrab, NULL, NULL},
628 {"ShadeKey", "None", (void *)WKBD_SHADE,
629 NULL, getKeybind, setKeyGrab, NULL, NULL},
630 {"SelectKey", "None", (void *)WKBD_SELECT,
631 NULL, getKeybind, setKeyGrab, NULL, NULL},
632 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
633 NULL, getKeybind, setKeyGrab, NULL, NULL},
634 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
635 NULL, getKeybind, setKeyGrab, NULL, NULL},
636 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
637 NULL, getKeybind, setKeyGrab, NULL, NULL},
638 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
639 NULL, getKeybind, setKeyGrab, NULL, NULL},
640 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
641 NULL, getKeybind, setKeyGrab, NULL, NULL},
642 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
643 NULL, getKeybind, setKeyGrab, NULL, NULL},
644 {"LastWorkspaceKey", "None", (void *)WKBD_LASTWORKSPACE,
645 NULL, getKeybind, setKeyGrab, NULL, NULL},
646 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
647 NULL, getKeybind, setKeyGrab, NULL, NULL},
648 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
649 NULL, getKeybind, setKeyGrab, NULL, NULL},
650 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
651 NULL, getKeybind, setKeyGrab, NULL, NULL},
652 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
653 NULL, getKeybind, setKeyGrab, NULL, NULL},
654 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
655 NULL, getKeybind, setKeyGrab, NULL, NULL},
656 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
657 NULL, getKeybind, setKeyGrab, NULL, NULL},
658 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
659 NULL, getKeybind, setKeyGrab, NULL, NULL},
660 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
661 NULL, getKeybind, setKeyGrab, NULL, NULL},
662 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
663 NULL, getKeybind, setKeyGrab, NULL, NULL},
664 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
665 NULL, getKeybind, setKeyGrab, NULL, NULL},
666 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
667 NULL, getKeybind, setKeyGrab, NULL, NULL},
668 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
669 NULL, getKeybind, setKeyGrab, NULL, NULL},
670 {"MoveToWorkspace1Key", "None", (void *)WKBD_MOVE_WORKSPACE1,
671 NULL, getKeybind, setKeyGrab, NULL, NULL},
672 {"MoveToWorkspace2Key", "None", (void *)WKBD_MOVE_WORKSPACE2,
673 NULL, getKeybind, setKeyGrab, NULL, NULL},
674 {"MoveToWorkspace3Key", "None", (void *)WKBD_MOVE_WORKSPACE3,
675 NULL, getKeybind, setKeyGrab, NULL, NULL},
676 {"MoveToWorkspace4Key", "None", (void *)WKBD_MOVE_WORKSPACE4,
677 NULL, getKeybind, setKeyGrab, NULL, NULL},
678 {"MoveToWorkspace5Key", "None", (void *)WKBD_MOVE_WORKSPACE5,
679 NULL, getKeybind, setKeyGrab, NULL, NULL},
680 {"MoveToWorkspace6Key", "None", (void *)WKBD_MOVE_WORKSPACE6,
681 NULL, getKeybind, setKeyGrab, NULL, NULL},
682 {"MoveToWorkspace7Key", "None", (void *)WKBD_MOVE_WORKSPACE7,
683 NULL, getKeybind, setKeyGrab, NULL, NULL},
684 {"MoveToWorkspace8Key", "None", (void *)WKBD_MOVE_WORKSPACE8,
685 NULL, getKeybind, setKeyGrab, NULL, NULL},
686 {"MoveToWorkspace9Key", "None", (void *)WKBD_MOVE_WORKSPACE9,
687 NULL, getKeybind, setKeyGrab, NULL, NULL},
688 {"MoveToWorkspace10Key", "None", (void *)WKBD_MOVE_WORKSPACE10,
689 NULL, getKeybind, setKeyGrab, NULL, NULL},
690 {"MoveToNextWorkspaceKey", "None", (void *)WKBD_MOVE_NEXTWORKSPACE,
691 NULL, getKeybind, setKeyGrab, NULL, NULL},
692 {"MoveToPrevWorkspaceKey", "None", (void *)WKBD_MOVE_PREVWORKSPACE,
693 NULL, getKeybind, setKeyGrab, NULL, NULL},
694 {"MoveToLastWorkspaceKey", "None", (void *)WKBD_MOVE_LASTWORKSPACE,
695 NULL, getKeybind, setKeyGrab, NULL, NULL},
696 {"MoveToNextWorkspaceLayerKey", "None", (void *)WKBD_MOVE_NEXTWSLAYER,
697 NULL, getKeybind, setKeyGrab, NULL, NULL},
698 {"MoveToPrevWorkspaceLayerKey", "None", (void *)WKBD_MOVE_PREVWSLAYER,
699 NULL, getKeybind, setKeyGrab, NULL, NULL},
700 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
701 NULL, getKeybind, setKeyGrab, NULL, NULL},
702 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
703 NULL, getKeybind, setKeyGrab, NULL, NULL},
704 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
705 NULL, getKeybind, setKeyGrab, NULL, NULL},
706 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
707 NULL, getKeybind, setKeyGrab, NULL, NULL},
708 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
709 NULL, getKeybind, setKeyGrab, NULL, NULL},
710 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
711 NULL, getKeybind, setKeyGrab, NULL, NULL},
712 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
713 NULL, getKeybind, setKeyGrab, NULL, NULL},
714 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
715 NULL, getKeybind, setKeyGrab, NULL, NULL},
716 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
717 NULL, getKeybind, setKeyGrab, NULL, NULL},
718 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
719 NULL, getKeybind, setKeyGrab, NULL, NULL},
720 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
721 NULL, getKeybind, setKeyGrab, NULL, NULL},
722 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
723 NULL, getKeybind, setKeyGrab, NULL, NULL},
725 #ifdef KEEP_XKB_LOCK_STATUS
726 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
727 NULL, getKeybind, setKeyGrab, NULL, NULL},
728 {"KbdModeLock", "NO", NULL,
729 &wPreferences.modelock, getBool, NULL, NULL, NULL},
730 #endif /* KEEP_XKB_LOCK_STATUS */
732 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
733 NULL, getCursor, setCursor, NULL, NULL},
734 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
735 NULL, getCursor, setCursor, NULL, NULL},
736 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
737 NULL, getCursor, setCursor, NULL, NULL},
738 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
739 NULL, getCursor, setCursor, NULL, NULL},
740 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
741 NULL, getCursor, setCursor, NULL, NULL},
742 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
743 NULL, getCursor, setCursor, NULL, NULL},
744 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
745 NULL, getCursor, setCursor, NULL, NULL},
746 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
747 NULL, getCursor, setCursor, NULL, NULL},
748 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
749 NULL, getCursor, setCursor, NULL, NULL},
750 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
751 NULL, getCursor, setCursor, NULL, NULL},
752 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
753 NULL, getCursor, setCursor, NULL, NULL},
754 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
755 NULL, getCursor, setCursor, NULL, NULL},
756 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
757 NULL, getCursor, setCursor, NULL, NULL},
758 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
759 NULL, getCursor, setCursor, NULL, NULL},
760 {"DialogHistoryLines", "500", NULL,
761 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
762 {"CycleActiveHeadOnly", "NO", NULL,
763 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL},
764 {"CycleIgnoreMinimized", "NO", NULL,
765 &wPreferences.cycle_ignore_minimized, getBool, NULL, NULL, NULL}
768 static void initDefaults(void)
770 unsigned int i;
771 WDefaultEntry *entry;
773 WMPLSetCaseSensitive(False);
775 for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) {
776 entry = &optionList[i];
778 entry->plkey = WMCreatePLString(entry->key);
779 if (entry->default_value)
780 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
781 else
782 entry->plvalue = NULL;
785 for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) {
786 entry = &staticOptionList[i];
788 entry->plkey = WMCreatePLString(entry->key);
789 if (entry->default_value)
790 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
791 else
792 entry->plvalue = NULL;
796 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
798 WMPropList *globalDict = NULL;
799 char path[PATH_MAX];
800 struct stat stbuf;
802 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
803 if (stat(path, &stbuf) >= 0) {
804 globalDict = WMReadPropListFromFile(path);
805 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
806 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
807 WMReleasePropList(globalDict);
808 globalDict = NULL;
809 } else if (!globalDict) {
810 wwarning(_("could not load domain %s from global defaults database"), domainName);
814 return globalDict;
817 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
818 static void prependMenu(WMPropList * destarr, WMPropList * array)
820 WMPropList *item;
821 int i;
823 for (i = 0; i < WMGetPropListItemCount(array); i++) {
824 item = WMGetFromPLArray(array, i);
825 if (item)
826 WMInsertInPLArray(destarr, i + 1, item);
830 static void appendMenu(WMPropList * destarr, WMPropList * array)
832 WMPropList *item;
833 int i;
835 for (i = 0; i < WMGetPropListItemCount(array); i++) {
836 item = WMGetFromPLArray(array, i);
837 if (item)
838 WMAddToPLArray(destarr, item);
841 #endif
843 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
845 WMPropList *menu = menuDomain->dictionary;
846 WMPropList *submenu;
848 if (!menu || !WMIsPLArray(menu))
849 return;
851 #ifdef GLOBAL_PREAMBLE_MENU_FILE
852 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
854 if (submenu && !WMIsPLArray(submenu)) {
855 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
856 WMReleasePropList(submenu);
857 submenu = NULL;
859 if (submenu) {
860 prependMenu(menu, submenu);
861 WMReleasePropList(submenu);
863 #endif
865 #ifdef GLOBAL_EPILOGUE_MENU_FILE
866 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
868 if (submenu && !WMIsPLArray(submenu)) {
869 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
870 WMReleasePropList(submenu);
871 submenu = NULL;
873 if (submenu) {
874 appendMenu(menu, submenu);
875 WMReleasePropList(submenu);
877 #endif
879 menuDomain->dictionary = menu;
882 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
884 WDDomain *db;
885 struct stat stbuf;
886 static int inited = 0;
887 char *the_path;
888 WMPropList *shared_dict = NULL;
890 if (!inited) {
891 inited = 1;
892 initDefaults();
895 db = wmalloc(sizeof(WDDomain));
896 db->domain_name = domain;
897 db->path = wdefaultspathfordomain(domain);
898 the_path = db->path;
900 if (the_path && stat(the_path, &stbuf) >= 0) {
901 db->dictionary = WMReadPropListFromFile(the_path);
902 if (db->dictionary) {
903 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
904 WMReleasePropList(db->dictionary);
905 db->dictionary = NULL;
906 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
908 db->timestamp = stbuf.st_mtime;
909 } else {
910 wwarning(_("could not load domain %s from user defaults database"), domain);
914 /* global system dictionary */
915 shared_dict = readGlobalDomain(domain, requireDictionary);
917 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
918 WMIsPLDictionary(db->dictionary)) {
919 WMMergePLDictionaries(shared_dict, db->dictionary, True);
920 WMReleasePropList(db->dictionary);
921 db->dictionary = shared_dict;
922 if (stbuf.st_mtime > db->timestamp)
923 db->timestamp = stbuf.st_mtime;
924 } else if (!db->dictionary) {
925 db->dictionary = shared_dict;
926 if (stbuf.st_mtime > db->timestamp)
927 db->timestamp = stbuf.st_mtime;
930 return db;
933 void wReadStaticDefaults(WMPropList * dict)
935 WMPropList *plvalue;
936 WDefaultEntry *entry;
937 unsigned int i;
938 void *tdata;
940 for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) {
941 entry = &staticOptionList[i];
943 if (dict)
944 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
945 else
946 plvalue = NULL;
948 /* no default in the DB. Use builtin default */
949 if (!plvalue)
950 plvalue = entry->plvalue;
952 if (plvalue) {
953 /* convert data */
954 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
955 if (entry->update)
956 (*entry->update) (NULL, entry, tdata, entry->extra_data);
961 void wDefaultsCheckDomains(void* arg)
963 WScreen *scr;
964 struct stat stbuf;
965 WMPropList *shared_dict = NULL;
966 WMPropList *dict;
967 int i;
969 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
970 WDWindowMaker->timestamp = stbuf.st_mtime;
972 /* Global dictionary */
973 shared_dict = readGlobalDomain("WindowMaker", True);
975 /* User dictionary */
976 dict = WMReadPropListFromFile(WDWindowMaker->path);
978 if (dict) {
979 if (!WMIsPLDictionary(dict)) {
980 WMReleasePropList(dict);
981 dict = NULL;
982 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
983 "WindowMaker", WDWindowMaker->path);
984 } else {
985 if (shared_dict) {
986 WMMergePLDictionaries(shared_dict, dict, True);
987 WMReleasePropList(dict);
988 dict = shared_dict;
989 shared_dict = NULL;
992 for (i = 0; i < wScreenCount; i++) {
993 scr = wScreenWithNumber(i);
994 if (scr)
995 wReadDefaults(scr, dict);
998 if (WDWindowMaker->dictionary)
999 WMReleasePropList(WDWindowMaker->dictionary);
1001 WDWindowMaker->dictionary = dict;
1003 } else {
1004 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1007 if (shared_dict)
1008 WMReleasePropList(shared_dict);
1012 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1013 /* global dictionary */
1014 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1015 /* user dictionary */
1016 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1017 if (dict) {
1018 if (!WMIsPLDictionary(dict)) {
1019 WMReleasePropList(dict);
1020 dict = NULL;
1021 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1022 "WMWindowAttributes", WDWindowAttributes->path);
1023 } else {
1024 if (shared_dict) {
1025 WMMergePLDictionaries(shared_dict, dict, True);
1026 WMReleasePropList(dict);
1027 dict = shared_dict;
1028 shared_dict = NULL;
1031 if (WDWindowAttributes->dictionary)
1032 WMReleasePropList(WDWindowAttributes->dictionary);
1034 WDWindowAttributes->dictionary = dict;
1035 for (i = 0; i < wScreenCount; i++) {
1036 scr = wScreenWithNumber(i);
1037 if (scr) {
1038 wDefaultUpdateIcons(scr);
1040 /* Update the panel image if changed */
1041 /* Don't worry. If the image is the same these
1042 * functions will have no performance impact. */
1043 create_logo_image(scr);
1047 } else {
1048 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1051 WDWindowAttributes->timestamp = stbuf.st_mtime;
1052 if (shared_dict)
1053 WMReleasePropList(shared_dict);
1056 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1057 dict = WMReadPropListFromFile(WDRootMenu->path);
1058 if (dict) {
1059 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1060 WMReleasePropList(dict);
1061 dict = NULL;
1062 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1063 "WMRootMenu", WDRootMenu->path);
1064 } else {
1065 if (WDRootMenu->dictionary)
1066 WMReleasePropList(WDRootMenu->dictionary);
1068 WDRootMenu->dictionary = dict;
1069 wDefaultsMergeGlobalMenus(WDRootMenu);
1071 } else {
1072 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1074 WDRootMenu->timestamp = stbuf.st_mtime;
1076 #ifndef HAVE_INOTIFY
1077 if (!arg)
1078 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1079 #endif
1082 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1084 WMPropList *plvalue, *old_value;
1085 WDefaultEntry *entry;
1086 unsigned int i;
1087 int update_workspace_back = 0; /* kluge :/ */
1088 unsigned int needs_refresh;
1089 void *tdata;
1090 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1092 needs_refresh = 0;
1094 for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) {
1095 entry = &optionList[i];
1097 if (new_dict)
1098 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1099 else
1100 plvalue = NULL;
1102 if (!old_dict)
1103 old_value = NULL;
1104 else
1105 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1107 if (!plvalue && !old_value) {
1108 /* no default in the DB. Use builtin default */
1109 plvalue = entry->plvalue;
1110 if (plvalue && new_dict)
1111 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1113 } else if (!plvalue) {
1114 /* value was deleted from DB. Keep current value */
1115 continue;
1116 } else if (!old_value) {
1117 /* set value for the 1st time */
1118 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1119 /* value has changed */
1120 } else {
1121 if (strcmp(entry->key, "WorkspaceBack") == 0
1122 && update_workspace_back && scr->flags.backimage_helper_launched) {
1123 } else {
1124 /* value was not changed since last time */
1125 continue;
1129 if (plvalue) {
1130 /* convert data */
1131 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1133 * If the WorkspaceSpecificBack data has been changed
1134 * so that the helper will be launched now, we must be
1135 * sure to send the default background texture config
1136 * to the helper.
1138 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1139 !scr->flags.backimage_helper_launched)
1140 update_workspace_back = 1;
1142 if (entry->update)
1143 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1149 if (needs_refresh != 0 && !scr->flags.startup) {
1150 int foo;
1152 foo = 0;
1153 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1154 foo |= WTextureSettings;
1155 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1156 foo |= WFontSettings;
1157 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1158 foo |= WColorSettings;
1159 if (foo)
1160 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1161 (void *)(uintptr_t) foo);
1163 foo = 0;
1164 if (needs_refresh & REFRESH_MENU_TEXTURE)
1165 foo |= WTextureSettings;
1166 if (needs_refresh & REFRESH_MENU_FONT)
1167 foo |= WFontSettings;
1168 if (needs_refresh & REFRESH_MENU_COLOR)
1169 foo |= WColorSettings;
1170 if (foo)
1171 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1173 foo = 0;
1174 if (needs_refresh & REFRESH_WINDOW_FONT)
1175 foo |= WFontSettings;
1176 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1177 foo |= WTextureSettings;
1178 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1179 foo |= WColorSettings;
1180 if (foo)
1181 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1183 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1184 foo = 0;
1185 if (needs_refresh & REFRESH_ICON_FONT)
1186 foo |= WFontSettings;
1187 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1188 foo |= WTextureSettings;
1189 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1190 foo |= WTextureSettings;
1191 if (foo)
1192 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1193 (void *)(uintptr_t) foo);
1195 if (needs_refresh & REFRESH_ICON_TILE)
1196 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1198 if (needs_refresh & REFRESH_WORKSPACE_MENU) {
1199 if (scr->workspace_menu)
1200 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
1201 if (scr->clip_ws_menu)
1202 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
1203 if (scr->workspace_submenu)
1204 scr->workspace_submenu->flags.realized = 0;
1205 if (scr->clip_submenu)
1206 scr->clip_submenu->flags.realized = 0;
1211 void wDefaultUpdateIcons(WScreen *scr)
1213 WAppIcon *aicon = scr->app_icon_list;
1214 WDrawerChain *dc;
1215 WWindow *wwin = scr->focused_window;
1217 while (aicon) {
1218 /* Get the application icon, default included */
1219 wIconChangeImageFile(aicon->icon, NULL);
1220 wAppIconPaint(aicon);
1221 aicon = aicon->next;
1224 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock)
1225 wClipIconPaint(scr->clip_icon);
1227 for (dc = scr->drawers; dc != NULL; dc = dc->next)
1228 wDrawerIconPaint(dc->adrawer->icon_array[0]);
1230 while (wwin) {
1231 if (wwin->icon && wwin->flags.miniaturized)
1232 wIconChangeImageFile(wwin->icon, NULL);
1233 wwin = wwin->prev;
1237 /* --------------------------- Local ----------------------- */
1239 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1240 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1241 entry->key, x); \
1242 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1243 var = entry->default_value;\
1244 } else var = WMGetFromPLString(value)\
1247 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1249 char *str;
1250 WOptionEnumeration *v;
1251 char buffer[TOTAL_VALUES_LENGTH];
1253 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1254 for (v = values; v->string != NULL; v++) {
1255 if (strcasecmp(v->string, str) == 0)
1256 return v->value;
1260 buffer[0] = 0;
1261 for (v = values; v->string != NULL; v++) {
1262 if (!v->is_alias) {
1263 if (buffer[0] != 0)
1264 strcat(buffer, ", ");
1265 snprintf(buffer+strlen(buffer),
1266 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1269 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1270 WMGetFromPLString(key),
1271 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1272 buffer);
1274 if (def) {
1275 return string2index(key, val, NULL, values);
1278 return -1;
1282 * value - is the value in the defaults DB
1283 * addr - is the address to store the data
1284 * ret - is the address to store a pointer to a temporary buffer. ret
1285 * must not be freed and is used by the set functions
1287 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1289 static char data;
1290 char *val;
1291 int second_pass = 0;
1293 GET_STRING_OR_DEFAULT("Boolean", val);
1295 again:
1296 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1297 || strcasecmp(val, "YES") == 0) {
1299 data = 1;
1300 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1301 || strcasecmp(val, "NO") == 0) {
1302 data = 0;
1303 } else {
1304 int i;
1305 if (sscanf(val, "%i", &i) == 1) {
1306 if (i != 0)
1307 data = 1;
1308 else
1309 data = 0;
1310 } else {
1311 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1312 if (second_pass == 0) {
1313 val = WMGetFromPLString(entry->plvalue);
1314 second_pass = 1;
1315 wwarning(_("using default \"%s\" instead"), val);
1316 goto again;
1318 return False;
1322 if (ret)
1323 *ret = &data;
1324 if (addr)
1325 *(char *)addr = data;
1327 return True;
1330 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1332 static int data;
1333 char *val;
1335 GET_STRING_OR_DEFAULT("Integer", val);
1337 if (sscanf(val, "%i", &data) != 1) {
1338 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1339 val = WMGetFromPLString(entry->plvalue);
1340 wwarning(_("using default \"%s\" instead"), val);
1341 if (sscanf(val, "%i", &data) != 1) {
1342 return False;
1346 if (ret)
1347 *ret = &data;
1348 if (addr)
1349 *(int *)addr = data;
1351 return True;
1354 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1356 static WCoord data;
1357 char *val_x, *val_y;
1358 int nelem, changed = 0;
1359 WMPropList *elem_x, *elem_y;
1361 again:
1362 if (!WMIsPLArray(value)) {
1363 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1364 if (changed == 0) {
1365 value = entry->plvalue;
1366 changed = 1;
1367 wwarning(_("using default \"%s\" instead"), entry->default_value);
1368 goto again;
1370 return False;
1373 nelem = WMGetPropListItemCount(value);
1374 if (nelem != 2) {
1375 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1376 if (changed == 0) {
1377 value = entry->plvalue;
1378 changed = 1;
1379 wwarning(_("using default \"%s\" instead"), entry->default_value);
1380 goto again;
1382 return False;
1385 elem_x = WMGetFromPLArray(value, 0);
1386 elem_y = WMGetFromPLArray(value, 1);
1388 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1389 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1390 if (changed == 0) {
1391 value = entry->plvalue;
1392 changed = 1;
1393 wwarning(_("using default \"%s\" instead"), entry->default_value);
1394 goto again;
1396 return False;
1399 val_x = WMGetFromPLString(elem_x);
1400 val_y = WMGetFromPLString(elem_y);
1402 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1403 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1404 if (changed == 0) {
1405 value = entry->plvalue;
1406 changed = 1;
1407 wwarning(_("using default \"%s\" instead"), entry->default_value);
1408 goto again;
1410 return False;
1413 if (data.x < 0)
1414 data.x = 0;
1415 else if (data.x > scr->scr_width / 3)
1416 data.x = scr->scr_width / 3;
1417 if (data.y < 0)
1418 data.y = 0;
1419 else if (data.y > scr->scr_height / 3)
1420 data.y = scr->scr_height / 3;
1422 if (ret)
1423 *ret = &data;
1424 if (addr)
1425 *(WCoord *) addr = data;
1427 return True;
1430 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1432 WMRetainPropList(value);
1434 *ret = value;
1436 return True;
1439 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1441 static char *data;
1442 int i, count, len;
1443 char *ptr;
1444 WMPropList *d;
1445 int changed = 0;
1447 again:
1448 if (!WMIsPLArray(value)) {
1449 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1450 if (changed == 0) {
1451 value = entry->plvalue;
1452 changed = 1;
1453 wwarning(_("using default \"%s\" instead"), entry->default_value);
1454 goto again;
1456 return False;
1459 i = 0;
1460 count = WMGetPropListItemCount(value);
1461 if (count < 1) {
1462 if (changed == 0) {
1463 value = entry->plvalue;
1464 changed = 1;
1465 wwarning(_("using default \"%s\" instead"), entry->default_value);
1466 goto again;
1468 return False;
1471 len = 0;
1472 for (i = 0; i < count; i++) {
1473 d = WMGetFromPLArray(value, i);
1474 if (!d || !WMIsPLString(d)) {
1475 count = i;
1476 break;
1478 len += strlen(WMGetFromPLString(d)) + 1;
1481 ptr = data = wmalloc(len + 1);
1483 for (i = 0; i < count; i++) {
1484 d = WMGetFromPLArray(value, i);
1485 if (!d || !WMIsPLString(d)) {
1486 break;
1488 strcpy(ptr, WMGetFromPLString(d));
1489 ptr += strlen(WMGetFromPLString(d));
1490 *ptr = ':';
1491 ptr++;
1493 ptr--;
1494 *(ptr--) = 0;
1496 if (*(char **)addr != NULL) {
1497 wfree(*(char **)addr);
1499 *(char **)addr = data;
1501 return True;
1504 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1506 static signed char data;
1508 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1509 if (data < 0)
1510 return False;
1512 if (ret)
1513 *ret = &data;
1514 if (addr)
1515 *(signed char *)addr = data;
1517 return True;
1521 * (solid <color>)
1522 * (hgradient <color> <color>)
1523 * (vgradient <color> <color>)
1524 * (dgradient <color> <color>)
1525 * (mhgradient <color> <color> ...)
1526 * (mvgradient <color> <color> ...)
1527 * (mdgradient <color> <color> ...)
1528 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1529 * (tpixmap <file> <color>)
1530 * (spixmap <file> <color>)
1531 * (cpixmap <file> <color>)
1532 * (thgradient <file> <opaqueness> <color> <color>)
1533 * (tvgradient <file> <opaqueness> <color> <color>)
1534 * (tdgradient <file> <opaqueness> <color> <color>)
1535 * (function <lib> <function> ...)
1538 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1540 WMPropList *elem;
1541 char *val;
1542 int nelem;
1543 WTexture *texture = NULL;
1545 nelem = WMGetPropListItemCount(pl);
1546 if (nelem < 1)
1547 return NULL;
1549 elem = WMGetFromPLArray(pl, 0);
1550 if (!elem || !WMIsPLString(elem))
1551 return NULL;
1552 val = WMGetFromPLString(elem);
1554 if (strcasecmp(val, "solid") == 0) {
1555 XColor color;
1557 if (nelem != 2)
1558 return NULL;
1560 /* get color */
1562 elem = WMGetFromPLArray(pl, 1);
1563 if (!elem || !WMIsPLString(elem))
1564 return NULL;
1565 val = WMGetFromPLString(elem);
1567 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1568 wwarning(_("\"%s\" is not a valid color name"), val);
1569 return NULL;
1572 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1573 } else if (strcasecmp(val, "dgradient") == 0
1574 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1575 RColor color1, color2;
1576 XColor xcolor;
1577 int type;
1579 if (nelem != 3) {
1580 wwarning(_("bad number of arguments in gradient specification"));
1581 return NULL;
1584 if (val[0] == 'd' || val[0] == 'D')
1585 type = WTEX_DGRADIENT;
1586 else if (val[0] == 'h' || val[0] == 'H')
1587 type = WTEX_HGRADIENT;
1588 else
1589 type = WTEX_VGRADIENT;
1591 /* get from color */
1592 elem = WMGetFromPLArray(pl, 1);
1593 if (!elem || !WMIsPLString(elem))
1594 return NULL;
1595 val = WMGetFromPLString(elem);
1597 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1598 wwarning(_("\"%s\" is not a valid color name"), val);
1599 return NULL;
1601 color1.alpha = 255;
1602 color1.red = xcolor.red >> 8;
1603 color1.green = xcolor.green >> 8;
1604 color1.blue = xcolor.blue >> 8;
1606 /* get to color */
1607 elem = WMGetFromPLArray(pl, 2);
1608 if (!elem || !WMIsPLString(elem)) {
1609 return NULL;
1611 val = WMGetFromPLString(elem);
1613 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1614 wwarning(_("\"%s\" is not a valid color name"), val);
1615 return NULL;
1617 color2.alpha = 255;
1618 color2.red = xcolor.red >> 8;
1619 color2.green = xcolor.green >> 8;
1620 color2.blue = xcolor.blue >> 8;
1622 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1624 } else if (strcasecmp(val, "igradient") == 0) {
1625 RColor colors1[2], colors2[2];
1626 int th1, th2;
1627 XColor xcolor;
1628 int i;
1630 if (nelem != 7) {
1631 wwarning(_("bad number of arguments in gradient specification"));
1632 return NULL;
1635 /* get from color */
1636 for (i = 0; i < 2; i++) {
1637 elem = WMGetFromPLArray(pl, 1 + i);
1638 if (!elem || !WMIsPLString(elem))
1639 return NULL;
1640 val = WMGetFromPLString(elem);
1642 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1643 wwarning(_("\"%s\" is not a valid color name"), val);
1644 return NULL;
1646 colors1[i].alpha = 255;
1647 colors1[i].red = xcolor.red >> 8;
1648 colors1[i].green = xcolor.green >> 8;
1649 colors1[i].blue = xcolor.blue >> 8;
1651 elem = WMGetFromPLArray(pl, 3);
1652 if (!elem || !WMIsPLString(elem))
1653 return NULL;
1654 val = WMGetFromPLString(elem);
1655 th1 = atoi(val);
1657 /* get from color */
1658 for (i = 0; i < 2; i++) {
1659 elem = WMGetFromPLArray(pl, 4 + i);
1660 if (!elem || !WMIsPLString(elem))
1661 return NULL;
1662 val = WMGetFromPLString(elem);
1664 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1665 wwarning(_("\"%s\" is not a valid color name"), val);
1666 return NULL;
1668 colors2[i].alpha = 255;
1669 colors2[i].red = xcolor.red >> 8;
1670 colors2[i].green = xcolor.green >> 8;
1671 colors2[i].blue = xcolor.blue >> 8;
1673 elem = WMGetFromPLArray(pl, 6);
1674 if (!elem || !WMIsPLString(elem))
1675 return NULL;
1676 val = WMGetFromPLString(elem);
1677 th2 = atoi(val);
1679 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1681 } else if (strcasecmp(val, "mhgradient") == 0
1682 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1683 XColor color;
1684 RColor **colors;
1685 int i, count;
1686 int type;
1688 if (nelem < 3) {
1689 wwarning(_("too few arguments in multicolor gradient specification"));
1690 return NULL;
1693 if (val[1] == 'h' || val[1] == 'H')
1694 type = WTEX_MHGRADIENT;
1695 else if (val[1] == 'v' || val[1] == 'V')
1696 type = WTEX_MVGRADIENT;
1697 else
1698 type = WTEX_MDGRADIENT;
1700 count = nelem - 1;
1702 colors = wmalloc(sizeof(RColor *) * (count + 1));
1704 for (i = 0; i < count; i++) {
1705 elem = WMGetFromPLArray(pl, i + 1);
1706 if (!elem || !WMIsPLString(elem)) {
1707 for (--i; i >= 0; --i) {
1708 wfree(colors[i]);
1710 wfree(colors);
1711 return NULL;
1713 val = WMGetFromPLString(elem);
1715 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1716 wwarning(_("\"%s\" is not a valid color name"), val);
1717 for (--i; i >= 0; --i) {
1718 wfree(colors[i]);
1720 wfree(colors);
1721 return NULL;
1722 } else {
1723 colors[i] = wmalloc(sizeof(RColor));
1724 colors[i]->red = color.red >> 8;
1725 colors[i]->green = color.green >> 8;
1726 colors[i]->blue = color.blue >> 8;
1729 colors[i] = NULL;
1731 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1732 } else if (strcasecmp(val, "spixmap") == 0 ||
1733 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1734 XColor color;
1735 int type;
1737 if (nelem != 3)
1738 return NULL;
1740 if (val[0] == 's' || val[0] == 'S')
1741 type = WTP_SCALE;
1742 else if (val[0] == 'c' || val[0] == 'C')
1743 type = WTP_CENTER;
1744 else
1745 type = WTP_TILE;
1747 /* get color */
1748 elem = WMGetFromPLArray(pl, 2);
1749 if (!elem || !WMIsPLString(elem)) {
1750 return NULL;
1752 val = WMGetFromPLString(elem);
1754 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1755 wwarning(_("\"%s\" is not a valid color name"), val);
1756 return NULL;
1759 /* file name */
1760 elem = WMGetFromPLArray(pl, 1);
1761 if (!elem || !WMIsPLString(elem))
1762 return NULL;
1763 val = WMGetFromPLString(elem);
1765 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1766 } else if (strcasecmp(val, "thgradient") == 0
1767 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1768 RColor color1, color2;
1769 XColor xcolor;
1770 int opacity;
1771 int style;
1773 if (val[1] == 'h' || val[1] == 'H')
1774 style = WTEX_THGRADIENT;
1775 else if (val[1] == 'v' || val[1] == 'V')
1776 style = WTEX_TVGRADIENT;
1777 else
1778 style = WTEX_TDGRADIENT;
1780 if (nelem != 5) {
1781 wwarning(_("bad number of arguments in textured gradient specification"));
1782 return NULL;
1785 /* get from color */
1786 elem = WMGetFromPLArray(pl, 3);
1787 if (!elem || !WMIsPLString(elem))
1788 return NULL;
1789 val = WMGetFromPLString(elem);
1791 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1792 wwarning(_("\"%s\" is not a valid color name"), val);
1793 return NULL;
1795 color1.alpha = 255;
1796 color1.red = xcolor.red >> 8;
1797 color1.green = xcolor.green >> 8;
1798 color1.blue = xcolor.blue >> 8;
1800 /* get to color */
1801 elem = WMGetFromPLArray(pl, 4);
1802 if (!elem || !WMIsPLString(elem)) {
1803 return NULL;
1805 val = WMGetFromPLString(elem);
1807 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1808 wwarning(_("\"%s\" is not a valid color name"), val);
1809 return NULL;
1811 color2.alpha = 255;
1812 color2.red = xcolor.red >> 8;
1813 color2.green = xcolor.green >> 8;
1814 color2.blue = xcolor.blue >> 8;
1816 /* get opacity */
1817 elem = WMGetFromPLArray(pl, 2);
1818 if (!elem || !WMIsPLString(elem))
1819 opacity = 128;
1820 else
1821 val = WMGetFromPLString(elem);
1823 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1824 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1825 opacity = 128;
1828 /* get file name */
1829 elem = WMGetFromPLArray(pl, 1);
1830 if (!elem || !WMIsPLString(elem))
1831 return NULL;
1832 val = WMGetFromPLString(elem);
1834 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1835 } else if (strcasecmp(val, "function") == 0) {
1836 /* Leave this in to handle the unlikely case of
1837 * someone actually having function textures configured */
1838 wwarning("function texture support has been removed");
1839 return NULL;
1840 } else {
1841 wwarning(_("invalid texture type %s"), val);
1842 return NULL;
1844 return texture;
1847 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1849 static WTexture *texture;
1850 int changed = 0;
1852 again:
1853 if (!WMIsPLArray(value)) {
1854 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1855 if (changed == 0) {
1856 value = entry->plvalue;
1857 changed = 1;
1858 wwarning(_("using default \"%s\" instead"), entry->default_value);
1859 goto again;
1861 return False;
1864 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1865 WMPropList *pl;
1867 pl = WMGetFromPLArray(value, 0);
1868 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1869 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1870 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1871 entry->key, "Solid Texture");
1873 value = entry->plvalue;
1874 changed = 1;
1875 wwarning(_("using default \"%s\" instead"), entry->default_value);
1876 goto again;
1880 texture = parse_texture(scr, value);
1882 if (!texture) {
1883 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1884 if (changed == 0) {
1885 value = entry->plvalue;
1886 changed = 1;
1887 wwarning(_("using default \"%s\" instead"), entry->default_value);
1888 goto again;
1890 return False;
1893 if (ret)
1894 *ret = &texture;
1896 if (addr)
1897 *(WTexture **) addr = texture;
1899 return True;
1902 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1904 WMPropList *elem;
1905 int changed = 0;
1906 char *val;
1907 int nelem;
1909 again:
1910 if (!WMIsPLArray(value)) {
1911 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1912 "WorkspaceBack", "Texture or None");
1913 if (changed == 0) {
1914 value = entry->plvalue;
1915 changed = 1;
1916 wwarning(_("using default \"%s\" instead"), entry->default_value);
1917 goto again;
1919 return False;
1922 /* only do basic error checking and verify for None texture */
1924 nelem = WMGetPropListItemCount(value);
1925 if (nelem > 0) {
1926 elem = WMGetFromPLArray(value, 0);
1927 if (!elem || !WMIsPLString(elem)) {
1928 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1929 if (changed == 0) {
1930 value = entry->plvalue;
1931 changed = 1;
1932 wwarning(_("using default \"%s\" instead"), entry->default_value);
1933 goto again;
1935 return False;
1937 val = WMGetFromPLString(elem);
1939 if (strcasecmp(val, "None") == 0)
1940 return True;
1942 *ret = WMRetainPropList(value);
1944 return True;
1947 static int
1948 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1950 WMPropList *elem;
1951 int nelem;
1952 int changed = 0;
1954 again:
1955 if (!WMIsPLArray(value)) {
1956 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1957 "WorkspaceSpecificBack", "an array of textures");
1958 if (changed == 0) {
1959 value = entry->plvalue;
1960 changed = 1;
1961 wwarning(_("using default \"%s\" instead"), entry->default_value);
1962 goto again;
1964 return False;
1967 /* only do basic error checking and verify for None texture */
1969 nelem = WMGetPropListItemCount(value);
1970 if (nelem > 0) {
1971 while (nelem--) {
1972 elem = WMGetFromPLArray(value, nelem);
1973 if (!elem || !WMIsPLArray(elem)) {
1974 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1975 nelem);
1980 *ret = WMRetainPropList(value);
1982 #ifdef notworking
1984 * Kluge to force wmsetbg helper to set the default background.
1985 * If the WorkspaceSpecificBack is changed once wmaker has started,
1986 * the WorkspaceBack won't be sent to the helper, unless the user
1987 * changes it's value too. So, we must force this by removing the
1988 * value from the defaults DB.
1990 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1991 WMPropList *key = WMCreatePLString("WorkspaceBack");
1993 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1995 WMReleasePropList(key);
1997 #endif
1998 return True;
2001 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2003 static WMFont *font;
2004 char *val;
2006 GET_STRING_OR_DEFAULT("Font", val);
2008 font = WMCreateFont(scr->wmscreen, val);
2009 if (!font)
2010 font = WMCreateFont(scr->wmscreen, "fixed");
2012 if (!font) {
2013 wfatal(_("could not load any usable font!!!"));
2014 exit(1);
2017 if (ret)
2018 *ret = font;
2020 /* can't assign font value outside update function */
2021 wassertrv(addr == NULL, True);
2023 return True;
2026 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2028 static XColor color;
2029 char *val;
2030 int second_pass = 0;
2032 GET_STRING_OR_DEFAULT("Color", val);
2034 again:
2035 if (!wGetColor(scr, val, &color)) {
2036 wwarning(_("could not get color for key \"%s\""), entry->key);
2037 if (second_pass == 0) {
2038 val = WMGetFromPLString(entry->plvalue);
2039 second_pass = 1;
2040 wwarning(_("using default \"%s\" instead"), val);
2041 goto again;
2043 return False;
2046 if (ret)
2047 *ret = &color;
2049 assert(addr == NULL);
2051 if (addr)
2052 *(unsigned long*)addr = pixel;
2055 return True;
2058 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2060 static WShortKey shortcut;
2061 KeySym ksym;
2062 char *val;
2063 char *k;
2064 char buf[MAX_SHORTCUT_LENGTH], *b;
2066 GET_STRING_OR_DEFAULT("Key spec", val);
2068 if (!val || strcasecmp(val, "NONE") == 0) {
2069 shortcut.keycode = 0;
2070 shortcut.modifier = 0;
2071 if (ret)
2072 *ret = &shortcut;
2073 return True;
2076 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2078 b = (char *)buf;
2080 /* get modifiers */
2081 shortcut.modifier = 0;
2082 while ((k = strchr(b, '+')) != NULL) {
2083 int mod;
2085 *k = 0;
2086 mod = wXModifierFromKey(b);
2087 if (mod < 0) {
2088 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2089 return False;
2091 shortcut.modifier |= mod;
2093 b = k + 1;
2096 /* get key */
2097 ksym = XStringToKeysym(b);
2099 if (ksym == NoSymbol) {
2100 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2101 return False;
2104 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2105 if (shortcut.keycode == 0) {
2106 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2107 return False;
2110 if (ret)
2111 *ret = &shortcut;
2113 return True;
2116 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2118 static int mask;
2119 char *str;
2121 GET_STRING_OR_DEFAULT("Modifier Key", str);
2123 if (!str)
2124 return False;
2126 mask = wXModifierFromKey(str);
2127 if (mask < 0) {
2128 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2129 mask = 0;
2130 return False;
2133 if (addr)
2134 *(int *)addr = mask;
2136 if (ret)
2137 *ret = &mask;
2139 return True;
2142 # include <X11/cursorfont.h>
2143 typedef struct {
2144 char *name;
2145 int id;
2146 } WCursorLookup;
2148 #define CURSOR_ID_NONE (XC_num_glyphs)
2150 static WCursorLookup cursor_table[] = {
2151 {"X_cursor", XC_X_cursor},
2152 {"arrow", XC_arrow},
2153 {"based_arrow_down", XC_based_arrow_down},
2154 {"based_arrow_up", XC_based_arrow_up},
2155 {"boat", XC_boat},
2156 {"bogosity", XC_bogosity},
2157 {"bottom_left_corner", XC_bottom_left_corner},
2158 {"bottom_right_corner", XC_bottom_right_corner},
2159 {"bottom_side", XC_bottom_side},
2160 {"bottom_tee", XC_bottom_tee},
2161 {"box_spiral", XC_box_spiral},
2162 {"center_ptr", XC_center_ptr},
2163 {"circle", XC_circle},
2164 {"clock", XC_clock},
2165 {"coffee_mug", XC_coffee_mug},
2166 {"cross", XC_cross},
2167 {"cross_reverse", XC_cross_reverse},
2168 {"crosshair", XC_crosshair},
2169 {"diamond_cross", XC_diamond_cross},
2170 {"dot", XC_dot},
2171 {"dotbox", XC_dotbox},
2172 {"double_arrow", XC_double_arrow},
2173 {"draft_large", XC_draft_large},
2174 {"draft_small", XC_draft_small},
2175 {"draped_box", XC_draped_box},
2176 {"exchange", XC_exchange},
2177 {"fleur", XC_fleur},
2178 {"gobbler", XC_gobbler},
2179 {"gumby", XC_gumby},
2180 {"hand1", XC_hand1},
2181 {"hand2", XC_hand2},
2182 {"heart", XC_heart},
2183 {"icon", XC_icon},
2184 {"iron_cross", XC_iron_cross},
2185 {"left_ptr", XC_left_ptr},
2186 {"left_side", XC_left_side},
2187 {"left_tee", XC_left_tee},
2188 {"leftbutton", XC_leftbutton},
2189 {"ll_angle", XC_ll_angle},
2190 {"lr_angle", XC_lr_angle},
2191 {"man", XC_man},
2192 {"middlebutton", XC_middlebutton},
2193 {"mouse", XC_mouse},
2194 {"pencil", XC_pencil},
2195 {"pirate", XC_pirate},
2196 {"plus", XC_plus},
2197 {"question_arrow", XC_question_arrow},
2198 {"right_ptr", XC_right_ptr},
2199 {"right_side", XC_right_side},
2200 {"right_tee", XC_right_tee},
2201 {"rightbutton", XC_rightbutton},
2202 {"rtl_logo", XC_rtl_logo},
2203 {"sailboat", XC_sailboat},
2204 {"sb_down_arrow", XC_sb_down_arrow},
2205 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2206 {"sb_left_arrow", XC_sb_left_arrow},
2207 {"sb_right_arrow", XC_sb_right_arrow},
2208 {"sb_up_arrow", XC_sb_up_arrow},
2209 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2210 {"shuttle", XC_shuttle},
2211 {"sizing", XC_sizing},
2212 {"spider", XC_spider},
2213 {"spraycan", XC_spraycan},
2214 {"star", XC_star},
2215 {"target", XC_target},
2216 {"tcross", XC_tcross},
2217 {"top_left_arrow", XC_top_left_arrow},
2218 {"top_left_corner", XC_top_left_corner},
2219 {"top_right_corner", XC_top_right_corner},
2220 {"top_side", XC_top_side},
2221 {"top_tee", XC_top_tee},
2222 {"trek", XC_trek},
2223 {"ul_angle", XC_ul_angle},
2224 {"umbrella", XC_umbrella},
2225 {"ur_angle", XC_ur_angle},
2226 {"watch", XC_watch},
2227 {"xterm", XC_xterm},
2228 {NULL, CURSOR_ID_NONE}
2231 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2233 switch (status) {
2234 case BitmapOpenFailed:
2235 wwarning(_("failed to open bitmap file \"%s\""), filename);
2236 break;
2237 case BitmapFileInvalid:
2238 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2239 break;
2240 case BitmapNoMemory:
2241 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2242 break;
2243 case BitmapSuccess:
2244 XFreePixmap(dpy, bitmap);
2245 break;
2250 * (none)
2251 * (builtin, <cursor_name>)
2252 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2254 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2256 WMPropList *elem;
2257 char *val;
2258 int nelem;
2259 int status = 0;
2261 nelem = WMGetPropListItemCount(pl);
2262 if (nelem < 1) {
2263 return (status);
2265 elem = WMGetFromPLArray(pl, 0);
2266 if (!elem || !WMIsPLString(elem)) {
2267 return (status);
2269 val = WMGetFromPLString(elem);
2271 if (strcasecmp(val, "none") == 0) {
2272 status = 1;
2273 *cursor = None;
2274 } else if (strcasecmp(val, "builtin") == 0) {
2275 int i;
2276 int cursor_id = CURSOR_ID_NONE;
2278 if (nelem != 2) {
2279 wwarning(_("bad number of arguments in cursor specification"));
2280 return (status);
2282 elem = WMGetFromPLArray(pl, 1);
2283 if (!elem || !WMIsPLString(elem)) {
2284 return (status);
2286 val = WMGetFromPLString(elem);
2288 for (i = 0; cursor_table[i].name != NULL; i++) {
2289 if (strcasecmp(val, cursor_table[i].name) == 0) {
2290 cursor_id = cursor_table[i].id;
2291 break;
2294 if (CURSOR_ID_NONE == cursor_id) {
2295 wwarning(_("unknown builtin cursor name \"%s\""), val);
2296 } else {
2297 *cursor = XCreateFontCursor(dpy, cursor_id);
2298 status = 1;
2300 } else if (strcasecmp(val, "bitmap") == 0) {
2301 char *bitmap_name;
2302 char *mask_name;
2303 int bitmap_status;
2304 int mask_status;
2305 Pixmap bitmap;
2306 Pixmap mask;
2307 unsigned int w, h;
2308 int x, y;
2309 XColor fg, bg;
2311 if (nelem != 3) {
2312 wwarning(_("bad number of arguments in cursor specification"));
2313 return (status);
2315 elem = WMGetFromPLArray(pl, 1);
2316 if (!elem || !WMIsPLString(elem)) {
2317 return (status);
2319 val = WMGetFromPLString(elem);
2320 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2321 if (!bitmap_name) {
2322 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2323 return (status);
2325 elem = WMGetFromPLArray(pl, 2);
2326 if (!elem || !WMIsPLString(elem)) {
2327 wfree(bitmap_name);
2328 return (status);
2330 val = WMGetFromPLString(elem);
2331 mask_name = FindImage(wPreferences.pixmap_path, val);
2332 if (!mask_name) {
2333 wfree(bitmap_name);
2334 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2335 return (status);
2337 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2338 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2339 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2340 fg.pixel = scr->black_pixel;
2341 bg.pixel = scr->white_pixel;
2342 XQueryColor(dpy, scr->w_colormap, &fg);
2343 XQueryColor(dpy, scr->w_colormap, &bg);
2344 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2345 status = 1;
2347 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2348 check_bitmap_status(mask_status, mask_name, mask);
2349 wfree(bitmap_name);
2350 wfree(mask_name);
2352 return (status);
2355 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2357 static Cursor cursor;
2358 int status;
2359 int changed = 0;
2361 again:
2362 if (!WMIsPLArray(value)) {
2363 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2364 entry->key, "cursor specification");
2365 if (!changed) {
2366 value = entry->plvalue;
2367 changed = 1;
2368 wwarning(_("using default \"%s\" instead"), entry->default_value);
2369 goto again;
2371 return (False);
2373 status = parse_cursor(scr, value, &cursor);
2374 if (!status) {
2375 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2376 if (!changed) {
2377 value = entry->plvalue;
2378 changed = 1;
2379 wwarning(_("using default \"%s\" instead"), entry->default_value);
2380 goto again;
2382 return (False);
2384 if (ret) {
2385 *ret = &cursor;
2387 if (addr) {
2388 *(Cursor *) addr = cursor;
2390 return (True);
2393 #undef CURSOR_ID_NONE
2395 /* ---------------- value setting functions --------------- */
2396 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2398 return REFRESH_WINDOW_TITLE_COLOR;
2401 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2403 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2406 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2408 switch (which) {
2409 case WM_DOCK:
2410 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2411 // Drawers require the dock
2412 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || wPreferences.flags.nodock;
2413 break;
2414 case WM_CLIP:
2415 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2416 break;
2417 case WM_DRAWER:
2418 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || *flag;
2419 break;
2420 default:
2421 break;
2423 return 0;
2426 static int setClipMergedInDock(WScreen *scr, WDefaultEntry *entry, char *flag, void *foo)
2428 wPreferences.flags.clip_merged_in_dock = *flag;
2429 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2430 return 0;
2433 static int setWrapAppiconsInDock(WScreen *scr, WDefaultEntry *entry, char *flag, void *foo)
2435 wPreferences.flags.wrap_appicons_in_dock = *flag;
2436 return 0;
2439 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2441 if (scr->workspaces) {
2442 wWorkspaceForceChange(scr, scr->current_workspace);
2443 wArrangeIcons(scr, False);
2445 return 0;
2448 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2450 Pixmap pixmap;
2451 RImage *img;
2452 int reset = 0;
2454 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2455 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2456 ? WREL_ICON : WREL_FLAT);
2457 if (!img) {
2458 wwarning(_("could not render texture for icon background"));
2459 if (!entry->addr)
2460 wTextureDestroy(scr, *texture);
2461 return 0;
2463 RConvertImage(scr->rcontext, img, &pixmap);
2465 if (scr->icon_tile) {
2466 reset = 1;
2467 RReleaseImage(scr->icon_tile);
2468 XFreePixmap(dpy, scr->icon_tile_pixmap);
2471 scr->icon_tile = img;
2473 /* put the icon in the noticeboard hint */
2474 PropSetIconTileHint(scr, img);
2476 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock) {
2477 if (scr->clip_tile) {
2478 RReleaseImage(scr->clip_tile);
2480 scr->clip_tile = wClipMakeTile(scr, img);
2483 if (!wPreferences.flags.nodrawer) {
2484 if (scr->drawer_tile) {
2485 RReleaseImage(scr->drawer_tile);
2487 scr->drawer_tile = wDrawerMakeTile(scr, img);
2490 scr->icon_tile_pixmap = pixmap;
2492 if (scr->def_icon_rimage) {
2493 RReleaseImage(scr->def_icon_rimage);
2494 scr->def_icon_rimage = NULL;
2497 if (scr->icon_back_texture)
2498 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2500 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2502 /* Free the texture as nobody else will use it, nor refer to it. */
2503 if (!entry->addr)
2504 wTextureDestroy(scr, *texture);
2506 return (reset ? REFRESH_ICON_TILE : 0);
2509 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2511 if (scr->title_font) {
2512 WMReleaseFont(scr->title_font);
2514 scr->title_font = font;
2516 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2519 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2521 if (scr->menu_title_font) {
2522 WMReleaseFont(scr->menu_title_font);
2525 scr->menu_title_font = font;
2527 return REFRESH_MENU_TITLE_FONT;
2530 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2532 if (scr->menu_entry_font) {
2533 WMReleaseFont(scr->menu_entry_font);
2535 scr->menu_entry_font = font;
2537 return REFRESH_MENU_FONT;
2540 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2542 if (scr->icon_title_font) {
2543 WMReleaseFont(scr->icon_title_font);
2546 scr->icon_title_font = font;
2548 return REFRESH_ICON_FONT;
2551 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2553 if (scr->clip_title_font) {
2554 WMReleaseFont(scr->clip_title_font);
2557 scr->clip_title_font = font;
2559 return REFRESH_ICON_FONT;
2562 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2564 if (scr->workspace_name_font) {
2565 WMReleaseFont(scr->workspace_name_font);
2568 scr->workspace_name_font = font;
2570 return 0;
2573 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2575 if (scr->select_color)
2576 WMReleaseColor(scr->select_color);
2578 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2580 wFreeColor(scr, color->pixel);
2582 return REFRESH_MENU_COLOR;
2585 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2587 if (scr->select_text_color)
2588 WMReleaseColor(scr->select_text_color);
2590 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2592 wFreeColor(scr, color->pixel);
2594 return REFRESH_MENU_COLOR;
2597 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2599 if (scr->clip_title_color[widx])
2600 WMReleaseColor(scr->clip_title_color[widx]);
2602 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2603 wFreeColor(scr, color->pixel);
2605 return REFRESH_ICON_TITLE_COLOR;
2608 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2610 if (scr->window_title_color[widx])
2611 WMReleaseColor(scr->window_title_color[widx]);
2613 scr->window_title_color[widx] =
2614 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2616 wFreeColor(scr, color->pixel);
2618 return REFRESH_WINDOW_TITLE_COLOR;
2621 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2623 if (scr->menu_title_color[0])
2624 WMReleaseColor(scr->menu_title_color[0]);
2626 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2628 wFreeColor(scr, color->pixel);
2630 return REFRESH_MENU_TITLE_COLOR;
2633 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2635 if (scr->mtext_color)
2636 WMReleaseColor(scr->mtext_color);
2638 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2640 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2641 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2642 } else {
2643 WMSetColorAlpha(scr->dtext_color, 0xffff);
2646 wFreeColor(scr, color->pixel);
2648 return REFRESH_MENU_COLOR;
2651 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2653 if (scr->dtext_color)
2654 WMReleaseColor(scr->dtext_color);
2656 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2658 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2659 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2660 } else {
2661 WMSetColorAlpha(scr->dtext_color, 0xffff);
2664 wFreeColor(scr, color->pixel);
2666 return REFRESH_MENU_COLOR;
2669 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2671 if (scr->icon_title_color)
2672 WMReleaseColor(scr->icon_title_color);
2673 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2675 wFreeColor(scr, color->pixel);
2677 return REFRESH_ICON_TITLE_COLOR;
2680 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2682 if (scr->icon_title_texture) {
2683 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2685 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2687 return REFRESH_ICON_TITLE_BACK;
2690 static int setFrameBorderWidth(WScreen * scr, WDefaultEntry * entry, int * value, void *foo)
2692 scr->frame_border_width = *value;
2694 return REFRESH_FRAME_BORDER;
2697 static int setFrameBorderColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2699 if (scr->frame_border_color)
2700 WMReleaseColor(scr->frame_border_color);
2701 scr->frame_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2703 wFreeColor(scr, color->pixel);
2705 return REFRESH_FRAME_BORDER;
2708 static int setFrameSelectedBorderColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2710 if (scr->frame_selected_border_color)
2711 WMReleaseColor(scr->frame_selected_border_color);
2712 scr->frame_selected_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2714 wFreeColor(scr, color->pixel);
2716 return REFRESH_FRAME_BORDER;
2719 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2721 close(scr->helper_fd);
2722 scr->helper_fd = 0;
2723 scr->helper_pid = 0;
2724 scr->flags.backimage_helper_launched = 0;
2727 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2729 WMPropList *val;
2730 char *str;
2731 int i;
2733 if (scr->flags.backimage_helper_launched) {
2734 if (WMGetPropListItemCount(value) == 0) {
2735 SendHelperMessage(scr, 'C', 0, NULL);
2736 SendHelperMessage(scr, 'K', 0, NULL);
2738 WMReleasePropList(value);
2739 return 0;
2741 } else {
2742 pid_t pid;
2743 int filedes[2];
2745 if (WMGetPropListItemCount(value) == 0)
2746 return 0;
2748 if (pipe(filedes) < 0) {
2749 werror("pipe() failed:can't set workspace specific background image");
2751 WMReleasePropList(value);
2752 return 0;
2755 pid = fork();
2756 if (pid < 0) {
2757 werror("fork() failed:can't set workspace specific background image");
2758 if (close(filedes[0]) < 0)
2759 werror("could not close pipe");
2760 if (close(filedes[1]) < 0)
2761 werror("could not close pipe");
2763 } else if (pid == 0) {
2764 char *dither;
2766 SetupEnvironment(scr);
2768 if (close(0) < 0)
2769 werror("could not close pipe");
2770 if (dup(filedes[0]) < 0) {
2771 werror("dup() failed:can't set workspace specific background image");
2773 dither = wPreferences.no_dithering ? "-m" : "-d";
2774 if (wPreferences.smooth_workspace_back)
2775 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2776 else
2777 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2778 werror("could not execute wmsetbg");
2779 exit(1);
2780 } else {
2782 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2783 werror("error setting close-on-exec flag");
2785 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2786 werror("error setting close-on-exec flag");
2789 scr->helper_fd = filedes[1];
2790 scr->helper_pid = pid;
2791 scr->flags.backimage_helper_launched = 1;
2793 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2795 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2800 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2801 val = WMGetFromPLArray(value, i);
2802 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2803 str = WMGetPropListDescription(val, False);
2805 SendHelperMessage(scr, 'S', i + 1, str);
2807 wfree(str);
2808 } else {
2809 SendHelperMessage(scr, 'U', i + 1, NULL);
2812 sleep(1);
2814 WMReleasePropList(value);
2815 return 0;
2818 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2820 if (scr->flags.backimage_helper_launched) {
2821 char *str;
2823 if (WMGetPropListItemCount(value) == 0) {
2824 SendHelperMessage(scr, 'U', 0, NULL);
2825 } else {
2826 /* set the default workspace background to this one */
2827 str = WMGetPropListDescription(value, False);
2828 if (str) {
2829 SendHelperMessage(scr, 'S', 0, str);
2830 wfree(str);
2831 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2832 } else {
2833 SendHelperMessage(scr, 'U', 0, NULL);
2836 } else if (WMGetPropListItemCount(value) > 0) {
2837 char *command;
2838 char *text;
2839 char *dither;
2840 int len;
2842 text = WMGetPropListDescription(value, False);
2843 len = strlen(text) + 40;
2844 command = wmalloc(len);
2845 dither = wPreferences.no_dithering ? "-m" : "-d";
2846 if (wPreferences.smooth_workspace_back)
2847 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2848 else
2849 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2850 wfree(text);
2851 ExecuteShellCommand(scr, command);
2852 wfree(command);
2854 WMReleasePropList(value);
2856 return 0;
2859 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2861 if (scr->widget_texture) {
2862 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2864 scr->widget_texture = *(WTexSolid **) texture;
2866 return 0;
2869 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2871 if (scr->window_title_texture[WS_FOCUSED]) {
2872 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2874 scr->window_title_texture[WS_FOCUSED] = *texture;
2876 return REFRESH_WINDOW_TEXTURES;
2879 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2881 if (scr->window_title_texture[WS_PFOCUSED]) {
2882 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2884 scr->window_title_texture[WS_PFOCUSED] = *texture;
2886 return REFRESH_WINDOW_TEXTURES;
2889 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2891 if (scr->window_title_texture[WS_UNFOCUSED]) {
2892 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2894 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2896 return REFRESH_WINDOW_TEXTURES;
2899 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2901 if (scr->resizebar_texture[0]) {
2902 wTextureDestroy(scr, scr->resizebar_texture[0]);
2904 scr->resizebar_texture[0] = *texture;
2906 return REFRESH_WINDOW_TEXTURES;
2909 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2911 if (scr->menu_title_texture[0]) {
2912 wTextureDestroy(scr, scr->menu_title_texture[0]);
2914 scr->menu_title_texture[0] = *texture;
2916 return REFRESH_MENU_TITLE_TEXTURE;
2919 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2921 if (scr->menu_item_texture) {
2922 wTextureDestroy(scr, scr->menu_item_texture);
2923 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2925 scr->menu_item_texture = *texture;
2927 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2929 return REFRESH_MENU_TEXTURE;
2932 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2934 WWindow *wwin;
2935 wKeyBindings[widx] = *shortcut;
2937 wwin = scr->focused_window;
2939 while (wwin != NULL) {
2940 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2942 if (!WFLAGP(wwin, no_bind_keys)) {
2943 wWindowSetKeyGrabs(wwin);
2945 wwin = wwin->prev;
2948 /* do we need to update window menus? */
2949 if (widx >= WKBD_WORKSPACE1 && widx <= WKBD_WORKSPACE10)
2950 return REFRESH_WORKSPACE_MENU;
2951 if (widx == WKBD_LASTWORKSPACE)
2952 return REFRESH_WORKSPACE_MENU;
2953 if (widx >= WKBD_MOVE_WORKSPACE1 && widx <= WKBD_MOVE_WORKSPACE10)
2954 return REFRESH_WORKSPACE_MENU;
2956 return 0;
2959 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2961 wScreenUpdateUsableArea(scr);
2962 wArrangeIcons(scr, True);
2964 return 0;
2967 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2969 wScreenUpdateUsableArea(scr);
2971 return 0;
2974 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2976 return REFRESH_MENU_TEXTURE;
2979 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2981 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2983 RCopyArea(img, image, x, y, w, h, 0, 0);
2985 return img;
2988 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2990 char *path;
2991 RImage *bgimage;
2992 int cwidth, cheight;
2993 WPreferences *prefs = (WPreferences *) foo;
2995 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2996 if (prefs->swtileImage)
2997 RReleaseImage(prefs->swtileImage);
2998 prefs->swtileImage = NULL;
3000 WMReleasePropList(array);
3001 return 0;
3004 switch (WMGetPropListItemCount(array)) {
3005 case 4:
3006 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3007 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3008 break;
3009 } else
3010 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3012 if (!path) {
3013 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3014 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3015 } else {
3016 bgimage = RLoadImage(scr->rcontext, path, 0);
3017 if (!bgimage) {
3018 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3019 wfree(path);
3020 } else {
3021 wfree(path);
3023 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3024 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3026 if (cwidth <= 0 || cheight <= 0 ||
3027 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3028 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3029 else {
3030 int i;
3031 int swidth, theight;
3032 for (i = 0; i < 9; i++) {
3033 if (prefs->swbackImage[i])
3034 RReleaseImage(prefs->swbackImage[i]);
3035 prefs->swbackImage[i] = NULL;
3037 swidth = (bgimage->width - cwidth) / 2;
3038 theight = (bgimage->height - cheight) / 2;
3040 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3041 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3042 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3043 swidth, theight);
3045 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3046 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3047 cwidth, cheight);
3048 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3049 swidth, cheight);
3051 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3052 swidth, theight);
3053 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3054 cwidth, theight);
3055 prefs->swbackImage[8] =
3056 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3057 theight);
3059 // check if anything failed
3060 for (i = 0; i < 9; i++) {
3061 if (!prefs->swbackImage[i]) {
3062 for (; i >= 0; --i) {
3063 RReleaseImage(prefs->swbackImage[i]);
3064 prefs->swbackImage[i] = NULL;
3066 break;
3070 RReleaseImage(bgimage);
3074 case 1:
3075 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3076 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3077 break;
3078 } else
3079 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3081 if (!path) {
3082 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3083 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3084 } else {
3085 if (prefs->swtileImage)
3086 RReleaseImage(prefs->swtileImage);
3088 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3089 if (!prefs->swtileImage) {
3090 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3092 wfree(path);
3094 break;
3096 default:
3097 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3098 break;
3101 WMReleasePropList(array);
3103 return 0;
3106 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
3108 int i;
3109 WPreferences *prefs = (WPreferences *) foo;
3111 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3112 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3113 WMReleasePropList(array);
3114 return 0;
3117 DestroyWindowMenu(scr);
3119 for (i = 0; i < 7; i++) {
3120 if (prefs->modifier_labels[i])
3121 wfree(prefs->modifier_labels[i]);
3123 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3124 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3125 } else {
3126 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3127 prefs->modifier_labels[i] = NULL;
3131 WMReleasePropList(array);
3133 return 0;
3136 static int setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3138 if (*value <= 0)
3139 *(int *)foo = 1;
3141 W_setconf_doubleClickDelay(*value);
3143 return 0;
3146 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3148 if (wCursor[widx] != None) {
3149 XFreeCursor(dpy, wCursor[widx]);
3152 wCursor[widx] = *cursor;
3154 if (widx == WCUR_ROOT && *cursor != None) {
3155 XDefineCursor(dpy, scr->root_win, *cursor);
3158 return 0;