wmaker: minor fixes for the size of an aperçu
[wmaker-crm.git] / src / defaults.c
blobe1237d568cad65859455e769c3d97cb1b53037f1
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
75 typedef struct _WDefaultEntry WDefaultEntry;
76 typedef int (WDECallbackConvert) (WScreen *scr, WDefaultEntry *entry, WMPropList *plvalue, void *addr, void **tdata);
77 typedef int (WDECallbackUpdate) (WScreen *scr, WDefaultEntry *entry, void *tdata, void *extra_data);
79 struct _WDefaultEntry {
80 const char *key;
81 const char *default_value;
82 void *extra_data;
83 void *addr;
84 WDECallbackConvert *convert;
85 WDECallbackUpdate *update;
86 WMPropList *plkey;
87 WMPropList *plvalue; /* default value */
90 /* used to map strings to integers */
91 typedef struct {
92 const char *string;
93 short value;
94 char is_alias;
95 } WOptionEnumeration;
97 /* type converters */
98 static WDECallbackConvert getBool;
99 static WDECallbackConvert getInt;
100 static WDECallbackConvert getCoord;
101 static WDECallbackConvert getPathList;
102 static WDECallbackConvert getEnum;
103 static WDECallbackConvert getTexture;
104 static WDECallbackConvert getWSBackground;
105 static WDECallbackConvert getWSSpecificBackground;
106 static WDECallbackConvert getFont;
107 static WDECallbackConvert getColor;
108 static WDECallbackConvert getKeybind;
109 static WDECallbackConvert getModMask;
110 static WDECallbackConvert getPropList;
112 /* value setting functions */
113 static WDECallbackUpdate setJustify;
114 static WDECallbackUpdate setClearance;
115 static WDECallbackUpdate setIfDockPresent;
116 static WDECallbackUpdate setClipMergedInDock;
117 static WDECallbackUpdate setWrapAppiconsInDock;
118 static WDECallbackUpdate setStickyIcons;
119 static WDECallbackUpdate setWidgetColor;
120 static WDECallbackUpdate setIconTile;
121 static WDECallbackUpdate setWinTitleFont;
122 static WDECallbackUpdate setMenuTitleFont;
123 static WDECallbackUpdate setMenuTextFont;
124 static WDECallbackUpdate setIconTitleFont;
125 static WDECallbackUpdate setIconTitleColor;
126 static WDECallbackUpdate setIconTitleBack;
127 static WDECallbackUpdate setFrameBorderWidth;
128 static WDECallbackUpdate setFrameBorderColor;
129 static WDECallbackUpdate setFrameFocusedBorderColor;
130 static WDECallbackUpdate setFrameSelectedBorderColor;
131 static WDECallbackUpdate setLargeDisplayFont;
132 static WDECallbackUpdate setWTitleColor;
133 static WDECallbackUpdate setFTitleBack;
134 static WDECallbackUpdate setPTitleBack;
135 static WDECallbackUpdate setUTitleBack;
136 static WDECallbackUpdate setResizebarBack;
137 static WDECallbackUpdate setWorkspaceBack;
138 static WDECallbackUpdate setWorkspaceSpecificBack;
139 static WDECallbackUpdate setMenuTitleColor;
140 static WDECallbackUpdate setMenuTextColor;
141 static WDECallbackUpdate setMenuDisabledColor;
142 static WDECallbackUpdate setMenuTitleBack;
143 static WDECallbackUpdate setMenuTextBack;
144 static WDECallbackUpdate setHightlight;
145 static WDECallbackUpdate setHightlightText;
146 static WDECallbackUpdate setKeyGrab;
147 static WDECallbackUpdate setDoubleClick;
148 static WDECallbackUpdate setIconPosition;
150 static WDECallbackUpdate setClipTitleFont;
151 static WDECallbackUpdate setClipTitleColor;
153 static WDECallbackUpdate setMenuStyle;
154 static WDECallbackUpdate setSwPOptions;
155 static WDECallbackUpdate updateUsableArea;
157 static WDECallbackUpdate setModifierKeyLabels;
159 static WDECallbackConvert getCursor;
160 static WDECallbackUpdate setCursor;
163 * Tables to convert strings to enumeration values.
164 * Values stored are char
167 /* WARNING: sum of length of all value strings must not exceed
168 * this value */
169 #define TOTAL_VALUES_LENGTH 80
171 #define REFRESH_WINDOW_TEXTURES (1<<0)
172 #define REFRESH_MENU_TEXTURE (1<<1)
173 #define REFRESH_MENU_FONT (1<<2)
174 #define REFRESH_MENU_COLOR (1<<3)
175 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
176 #define REFRESH_MENU_TITLE_FONT (1<<5)
177 #define REFRESH_MENU_TITLE_COLOR (1<<6)
178 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
179 #define REFRESH_WINDOW_FONT (1<<8)
180 #define REFRESH_ICON_TILE (1<<9)
181 #define REFRESH_ICON_FONT (1<<10)
182 #define REFRESH_WORKSPACE_BACK (1<<11)
184 #define REFRESH_BUTTON_IMAGES (1<<12)
186 #define REFRESH_ICON_TITLE_COLOR (1<<13)
187 #define REFRESH_ICON_TITLE_BACK (1<<14)
189 #define REFRESH_WORKSPACE_MENU (1<<15)
191 #define REFRESH_FRAME_BORDER REFRESH_MENU_FONT|REFRESH_WINDOW_FONT
193 static WOptionEnumeration seFocusModes[] = {
194 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
195 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
196 {NULL, 0, 0}
199 static WOptionEnumeration seTitlebarModes[] = {
200 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
201 {"next", TS_NEXT, 0}, {NULL, 0, 0}
204 static WOptionEnumeration seColormapModes[] = {
205 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
206 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
207 {NULL, 0, 0}
210 static WOptionEnumeration sePlacements[] = {
211 {"Auto", WPM_AUTO, 0},
212 {"Smart", WPM_SMART, 0},
213 {"Cascade", WPM_CASCADE, 0},
214 {"Random", WPM_RANDOM, 0},
215 {"Manual", WPM_MANUAL, 0},
216 {"Center", WPM_CENTER, 0},
217 {NULL, 0, 0}
220 static WOptionEnumeration seGeomDisplays[] = {
221 {"None", WDIS_NONE, 0},
222 {"Center", WDIS_CENTER, 0},
223 {"Corner", WDIS_TOPLEFT, 0},
224 {"Floating", WDIS_FRAME_CENTER, 0},
225 {"Line", WDIS_NEW, 0},
226 {NULL, 0, 0}
229 static WOptionEnumeration seSpeeds[] = {
230 {"UltraFast", SPEED_ULTRAFAST, 0},
231 {"Fast", SPEED_FAST, 0},
232 {"Medium", SPEED_MEDIUM, 0},
233 {"Slow", SPEED_SLOW, 0},
234 {"UltraSlow", SPEED_ULTRASLOW, 0},
235 {NULL, 0, 0}
238 static WOptionEnumeration seMouseButtonActions[] = {
239 {"None", WA_NONE, 0},
240 {"SelectWindows", WA_SELECT_WINDOWS, 0},
241 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
242 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
243 {"MoveToPrevWorkspace", WA_MOVE_PREVWORKSPACE, 0},
244 {"MoveToNextWorkspace", WA_MOVE_NEXTWORKSPACE, 0},
245 {"MoveToPrevWindow", WA_MOVE_PREVWINDOW, 0},
246 {"MoveToNextWindow", WA_MOVE_NEXTWINDOW, 0},
247 {NULL, 0, 0}
250 static WOptionEnumeration seMouseWheelActions[] = {
251 {"None", WA_NONE, 0},
252 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
253 {"SwitchWindows", WA_SWITCH_WINDOWS, 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}
312 static WOptionEnumeration seDragMaximizedWindow[] = {
313 {"Move", DRAGMAX_MOVE, 0},
314 {"RestoreGeometry", DRAGMAX_RESTORE, 0},
315 {"Unmaximize", DRAGMAX_UNMAXIMIZE, 0},
316 {"NoMove", DRAGMAX_NOMOVE, 0},
317 {NULL, 0, 0}
321 * ALL entries in the tables bellow, NEED to have a default value
322 * defined, and this value needs to be correct.
325 /* these options will only affect the window manager on startup
327 * static defaults can't access the screen data, because it is
328 * created after these defaults are read
330 WDefaultEntry staticOptionList[] = {
332 {"ColormapSize", "4", NULL,
333 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
334 {"DisableDithering", "NO", NULL,
335 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
336 {"IconSize", "64", NULL,
337 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
338 {"ModifierKey", "Mod1", NULL,
339 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
340 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
341 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
342 {"NewStyle", "new", seTitlebarModes,
343 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
344 {"DisableDock", "NO", (void *)WM_DOCK,
345 NULL, getBool, setIfDockPresent, NULL, NULL},
346 {"DisableClip", "NO", (void *)WM_CLIP,
347 NULL, getBool, setIfDockPresent, NULL, NULL},
348 {"DisableDrawers", "NO", (void *)WM_DRAWER,
349 NULL, getBool, setIfDockPresent, NULL, NULL},
350 {"ClipMergedInDock", "NO", NULL,
351 NULL, getBool, setClipMergedInDock, NULL, NULL},
352 {"DisableMiniwindows", "NO", NULL,
353 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
356 #define NUM2STRING_(x) #x
357 #define NUM2STRING(x) NUM2STRING_(x)
359 WDefaultEntry optionList[] = {
361 /* dynamic options */
363 {"IconPosition", "blh", seIconPositions,
364 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
365 {"IconificationStyle", "Zoom", seIconificationStyles,
366 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
367 {"DisableWSMouseActions", "NO", NULL,
368 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
369 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
370 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
371 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
372 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
373 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
374 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
375 {"MouseBackwardButtonAction", "None", seMouseButtonActions,
376 &wPreferences.mouse_button8, getEnum, NULL, NULL, NULL},
377 {"MouseForwardButtonAction", "None", seMouseButtonActions,
378 &wPreferences.mouse_button9, getEnum, NULL, NULL, NULL},
379 {"MouseWheelAction", "None", seMouseWheelActions,
380 &wPreferences.mouse_wheel_scroll, getEnum, NULL, NULL, NULL},
381 {"MouseWheelTiltAction", "None", seMouseWheelActions,
382 &wPreferences.mouse_wheel_tilt, getEnum, NULL, NULL, NULL},
383 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
384 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
385 {"IconPath", DEF_ICON_PATHS, NULL,
386 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
387 {"ColormapMode", "auto", seColormapModes,
388 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
389 {"AutoFocus", "NO", NULL,
390 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
391 {"RaiseDelay", "0", NULL,
392 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
393 {"CirculateRaise", "NO", NULL,
394 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
395 {"Superfluous", "NO", NULL,
396 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
397 {"AdvanceToNewWorkspace", "NO", NULL,
398 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
399 {"CycleWorkspaces", "NO", NULL,
400 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
401 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
402 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
403 {"WorkspaceBorder", "None", seWorkspaceBorder,
404 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
405 {"WorkspaceBorderSize", "0", NULL,
406 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
407 {"StickyIcons", "NO", NULL,
408 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
409 {"SaveSessionOnExit", "NO", NULL,
410 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
411 {"WrapMenus", "NO", NULL,
412 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
413 {"ScrollableMenus", "NO", NULL,
414 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
415 {"MenuScrollSpeed", "medium", seSpeeds,
416 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
417 {"IconSlideSpeed", "medium", seSpeeds,
418 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
419 {"ShadeSpeed", "medium", seSpeeds,
420 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
421 {"BounceAppIconsWhenUrgent", "YES", NULL,
422 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
423 {"RaiseAppIconsWhenBouncing", "NO", NULL,
424 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
425 {"DoNotMakeAppIconsBounce", "NO", NULL,
426 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
427 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
428 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
429 {"ClipAutoraiseDelay", "600", NULL,
430 &wPreferences.clip_auto_raise_delay, getInt, NULL, NULL, NULL},
431 {"ClipAutolowerDelay", "1000", NULL,
432 &wPreferences.clip_auto_lower_delay, getInt, NULL, NULL, NULL},
433 {"ClipAutoexpandDelay", "600", NULL,
434 &wPreferences.clip_auto_expand_delay, getInt, NULL, NULL, NULL},
435 {"ClipAutocollapseDelay", "1000", NULL,
436 &wPreferences.clip_auto_collapse_delay, getInt, NULL, NULL, NULL},
437 {"WrapAppiconsInDock", "YES", NULL,
438 NULL, getBool, setWrapAppiconsInDock, NULL, NULL},
439 {"AlignSubmenus", "NO", NULL,
440 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
441 {"ViKeyMenus", "NO", NULL,
442 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
443 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
444 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
445 {"WindowPlacement", "auto", sePlacements,
446 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
447 {"IgnoreFocusClick", "NO", NULL,
448 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
449 {"UseSaveUnders", "NO", NULL,
450 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
451 {"OpaqueMove", "NO", NULL,
452 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
453 {"OpaqueResize", "NO", NULL,
454 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
455 {"OpaqueMoveResizeKeyboard", "NO", NULL,
456 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
457 {"DisableAnimations", "NO", NULL,
458 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
459 {"DontLinkWorkspaces", "NO", NULL,
460 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
461 {"WindowSnapping", "NO", NULL,
462 &wPreferences.window_snapping, getBool, NULL, NULL, NULL},
463 {"DragMaximizedWindow", "Move", seDragMaximizedWindow,
464 &wPreferences.drag_maximized_window, getEnum, NULL, NULL, NULL},
465 {"HighlightActiveApp", "YES", NULL,
466 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
467 {"AutoArrangeIcons", "NO", NULL,
468 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
469 {"NoWindowOverDock", "NO", NULL,
470 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
471 {"NoWindowOverIcons", "NO", NULL,
472 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
473 {"WindowPlaceOrigin", "(0, 0)", NULL,
474 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
475 {"ResizeDisplay", "corner", seGeomDisplays,
476 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
477 {"MoveDisplay", "corner", seGeomDisplays,
478 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
479 {"DontConfirmKill", "NO", NULL,
480 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
481 {"WindowTitleBalloons", "NO", NULL,
482 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
483 {"MiniwindowTitleBalloons", "NO", NULL,
484 &wPreferences.miniwin_title_balloon, getBool, NULL, NULL, NULL},
485 {"MiniwindowApercuBalloons", "NO", NULL,
486 &wPreferences.miniwin_apercu_balloon, getBool, NULL, NULL, NULL},
487 {"AppIconBalloons", "NO", NULL,
488 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
489 {"HelpBalloons", "NO", NULL,
490 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
491 {"EdgeResistance", "30", NULL,
492 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
493 {"ResizeIncrement", "0", NULL,
494 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
495 {"Attraction", "NO", NULL,
496 &wPreferences.attract, getBool, NULL, NULL, NULL},
497 {"DisableBlinking", "NO", NULL,
498 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
499 {"SingleClickLaunch", "NO", NULL,
500 &wPreferences.single_click, getBool, NULL, NULL, NULL},
501 {"StrictWindozeCycle", "YES", NULL,
502 &wPreferences.strict_windoze_cycle, getBool, NULL, NULL, NULL},
503 {"SwitchPanelOnlyOpen", "NO", NULL,
504 &wPreferences.panel_only_open, getBool, NULL, NULL, NULL},
505 {"ApercuSize", "128", NULL,
506 &wPreferences.apercu_size, getInt, NULL, NULL, NULL},
508 /* style options */
510 {"MenuStyle", "normal", seMenuStyles,
511 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
512 {"WidgetColor", "(solid, gray)", NULL,
513 NULL, getTexture, setWidgetColor, NULL, NULL},
514 {"WorkspaceSpecificBack", "()", NULL,
515 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
516 /* WorkspaceBack must come after WorkspaceSpecificBack or
517 * WorkspaceBack wont know WorkspaceSpecificBack was also
518 * specified and 2 copies of wmsetbg will be launched */
519 {"WorkspaceBack", "(solid, black)", NULL,
520 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
521 {"SmoothWorkspaceBack", "NO", NULL,
522 NULL, getBool, NULL, NULL, NULL},
523 {"IconBack", "(solid, gray)", NULL,
524 NULL, getTexture, setIconTile, NULL, NULL},
525 {"TitleJustify", "center", seJustifications,
526 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
527 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
528 NULL, getFont, setWinTitleFont, NULL, NULL},
529 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
530 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
531 {"WindowTitleMinHeight", "0", NULL,
532 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
533 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
534 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
535 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
536 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
537 {"MenuTitleMinHeight", "0", NULL,
538 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
539 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
540 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
541 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
542 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
543 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
544 NULL, getFont, setMenuTitleFont, NULL, NULL},
545 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
546 NULL, getFont, setMenuTextFont, NULL, NULL},
547 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
548 NULL, getFont, setIconTitleFont, NULL, NULL},
549 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
550 NULL, getFont, setClipTitleFont, NULL, NULL},
551 {"ShowClipTitle", "YES", NULL,
552 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
553 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
554 NULL, getFont, setLargeDisplayFont, NULL, NULL},
555 {"HighlightColor", "white", NULL,
556 NULL, getColor, setHightlight, NULL, NULL},
557 {"HighlightTextColor", "black", NULL,
558 NULL, getColor, setHightlightText, NULL, NULL},
559 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
560 NULL, getColor, setClipTitleColor, NULL, NULL},
561 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
562 NULL, getColor, setClipTitleColor, NULL, NULL},
563 {"FTitleColor", "white", (void *)WS_FOCUSED,
564 NULL, getColor, setWTitleColor, NULL, NULL},
565 {"PTitleColor", "white", (void *)WS_PFOCUSED,
566 NULL, getColor, setWTitleColor, NULL, NULL},
567 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
568 NULL, getColor, setWTitleColor, NULL, NULL},
569 {"FTitleBack", "(solid, black)", NULL,
570 NULL, getTexture, setFTitleBack, NULL, NULL},
571 {"PTitleBack", "(solid, \"#616161\")", NULL,
572 NULL, getTexture, setPTitleBack, NULL, NULL},
573 {"UTitleBack", "(solid, gray)", NULL,
574 NULL, getTexture, setUTitleBack, NULL, NULL},
575 {"ResizebarBack", "(solid, gray)", NULL,
576 NULL, getTexture, setResizebarBack, NULL, NULL},
577 {"MenuTitleColor", "white", NULL,
578 NULL, getColor, setMenuTitleColor, NULL, NULL},
579 {"MenuTextColor", "black", NULL,
580 NULL, getColor, setMenuTextColor, NULL, NULL},
581 {"MenuDisabledColor", "\"#616161\"", NULL,
582 NULL, getColor, setMenuDisabledColor, NULL, NULL},
583 {"MenuTitleBack", "(solid, black)", NULL,
584 NULL, getTexture, setMenuTitleBack, NULL, NULL},
585 {"MenuTextBack", "(solid, gray)", NULL,
586 NULL, getTexture, setMenuTextBack, NULL, NULL},
587 {"IconTitleColor", "white", NULL,
588 NULL, getColor, setIconTitleColor, NULL, NULL},
589 {"IconTitleBack", "black", NULL,
590 NULL, getColor, setIconTitleBack, NULL, NULL},
591 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
592 NULL, getPropList, setSwPOptions, NULL, NULL},
593 {"ModifierKeyLabels", "(\"Shift+\", \"Control+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
594 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
595 {"FrameBorderWidth", "1", NULL,
596 NULL, getInt, setFrameBorderWidth, NULL, NULL},
597 {"FrameBorderColor", "black", NULL,
598 NULL, getColor, setFrameBorderColor, NULL, NULL},
599 {"FrameFocusedBorderColor", "black", NULL,
600 NULL, getColor, setFrameFocusedBorderColor, NULL, NULL},
601 {"FrameSelectedBorderColor", "white", NULL,
602 NULL, getColor, setFrameSelectedBorderColor, NULL, NULL},
604 /* keybindings */
606 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
607 NULL, getKeybind, setKeyGrab, NULL, NULL},
608 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
609 NULL, getKeybind, setKeyGrab, NULL, NULL},
610 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
611 NULL, getKeybind, setKeyGrab, NULL, NULL},
612 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
613 NULL, getKeybind, setKeyGrab, NULL, NULL},
614 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
615 NULL, getKeybind, setKeyGrab, NULL, NULL},
616 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
617 NULL, getKeybind, setKeyGrab, NULL, NULL},
618 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
619 NULL, getKeybind, setKeyGrab, NULL, NULL },
620 {"HideKey", "None", (void *)WKBD_HIDE,
621 NULL, getKeybind, setKeyGrab, NULL, NULL},
622 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
623 NULL, getKeybind, setKeyGrab, NULL, NULL},
624 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
625 NULL, getKeybind, setKeyGrab, NULL, NULL},
626 {"CloseKey", "None", (void *)WKBD_CLOSE,
627 NULL, getKeybind, setKeyGrab, NULL, NULL},
628 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
629 NULL, getKeybind, setKeyGrab, NULL, NULL},
630 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
631 NULL, getKeybind, setKeyGrab, NULL, NULL},
632 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
633 NULL, getKeybind, setKeyGrab, NULL, NULL},
634 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
635 NULL, getKeybind, setKeyGrab, NULL, NULL},
636 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
637 NULL, getKeybind, setKeyGrab, NULL, NULL},
638 {"THMaximizeKey", "None", (void*)WKBD_THMAXIMIZE,
639 NULL, getKeybind, setKeyGrab, NULL, NULL},
640 {"BHMaximizeKey", "None", (void*)WKBD_BHMAXIMIZE,
641 NULL, getKeybind, setKeyGrab, NULL, NULL},
642 {"LTCMaximizeKey", "None", (void*)WKBD_LTCMAXIMIZE,
643 NULL, getKeybind, setKeyGrab, NULL, NULL},
644 {"RTCMaximizeKey", "None", (void*)WKBD_RTCMAXIMIZE,
645 NULL, getKeybind, setKeyGrab, NULL, NULL},
646 {"LBCMaximizeKey", "None", (void*)WKBD_LBCMAXIMIZE,
647 NULL, getKeybind, setKeyGrab, NULL, NULL},
648 {"RBCMaximizeKey", "None", (void*)WKBD_RBCMAXIMIZE,
649 NULL, getKeybind, setKeyGrab, NULL, NULL},
650 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
651 NULL, getKeybind, setKeyGrab, NULL, NULL},
652 {"OmnipresentKey", "None", (void *)WKBD_OMNIPRESENT,
653 NULL, getKeybind, setKeyGrab, NULL, NULL},
654 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
655 NULL, getKeybind, setKeyGrab, NULL, NULL},
656 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
657 NULL, getKeybind, setKeyGrab, NULL, NULL},
658 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
659 NULL, getKeybind, setKeyGrab, NULL, NULL},
660 {"ShadeKey", "None", (void *)WKBD_SHADE,
661 NULL, getKeybind, setKeyGrab, NULL, NULL},
662 {"SelectKey", "None", (void *)WKBD_SELECT,
663 NULL, getKeybind, setKeyGrab, NULL, NULL},
664 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
665 NULL, getKeybind, setKeyGrab, NULL, NULL},
666 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
667 NULL, getKeybind, setKeyGrab, NULL, NULL},
668 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
669 NULL, getKeybind, setKeyGrab, NULL, NULL},
670 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
671 NULL, getKeybind, setKeyGrab, NULL, NULL},
672 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
673 NULL, getKeybind, setKeyGrab, NULL, NULL},
674 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
675 NULL, getKeybind, setKeyGrab, NULL, NULL},
676 {"LastWorkspaceKey", "None", (void *)WKBD_LASTWORKSPACE,
677 NULL, getKeybind, setKeyGrab, NULL, NULL},
678 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
679 NULL, getKeybind, setKeyGrab, NULL, NULL},
680 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
681 NULL, getKeybind, setKeyGrab, NULL, NULL},
682 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
683 NULL, getKeybind, setKeyGrab, NULL, NULL},
684 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
685 NULL, getKeybind, setKeyGrab, NULL, NULL},
686 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
687 NULL, getKeybind, setKeyGrab, NULL, NULL},
688 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
689 NULL, getKeybind, setKeyGrab, NULL, NULL},
690 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
691 NULL, getKeybind, setKeyGrab, NULL, NULL},
692 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
693 NULL, getKeybind, setKeyGrab, NULL, NULL},
694 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
695 NULL, getKeybind, setKeyGrab, NULL, NULL},
696 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
697 NULL, getKeybind, setKeyGrab, NULL, NULL},
698 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
699 NULL, getKeybind, setKeyGrab, NULL, NULL},
700 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
701 NULL, getKeybind, setKeyGrab, NULL, NULL},
702 {"MoveToWorkspace1Key", "None", (void *)WKBD_MOVE_WORKSPACE1,
703 NULL, getKeybind, setKeyGrab, NULL, NULL},
704 {"MoveToWorkspace2Key", "None", (void *)WKBD_MOVE_WORKSPACE2,
705 NULL, getKeybind, setKeyGrab, NULL, NULL},
706 {"MoveToWorkspace3Key", "None", (void *)WKBD_MOVE_WORKSPACE3,
707 NULL, getKeybind, setKeyGrab, NULL, NULL},
708 {"MoveToWorkspace4Key", "None", (void *)WKBD_MOVE_WORKSPACE4,
709 NULL, getKeybind, setKeyGrab, NULL, NULL},
710 {"MoveToWorkspace5Key", "None", (void *)WKBD_MOVE_WORKSPACE5,
711 NULL, getKeybind, setKeyGrab, NULL, NULL},
712 {"MoveToWorkspace6Key", "None", (void *)WKBD_MOVE_WORKSPACE6,
713 NULL, getKeybind, setKeyGrab, NULL, NULL},
714 {"MoveToWorkspace7Key", "None", (void *)WKBD_MOVE_WORKSPACE7,
715 NULL, getKeybind, setKeyGrab, NULL, NULL},
716 {"MoveToWorkspace8Key", "None", (void *)WKBD_MOVE_WORKSPACE8,
717 NULL, getKeybind, setKeyGrab, NULL, NULL},
718 {"MoveToWorkspace9Key", "None", (void *)WKBD_MOVE_WORKSPACE9,
719 NULL, getKeybind, setKeyGrab, NULL, NULL},
720 {"MoveToWorkspace10Key", "None", (void *)WKBD_MOVE_WORKSPACE10,
721 NULL, getKeybind, setKeyGrab, NULL, NULL},
722 {"MoveToNextWorkspaceKey", "None", (void *)WKBD_MOVE_NEXTWORKSPACE,
723 NULL, getKeybind, setKeyGrab, NULL, NULL},
724 {"MoveToPrevWorkspaceKey", "None", (void *)WKBD_MOVE_PREVWORKSPACE,
725 NULL, getKeybind, setKeyGrab, NULL, NULL},
726 {"MoveToLastWorkspaceKey", "None", (void *)WKBD_MOVE_LASTWORKSPACE,
727 NULL, getKeybind, setKeyGrab, NULL, NULL},
728 {"MoveToNextWorkspaceLayerKey", "None", (void *)WKBD_MOVE_NEXTWSLAYER,
729 NULL, getKeybind, setKeyGrab, NULL, NULL},
730 {"MoveToPrevWorkspaceLayerKey", "None", (void *)WKBD_MOVE_PREVWSLAYER,
731 NULL, getKeybind, setKeyGrab, NULL, NULL},
732 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
733 NULL, getKeybind, setKeyGrab, NULL, NULL},
734 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
735 NULL, getKeybind, setKeyGrab, NULL, NULL},
736 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
737 NULL, getKeybind, setKeyGrab, NULL, NULL},
738 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
739 NULL, getKeybind, setKeyGrab, NULL, NULL},
740 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
741 NULL, getKeybind, setKeyGrab, NULL, NULL},
742 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
743 NULL, getKeybind, setKeyGrab, NULL, NULL},
744 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
745 NULL, getKeybind, setKeyGrab, NULL, NULL},
746 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
747 NULL, getKeybind, setKeyGrab, NULL, NULL},
748 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
749 NULL, getKeybind, setKeyGrab, NULL, NULL},
750 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
751 NULL, getKeybind, setKeyGrab, NULL, NULL},
752 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
753 NULL, getKeybind, setKeyGrab, NULL, NULL},
754 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
755 NULL, getKeybind, setKeyGrab, NULL, NULL},
756 {"RunKey", "None", (void *)WKBD_RUN,
757 NULL, getKeybind, setKeyGrab, NULL, NULL},
759 #ifdef KEEP_XKB_LOCK_STATUS
760 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
761 NULL, getKeybind, setKeyGrab, NULL, NULL},
762 {"KbdModeLock", "NO", NULL,
763 &wPreferences.modelock, getBool, NULL, NULL, NULL},
764 #endif /* KEEP_XKB_LOCK_STATUS */
766 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
767 NULL, getCursor, setCursor, NULL, NULL},
768 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
769 NULL, getCursor, setCursor, NULL, NULL},
770 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
771 NULL, getCursor, setCursor, NULL, NULL},
772 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
773 NULL, getCursor, setCursor, NULL, NULL},
774 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
775 NULL, getCursor, setCursor, NULL, NULL},
776 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
777 NULL, getCursor, setCursor, NULL, NULL},
778 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
779 NULL, getCursor, setCursor, NULL, NULL},
780 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
781 NULL, getCursor, setCursor, NULL, NULL},
782 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
783 NULL, getCursor, setCursor, NULL, NULL},
784 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
785 NULL, getCursor, setCursor, NULL, NULL},
786 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
787 NULL, getCursor, setCursor, NULL, NULL},
788 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
789 NULL, getCursor, setCursor, NULL, NULL},
790 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
791 NULL, getCursor, setCursor, NULL, NULL},
792 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
793 NULL, getCursor, setCursor, NULL, NULL},
794 {"DialogHistoryLines", "500", NULL,
795 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
796 {"CycleActiveHeadOnly", "NO", NULL,
797 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL},
798 {"CycleIgnoreMinimized", "NO", NULL,
799 &wPreferences.cycle_ignore_minimized, getBool, NULL, NULL, NULL}
802 static void initDefaults(void)
804 unsigned int i;
805 WDefaultEntry *entry;
807 WMPLSetCaseSensitive(False);
809 for (i = 0; i < wlengthof(optionList); i++) {
810 entry = &optionList[i];
812 entry->plkey = WMCreatePLString(entry->key);
813 if (entry->default_value)
814 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
815 else
816 entry->plvalue = NULL;
819 for (i = 0; i < wlengthof(staticOptionList); i++) {
820 entry = &staticOptionList[i];
822 entry->plkey = WMCreatePLString(entry->key);
823 if (entry->default_value)
824 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
825 else
826 entry->plvalue = NULL;
830 static WMPropList *readGlobalDomain(const char *domainName, Bool requireDictionary)
832 WMPropList *globalDict = NULL;
833 char path[PATH_MAX];
834 struct stat stbuf;
836 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
837 if (stat(path, &stbuf) >= 0) {
838 globalDict = WMReadPropListFromFile(path);
839 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
840 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
841 WMReleasePropList(globalDict);
842 globalDict = NULL;
843 } else if (!globalDict) {
844 wwarning(_("could not load domain %s from global defaults database"), domainName);
848 return globalDict;
851 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
852 static void prependMenu(WMPropList * destarr, WMPropList * array)
854 WMPropList *item;
855 int i;
857 for (i = 0; i < WMGetPropListItemCount(array); i++) {
858 item = WMGetFromPLArray(array, i);
859 if (item)
860 WMInsertInPLArray(destarr, i + 1, item);
864 static void appendMenu(WMPropList * destarr, WMPropList * array)
866 WMPropList *item;
867 int i;
869 for (i = 0; i < WMGetPropListItemCount(array); i++) {
870 item = WMGetFromPLArray(array, i);
871 if (item)
872 WMAddToPLArray(destarr, item);
875 #endif
877 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
879 WMPropList *menu = menuDomain->dictionary;
880 WMPropList *submenu;
882 if (!menu || !WMIsPLArray(menu))
883 return;
885 #ifdef GLOBAL_PREAMBLE_MENU_FILE
886 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
888 if (submenu && !WMIsPLArray(submenu)) {
889 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
890 WMReleasePropList(submenu);
891 submenu = NULL;
893 if (submenu) {
894 prependMenu(menu, submenu);
895 WMReleasePropList(submenu);
897 #endif
899 #ifdef GLOBAL_EPILOGUE_MENU_FILE
900 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
902 if (submenu && !WMIsPLArray(submenu)) {
903 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
904 WMReleasePropList(submenu);
905 submenu = NULL;
907 if (submenu) {
908 appendMenu(menu, submenu);
909 WMReleasePropList(submenu);
911 #endif
913 menuDomain->dictionary = menu;
916 WDDomain *wDefaultsInitDomain(const char *domain, Bool requireDictionary)
918 WDDomain *db;
919 struct stat stbuf;
920 static int inited = 0;
921 WMPropList *shared_dict = NULL;
923 if (!inited) {
924 inited = 1;
925 initDefaults();
928 db = wmalloc(sizeof(WDDomain));
929 db->domain_name = domain;
930 db->path = wdefaultspathfordomain(domain);
932 if (stat(db->path, &stbuf) >= 0) {
933 db->dictionary = WMReadPropListFromFile(db->path);
934 if (db->dictionary) {
935 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
936 WMReleasePropList(db->dictionary);
937 db->dictionary = NULL;
938 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, db->path);
940 db->timestamp = stbuf.st_mtime;
941 } else {
942 wwarning(_("could not load domain %s from user defaults database"), domain);
946 /* global system dictionary */
947 shared_dict = readGlobalDomain(domain, requireDictionary);
949 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
950 WMIsPLDictionary(db->dictionary)) {
951 WMMergePLDictionaries(shared_dict, db->dictionary, True);
952 WMReleasePropList(db->dictionary);
953 db->dictionary = shared_dict;
954 if (stbuf.st_mtime > db->timestamp)
955 db->timestamp = stbuf.st_mtime;
956 } else if (!db->dictionary) {
957 db->dictionary = shared_dict;
958 if (stbuf.st_mtime > db->timestamp)
959 db->timestamp = stbuf.st_mtime;
962 return db;
965 void wReadStaticDefaults(WMPropList * dict)
967 WMPropList *plvalue;
968 WDefaultEntry *entry;
969 unsigned int i;
970 void *tdata;
972 for (i = 0; i < wlengthof(staticOptionList); i++) {
973 entry = &staticOptionList[i];
975 if (dict)
976 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
977 else
978 plvalue = NULL;
980 /* no default in the DB. Use builtin default */
981 if (!plvalue)
982 plvalue = entry->plvalue;
984 if (plvalue) {
985 /* convert data */
986 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
987 if (entry->update)
988 (*entry->update) (NULL, entry, tdata, entry->extra_data);
993 void wDefaultsCheckDomains(void* arg)
995 WScreen *scr;
996 struct stat stbuf;
997 WMPropList *shared_dict = NULL;
998 WMPropList *dict;
999 int i;
1001 /* Parameter not used, but tell the compiler that it is ok */
1002 (void) arg;
1004 if (stat(w_global.domain.wmaker->path, &stbuf) >= 0 && w_global.domain.wmaker->timestamp < stbuf.st_mtime) {
1005 w_global.domain.wmaker->timestamp = stbuf.st_mtime;
1007 /* Global dictionary */
1008 shared_dict = readGlobalDomain("WindowMaker", True);
1010 /* User dictionary */
1011 dict = WMReadPropListFromFile(w_global.domain.wmaker->path);
1013 if (dict) {
1014 if (!WMIsPLDictionary(dict)) {
1015 WMReleasePropList(dict);
1016 dict = NULL;
1017 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1018 "WindowMaker", w_global.domain.wmaker->path);
1019 } else {
1020 if (shared_dict) {
1021 WMMergePLDictionaries(shared_dict, dict, True);
1022 WMReleasePropList(dict);
1023 dict = shared_dict;
1024 shared_dict = NULL;
1027 for (i = 0; i < w_global.screen_count; i++) {
1028 scr = wScreenWithNumber(i);
1029 if (scr)
1030 wReadDefaults(scr, dict);
1033 if (w_global.domain.wmaker->dictionary)
1034 WMReleasePropList(w_global.domain.wmaker->dictionary);
1036 w_global.domain.wmaker->dictionary = dict;
1038 } else {
1039 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1042 if (shared_dict)
1043 WMReleasePropList(shared_dict);
1047 if (stat(w_global.domain.window_attr->path, &stbuf) >= 0 && w_global.domain.window_attr->timestamp < stbuf.st_mtime) {
1048 /* global dictionary */
1049 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1050 /* user dictionary */
1051 dict = WMReadPropListFromFile(w_global.domain.window_attr->path);
1052 if (dict) {
1053 if (!WMIsPLDictionary(dict)) {
1054 WMReleasePropList(dict);
1055 dict = NULL;
1056 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1057 "WMWindowAttributes", w_global.domain.window_attr->path);
1058 } else {
1059 if (shared_dict) {
1060 WMMergePLDictionaries(shared_dict, dict, True);
1061 WMReleasePropList(dict);
1062 dict = shared_dict;
1063 shared_dict = NULL;
1066 if (w_global.domain.window_attr->dictionary)
1067 WMReleasePropList(w_global.domain.window_attr->dictionary);
1069 w_global.domain.window_attr->dictionary = dict;
1070 for (i = 0; i < w_global.screen_count; i++) {
1071 scr = wScreenWithNumber(i);
1072 if (scr) {
1073 wDefaultUpdateIcons(scr);
1075 /* Update the panel image if changed */
1076 /* Don't worry. If the image is the same these
1077 * functions will have no performance impact. */
1078 create_logo_image(scr);
1082 } else {
1083 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1086 w_global.domain.window_attr->timestamp = stbuf.st_mtime;
1087 if (shared_dict)
1088 WMReleasePropList(shared_dict);
1091 if (stat(w_global.domain.root_menu->path, &stbuf) >= 0 && w_global.domain.root_menu->timestamp < stbuf.st_mtime) {
1092 dict = WMReadPropListFromFile(w_global.domain.root_menu->path);
1093 if (dict) {
1094 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1095 WMReleasePropList(dict);
1096 dict = NULL;
1097 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1098 "WMRootMenu", w_global.domain.root_menu->path);
1099 } else {
1100 if (w_global.domain.root_menu->dictionary)
1101 WMReleasePropList(w_global.domain.root_menu->dictionary);
1103 w_global.domain.root_menu->dictionary = dict;
1104 wDefaultsMergeGlobalMenus(w_global.domain.root_menu);
1106 } else {
1107 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1109 w_global.domain.root_menu->timestamp = stbuf.st_mtime;
1111 #ifndef HAVE_INOTIFY
1112 if (!arg)
1113 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1114 #endif
1117 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1119 WMPropList *plvalue, *old_value;
1120 WDefaultEntry *entry;
1121 unsigned int i;
1122 int update_workspace_back = 0; /* kluge :/ */
1123 unsigned int needs_refresh;
1124 void *tdata;
1125 WMPropList *old_dict = (w_global.domain.wmaker->dictionary != new_dict ? w_global.domain.wmaker->dictionary : NULL);
1127 needs_refresh = 0;
1129 for (i = 0; i < wlengthof(optionList); i++) {
1130 entry = &optionList[i];
1132 if (new_dict)
1133 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1134 else
1135 plvalue = NULL;
1137 if (!old_dict)
1138 old_value = NULL;
1139 else
1140 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1142 if (!plvalue && !old_value) {
1143 /* no default in the DB. Use builtin default */
1144 plvalue = entry->plvalue;
1145 if (plvalue && new_dict)
1146 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1148 } else if (!plvalue) {
1149 /* value was deleted from DB. Keep current value */
1150 continue;
1151 } else if (!old_value) {
1152 /* set value for the 1st time */
1153 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1154 /* value has changed */
1155 } else {
1156 if (strcmp(entry->key, "WorkspaceBack") == 0
1157 && update_workspace_back && scr->flags.backimage_helper_launched) {
1158 } else {
1159 /* value was not changed since last time */
1160 continue;
1164 if (plvalue) {
1165 /* convert data */
1166 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1168 * If the WorkspaceSpecificBack data has been changed
1169 * so that the helper will be launched now, we must be
1170 * sure to send the default background texture config
1171 * to the helper.
1173 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1174 !scr->flags.backimage_helper_launched)
1175 update_workspace_back = 1;
1177 if (entry->update)
1178 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1185 * Backward Compatibility:
1186 * the option 'apercu_size' used to be coded as a multiple of the icon size in v0.95.6
1187 * it is now expressed directly in pixels, but to avoid breaking user's setting we check
1188 * for old coding and convert it now.
1189 * This code should probably stay for at least 2 years, you should not consider removing
1190 * it before year 2017
1192 if (wPreferences.apercu_size < 24) {
1193 /* 24 is the minimum icon size proposed in WPref's settings */
1194 wPreferences.apercu_size *= wPreferences.icon_size;
1195 if (wPreferences.miniwin_apercu_balloon)
1196 wwarning(_("your ApercuSize setting is using old syntax, it is converted to %d pixels; consider running WPrefs.app to update your settings"),
1197 wPreferences.apercu_size);
1200 if (needs_refresh != 0 && !scr->flags.startup) {
1201 int foo;
1203 foo = 0;
1204 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1205 foo |= WTextureSettings;
1206 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1207 foo |= WFontSettings;
1208 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1209 foo |= WColorSettings;
1210 if (foo)
1211 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1212 (void *)(uintptr_t) foo);
1214 foo = 0;
1215 if (needs_refresh & REFRESH_MENU_TEXTURE)
1216 foo |= WTextureSettings;
1217 if (needs_refresh & REFRESH_MENU_FONT)
1218 foo |= WFontSettings;
1219 if (needs_refresh & REFRESH_MENU_COLOR)
1220 foo |= WColorSettings;
1221 if (foo)
1222 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1224 foo = 0;
1225 if (needs_refresh & REFRESH_WINDOW_FONT)
1226 foo |= WFontSettings;
1227 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1228 foo |= WTextureSettings;
1229 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1230 foo |= WColorSettings;
1231 if (foo)
1232 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1234 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1235 foo = 0;
1236 if (needs_refresh & REFRESH_ICON_FONT)
1237 foo |= WFontSettings;
1238 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1239 foo |= WTextureSettings;
1240 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1241 foo |= WTextureSettings;
1242 if (foo)
1243 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1244 (void *)(uintptr_t) foo);
1246 if (needs_refresh & REFRESH_ICON_TILE)
1247 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1249 if (needs_refresh & REFRESH_WORKSPACE_MENU) {
1250 if (scr->workspace_menu)
1251 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
1252 if (scr->clip_ws_menu)
1253 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
1254 if (scr->workspace_submenu)
1255 scr->workspace_submenu->flags.realized = 0;
1256 if (scr->clip_submenu)
1257 scr->clip_submenu->flags.realized = 0;
1262 void wDefaultUpdateIcons(WScreen *scr)
1264 WAppIcon *aicon = scr->app_icon_list;
1265 WDrawerChain *dc;
1266 WWindow *wwin = scr->focused_window;
1268 while (aicon) {
1269 /* Get the application icon, default included */
1270 wIconChangeImageFile(aicon->icon, NULL);
1271 wAppIconPaint(aicon);
1272 aicon = aicon->next;
1275 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock)
1276 wClipIconPaint(scr->clip_icon);
1278 for (dc = scr->drawers; dc != NULL; dc = dc->next)
1279 wDrawerIconPaint(dc->adrawer->icon_array[0]);
1281 while (wwin) {
1282 if (wwin->icon && wwin->flags.miniaturized)
1283 wIconChangeImageFile(wwin->icon, NULL);
1284 wwin = wwin->prev;
1288 /* --------------------------- Local ----------------------- */
1290 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1291 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1292 entry->key, x); \
1293 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1294 var = entry->default_value;\
1295 } else var = WMGetFromPLString(value)\
1298 static int string2index(WMPropList *key, WMPropList *val, const char *def, WOptionEnumeration * values)
1300 char *str;
1301 WOptionEnumeration *v;
1302 char buffer[TOTAL_VALUES_LENGTH];
1304 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1305 for (v = values; v->string != NULL; v++) {
1306 if (strcasecmp(v->string, str) == 0)
1307 return v->value;
1311 buffer[0] = 0;
1312 for (v = values; v->string != NULL; v++) {
1313 if (!v->is_alias) {
1314 if (buffer[0] != 0)
1315 strcat(buffer, ", ");
1316 snprintf(buffer+strlen(buffer),
1317 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1320 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1321 WMGetFromPLString(key),
1322 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1323 buffer);
1325 if (def) {
1326 return string2index(key, val, NULL, values);
1329 return -1;
1333 * value - is the value in the defaults DB
1334 * addr - is the address to store the data
1335 * ret - is the address to store a pointer to a temporary buffer. ret
1336 * must not be freed and is used by the set functions
1338 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1340 static char data;
1341 const char *val;
1342 int second_pass = 0;
1344 /* Parameter not used, but tell the compiler that it is ok */
1345 (void) scr;
1347 GET_STRING_OR_DEFAULT("Boolean", val);
1349 again:
1350 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1351 || strcasecmp(val, "YES") == 0) {
1353 data = 1;
1354 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1355 || strcasecmp(val, "NO") == 0) {
1356 data = 0;
1357 } else {
1358 int i;
1359 if (sscanf(val, "%i", &i) == 1) {
1360 if (i != 0)
1361 data = 1;
1362 else
1363 data = 0;
1364 } else {
1365 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1366 if (second_pass == 0) {
1367 val = WMGetFromPLString(entry->plvalue);
1368 second_pass = 1;
1369 wwarning(_("using default \"%s\" instead"), val);
1370 goto again;
1372 return False;
1376 if (ret)
1377 *ret = &data;
1378 if (addr)
1379 *(char *)addr = data;
1381 return True;
1384 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1386 static int data;
1387 const char *val;
1389 /* Parameter not used, but tell the compiler that it is ok */
1390 (void) scr;
1392 GET_STRING_OR_DEFAULT("Integer", val);
1394 if (sscanf(val, "%i", &data) != 1) {
1395 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1396 val = WMGetFromPLString(entry->plvalue);
1397 wwarning(_("using default \"%s\" instead"), val);
1398 if (sscanf(val, "%i", &data) != 1) {
1399 return False;
1403 if (ret)
1404 *ret = &data;
1405 if (addr)
1406 *(int *)addr = data;
1408 return True;
1411 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1413 static WCoord data;
1414 char *val_x, *val_y;
1415 int nelem, changed = 0;
1416 WMPropList *elem_x, *elem_y;
1418 again:
1419 if (!WMIsPLArray(value)) {
1420 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1421 if (changed == 0) {
1422 value = entry->plvalue;
1423 changed = 1;
1424 wwarning(_("using default \"%s\" instead"), entry->default_value);
1425 goto again;
1427 return False;
1430 nelem = WMGetPropListItemCount(value);
1431 if (nelem != 2) {
1432 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1433 if (changed == 0) {
1434 value = entry->plvalue;
1435 changed = 1;
1436 wwarning(_("using default \"%s\" instead"), entry->default_value);
1437 goto again;
1439 return False;
1442 elem_x = WMGetFromPLArray(value, 0);
1443 elem_y = WMGetFromPLArray(value, 1);
1445 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1446 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1447 if (changed == 0) {
1448 value = entry->plvalue;
1449 changed = 1;
1450 wwarning(_("using default \"%s\" instead"), entry->default_value);
1451 goto again;
1453 return False;
1456 val_x = WMGetFromPLString(elem_x);
1457 val_y = WMGetFromPLString(elem_y);
1459 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1460 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1461 if (changed == 0) {
1462 value = entry->plvalue;
1463 changed = 1;
1464 wwarning(_("using default \"%s\" instead"), entry->default_value);
1465 goto again;
1467 return False;
1470 if (data.x < 0)
1471 data.x = 0;
1472 else if (data.x > scr->scr_width / 3)
1473 data.x = scr->scr_width / 3;
1474 if (data.y < 0)
1475 data.y = 0;
1476 else if (data.y > scr->scr_height / 3)
1477 data.y = scr->scr_height / 3;
1479 if (ret)
1480 *ret = &data;
1481 if (addr)
1482 *(WCoord *) addr = data;
1484 return True;
1487 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1489 /* Parameter not used, but tell the compiler that it is ok */
1490 (void) scr;
1491 (void) entry;
1492 (void) addr;
1494 WMRetainPropList(value);
1496 *ret = value;
1498 return True;
1501 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1503 static char *data;
1504 int i, count, len;
1505 char *ptr;
1506 WMPropList *d;
1507 int changed = 0;
1509 /* Parameter not used, but tell the compiler that it is ok */
1510 (void) scr;
1511 (void) ret;
1513 again:
1514 if (!WMIsPLArray(value)) {
1515 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1516 if (changed == 0) {
1517 value = entry->plvalue;
1518 changed = 1;
1519 wwarning(_("using default \"%s\" instead"), entry->default_value);
1520 goto again;
1522 return False;
1525 i = 0;
1526 count = WMGetPropListItemCount(value);
1527 if (count < 1) {
1528 if (changed == 0) {
1529 value = entry->plvalue;
1530 changed = 1;
1531 wwarning(_("using default \"%s\" instead"), entry->default_value);
1532 goto again;
1534 return False;
1537 len = 0;
1538 for (i = 0; i < count; i++) {
1539 d = WMGetFromPLArray(value, i);
1540 if (!d || !WMIsPLString(d)) {
1541 count = i;
1542 break;
1544 len += strlen(WMGetFromPLString(d)) + 1;
1547 ptr = data = wmalloc(len + 1);
1549 for (i = 0; i < count; i++) {
1550 d = WMGetFromPLArray(value, i);
1551 if (!d || !WMIsPLString(d)) {
1552 break;
1554 strcpy(ptr, WMGetFromPLString(d));
1555 ptr += strlen(WMGetFromPLString(d));
1556 *ptr = ':';
1557 ptr++;
1559 ptr--;
1560 *(ptr--) = 0;
1562 if (*(char **)addr != NULL) {
1563 wfree(*(char **)addr);
1565 *(char **)addr = data;
1567 return True;
1570 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1572 static signed char data;
1574 /* Parameter not used, but tell the compiler that it is ok */
1575 (void) scr;
1577 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1578 if (data < 0)
1579 return False;
1581 if (ret)
1582 *ret = &data;
1583 if (addr)
1584 *(signed char *)addr = data;
1586 return True;
1590 * (solid <color>)
1591 * (hgradient <color> <color>)
1592 * (vgradient <color> <color>)
1593 * (dgradient <color> <color>)
1594 * (mhgradient <color> <color> ...)
1595 * (mvgradient <color> <color> ...)
1596 * (mdgradient <color> <color> ...)
1597 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1598 * (tpixmap <file> <color>)
1599 * (spixmap <file> <color>)
1600 * (cpixmap <file> <color>)
1601 * (thgradient <file> <opaqueness> <color> <color>)
1602 * (tvgradient <file> <opaqueness> <color> <color>)
1603 * (tdgradient <file> <opaqueness> <color> <color>)
1604 * (function <lib> <function> ...)
1607 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1609 WMPropList *elem;
1610 char *val;
1611 int nelem;
1612 WTexture *texture = NULL;
1614 nelem = WMGetPropListItemCount(pl);
1615 if (nelem < 1)
1616 return NULL;
1618 elem = WMGetFromPLArray(pl, 0);
1619 if (!elem || !WMIsPLString(elem))
1620 return NULL;
1621 val = WMGetFromPLString(elem);
1623 if (strcasecmp(val, "solid") == 0) {
1624 XColor color;
1626 if (nelem != 2)
1627 return NULL;
1629 /* get color */
1631 elem = WMGetFromPLArray(pl, 1);
1632 if (!elem || !WMIsPLString(elem))
1633 return NULL;
1634 val = WMGetFromPLString(elem);
1636 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1637 wwarning(_("\"%s\" is not a valid color name"), val);
1638 return NULL;
1641 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1642 } else if (strcasecmp(val, "dgradient") == 0
1643 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1644 RColor color1, color2;
1645 XColor xcolor;
1646 int type;
1648 if (nelem != 3) {
1649 wwarning(_("bad number of arguments in gradient specification"));
1650 return NULL;
1653 if (val[0] == 'd' || val[0] == 'D')
1654 type = WTEX_DGRADIENT;
1655 else if (val[0] == 'h' || val[0] == 'H')
1656 type = WTEX_HGRADIENT;
1657 else
1658 type = WTEX_VGRADIENT;
1660 /* get from color */
1661 elem = WMGetFromPLArray(pl, 1);
1662 if (!elem || !WMIsPLString(elem))
1663 return NULL;
1664 val = WMGetFromPLString(elem);
1666 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1667 wwarning(_("\"%s\" is not a valid color name"), val);
1668 return NULL;
1670 color1.alpha = 255;
1671 color1.red = xcolor.red >> 8;
1672 color1.green = xcolor.green >> 8;
1673 color1.blue = xcolor.blue >> 8;
1675 /* get to color */
1676 elem = WMGetFromPLArray(pl, 2);
1677 if (!elem || !WMIsPLString(elem)) {
1678 return NULL;
1680 val = WMGetFromPLString(elem);
1682 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1683 wwarning(_("\"%s\" is not a valid color name"), val);
1684 return NULL;
1686 color2.alpha = 255;
1687 color2.red = xcolor.red >> 8;
1688 color2.green = xcolor.green >> 8;
1689 color2.blue = xcolor.blue >> 8;
1691 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1693 } else if (strcasecmp(val, "igradient") == 0) {
1694 RColor colors1[2], colors2[2];
1695 int th1, th2;
1696 XColor xcolor;
1697 int i;
1699 if (nelem != 7) {
1700 wwarning(_("bad number of arguments in gradient specification"));
1701 return NULL;
1704 /* get from color */
1705 for (i = 0; i < 2; i++) {
1706 elem = WMGetFromPLArray(pl, 1 + i);
1707 if (!elem || !WMIsPLString(elem))
1708 return NULL;
1709 val = WMGetFromPLString(elem);
1711 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1712 wwarning(_("\"%s\" is not a valid color name"), val);
1713 return NULL;
1715 colors1[i].alpha = 255;
1716 colors1[i].red = xcolor.red >> 8;
1717 colors1[i].green = xcolor.green >> 8;
1718 colors1[i].blue = xcolor.blue >> 8;
1720 elem = WMGetFromPLArray(pl, 3);
1721 if (!elem || !WMIsPLString(elem))
1722 return NULL;
1723 val = WMGetFromPLString(elem);
1724 th1 = atoi(val);
1726 /* get from color */
1727 for (i = 0; i < 2; i++) {
1728 elem = WMGetFromPLArray(pl, 4 + i);
1729 if (!elem || !WMIsPLString(elem))
1730 return NULL;
1731 val = WMGetFromPLString(elem);
1733 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1734 wwarning(_("\"%s\" is not a valid color name"), val);
1735 return NULL;
1737 colors2[i].alpha = 255;
1738 colors2[i].red = xcolor.red >> 8;
1739 colors2[i].green = xcolor.green >> 8;
1740 colors2[i].blue = xcolor.blue >> 8;
1742 elem = WMGetFromPLArray(pl, 6);
1743 if (!elem || !WMIsPLString(elem))
1744 return NULL;
1745 val = WMGetFromPLString(elem);
1746 th2 = atoi(val);
1748 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1750 } else if (strcasecmp(val, "mhgradient") == 0
1751 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1752 XColor color;
1753 RColor **colors;
1754 int i, count;
1755 int type;
1757 if (nelem < 3) {
1758 wwarning(_("too few arguments in multicolor gradient specification"));
1759 return NULL;
1762 if (val[1] == 'h' || val[1] == 'H')
1763 type = WTEX_MHGRADIENT;
1764 else if (val[1] == 'v' || val[1] == 'V')
1765 type = WTEX_MVGRADIENT;
1766 else
1767 type = WTEX_MDGRADIENT;
1769 count = nelem - 1;
1771 colors = wmalloc(sizeof(RColor *) * (count + 1));
1773 for (i = 0; i < count; i++) {
1774 elem = WMGetFromPLArray(pl, i + 1);
1775 if (!elem || !WMIsPLString(elem)) {
1776 for (--i; i >= 0; --i) {
1777 wfree(colors[i]);
1779 wfree(colors);
1780 return NULL;
1782 val = WMGetFromPLString(elem);
1784 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1785 wwarning(_("\"%s\" is not a valid color name"), val);
1786 for (--i; i >= 0; --i) {
1787 wfree(colors[i]);
1789 wfree(colors);
1790 return NULL;
1791 } else {
1792 colors[i] = wmalloc(sizeof(RColor));
1793 colors[i]->red = color.red >> 8;
1794 colors[i]->green = color.green >> 8;
1795 colors[i]->blue = color.blue >> 8;
1798 colors[i] = NULL;
1800 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1801 } else if (strcasecmp(val, "spixmap") == 0 ||
1802 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1803 XColor color;
1804 int type;
1806 if (nelem != 3)
1807 return NULL;
1809 if (val[0] == 's' || val[0] == 'S')
1810 type = WTP_SCALE;
1811 else if (val[0] == 'c' || val[0] == 'C')
1812 type = WTP_CENTER;
1813 else
1814 type = WTP_TILE;
1816 /* get color */
1817 elem = WMGetFromPLArray(pl, 2);
1818 if (!elem || !WMIsPLString(elem)) {
1819 return NULL;
1821 val = WMGetFromPLString(elem);
1823 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1824 wwarning(_("\"%s\" is not a valid color name"), val);
1825 return NULL;
1828 /* file name */
1829 elem = WMGetFromPLArray(pl, 1);
1830 if (!elem || !WMIsPLString(elem))
1831 return NULL;
1832 val = WMGetFromPLString(elem);
1834 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1835 } else if (strcasecmp(val, "thgradient") == 0
1836 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1837 RColor color1, color2;
1838 XColor xcolor;
1839 int opacity;
1840 int style;
1842 if (val[1] == 'h' || val[1] == 'H')
1843 style = WTEX_THGRADIENT;
1844 else if (val[1] == 'v' || val[1] == 'V')
1845 style = WTEX_TVGRADIENT;
1846 else
1847 style = WTEX_TDGRADIENT;
1849 if (nelem != 5) {
1850 wwarning(_("bad number of arguments in textured gradient specification"));
1851 return NULL;
1854 /* get from color */
1855 elem = WMGetFromPLArray(pl, 3);
1856 if (!elem || !WMIsPLString(elem))
1857 return NULL;
1858 val = WMGetFromPLString(elem);
1860 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1861 wwarning(_("\"%s\" is not a valid color name"), val);
1862 return NULL;
1864 color1.alpha = 255;
1865 color1.red = xcolor.red >> 8;
1866 color1.green = xcolor.green >> 8;
1867 color1.blue = xcolor.blue >> 8;
1869 /* get to color */
1870 elem = WMGetFromPLArray(pl, 4);
1871 if (!elem || !WMIsPLString(elem)) {
1872 return NULL;
1874 val = WMGetFromPLString(elem);
1876 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1877 wwarning(_("\"%s\" is not a valid color name"), val);
1878 return NULL;
1880 color2.alpha = 255;
1881 color2.red = xcolor.red >> 8;
1882 color2.green = xcolor.green >> 8;
1883 color2.blue = xcolor.blue >> 8;
1885 /* get opacity */
1886 elem = WMGetFromPLArray(pl, 2);
1887 if (!elem || !WMIsPLString(elem))
1888 opacity = 128;
1889 else
1890 val = WMGetFromPLString(elem);
1892 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1893 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1894 opacity = 128;
1897 /* get file name */
1898 elem = WMGetFromPLArray(pl, 1);
1899 if (!elem || !WMIsPLString(elem))
1900 return NULL;
1901 val = WMGetFromPLString(elem);
1903 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1904 } else if (strcasecmp(val, "function") == 0) {
1905 /* Leave this in to handle the unlikely case of
1906 * someone actually having function textures configured */
1907 wwarning("function texture support has been removed");
1908 return NULL;
1909 } else {
1910 wwarning(_("invalid texture type %s"), val);
1911 return NULL;
1913 return texture;
1916 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1918 static WTexture *texture;
1919 int changed = 0;
1921 again:
1922 if (!WMIsPLArray(value)) {
1923 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1924 if (changed == 0) {
1925 value = entry->plvalue;
1926 changed = 1;
1927 wwarning(_("using default \"%s\" instead"), entry->default_value);
1928 goto again;
1930 return False;
1933 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1934 WMPropList *pl;
1936 pl = WMGetFromPLArray(value, 0);
1937 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1938 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1939 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1940 entry->key, "Solid Texture");
1942 value = entry->plvalue;
1943 changed = 1;
1944 wwarning(_("using default \"%s\" instead"), entry->default_value);
1945 goto again;
1949 texture = parse_texture(scr, value);
1951 if (!texture) {
1952 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1953 if (changed == 0) {
1954 value = entry->plvalue;
1955 changed = 1;
1956 wwarning(_("using default \"%s\" instead"), entry->default_value);
1957 goto again;
1959 return False;
1962 if (ret)
1963 *ret = &texture;
1965 if (addr)
1966 *(WTexture **) addr = texture;
1968 return True;
1971 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1973 WMPropList *elem;
1974 int changed = 0;
1975 char *val;
1976 int nelem;
1978 /* Parameter not used, but tell the compiler that it is ok */
1979 (void) scr;
1980 (void) addr;
1982 again:
1983 if (!WMIsPLArray(value)) {
1984 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1985 "WorkspaceBack", "Texture or None");
1986 if (changed == 0) {
1987 value = entry->plvalue;
1988 changed = 1;
1989 wwarning(_("using default \"%s\" instead"), entry->default_value);
1990 goto again;
1992 return False;
1995 /* only do basic error checking and verify for None texture */
1997 nelem = WMGetPropListItemCount(value);
1998 if (nelem > 0) {
1999 elem = WMGetFromPLArray(value, 0);
2000 if (!elem || !WMIsPLString(elem)) {
2001 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2002 if (changed == 0) {
2003 value = entry->plvalue;
2004 changed = 1;
2005 wwarning(_("using default \"%s\" instead"), entry->default_value);
2006 goto again;
2008 return False;
2010 val = WMGetFromPLString(elem);
2012 if (strcasecmp(val, "None") == 0)
2013 return True;
2015 *ret = WMRetainPropList(value);
2017 return True;
2020 static int
2021 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2023 WMPropList *elem;
2024 int nelem;
2025 int changed = 0;
2027 /* Parameter not used, but tell the compiler that it is ok */
2028 (void) scr;
2029 (void) addr;
2031 again:
2032 if (!WMIsPLArray(value)) {
2033 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2034 "WorkspaceSpecificBack", "an array of textures");
2035 if (changed == 0) {
2036 value = entry->plvalue;
2037 changed = 1;
2038 wwarning(_("using default \"%s\" instead"), entry->default_value);
2039 goto again;
2041 return False;
2044 /* only do basic error checking and verify for None texture */
2046 nelem = WMGetPropListItemCount(value);
2047 if (nelem > 0) {
2048 while (nelem--) {
2049 elem = WMGetFromPLArray(value, nelem);
2050 if (!elem || !WMIsPLArray(elem)) {
2051 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2052 nelem);
2057 *ret = WMRetainPropList(value);
2059 #ifdef notworking
2061 * Kluge to force wmsetbg helper to set the default background.
2062 * If the WorkspaceSpecificBack is changed once wmaker has started,
2063 * the WorkspaceBack won't be sent to the helper, unless the user
2064 * changes it's value too. So, we must force this by removing the
2065 * value from the defaults DB.
2067 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2068 WMPropList *key = WMCreatePLString("WorkspaceBack");
2070 WMRemoveFromPLDictionary(w_global.domain.wmaker->dictionary, key);
2072 WMReleasePropList(key);
2074 #endif
2075 return True;
2078 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2080 static WMFont *font;
2081 const char *val;
2083 (void) addr;
2085 GET_STRING_OR_DEFAULT("Font", val);
2087 font = WMCreateFont(scr->wmscreen, val);
2088 if (!font)
2089 font = WMCreateFont(scr->wmscreen, "fixed");
2091 if (!font) {
2092 wfatal(_("could not load any usable font!!!"));
2093 exit(1);
2096 if (ret)
2097 *ret = font;
2099 /* can't assign font value outside update function */
2100 wassertrv(addr == NULL, True);
2102 return True;
2105 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2107 static XColor color;
2108 const char *val;
2109 int second_pass = 0;
2111 (void) addr;
2113 GET_STRING_OR_DEFAULT("Color", val);
2115 again:
2116 if (!wGetColor(scr, val, &color)) {
2117 wwarning(_("could not get color for key \"%s\""), entry->key);
2118 if (second_pass == 0) {
2119 val = WMGetFromPLString(entry->plvalue);
2120 second_pass = 1;
2121 wwarning(_("using default \"%s\" instead"), val);
2122 goto again;
2124 return False;
2127 if (ret)
2128 *ret = &color;
2130 assert(addr == NULL);
2132 if (addr)
2133 *(unsigned long*)addr = pixel;
2136 return True;
2139 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2141 static WShortKey shortcut;
2142 KeySym ksym;
2143 const char *val;
2144 char *k;
2145 char buf[MAX_SHORTCUT_LENGTH], *b;
2147 /* Parameter not used, but tell the compiler that it is ok */
2148 (void) scr;
2149 (void) addr;
2151 GET_STRING_OR_DEFAULT("Key spec", val);
2153 if (!val || strcasecmp(val, "NONE") == 0) {
2154 shortcut.keycode = 0;
2155 shortcut.modifier = 0;
2156 if (ret)
2157 *ret = &shortcut;
2158 return True;
2161 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2163 b = (char *)buf;
2165 /* get modifiers */
2166 shortcut.modifier = 0;
2167 while ((k = strchr(b, '+')) != NULL) {
2168 int mod;
2170 *k = 0;
2171 mod = wXModifierFromKey(b);
2172 if (mod < 0) {
2173 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2174 return False;
2176 shortcut.modifier |= mod;
2178 b = k + 1;
2181 /* get key */
2182 ksym = XStringToKeysym(b);
2184 if (ksym == NoSymbol) {
2185 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2186 return False;
2189 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2190 if (shortcut.keycode == 0) {
2191 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2192 return False;
2195 if (ret)
2196 *ret = &shortcut;
2198 return True;
2201 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2203 static int mask;
2204 const char *str;
2206 /* Parameter not used, but tell the compiler that it is ok */
2207 (void) scr;
2209 GET_STRING_OR_DEFAULT("Modifier Key", str);
2211 if (!str)
2212 return False;
2214 mask = wXModifierFromKey(str);
2215 if (mask < 0) {
2216 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2217 mask = 0;
2218 return False;
2221 if (addr)
2222 *(int *)addr = mask;
2224 if (ret)
2225 *ret = &mask;
2227 return True;
2230 # include <X11/cursorfont.h>
2231 typedef struct {
2232 const char *name;
2233 int id;
2234 } WCursorLookup;
2236 #define CURSOR_ID_NONE (XC_num_glyphs)
2238 static const WCursorLookup cursor_table[] = {
2239 {"X_cursor", XC_X_cursor},
2240 {"arrow", XC_arrow},
2241 {"based_arrow_down", XC_based_arrow_down},
2242 {"based_arrow_up", XC_based_arrow_up},
2243 {"boat", XC_boat},
2244 {"bogosity", XC_bogosity},
2245 {"bottom_left_corner", XC_bottom_left_corner},
2246 {"bottom_right_corner", XC_bottom_right_corner},
2247 {"bottom_side", XC_bottom_side},
2248 {"bottom_tee", XC_bottom_tee},
2249 {"box_spiral", XC_box_spiral},
2250 {"center_ptr", XC_center_ptr},
2251 {"circle", XC_circle},
2252 {"clock", XC_clock},
2253 {"coffee_mug", XC_coffee_mug},
2254 {"cross", XC_cross},
2255 {"cross_reverse", XC_cross_reverse},
2256 {"crosshair", XC_crosshair},
2257 {"diamond_cross", XC_diamond_cross},
2258 {"dot", XC_dot},
2259 {"dotbox", XC_dotbox},
2260 {"double_arrow", XC_double_arrow},
2261 {"draft_large", XC_draft_large},
2262 {"draft_small", XC_draft_small},
2263 {"draped_box", XC_draped_box},
2264 {"exchange", XC_exchange},
2265 {"fleur", XC_fleur},
2266 {"gobbler", XC_gobbler},
2267 {"gumby", XC_gumby},
2268 {"hand1", XC_hand1},
2269 {"hand2", XC_hand2},
2270 {"heart", XC_heart},
2271 {"icon", XC_icon},
2272 {"iron_cross", XC_iron_cross},
2273 {"left_ptr", XC_left_ptr},
2274 {"left_side", XC_left_side},
2275 {"left_tee", XC_left_tee},
2276 {"leftbutton", XC_leftbutton},
2277 {"ll_angle", XC_ll_angle},
2278 {"lr_angle", XC_lr_angle},
2279 {"man", XC_man},
2280 {"middlebutton", XC_middlebutton},
2281 {"mouse", XC_mouse},
2282 {"pencil", XC_pencil},
2283 {"pirate", XC_pirate},
2284 {"plus", XC_plus},
2285 {"question_arrow", XC_question_arrow},
2286 {"right_ptr", XC_right_ptr},
2287 {"right_side", XC_right_side},
2288 {"right_tee", XC_right_tee},
2289 {"rightbutton", XC_rightbutton},
2290 {"rtl_logo", XC_rtl_logo},
2291 {"sailboat", XC_sailboat},
2292 {"sb_down_arrow", XC_sb_down_arrow},
2293 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2294 {"sb_left_arrow", XC_sb_left_arrow},
2295 {"sb_right_arrow", XC_sb_right_arrow},
2296 {"sb_up_arrow", XC_sb_up_arrow},
2297 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2298 {"shuttle", XC_shuttle},
2299 {"sizing", XC_sizing},
2300 {"spider", XC_spider},
2301 {"spraycan", XC_spraycan},
2302 {"star", XC_star},
2303 {"target", XC_target},
2304 {"tcross", XC_tcross},
2305 {"top_left_arrow", XC_top_left_arrow},
2306 {"top_left_corner", XC_top_left_corner},
2307 {"top_right_corner", XC_top_right_corner},
2308 {"top_side", XC_top_side},
2309 {"top_tee", XC_top_tee},
2310 {"trek", XC_trek},
2311 {"ul_angle", XC_ul_angle},
2312 {"umbrella", XC_umbrella},
2313 {"ur_angle", XC_ur_angle},
2314 {"watch", XC_watch},
2315 {"xterm", XC_xterm},
2316 {NULL, CURSOR_ID_NONE}
2319 static void check_bitmap_status(int status, const char *filename, Pixmap bitmap)
2321 switch (status) {
2322 case BitmapOpenFailed:
2323 wwarning(_("failed to open bitmap file \"%s\""), filename);
2324 break;
2325 case BitmapFileInvalid:
2326 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2327 break;
2328 case BitmapNoMemory:
2329 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2330 break;
2331 case BitmapSuccess:
2332 XFreePixmap(dpy, bitmap);
2333 break;
2338 * (none)
2339 * (builtin, <cursor_name>)
2340 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2342 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2344 WMPropList *elem;
2345 char *val;
2346 int nelem;
2347 int status = 0;
2349 nelem = WMGetPropListItemCount(pl);
2350 if (nelem < 1) {
2351 return (status);
2353 elem = WMGetFromPLArray(pl, 0);
2354 if (!elem || !WMIsPLString(elem)) {
2355 return (status);
2357 val = WMGetFromPLString(elem);
2359 if (strcasecmp(val, "none") == 0) {
2360 status = 1;
2361 *cursor = None;
2362 } else if (strcasecmp(val, "builtin") == 0) {
2363 int i;
2364 int cursor_id = CURSOR_ID_NONE;
2366 if (nelem != 2) {
2367 wwarning(_("bad number of arguments in cursor specification"));
2368 return (status);
2370 elem = WMGetFromPLArray(pl, 1);
2371 if (!elem || !WMIsPLString(elem)) {
2372 return (status);
2374 val = WMGetFromPLString(elem);
2376 for (i = 0; cursor_table[i].name != NULL; i++) {
2377 if (strcasecmp(val, cursor_table[i].name) == 0) {
2378 cursor_id = cursor_table[i].id;
2379 break;
2382 if (CURSOR_ID_NONE == cursor_id) {
2383 wwarning(_("unknown builtin cursor name \"%s\""), val);
2384 } else {
2385 *cursor = XCreateFontCursor(dpy, cursor_id);
2386 status = 1;
2388 } else if (strcasecmp(val, "bitmap") == 0) {
2389 char *bitmap_name;
2390 char *mask_name;
2391 int bitmap_status;
2392 int mask_status;
2393 Pixmap bitmap;
2394 Pixmap mask;
2395 unsigned int w, h;
2396 int x, y;
2397 XColor fg, bg;
2399 if (nelem != 3) {
2400 wwarning(_("bad number of arguments in cursor specification"));
2401 return (status);
2403 elem = WMGetFromPLArray(pl, 1);
2404 if (!elem || !WMIsPLString(elem)) {
2405 return (status);
2407 val = WMGetFromPLString(elem);
2408 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2409 if (!bitmap_name) {
2410 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2411 return (status);
2413 elem = WMGetFromPLArray(pl, 2);
2414 if (!elem || !WMIsPLString(elem)) {
2415 wfree(bitmap_name);
2416 return (status);
2418 val = WMGetFromPLString(elem);
2419 mask_name = FindImage(wPreferences.pixmap_path, val);
2420 if (!mask_name) {
2421 wfree(bitmap_name);
2422 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2423 return (status);
2425 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2426 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2427 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2428 fg.pixel = scr->black_pixel;
2429 bg.pixel = scr->white_pixel;
2430 XQueryColor(dpy, scr->w_colormap, &fg);
2431 XQueryColor(dpy, scr->w_colormap, &bg);
2432 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2433 status = 1;
2435 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2436 check_bitmap_status(mask_status, mask_name, mask);
2437 wfree(bitmap_name);
2438 wfree(mask_name);
2440 return (status);
2443 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2445 static Cursor cursor;
2446 int status;
2447 int changed = 0;
2449 again:
2450 if (!WMIsPLArray(value)) {
2451 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2452 entry->key, "cursor specification");
2453 if (!changed) {
2454 value = entry->plvalue;
2455 changed = 1;
2456 wwarning(_("using default \"%s\" instead"), entry->default_value);
2457 goto again;
2459 return (False);
2461 status = parse_cursor(scr, value, &cursor);
2462 if (!status) {
2463 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2464 if (!changed) {
2465 value = entry->plvalue;
2466 changed = 1;
2467 wwarning(_("using default \"%s\" instead"), entry->default_value);
2468 goto again;
2470 return (False);
2472 if (ret) {
2473 *ret = &cursor;
2475 if (addr) {
2476 *(Cursor *) addr = cursor;
2478 return (True);
2481 #undef CURSOR_ID_NONE
2483 /* ---------------- value setting functions --------------- */
2484 static int setJustify(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2486 /* Parameter not used, but tell the compiler that it is ok */
2487 (void) scr;
2488 (void) entry;
2489 (void) tdata;
2490 (void) extra_data;
2492 return REFRESH_WINDOW_TITLE_COLOR;
2495 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2497 /* Parameter not used, but tell the compiler that it is ok */
2498 (void) scr;
2499 (void) entry;
2500 (void) bar;
2501 (void) foo;
2503 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2506 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2508 char *flag = tdata;
2509 long which = (long) extra_data;
2511 /* Parameter not used, but tell the compiler that it is ok */
2512 (void) scr;
2513 (void) entry;
2515 switch (which) {
2516 case WM_DOCK:
2517 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2518 // Drawers require the dock
2519 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || wPreferences.flags.nodock;
2520 break;
2521 case WM_CLIP:
2522 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2523 break;
2524 case WM_DRAWER:
2525 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || *flag;
2526 break;
2527 default:
2528 break;
2530 return 0;
2533 static int setClipMergedInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2535 char *flag = tdata;
2537 /* Parameter not used, but tell the compiler that it is ok */
2538 (void) scr;
2539 (void) entry;
2540 (void) foo;
2542 wPreferences.flags.clip_merged_in_dock = *flag;
2543 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2544 return 0;
2547 static int setWrapAppiconsInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2549 char *flag = tdata;
2551 /* Parameter not used, but tell the compiler that it is ok */
2552 (void) scr;
2553 (void) entry;
2554 (void) foo;
2556 wPreferences.flags.wrap_appicons_in_dock = *flag;
2557 return 0;
2560 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2562 /* Parameter not used, but tell the compiler that it is ok */
2563 (void) entry;
2564 (void) bar;
2565 (void) foo;
2567 if (scr->workspaces) {
2568 wWorkspaceForceChange(scr, scr->current_workspace);
2569 wArrangeIcons(scr, False);
2571 return 0;
2574 static int setIconTile(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2576 Pixmap pixmap;
2577 RImage *img;
2578 WTexture ** texture = tdata;
2579 int reset = 0;
2581 /* Parameter not used, but tell the compiler that it is ok */
2582 (void) foo;
2584 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2585 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2586 ? WREL_ICON : WREL_FLAT);
2587 if (!img) {
2588 wwarning(_("could not render texture for icon background"));
2589 if (!entry->addr)
2590 wTextureDestroy(scr, *texture);
2591 return 0;
2593 RConvertImage(scr->rcontext, img, &pixmap);
2595 if (scr->icon_tile) {
2596 reset = 1;
2597 RReleaseImage(scr->icon_tile);
2598 XFreePixmap(dpy, scr->icon_tile_pixmap);
2601 scr->icon_tile = img;
2603 /* put the icon in the noticeboard hint */
2604 PropSetIconTileHint(scr, img);
2606 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock) {
2607 if (scr->clip_tile) {
2608 RReleaseImage(scr->clip_tile);
2610 scr->clip_tile = wClipMakeTile(img);
2613 if (!wPreferences.flags.nodrawer) {
2614 if (scr->drawer_tile) {
2615 RReleaseImage(scr->drawer_tile);
2617 scr->drawer_tile = wDrawerMakeTile(scr, img);
2620 scr->icon_tile_pixmap = pixmap;
2622 if (scr->def_icon_rimage) {
2623 RReleaseImage(scr->def_icon_rimage);
2624 scr->def_icon_rimage = NULL;
2627 if (scr->icon_back_texture)
2628 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2630 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2632 /* Free the texture as nobody else will use it, nor refer to it. */
2633 if (!entry->addr)
2634 wTextureDestroy(scr, *texture);
2636 return (reset ? REFRESH_ICON_TILE : 0);
2639 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2641 WMFont *font = tdata;
2643 /* Parameter not used, but tell the compiler that it is ok */
2644 (void) entry;
2645 (void) foo;
2647 if (scr->title_font) {
2648 WMReleaseFont(scr->title_font);
2650 scr->title_font = font;
2652 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2655 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2657 WMFont *font = tdata;
2659 /* Parameter not used, but tell the compiler that it is ok */
2660 (void) entry;
2661 (void) foo;
2663 if (scr->menu_title_font) {
2664 WMReleaseFont(scr->menu_title_font);
2667 scr->menu_title_font = font;
2669 return REFRESH_MENU_TITLE_FONT;
2672 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2674 WMFont *font = tdata;
2676 /* Parameter not used, but tell the compiler that it is ok */
2677 (void) entry;
2678 (void) foo;
2680 if (scr->menu_entry_font) {
2681 WMReleaseFont(scr->menu_entry_font);
2683 scr->menu_entry_font = font;
2685 return REFRESH_MENU_FONT;
2688 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2690 WMFont *font = tdata;
2692 /* Parameter not used, but tell the compiler that it is ok */
2693 (void) entry;
2694 (void) foo;
2696 if (scr->icon_title_font) {
2697 WMReleaseFont(scr->icon_title_font);
2700 scr->icon_title_font = font;
2702 return REFRESH_ICON_FONT;
2705 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2707 WMFont *font = tdata;
2709 /* Parameter not used, but tell the compiler that it is ok */
2710 (void) entry;
2711 (void) foo;
2713 if (scr->clip_title_font) {
2714 WMReleaseFont(scr->clip_title_font);
2717 scr->clip_title_font = font;
2719 return REFRESH_ICON_FONT;
2722 static int setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2724 WMFont *font = tdata;
2726 /* Parameter not used, but tell the compiler that it is ok */
2727 (void) scr;
2728 (void) entry;
2729 (void) foo;
2731 if (scr->workspace_name_font)
2732 WMReleaseFont(scr->workspace_name_font);
2734 scr->workspace_name_font = font;
2736 return 0;
2739 static int setHightlight(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2741 XColor *color = tdata;
2743 /* Parameter not used, but tell the compiler that it is ok */
2744 (void) entry;
2745 (void) foo;
2747 if (scr->select_color)
2748 WMReleaseColor(scr->select_color);
2750 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2752 wFreeColor(scr, color->pixel);
2754 return REFRESH_MENU_COLOR;
2757 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2759 XColor *color = tdata;
2761 /* Parameter not used, but tell the compiler that it is ok */
2762 (void) entry;
2763 (void) foo;
2765 if (scr->select_text_color)
2766 WMReleaseColor(scr->select_text_color);
2768 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2770 wFreeColor(scr, color->pixel);
2772 return REFRESH_MENU_COLOR;
2775 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2777 XColor *color = tdata;
2778 long widx = (long) extra_data;
2780 /* Parameter not used, but tell the compiler that it is ok */
2781 (void) entry;
2783 if (scr->clip_title_color[widx])
2784 WMReleaseColor(scr->clip_title_color[widx]);
2786 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2787 wFreeColor(scr, color->pixel);
2789 return REFRESH_ICON_TITLE_COLOR;
2792 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2794 XColor *color = tdata;
2795 long widx = (long) extra_data;
2797 /* Parameter not used, but tell the compiler that it is ok */
2798 (void) entry;
2800 if (scr->window_title_color[widx])
2801 WMReleaseColor(scr->window_title_color[widx]);
2803 scr->window_title_color[widx] =
2804 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2806 wFreeColor(scr, color->pixel);
2808 return REFRESH_WINDOW_TITLE_COLOR;
2811 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2813 XColor *color = tdata;
2815 /* Parameter not used, but tell the compiler that it is ok */
2816 (void) entry;
2817 (void) extra_data;
2819 if (scr->menu_title_color[0])
2820 WMReleaseColor(scr->menu_title_color[0]);
2822 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2824 wFreeColor(scr, color->pixel);
2826 return REFRESH_MENU_TITLE_COLOR;
2829 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2831 XColor *color = tdata;
2833 /* Parameter not used, but tell the compiler that it is ok */
2834 (void) entry;
2835 (void) foo;
2837 if (scr->mtext_color)
2838 WMReleaseColor(scr->mtext_color);
2840 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2842 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2843 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2844 } else {
2845 WMSetColorAlpha(scr->dtext_color, 0xffff);
2848 wFreeColor(scr, color->pixel);
2850 return REFRESH_MENU_COLOR;
2853 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2855 XColor *color = tdata;
2857 /* Parameter not used, but tell the compiler that it is ok */
2858 (void) entry;
2859 (void) foo;
2861 if (scr->dtext_color)
2862 WMReleaseColor(scr->dtext_color);
2864 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2866 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2867 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2868 } else {
2869 WMSetColorAlpha(scr->dtext_color, 0xffff);
2872 wFreeColor(scr, color->pixel);
2874 return REFRESH_MENU_COLOR;
2877 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2879 XColor *color = tdata;
2881 /* Parameter not used, but tell the compiler that it is ok */
2882 (void) entry;
2883 (void) foo;
2885 if (scr->icon_title_color)
2886 WMReleaseColor(scr->icon_title_color);
2887 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2889 wFreeColor(scr, color->pixel);
2891 return REFRESH_ICON_TITLE_COLOR;
2894 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2896 XColor *color = tdata;
2898 /* Parameter not used, but tell the compiler that it is ok */
2899 (void) entry;
2900 (void) foo;
2902 if (scr->icon_title_texture) {
2903 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2905 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2907 return REFRESH_ICON_TITLE_BACK;
2910 static int setFrameBorderWidth(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2912 int *value = tdata;
2914 /* Parameter not used, but tell the compiler that it is ok */
2915 (void) entry;
2916 (void) foo;
2918 scr->frame_border_width = *value;
2920 return REFRESH_FRAME_BORDER;
2923 static int setFrameBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2925 XColor *color = tdata;
2927 /* Parameter not used, but tell the compiler that it is ok */
2928 (void) entry;
2929 (void) foo;
2931 if (scr->frame_border_color)
2932 WMReleaseColor(scr->frame_border_color);
2933 scr->frame_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2935 wFreeColor(scr, color->pixel);
2937 return REFRESH_FRAME_BORDER;
2940 static int setFrameFocusedBorderColor(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2942 XColor *color = tdata;
2944 /* Parameter not used, but tell the compiler that it is ok */
2945 (void) entry;
2946 (void) foo;
2948 if (scr->frame_focused_border_color)
2949 WMReleaseColor(scr->frame_focused_border_color);
2950 scr->frame_focused_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2952 wFreeColor(scr, color->pixel);
2954 return REFRESH_FRAME_BORDER;
2957 static int setFrameSelectedBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2959 XColor *color = tdata;
2961 /* Parameter not used, but tell the compiler that it is ok */
2962 (void) entry;
2963 (void) foo;
2965 if (scr->frame_selected_border_color)
2966 WMReleaseColor(scr->frame_selected_border_color);
2967 scr->frame_selected_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2969 wFreeColor(scr, color->pixel);
2971 return REFRESH_FRAME_BORDER;
2974 static void trackDeadProcess(pid_t pid, unsigned int status, void *client_data)
2976 WScreen *scr = (WScreen *) client_data;
2978 /* Parameter not used, but tell the compiler that it is ok */
2979 (void) pid;
2980 (void) status;
2982 close(scr->helper_fd);
2983 scr->helper_fd = 0;
2984 scr->helper_pid = 0;
2985 scr->flags.backimage_helper_launched = 0;
2988 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
2990 WMPropList *value = tdata;
2991 WMPropList *val;
2992 char *str;
2993 int i;
2995 /* Parameter not used, but tell the compiler that it is ok */
2996 (void) entry;
2997 (void) bar;
2999 if (scr->flags.backimage_helper_launched) {
3000 if (WMGetPropListItemCount(value) == 0) {
3001 SendHelperMessage(scr, 'C', 0, NULL);
3002 SendHelperMessage(scr, 'K', 0, NULL);
3004 WMReleasePropList(value);
3005 return 0;
3007 } else {
3008 pid_t pid;
3009 int filedes[2];
3011 if (WMGetPropListItemCount(value) == 0)
3012 return 0;
3014 if (pipe(filedes) < 0) {
3015 werror("pipe() failed:can't set workspace specific background image");
3017 WMReleasePropList(value);
3018 return 0;
3021 pid = fork();
3022 if (pid < 0) {
3023 werror("fork() failed:can't set workspace specific background image");
3024 if (close(filedes[0]) < 0)
3025 werror("could not close pipe");
3026 if (close(filedes[1]) < 0)
3027 werror("could not close pipe");
3029 } else if (pid == 0) {
3030 char *dither;
3032 SetupEnvironment(scr);
3034 if (close(0) < 0)
3035 werror("could not close pipe");
3036 if (dup(filedes[0]) < 0) {
3037 werror("dup() failed:can't set workspace specific background image");
3039 dither = wPreferences.no_dithering ? "-m" : "-d";
3040 if (wPreferences.smooth_workspace_back)
3041 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3042 else
3043 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3044 werror("could not execute wmsetbg");
3045 exit(1);
3046 } else {
3048 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3049 werror("error setting close-on-exec flag");
3051 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3052 werror("error setting close-on-exec flag");
3055 scr->helper_fd = filedes[1];
3056 scr->helper_pid = pid;
3057 scr->flags.backimage_helper_launched = 1;
3059 wAddDeathHandler(pid, trackDeadProcess, scr);
3061 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3066 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3067 val = WMGetFromPLArray(value, i);
3068 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
3069 str = WMGetPropListDescription(val, False);
3071 SendHelperMessage(scr, 'S', i + 1, str);
3073 wfree(str);
3074 } else {
3075 SendHelperMessage(scr, 'U', i + 1, NULL);
3078 sleep(1);
3080 WMReleasePropList(value);
3081 return 0;
3084 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
3086 WMPropList *value = tdata;
3088 /* Parameter not used, but tell the compiler that it is ok */
3089 (void) entry;
3090 (void) bar;
3092 if (scr->flags.backimage_helper_launched) {
3093 char *str;
3095 if (WMGetPropListItemCount(value) == 0) {
3096 SendHelperMessage(scr, 'U', 0, NULL);
3097 } else {
3098 /* set the default workspace background to this one */
3099 str = WMGetPropListDescription(value, False);
3100 if (str) {
3101 SendHelperMessage(scr, 'S', 0, str);
3102 wfree(str);
3103 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
3104 } else {
3105 SendHelperMessage(scr, 'U', 0, NULL);
3108 } else if (WMGetPropListItemCount(value) > 0) {
3109 char *command;
3110 char *text;
3111 char *dither;
3112 int len;
3114 text = WMGetPropListDescription(value, False);
3115 len = strlen(text) + 40;
3116 command = wmalloc(len);
3117 dither = wPreferences.no_dithering ? "-m" : "-d";
3118 if (!strchr(text, '\'') && !strchr(text, '\\')) {
3119 command = wmalloc(len);
3120 if (wPreferences.smooth_workspace_back)
3121 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3122 else
3123 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3124 ExecuteShellCommand(scr, command);
3125 wfree(command);
3126 } else
3127 wwarning(_("Invalid arguments for background \"%s\""), text);
3128 wfree(text);
3130 WMReleasePropList(value);
3132 return 0;
3135 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3137 WTexture **texture = tdata;
3139 /* Parameter not used, but tell the compiler that it is ok */
3140 (void) entry;
3141 (void) foo;
3143 if (scr->widget_texture) {
3144 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3146 scr->widget_texture = *(WTexSolid **) texture;
3148 return 0;
3151 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3153 WTexture **texture = tdata;
3155 /* Parameter not used, but tell the compiler that it is ok */
3156 (void) entry;
3157 (void) foo;
3159 if (scr->window_title_texture[WS_FOCUSED]) {
3160 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3162 scr->window_title_texture[WS_FOCUSED] = *texture;
3164 return REFRESH_WINDOW_TEXTURES;
3167 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3169 WTexture **texture = tdata;
3171 /* Parameter not used, but tell the compiler that it is ok */
3172 (void) entry;
3173 (void) foo;
3175 if (scr->window_title_texture[WS_PFOCUSED]) {
3176 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3178 scr->window_title_texture[WS_PFOCUSED] = *texture;
3180 return REFRESH_WINDOW_TEXTURES;
3183 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3185 WTexture **texture = tdata;
3187 /* Parameter not used, but tell the compiler that it is ok */
3188 (void) entry;
3189 (void) foo;
3191 if (scr->window_title_texture[WS_UNFOCUSED]) {
3192 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3194 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3196 return REFRESH_WINDOW_TEXTURES;
3199 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3201 WTexture **texture = tdata;
3203 /* Parameter not used, but tell the compiler that it is ok */
3204 (void) entry;
3205 (void) foo;
3207 if (scr->resizebar_texture[0]) {
3208 wTextureDestroy(scr, scr->resizebar_texture[0]);
3210 scr->resizebar_texture[0] = *texture;
3212 return REFRESH_WINDOW_TEXTURES;
3215 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3217 WTexture **texture = tdata;
3219 /* Parameter not used, but tell the compiler that it is ok */
3220 (void) entry;
3221 (void) foo;
3223 if (scr->menu_title_texture[0]) {
3224 wTextureDestroy(scr, scr->menu_title_texture[0]);
3226 scr->menu_title_texture[0] = *texture;
3228 return REFRESH_MENU_TITLE_TEXTURE;
3231 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3233 WTexture **texture = tdata;
3235 /* Parameter not used, but tell the compiler that it is ok */
3236 (void) entry;
3237 (void) foo;
3239 if (scr->menu_item_texture) {
3240 wTextureDestroy(scr, scr->menu_item_texture);
3241 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3243 scr->menu_item_texture = *texture;
3245 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3247 return REFRESH_MENU_TEXTURE;
3250 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3252 WShortKey *shortcut = tdata;
3253 WWindow *wwin;
3254 long widx = (long) extra_data;
3256 /* Parameter not used, but tell the compiler that it is ok */
3257 (void) entry;
3259 wKeyBindings[widx] = *shortcut;
3261 wwin = scr->focused_window;
3263 while (wwin != NULL) {
3264 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3266 if (!WFLAGP(wwin, no_bind_keys)) {
3267 wWindowSetKeyGrabs(wwin);
3269 wwin = wwin->prev;
3272 /* do we need to update window menus? */
3273 if (widx >= WKBD_WORKSPACE1 && widx <= WKBD_WORKSPACE10)
3274 return REFRESH_WORKSPACE_MENU;
3275 if (widx == WKBD_LASTWORKSPACE)
3276 return REFRESH_WORKSPACE_MENU;
3277 if (widx >= WKBD_MOVE_WORKSPACE1 && widx <= WKBD_MOVE_WORKSPACE10)
3278 return REFRESH_WORKSPACE_MENU;
3280 return 0;
3283 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3285 /* Parameter not used, but tell the compiler that it is ok */
3286 (void) entry;
3287 (void) bar;
3288 (void) foo;
3290 wScreenUpdateUsableArea(scr);
3291 wArrangeIcons(scr, True);
3293 return 0;
3296 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3298 /* Parameter not used, but tell the compiler that it is ok */
3299 (void) entry;
3300 (void) bar;
3301 (void) foo;
3303 wScreenUpdateUsableArea(scr);
3305 return 0;
3308 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3310 /* Parameter not used, but tell the compiler that it is ok */
3311 (void) scr;
3312 (void) entry;
3313 (void) tdata;
3314 (void) foo;
3316 return REFRESH_MENU_TEXTURE;
3319 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3321 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3323 RCopyArea(img, image, x, y, w, h, 0, 0);
3325 return img;
3328 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3330 WMPropList *array = tdata;
3331 char *path;
3332 RImage *bgimage;
3333 int cwidth, cheight;
3334 struct WPreferences *prefs = foo;
3336 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3337 if (prefs->swtileImage)
3338 RReleaseImage(prefs->swtileImage);
3339 prefs->swtileImage = NULL;
3341 WMReleasePropList(array);
3342 return 0;
3345 switch (WMGetPropListItemCount(array)) {
3346 case 4:
3347 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3348 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3349 break;
3350 } else
3351 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3353 if (!path) {
3354 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3355 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3356 } else {
3357 bgimage = RLoadImage(scr->rcontext, path, 0);
3358 if (!bgimage) {
3359 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3360 wfree(path);
3361 } else {
3362 wfree(path);
3364 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3365 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3367 if (cwidth <= 0 || cheight <= 0 ||
3368 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3369 wwarning(_("Invalid split sizes for switch panel back image."));
3370 else {
3371 int i;
3372 int swidth, theight;
3373 for (i = 0; i < 9; i++) {
3374 if (prefs->swbackImage[i])
3375 RReleaseImage(prefs->swbackImage[i]);
3376 prefs->swbackImage[i] = NULL;
3378 swidth = (bgimage->width - cwidth) / 2;
3379 theight = (bgimage->height - cheight) / 2;
3381 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3382 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3383 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3384 swidth, theight);
3386 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3387 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3388 cwidth, cheight);
3389 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3390 swidth, cheight);
3392 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3393 swidth, theight);
3394 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3395 cwidth, theight);
3396 prefs->swbackImage[8] =
3397 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3398 theight);
3400 // check if anything failed
3401 for (i = 0; i < 9; i++) {
3402 if (!prefs->swbackImage[i]) {
3403 for (; i >= 0; --i) {
3404 RReleaseImage(prefs->swbackImage[i]);
3405 prefs->swbackImage[i] = NULL;
3407 break;
3411 RReleaseImage(bgimage);
3415 case 1:
3416 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3417 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3418 break;
3419 } else
3420 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3422 if (!path) {
3423 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3424 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3425 } else {
3426 if (prefs->swtileImage)
3427 RReleaseImage(prefs->swtileImage);
3429 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3430 if (!prefs->swtileImage) {
3431 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3433 wfree(path);
3435 break;
3437 default:
3438 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3439 break;
3442 WMReleasePropList(array);
3444 return 0;
3447 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3449 WMPropList *array = tdata;
3450 int i;
3451 struct WPreferences *prefs = foo;
3453 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3454 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3455 WMReleasePropList(array);
3456 return 0;
3459 DestroyWindowMenu(scr);
3461 for (i = 0; i < 7; i++) {
3462 if (prefs->modifier_labels[i])
3463 wfree(prefs->modifier_labels[i]);
3465 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3466 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3467 } else {
3468 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3469 prefs->modifier_labels[i] = NULL;
3473 WMReleasePropList(array);
3475 return 0;
3478 static int setDoubleClick(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
3480 int *value = tdata;
3482 /* Parameter not used, but tell the compiler that it is ok */
3483 (void) entry;
3484 (void) scr;
3486 if (*value <= 0)
3487 *(int *)foo = 1;
3489 W_setconf_doubleClickDelay(*value);
3491 return 0;
3494 static int setCursor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3496 Cursor *cursor = tdata;
3497 long widx = (long) extra_data;
3499 /* Parameter not used, but tell the compiler that it is ok */
3500 (void) entry;
3502 if (wPreferences.cursor[widx] != None) {
3503 XFreeCursor(dpy, wPreferences.cursor[widx]);
3506 wPreferences.cursor[widx] = *cursor;
3508 if (widx == WCUR_ROOT && *cursor != None) {
3509 XDefineCursor(dpy, scr->root_win, *cursor);
3512 return 0;