Variable workspace_menu moved to workspace object in global namespace
[wmaker-crm.git] / src / defaults.c
blob2db256fc3740822437ab9912a5539bee44591d3f
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 static WDECallbackConvert getCursor;
165 static WDECallbackUpdate setCursor;
168 * Tables to convert strings to enumeration values.
169 * Values stored are char
172 /* WARNING: sum of length of all value strings must not exceed
173 * this value */
174 #define TOTAL_VALUES_LENGTH 80
176 #define REFRESH_WINDOW_TEXTURES (1<<0)
177 #define REFRESH_MENU_TEXTURE (1<<1)
178 #define REFRESH_MENU_FONT (1<<2)
179 #define REFRESH_MENU_COLOR (1<<3)
180 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
181 #define REFRESH_MENU_TITLE_FONT (1<<5)
182 #define REFRESH_MENU_TITLE_COLOR (1<<6)
183 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
184 #define REFRESH_WINDOW_FONT (1<<8)
185 #define REFRESH_ICON_TILE (1<<9)
186 #define REFRESH_ICON_FONT (1<<10)
187 #define REFRESH_WORKSPACE_BACK (1<<11)
189 #define REFRESH_BUTTON_IMAGES (1<<12)
191 #define REFRESH_ICON_TITLE_COLOR (1<<13)
192 #define REFRESH_ICON_TITLE_BACK (1<<14)
194 #define REFRESH_WORKSPACE_MENU (1<<15)
196 #define REFRESH_FRAME_BORDER REFRESH_MENU_FONT|REFRESH_WINDOW_FONT
198 static WOptionEnumeration seFocusModes[] = {
199 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
200 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
201 {NULL, 0, 0}
204 static WOptionEnumeration seTitlebarModes[] = {
205 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
206 {"next", TS_NEXT, 0}, {NULL, 0, 0}
209 static WOptionEnumeration seColormapModes[] = {
210 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
211 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
212 {NULL, 0, 0}
215 static WOptionEnumeration sePlacements[] = {
216 {"Auto", WPM_AUTO, 0},
217 {"Smart", WPM_SMART, 0},
218 {"Cascade", WPM_CASCADE, 0},
219 {"Random", WPM_RANDOM, 0},
220 {"Manual", WPM_MANUAL, 0},
221 {"Center", WPM_CENTER, 0},
222 {NULL, 0, 0}
225 static WOptionEnumeration seGeomDisplays[] = {
226 {"None", WDIS_NONE, 0},
227 {"Center", WDIS_CENTER, 0},
228 {"Corner", WDIS_TOPLEFT, 0},
229 {"Floating", WDIS_FRAME_CENTER, 0},
230 {"Line", WDIS_NEW, 0},
231 {NULL, 0, 0}
234 static WOptionEnumeration seSpeeds[] = {
235 {"UltraFast", SPEED_ULTRAFAST, 0},
236 {"Fast", SPEED_FAST, 0},
237 {"Medium", SPEED_MEDIUM, 0},
238 {"Slow", SPEED_SLOW, 0},
239 {"UltraSlow", SPEED_ULTRASLOW, 0},
240 {NULL, 0, 0}
243 static WOptionEnumeration seMouseButtonActions[] = {
244 {"None", WA_NONE, 0},
245 {"SelectWindows", WA_SELECT_WINDOWS, 0},
246 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
247 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
248 {NULL, 0, 0}
251 static WOptionEnumeration seMouseWheelActions[] = {
252 {"None", WA_NONE, 0},
253 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
254 {NULL, 0, 0}
257 static WOptionEnumeration seIconificationStyles[] = {
258 {"Zoom", WIS_ZOOM, 0},
259 {"Twist", WIS_TWIST, 0},
260 {"Flip", WIS_FLIP, 0},
261 {"None", WIS_NONE, 0},
262 {"random", WIS_RANDOM, 0},
263 {NULL, 0, 0}
266 static WOptionEnumeration seJustifications[] = {
267 {"Left", WTJ_LEFT, 0},
268 {"Center", WTJ_CENTER, 0},
269 {"Right", WTJ_RIGHT, 0},
270 {NULL, 0, 0}
273 static WOptionEnumeration seIconPositions[] = {
274 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
275 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
276 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
277 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
278 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
279 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
280 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
281 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
282 {NULL, 0, 0}
285 static WOptionEnumeration seMenuStyles[] = {
286 {"normal", MS_NORMAL, 0},
287 {"singletexture", MS_SINGLE_TEXTURE, 0},
288 {"flat", MS_FLAT, 0},
289 {NULL, 0, 0}
292 static WOptionEnumeration seDisplayPositions[] = {
293 {"none", WD_NONE, 0},
294 {"center", WD_CENTER, 0},
295 {"top", WD_TOP, 0},
296 {"bottom", WD_BOTTOM, 0},
297 {"topleft", WD_TOPLEFT, 0},
298 {"topright", WD_TOPRIGHT, 0},
299 {"bottomleft", WD_BOTTOMLEFT, 0},
300 {"bottomright", WD_BOTTOMRIGHT, 0},
301 {NULL, 0, 0}
304 static WOptionEnumeration seWorkspaceBorder[] = {
305 {"None", WB_NONE, 0},
306 {"LeftRight", WB_LEFTRIGHT, 0},
307 {"TopBottom", WB_TOPBOTTOM, 0},
308 {"AllDirections", WB_ALLDIRS, 0},
309 {NULL, 0, 0}
313 * ALL entries in the tables bellow, NEED to have a default value
314 * defined, and this value needs to be correct.
317 /* these options will only affect the window manager on startup
319 * static defaults can't access the screen data, because it is
320 * created after these defaults are read
322 WDefaultEntry staticOptionList[] = {
324 {"ColormapSize", "4", NULL,
325 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
326 {"DisableDithering", "NO", NULL,
327 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
328 {"IconSize", "64", NULL,
329 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
330 {"ModifierKey", "Mod1", NULL,
331 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
332 {"DisableWSMouseActions", "NO", NULL,
333 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
334 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
335 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
336 {"NewStyle", "new", seTitlebarModes,
337 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
338 {"DisableDock", "NO", (void *)WM_DOCK,
339 NULL, getBool, setIfDockPresent, NULL, NULL},
340 {"DisableClip", "NO", (void *)WM_CLIP,
341 NULL, getBool, setIfDockPresent, NULL, NULL},
342 {"DisableDrawers", "NO", (void *)WM_DRAWER,
343 NULL, getBool, setIfDockPresent, NULL, NULL},
344 {"ClipMergedInDock", "NO", NULL,
345 NULL, getBool, setClipMergedInDock, NULL, NULL},
346 {"DisableMiniwindows", "NO", NULL,
347 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
350 #define NUM2STRING_(x) #x
351 #define NUM2STRING(x) NUM2STRING_(x)
353 WDefaultEntry optionList[] = {
355 /* dynamic options */
357 {"IconPosition", "blh", seIconPositions,
358 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
359 {"IconificationStyle", "Zoom", seIconificationStyles,
360 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
361 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
362 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
363 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
364 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
365 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
366 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
367 {"MouseWheelAction", "None", seMouseWheelActions,
368 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
369 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
370 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
371 {"IconPath", DEF_ICON_PATHS, NULL,
372 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
373 {"ColormapMode", "auto", seColormapModes,
374 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
375 {"AutoFocus", "NO", NULL,
376 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
377 {"RaiseDelay", "0", NULL,
378 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
379 {"CirculateRaise", "NO", NULL,
380 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
381 {"Superfluous", "NO", NULL,
382 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
383 {"AdvanceToNewWorkspace", "NO", NULL,
384 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
385 {"CycleWorkspaces", "NO", NULL,
386 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
387 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
388 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
389 {"WorkspaceBorder", "None", seWorkspaceBorder,
390 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
391 {"WorkspaceBorderSize", "0", NULL,
392 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
393 {"StickyIcons", "NO", NULL,
394 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
395 {"SaveSessionOnExit", "NO", NULL,
396 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
397 {"WrapMenus", "NO", NULL,
398 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
399 {"ScrollableMenus", "NO", NULL,
400 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
401 {"MenuScrollSpeed", "medium", seSpeeds,
402 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
403 {"IconSlideSpeed", "medium", seSpeeds,
404 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
405 {"ShadeSpeed", "medium", seSpeeds,
406 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
407 {"BounceAppIconsWhenUrgent", "YES", NULL,
408 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
409 {"RaiseAppIconsWhenBouncing", "NO", NULL,
410 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
411 {"DoNotMakeAppIconsBounce", "NO", NULL,
412 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
413 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
414 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
415 {"ClipAutoraiseDelay", "600", NULL,
416 &wPreferences.clip_auto_raise_delay, getInt, NULL, NULL, NULL},
417 {"ClipAutolowerDelay", "1000", NULL,
418 &wPreferences.clip_auto_lower_delay, getInt, NULL, NULL, NULL},
419 {"ClipAutoexpandDelay", "600", NULL,
420 &wPreferences.clip_auto_expand_delay, getInt, NULL, NULL, NULL},
421 {"ClipAutocollapseDelay", "1000", NULL,
422 &wPreferences.clip_auto_collapse_delay, getInt, NULL, NULL, NULL},
423 {"WrapAppiconsInDock", "YES", NULL,
424 NULL, getBool, setWrapAppiconsInDock, NULL, NULL},
425 {"AlignSubmenus", "NO", NULL,
426 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
427 {"ViKeyMenus", "NO", NULL,
428 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
429 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
430 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
431 {"WindowPlacement", "auto", sePlacements,
432 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
433 {"IgnoreFocusClick", "NO", NULL,
434 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
435 {"UseSaveUnders", "NO", NULL,
436 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
437 {"OpaqueMove", "NO", NULL,
438 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
439 {"OpaqueResize", "NO", NULL,
440 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
441 {"OpaqueMoveResizeKeyboard", "NO", NULL,
442 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
443 {"DisableAnimations", "NO", NULL,
444 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
445 {"DontLinkWorkspaces", "NO", NULL,
446 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
447 {"HighlightActiveApp", "YES", NULL,
448 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
449 {"AutoArrangeIcons", "NO", NULL,
450 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
451 {"NoWindowOverDock", "NO", NULL,
452 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
453 {"NoWindowOverIcons", "NO", NULL,
454 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
455 {"WindowPlaceOrigin", "(0, 0)", NULL,
456 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
457 {"ResizeDisplay", "corner", seGeomDisplays,
458 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
459 {"MoveDisplay", "corner", seGeomDisplays,
460 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
461 {"DontConfirmKill", "NO", NULL,
462 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
463 {"WindowTitleBalloons", "NO", NULL,
464 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
465 {"MiniwindowTitleBalloons", "NO", NULL,
466 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
467 {"AppIconBalloons", "NO", NULL,
468 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
469 {"HelpBalloons", "NO", NULL,
470 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
471 {"EdgeResistance", "30", NULL,
472 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
473 {"ResizeIncrement", "0", NULL,
474 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
475 {"Attraction", "NO", NULL,
476 &wPreferences.attract, getBool, NULL, NULL, NULL},
477 {"DisableBlinking", "NO", NULL,
478 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
479 {"SingleClickLaunch", "NO", NULL,
480 &wPreferences.single_click, getBool, NULL, NULL, NULL},
481 {"StrictWindozeCycle", "YES", NULL,
482 &wPreferences.strict_windoze_cycle, getBool, NULL, NULL, NULL},
483 {"SwitchPanelOnlyOpen", "NO", NULL,
484 &wPreferences.panel_only_open, getBool, NULL, NULL, NULL},
486 /* style options */
488 {"MenuStyle", "normal", seMenuStyles,
489 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
490 {"WidgetColor", "(solid, gray)", NULL,
491 NULL, getTexture, setWidgetColor, NULL, NULL},
492 {"WorkspaceSpecificBack", "()", NULL,
493 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
494 /* WorkspaceBack must come after WorkspaceSpecificBack or
495 * WorkspaceBack wont know WorkspaceSpecificBack was also
496 * specified and 2 copies of wmsetbg will be launched */
497 {"WorkspaceBack", "(solid, black)", NULL,
498 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
499 {"SmoothWorkspaceBack", "NO", NULL,
500 NULL, getBool, NULL, NULL, NULL},
501 {"IconBack", "(solid, gray)", NULL,
502 NULL, getTexture, setIconTile, NULL, NULL},
503 {"TitleJustify", "center", seJustifications,
504 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
505 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
506 NULL, getFont, setWinTitleFont, NULL, NULL},
507 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
508 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
509 {"WindowTitleMinHeight", "0", NULL,
510 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
511 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
512 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
513 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
514 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
515 {"MenuTitleMinHeight", "0", NULL,
516 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
517 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
518 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
519 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
520 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
521 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
522 NULL, getFont, setMenuTitleFont, NULL, NULL},
523 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
524 NULL, getFont, setMenuTextFont, NULL, NULL},
525 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
526 NULL, getFont, setIconTitleFont, NULL, NULL},
527 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
528 NULL, getFont, setClipTitleFont, NULL, NULL},
529 {"ShowClipTitle", "YES", NULL,
530 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
531 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
532 NULL, getFont, setLargeDisplayFont, NULL, NULL},
533 {"HighlightColor", "white", NULL,
534 NULL, getColor, setHightlight, NULL, NULL},
535 {"HighlightTextColor", "black", NULL,
536 NULL, getColor, setHightlightText, NULL, NULL},
537 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
538 NULL, getColor, setClipTitleColor, NULL, NULL},
539 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
540 NULL, getColor, setClipTitleColor, NULL, NULL},
541 {"FTitleColor", "white", (void *)WS_FOCUSED,
542 NULL, getColor, setWTitleColor, NULL, NULL},
543 {"PTitleColor", "white", (void *)WS_PFOCUSED,
544 NULL, getColor, setWTitleColor, NULL, NULL},
545 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
546 NULL, getColor, setWTitleColor, NULL, NULL},
547 {"FTitleBack", "(solid, black)", NULL,
548 NULL, getTexture, setFTitleBack, NULL, NULL},
549 {"PTitleBack", "(solid, \"#616161\")", NULL,
550 NULL, getTexture, setPTitleBack, NULL, NULL},
551 {"UTitleBack", "(solid, gray)", NULL,
552 NULL, getTexture, setUTitleBack, NULL, NULL},
553 {"ResizebarBack", "(solid, gray)", NULL,
554 NULL, getTexture, setResizebarBack, NULL, NULL},
555 {"MenuTitleColor", "white", NULL,
556 NULL, getColor, setMenuTitleColor, NULL, NULL},
557 {"MenuTextColor", "black", NULL,
558 NULL, getColor, setMenuTextColor, NULL, NULL},
559 {"MenuDisabledColor", "\"#616161\"", NULL,
560 NULL, getColor, setMenuDisabledColor, NULL, NULL},
561 {"MenuTitleBack", "(solid, black)", NULL,
562 NULL, getTexture, setMenuTitleBack, NULL, NULL},
563 {"MenuTextBack", "(solid, gray)", NULL,
564 NULL, getTexture, setMenuTextBack, NULL, NULL},
565 {"IconTitleColor", "white", NULL,
566 NULL, getColor, setIconTitleColor, NULL, NULL},
567 {"IconTitleBack", "black", NULL,
568 NULL, getColor, setIconTitleBack, NULL, NULL},
569 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
570 NULL, getPropList, setSwPOptions, NULL, NULL},
571 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
572 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
573 {"FrameBorderWidth", "1", NULL,
574 NULL, getInt, setFrameBorderWidth, NULL, NULL},
575 {"FrameBorderColor", "black", NULL,
576 NULL, getColor, setFrameBorderColor, NULL, NULL},
577 {"FrameSelectedBorderColor", "white", NULL,
578 NULL, getColor, setFrameSelectedBorderColor, NULL, NULL},
580 /* keybindings */
582 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
583 NULL, getKeybind, setKeyGrab, NULL, NULL},
584 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
585 NULL, getKeybind, setKeyGrab, NULL, NULL},
586 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
587 NULL, getKeybind, setKeyGrab, NULL, NULL},
588 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
589 NULL, getKeybind, setKeyGrab, NULL, NULL},
590 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
591 NULL, getKeybind, setKeyGrab, NULL, NULL},
592 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
593 NULL, getKeybind, setKeyGrab, NULL, NULL},
594 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
595 NULL, getKeybind, setKeyGrab, NULL, NULL },
596 {"HideKey", "None", (void *)WKBD_HIDE,
597 NULL, getKeybind, setKeyGrab, NULL, NULL},
598 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
599 NULL, getKeybind, setKeyGrab, NULL, NULL},
600 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
601 NULL, getKeybind, setKeyGrab, NULL, NULL},
602 {"CloseKey", "None", (void *)WKBD_CLOSE,
603 NULL, getKeybind, setKeyGrab, NULL, NULL},
604 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
605 NULL, getKeybind, setKeyGrab, NULL, NULL},
606 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
607 NULL, getKeybind, setKeyGrab, NULL, NULL},
608 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
609 NULL, getKeybind, setKeyGrab, NULL, NULL},
610 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
611 NULL, getKeybind, setKeyGrab, NULL, NULL},
612 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
613 NULL, getKeybind, setKeyGrab, NULL, NULL},
614 {"THMaximizeKey", "None", (void*)WKBD_THMAXIMIZE,
615 NULL, getKeybind, setKeyGrab, NULL, NULL},
616 {"BHMaximizeKey", "None", (void*)WKBD_BHMAXIMIZE,
617 NULL, getKeybind, setKeyGrab, NULL, NULL},
618 {"LTCMaximizeKey", "None", (void*)WKBD_LTCMAXIMIZE,
619 NULL, getKeybind, setKeyGrab, NULL, NULL},
620 {"RTCMaximizeKey", "None", (void*)WKBD_RTCMAXIMIZE,
621 NULL, getKeybind, setKeyGrab, NULL, NULL},
622 {"LBCMaximizeKey", "None", (void*)WKBD_LBCMAXIMIZE,
623 NULL, getKeybind, setKeyGrab, NULL, NULL},
624 {"RBCMaximizeKey", "None", (void*)WKBD_RBCMAXIMIZE,
625 NULL, getKeybind, setKeyGrab, NULL, NULL},
626 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
627 NULL, getKeybind, setKeyGrab, NULL, NULL},
628 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
629 NULL, getKeybind, setKeyGrab, NULL, NULL},
630 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
631 NULL, getKeybind, setKeyGrab, NULL, NULL},
632 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
633 NULL, getKeybind, setKeyGrab, NULL, NULL},
634 {"ShadeKey", "None", (void *)WKBD_SHADE,
635 NULL, getKeybind, setKeyGrab, NULL, NULL},
636 {"SelectKey", "None", (void *)WKBD_SELECT,
637 NULL, getKeybind, setKeyGrab, NULL, NULL},
638 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
639 NULL, getKeybind, setKeyGrab, NULL, NULL},
640 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
641 NULL, getKeybind, setKeyGrab, NULL, NULL},
642 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
643 NULL, getKeybind, setKeyGrab, NULL, NULL},
644 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
645 NULL, getKeybind, setKeyGrab, NULL, NULL},
646 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
647 NULL, getKeybind, setKeyGrab, NULL, NULL},
648 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
649 NULL, getKeybind, setKeyGrab, NULL, NULL},
650 {"LastWorkspaceKey", "None", (void *)WKBD_LASTWORKSPACE,
651 NULL, getKeybind, setKeyGrab, NULL, NULL},
652 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
653 NULL, getKeybind, setKeyGrab, NULL, NULL},
654 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
655 NULL, getKeybind, setKeyGrab, NULL, NULL},
656 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
657 NULL, getKeybind, setKeyGrab, NULL, NULL},
658 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
659 NULL, getKeybind, setKeyGrab, NULL, NULL},
660 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
661 NULL, getKeybind, setKeyGrab, NULL, NULL},
662 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
663 NULL, getKeybind, setKeyGrab, NULL, NULL},
664 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
665 NULL, getKeybind, setKeyGrab, NULL, NULL},
666 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
667 NULL, getKeybind, setKeyGrab, NULL, NULL},
668 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
669 NULL, getKeybind, setKeyGrab, NULL, NULL},
670 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
671 NULL, getKeybind, setKeyGrab, NULL, NULL},
672 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
673 NULL, getKeybind, setKeyGrab, NULL, NULL},
674 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
675 NULL, getKeybind, setKeyGrab, NULL, NULL},
676 {"MoveToWorkspace1Key", "None", (void *)WKBD_MOVE_WORKSPACE1,
677 NULL, getKeybind, setKeyGrab, NULL, NULL},
678 {"MoveToWorkspace2Key", "None", (void *)WKBD_MOVE_WORKSPACE2,
679 NULL, getKeybind, setKeyGrab, NULL, NULL},
680 {"MoveToWorkspace3Key", "None", (void *)WKBD_MOVE_WORKSPACE3,
681 NULL, getKeybind, setKeyGrab, NULL, NULL},
682 {"MoveToWorkspace4Key", "None", (void *)WKBD_MOVE_WORKSPACE4,
683 NULL, getKeybind, setKeyGrab, NULL, NULL},
684 {"MoveToWorkspace5Key", "None", (void *)WKBD_MOVE_WORKSPACE5,
685 NULL, getKeybind, setKeyGrab, NULL, NULL},
686 {"MoveToWorkspace6Key", "None", (void *)WKBD_MOVE_WORKSPACE6,
687 NULL, getKeybind, setKeyGrab, NULL, NULL},
688 {"MoveToWorkspace7Key", "None", (void *)WKBD_MOVE_WORKSPACE7,
689 NULL, getKeybind, setKeyGrab, NULL, NULL},
690 {"MoveToWorkspace8Key", "None", (void *)WKBD_MOVE_WORKSPACE8,
691 NULL, getKeybind, setKeyGrab, NULL, NULL},
692 {"MoveToWorkspace9Key", "None", (void *)WKBD_MOVE_WORKSPACE9,
693 NULL, getKeybind, setKeyGrab, NULL, NULL},
694 {"MoveToWorkspace10Key", "None", (void *)WKBD_MOVE_WORKSPACE10,
695 NULL, getKeybind, setKeyGrab, NULL, NULL},
696 {"MoveToNextWorkspaceKey", "None", (void *)WKBD_MOVE_NEXTWORKSPACE,
697 NULL, getKeybind, setKeyGrab, NULL, NULL},
698 {"MoveToPrevWorkspaceKey", "None", (void *)WKBD_MOVE_PREVWORKSPACE,
699 NULL, getKeybind, setKeyGrab, NULL, NULL},
700 {"MoveToLastWorkspaceKey", "None", (void *)WKBD_MOVE_LASTWORKSPACE,
701 NULL, getKeybind, setKeyGrab, NULL, NULL},
702 {"MoveToNextWorkspaceLayerKey", "None", (void *)WKBD_MOVE_NEXTWSLAYER,
703 NULL, getKeybind, setKeyGrab, NULL, NULL},
704 {"MoveToPrevWorkspaceLayerKey", "None", (void *)WKBD_MOVE_PREVWSLAYER,
705 NULL, getKeybind, setKeyGrab, NULL, NULL},
706 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
707 NULL, getKeybind, setKeyGrab, NULL, NULL},
708 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
709 NULL, getKeybind, setKeyGrab, NULL, NULL},
710 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
711 NULL, getKeybind, setKeyGrab, NULL, NULL},
712 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
713 NULL, getKeybind, setKeyGrab, NULL, NULL},
714 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
715 NULL, getKeybind, setKeyGrab, NULL, NULL},
716 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
717 NULL, getKeybind, setKeyGrab, NULL, NULL},
718 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
719 NULL, getKeybind, setKeyGrab, NULL, NULL},
720 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
721 NULL, getKeybind, setKeyGrab, NULL, NULL},
722 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
723 NULL, getKeybind, setKeyGrab, NULL, NULL},
724 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
725 NULL, getKeybind, setKeyGrab, NULL, NULL},
726 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
727 NULL, getKeybind, setKeyGrab, NULL, NULL},
728 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
729 NULL, getKeybind, setKeyGrab, NULL, NULL},
731 #ifdef KEEP_XKB_LOCK_STATUS
732 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
733 NULL, getKeybind, setKeyGrab, NULL, NULL},
734 {"KbdModeLock", "NO", NULL,
735 &wPreferences.modelock, getBool, NULL, NULL, NULL},
736 #endif /* KEEP_XKB_LOCK_STATUS */
738 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
739 NULL, getCursor, setCursor, NULL, NULL},
740 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
741 NULL, getCursor, setCursor, NULL, NULL},
742 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
743 NULL, getCursor, setCursor, NULL, NULL},
744 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
745 NULL, getCursor, setCursor, NULL, NULL},
746 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
747 NULL, getCursor, setCursor, NULL, NULL},
748 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
749 NULL, getCursor, setCursor, NULL, NULL},
750 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
751 NULL, getCursor, setCursor, NULL, NULL},
752 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
753 NULL, getCursor, setCursor, NULL, NULL},
754 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
755 NULL, getCursor, setCursor, NULL, NULL},
756 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
757 NULL, getCursor, setCursor, NULL, NULL},
758 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
759 NULL, getCursor, setCursor, NULL, NULL},
760 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
761 NULL, getCursor, setCursor, NULL, NULL},
762 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
763 NULL, getCursor, setCursor, NULL, NULL},
764 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
765 NULL, getCursor, setCursor, NULL, NULL},
766 {"DialogHistoryLines", "500", NULL,
767 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
768 {"CycleActiveHeadOnly", "NO", NULL,
769 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL},
770 {"CycleIgnoreMinimized", "NO", NULL,
771 &wPreferences.cycle_ignore_minimized, getBool, NULL, NULL, NULL}
774 static void initDefaults(void)
776 unsigned int i;
777 WDefaultEntry *entry;
779 WMPLSetCaseSensitive(False);
781 for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) {
782 entry = &optionList[i];
784 entry->plkey = WMCreatePLString(entry->key);
785 if (entry->default_value)
786 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
787 else
788 entry->plvalue = NULL;
791 for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) {
792 entry = &staticOptionList[i];
794 entry->plkey = WMCreatePLString(entry->key);
795 if (entry->default_value)
796 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
797 else
798 entry->plvalue = NULL;
802 static WMPropList *readGlobalDomain(const char *domainName, Bool requireDictionary)
804 WMPropList *globalDict = NULL;
805 char path[PATH_MAX];
806 struct stat stbuf;
808 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
809 if (stat(path, &stbuf) >= 0) {
810 globalDict = WMReadPropListFromFile(path);
811 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
812 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
813 WMReleasePropList(globalDict);
814 globalDict = NULL;
815 } else if (!globalDict) {
816 wwarning(_("could not load domain %s from global defaults database"), domainName);
820 return globalDict;
823 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
824 static void prependMenu(WMPropList * destarr, WMPropList * array)
826 WMPropList *item;
827 int i;
829 for (i = 0; i < WMGetPropListItemCount(array); i++) {
830 item = WMGetFromPLArray(array, i);
831 if (item)
832 WMInsertInPLArray(destarr, i + 1, item);
836 static void appendMenu(WMPropList * destarr, WMPropList * array)
838 WMPropList *item;
839 int i;
841 for (i = 0; i < WMGetPropListItemCount(array); i++) {
842 item = WMGetFromPLArray(array, i);
843 if (item)
844 WMAddToPLArray(destarr, item);
847 #endif
849 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
851 WMPropList *menu = menuDomain->dictionary;
852 WMPropList *submenu;
854 if (!menu || !WMIsPLArray(menu))
855 return;
857 #ifdef GLOBAL_PREAMBLE_MENU_FILE
858 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
860 if (submenu && !WMIsPLArray(submenu)) {
861 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
862 WMReleasePropList(submenu);
863 submenu = NULL;
865 if (submenu) {
866 prependMenu(menu, submenu);
867 WMReleasePropList(submenu);
869 #endif
871 #ifdef GLOBAL_EPILOGUE_MENU_FILE
872 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
874 if (submenu && !WMIsPLArray(submenu)) {
875 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
876 WMReleasePropList(submenu);
877 submenu = NULL;
879 if (submenu) {
880 appendMenu(menu, submenu);
881 WMReleasePropList(submenu);
883 #endif
885 menuDomain->dictionary = menu;
888 WDDomain *wDefaultsInitDomain(const char *domain, Bool requireDictionary)
890 WDDomain *db;
891 struct stat stbuf;
892 static int inited = 0;
893 const char *the_path;
894 WMPropList *shared_dict = NULL;
896 if (!inited) {
897 inited = 1;
898 initDefaults();
901 db = wmalloc(sizeof(WDDomain));
902 db->domain_name = domain;
903 db->path = wdefaultspathfordomain(domain);
904 the_path = db->path;
906 if (the_path && stat(the_path, &stbuf) >= 0) {
907 db->dictionary = WMReadPropListFromFile(the_path);
908 if (db->dictionary) {
909 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
910 WMReleasePropList(db->dictionary);
911 db->dictionary = NULL;
912 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
914 db->timestamp = stbuf.st_mtime;
915 } else {
916 wwarning(_("could not load domain %s from user defaults database"), domain);
920 /* global system dictionary */
921 shared_dict = readGlobalDomain(domain, requireDictionary);
923 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
924 WMIsPLDictionary(db->dictionary)) {
925 WMMergePLDictionaries(shared_dict, db->dictionary, True);
926 WMReleasePropList(db->dictionary);
927 db->dictionary = shared_dict;
928 if (stbuf.st_mtime > db->timestamp)
929 db->timestamp = stbuf.st_mtime;
930 } else if (!db->dictionary) {
931 db->dictionary = shared_dict;
932 if (stbuf.st_mtime > db->timestamp)
933 db->timestamp = stbuf.st_mtime;
936 return db;
939 void wReadStaticDefaults(WMPropList * dict)
941 WMPropList *plvalue;
942 WDefaultEntry *entry;
943 unsigned int i;
944 void *tdata;
946 for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) {
947 entry = &staticOptionList[i];
949 if (dict)
950 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
951 else
952 plvalue = NULL;
954 /* no default in the DB. Use builtin default */
955 if (!plvalue)
956 plvalue = entry->plvalue;
958 if (plvalue) {
959 /* convert data */
960 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
961 if (entry->update)
962 (*entry->update) (NULL, entry, tdata, entry->extra_data);
967 void wDefaultsCheckDomains(void* arg)
969 WScreen *scr;
970 struct stat stbuf;
971 WMPropList *shared_dict = NULL;
972 WMPropList *dict;
973 int i;
975 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
976 WDWindowMaker->timestamp = stbuf.st_mtime;
978 /* Global dictionary */
979 shared_dict = readGlobalDomain("WindowMaker", True);
981 /* User dictionary */
982 dict = WMReadPropListFromFile(WDWindowMaker->path);
984 if (dict) {
985 if (!WMIsPLDictionary(dict)) {
986 WMReleasePropList(dict);
987 dict = NULL;
988 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
989 "WindowMaker", WDWindowMaker->path);
990 } else {
991 if (shared_dict) {
992 WMMergePLDictionaries(shared_dict, dict, True);
993 WMReleasePropList(dict);
994 dict = shared_dict;
995 shared_dict = NULL;
998 for (i = 0; i < wScreenCount; i++) {
999 scr = wScreenWithNumber(i);
1000 if (scr)
1001 wReadDefaults(scr, dict);
1004 if (WDWindowMaker->dictionary)
1005 WMReleasePropList(WDWindowMaker->dictionary);
1007 WDWindowMaker->dictionary = dict;
1009 } else {
1010 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1013 if (shared_dict)
1014 WMReleasePropList(shared_dict);
1018 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1019 /* global dictionary */
1020 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1021 /* user dictionary */
1022 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1023 if (dict) {
1024 if (!WMIsPLDictionary(dict)) {
1025 WMReleasePropList(dict);
1026 dict = NULL;
1027 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1028 "WMWindowAttributes", WDWindowAttributes->path);
1029 } else {
1030 if (shared_dict) {
1031 WMMergePLDictionaries(shared_dict, dict, True);
1032 WMReleasePropList(dict);
1033 dict = shared_dict;
1034 shared_dict = NULL;
1037 if (WDWindowAttributes->dictionary)
1038 WMReleasePropList(WDWindowAttributes->dictionary);
1040 WDWindowAttributes->dictionary = dict;
1041 for (i = 0; i < wScreenCount; i++) {
1042 scr = wScreenWithNumber(i);
1043 if (scr) {
1044 wDefaultUpdateIcons(scr);
1046 /* Update the panel image if changed */
1047 /* Don't worry. If the image is the same these
1048 * functions will have no performance impact. */
1049 create_logo_image(scr);
1053 } else {
1054 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1057 WDWindowAttributes->timestamp = stbuf.st_mtime;
1058 if (shared_dict)
1059 WMReleasePropList(shared_dict);
1062 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1063 dict = WMReadPropListFromFile(WDRootMenu->path);
1064 if (dict) {
1065 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1066 WMReleasePropList(dict);
1067 dict = NULL;
1068 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1069 "WMRootMenu", WDRootMenu->path);
1070 } else {
1071 if (WDRootMenu->dictionary)
1072 WMReleasePropList(WDRootMenu->dictionary);
1074 WDRootMenu->dictionary = dict;
1075 wDefaultsMergeGlobalMenus(WDRootMenu);
1077 } else {
1078 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1080 WDRootMenu->timestamp = stbuf.st_mtime;
1082 #ifndef HAVE_INOTIFY
1083 if (!arg)
1084 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1085 #endif
1088 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1090 WMPropList *plvalue, *old_value;
1091 WDefaultEntry *entry;
1092 unsigned int i;
1093 int update_workspace_back = 0; /* kluge :/ */
1094 unsigned int needs_refresh;
1095 void *tdata;
1096 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1098 needs_refresh = 0;
1100 for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) {
1101 entry = &optionList[i];
1103 if (new_dict)
1104 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1105 else
1106 plvalue = NULL;
1108 if (!old_dict)
1109 old_value = NULL;
1110 else
1111 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1113 if (!plvalue && !old_value) {
1114 /* no default in the DB. Use builtin default */
1115 plvalue = entry->plvalue;
1116 if (plvalue && new_dict)
1117 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1119 } else if (!plvalue) {
1120 /* value was deleted from DB. Keep current value */
1121 continue;
1122 } else if (!old_value) {
1123 /* set value for the 1st time */
1124 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1125 /* value has changed */
1126 } else {
1127 if (strcmp(entry->key, "WorkspaceBack") == 0
1128 && update_workspace_back && scr->flags.backimage_helper_launched) {
1129 } else {
1130 /* value was not changed since last time */
1131 continue;
1135 if (plvalue) {
1136 /* convert data */
1137 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1139 * If the WorkspaceSpecificBack data has been changed
1140 * so that the helper will be launched now, we must be
1141 * sure to send the default background texture config
1142 * to the helper.
1144 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1145 !scr->flags.backimage_helper_launched)
1146 update_workspace_back = 1;
1148 if (entry->update)
1149 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1155 if (needs_refresh != 0 && !scr->flags.startup) {
1156 int foo;
1158 foo = 0;
1159 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1160 foo |= WTextureSettings;
1161 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1162 foo |= WFontSettings;
1163 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1164 foo |= WColorSettings;
1165 if (foo)
1166 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1167 (void *)(uintptr_t) foo);
1169 foo = 0;
1170 if (needs_refresh & REFRESH_MENU_TEXTURE)
1171 foo |= WTextureSettings;
1172 if (needs_refresh & REFRESH_MENU_FONT)
1173 foo |= WFontSettings;
1174 if (needs_refresh & REFRESH_MENU_COLOR)
1175 foo |= WColorSettings;
1176 if (foo)
1177 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1179 foo = 0;
1180 if (needs_refresh & REFRESH_WINDOW_FONT)
1181 foo |= WFontSettings;
1182 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1183 foo |= WTextureSettings;
1184 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1185 foo |= WColorSettings;
1186 if (foo)
1187 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1189 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1190 foo = 0;
1191 if (needs_refresh & REFRESH_ICON_FONT)
1192 foo |= WFontSettings;
1193 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1194 foo |= WTextureSettings;
1195 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1196 foo |= WTextureSettings;
1197 if (foo)
1198 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1199 (void *)(uintptr_t) foo);
1201 if (needs_refresh & REFRESH_ICON_TILE)
1202 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1204 if (needs_refresh & REFRESH_WORKSPACE_MENU) {
1205 if (w_global.workspace.menu)
1206 wWorkspaceMenuUpdate(scr, w_global.workspace.menu);
1207 if (scr->clip_ws_menu)
1208 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
1209 if (scr->workspace_submenu)
1210 scr->workspace_submenu->flags.realized = 0;
1211 if (scr->clip_submenu)
1212 scr->clip_submenu->flags.realized = 0;
1217 void wDefaultUpdateIcons(WScreen *scr)
1219 WAppIcon *aicon = scr->app_icon_list;
1220 WDrawerChain *dc;
1221 WWindow *wwin = scr->focused_window;
1223 while (aicon) {
1224 /* Get the application icon, default included */
1225 wIconChangeImageFile(aicon->icon, NULL);
1226 wAppIconPaint(aicon);
1227 aicon = aicon->next;
1230 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock)
1231 wClipIconPaint(scr->clip_icon);
1233 for (dc = scr->drawers; dc != NULL; dc = dc->next)
1234 wDrawerIconPaint(dc->adrawer->icon_array[0]);
1236 while (wwin) {
1237 if (wwin->icon && wwin->flags.miniaturized)
1238 wIconChangeImageFile(wwin->icon, NULL);
1239 wwin = wwin->prev;
1243 /* --------------------------- Local ----------------------- */
1245 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1246 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1247 entry->key, x); \
1248 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1249 var = entry->default_value;\
1250 } else var = WMGetFromPLString(value)\
1253 static int string2index(WMPropList *key, WMPropList *val, const char *def, WOptionEnumeration * values)
1255 char *str;
1256 WOptionEnumeration *v;
1257 char buffer[TOTAL_VALUES_LENGTH];
1259 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1260 for (v = values; v->string != NULL; v++) {
1261 if (strcasecmp(v->string, str) == 0)
1262 return v->value;
1266 buffer[0] = 0;
1267 for (v = values; v->string != NULL; v++) {
1268 if (!v->is_alias) {
1269 if (buffer[0] != 0)
1270 strcat(buffer, ", ");
1271 snprintf(buffer+strlen(buffer),
1272 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1275 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1276 WMGetFromPLString(key),
1277 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1278 buffer);
1280 if (def) {
1281 return string2index(key, val, NULL, values);
1284 return -1;
1288 * value - is the value in the defaults DB
1289 * addr - is the address to store the data
1290 * ret - is the address to store a pointer to a temporary buffer. ret
1291 * must not be freed and is used by the set functions
1293 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1295 static char data;
1296 const char *val;
1297 int second_pass = 0;
1299 GET_STRING_OR_DEFAULT("Boolean", val);
1301 again:
1302 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1303 || strcasecmp(val, "YES") == 0) {
1305 data = 1;
1306 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1307 || strcasecmp(val, "NO") == 0) {
1308 data = 0;
1309 } else {
1310 int i;
1311 if (sscanf(val, "%i", &i) == 1) {
1312 if (i != 0)
1313 data = 1;
1314 else
1315 data = 0;
1316 } else {
1317 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1318 if (second_pass == 0) {
1319 val = WMGetFromPLString(entry->plvalue);
1320 second_pass = 1;
1321 wwarning(_("using default \"%s\" instead"), val);
1322 goto again;
1324 return False;
1328 if (ret)
1329 *ret = &data;
1330 if (addr)
1331 *(char *)addr = data;
1333 return True;
1336 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1338 static int data;
1339 const char *val;
1341 GET_STRING_OR_DEFAULT("Integer", val);
1343 if (sscanf(val, "%i", &data) != 1) {
1344 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1345 val = WMGetFromPLString(entry->plvalue);
1346 wwarning(_("using default \"%s\" instead"), val);
1347 if (sscanf(val, "%i", &data) != 1) {
1348 return False;
1352 if (ret)
1353 *ret = &data;
1354 if (addr)
1355 *(int *)addr = data;
1357 return True;
1360 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1362 static WCoord data;
1363 char *val_x, *val_y;
1364 int nelem, changed = 0;
1365 WMPropList *elem_x, *elem_y;
1367 again:
1368 if (!WMIsPLArray(value)) {
1369 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1370 if (changed == 0) {
1371 value = entry->plvalue;
1372 changed = 1;
1373 wwarning(_("using default \"%s\" instead"), entry->default_value);
1374 goto again;
1376 return False;
1379 nelem = WMGetPropListItemCount(value);
1380 if (nelem != 2) {
1381 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1382 if (changed == 0) {
1383 value = entry->plvalue;
1384 changed = 1;
1385 wwarning(_("using default \"%s\" instead"), entry->default_value);
1386 goto again;
1388 return False;
1391 elem_x = WMGetFromPLArray(value, 0);
1392 elem_y = WMGetFromPLArray(value, 1);
1394 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1395 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1396 if (changed == 0) {
1397 value = entry->plvalue;
1398 changed = 1;
1399 wwarning(_("using default \"%s\" instead"), entry->default_value);
1400 goto again;
1402 return False;
1405 val_x = WMGetFromPLString(elem_x);
1406 val_y = WMGetFromPLString(elem_y);
1408 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1409 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1410 if (changed == 0) {
1411 value = entry->plvalue;
1412 changed = 1;
1413 wwarning(_("using default \"%s\" instead"), entry->default_value);
1414 goto again;
1416 return False;
1419 if (data.x < 0)
1420 data.x = 0;
1421 else if (data.x > scr->scr_width / 3)
1422 data.x = scr->scr_width / 3;
1423 if (data.y < 0)
1424 data.y = 0;
1425 else if (data.y > scr->scr_height / 3)
1426 data.y = scr->scr_height / 3;
1428 if (ret)
1429 *ret = &data;
1430 if (addr)
1431 *(WCoord *) addr = data;
1433 return True;
1436 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1438 WMRetainPropList(value);
1440 *ret = value;
1442 return True;
1445 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1447 static char *data;
1448 int i, count, len;
1449 char *ptr;
1450 WMPropList *d;
1451 int changed = 0;
1453 again:
1454 if (!WMIsPLArray(value)) {
1455 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1456 if (changed == 0) {
1457 value = entry->plvalue;
1458 changed = 1;
1459 wwarning(_("using default \"%s\" instead"), entry->default_value);
1460 goto again;
1462 return False;
1465 i = 0;
1466 count = WMGetPropListItemCount(value);
1467 if (count < 1) {
1468 if (changed == 0) {
1469 value = entry->plvalue;
1470 changed = 1;
1471 wwarning(_("using default \"%s\" instead"), entry->default_value);
1472 goto again;
1474 return False;
1477 len = 0;
1478 for (i = 0; i < count; i++) {
1479 d = WMGetFromPLArray(value, i);
1480 if (!d || !WMIsPLString(d)) {
1481 count = i;
1482 break;
1484 len += strlen(WMGetFromPLString(d)) + 1;
1487 ptr = data = wmalloc(len + 1);
1489 for (i = 0; i < count; i++) {
1490 d = WMGetFromPLArray(value, i);
1491 if (!d || !WMIsPLString(d)) {
1492 break;
1494 strcpy(ptr, WMGetFromPLString(d));
1495 ptr += strlen(WMGetFromPLString(d));
1496 *ptr = ':';
1497 ptr++;
1499 ptr--;
1500 *(ptr--) = 0;
1502 if (*(char **)addr != NULL) {
1503 wfree(*(char **)addr);
1505 *(char **)addr = data;
1507 return True;
1510 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1512 static signed char data;
1514 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1515 if (data < 0)
1516 return False;
1518 if (ret)
1519 *ret = &data;
1520 if (addr)
1521 *(signed char *)addr = data;
1523 return True;
1527 * (solid <color>)
1528 * (hgradient <color> <color>)
1529 * (vgradient <color> <color>)
1530 * (dgradient <color> <color>)
1531 * (mhgradient <color> <color> ...)
1532 * (mvgradient <color> <color> ...)
1533 * (mdgradient <color> <color> ...)
1534 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1535 * (tpixmap <file> <color>)
1536 * (spixmap <file> <color>)
1537 * (cpixmap <file> <color>)
1538 * (thgradient <file> <opaqueness> <color> <color>)
1539 * (tvgradient <file> <opaqueness> <color> <color>)
1540 * (tdgradient <file> <opaqueness> <color> <color>)
1541 * (function <lib> <function> ...)
1544 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1546 WMPropList *elem;
1547 char *val;
1548 int nelem;
1549 WTexture *texture = NULL;
1551 nelem = WMGetPropListItemCount(pl);
1552 if (nelem < 1)
1553 return NULL;
1555 elem = WMGetFromPLArray(pl, 0);
1556 if (!elem || !WMIsPLString(elem))
1557 return NULL;
1558 val = WMGetFromPLString(elem);
1560 if (strcasecmp(val, "solid") == 0) {
1561 XColor color;
1563 if (nelem != 2)
1564 return NULL;
1566 /* get color */
1568 elem = WMGetFromPLArray(pl, 1);
1569 if (!elem || !WMIsPLString(elem))
1570 return NULL;
1571 val = WMGetFromPLString(elem);
1573 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1574 wwarning(_("\"%s\" is not a valid color name"), val);
1575 return NULL;
1578 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1579 } else if (strcasecmp(val, "dgradient") == 0
1580 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1581 RColor color1, color2;
1582 XColor xcolor;
1583 int type;
1585 if (nelem != 3) {
1586 wwarning(_("bad number of arguments in gradient specification"));
1587 return NULL;
1590 if (val[0] == 'd' || val[0] == 'D')
1591 type = WTEX_DGRADIENT;
1592 else if (val[0] == 'h' || val[0] == 'H')
1593 type = WTEX_HGRADIENT;
1594 else
1595 type = WTEX_VGRADIENT;
1597 /* get from color */
1598 elem = WMGetFromPLArray(pl, 1);
1599 if (!elem || !WMIsPLString(elem))
1600 return NULL;
1601 val = WMGetFromPLString(elem);
1603 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1604 wwarning(_("\"%s\" is not a valid color name"), val);
1605 return NULL;
1607 color1.alpha = 255;
1608 color1.red = xcolor.red >> 8;
1609 color1.green = xcolor.green >> 8;
1610 color1.blue = xcolor.blue >> 8;
1612 /* get to color */
1613 elem = WMGetFromPLArray(pl, 2);
1614 if (!elem || !WMIsPLString(elem)) {
1615 return NULL;
1617 val = WMGetFromPLString(elem);
1619 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1620 wwarning(_("\"%s\" is not a valid color name"), val);
1621 return NULL;
1623 color2.alpha = 255;
1624 color2.red = xcolor.red >> 8;
1625 color2.green = xcolor.green >> 8;
1626 color2.blue = xcolor.blue >> 8;
1628 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1630 } else if (strcasecmp(val, "igradient") == 0) {
1631 RColor colors1[2], colors2[2];
1632 int th1, th2;
1633 XColor xcolor;
1634 int i;
1636 if (nelem != 7) {
1637 wwarning(_("bad number of arguments in gradient specification"));
1638 return NULL;
1641 /* get from color */
1642 for (i = 0; i < 2; i++) {
1643 elem = WMGetFromPLArray(pl, 1 + i);
1644 if (!elem || !WMIsPLString(elem))
1645 return NULL;
1646 val = WMGetFromPLString(elem);
1648 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1649 wwarning(_("\"%s\" is not a valid color name"), val);
1650 return NULL;
1652 colors1[i].alpha = 255;
1653 colors1[i].red = xcolor.red >> 8;
1654 colors1[i].green = xcolor.green >> 8;
1655 colors1[i].blue = xcolor.blue >> 8;
1657 elem = WMGetFromPLArray(pl, 3);
1658 if (!elem || !WMIsPLString(elem))
1659 return NULL;
1660 val = WMGetFromPLString(elem);
1661 th1 = atoi(val);
1663 /* get from color */
1664 for (i = 0; i < 2; i++) {
1665 elem = WMGetFromPLArray(pl, 4 + i);
1666 if (!elem || !WMIsPLString(elem))
1667 return NULL;
1668 val = WMGetFromPLString(elem);
1670 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1671 wwarning(_("\"%s\" is not a valid color name"), val);
1672 return NULL;
1674 colors2[i].alpha = 255;
1675 colors2[i].red = xcolor.red >> 8;
1676 colors2[i].green = xcolor.green >> 8;
1677 colors2[i].blue = xcolor.blue >> 8;
1679 elem = WMGetFromPLArray(pl, 6);
1680 if (!elem || !WMIsPLString(elem))
1681 return NULL;
1682 val = WMGetFromPLString(elem);
1683 th2 = atoi(val);
1685 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1687 } else if (strcasecmp(val, "mhgradient") == 0
1688 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1689 XColor color;
1690 RColor **colors;
1691 int i, count;
1692 int type;
1694 if (nelem < 3) {
1695 wwarning(_("too few arguments in multicolor gradient specification"));
1696 return NULL;
1699 if (val[1] == 'h' || val[1] == 'H')
1700 type = WTEX_MHGRADIENT;
1701 else if (val[1] == 'v' || val[1] == 'V')
1702 type = WTEX_MVGRADIENT;
1703 else
1704 type = WTEX_MDGRADIENT;
1706 count = nelem - 1;
1708 colors = wmalloc(sizeof(RColor *) * (count + 1));
1710 for (i = 0; i < count; i++) {
1711 elem = WMGetFromPLArray(pl, i + 1);
1712 if (!elem || !WMIsPLString(elem)) {
1713 for (--i; i >= 0; --i) {
1714 wfree(colors[i]);
1716 wfree(colors);
1717 return NULL;
1719 val = WMGetFromPLString(elem);
1721 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1722 wwarning(_("\"%s\" is not a valid color name"), val);
1723 for (--i; i >= 0; --i) {
1724 wfree(colors[i]);
1726 wfree(colors);
1727 return NULL;
1728 } else {
1729 colors[i] = wmalloc(sizeof(RColor));
1730 colors[i]->red = color.red >> 8;
1731 colors[i]->green = color.green >> 8;
1732 colors[i]->blue = color.blue >> 8;
1735 colors[i] = NULL;
1737 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1738 } else if (strcasecmp(val, "spixmap") == 0 ||
1739 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1740 XColor color;
1741 int type;
1743 if (nelem != 3)
1744 return NULL;
1746 if (val[0] == 's' || val[0] == 'S')
1747 type = WTP_SCALE;
1748 else if (val[0] == 'c' || val[0] == 'C')
1749 type = WTP_CENTER;
1750 else
1751 type = WTP_TILE;
1753 /* get color */
1754 elem = WMGetFromPLArray(pl, 2);
1755 if (!elem || !WMIsPLString(elem)) {
1756 return NULL;
1758 val = WMGetFromPLString(elem);
1760 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1761 wwarning(_("\"%s\" is not a valid color name"), val);
1762 return NULL;
1765 /* file name */
1766 elem = WMGetFromPLArray(pl, 1);
1767 if (!elem || !WMIsPLString(elem))
1768 return NULL;
1769 val = WMGetFromPLString(elem);
1771 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1772 } else if (strcasecmp(val, "thgradient") == 0
1773 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1774 RColor color1, color2;
1775 XColor xcolor;
1776 int opacity;
1777 int style;
1779 if (val[1] == 'h' || val[1] == 'H')
1780 style = WTEX_THGRADIENT;
1781 else if (val[1] == 'v' || val[1] == 'V')
1782 style = WTEX_TVGRADIENT;
1783 else
1784 style = WTEX_TDGRADIENT;
1786 if (nelem != 5) {
1787 wwarning(_("bad number of arguments in textured gradient specification"));
1788 return NULL;
1791 /* get from color */
1792 elem = WMGetFromPLArray(pl, 3);
1793 if (!elem || !WMIsPLString(elem))
1794 return NULL;
1795 val = WMGetFromPLString(elem);
1797 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1798 wwarning(_("\"%s\" is not a valid color name"), val);
1799 return NULL;
1801 color1.alpha = 255;
1802 color1.red = xcolor.red >> 8;
1803 color1.green = xcolor.green >> 8;
1804 color1.blue = xcolor.blue >> 8;
1806 /* get to color */
1807 elem = WMGetFromPLArray(pl, 4);
1808 if (!elem || !WMIsPLString(elem)) {
1809 return NULL;
1811 val = WMGetFromPLString(elem);
1813 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1814 wwarning(_("\"%s\" is not a valid color name"), val);
1815 return NULL;
1817 color2.alpha = 255;
1818 color2.red = xcolor.red >> 8;
1819 color2.green = xcolor.green >> 8;
1820 color2.blue = xcolor.blue >> 8;
1822 /* get opacity */
1823 elem = WMGetFromPLArray(pl, 2);
1824 if (!elem || !WMIsPLString(elem))
1825 opacity = 128;
1826 else
1827 val = WMGetFromPLString(elem);
1829 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1830 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1831 opacity = 128;
1834 /* get file name */
1835 elem = WMGetFromPLArray(pl, 1);
1836 if (!elem || !WMIsPLString(elem))
1837 return NULL;
1838 val = WMGetFromPLString(elem);
1840 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1841 } else if (strcasecmp(val, "function") == 0) {
1842 /* Leave this in to handle the unlikely case of
1843 * someone actually having function textures configured */
1844 wwarning("function texture support has been removed");
1845 return NULL;
1846 } else {
1847 wwarning(_("invalid texture type %s"), val);
1848 return NULL;
1850 return texture;
1853 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1855 static WTexture *texture;
1856 int changed = 0;
1858 again:
1859 if (!WMIsPLArray(value)) {
1860 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1861 if (changed == 0) {
1862 value = entry->plvalue;
1863 changed = 1;
1864 wwarning(_("using default \"%s\" instead"), entry->default_value);
1865 goto again;
1867 return False;
1870 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1871 WMPropList *pl;
1873 pl = WMGetFromPLArray(value, 0);
1874 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1875 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1876 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1877 entry->key, "Solid Texture");
1879 value = entry->plvalue;
1880 changed = 1;
1881 wwarning(_("using default \"%s\" instead"), entry->default_value);
1882 goto again;
1886 texture = parse_texture(scr, value);
1888 if (!texture) {
1889 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1890 if (changed == 0) {
1891 value = entry->plvalue;
1892 changed = 1;
1893 wwarning(_("using default \"%s\" instead"), entry->default_value);
1894 goto again;
1896 return False;
1899 if (ret)
1900 *ret = &texture;
1902 if (addr)
1903 *(WTexture **) addr = texture;
1905 return True;
1908 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1910 WMPropList *elem;
1911 int changed = 0;
1912 char *val;
1913 int nelem;
1915 again:
1916 if (!WMIsPLArray(value)) {
1917 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1918 "WorkspaceBack", "Texture or None");
1919 if (changed == 0) {
1920 value = entry->plvalue;
1921 changed = 1;
1922 wwarning(_("using default \"%s\" instead"), entry->default_value);
1923 goto again;
1925 return False;
1928 /* only do basic error checking and verify for None texture */
1930 nelem = WMGetPropListItemCount(value);
1931 if (nelem > 0) {
1932 elem = WMGetFromPLArray(value, 0);
1933 if (!elem || !WMIsPLString(elem)) {
1934 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1935 if (changed == 0) {
1936 value = entry->plvalue;
1937 changed = 1;
1938 wwarning(_("using default \"%s\" instead"), entry->default_value);
1939 goto again;
1941 return False;
1943 val = WMGetFromPLString(elem);
1945 if (strcasecmp(val, "None") == 0)
1946 return True;
1948 *ret = WMRetainPropList(value);
1950 return True;
1953 static int
1954 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1956 WMPropList *elem;
1957 int nelem;
1958 int changed = 0;
1960 again:
1961 if (!WMIsPLArray(value)) {
1962 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1963 "WorkspaceSpecificBack", "an array of textures");
1964 if (changed == 0) {
1965 value = entry->plvalue;
1966 changed = 1;
1967 wwarning(_("using default \"%s\" instead"), entry->default_value);
1968 goto again;
1970 return False;
1973 /* only do basic error checking and verify for None texture */
1975 nelem = WMGetPropListItemCount(value);
1976 if (nelem > 0) {
1977 while (nelem--) {
1978 elem = WMGetFromPLArray(value, nelem);
1979 if (!elem || !WMIsPLArray(elem)) {
1980 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1981 nelem);
1986 *ret = WMRetainPropList(value);
1988 #ifdef notworking
1990 * Kluge to force wmsetbg helper to set the default background.
1991 * If the WorkspaceSpecificBack is changed once wmaker has started,
1992 * the WorkspaceBack won't be sent to the helper, unless the user
1993 * changes it's value too. So, we must force this by removing the
1994 * value from the defaults DB.
1996 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1997 WMPropList *key = WMCreatePLString("WorkspaceBack");
1999 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2001 WMReleasePropList(key);
2003 #endif
2004 return True;
2007 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2009 static WMFont *font;
2010 const char *val;
2012 GET_STRING_OR_DEFAULT("Font", val);
2014 font = WMCreateFont(scr->wmscreen, val);
2015 if (!font)
2016 font = WMCreateFont(scr->wmscreen, "fixed");
2018 if (!font) {
2019 wfatal(_("could not load any usable font!!!"));
2020 exit(1);
2023 if (ret)
2024 *ret = font;
2026 /* can't assign font value outside update function */
2027 wassertrv(addr == NULL, True);
2029 return True;
2032 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2034 static XColor color;
2035 const char *val;
2036 int second_pass = 0;
2038 GET_STRING_OR_DEFAULT("Color", val);
2040 again:
2041 if (!wGetColor(scr, val, &color)) {
2042 wwarning(_("could not get color for key \"%s\""), entry->key);
2043 if (second_pass == 0) {
2044 val = WMGetFromPLString(entry->plvalue);
2045 second_pass = 1;
2046 wwarning(_("using default \"%s\" instead"), val);
2047 goto again;
2049 return False;
2052 if (ret)
2053 *ret = &color;
2055 assert(addr == NULL);
2057 if (addr)
2058 *(unsigned long*)addr = pixel;
2061 return True;
2064 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2066 static WShortKey shortcut;
2067 KeySym ksym;
2068 const char *val;
2069 char *k;
2070 char buf[MAX_SHORTCUT_LENGTH], *b;
2072 GET_STRING_OR_DEFAULT("Key spec", val);
2074 if (!val || strcasecmp(val, "NONE") == 0) {
2075 shortcut.keycode = 0;
2076 shortcut.modifier = 0;
2077 if (ret)
2078 *ret = &shortcut;
2079 return True;
2082 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2084 b = (char *)buf;
2086 /* get modifiers */
2087 shortcut.modifier = 0;
2088 while ((k = strchr(b, '+')) != NULL) {
2089 int mod;
2091 *k = 0;
2092 mod = wXModifierFromKey(b);
2093 if (mod < 0) {
2094 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2095 return False;
2097 shortcut.modifier |= mod;
2099 b = k + 1;
2102 /* get key */
2103 ksym = XStringToKeysym(b);
2105 if (ksym == NoSymbol) {
2106 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2107 return False;
2110 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2111 if (shortcut.keycode == 0) {
2112 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2113 return False;
2116 if (ret)
2117 *ret = &shortcut;
2119 return True;
2122 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2124 static int mask;
2125 const char *str;
2127 GET_STRING_OR_DEFAULT("Modifier Key", str);
2129 if (!str)
2130 return False;
2132 mask = wXModifierFromKey(str);
2133 if (mask < 0) {
2134 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2135 mask = 0;
2136 return False;
2139 if (addr)
2140 *(int *)addr = mask;
2142 if (ret)
2143 *ret = &mask;
2145 return True;
2148 # include <X11/cursorfont.h>
2149 typedef struct {
2150 const char *name;
2151 int id;
2152 } WCursorLookup;
2154 #define CURSOR_ID_NONE (XC_num_glyphs)
2156 static const WCursorLookup cursor_table[] = {
2157 {"X_cursor", XC_X_cursor},
2158 {"arrow", XC_arrow},
2159 {"based_arrow_down", XC_based_arrow_down},
2160 {"based_arrow_up", XC_based_arrow_up},
2161 {"boat", XC_boat},
2162 {"bogosity", XC_bogosity},
2163 {"bottom_left_corner", XC_bottom_left_corner},
2164 {"bottom_right_corner", XC_bottom_right_corner},
2165 {"bottom_side", XC_bottom_side},
2166 {"bottom_tee", XC_bottom_tee},
2167 {"box_spiral", XC_box_spiral},
2168 {"center_ptr", XC_center_ptr},
2169 {"circle", XC_circle},
2170 {"clock", XC_clock},
2171 {"coffee_mug", XC_coffee_mug},
2172 {"cross", XC_cross},
2173 {"cross_reverse", XC_cross_reverse},
2174 {"crosshair", XC_crosshair},
2175 {"diamond_cross", XC_diamond_cross},
2176 {"dot", XC_dot},
2177 {"dotbox", XC_dotbox},
2178 {"double_arrow", XC_double_arrow},
2179 {"draft_large", XC_draft_large},
2180 {"draft_small", XC_draft_small},
2181 {"draped_box", XC_draped_box},
2182 {"exchange", XC_exchange},
2183 {"fleur", XC_fleur},
2184 {"gobbler", XC_gobbler},
2185 {"gumby", XC_gumby},
2186 {"hand1", XC_hand1},
2187 {"hand2", XC_hand2},
2188 {"heart", XC_heart},
2189 {"icon", XC_icon},
2190 {"iron_cross", XC_iron_cross},
2191 {"left_ptr", XC_left_ptr},
2192 {"left_side", XC_left_side},
2193 {"left_tee", XC_left_tee},
2194 {"leftbutton", XC_leftbutton},
2195 {"ll_angle", XC_ll_angle},
2196 {"lr_angle", XC_lr_angle},
2197 {"man", XC_man},
2198 {"middlebutton", XC_middlebutton},
2199 {"mouse", XC_mouse},
2200 {"pencil", XC_pencil},
2201 {"pirate", XC_pirate},
2202 {"plus", XC_plus},
2203 {"question_arrow", XC_question_arrow},
2204 {"right_ptr", XC_right_ptr},
2205 {"right_side", XC_right_side},
2206 {"right_tee", XC_right_tee},
2207 {"rightbutton", XC_rightbutton},
2208 {"rtl_logo", XC_rtl_logo},
2209 {"sailboat", XC_sailboat},
2210 {"sb_down_arrow", XC_sb_down_arrow},
2211 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2212 {"sb_left_arrow", XC_sb_left_arrow},
2213 {"sb_right_arrow", XC_sb_right_arrow},
2214 {"sb_up_arrow", XC_sb_up_arrow},
2215 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2216 {"shuttle", XC_shuttle},
2217 {"sizing", XC_sizing},
2218 {"spider", XC_spider},
2219 {"spraycan", XC_spraycan},
2220 {"star", XC_star},
2221 {"target", XC_target},
2222 {"tcross", XC_tcross},
2223 {"top_left_arrow", XC_top_left_arrow},
2224 {"top_left_corner", XC_top_left_corner},
2225 {"top_right_corner", XC_top_right_corner},
2226 {"top_side", XC_top_side},
2227 {"top_tee", XC_top_tee},
2228 {"trek", XC_trek},
2229 {"ul_angle", XC_ul_angle},
2230 {"umbrella", XC_umbrella},
2231 {"ur_angle", XC_ur_angle},
2232 {"watch", XC_watch},
2233 {"xterm", XC_xterm},
2234 {NULL, CURSOR_ID_NONE}
2237 static void check_bitmap_status(int status, const char *filename, Pixmap bitmap)
2239 switch (status) {
2240 case BitmapOpenFailed:
2241 wwarning(_("failed to open bitmap file \"%s\""), filename);
2242 break;
2243 case BitmapFileInvalid:
2244 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2245 break;
2246 case BitmapNoMemory:
2247 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2248 break;
2249 case BitmapSuccess:
2250 XFreePixmap(dpy, bitmap);
2251 break;
2256 * (none)
2257 * (builtin, <cursor_name>)
2258 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2260 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2262 WMPropList *elem;
2263 char *val;
2264 int nelem;
2265 int status = 0;
2267 nelem = WMGetPropListItemCount(pl);
2268 if (nelem < 1) {
2269 return (status);
2271 elem = WMGetFromPLArray(pl, 0);
2272 if (!elem || !WMIsPLString(elem)) {
2273 return (status);
2275 val = WMGetFromPLString(elem);
2277 if (strcasecmp(val, "none") == 0) {
2278 status = 1;
2279 *cursor = None;
2280 } else if (strcasecmp(val, "builtin") == 0) {
2281 int i;
2282 int cursor_id = CURSOR_ID_NONE;
2284 if (nelem != 2) {
2285 wwarning(_("bad number of arguments in cursor specification"));
2286 return (status);
2288 elem = WMGetFromPLArray(pl, 1);
2289 if (!elem || !WMIsPLString(elem)) {
2290 return (status);
2292 val = WMGetFromPLString(elem);
2294 for (i = 0; cursor_table[i].name != NULL; i++) {
2295 if (strcasecmp(val, cursor_table[i].name) == 0) {
2296 cursor_id = cursor_table[i].id;
2297 break;
2300 if (CURSOR_ID_NONE == cursor_id) {
2301 wwarning(_("unknown builtin cursor name \"%s\""), val);
2302 } else {
2303 *cursor = XCreateFontCursor(dpy, cursor_id);
2304 status = 1;
2306 } else if (strcasecmp(val, "bitmap") == 0) {
2307 char *bitmap_name;
2308 char *mask_name;
2309 int bitmap_status;
2310 int mask_status;
2311 Pixmap bitmap;
2312 Pixmap mask;
2313 unsigned int w, h;
2314 int x, y;
2315 XColor fg, bg;
2317 if (nelem != 3) {
2318 wwarning(_("bad number of arguments in cursor specification"));
2319 return (status);
2321 elem = WMGetFromPLArray(pl, 1);
2322 if (!elem || !WMIsPLString(elem)) {
2323 return (status);
2325 val = WMGetFromPLString(elem);
2326 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2327 if (!bitmap_name) {
2328 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2329 return (status);
2331 elem = WMGetFromPLArray(pl, 2);
2332 if (!elem || !WMIsPLString(elem)) {
2333 wfree(bitmap_name);
2334 return (status);
2336 val = WMGetFromPLString(elem);
2337 mask_name = FindImage(wPreferences.pixmap_path, val);
2338 if (!mask_name) {
2339 wfree(bitmap_name);
2340 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2341 return (status);
2343 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2344 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2345 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2346 fg.pixel = scr->black_pixel;
2347 bg.pixel = scr->white_pixel;
2348 XQueryColor(dpy, scr->w_colormap, &fg);
2349 XQueryColor(dpy, scr->w_colormap, &bg);
2350 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2351 status = 1;
2353 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2354 check_bitmap_status(mask_status, mask_name, mask);
2355 wfree(bitmap_name);
2356 wfree(mask_name);
2358 return (status);
2361 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2363 static Cursor cursor;
2364 int status;
2365 int changed = 0;
2367 again:
2368 if (!WMIsPLArray(value)) {
2369 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2370 entry->key, "cursor specification");
2371 if (!changed) {
2372 value = entry->plvalue;
2373 changed = 1;
2374 wwarning(_("using default \"%s\" instead"), entry->default_value);
2375 goto again;
2377 return (False);
2379 status = parse_cursor(scr, value, &cursor);
2380 if (!status) {
2381 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2382 if (!changed) {
2383 value = entry->plvalue;
2384 changed = 1;
2385 wwarning(_("using default \"%s\" instead"), entry->default_value);
2386 goto again;
2388 return (False);
2390 if (ret) {
2391 *ret = &cursor;
2393 if (addr) {
2394 *(Cursor *) addr = cursor;
2396 return (True);
2399 #undef CURSOR_ID_NONE
2401 /* ---------------- value setting functions --------------- */
2402 static int setJustify(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2404 return REFRESH_WINDOW_TITLE_COLOR;
2407 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2409 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2412 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2414 char *flag = tdata;
2415 long which = (long) extra_data;
2417 switch (which) {
2418 case WM_DOCK:
2419 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2420 // Drawers require the dock
2421 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || wPreferences.flags.nodock;
2422 break;
2423 case WM_CLIP:
2424 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2425 break;
2426 case WM_DRAWER:
2427 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || *flag;
2428 break;
2429 default:
2430 break;
2432 return 0;
2435 static int setClipMergedInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2437 char *flag = tdata;
2439 wPreferences.flags.clip_merged_in_dock = *flag;
2440 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2441 return 0;
2444 static int setWrapAppiconsInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2446 char *flag = tdata;
2448 wPreferences.flags.wrap_appicons_in_dock = *flag;
2449 return 0;
2452 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2454 if (w_global.workspace.array) {
2455 wWorkspaceForceChange(scr, w_global.workspace.current);
2456 wArrangeIcons(scr, False);
2458 return 0;
2461 static int setIconTile(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2463 Pixmap pixmap;
2464 RImage *img;
2465 WTexture ** texture = tdata;
2466 int reset = 0;
2468 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2469 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2470 ? WREL_ICON : WREL_FLAT);
2471 if (!img) {
2472 wwarning(_("could not render texture for icon background"));
2473 if (!entry->addr)
2474 wTextureDestroy(scr, *texture);
2475 return 0;
2477 RConvertImage(scr->rcontext, img, &pixmap);
2479 if (scr->icon_tile) {
2480 reset = 1;
2481 RReleaseImage(scr->icon_tile);
2482 XFreePixmap(dpy, scr->icon_tile_pixmap);
2485 scr->icon_tile = img;
2487 /* put the icon in the noticeboard hint */
2488 PropSetIconTileHint(scr, img);
2490 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock) {
2491 if (scr->clip_tile) {
2492 RReleaseImage(scr->clip_tile);
2494 scr->clip_tile = wClipMakeTile(scr, img);
2497 if (!wPreferences.flags.nodrawer) {
2498 if (scr->drawer_tile) {
2499 RReleaseImage(scr->drawer_tile);
2501 scr->drawer_tile = wDrawerMakeTile(scr, img);
2504 scr->icon_tile_pixmap = pixmap;
2506 if (scr->def_icon_rimage) {
2507 RReleaseImage(scr->def_icon_rimage);
2508 scr->def_icon_rimage = NULL;
2511 if (scr->icon_back_texture)
2512 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2514 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2516 /* Free the texture as nobody else will use it, nor refer to it. */
2517 if (!entry->addr)
2518 wTextureDestroy(scr, *texture);
2520 return (reset ? REFRESH_ICON_TILE : 0);
2523 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2525 WMFont *font = tdata;
2527 if (scr->title_font) {
2528 WMReleaseFont(scr->title_font);
2530 scr->title_font = font;
2532 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2535 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2537 WMFont *font = tdata;
2539 if (scr->menu_title_font) {
2540 WMReleaseFont(scr->menu_title_font);
2543 scr->menu_title_font = font;
2545 return REFRESH_MENU_TITLE_FONT;
2548 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2550 WMFont *font = tdata;
2552 if (scr->menu_entry_font) {
2553 WMReleaseFont(scr->menu_entry_font);
2555 scr->menu_entry_font = font;
2557 return REFRESH_MENU_FONT;
2560 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2562 WMFont *font = tdata;
2564 if (scr->icon_title_font) {
2565 WMReleaseFont(scr->icon_title_font);
2568 scr->icon_title_font = font;
2570 return REFRESH_ICON_FONT;
2573 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2575 WMFont *font = tdata;
2577 if (scr->clip_title_font) {
2578 WMReleaseFont(scr->clip_title_font);
2581 scr->clip_title_font = font;
2583 return REFRESH_ICON_FONT;
2586 static int setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2588 WMFont *font = tdata;
2590 if (w_global.workspace.font_for_name)
2591 WMReleaseFont(w_global.workspace.font_for_name);
2593 w_global.workspace.font_for_name = font;
2595 return 0;
2598 static int setHightlight(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2600 XColor *color = tdata;
2602 if (scr->select_color)
2603 WMReleaseColor(scr->select_color);
2605 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2607 wFreeColor(scr, color->pixel);
2609 return REFRESH_MENU_COLOR;
2612 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2614 XColor *color = tdata;
2616 if (scr->select_text_color)
2617 WMReleaseColor(scr->select_text_color);
2619 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2621 wFreeColor(scr, color->pixel);
2623 return REFRESH_MENU_COLOR;
2626 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2628 XColor *color = tdata;
2629 long widx = (long) extra_data;
2631 if (scr->clip_title_color[widx])
2632 WMReleaseColor(scr->clip_title_color[widx]);
2634 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2635 wFreeColor(scr, color->pixel);
2637 return REFRESH_ICON_TITLE_COLOR;
2640 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2642 XColor *color = tdata;
2643 long widx = (long) extra_data;
2645 if (scr->window_title_color[widx])
2646 WMReleaseColor(scr->window_title_color[widx]);
2648 scr->window_title_color[widx] =
2649 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2651 wFreeColor(scr, color->pixel);
2653 return REFRESH_WINDOW_TITLE_COLOR;
2656 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2658 XColor *color = tdata;
2660 if (scr->menu_title_color[0])
2661 WMReleaseColor(scr->menu_title_color[0]);
2663 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2665 wFreeColor(scr, color->pixel);
2667 return REFRESH_MENU_TITLE_COLOR;
2670 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2672 XColor *color = tdata;
2674 if (scr->mtext_color)
2675 WMReleaseColor(scr->mtext_color);
2677 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2679 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2680 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2681 } else {
2682 WMSetColorAlpha(scr->dtext_color, 0xffff);
2685 wFreeColor(scr, color->pixel);
2687 return REFRESH_MENU_COLOR;
2690 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2692 XColor *color = tdata;
2694 if (scr->dtext_color)
2695 WMReleaseColor(scr->dtext_color);
2697 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2699 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2700 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2701 } else {
2702 WMSetColorAlpha(scr->dtext_color, 0xffff);
2705 wFreeColor(scr, color->pixel);
2707 return REFRESH_MENU_COLOR;
2710 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2712 XColor *color = tdata;
2714 if (scr->icon_title_color)
2715 WMReleaseColor(scr->icon_title_color);
2716 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2718 wFreeColor(scr, color->pixel);
2720 return REFRESH_ICON_TITLE_COLOR;
2723 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2725 XColor *color = tdata;
2727 if (scr->icon_title_texture) {
2728 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2730 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2732 return REFRESH_ICON_TITLE_BACK;
2735 static int setFrameBorderWidth(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2737 int *value = tdata;
2739 scr->frame_border_width = *value;
2741 return REFRESH_FRAME_BORDER;
2744 static int setFrameBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2746 XColor *color = tdata;
2748 if (scr->frame_border_color)
2749 WMReleaseColor(scr->frame_border_color);
2750 scr->frame_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2752 wFreeColor(scr, color->pixel);
2754 return REFRESH_FRAME_BORDER;
2757 static int setFrameSelectedBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2759 XColor *color = tdata;
2761 if (scr->frame_selected_border_color)
2762 WMReleaseColor(scr->frame_selected_border_color);
2763 scr->frame_selected_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2765 wFreeColor(scr, color->pixel);
2767 return REFRESH_FRAME_BORDER;
2770 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2772 close(scr->helper_fd);
2773 scr->helper_fd = 0;
2774 scr->helper_pid = 0;
2775 scr->flags.backimage_helper_launched = 0;
2778 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
2780 WMPropList *value = tdata;
2781 WMPropList *val;
2782 char *str;
2783 int i;
2785 if (scr->flags.backimage_helper_launched) {
2786 if (WMGetPropListItemCount(value) == 0) {
2787 SendHelperMessage(scr, 'C', 0, NULL);
2788 SendHelperMessage(scr, 'K', 0, NULL);
2790 WMReleasePropList(value);
2791 return 0;
2793 } else {
2794 pid_t pid;
2795 int filedes[2];
2797 if (WMGetPropListItemCount(value) == 0)
2798 return 0;
2800 if (pipe(filedes) < 0) {
2801 werror("pipe() failed:can't set workspace specific background image");
2803 WMReleasePropList(value);
2804 return 0;
2807 pid = fork();
2808 if (pid < 0) {
2809 werror("fork() failed:can't set workspace specific background image");
2810 if (close(filedes[0]) < 0)
2811 werror("could not close pipe");
2812 if (close(filedes[1]) < 0)
2813 werror("could not close pipe");
2815 } else if (pid == 0) {
2816 char *dither;
2818 SetupEnvironment(scr);
2820 if (close(0) < 0)
2821 werror("could not close pipe");
2822 if (dup(filedes[0]) < 0) {
2823 werror("dup() failed:can't set workspace specific background image");
2825 dither = wPreferences.no_dithering ? "-m" : "-d";
2826 if (wPreferences.smooth_workspace_back)
2827 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2828 else
2829 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2830 werror("could not execute wmsetbg");
2831 exit(1);
2832 } else {
2834 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2835 werror("error setting close-on-exec flag");
2837 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2838 werror("error setting close-on-exec flag");
2841 scr->helper_fd = filedes[1];
2842 scr->helper_pid = pid;
2843 scr->flags.backimage_helper_launched = 1;
2845 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2847 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2852 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2853 val = WMGetFromPLArray(value, i);
2854 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2855 str = WMGetPropListDescription(val, False);
2857 SendHelperMessage(scr, 'S', i + 1, str);
2859 wfree(str);
2860 } else {
2861 SendHelperMessage(scr, 'U', i + 1, NULL);
2864 sleep(1);
2866 WMReleasePropList(value);
2867 return 0;
2870 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
2872 WMPropList *value = tdata;
2874 if (scr->flags.backimage_helper_launched) {
2875 char *str;
2877 if (WMGetPropListItemCount(value) == 0) {
2878 SendHelperMessage(scr, 'U', 0, NULL);
2879 } else {
2880 /* set the default workspace background to this one */
2881 str = WMGetPropListDescription(value, False);
2882 if (str) {
2883 SendHelperMessage(scr, 'S', 0, str);
2884 wfree(str);
2885 SendHelperMessage(scr, 'C', w_global.workspace.current + 1, NULL);
2886 } else {
2887 SendHelperMessage(scr, 'U', 0, NULL);
2890 } else if (WMGetPropListItemCount(value) > 0) {
2891 char *command;
2892 char *text;
2893 char *dither;
2894 int len;
2896 text = WMGetPropListDescription(value, False);
2897 len = strlen(text) + 40;
2898 command = wmalloc(len);
2899 dither = wPreferences.no_dithering ? "-m" : "-d";
2900 if (wPreferences.smooth_workspace_back)
2901 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2902 else
2903 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2904 wfree(text);
2905 ExecuteShellCommand(scr, command);
2906 wfree(command);
2908 WMReleasePropList(value);
2910 return 0;
2913 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2915 WTexture **texture = tdata;
2917 if (scr->widget_texture) {
2918 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2920 scr->widget_texture = *(WTexSolid **) texture;
2922 return 0;
2925 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2927 WTexture **texture = tdata;
2929 if (scr->window_title_texture[WS_FOCUSED]) {
2930 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2932 scr->window_title_texture[WS_FOCUSED] = *texture;
2934 return REFRESH_WINDOW_TEXTURES;
2937 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2939 WTexture **texture = tdata;
2941 if (scr->window_title_texture[WS_PFOCUSED]) {
2942 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2944 scr->window_title_texture[WS_PFOCUSED] = *texture;
2946 return REFRESH_WINDOW_TEXTURES;
2949 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2951 WTexture **texture = tdata;
2953 if (scr->window_title_texture[WS_UNFOCUSED]) {
2954 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2956 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2958 return REFRESH_WINDOW_TEXTURES;
2961 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2963 WTexture **texture = tdata;
2965 if (scr->resizebar_texture[0]) {
2966 wTextureDestroy(scr, scr->resizebar_texture[0]);
2968 scr->resizebar_texture[0] = *texture;
2970 return REFRESH_WINDOW_TEXTURES;
2973 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2975 WTexture **texture = tdata;
2977 if (scr->menu_title_texture[0]) {
2978 wTextureDestroy(scr, scr->menu_title_texture[0]);
2980 scr->menu_title_texture[0] = *texture;
2982 return REFRESH_MENU_TITLE_TEXTURE;
2985 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2987 WTexture **texture = tdata;
2989 if (scr->menu_item_texture) {
2990 wTextureDestroy(scr, scr->menu_item_texture);
2991 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2993 scr->menu_item_texture = *texture;
2995 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2997 return REFRESH_MENU_TEXTURE;
3000 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3002 WShortKey *shortcut = tdata;
3003 WWindow *wwin;
3004 long widx = (long) extra_data;
3006 wKeyBindings[widx] = *shortcut;
3008 wwin = scr->focused_window;
3010 while (wwin != NULL) {
3011 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3013 if (!WFLAGP(wwin, no_bind_keys)) {
3014 wWindowSetKeyGrabs(wwin);
3016 wwin = wwin->prev;
3019 /* do we need to update window menus? */
3020 if (widx >= WKBD_WORKSPACE1 && widx <= WKBD_WORKSPACE10)
3021 return REFRESH_WORKSPACE_MENU;
3022 if (widx == WKBD_LASTWORKSPACE)
3023 return REFRESH_WORKSPACE_MENU;
3024 if (widx >= WKBD_MOVE_WORKSPACE1 && widx <= WKBD_MOVE_WORKSPACE10)
3025 return REFRESH_WORKSPACE_MENU;
3027 return 0;
3030 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3032 wScreenUpdateUsableArea(scr);
3033 wArrangeIcons(scr, True);
3035 return 0;
3038 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3040 wScreenUpdateUsableArea(scr);
3042 return 0;
3045 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3047 return REFRESH_MENU_TEXTURE;
3050 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3052 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3054 RCopyArea(img, image, x, y, w, h, 0, 0);
3056 return img;
3059 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3061 WMPropList *array = tdata;
3062 char *path;
3063 RImage *bgimage;
3064 int cwidth, cheight;
3065 struct WPreferences *prefs = foo;
3067 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3068 if (prefs->swtileImage)
3069 RReleaseImage(prefs->swtileImage);
3070 prefs->swtileImage = NULL;
3072 WMReleasePropList(array);
3073 return 0;
3076 switch (WMGetPropListItemCount(array)) {
3077 case 4:
3078 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3079 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3080 break;
3081 } else
3082 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3084 if (!path) {
3085 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3086 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3087 } else {
3088 bgimage = RLoadImage(scr->rcontext, path, 0);
3089 if (!bgimage) {
3090 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3091 wfree(path);
3092 } else {
3093 wfree(path);
3095 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3096 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3098 if (cwidth <= 0 || cheight <= 0 ||
3099 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3100 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3101 else {
3102 int i;
3103 int swidth, theight;
3104 for (i = 0; i < 9; i++) {
3105 if (prefs->swbackImage[i])
3106 RReleaseImage(prefs->swbackImage[i]);
3107 prefs->swbackImage[i] = NULL;
3109 swidth = (bgimage->width - cwidth) / 2;
3110 theight = (bgimage->height - cheight) / 2;
3112 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3113 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3114 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3115 swidth, theight);
3117 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3118 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3119 cwidth, cheight);
3120 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3121 swidth, cheight);
3123 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3124 swidth, theight);
3125 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3126 cwidth, theight);
3127 prefs->swbackImage[8] =
3128 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3129 theight);
3131 // check if anything failed
3132 for (i = 0; i < 9; i++) {
3133 if (!prefs->swbackImage[i]) {
3134 for (; i >= 0; --i) {
3135 RReleaseImage(prefs->swbackImage[i]);
3136 prefs->swbackImage[i] = NULL;
3138 break;
3142 RReleaseImage(bgimage);
3146 case 1:
3147 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3148 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3149 break;
3150 } else
3151 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3153 if (!path) {
3154 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3155 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3156 } else {
3157 if (prefs->swtileImage)
3158 RReleaseImage(prefs->swtileImage);
3160 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3161 if (!prefs->swtileImage) {
3162 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3164 wfree(path);
3166 break;
3168 default:
3169 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3170 break;
3173 WMReleasePropList(array);
3175 return 0;
3178 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3180 WMPropList *array = tdata;
3181 int i;
3182 struct WPreferences *prefs = foo;
3184 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3185 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3186 WMReleasePropList(array);
3187 return 0;
3190 DestroyWindowMenu(scr);
3192 for (i = 0; i < 7; i++) {
3193 if (prefs->modifier_labels[i])
3194 wfree(prefs->modifier_labels[i]);
3196 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3197 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3198 } else {
3199 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3200 prefs->modifier_labels[i] = NULL;
3204 WMReleasePropList(array);
3206 return 0;
3209 static int setDoubleClick(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
3211 int *value = tdata;
3213 if (*value <= 0)
3214 *(int *)foo = 1;
3216 W_setconf_doubleClickDelay(*value);
3218 return 0;
3221 static int setCursor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3223 Cursor *cursor = tdata;
3224 long widx = (long) extra_data;
3226 if (wPreferences.cursor[widx] != None) {
3227 XFreeCursor(dpy, wPreferences.cursor[widx]);
3230 wPreferences.cursor[widx] = *cursor;
3232 if (widx == WCUR_ROOT && *cursor != None) {
3233 XDefineCursor(dpy, scr->root_win, *cursor);
3236 return 0;