wmaker: Replaced local 'extern' definition of wPreferences by proper header usage
[wmaker-crm.git] / src / defaults.c
blob02f01a3e38b26209cfbcdcbff5065e3057cc9dc6
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"
65 #include "event.h"
66 #include "winmenu.h"
68 #define MAX_SHORTCUT_LENGTH 32
70 #ifndef GLOBAL_DEFAULTS_SUBDIR
71 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
72 #endif
74 /***** Global *****/
75 extern WDDomain *WDWindowMaker;
76 extern WDDomain *WDWindowAttributes;
77 extern WDDomain *WDRootMenu;
78 extern int wScreenCount;
79 extern WShortKey wKeyBindings[WKBD_LAST];
81 typedef struct _WDefaultEntry WDefaultEntry;
82 typedef int (WDECallbackConvert) (WScreen *scr, WDefaultEntry *entry, WMPropList *plvalue, void *addr, void **tdata);
83 typedef int (WDECallbackUpdate) (WScreen *scr, WDefaultEntry *entry, void *tdata, void *extra_data);
85 struct _WDefaultEntry {
86 const char *key;
87 const char *default_value;
88 void *extra_data;
89 void *addr;
90 WDECallbackConvert *convert;
91 WDECallbackUpdate *update;
92 WMPropList *plkey;
93 WMPropList *plvalue; /* default value */
96 /* used to map strings to integers */
97 typedef struct {
98 const char *string;
99 short value;
100 char is_alias;
101 } WOptionEnumeration;
103 /* type converters */
104 static WDECallbackConvert getBool;
105 static WDECallbackConvert getInt;
106 static WDECallbackConvert getCoord;
107 static WDECallbackConvert getPathList;
108 static WDECallbackConvert getEnum;
109 static WDECallbackConvert getTexture;
110 static WDECallbackConvert getWSBackground;
111 static WDECallbackConvert getWSSpecificBackground;
112 static WDECallbackConvert getFont;
113 static WDECallbackConvert getColor;
114 static WDECallbackConvert getKeybind;
115 static WDECallbackConvert getModMask;
116 static WDECallbackConvert getPropList;
118 /* value setting functions */
119 static WDECallbackUpdate setJustify;
120 static WDECallbackUpdate setClearance;
121 static WDECallbackUpdate setIfDockPresent;
122 static WDECallbackUpdate setClipMergedInDock;
123 static WDECallbackUpdate setWrapAppiconsInDock;
124 static WDECallbackUpdate setStickyIcons;
125 static WDECallbackUpdate setWidgetColor;
126 static WDECallbackUpdate setIconTile;
127 static WDECallbackUpdate setWinTitleFont;
128 static WDECallbackUpdate setMenuTitleFont;
129 static WDECallbackUpdate setMenuTextFont;
130 static WDECallbackUpdate setIconTitleFont;
131 static WDECallbackUpdate setIconTitleColor;
132 static WDECallbackUpdate setIconTitleBack;
133 static WDECallbackUpdate setFrameBorderWidth;
134 static WDECallbackUpdate setFrameBorderColor;
135 static WDECallbackUpdate setFrameSelectedBorderColor;
136 static WDECallbackUpdate setLargeDisplayFont;
137 static WDECallbackUpdate setWTitleColor;
138 static WDECallbackUpdate setFTitleBack;
139 static WDECallbackUpdate setPTitleBack;
140 static WDECallbackUpdate setUTitleBack;
141 static WDECallbackUpdate setResizebarBack;
142 static WDECallbackUpdate setWorkspaceBack;
143 static WDECallbackUpdate setWorkspaceSpecificBack;
144 static WDECallbackUpdate setMenuTitleColor;
145 static WDECallbackUpdate setMenuTextColor;
146 static WDECallbackUpdate setMenuDisabledColor;
147 static WDECallbackUpdate setMenuTitleBack;
148 static WDECallbackUpdate setMenuTextBack;
149 static WDECallbackUpdate setHightlight;
150 static WDECallbackUpdate setHightlightText;
151 static WDECallbackUpdate setKeyGrab;
152 static WDECallbackUpdate setDoubleClick;
153 static WDECallbackUpdate setIconPosition;
155 static WDECallbackUpdate setClipTitleFont;
156 static WDECallbackUpdate setClipTitleColor;
158 static WDECallbackUpdate setMenuStyle;
159 static WDECallbackUpdate setSwPOptions;
160 static WDECallbackUpdate updateUsableArea;
162 static WDECallbackUpdate setModifierKeyLabels;
164 extern Cursor wCursor[WCUR_LAST];
165 static WDECallbackConvert getCursor;
166 static WDECallbackUpdate setCursor;
169 * Tables to convert strings to enumeration values.
170 * Values stored are char
173 /* WARNING: sum of length of all value strings must not exceed
174 * this value */
175 #define TOTAL_VALUES_LENGTH 80
177 #define REFRESH_WINDOW_TEXTURES (1<<0)
178 #define REFRESH_MENU_TEXTURE (1<<1)
179 #define REFRESH_MENU_FONT (1<<2)
180 #define REFRESH_MENU_COLOR (1<<3)
181 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
182 #define REFRESH_MENU_TITLE_FONT (1<<5)
183 #define REFRESH_MENU_TITLE_COLOR (1<<6)
184 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
185 #define REFRESH_WINDOW_FONT (1<<8)
186 #define REFRESH_ICON_TILE (1<<9)
187 #define REFRESH_ICON_FONT (1<<10)
188 #define REFRESH_WORKSPACE_BACK (1<<11)
190 #define REFRESH_BUTTON_IMAGES (1<<12)
192 #define REFRESH_ICON_TITLE_COLOR (1<<13)
193 #define REFRESH_ICON_TITLE_BACK (1<<14)
195 #define REFRESH_WORKSPACE_MENU (1<<15)
197 #define REFRESH_FRAME_BORDER REFRESH_MENU_FONT|REFRESH_WINDOW_FONT
199 static WOptionEnumeration seFocusModes[] = {
200 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
201 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
202 {NULL, 0, 0}
205 static WOptionEnumeration seTitlebarModes[] = {
206 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
207 {"next", TS_NEXT, 0}, {NULL, 0, 0}
210 static WOptionEnumeration seColormapModes[] = {
211 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
212 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
213 {NULL, 0, 0}
216 static WOptionEnumeration sePlacements[] = {
217 {"Auto", WPM_AUTO, 0},
218 {"Smart", WPM_SMART, 0},
219 {"Cascade", WPM_CASCADE, 0},
220 {"Random", WPM_RANDOM, 0},
221 {"Manual", WPM_MANUAL, 0},
222 {"Center", WPM_CENTER, 0},
223 {NULL, 0, 0}
226 static WOptionEnumeration seGeomDisplays[] = {
227 {"None", WDIS_NONE, 0},
228 {"Center", WDIS_CENTER, 0},
229 {"Corner", WDIS_TOPLEFT, 0},
230 {"Floating", WDIS_FRAME_CENTER, 0},
231 {"Line", WDIS_NEW, 0},
232 {NULL, 0, 0}
235 static WOptionEnumeration seSpeeds[] = {
236 {"UltraFast", SPEED_ULTRAFAST, 0},
237 {"Fast", SPEED_FAST, 0},
238 {"Medium", SPEED_MEDIUM, 0},
239 {"Slow", SPEED_SLOW, 0},
240 {"UltraSlow", SPEED_ULTRASLOW, 0},
241 {NULL, 0, 0}
244 static WOptionEnumeration seMouseButtonActions[] = {
245 {"None", WA_NONE, 0},
246 {"SelectWindows", WA_SELECT_WINDOWS, 0},
247 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
248 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
249 {NULL, 0, 0}
252 static WOptionEnumeration seMouseWheelActions[] = {
253 {"None", WA_NONE, 0},
254 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
255 {NULL, 0, 0}
258 static WOptionEnumeration seIconificationStyles[] = {
259 {"Zoom", WIS_ZOOM, 0},
260 {"Twist", WIS_TWIST, 0},
261 {"Flip", WIS_FLIP, 0},
262 {"None", WIS_NONE, 0},
263 {"random", WIS_RANDOM, 0},
264 {NULL, 0, 0}
267 static WOptionEnumeration seJustifications[] = {
268 {"Left", WTJ_LEFT, 0},
269 {"Center", WTJ_CENTER, 0},
270 {"Right", WTJ_RIGHT, 0},
271 {NULL, 0, 0}
274 static WOptionEnumeration seIconPositions[] = {
275 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
276 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
277 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
278 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
279 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
280 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
281 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
282 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
283 {NULL, 0, 0}
286 static WOptionEnumeration seMenuStyles[] = {
287 {"normal", MS_NORMAL, 0},
288 {"singletexture", MS_SINGLE_TEXTURE, 0},
289 {"flat", MS_FLAT, 0},
290 {NULL, 0, 0}
293 static WOptionEnumeration seDisplayPositions[] = {
294 {"none", WD_NONE, 0},
295 {"center", WD_CENTER, 0},
296 {"top", WD_TOP, 0},
297 {"bottom", WD_BOTTOM, 0},
298 {"topleft", WD_TOPLEFT, 0},
299 {"topright", WD_TOPRIGHT, 0},
300 {"bottomleft", WD_BOTTOMLEFT, 0},
301 {"bottomright", WD_BOTTOMRIGHT, 0},
302 {NULL, 0, 0}
305 static WOptionEnumeration seWorkspaceBorder[] = {
306 {"None", WB_NONE, 0},
307 {"LeftRight", WB_LEFTRIGHT, 0},
308 {"TopBottom", WB_TOPBOTTOM, 0},
309 {"AllDirections", WB_ALLDIRS, 0},
310 {NULL, 0, 0}
314 * ALL entries in the tables bellow, NEED to have a default value
315 * defined, and this value needs to be correct.
318 /* these options will only affect the window manager on startup
320 * static defaults can't access the screen data, because it is
321 * created after these defaults are read
323 WDefaultEntry staticOptionList[] = {
325 {"ColormapSize", "4", NULL,
326 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
327 {"DisableDithering", "NO", NULL,
328 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
329 {"IconSize", "64", NULL,
330 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
331 {"ModifierKey", "Mod1", NULL,
332 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
333 {"DisableWSMouseActions", "NO", NULL,
334 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
335 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
336 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
337 {"NewStyle", "new", seTitlebarModes,
338 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
339 {"DisableDock", "NO", (void *)WM_DOCK,
340 NULL, getBool, setIfDockPresent, NULL, NULL},
341 {"DisableClip", "NO", (void *)WM_CLIP,
342 NULL, getBool, setIfDockPresent, NULL, NULL},
343 {"DisableDrawers", "NO", (void *)WM_DRAWER,
344 NULL, getBool, setIfDockPresent, NULL, NULL},
345 {"ClipMergedInDock", "NO", NULL,
346 NULL, getBool, setClipMergedInDock, NULL, NULL},
347 {"DisableMiniwindows", "NO", NULL,
348 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
351 #define NUM2STRING_(x) #x
352 #define NUM2STRING(x) NUM2STRING_(x)
354 WDefaultEntry optionList[] = {
356 /* dynamic options */
358 {"IconPosition", "blh", seIconPositions,
359 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
360 {"IconificationStyle", "Zoom", seIconificationStyles,
361 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
362 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
363 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
364 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
365 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
366 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
367 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
368 {"MouseWheelAction", "None", seMouseWheelActions,
369 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
370 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
371 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
372 {"IconPath", DEF_ICON_PATHS, NULL,
373 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
374 {"ColormapMode", "auto", seColormapModes,
375 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
376 {"AutoFocus", "NO", NULL,
377 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
378 {"RaiseDelay", "0", NULL,
379 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
380 {"CirculateRaise", "NO", NULL,
381 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
382 {"Superfluous", "NO", NULL,
383 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
384 {"AdvanceToNewWorkspace", "NO", NULL,
385 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
386 {"CycleWorkspaces", "NO", NULL,
387 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
388 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
389 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
390 {"WorkspaceBorder", "None", seWorkspaceBorder,
391 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
392 {"WorkspaceBorderSize", "0", NULL,
393 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
394 {"StickyIcons", "NO", NULL,
395 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
396 {"SaveSessionOnExit", "NO", NULL,
397 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
398 {"WrapMenus", "NO", NULL,
399 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
400 {"ScrollableMenus", "NO", NULL,
401 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
402 {"MenuScrollSpeed", "medium", seSpeeds,
403 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
404 {"IconSlideSpeed", "medium", seSpeeds,
405 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
406 {"ShadeSpeed", "medium", seSpeeds,
407 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
408 {"BounceAppIconsWhenUrgent", "YES", NULL,
409 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
410 {"RaiseAppIconsWhenBouncing", "NO", NULL,
411 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
412 {"DoNotMakeAppIconsBounce", "NO", NULL,
413 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
414 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
415 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
416 {"ClipAutoraiseDelay", "600", NULL,
417 &wPreferences.clip_auto_raise_delay, getInt, NULL, NULL, NULL},
418 {"ClipAutolowerDelay", "1000", NULL,
419 &wPreferences.clip_auto_lower_delay, getInt, NULL, NULL, NULL},
420 {"ClipAutoexpandDelay", "600", NULL,
421 &wPreferences.clip_auto_expand_delay, getInt, NULL, NULL, NULL},
422 {"ClipAutocollapseDelay", "1000", NULL,
423 &wPreferences.clip_auto_collapse_delay, getInt, NULL, NULL, NULL},
424 {"WrapAppiconsInDock", "YES", NULL,
425 NULL, getBool, setWrapAppiconsInDock, NULL, NULL},
426 {"AlignSubmenus", "NO", NULL,
427 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
428 {"ViKeyMenus", "NO", NULL,
429 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
430 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
431 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
432 {"WindowPlacement", "auto", sePlacements,
433 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
434 {"IgnoreFocusClick", "NO", NULL,
435 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
436 {"UseSaveUnders", "NO", NULL,
437 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
438 {"OpaqueMove", "NO", NULL,
439 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
440 {"OpaqueResize", "NO", NULL,
441 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
442 {"OpaqueMoveResizeKeyboard", "NO", NULL,
443 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
444 {"DisableAnimations", "NO", NULL,
445 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
446 {"DontLinkWorkspaces", "NO", NULL,
447 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
448 {"HighlightActiveApp", "YES", NULL,
449 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
450 {"AutoArrangeIcons", "NO", NULL,
451 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
452 {"NoWindowOverDock", "NO", NULL,
453 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
454 {"NoWindowOverIcons", "NO", NULL,
455 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
456 {"WindowPlaceOrigin", "(0, 0)", NULL,
457 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
458 {"ResizeDisplay", "corner", seGeomDisplays,
459 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
460 {"MoveDisplay", "corner", seGeomDisplays,
461 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
462 {"DontConfirmKill", "NO", NULL,
463 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
464 {"WindowTitleBalloons", "NO", NULL,
465 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
466 {"MiniwindowTitleBalloons", "NO", NULL,
467 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
468 {"AppIconBalloons", "NO", NULL,
469 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
470 {"HelpBalloons", "NO", NULL,
471 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
472 {"EdgeResistance", "30", NULL,
473 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
474 {"ResizeIncrement", "0", NULL,
475 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
476 {"Attraction", "NO", NULL,
477 &wPreferences.attract, getBool, NULL, NULL, NULL},
478 {"DisableBlinking", "NO", NULL,
479 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
480 {"SingleClickLaunch", "NO", NULL,
481 &wPreferences.single_click, getBool, NULL, NULL, NULL},
482 {"StrictWindozeCycle", "YES", NULL,
483 &wPreferences.strict_windoze_cycle, getBool, NULL, NULL, NULL},
484 {"SwitchPanelOnlyOpen", "NO", NULL,
485 &wPreferences.panel_only_open, getBool, NULL, NULL, NULL},
487 /* style options */
489 {"MenuStyle", "normal", seMenuStyles,
490 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
491 {"WidgetColor", "(solid, gray)", NULL,
492 NULL, getTexture, setWidgetColor, NULL, NULL},
493 {"WorkspaceSpecificBack", "()", NULL,
494 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
495 /* WorkspaceBack must come after WorkspaceSpecificBack or
496 * WorkspaceBack wont know WorkspaceSpecificBack was also
497 * specified and 2 copies of wmsetbg will be launched */
498 {"WorkspaceBack", "(solid, black)", NULL,
499 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
500 {"SmoothWorkspaceBack", "NO", NULL,
501 NULL, getBool, NULL, NULL, NULL},
502 {"IconBack", "(solid, gray)", NULL,
503 NULL, getTexture, setIconTile, NULL, NULL},
504 {"TitleJustify", "center", seJustifications,
505 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
506 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
507 NULL, getFont, setWinTitleFont, NULL, NULL},
508 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
509 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
510 {"WindowTitleMinHeight", "0", NULL,
511 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
512 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
513 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
514 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
515 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
516 {"MenuTitleMinHeight", "0", NULL,
517 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
518 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
519 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
520 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
521 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
522 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
523 NULL, getFont, setMenuTitleFont, NULL, NULL},
524 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
525 NULL, getFont, setMenuTextFont, NULL, NULL},
526 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
527 NULL, getFont, setIconTitleFont, NULL, NULL},
528 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
529 NULL, getFont, setClipTitleFont, NULL, NULL},
530 {"ShowClipTitle", "YES", NULL,
531 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
532 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
533 NULL, getFont, setLargeDisplayFont, NULL, NULL},
534 {"HighlightColor", "white", NULL,
535 NULL, getColor, setHightlight, NULL, NULL},
536 {"HighlightTextColor", "black", NULL,
537 NULL, getColor, setHightlightText, NULL, NULL},
538 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
539 NULL, getColor, setClipTitleColor, NULL, NULL},
540 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
541 NULL, getColor, setClipTitleColor, NULL, NULL},
542 {"FTitleColor", "white", (void *)WS_FOCUSED,
543 NULL, getColor, setWTitleColor, NULL, NULL},
544 {"PTitleColor", "white", (void *)WS_PFOCUSED,
545 NULL, getColor, setWTitleColor, NULL, NULL},
546 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
547 NULL, getColor, setWTitleColor, NULL, NULL},
548 {"FTitleBack", "(solid, black)", NULL,
549 NULL, getTexture, setFTitleBack, NULL, NULL},
550 {"PTitleBack", "(solid, \"#616161\")", NULL,
551 NULL, getTexture, setPTitleBack, NULL, NULL},
552 {"UTitleBack", "(solid, gray)", NULL,
553 NULL, getTexture, setUTitleBack, NULL, NULL},
554 {"ResizebarBack", "(solid, gray)", NULL,
555 NULL, getTexture, setResizebarBack, NULL, NULL},
556 {"MenuTitleColor", "white", NULL,
557 NULL, getColor, setMenuTitleColor, NULL, NULL},
558 {"MenuTextColor", "black", NULL,
559 NULL, getColor, setMenuTextColor, NULL, NULL},
560 {"MenuDisabledColor", "\"#616161\"", NULL,
561 NULL, getColor, setMenuDisabledColor, NULL, NULL},
562 {"MenuTitleBack", "(solid, black)", NULL,
563 NULL, getTexture, setMenuTitleBack, NULL, NULL},
564 {"MenuTextBack", "(solid, gray)", NULL,
565 NULL, getTexture, setMenuTextBack, NULL, NULL},
566 {"IconTitleColor", "white", NULL,
567 NULL, getColor, setIconTitleColor, NULL, NULL},
568 {"IconTitleBack", "black", NULL,
569 NULL, getColor, setIconTitleBack, NULL, NULL},
570 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
571 NULL, getPropList, setSwPOptions, NULL, NULL},
572 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
573 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
574 {"FrameBorderWidth", "1", NULL,
575 NULL, getInt, setFrameBorderWidth, NULL, NULL},
576 {"FrameBorderColor", "black", NULL,
577 NULL, getColor, setFrameBorderColor, NULL, NULL},
578 {"FrameSelectedBorderColor", "white", NULL,
579 NULL, getColor, setFrameSelectedBorderColor, NULL, NULL},
581 /* keybindings */
583 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
584 NULL, getKeybind, setKeyGrab, NULL, NULL},
585 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
586 NULL, getKeybind, setKeyGrab, NULL, NULL},
587 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
588 NULL, getKeybind, setKeyGrab, NULL, NULL},
589 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
590 NULL, getKeybind, setKeyGrab, NULL, NULL},
591 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
592 NULL, getKeybind, setKeyGrab, NULL, NULL},
593 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
594 NULL, getKeybind, setKeyGrab, NULL, NULL},
595 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
596 NULL, getKeybind, setKeyGrab, NULL, NULL },
597 {"HideKey", "None", (void *)WKBD_HIDE,
598 NULL, getKeybind, setKeyGrab, NULL, NULL},
599 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
600 NULL, getKeybind, setKeyGrab, NULL, NULL},
601 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
602 NULL, getKeybind, setKeyGrab, NULL, NULL},
603 {"CloseKey", "None", (void *)WKBD_CLOSE,
604 NULL, getKeybind, setKeyGrab, NULL, NULL},
605 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
606 NULL, getKeybind, setKeyGrab, NULL, NULL},
607 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
608 NULL, getKeybind, setKeyGrab, NULL, NULL},
609 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
610 NULL, getKeybind, setKeyGrab, NULL, NULL},
611 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
612 NULL, getKeybind, setKeyGrab, NULL, NULL},
613 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
614 NULL, getKeybind, setKeyGrab, NULL, NULL},
615 {"THMaximizeKey", "None", (void*)WKBD_THMAXIMIZE,
616 NULL, getKeybind, setKeyGrab, NULL, NULL},
617 {"BHMaximizeKey", "None", (void*)WKBD_BHMAXIMIZE,
618 NULL, getKeybind, setKeyGrab, NULL, NULL},
619 {"LTCMaximizeKey", "None", (void*)WKBD_LTCMAXIMIZE,
620 NULL, getKeybind, setKeyGrab, NULL, NULL},
621 {"RTCMaximizeKey", "None", (void*)WKBD_RTCMAXIMIZE,
622 NULL, getKeybind, setKeyGrab, NULL, NULL},
623 {"LBCMaximizeKey", "None", (void*)WKBD_LBCMAXIMIZE,
624 NULL, getKeybind, setKeyGrab, NULL, NULL},
625 {"RBCMaximizeKey", "None", (void*)WKBD_RBCMAXIMIZE,
626 NULL, getKeybind, setKeyGrab, NULL, NULL},
627 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
628 NULL, getKeybind, setKeyGrab, NULL, NULL},
629 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
630 NULL, getKeybind, setKeyGrab, NULL, NULL},
631 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
632 NULL, getKeybind, setKeyGrab, NULL, NULL},
633 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
634 NULL, getKeybind, setKeyGrab, NULL, NULL},
635 {"ShadeKey", "None", (void *)WKBD_SHADE,
636 NULL, getKeybind, setKeyGrab, NULL, NULL},
637 {"SelectKey", "None", (void *)WKBD_SELECT,
638 NULL, getKeybind, setKeyGrab, NULL, NULL},
639 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
640 NULL, getKeybind, setKeyGrab, NULL, NULL},
641 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
642 NULL, getKeybind, setKeyGrab, NULL, NULL},
643 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
644 NULL, getKeybind, setKeyGrab, NULL, NULL},
645 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
646 NULL, getKeybind, setKeyGrab, NULL, NULL},
647 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
648 NULL, getKeybind, setKeyGrab, NULL, NULL},
649 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
650 NULL, getKeybind, setKeyGrab, NULL, NULL},
651 {"LastWorkspaceKey", "None", (void *)WKBD_LASTWORKSPACE,
652 NULL, getKeybind, setKeyGrab, NULL, NULL},
653 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
654 NULL, getKeybind, setKeyGrab, NULL, NULL},
655 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
656 NULL, getKeybind, setKeyGrab, NULL, NULL},
657 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
658 NULL, getKeybind, setKeyGrab, NULL, NULL},
659 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
660 NULL, getKeybind, setKeyGrab, NULL, NULL},
661 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
662 NULL, getKeybind, setKeyGrab, NULL, NULL},
663 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
664 NULL, getKeybind, setKeyGrab, NULL, NULL},
665 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
666 NULL, getKeybind, setKeyGrab, NULL, NULL},
667 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
668 NULL, getKeybind, setKeyGrab, NULL, NULL},
669 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
670 NULL, getKeybind, setKeyGrab, NULL, NULL},
671 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
672 NULL, getKeybind, setKeyGrab, NULL, NULL},
673 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
674 NULL, getKeybind, setKeyGrab, NULL, NULL},
675 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
676 NULL, getKeybind, setKeyGrab, NULL, NULL},
677 {"MoveToWorkspace1Key", "None", (void *)WKBD_MOVE_WORKSPACE1,
678 NULL, getKeybind, setKeyGrab, NULL, NULL},
679 {"MoveToWorkspace2Key", "None", (void *)WKBD_MOVE_WORKSPACE2,
680 NULL, getKeybind, setKeyGrab, NULL, NULL},
681 {"MoveToWorkspace3Key", "None", (void *)WKBD_MOVE_WORKSPACE3,
682 NULL, getKeybind, setKeyGrab, NULL, NULL},
683 {"MoveToWorkspace4Key", "None", (void *)WKBD_MOVE_WORKSPACE4,
684 NULL, getKeybind, setKeyGrab, NULL, NULL},
685 {"MoveToWorkspace5Key", "None", (void *)WKBD_MOVE_WORKSPACE5,
686 NULL, getKeybind, setKeyGrab, NULL, NULL},
687 {"MoveToWorkspace6Key", "None", (void *)WKBD_MOVE_WORKSPACE6,
688 NULL, getKeybind, setKeyGrab, NULL, NULL},
689 {"MoveToWorkspace7Key", "None", (void *)WKBD_MOVE_WORKSPACE7,
690 NULL, getKeybind, setKeyGrab, NULL, NULL},
691 {"MoveToWorkspace8Key", "None", (void *)WKBD_MOVE_WORKSPACE8,
692 NULL, getKeybind, setKeyGrab, NULL, NULL},
693 {"MoveToWorkspace9Key", "None", (void *)WKBD_MOVE_WORKSPACE9,
694 NULL, getKeybind, setKeyGrab, NULL, NULL},
695 {"MoveToWorkspace10Key", "None", (void *)WKBD_MOVE_WORKSPACE10,
696 NULL, getKeybind, setKeyGrab, NULL, NULL},
697 {"MoveToNextWorkspaceKey", "None", (void *)WKBD_MOVE_NEXTWORKSPACE,
698 NULL, getKeybind, setKeyGrab, NULL, NULL},
699 {"MoveToPrevWorkspaceKey", "None", (void *)WKBD_MOVE_PREVWORKSPACE,
700 NULL, getKeybind, setKeyGrab, NULL, NULL},
701 {"MoveToLastWorkspaceKey", "None", (void *)WKBD_MOVE_LASTWORKSPACE,
702 NULL, getKeybind, setKeyGrab, NULL, NULL},
703 {"MoveToNextWorkspaceLayerKey", "None", (void *)WKBD_MOVE_NEXTWSLAYER,
704 NULL, getKeybind, setKeyGrab, NULL, NULL},
705 {"MoveToPrevWorkspaceLayerKey", "None", (void *)WKBD_MOVE_PREVWSLAYER,
706 NULL, getKeybind, setKeyGrab, NULL, NULL},
707 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
708 NULL, getKeybind, setKeyGrab, NULL, NULL},
709 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
710 NULL, getKeybind, setKeyGrab, NULL, NULL},
711 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
712 NULL, getKeybind, setKeyGrab, NULL, NULL},
713 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
714 NULL, getKeybind, setKeyGrab, NULL, NULL},
715 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
716 NULL, getKeybind, setKeyGrab, NULL, NULL},
717 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
718 NULL, getKeybind, setKeyGrab, NULL, NULL},
719 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
720 NULL, getKeybind, setKeyGrab, NULL, NULL},
721 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
722 NULL, getKeybind, setKeyGrab, NULL, NULL},
723 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
724 NULL, getKeybind, setKeyGrab, NULL, NULL},
725 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
726 NULL, getKeybind, setKeyGrab, NULL, NULL},
727 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
728 NULL, getKeybind, setKeyGrab, NULL, NULL},
729 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
730 NULL, getKeybind, setKeyGrab, NULL, NULL},
732 #ifdef KEEP_XKB_LOCK_STATUS
733 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
734 NULL, getKeybind, setKeyGrab, NULL, NULL},
735 {"KbdModeLock", "NO", NULL,
736 &wPreferences.modelock, getBool, NULL, NULL, NULL},
737 #endif /* KEEP_XKB_LOCK_STATUS */
739 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
740 NULL, getCursor, setCursor, NULL, NULL},
741 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
742 NULL, getCursor, setCursor, NULL, NULL},
743 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
744 NULL, getCursor, setCursor, NULL, NULL},
745 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
746 NULL, getCursor, setCursor, NULL, NULL},
747 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
748 NULL, getCursor, setCursor, NULL, NULL},
749 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
750 NULL, getCursor, setCursor, NULL, NULL},
751 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
752 NULL, getCursor, setCursor, NULL, NULL},
753 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
754 NULL, getCursor, setCursor, NULL, NULL},
755 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
756 NULL, getCursor, setCursor, NULL, NULL},
757 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
758 NULL, getCursor, setCursor, NULL, NULL},
759 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
760 NULL, getCursor, setCursor, NULL, NULL},
761 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
762 NULL, getCursor, setCursor, NULL, NULL},
763 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
764 NULL, getCursor, setCursor, NULL, NULL},
765 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
766 NULL, getCursor, setCursor, NULL, NULL},
767 {"DialogHistoryLines", "500", NULL,
768 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
769 {"CycleActiveHeadOnly", "NO", NULL,
770 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL},
771 {"CycleIgnoreMinimized", "NO", NULL,
772 &wPreferences.cycle_ignore_minimized, getBool, NULL, NULL, NULL}
775 static void initDefaults(void)
777 unsigned int i;
778 WDefaultEntry *entry;
780 WMPLSetCaseSensitive(False);
782 for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) {
783 entry = &optionList[i];
785 entry->plkey = WMCreatePLString(entry->key);
786 if (entry->default_value)
787 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
788 else
789 entry->plvalue = NULL;
792 for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) {
793 entry = &staticOptionList[i];
795 entry->plkey = WMCreatePLString(entry->key);
796 if (entry->default_value)
797 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
798 else
799 entry->plvalue = NULL;
803 static WMPropList *readGlobalDomain(const char *domainName, Bool requireDictionary)
805 WMPropList *globalDict = NULL;
806 char path[PATH_MAX];
807 struct stat stbuf;
809 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
810 if (stat(path, &stbuf) >= 0) {
811 globalDict = WMReadPropListFromFile(path);
812 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
813 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
814 WMReleasePropList(globalDict);
815 globalDict = NULL;
816 } else if (!globalDict) {
817 wwarning(_("could not load domain %s from global defaults database"), domainName);
821 return globalDict;
824 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
825 static void prependMenu(WMPropList * destarr, WMPropList * array)
827 WMPropList *item;
828 int i;
830 for (i = 0; i < WMGetPropListItemCount(array); i++) {
831 item = WMGetFromPLArray(array, i);
832 if (item)
833 WMInsertInPLArray(destarr, i + 1, item);
837 static void appendMenu(WMPropList * destarr, WMPropList * array)
839 WMPropList *item;
840 int i;
842 for (i = 0; i < WMGetPropListItemCount(array); i++) {
843 item = WMGetFromPLArray(array, i);
844 if (item)
845 WMAddToPLArray(destarr, item);
848 #endif
850 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
852 WMPropList *menu = menuDomain->dictionary;
853 WMPropList *submenu;
855 if (!menu || !WMIsPLArray(menu))
856 return;
858 #ifdef GLOBAL_PREAMBLE_MENU_FILE
859 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
861 if (submenu && !WMIsPLArray(submenu)) {
862 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
863 WMReleasePropList(submenu);
864 submenu = NULL;
866 if (submenu) {
867 prependMenu(menu, submenu);
868 WMReleasePropList(submenu);
870 #endif
872 #ifdef GLOBAL_EPILOGUE_MENU_FILE
873 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
875 if (submenu && !WMIsPLArray(submenu)) {
876 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
877 WMReleasePropList(submenu);
878 submenu = NULL;
880 if (submenu) {
881 appendMenu(menu, submenu);
882 WMReleasePropList(submenu);
884 #endif
886 menuDomain->dictionary = menu;
889 WDDomain *wDefaultsInitDomain(const char *domain, Bool requireDictionary)
891 WDDomain *db;
892 struct stat stbuf;
893 static int inited = 0;
894 const char *the_path;
895 WMPropList *shared_dict = NULL;
897 if (!inited) {
898 inited = 1;
899 initDefaults();
902 db = wmalloc(sizeof(WDDomain));
903 db->domain_name = domain;
904 db->path = wdefaultspathfordomain(domain);
905 the_path = db->path;
907 if (the_path && stat(the_path, &stbuf) >= 0) {
908 db->dictionary = WMReadPropListFromFile(the_path);
909 if (db->dictionary) {
910 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
911 WMReleasePropList(db->dictionary);
912 db->dictionary = NULL;
913 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
915 db->timestamp = stbuf.st_mtime;
916 } else {
917 wwarning(_("could not load domain %s from user defaults database"), domain);
921 /* global system dictionary */
922 shared_dict = readGlobalDomain(domain, requireDictionary);
924 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
925 WMIsPLDictionary(db->dictionary)) {
926 WMMergePLDictionaries(shared_dict, db->dictionary, True);
927 WMReleasePropList(db->dictionary);
928 db->dictionary = shared_dict;
929 if (stbuf.st_mtime > db->timestamp)
930 db->timestamp = stbuf.st_mtime;
931 } else if (!db->dictionary) {
932 db->dictionary = shared_dict;
933 if (stbuf.st_mtime > db->timestamp)
934 db->timestamp = stbuf.st_mtime;
937 return db;
940 void wReadStaticDefaults(WMPropList * dict)
942 WMPropList *plvalue;
943 WDefaultEntry *entry;
944 unsigned int i;
945 void *tdata;
947 for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) {
948 entry = &staticOptionList[i];
950 if (dict)
951 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
952 else
953 plvalue = NULL;
955 /* no default in the DB. Use builtin default */
956 if (!plvalue)
957 plvalue = entry->plvalue;
959 if (plvalue) {
960 /* convert data */
961 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
962 if (entry->update)
963 (*entry->update) (NULL, entry, tdata, entry->extra_data);
968 void wDefaultsCheckDomains(void* arg)
970 WScreen *scr;
971 struct stat stbuf;
972 WMPropList *shared_dict = NULL;
973 WMPropList *dict;
974 int i;
976 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
977 WDWindowMaker->timestamp = stbuf.st_mtime;
979 /* Global dictionary */
980 shared_dict = readGlobalDomain("WindowMaker", True);
982 /* User dictionary */
983 dict = WMReadPropListFromFile(WDWindowMaker->path);
985 if (dict) {
986 if (!WMIsPLDictionary(dict)) {
987 WMReleasePropList(dict);
988 dict = NULL;
989 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
990 "WindowMaker", WDWindowMaker->path);
991 } else {
992 if (shared_dict) {
993 WMMergePLDictionaries(shared_dict, dict, True);
994 WMReleasePropList(dict);
995 dict = shared_dict;
996 shared_dict = NULL;
999 for (i = 0; i < wScreenCount; i++) {
1000 scr = wScreenWithNumber(i);
1001 if (scr)
1002 wReadDefaults(scr, dict);
1005 if (WDWindowMaker->dictionary)
1006 WMReleasePropList(WDWindowMaker->dictionary);
1008 WDWindowMaker->dictionary = dict;
1010 } else {
1011 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1014 if (shared_dict)
1015 WMReleasePropList(shared_dict);
1019 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1020 /* global dictionary */
1021 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1022 /* user dictionary */
1023 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1024 if (dict) {
1025 if (!WMIsPLDictionary(dict)) {
1026 WMReleasePropList(dict);
1027 dict = NULL;
1028 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1029 "WMWindowAttributes", WDWindowAttributes->path);
1030 } else {
1031 if (shared_dict) {
1032 WMMergePLDictionaries(shared_dict, dict, True);
1033 WMReleasePropList(dict);
1034 dict = shared_dict;
1035 shared_dict = NULL;
1038 if (WDWindowAttributes->dictionary)
1039 WMReleasePropList(WDWindowAttributes->dictionary);
1041 WDWindowAttributes->dictionary = dict;
1042 for (i = 0; i < wScreenCount; i++) {
1043 scr = wScreenWithNumber(i);
1044 if (scr) {
1045 wDefaultUpdateIcons(scr);
1047 /* Update the panel image if changed */
1048 /* Don't worry. If the image is the same these
1049 * functions will have no performance impact. */
1050 create_logo_image(scr);
1054 } else {
1055 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1058 WDWindowAttributes->timestamp = stbuf.st_mtime;
1059 if (shared_dict)
1060 WMReleasePropList(shared_dict);
1063 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1064 dict = WMReadPropListFromFile(WDRootMenu->path);
1065 if (dict) {
1066 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1067 WMReleasePropList(dict);
1068 dict = NULL;
1069 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1070 "WMRootMenu", WDRootMenu->path);
1071 } else {
1072 if (WDRootMenu->dictionary)
1073 WMReleasePropList(WDRootMenu->dictionary);
1075 WDRootMenu->dictionary = dict;
1076 wDefaultsMergeGlobalMenus(WDRootMenu);
1078 } else {
1079 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1081 WDRootMenu->timestamp = stbuf.st_mtime;
1083 #ifndef HAVE_INOTIFY
1084 if (!arg)
1085 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1086 #endif
1089 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1091 WMPropList *plvalue, *old_value;
1092 WDefaultEntry *entry;
1093 unsigned int i;
1094 int update_workspace_back = 0; /* kluge :/ */
1095 unsigned int needs_refresh;
1096 void *tdata;
1097 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1099 needs_refresh = 0;
1101 for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) {
1102 entry = &optionList[i];
1104 if (new_dict)
1105 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1106 else
1107 plvalue = NULL;
1109 if (!old_dict)
1110 old_value = NULL;
1111 else
1112 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1114 if (!plvalue && !old_value) {
1115 /* no default in the DB. Use builtin default */
1116 plvalue = entry->plvalue;
1117 if (plvalue && new_dict)
1118 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1120 } else if (!plvalue) {
1121 /* value was deleted from DB. Keep current value */
1122 continue;
1123 } else if (!old_value) {
1124 /* set value for the 1st time */
1125 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1126 /* value has changed */
1127 } else {
1128 if (strcmp(entry->key, "WorkspaceBack") == 0
1129 && update_workspace_back && scr->flags.backimage_helper_launched) {
1130 } else {
1131 /* value was not changed since last time */
1132 continue;
1136 if (plvalue) {
1137 /* convert data */
1138 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1140 * If the WorkspaceSpecificBack data has been changed
1141 * so that the helper will be launched now, we must be
1142 * sure to send the default background texture config
1143 * to the helper.
1145 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1146 !scr->flags.backimage_helper_launched)
1147 update_workspace_back = 1;
1149 if (entry->update)
1150 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1156 if (needs_refresh != 0 && !scr->flags.startup) {
1157 int foo;
1159 foo = 0;
1160 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1161 foo |= WTextureSettings;
1162 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1163 foo |= WFontSettings;
1164 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1165 foo |= WColorSettings;
1166 if (foo)
1167 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1168 (void *)(uintptr_t) foo);
1170 foo = 0;
1171 if (needs_refresh & REFRESH_MENU_TEXTURE)
1172 foo |= WTextureSettings;
1173 if (needs_refresh & REFRESH_MENU_FONT)
1174 foo |= WFontSettings;
1175 if (needs_refresh & REFRESH_MENU_COLOR)
1176 foo |= WColorSettings;
1177 if (foo)
1178 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1180 foo = 0;
1181 if (needs_refresh & REFRESH_WINDOW_FONT)
1182 foo |= WFontSettings;
1183 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1184 foo |= WTextureSettings;
1185 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1186 foo |= WColorSettings;
1187 if (foo)
1188 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1190 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1191 foo = 0;
1192 if (needs_refresh & REFRESH_ICON_FONT)
1193 foo |= WFontSettings;
1194 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1195 foo |= WTextureSettings;
1196 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1197 foo |= WTextureSettings;
1198 if (foo)
1199 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1200 (void *)(uintptr_t) foo);
1202 if (needs_refresh & REFRESH_ICON_TILE)
1203 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1205 if (needs_refresh & REFRESH_WORKSPACE_MENU) {
1206 if (scr->workspace_menu)
1207 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
1208 if (scr->clip_ws_menu)
1209 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
1210 if (scr->workspace_submenu)
1211 scr->workspace_submenu->flags.realized = 0;
1212 if (scr->clip_submenu)
1213 scr->clip_submenu->flags.realized = 0;
1218 void wDefaultUpdateIcons(WScreen *scr)
1220 WAppIcon *aicon = scr->app_icon_list;
1221 WDrawerChain *dc;
1222 WWindow *wwin = scr->focused_window;
1224 while (aicon) {
1225 /* Get the application icon, default included */
1226 wIconChangeImageFile(aicon->icon, NULL);
1227 wAppIconPaint(aicon);
1228 aicon = aicon->next;
1231 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock)
1232 wClipIconPaint(scr->clip_icon);
1234 for (dc = scr->drawers; dc != NULL; dc = dc->next)
1235 wDrawerIconPaint(dc->adrawer->icon_array[0]);
1237 while (wwin) {
1238 if (wwin->icon && wwin->flags.miniaturized)
1239 wIconChangeImageFile(wwin->icon, NULL);
1240 wwin = wwin->prev;
1244 /* --------------------------- Local ----------------------- */
1246 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1247 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1248 entry->key, x); \
1249 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1250 var = entry->default_value;\
1251 } else var = WMGetFromPLString(value)\
1254 static int string2index(WMPropList *key, WMPropList *val, const char *def, WOptionEnumeration * values)
1256 char *str;
1257 WOptionEnumeration *v;
1258 char buffer[TOTAL_VALUES_LENGTH];
1260 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1261 for (v = values; v->string != NULL; v++) {
1262 if (strcasecmp(v->string, str) == 0)
1263 return v->value;
1267 buffer[0] = 0;
1268 for (v = values; v->string != NULL; v++) {
1269 if (!v->is_alias) {
1270 if (buffer[0] != 0)
1271 strcat(buffer, ", ");
1272 snprintf(buffer+strlen(buffer),
1273 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1276 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1277 WMGetFromPLString(key),
1278 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1279 buffer);
1281 if (def) {
1282 return string2index(key, val, NULL, values);
1285 return -1;
1289 * value - is the value in the defaults DB
1290 * addr - is the address to store the data
1291 * ret - is the address to store a pointer to a temporary buffer. ret
1292 * must not be freed and is used by the set functions
1294 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1296 static char data;
1297 const char *val;
1298 int second_pass = 0;
1300 GET_STRING_OR_DEFAULT("Boolean", val);
1302 again:
1303 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1304 || strcasecmp(val, "YES") == 0) {
1306 data = 1;
1307 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1308 || strcasecmp(val, "NO") == 0) {
1309 data = 0;
1310 } else {
1311 int i;
1312 if (sscanf(val, "%i", &i) == 1) {
1313 if (i != 0)
1314 data = 1;
1315 else
1316 data = 0;
1317 } else {
1318 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1319 if (second_pass == 0) {
1320 val = WMGetFromPLString(entry->plvalue);
1321 second_pass = 1;
1322 wwarning(_("using default \"%s\" instead"), val);
1323 goto again;
1325 return False;
1329 if (ret)
1330 *ret = &data;
1331 if (addr)
1332 *(char *)addr = data;
1334 return True;
1337 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1339 static int data;
1340 const char *val;
1342 GET_STRING_OR_DEFAULT("Integer", val);
1344 if (sscanf(val, "%i", &data) != 1) {
1345 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1346 val = WMGetFromPLString(entry->plvalue);
1347 wwarning(_("using default \"%s\" instead"), val);
1348 if (sscanf(val, "%i", &data) != 1) {
1349 return False;
1353 if (ret)
1354 *ret = &data;
1355 if (addr)
1356 *(int *)addr = data;
1358 return True;
1361 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1363 static WCoord data;
1364 char *val_x, *val_y;
1365 int nelem, changed = 0;
1366 WMPropList *elem_x, *elem_y;
1368 again:
1369 if (!WMIsPLArray(value)) {
1370 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1371 if (changed == 0) {
1372 value = entry->plvalue;
1373 changed = 1;
1374 wwarning(_("using default \"%s\" instead"), entry->default_value);
1375 goto again;
1377 return False;
1380 nelem = WMGetPropListItemCount(value);
1381 if (nelem != 2) {
1382 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1383 if (changed == 0) {
1384 value = entry->plvalue;
1385 changed = 1;
1386 wwarning(_("using default \"%s\" instead"), entry->default_value);
1387 goto again;
1389 return False;
1392 elem_x = WMGetFromPLArray(value, 0);
1393 elem_y = WMGetFromPLArray(value, 1);
1395 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1396 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1397 if (changed == 0) {
1398 value = entry->plvalue;
1399 changed = 1;
1400 wwarning(_("using default \"%s\" instead"), entry->default_value);
1401 goto again;
1403 return False;
1406 val_x = WMGetFromPLString(elem_x);
1407 val_y = WMGetFromPLString(elem_y);
1409 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1410 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1411 if (changed == 0) {
1412 value = entry->plvalue;
1413 changed = 1;
1414 wwarning(_("using default \"%s\" instead"), entry->default_value);
1415 goto again;
1417 return False;
1420 if (data.x < 0)
1421 data.x = 0;
1422 else if (data.x > scr->scr_width / 3)
1423 data.x = scr->scr_width / 3;
1424 if (data.y < 0)
1425 data.y = 0;
1426 else if (data.y > scr->scr_height / 3)
1427 data.y = scr->scr_height / 3;
1429 if (ret)
1430 *ret = &data;
1431 if (addr)
1432 *(WCoord *) addr = data;
1434 return True;
1437 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1439 WMRetainPropList(value);
1441 *ret = value;
1443 return True;
1446 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1448 static char *data;
1449 int i, count, len;
1450 char *ptr;
1451 WMPropList *d;
1452 int changed = 0;
1454 again:
1455 if (!WMIsPLArray(value)) {
1456 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1457 if (changed == 0) {
1458 value = entry->plvalue;
1459 changed = 1;
1460 wwarning(_("using default \"%s\" instead"), entry->default_value);
1461 goto again;
1463 return False;
1466 i = 0;
1467 count = WMGetPropListItemCount(value);
1468 if (count < 1) {
1469 if (changed == 0) {
1470 value = entry->plvalue;
1471 changed = 1;
1472 wwarning(_("using default \"%s\" instead"), entry->default_value);
1473 goto again;
1475 return False;
1478 len = 0;
1479 for (i = 0; i < count; i++) {
1480 d = WMGetFromPLArray(value, i);
1481 if (!d || !WMIsPLString(d)) {
1482 count = i;
1483 break;
1485 len += strlen(WMGetFromPLString(d)) + 1;
1488 ptr = data = wmalloc(len + 1);
1490 for (i = 0; i < count; i++) {
1491 d = WMGetFromPLArray(value, i);
1492 if (!d || !WMIsPLString(d)) {
1493 break;
1495 strcpy(ptr, WMGetFromPLString(d));
1496 ptr += strlen(WMGetFromPLString(d));
1497 *ptr = ':';
1498 ptr++;
1500 ptr--;
1501 *(ptr--) = 0;
1503 if (*(char **)addr != NULL) {
1504 wfree(*(char **)addr);
1506 *(char **)addr = data;
1508 return True;
1511 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1513 static signed char data;
1515 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1516 if (data < 0)
1517 return False;
1519 if (ret)
1520 *ret = &data;
1521 if (addr)
1522 *(signed char *)addr = data;
1524 return True;
1528 * (solid <color>)
1529 * (hgradient <color> <color>)
1530 * (vgradient <color> <color>)
1531 * (dgradient <color> <color>)
1532 * (mhgradient <color> <color> ...)
1533 * (mvgradient <color> <color> ...)
1534 * (mdgradient <color> <color> ...)
1535 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1536 * (tpixmap <file> <color>)
1537 * (spixmap <file> <color>)
1538 * (cpixmap <file> <color>)
1539 * (thgradient <file> <opaqueness> <color> <color>)
1540 * (tvgradient <file> <opaqueness> <color> <color>)
1541 * (tdgradient <file> <opaqueness> <color> <color>)
1542 * (function <lib> <function> ...)
1545 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1547 WMPropList *elem;
1548 char *val;
1549 int nelem;
1550 WTexture *texture = NULL;
1552 nelem = WMGetPropListItemCount(pl);
1553 if (nelem < 1)
1554 return NULL;
1556 elem = WMGetFromPLArray(pl, 0);
1557 if (!elem || !WMIsPLString(elem))
1558 return NULL;
1559 val = WMGetFromPLString(elem);
1561 if (strcasecmp(val, "solid") == 0) {
1562 XColor color;
1564 if (nelem != 2)
1565 return NULL;
1567 /* get color */
1569 elem = WMGetFromPLArray(pl, 1);
1570 if (!elem || !WMIsPLString(elem))
1571 return NULL;
1572 val = WMGetFromPLString(elem);
1574 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1575 wwarning(_("\"%s\" is not a valid color name"), val);
1576 return NULL;
1579 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1580 } else if (strcasecmp(val, "dgradient") == 0
1581 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1582 RColor color1, color2;
1583 XColor xcolor;
1584 int type;
1586 if (nelem != 3) {
1587 wwarning(_("bad number of arguments in gradient specification"));
1588 return NULL;
1591 if (val[0] == 'd' || val[0] == 'D')
1592 type = WTEX_DGRADIENT;
1593 else if (val[0] == 'h' || val[0] == 'H')
1594 type = WTEX_HGRADIENT;
1595 else
1596 type = WTEX_VGRADIENT;
1598 /* get from color */
1599 elem = WMGetFromPLArray(pl, 1);
1600 if (!elem || !WMIsPLString(elem))
1601 return NULL;
1602 val = WMGetFromPLString(elem);
1604 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1605 wwarning(_("\"%s\" is not a valid color name"), val);
1606 return NULL;
1608 color1.alpha = 255;
1609 color1.red = xcolor.red >> 8;
1610 color1.green = xcolor.green >> 8;
1611 color1.blue = xcolor.blue >> 8;
1613 /* get to color */
1614 elem = WMGetFromPLArray(pl, 2);
1615 if (!elem || !WMIsPLString(elem)) {
1616 return NULL;
1618 val = WMGetFromPLString(elem);
1620 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1621 wwarning(_("\"%s\" is not a valid color name"), val);
1622 return NULL;
1624 color2.alpha = 255;
1625 color2.red = xcolor.red >> 8;
1626 color2.green = xcolor.green >> 8;
1627 color2.blue = xcolor.blue >> 8;
1629 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1631 } else if (strcasecmp(val, "igradient") == 0) {
1632 RColor colors1[2], colors2[2];
1633 int th1, th2;
1634 XColor xcolor;
1635 int i;
1637 if (nelem != 7) {
1638 wwarning(_("bad number of arguments in gradient specification"));
1639 return NULL;
1642 /* get from color */
1643 for (i = 0; i < 2; i++) {
1644 elem = WMGetFromPLArray(pl, 1 + i);
1645 if (!elem || !WMIsPLString(elem))
1646 return NULL;
1647 val = WMGetFromPLString(elem);
1649 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1650 wwarning(_("\"%s\" is not a valid color name"), val);
1651 return NULL;
1653 colors1[i].alpha = 255;
1654 colors1[i].red = xcolor.red >> 8;
1655 colors1[i].green = xcolor.green >> 8;
1656 colors1[i].blue = xcolor.blue >> 8;
1658 elem = WMGetFromPLArray(pl, 3);
1659 if (!elem || !WMIsPLString(elem))
1660 return NULL;
1661 val = WMGetFromPLString(elem);
1662 th1 = atoi(val);
1664 /* get from color */
1665 for (i = 0; i < 2; i++) {
1666 elem = WMGetFromPLArray(pl, 4 + i);
1667 if (!elem || !WMIsPLString(elem))
1668 return NULL;
1669 val = WMGetFromPLString(elem);
1671 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1672 wwarning(_("\"%s\" is not a valid color name"), val);
1673 return NULL;
1675 colors2[i].alpha = 255;
1676 colors2[i].red = xcolor.red >> 8;
1677 colors2[i].green = xcolor.green >> 8;
1678 colors2[i].blue = xcolor.blue >> 8;
1680 elem = WMGetFromPLArray(pl, 6);
1681 if (!elem || !WMIsPLString(elem))
1682 return NULL;
1683 val = WMGetFromPLString(elem);
1684 th2 = atoi(val);
1686 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1688 } else if (strcasecmp(val, "mhgradient") == 0
1689 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1690 XColor color;
1691 RColor **colors;
1692 int i, count;
1693 int type;
1695 if (nelem < 3) {
1696 wwarning(_("too few arguments in multicolor gradient specification"));
1697 return NULL;
1700 if (val[1] == 'h' || val[1] == 'H')
1701 type = WTEX_MHGRADIENT;
1702 else if (val[1] == 'v' || val[1] == 'V')
1703 type = WTEX_MVGRADIENT;
1704 else
1705 type = WTEX_MDGRADIENT;
1707 count = nelem - 1;
1709 colors = wmalloc(sizeof(RColor *) * (count + 1));
1711 for (i = 0; i < count; i++) {
1712 elem = WMGetFromPLArray(pl, i + 1);
1713 if (!elem || !WMIsPLString(elem)) {
1714 for (--i; i >= 0; --i) {
1715 wfree(colors[i]);
1717 wfree(colors);
1718 return NULL;
1720 val = WMGetFromPLString(elem);
1722 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1723 wwarning(_("\"%s\" is not a valid color name"), val);
1724 for (--i; i >= 0; --i) {
1725 wfree(colors[i]);
1727 wfree(colors);
1728 return NULL;
1729 } else {
1730 colors[i] = wmalloc(sizeof(RColor));
1731 colors[i]->red = color.red >> 8;
1732 colors[i]->green = color.green >> 8;
1733 colors[i]->blue = color.blue >> 8;
1736 colors[i] = NULL;
1738 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1739 } else if (strcasecmp(val, "spixmap") == 0 ||
1740 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1741 XColor color;
1742 int type;
1744 if (nelem != 3)
1745 return NULL;
1747 if (val[0] == 's' || val[0] == 'S')
1748 type = WTP_SCALE;
1749 else if (val[0] == 'c' || val[0] == 'C')
1750 type = WTP_CENTER;
1751 else
1752 type = WTP_TILE;
1754 /* get color */
1755 elem = WMGetFromPLArray(pl, 2);
1756 if (!elem || !WMIsPLString(elem)) {
1757 return NULL;
1759 val = WMGetFromPLString(elem);
1761 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1762 wwarning(_("\"%s\" is not a valid color name"), val);
1763 return NULL;
1766 /* file name */
1767 elem = WMGetFromPLArray(pl, 1);
1768 if (!elem || !WMIsPLString(elem))
1769 return NULL;
1770 val = WMGetFromPLString(elem);
1772 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1773 } else if (strcasecmp(val, "thgradient") == 0
1774 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1775 RColor color1, color2;
1776 XColor xcolor;
1777 int opacity;
1778 int style;
1780 if (val[1] == 'h' || val[1] == 'H')
1781 style = WTEX_THGRADIENT;
1782 else if (val[1] == 'v' || val[1] == 'V')
1783 style = WTEX_TVGRADIENT;
1784 else
1785 style = WTEX_TDGRADIENT;
1787 if (nelem != 5) {
1788 wwarning(_("bad number of arguments in textured gradient specification"));
1789 return NULL;
1792 /* get from color */
1793 elem = WMGetFromPLArray(pl, 3);
1794 if (!elem || !WMIsPLString(elem))
1795 return NULL;
1796 val = WMGetFromPLString(elem);
1798 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1799 wwarning(_("\"%s\" is not a valid color name"), val);
1800 return NULL;
1802 color1.alpha = 255;
1803 color1.red = xcolor.red >> 8;
1804 color1.green = xcolor.green >> 8;
1805 color1.blue = xcolor.blue >> 8;
1807 /* get to color */
1808 elem = WMGetFromPLArray(pl, 4);
1809 if (!elem || !WMIsPLString(elem)) {
1810 return NULL;
1812 val = WMGetFromPLString(elem);
1814 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1815 wwarning(_("\"%s\" is not a valid color name"), val);
1816 return NULL;
1818 color2.alpha = 255;
1819 color2.red = xcolor.red >> 8;
1820 color2.green = xcolor.green >> 8;
1821 color2.blue = xcolor.blue >> 8;
1823 /* get opacity */
1824 elem = WMGetFromPLArray(pl, 2);
1825 if (!elem || !WMIsPLString(elem))
1826 opacity = 128;
1827 else
1828 val = WMGetFromPLString(elem);
1830 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1831 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1832 opacity = 128;
1835 /* get file name */
1836 elem = WMGetFromPLArray(pl, 1);
1837 if (!elem || !WMIsPLString(elem))
1838 return NULL;
1839 val = WMGetFromPLString(elem);
1841 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1842 } else if (strcasecmp(val, "function") == 0) {
1843 /* Leave this in to handle the unlikely case of
1844 * someone actually having function textures configured */
1845 wwarning("function texture support has been removed");
1846 return NULL;
1847 } else {
1848 wwarning(_("invalid texture type %s"), val);
1849 return NULL;
1851 return texture;
1854 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1856 static WTexture *texture;
1857 int changed = 0;
1859 again:
1860 if (!WMIsPLArray(value)) {
1861 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1862 if (changed == 0) {
1863 value = entry->plvalue;
1864 changed = 1;
1865 wwarning(_("using default \"%s\" instead"), entry->default_value);
1866 goto again;
1868 return False;
1871 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1872 WMPropList *pl;
1874 pl = WMGetFromPLArray(value, 0);
1875 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1876 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1877 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1878 entry->key, "Solid Texture");
1880 value = entry->plvalue;
1881 changed = 1;
1882 wwarning(_("using default \"%s\" instead"), entry->default_value);
1883 goto again;
1887 texture = parse_texture(scr, value);
1889 if (!texture) {
1890 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1891 if (changed == 0) {
1892 value = entry->plvalue;
1893 changed = 1;
1894 wwarning(_("using default \"%s\" instead"), entry->default_value);
1895 goto again;
1897 return False;
1900 if (ret)
1901 *ret = &texture;
1903 if (addr)
1904 *(WTexture **) addr = texture;
1906 return True;
1909 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1911 WMPropList *elem;
1912 int changed = 0;
1913 char *val;
1914 int nelem;
1916 again:
1917 if (!WMIsPLArray(value)) {
1918 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1919 "WorkspaceBack", "Texture or None");
1920 if (changed == 0) {
1921 value = entry->plvalue;
1922 changed = 1;
1923 wwarning(_("using default \"%s\" instead"), entry->default_value);
1924 goto again;
1926 return False;
1929 /* only do basic error checking and verify for None texture */
1931 nelem = WMGetPropListItemCount(value);
1932 if (nelem > 0) {
1933 elem = WMGetFromPLArray(value, 0);
1934 if (!elem || !WMIsPLString(elem)) {
1935 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1936 if (changed == 0) {
1937 value = entry->plvalue;
1938 changed = 1;
1939 wwarning(_("using default \"%s\" instead"), entry->default_value);
1940 goto again;
1942 return False;
1944 val = WMGetFromPLString(elem);
1946 if (strcasecmp(val, "None") == 0)
1947 return True;
1949 *ret = WMRetainPropList(value);
1951 return True;
1954 static int
1955 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1957 WMPropList *elem;
1958 int nelem;
1959 int changed = 0;
1961 again:
1962 if (!WMIsPLArray(value)) {
1963 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1964 "WorkspaceSpecificBack", "an array of textures");
1965 if (changed == 0) {
1966 value = entry->plvalue;
1967 changed = 1;
1968 wwarning(_("using default \"%s\" instead"), entry->default_value);
1969 goto again;
1971 return False;
1974 /* only do basic error checking and verify for None texture */
1976 nelem = WMGetPropListItemCount(value);
1977 if (nelem > 0) {
1978 while (nelem--) {
1979 elem = WMGetFromPLArray(value, nelem);
1980 if (!elem || !WMIsPLArray(elem)) {
1981 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1982 nelem);
1987 *ret = WMRetainPropList(value);
1989 #ifdef notworking
1991 * Kluge to force wmsetbg helper to set the default background.
1992 * If the WorkspaceSpecificBack is changed once wmaker has started,
1993 * the WorkspaceBack won't be sent to the helper, unless the user
1994 * changes it's value too. So, we must force this by removing the
1995 * value from the defaults DB.
1997 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1998 WMPropList *key = WMCreatePLString("WorkspaceBack");
2000 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2002 WMReleasePropList(key);
2004 #endif
2005 return True;
2008 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2010 static WMFont *font;
2011 const char *val;
2013 GET_STRING_OR_DEFAULT("Font", val);
2015 font = WMCreateFont(scr->wmscreen, val);
2016 if (!font)
2017 font = WMCreateFont(scr->wmscreen, "fixed");
2019 if (!font) {
2020 wfatal(_("could not load any usable font!!!"));
2021 exit(1);
2024 if (ret)
2025 *ret = font;
2027 /* can't assign font value outside update function */
2028 wassertrv(addr == NULL, True);
2030 return True;
2033 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2035 static XColor color;
2036 const char *val;
2037 int second_pass = 0;
2039 GET_STRING_OR_DEFAULT("Color", val);
2041 again:
2042 if (!wGetColor(scr, val, &color)) {
2043 wwarning(_("could not get color for key \"%s\""), entry->key);
2044 if (second_pass == 0) {
2045 val = WMGetFromPLString(entry->plvalue);
2046 second_pass = 1;
2047 wwarning(_("using default \"%s\" instead"), val);
2048 goto again;
2050 return False;
2053 if (ret)
2054 *ret = &color;
2056 assert(addr == NULL);
2058 if (addr)
2059 *(unsigned long*)addr = pixel;
2062 return True;
2065 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2067 static WShortKey shortcut;
2068 KeySym ksym;
2069 const char *val;
2070 char *k;
2071 char buf[MAX_SHORTCUT_LENGTH], *b;
2073 GET_STRING_OR_DEFAULT("Key spec", val);
2075 if (!val || strcasecmp(val, "NONE") == 0) {
2076 shortcut.keycode = 0;
2077 shortcut.modifier = 0;
2078 if (ret)
2079 *ret = &shortcut;
2080 return True;
2083 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2085 b = (char *)buf;
2087 /* get modifiers */
2088 shortcut.modifier = 0;
2089 while ((k = strchr(b, '+')) != NULL) {
2090 int mod;
2092 *k = 0;
2093 mod = wXModifierFromKey(b);
2094 if (mod < 0) {
2095 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2096 return False;
2098 shortcut.modifier |= mod;
2100 b = k + 1;
2103 /* get key */
2104 ksym = XStringToKeysym(b);
2106 if (ksym == NoSymbol) {
2107 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2108 return False;
2111 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2112 if (shortcut.keycode == 0) {
2113 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2114 return False;
2117 if (ret)
2118 *ret = &shortcut;
2120 return True;
2123 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2125 static int mask;
2126 const char *str;
2128 GET_STRING_OR_DEFAULT("Modifier Key", str);
2130 if (!str)
2131 return False;
2133 mask = wXModifierFromKey(str);
2134 if (mask < 0) {
2135 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2136 mask = 0;
2137 return False;
2140 if (addr)
2141 *(int *)addr = mask;
2143 if (ret)
2144 *ret = &mask;
2146 return True;
2149 # include <X11/cursorfont.h>
2150 typedef struct {
2151 const char *name;
2152 int id;
2153 } WCursorLookup;
2155 #define CURSOR_ID_NONE (XC_num_glyphs)
2157 static const WCursorLookup cursor_table[] = {
2158 {"X_cursor", XC_X_cursor},
2159 {"arrow", XC_arrow},
2160 {"based_arrow_down", XC_based_arrow_down},
2161 {"based_arrow_up", XC_based_arrow_up},
2162 {"boat", XC_boat},
2163 {"bogosity", XC_bogosity},
2164 {"bottom_left_corner", XC_bottom_left_corner},
2165 {"bottom_right_corner", XC_bottom_right_corner},
2166 {"bottom_side", XC_bottom_side},
2167 {"bottom_tee", XC_bottom_tee},
2168 {"box_spiral", XC_box_spiral},
2169 {"center_ptr", XC_center_ptr},
2170 {"circle", XC_circle},
2171 {"clock", XC_clock},
2172 {"coffee_mug", XC_coffee_mug},
2173 {"cross", XC_cross},
2174 {"cross_reverse", XC_cross_reverse},
2175 {"crosshair", XC_crosshair},
2176 {"diamond_cross", XC_diamond_cross},
2177 {"dot", XC_dot},
2178 {"dotbox", XC_dotbox},
2179 {"double_arrow", XC_double_arrow},
2180 {"draft_large", XC_draft_large},
2181 {"draft_small", XC_draft_small},
2182 {"draped_box", XC_draped_box},
2183 {"exchange", XC_exchange},
2184 {"fleur", XC_fleur},
2185 {"gobbler", XC_gobbler},
2186 {"gumby", XC_gumby},
2187 {"hand1", XC_hand1},
2188 {"hand2", XC_hand2},
2189 {"heart", XC_heart},
2190 {"icon", XC_icon},
2191 {"iron_cross", XC_iron_cross},
2192 {"left_ptr", XC_left_ptr},
2193 {"left_side", XC_left_side},
2194 {"left_tee", XC_left_tee},
2195 {"leftbutton", XC_leftbutton},
2196 {"ll_angle", XC_ll_angle},
2197 {"lr_angle", XC_lr_angle},
2198 {"man", XC_man},
2199 {"middlebutton", XC_middlebutton},
2200 {"mouse", XC_mouse},
2201 {"pencil", XC_pencil},
2202 {"pirate", XC_pirate},
2203 {"plus", XC_plus},
2204 {"question_arrow", XC_question_arrow},
2205 {"right_ptr", XC_right_ptr},
2206 {"right_side", XC_right_side},
2207 {"right_tee", XC_right_tee},
2208 {"rightbutton", XC_rightbutton},
2209 {"rtl_logo", XC_rtl_logo},
2210 {"sailboat", XC_sailboat},
2211 {"sb_down_arrow", XC_sb_down_arrow},
2212 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2213 {"sb_left_arrow", XC_sb_left_arrow},
2214 {"sb_right_arrow", XC_sb_right_arrow},
2215 {"sb_up_arrow", XC_sb_up_arrow},
2216 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2217 {"shuttle", XC_shuttle},
2218 {"sizing", XC_sizing},
2219 {"spider", XC_spider},
2220 {"spraycan", XC_spraycan},
2221 {"star", XC_star},
2222 {"target", XC_target},
2223 {"tcross", XC_tcross},
2224 {"top_left_arrow", XC_top_left_arrow},
2225 {"top_left_corner", XC_top_left_corner},
2226 {"top_right_corner", XC_top_right_corner},
2227 {"top_side", XC_top_side},
2228 {"top_tee", XC_top_tee},
2229 {"trek", XC_trek},
2230 {"ul_angle", XC_ul_angle},
2231 {"umbrella", XC_umbrella},
2232 {"ur_angle", XC_ur_angle},
2233 {"watch", XC_watch},
2234 {"xterm", XC_xterm},
2235 {NULL, CURSOR_ID_NONE}
2238 static void check_bitmap_status(int status, const char *filename, Pixmap bitmap)
2240 switch (status) {
2241 case BitmapOpenFailed:
2242 wwarning(_("failed to open bitmap file \"%s\""), filename);
2243 break;
2244 case BitmapFileInvalid:
2245 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2246 break;
2247 case BitmapNoMemory:
2248 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2249 break;
2250 case BitmapSuccess:
2251 XFreePixmap(dpy, bitmap);
2252 break;
2257 * (none)
2258 * (builtin, <cursor_name>)
2259 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2261 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2263 WMPropList *elem;
2264 char *val;
2265 int nelem;
2266 int status = 0;
2268 nelem = WMGetPropListItemCount(pl);
2269 if (nelem < 1) {
2270 return (status);
2272 elem = WMGetFromPLArray(pl, 0);
2273 if (!elem || !WMIsPLString(elem)) {
2274 return (status);
2276 val = WMGetFromPLString(elem);
2278 if (strcasecmp(val, "none") == 0) {
2279 status = 1;
2280 *cursor = None;
2281 } else if (strcasecmp(val, "builtin") == 0) {
2282 int i;
2283 int cursor_id = CURSOR_ID_NONE;
2285 if (nelem != 2) {
2286 wwarning(_("bad number of arguments in cursor specification"));
2287 return (status);
2289 elem = WMGetFromPLArray(pl, 1);
2290 if (!elem || !WMIsPLString(elem)) {
2291 return (status);
2293 val = WMGetFromPLString(elem);
2295 for (i = 0; cursor_table[i].name != NULL; i++) {
2296 if (strcasecmp(val, cursor_table[i].name) == 0) {
2297 cursor_id = cursor_table[i].id;
2298 break;
2301 if (CURSOR_ID_NONE == cursor_id) {
2302 wwarning(_("unknown builtin cursor name \"%s\""), val);
2303 } else {
2304 *cursor = XCreateFontCursor(dpy, cursor_id);
2305 status = 1;
2307 } else if (strcasecmp(val, "bitmap") == 0) {
2308 char *bitmap_name;
2309 char *mask_name;
2310 int bitmap_status;
2311 int mask_status;
2312 Pixmap bitmap;
2313 Pixmap mask;
2314 unsigned int w, h;
2315 int x, y;
2316 XColor fg, bg;
2318 if (nelem != 3) {
2319 wwarning(_("bad number of arguments in cursor specification"));
2320 return (status);
2322 elem = WMGetFromPLArray(pl, 1);
2323 if (!elem || !WMIsPLString(elem)) {
2324 return (status);
2326 val = WMGetFromPLString(elem);
2327 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2328 if (!bitmap_name) {
2329 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2330 return (status);
2332 elem = WMGetFromPLArray(pl, 2);
2333 if (!elem || !WMIsPLString(elem)) {
2334 wfree(bitmap_name);
2335 return (status);
2337 val = WMGetFromPLString(elem);
2338 mask_name = FindImage(wPreferences.pixmap_path, val);
2339 if (!mask_name) {
2340 wfree(bitmap_name);
2341 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2342 return (status);
2344 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2345 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2346 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2347 fg.pixel = scr->black_pixel;
2348 bg.pixel = scr->white_pixel;
2349 XQueryColor(dpy, scr->w_colormap, &fg);
2350 XQueryColor(dpy, scr->w_colormap, &bg);
2351 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2352 status = 1;
2354 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2355 check_bitmap_status(mask_status, mask_name, mask);
2356 wfree(bitmap_name);
2357 wfree(mask_name);
2359 return (status);
2362 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2364 static Cursor cursor;
2365 int status;
2366 int changed = 0;
2368 again:
2369 if (!WMIsPLArray(value)) {
2370 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2371 entry->key, "cursor specification");
2372 if (!changed) {
2373 value = entry->plvalue;
2374 changed = 1;
2375 wwarning(_("using default \"%s\" instead"), entry->default_value);
2376 goto again;
2378 return (False);
2380 status = parse_cursor(scr, value, &cursor);
2381 if (!status) {
2382 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2383 if (!changed) {
2384 value = entry->plvalue;
2385 changed = 1;
2386 wwarning(_("using default \"%s\" instead"), entry->default_value);
2387 goto again;
2389 return (False);
2391 if (ret) {
2392 *ret = &cursor;
2394 if (addr) {
2395 *(Cursor *) addr = cursor;
2397 return (True);
2400 #undef CURSOR_ID_NONE
2402 /* ---------------- value setting functions --------------- */
2403 static int setJustify(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2405 return REFRESH_WINDOW_TITLE_COLOR;
2408 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2410 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2413 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2415 char *flag = tdata;
2416 long which = (long) extra_data;
2418 switch (which) {
2419 case WM_DOCK:
2420 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2421 // Drawers require the dock
2422 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || wPreferences.flags.nodock;
2423 break;
2424 case WM_CLIP:
2425 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2426 break;
2427 case WM_DRAWER:
2428 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || *flag;
2429 break;
2430 default:
2431 break;
2433 return 0;
2436 static int setClipMergedInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2438 char *flag = tdata;
2440 wPreferences.flags.clip_merged_in_dock = *flag;
2441 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2442 return 0;
2445 static int setWrapAppiconsInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2447 char *flag = tdata;
2449 wPreferences.flags.wrap_appicons_in_dock = *flag;
2450 return 0;
2453 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2455 if (scr->workspaces) {
2456 wWorkspaceForceChange(scr, scr->current_workspace);
2457 wArrangeIcons(scr, False);
2459 return 0;
2462 static int setIconTile(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2464 Pixmap pixmap;
2465 RImage *img;
2466 WTexture ** texture = tdata;
2467 int reset = 0;
2469 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2470 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2471 ? WREL_ICON : WREL_FLAT);
2472 if (!img) {
2473 wwarning(_("could not render texture for icon background"));
2474 if (!entry->addr)
2475 wTextureDestroy(scr, *texture);
2476 return 0;
2478 RConvertImage(scr->rcontext, img, &pixmap);
2480 if (scr->icon_tile) {
2481 reset = 1;
2482 RReleaseImage(scr->icon_tile);
2483 XFreePixmap(dpy, scr->icon_tile_pixmap);
2486 scr->icon_tile = img;
2488 /* put the icon in the noticeboard hint */
2489 PropSetIconTileHint(scr, img);
2491 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock) {
2492 if (scr->clip_tile) {
2493 RReleaseImage(scr->clip_tile);
2495 scr->clip_tile = wClipMakeTile(scr, img);
2498 if (!wPreferences.flags.nodrawer) {
2499 if (scr->drawer_tile) {
2500 RReleaseImage(scr->drawer_tile);
2502 scr->drawer_tile = wDrawerMakeTile(scr, img);
2505 scr->icon_tile_pixmap = pixmap;
2507 if (scr->def_icon_rimage) {
2508 RReleaseImage(scr->def_icon_rimage);
2509 scr->def_icon_rimage = NULL;
2512 if (scr->icon_back_texture)
2513 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2515 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2517 /* Free the texture as nobody else will use it, nor refer to it. */
2518 if (!entry->addr)
2519 wTextureDestroy(scr, *texture);
2521 return (reset ? REFRESH_ICON_TILE : 0);
2524 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2526 WMFont *font = tdata;
2528 if (scr->title_font) {
2529 WMReleaseFont(scr->title_font);
2531 scr->title_font = font;
2533 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2536 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2538 WMFont *font = tdata;
2540 if (scr->menu_title_font) {
2541 WMReleaseFont(scr->menu_title_font);
2544 scr->menu_title_font = font;
2546 return REFRESH_MENU_TITLE_FONT;
2549 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2551 WMFont *font = tdata;
2553 if (scr->menu_entry_font) {
2554 WMReleaseFont(scr->menu_entry_font);
2556 scr->menu_entry_font = font;
2558 return REFRESH_MENU_FONT;
2561 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2563 WMFont *font = tdata;
2565 if (scr->icon_title_font) {
2566 WMReleaseFont(scr->icon_title_font);
2569 scr->icon_title_font = font;
2571 return REFRESH_ICON_FONT;
2574 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2576 WMFont *font = tdata;
2578 if (scr->clip_title_font) {
2579 WMReleaseFont(scr->clip_title_font);
2582 scr->clip_title_font = font;
2584 return REFRESH_ICON_FONT;
2587 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2589 WMFont *font = tdata;
2591 if (scr->workspace_name_font) {
2592 WMReleaseFont(scr->workspace_name_font);
2595 scr->workspace_name_font = font;
2597 return 0;
2600 static int setHightlight(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2602 XColor *color = tdata;
2604 if (scr->select_color)
2605 WMReleaseColor(scr->select_color);
2607 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2609 wFreeColor(scr, color->pixel);
2611 return REFRESH_MENU_COLOR;
2614 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2616 XColor *color = tdata;
2618 if (scr->select_text_color)
2619 WMReleaseColor(scr->select_text_color);
2621 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2623 wFreeColor(scr, color->pixel);
2625 return REFRESH_MENU_COLOR;
2628 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2630 XColor *color = tdata;
2631 long widx = (long) extra_data;
2633 if (scr->clip_title_color[widx])
2634 WMReleaseColor(scr->clip_title_color[widx]);
2636 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2637 wFreeColor(scr, color->pixel);
2639 return REFRESH_ICON_TITLE_COLOR;
2642 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2644 XColor *color = tdata;
2645 long widx = (long) extra_data;
2647 if (scr->window_title_color[widx])
2648 WMReleaseColor(scr->window_title_color[widx]);
2650 scr->window_title_color[widx] =
2651 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2653 wFreeColor(scr, color->pixel);
2655 return REFRESH_WINDOW_TITLE_COLOR;
2658 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2660 XColor *color = tdata;
2662 if (scr->menu_title_color[0])
2663 WMReleaseColor(scr->menu_title_color[0]);
2665 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2667 wFreeColor(scr, color->pixel);
2669 return REFRESH_MENU_TITLE_COLOR;
2672 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2674 XColor *color = tdata;
2676 if (scr->mtext_color)
2677 WMReleaseColor(scr->mtext_color);
2679 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2681 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2682 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2683 } else {
2684 WMSetColorAlpha(scr->dtext_color, 0xffff);
2687 wFreeColor(scr, color->pixel);
2689 return REFRESH_MENU_COLOR;
2692 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2694 XColor *color = tdata;
2696 if (scr->dtext_color)
2697 WMReleaseColor(scr->dtext_color);
2699 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2701 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2702 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2703 } else {
2704 WMSetColorAlpha(scr->dtext_color, 0xffff);
2707 wFreeColor(scr, color->pixel);
2709 return REFRESH_MENU_COLOR;
2712 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2714 XColor *color = tdata;
2716 if (scr->icon_title_color)
2717 WMReleaseColor(scr->icon_title_color);
2718 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2720 wFreeColor(scr, color->pixel);
2722 return REFRESH_ICON_TITLE_COLOR;
2725 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2727 XColor *color = tdata;
2729 if (scr->icon_title_texture) {
2730 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2732 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2734 return REFRESH_ICON_TITLE_BACK;
2737 static int setFrameBorderWidth(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2739 int *value = tdata;
2741 scr->frame_border_width = *value;
2743 return REFRESH_FRAME_BORDER;
2746 static int setFrameBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2748 XColor *color = tdata;
2750 if (scr->frame_border_color)
2751 WMReleaseColor(scr->frame_border_color);
2752 scr->frame_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2754 wFreeColor(scr, color->pixel);
2756 return REFRESH_FRAME_BORDER;
2759 static int setFrameSelectedBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2761 XColor *color = tdata;
2763 if (scr->frame_selected_border_color)
2764 WMReleaseColor(scr->frame_selected_border_color);
2765 scr->frame_selected_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2767 wFreeColor(scr, color->pixel);
2769 return REFRESH_FRAME_BORDER;
2772 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2774 close(scr->helper_fd);
2775 scr->helper_fd = 0;
2776 scr->helper_pid = 0;
2777 scr->flags.backimage_helper_launched = 0;
2780 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
2782 WMPropList *value = tdata;
2783 WMPropList *val;
2784 char *str;
2785 int i;
2787 if (scr->flags.backimage_helper_launched) {
2788 if (WMGetPropListItemCount(value) == 0) {
2789 SendHelperMessage(scr, 'C', 0, NULL);
2790 SendHelperMessage(scr, 'K', 0, NULL);
2792 WMReleasePropList(value);
2793 return 0;
2795 } else {
2796 pid_t pid;
2797 int filedes[2];
2799 if (WMGetPropListItemCount(value) == 0)
2800 return 0;
2802 if (pipe(filedes) < 0) {
2803 werror("pipe() failed:can't set workspace specific background image");
2805 WMReleasePropList(value);
2806 return 0;
2809 pid = fork();
2810 if (pid < 0) {
2811 werror("fork() failed:can't set workspace specific background image");
2812 if (close(filedes[0]) < 0)
2813 werror("could not close pipe");
2814 if (close(filedes[1]) < 0)
2815 werror("could not close pipe");
2817 } else if (pid == 0) {
2818 char *dither;
2820 SetupEnvironment(scr);
2822 if (close(0) < 0)
2823 werror("could not close pipe");
2824 if (dup(filedes[0]) < 0) {
2825 werror("dup() failed:can't set workspace specific background image");
2827 dither = wPreferences.no_dithering ? "-m" : "-d";
2828 if (wPreferences.smooth_workspace_back)
2829 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2830 else
2831 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2832 werror("could not execute wmsetbg");
2833 exit(1);
2834 } else {
2836 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2837 werror("error setting close-on-exec flag");
2839 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2840 werror("error setting close-on-exec flag");
2843 scr->helper_fd = filedes[1];
2844 scr->helper_pid = pid;
2845 scr->flags.backimage_helper_launched = 1;
2847 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2849 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2854 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2855 val = WMGetFromPLArray(value, i);
2856 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2857 str = WMGetPropListDescription(val, False);
2859 SendHelperMessage(scr, 'S', i + 1, str);
2861 wfree(str);
2862 } else {
2863 SendHelperMessage(scr, 'U', i + 1, NULL);
2866 sleep(1);
2868 WMReleasePropList(value);
2869 return 0;
2872 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
2874 WMPropList *value = tdata;
2876 if (scr->flags.backimage_helper_launched) {
2877 char *str;
2879 if (WMGetPropListItemCount(value) == 0) {
2880 SendHelperMessage(scr, 'U', 0, NULL);
2881 } else {
2882 /* set the default workspace background to this one */
2883 str = WMGetPropListDescription(value, False);
2884 if (str) {
2885 SendHelperMessage(scr, 'S', 0, str);
2886 wfree(str);
2887 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2888 } else {
2889 SendHelperMessage(scr, 'U', 0, NULL);
2892 } else if (WMGetPropListItemCount(value) > 0) {
2893 char *command;
2894 char *text;
2895 char *dither;
2896 int len;
2898 text = WMGetPropListDescription(value, False);
2899 len = strlen(text) + 40;
2900 command = wmalloc(len);
2901 dither = wPreferences.no_dithering ? "-m" : "-d";
2902 if (wPreferences.smooth_workspace_back)
2903 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2904 else
2905 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2906 wfree(text);
2907 ExecuteShellCommand(scr, command);
2908 wfree(command);
2910 WMReleasePropList(value);
2912 return 0;
2915 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2917 WTexture **texture = tdata;
2919 if (scr->widget_texture) {
2920 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2922 scr->widget_texture = *(WTexSolid **) texture;
2924 return 0;
2927 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2929 WTexture **texture = tdata;
2931 if (scr->window_title_texture[WS_FOCUSED]) {
2932 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2934 scr->window_title_texture[WS_FOCUSED] = *texture;
2936 return REFRESH_WINDOW_TEXTURES;
2939 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2941 WTexture **texture = tdata;
2943 if (scr->window_title_texture[WS_PFOCUSED]) {
2944 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2946 scr->window_title_texture[WS_PFOCUSED] = *texture;
2948 return REFRESH_WINDOW_TEXTURES;
2951 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2953 WTexture **texture = tdata;
2955 if (scr->window_title_texture[WS_UNFOCUSED]) {
2956 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2958 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2960 return REFRESH_WINDOW_TEXTURES;
2963 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2965 WTexture **texture = tdata;
2967 if (scr->resizebar_texture[0]) {
2968 wTextureDestroy(scr, scr->resizebar_texture[0]);
2970 scr->resizebar_texture[0] = *texture;
2972 return REFRESH_WINDOW_TEXTURES;
2975 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2977 WTexture **texture = tdata;
2979 if (scr->menu_title_texture[0]) {
2980 wTextureDestroy(scr, scr->menu_title_texture[0]);
2982 scr->menu_title_texture[0] = *texture;
2984 return REFRESH_MENU_TITLE_TEXTURE;
2987 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2989 WTexture **texture = tdata;
2991 if (scr->menu_item_texture) {
2992 wTextureDestroy(scr, scr->menu_item_texture);
2993 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2995 scr->menu_item_texture = *texture;
2997 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2999 return REFRESH_MENU_TEXTURE;
3002 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3004 WShortKey *shortcut = tdata;
3005 WWindow *wwin;
3006 long widx = (long) extra_data;
3008 wKeyBindings[widx] = *shortcut;
3010 wwin = scr->focused_window;
3012 while (wwin != NULL) {
3013 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3015 if (!WFLAGP(wwin, no_bind_keys)) {
3016 wWindowSetKeyGrabs(wwin);
3018 wwin = wwin->prev;
3021 /* do we need to update window menus? */
3022 if (widx >= WKBD_WORKSPACE1 && widx <= WKBD_WORKSPACE10)
3023 return REFRESH_WORKSPACE_MENU;
3024 if (widx == WKBD_LASTWORKSPACE)
3025 return REFRESH_WORKSPACE_MENU;
3026 if (widx >= WKBD_MOVE_WORKSPACE1 && widx <= WKBD_MOVE_WORKSPACE10)
3027 return REFRESH_WORKSPACE_MENU;
3029 return 0;
3032 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3034 wScreenUpdateUsableArea(scr);
3035 wArrangeIcons(scr, True);
3037 return 0;
3040 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3042 wScreenUpdateUsableArea(scr);
3044 return 0;
3047 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3049 return REFRESH_MENU_TEXTURE;
3052 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3054 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3056 RCopyArea(img, image, x, y, w, h, 0, 0);
3058 return img;
3061 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3063 WMPropList *array = tdata;
3064 char *path;
3065 RImage *bgimage;
3066 int cwidth, cheight;
3067 struct WPreferences *prefs = foo;
3069 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3070 if (prefs->swtileImage)
3071 RReleaseImage(prefs->swtileImage);
3072 prefs->swtileImage = NULL;
3074 WMReleasePropList(array);
3075 return 0;
3078 switch (WMGetPropListItemCount(array)) {
3079 case 4:
3080 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3081 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3082 break;
3083 } else
3084 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3086 if (!path) {
3087 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3088 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3089 } else {
3090 bgimage = RLoadImage(scr->rcontext, path, 0);
3091 if (!bgimage) {
3092 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3093 wfree(path);
3094 } else {
3095 wfree(path);
3097 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3098 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3100 if (cwidth <= 0 || cheight <= 0 ||
3101 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3102 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3103 else {
3104 int i;
3105 int swidth, theight;
3106 for (i = 0; i < 9; i++) {
3107 if (prefs->swbackImage[i])
3108 RReleaseImage(prefs->swbackImage[i]);
3109 prefs->swbackImage[i] = NULL;
3111 swidth = (bgimage->width - cwidth) / 2;
3112 theight = (bgimage->height - cheight) / 2;
3114 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3115 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3116 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3117 swidth, theight);
3119 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3120 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3121 cwidth, cheight);
3122 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3123 swidth, cheight);
3125 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3126 swidth, theight);
3127 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3128 cwidth, theight);
3129 prefs->swbackImage[8] =
3130 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3131 theight);
3133 // check if anything failed
3134 for (i = 0; i < 9; i++) {
3135 if (!prefs->swbackImage[i]) {
3136 for (; i >= 0; --i) {
3137 RReleaseImage(prefs->swbackImage[i]);
3138 prefs->swbackImage[i] = NULL;
3140 break;
3144 RReleaseImage(bgimage);
3148 case 1:
3149 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3150 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3151 break;
3152 } else
3153 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3155 if (!path) {
3156 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3157 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3158 } else {
3159 if (prefs->swtileImage)
3160 RReleaseImage(prefs->swtileImage);
3162 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3163 if (!prefs->swtileImage) {
3164 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3166 wfree(path);
3168 break;
3170 default:
3171 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3172 break;
3175 WMReleasePropList(array);
3177 return 0;
3180 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3182 WMPropList *array = tdata;
3183 int i;
3184 struct WPreferences *prefs = foo;
3186 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3187 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3188 WMReleasePropList(array);
3189 return 0;
3192 DestroyWindowMenu(scr);
3194 for (i = 0; i < 7; i++) {
3195 if (prefs->modifier_labels[i])
3196 wfree(prefs->modifier_labels[i]);
3198 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3199 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3200 } else {
3201 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3202 prefs->modifier_labels[i] = NULL;
3206 WMReleasePropList(array);
3208 return 0;
3211 static int setDoubleClick(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
3213 int *value = tdata;
3215 if (*value <= 0)
3216 *(int *)foo = 1;
3218 W_setconf_doubleClickDelay(*value);
3220 return 0;
3223 static int setCursor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3225 Cursor *cursor = tdata;
3226 long widx = (long) extra_data;
3228 if (wCursor[widx] != None) {
3229 XFreeCursor(dpy, wCursor[widx]);
3232 wCursor[widx] = *cursor;
3234 if (widx == WCUR_ROOT && *cursor != None) {
3235 XDefineCursor(dpy, scr->root_win, *cursor);
3238 return 0;