Fixed a few improper macro usages
[wmaker-crm.git] / src / defaults.c
blob5bf82672e7f0cda78b4cabf7e12a790b9a6dd447
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 setFrameSelectedBorderColor;
130 static WDECallbackUpdate setLargeDisplayFont;
131 static WDECallbackUpdate setWTitleColor;
132 static WDECallbackUpdate setFTitleBack;
133 static WDECallbackUpdate setPTitleBack;
134 static WDECallbackUpdate setUTitleBack;
135 static WDECallbackUpdate setResizebarBack;
136 static WDECallbackUpdate setWorkspaceBack;
137 static WDECallbackUpdate setWorkspaceSpecificBack;
138 static WDECallbackUpdate setMenuTitleColor;
139 static WDECallbackUpdate setMenuTextColor;
140 static WDECallbackUpdate setMenuDisabledColor;
141 static WDECallbackUpdate setMenuTitleBack;
142 static WDECallbackUpdate setMenuTextBack;
143 static WDECallbackUpdate setHightlight;
144 static WDECallbackUpdate setHightlightText;
145 static WDECallbackUpdate setKeyGrab;
146 static WDECallbackUpdate setDoubleClick;
147 static WDECallbackUpdate setIconPosition;
149 static WDECallbackUpdate setClipTitleFont;
150 static WDECallbackUpdate setClipTitleColor;
152 static WDECallbackUpdate setMenuStyle;
153 static WDECallbackUpdate setSwPOptions;
154 static WDECallbackUpdate updateUsableArea;
156 static WDECallbackUpdate setModifierKeyLabels;
158 static WDECallbackConvert getCursor;
159 static WDECallbackUpdate setCursor;
162 * Tables to convert strings to enumeration values.
163 * Values stored are char
166 /* WARNING: sum of length of all value strings must not exceed
167 * this value */
168 #define TOTAL_VALUES_LENGTH 80
170 #define REFRESH_WINDOW_TEXTURES (1<<0)
171 #define REFRESH_MENU_TEXTURE (1<<1)
172 #define REFRESH_MENU_FONT (1<<2)
173 #define REFRESH_MENU_COLOR (1<<3)
174 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
175 #define REFRESH_MENU_TITLE_FONT (1<<5)
176 #define REFRESH_MENU_TITLE_COLOR (1<<6)
177 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
178 #define REFRESH_WINDOW_FONT (1<<8)
179 #define REFRESH_ICON_TILE (1<<9)
180 #define REFRESH_ICON_FONT (1<<10)
181 #define REFRESH_WORKSPACE_BACK (1<<11)
183 #define REFRESH_BUTTON_IMAGES (1<<12)
185 #define REFRESH_ICON_TITLE_COLOR (1<<13)
186 #define REFRESH_ICON_TITLE_BACK (1<<14)
188 #define REFRESH_WORKSPACE_MENU (1<<15)
190 #define REFRESH_FRAME_BORDER REFRESH_MENU_FONT|REFRESH_WINDOW_FONT
192 static WOptionEnumeration seFocusModes[] = {
193 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
194 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
195 {NULL, 0, 0}
198 static WOptionEnumeration seTitlebarModes[] = {
199 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
200 {"next", TS_NEXT, 0}, {NULL, 0, 0}
203 static WOptionEnumeration seColormapModes[] = {
204 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
205 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
206 {NULL, 0, 0}
209 static WOptionEnumeration sePlacements[] = {
210 {"Auto", WPM_AUTO, 0},
211 {"Smart", WPM_SMART, 0},
212 {"Cascade", WPM_CASCADE, 0},
213 {"Random", WPM_RANDOM, 0},
214 {"Manual", WPM_MANUAL, 0},
215 {"Center", WPM_CENTER, 0},
216 {NULL, 0, 0}
219 static WOptionEnumeration seGeomDisplays[] = {
220 {"None", WDIS_NONE, 0},
221 {"Center", WDIS_CENTER, 0},
222 {"Corner", WDIS_TOPLEFT, 0},
223 {"Floating", WDIS_FRAME_CENTER, 0},
224 {"Line", WDIS_NEW, 0},
225 {NULL, 0, 0}
228 static WOptionEnumeration seSpeeds[] = {
229 {"UltraFast", SPEED_ULTRAFAST, 0},
230 {"Fast", SPEED_FAST, 0},
231 {"Medium", SPEED_MEDIUM, 0},
232 {"Slow", SPEED_SLOW, 0},
233 {"UltraSlow", SPEED_ULTRASLOW, 0},
234 {NULL, 0, 0}
237 static WOptionEnumeration seMouseButtonActions[] = {
238 {"None", WA_NONE, 0},
239 {"SelectWindows", WA_SELECT_WINDOWS, 0},
240 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
241 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
242 {NULL, 0, 0}
245 static WOptionEnumeration seMouseWheelActions[] = {
246 {"None", WA_NONE, 0},
247 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
248 {NULL, 0, 0}
251 static WOptionEnumeration seIconificationStyles[] = {
252 {"Zoom", WIS_ZOOM, 0},
253 {"Twist", WIS_TWIST, 0},
254 {"Flip", WIS_FLIP, 0},
255 {"None", WIS_NONE, 0},
256 {"random", WIS_RANDOM, 0},
257 {NULL, 0, 0}
260 static WOptionEnumeration seJustifications[] = {
261 {"Left", WTJ_LEFT, 0},
262 {"Center", WTJ_CENTER, 0},
263 {"Right", WTJ_RIGHT, 0},
264 {NULL, 0, 0}
267 static WOptionEnumeration seIconPositions[] = {
268 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
269 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
270 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
271 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
272 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
273 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
274 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
275 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
276 {NULL, 0, 0}
279 static WOptionEnumeration seMenuStyles[] = {
280 {"normal", MS_NORMAL, 0},
281 {"singletexture", MS_SINGLE_TEXTURE, 0},
282 {"flat", MS_FLAT, 0},
283 {NULL, 0, 0}
286 static WOptionEnumeration seDisplayPositions[] = {
287 {"none", WD_NONE, 0},
288 {"center", WD_CENTER, 0},
289 {"top", WD_TOP, 0},
290 {"bottom", WD_BOTTOM, 0},
291 {"topleft", WD_TOPLEFT, 0},
292 {"topright", WD_TOPRIGHT, 0},
293 {"bottomleft", WD_BOTTOMLEFT, 0},
294 {"bottomright", WD_BOTTOMRIGHT, 0},
295 {NULL, 0, 0}
298 static WOptionEnumeration seWorkspaceBorder[] = {
299 {"None", WB_NONE, 0},
300 {"LeftRight", WB_LEFTRIGHT, 0},
301 {"TopBottom", WB_TOPBOTTOM, 0},
302 {"AllDirections", WB_ALLDIRS, 0},
303 {NULL, 0, 0}
307 * ALL entries in the tables bellow, NEED to have a default value
308 * defined, and this value needs to be correct.
311 /* these options will only affect the window manager on startup
313 * static defaults can't access the screen data, because it is
314 * created after these defaults are read
316 WDefaultEntry staticOptionList[] = {
318 {"ColormapSize", "4", NULL,
319 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
320 {"DisableDithering", "NO", NULL,
321 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
322 {"IconSize", "64", NULL,
323 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
324 {"ModifierKey", "Mod1", NULL,
325 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
326 {"DisableWSMouseActions", "NO", NULL,
327 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
328 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
329 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
330 {"NewStyle", "new", seTitlebarModes,
331 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
332 {"DisableDock", "NO", (void *)WM_DOCK,
333 NULL, getBool, setIfDockPresent, NULL, NULL},
334 {"DisableClip", "NO", (void *)WM_CLIP,
335 NULL, getBool, setIfDockPresent, NULL, NULL},
336 {"DisableDrawers", "NO", (void *)WM_DRAWER,
337 NULL, getBool, setIfDockPresent, NULL, NULL},
338 {"ClipMergedInDock", "NO", NULL,
339 NULL, getBool, setClipMergedInDock, NULL, NULL},
340 {"DisableMiniwindows", "NO", NULL,
341 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
344 #define NUM2STRING_(x) #x
345 #define NUM2STRING(x) NUM2STRING_(x)
347 WDefaultEntry optionList[] = {
349 /* dynamic options */
351 {"IconPosition", "blh", seIconPositions,
352 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
353 {"IconificationStyle", "Zoom", seIconificationStyles,
354 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
355 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
356 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
357 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
358 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
359 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
360 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
361 {"MouseWheelAction", "None", seMouseWheelActions,
362 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
363 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
364 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
365 {"IconPath", DEF_ICON_PATHS, NULL,
366 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
367 {"ColormapMode", "auto", seColormapModes,
368 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
369 {"AutoFocus", "NO", NULL,
370 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
371 {"RaiseDelay", "0", NULL,
372 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
373 {"CirculateRaise", "NO", NULL,
374 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
375 {"Superfluous", "NO", NULL,
376 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
377 {"AdvanceToNewWorkspace", "NO", NULL,
378 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
379 {"CycleWorkspaces", "NO", NULL,
380 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
381 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
382 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
383 {"WorkspaceBorder", "None", seWorkspaceBorder,
384 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
385 {"WorkspaceBorderSize", "0", NULL,
386 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
387 {"StickyIcons", "NO", NULL,
388 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
389 {"SaveSessionOnExit", "NO", NULL,
390 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
391 {"WrapMenus", "NO", NULL,
392 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
393 {"ScrollableMenus", "NO", NULL,
394 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
395 {"MenuScrollSpeed", "medium", seSpeeds,
396 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
397 {"IconSlideSpeed", "medium", seSpeeds,
398 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
399 {"ShadeSpeed", "medium", seSpeeds,
400 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
401 {"BounceAppIconsWhenUrgent", "YES", NULL,
402 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
403 {"RaiseAppIconsWhenBouncing", "NO", NULL,
404 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
405 {"DoNotMakeAppIconsBounce", "NO", NULL,
406 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
407 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
408 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
409 {"ClipAutoraiseDelay", "600", NULL,
410 &wPreferences.clip_auto_raise_delay, getInt, NULL, NULL, NULL},
411 {"ClipAutolowerDelay", "1000", NULL,
412 &wPreferences.clip_auto_lower_delay, getInt, NULL, NULL, NULL},
413 {"ClipAutoexpandDelay", "600", NULL,
414 &wPreferences.clip_auto_expand_delay, getInt, NULL, NULL, NULL},
415 {"ClipAutocollapseDelay", "1000", NULL,
416 &wPreferences.clip_auto_collapse_delay, getInt, NULL, NULL, NULL},
417 {"WrapAppiconsInDock", "YES", NULL,
418 NULL, getBool, setWrapAppiconsInDock, NULL, NULL},
419 {"AlignSubmenus", "NO", NULL,
420 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
421 {"ViKeyMenus", "NO", NULL,
422 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
423 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
424 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
425 {"WindowPlacement", "auto", sePlacements,
426 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
427 {"IgnoreFocusClick", "NO", NULL,
428 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
429 {"UseSaveUnders", "NO", NULL,
430 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
431 {"OpaqueMove", "NO", NULL,
432 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
433 {"OpaqueResize", "NO", NULL,
434 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
435 {"OpaqueMoveResizeKeyboard", "NO", NULL,
436 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
437 {"DisableAnimations", "NO", NULL,
438 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
439 {"DontLinkWorkspaces", "NO", NULL,
440 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
441 {"HighlightActiveApp", "YES", NULL,
442 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
443 {"AutoArrangeIcons", "NO", NULL,
444 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
445 {"NoWindowOverDock", "NO", NULL,
446 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
447 {"NoWindowOverIcons", "NO", NULL,
448 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
449 {"WindowPlaceOrigin", "(0, 0)", NULL,
450 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
451 {"ResizeDisplay", "corner", seGeomDisplays,
452 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
453 {"MoveDisplay", "corner", seGeomDisplays,
454 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
455 {"DontConfirmKill", "NO", NULL,
456 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
457 {"WindowTitleBalloons", "NO", NULL,
458 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
459 {"MiniwindowTitleBalloons", "NO", NULL,
460 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
461 {"AppIconBalloons", "NO", NULL,
462 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
463 {"HelpBalloons", "NO", NULL,
464 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
465 {"EdgeResistance", "30", NULL,
466 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
467 {"ResizeIncrement", "0", NULL,
468 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
469 {"Attraction", "NO", NULL,
470 &wPreferences.attract, getBool, NULL, NULL, NULL},
471 {"DisableBlinking", "NO", NULL,
472 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
473 {"SingleClickLaunch", "NO", NULL,
474 &wPreferences.single_click, getBool, NULL, NULL, NULL},
475 {"StrictWindozeCycle", "YES", NULL,
476 &wPreferences.strict_windoze_cycle, getBool, NULL, NULL, NULL},
477 {"SwitchPanelOnlyOpen", "NO", NULL,
478 &wPreferences.panel_only_open, getBool, NULL, NULL, NULL},
480 /* style options */
482 {"MenuStyle", "normal", seMenuStyles,
483 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
484 {"WidgetColor", "(solid, gray)", NULL,
485 NULL, getTexture, setWidgetColor, NULL, NULL},
486 {"WorkspaceSpecificBack", "()", NULL,
487 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
488 /* WorkspaceBack must come after WorkspaceSpecificBack or
489 * WorkspaceBack wont know WorkspaceSpecificBack was also
490 * specified and 2 copies of wmsetbg will be launched */
491 {"WorkspaceBack", "(solid, black)", NULL,
492 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
493 {"SmoothWorkspaceBack", "NO", NULL,
494 NULL, getBool, NULL, NULL, NULL},
495 {"IconBack", "(solid, gray)", NULL,
496 NULL, getTexture, setIconTile, NULL, NULL},
497 {"TitleJustify", "center", seJustifications,
498 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
499 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
500 NULL, getFont, setWinTitleFont, NULL, NULL},
501 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
502 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
503 {"WindowTitleMinHeight", "0", NULL,
504 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
505 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
506 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
507 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
508 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
509 {"MenuTitleMinHeight", "0", NULL,
510 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
511 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
512 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
513 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
514 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
515 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
516 NULL, getFont, setMenuTitleFont, NULL, NULL},
517 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
518 NULL, getFont, setMenuTextFont, NULL, NULL},
519 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
520 NULL, getFont, setIconTitleFont, NULL, NULL},
521 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
522 NULL, getFont, setClipTitleFont, NULL, NULL},
523 {"ShowClipTitle", "YES", NULL,
524 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
525 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
526 NULL, getFont, setLargeDisplayFont, NULL, NULL},
527 {"HighlightColor", "white", NULL,
528 NULL, getColor, setHightlight, NULL, NULL},
529 {"HighlightTextColor", "black", NULL,
530 NULL, getColor, setHightlightText, NULL, NULL},
531 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
532 NULL, getColor, setClipTitleColor, NULL, NULL},
533 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
534 NULL, getColor, setClipTitleColor, NULL, NULL},
535 {"FTitleColor", "white", (void *)WS_FOCUSED,
536 NULL, getColor, setWTitleColor, NULL, NULL},
537 {"PTitleColor", "white", (void *)WS_PFOCUSED,
538 NULL, getColor, setWTitleColor, NULL, NULL},
539 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
540 NULL, getColor, setWTitleColor, NULL, NULL},
541 {"FTitleBack", "(solid, black)", NULL,
542 NULL, getTexture, setFTitleBack, NULL, NULL},
543 {"PTitleBack", "(solid, \"#616161\")", NULL,
544 NULL, getTexture, setPTitleBack, NULL, NULL},
545 {"UTitleBack", "(solid, gray)", NULL,
546 NULL, getTexture, setUTitleBack, NULL, NULL},
547 {"ResizebarBack", "(solid, gray)", NULL,
548 NULL, getTexture, setResizebarBack, NULL, NULL},
549 {"MenuTitleColor", "white", NULL,
550 NULL, getColor, setMenuTitleColor, NULL, NULL},
551 {"MenuTextColor", "black", NULL,
552 NULL, getColor, setMenuTextColor, NULL, NULL},
553 {"MenuDisabledColor", "\"#616161\"", NULL,
554 NULL, getColor, setMenuDisabledColor, NULL, NULL},
555 {"MenuTitleBack", "(solid, black)", NULL,
556 NULL, getTexture, setMenuTitleBack, NULL, NULL},
557 {"MenuTextBack", "(solid, gray)", NULL,
558 NULL, getTexture, setMenuTextBack, NULL, NULL},
559 {"IconTitleColor", "white", NULL,
560 NULL, getColor, setIconTitleColor, NULL, NULL},
561 {"IconTitleBack", "black", NULL,
562 NULL, getColor, setIconTitleBack, NULL, NULL},
563 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
564 NULL, getPropList, setSwPOptions, NULL, NULL},
565 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
566 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
567 {"FrameBorderWidth", "1", NULL,
568 NULL, getInt, setFrameBorderWidth, NULL, NULL},
569 {"FrameBorderColor", "black", NULL,
570 NULL, getColor, setFrameBorderColor, NULL, NULL},
571 {"FrameSelectedBorderColor", "white", NULL,
572 NULL, getColor, setFrameSelectedBorderColor, NULL, NULL},
574 /* keybindings */
576 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
577 NULL, getKeybind, setKeyGrab, NULL, NULL},
578 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
579 NULL, getKeybind, setKeyGrab, NULL, NULL},
580 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
581 NULL, getKeybind, setKeyGrab, NULL, NULL},
582 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
583 NULL, getKeybind, setKeyGrab, NULL, NULL},
584 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
585 NULL, getKeybind, setKeyGrab, NULL, NULL},
586 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
587 NULL, getKeybind, setKeyGrab, NULL, NULL},
588 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
589 NULL, getKeybind, setKeyGrab, NULL, NULL },
590 {"HideKey", "None", (void *)WKBD_HIDE,
591 NULL, getKeybind, setKeyGrab, NULL, NULL},
592 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
593 NULL, getKeybind, setKeyGrab, NULL, NULL},
594 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
595 NULL, getKeybind, setKeyGrab, NULL, NULL},
596 {"CloseKey", "None", (void *)WKBD_CLOSE,
597 NULL, getKeybind, setKeyGrab, NULL, NULL},
598 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
599 NULL, getKeybind, setKeyGrab, NULL, NULL},
600 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
601 NULL, getKeybind, setKeyGrab, NULL, NULL},
602 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
603 NULL, getKeybind, setKeyGrab, NULL, NULL},
604 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
605 NULL, getKeybind, setKeyGrab, NULL, NULL},
606 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
607 NULL, getKeybind, setKeyGrab, NULL, NULL},
608 {"THMaximizeKey", "None", (void*)WKBD_THMAXIMIZE,
609 NULL, getKeybind, setKeyGrab, NULL, NULL},
610 {"BHMaximizeKey", "None", (void*)WKBD_BHMAXIMIZE,
611 NULL, getKeybind, setKeyGrab, NULL, NULL},
612 {"LTCMaximizeKey", "None", (void*)WKBD_LTCMAXIMIZE,
613 NULL, getKeybind, setKeyGrab, NULL, NULL},
614 {"RTCMaximizeKey", "None", (void*)WKBD_RTCMAXIMIZE,
615 NULL, getKeybind, setKeyGrab, NULL, NULL},
616 {"LBCMaximizeKey", "None", (void*)WKBD_LBCMAXIMIZE,
617 NULL, getKeybind, setKeyGrab, NULL, NULL},
618 {"RBCMaximizeKey", "None", (void*)WKBD_RBCMAXIMIZE,
619 NULL, getKeybind, setKeyGrab, NULL, NULL},
620 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
621 NULL, getKeybind, setKeyGrab, NULL, NULL},
622 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
623 NULL, getKeybind, setKeyGrab, NULL, NULL},
624 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
625 NULL, getKeybind, setKeyGrab, NULL, NULL},
626 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
627 NULL, getKeybind, setKeyGrab, NULL, NULL},
628 {"ShadeKey", "None", (void *)WKBD_SHADE,
629 NULL, getKeybind, setKeyGrab, NULL, NULL},
630 {"SelectKey", "None", (void *)WKBD_SELECT,
631 NULL, getKeybind, setKeyGrab, NULL, NULL},
632 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
633 NULL, getKeybind, setKeyGrab, NULL, NULL},
634 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
635 NULL, getKeybind, setKeyGrab, NULL, NULL},
636 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
637 NULL, getKeybind, setKeyGrab, NULL, NULL},
638 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
639 NULL, getKeybind, setKeyGrab, NULL, NULL},
640 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
641 NULL, getKeybind, setKeyGrab, NULL, NULL},
642 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
643 NULL, getKeybind, setKeyGrab, NULL, NULL},
644 {"LastWorkspaceKey", "None", (void *)WKBD_LASTWORKSPACE,
645 NULL, getKeybind, setKeyGrab, NULL, NULL},
646 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
647 NULL, getKeybind, setKeyGrab, NULL, NULL},
648 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
649 NULL, getKeybind, setKeyGrab, NULL, NULL},
650 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
651 NULL, getKeybind, setKeyGrab, NULL, NULL},
652 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
653 NULL, getKeybind, setKeyGrab, NULL, NULL},
654 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
655 NULL, getKeybind, setKeyGrab, NULL, NULL},
656 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
657 NULL, getKeybind, setKeyGrab, NULL, NULL},
658 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
659 NULL, getKeybind, setKeyGrab, NULL, NULL},
660 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
661 NULL, getKeybind, setKeyGrab, NULL, NULL},
662 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
663 NULL, getKeybind, setKeyGrab, NULL, NULL},
664 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
665 NULL, getKeybind, setKeyGrab, NULL, NULL},
666 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
667 NULL, getKeybind, setKeyGrab, NULL, NULL},
668 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
669 NULL, getKeybind, setKeyGrab, NULL, NULL},
670 {"MoveToWorkspace1Key", "None", (void *)WKBD_MOVE_WORKSPACE1,
671 NULL, getKeybind, setKeyGrab, NULL, NULL},
672 {"MoveToWorkspace2Key", "None", (void *)WKBD_MOVE_WORKSPACE2,
673 NULL, getKeybind, setKeyGrab, NULL, NULL},
674 {"MoveToWorkspace3Key", "None", (void *)WKBD_MOVE_WORKSPACE3,
675 NULL, getKeybind, setKeyGrab, NULL, NULL},
676 {"MoveToWorkspace4Key", "None", (void *)WKBD_MOVE_WORKSPACE4,
677 NULL, getKeybind, setKeyGrab, NULL, NULL},
678 {"MoveToWorkspace5Key", "None", (void *)WKBD_MOVE_WORKSPACE5,
679 NULL, getKeybind, setKeyGrab, NULL, NULL},
680 {"MoveToWorkspace6Key", "None", (void *)WKBD_MOVE_WORKSPACE6,
681 NULL, getKeybind, setKeyGrab, NULL, NULL},
682 {"MoveToWorkspace7Key", "None", (void *)WKBD_MOVE_WORKSPACE7,
683 NULL, getKeybind, setKeyGrab, NULL, NULL},
684 {"MoveToWorkspace8Key", "None", (void *)WKBD_MOVE_WORKSPACE8,
685 NULL, getKeybind, setKeyGrab, NULL, NULL},
686 {"MoveToWorkspace9Key", "None", (void *)WKBD_MOVE_WORKSPACE9,
687 NULL, getKeybind, setKeyGrab, NULL, NULL},
688 {"MoveToWorkspace10Key", "None", (void *)WKBD_MOVE_WORKSPACE10,
689 NULL, getKeybind, setKeyGrab, NULL, NULL},
690 {"MoveToNextWorkspaceKey", "None", (void *)WKBD_MOVE_NEXTWORKSPACE,
691 NULL, getKeybind, setKeyGrab, NULL, NULL},
692 {"MoveToPrevWorkspaceKey", "None", (void *)WKBD_MOVE_PREVWORKSPACE,
693 NULL, getKeybind, setKeyGrab, NULL, NULL},
694 {"MoveToLastWorkspaceKey", "None", (void *)WKBD_MOVE_LASTWORKSPACE,
695 NULL, getKeybind, setKeyGrab, NULL, NULL},
696 {"MoveToNextWorkspaceLayerKey", "None", (void *)WKBD_MOVE_NEXTWSLAYER,
697 NULL, getKeybind, setKeyGrab, NULL, NULL},
698 {"MoveToPrevWorkspaceLayerKey", "None", (void *)WKBD_MOVE_PREVWSLAYER,
699 NULL, getKeybind, setKeyGrab, NULL, NULL},
700 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
701 NULL, getKeybind, setKeyGrab, NULL, NULL},
702 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
703 NULL, getKeybind, setKeyGrab, NULL, NULL},
704 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
705 NULL, getKeybind, setKeyGrab, NULL, NULL},
706 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
707 NULL, getKeybind, setKeyGrab, NULL, NULL},
708 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
709 NULL, getKeybind, setKeyGrab, NULL, NULL},
710 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
711 NULL, getKeybind, setKeyGrab, NULL, NULL},
712 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
713 NULL, getKeybind, setKeyGrab, NULL, NULL},
714 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
715 NULL, getKeybind, setKeyGrab, NULL, NULL},
716 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
717 NULL, getKeybind, setKeyGrab, NULL, NULL},
718 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
719 NULL, getKeybind, setKeyGrab, NULL, NULL},
720 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
721 NULL, getKeybind, setKeyGrab, NULL, NULL},
722 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
723 NULL, getKeybind, setKeyGrab, NULL, NULL},
725 #ifdef KEEP_XKB_LOCK_STATUS
726 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
727 NULL, getKeybind, setKeyGrab, NULL, NULL},
728 {"KbdModeLock", "NO", NULL,
729 &wPreferences.modelock, getBool, NULL, NULL, NULL},
730 #endif /* KEEP_XKB_LOCK_STATUS */
732 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
733 NULL, getCursor, setCursor, NULL, NULL},
734 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
735 NULL, getCursor, setCursor, NULL, NULL},
736 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
737 NULL, getCursor, setCursor, NULL, NULL},
738 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
739 NULL, getCursor, setCursor, NULL, NULL},
740 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
741 NULL, getCursor, setCursor, NULL, NULL},
742 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
743 NULL, getCursor, setCursor, NULL, NULL},
744 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
745 NULL, getCursor, setCursor, NULL, NULL},
746 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
747 NULL, getCursor, setCursor, NULL, NULL},
748 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
749 NULL, getCursor, setCursor, NULL, NULL},
750 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
751 NULL, getCursor, setCursor, NULL, NULL},
752 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
753 NULL, getCursor, setCursor, NULL, NULL},
754 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
755 NULL, getCursor, setCursor, NULL, NULL},
756 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
757 NULL, getCursor, setCursor, NULL, NULL},
758 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
759 NULL, getCursor, setCursor, NULL, NULL},
760 {"DialogHistoryLines", "500", NULL,
761 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
762 {"CycleActiveHeadOnly", "NO", NULL,
763 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL},
764 {"CycleIgnoreMinimized", "NO", NULL,
765 &wPreferences.cycle_ignore_minimized, getBool, NULL, NULL, NULL}
768 static void initDefaults(void)
770 unsigned int i;
771 WDefaultEntry *entry;
773 WMPLSetCaseSensitive(False);
775 for (i = 0; i < wlengthof(optionList); i++) {
776 entry = &optionList[i];
778 entry->plkey = WMCreatePLString(entry->key);
779 if (entry->default_value)
780 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
781 else
782 entry->plvalue = NULL;
785 for (i = 0; i < wlengthof(staticOptionList); i++) {
786 entry = &staticOptionList[i];
788 entry->plkey = WMCreatePLString(entry->key);
789 if (entry->default_value)
790 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
791 else
792 entry->plvalue = NULL;
796 static WMPropList *readGlobalDomain(const char *domainName, Bool requireDictionary)
798 WMPropList *globalDict = NULL;
799 char path[PATH_MAX];
800 struct stat stbuf;
802 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
803 if (stat(path, &stbuf) >= 0) {
804 globalDict = WMReadPropListFromFile(path);
805 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
806 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
807 WMReleasePropList(globalDict);
808 globalDict = NULL;
809 } else if (!globalDict) {
810 wwarning(_("could not load domain %s from global defaults database"), domainName);
814 return globalDict;
817 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
818 static void prependMenu(WMPropList * destarr, WMPropList * array)
820 WMPropList *item;
821 int i;
823 for (i = 0; i < WMGetPropListItemCount(array); i++) {
824 item = WMGetFromPLArray(array, i);
825 if (item)
826 WMInsertInPLArray(destarr, i + 1, item);
830 static void appendMenu(WMPropList * destarr, WMPropList * array)
832 WMPropList *item;
833 int i;
835 for (i = 0; i < WMGetPropListItemCount(array); i++) {
836 item = WMGetFromPLArray(array, i);
837 if (item)
838 WMAddToPLArray(destarr, item);
841 #endif
843 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
845 WMPropList *menu = menuDomain->dictionary;
846 WMPropList *submenu;
848 if (!menu || !WMIsPLArray(menu))
849 return;
851 #ifdef GLOBAL_PREAMBLE_MENU_FILE
852 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
854 if (submenu && !WMIsPLArray(submenu)) {
855 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
856 WMReleasePropList(submenu);
857 submenu = NULL;
859 if (submenu) {
860 prependMenu(menu, submenu);
861 WMReleasePropList(submenu);
863 #endif
865 #ifdef GLOBAL_EPILOGUE_MENU_FILE
866 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
868 if (submenu && !WMIsPLArray(submenu)) {
869 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
870 WMReleasePropList(submenu);
871 submenu = NULL;
873 if (submenu) {
874 appendMenu(menu, submenu);
875 WMReleasePropList(submenu);
877 #endif
879 menuDomain->dictionary = menu;
882 WDDomain *wDefaultsInitDomain(const char *domain, Bool requireDictionary)
884 WDDomain *db;
885 struct stat stbuf;
886 static int inited = 0;
887 const char *the_path;
888 WMPropList *shared_dict = NULL;
890 if (!inited) {
891 inited = 1;
892 initDefaults();
895 db = wmalloc(sizeof(WDDomain));
896 db->domain_name = domain;
897 db->path = wdefaultspathfordomain(domain);
898 the_path = db->path;
900 if (the_path && stat(the_path, &stbuf) >= 0) {
901 db->dictionary = WMReadPropListFromFile(the_path);
902 if (db->dictionary) {
903 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
904 WMReleasePropList(db->dictionary);
905 db->dictionary = NULL;
906 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
908 db->timestamp = stbuf.st_mtime;
909 } else {
910 wwarning(_("could not load domain %s from user defaults database"), domain);
914 /* global system dictionary */
915 shared_dict = readGlobalDomain(domain, requireDictionary);
917 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
918 WMIsPLDictionary(db->dictionary)) {
919 WMMergePLDictionaries(shared_dict, db->dictionary, True);
920 WMReleasePropList(db->dictionary);
921 db->dictionary = shared_dict;
922 if (stbuf.st_mtime > db->timestamp)
923 db->timestamp = stbuf.st_mtime;
924 } else if (!db->dictionary) {
925 db->dictionary = shared_dict;
926 if (stbuf.st_mtime > db->timestamp)
927 db->timestamp = stbuf.st_mtime;
930 return db;
933 void wReadStaticDefaults(WMPropList * dict)
935 WMPropList *plvalue;
936 WDefaultEntry *entry;
937 unsigned int i;
938 void *tdata;
940 for (i = 0; i < wlengthof(staticOptionList); i++) {
941 entry = &staticOptionList[i];
943 if (dict)
944 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
945 else
946 plvalue = NULL;
948 /* no default in the DB. Use builtin default */
949 if (!plvalue)
950 plvalue = entry->plvalue;
952 if (plvalue) {
953 /* convert data */
954 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
955 if (entry->update)
956 (*entry->update) (NULL, entry, tdata, entry->extra_data);
961 void wDefaultsCheckDomains(void* arg)
963 WScreen *scr;
964 struct stat stbuf;
965 WMPropList *shared_dict = NULL;
966 WMPropList *dict;
967 int i;
969 /* Parameter not used, but tell the compiler that it is ok */
970 (void) arg;
972 if (stat(w_global.domain.wmaker->path, &stbuf) >= 0 && w_global.domain.wmaker->timestamp < stbuf.st_mtime) {
973 w_global.domain.wmaker->timestamp = stbuf.st_mtime;
975 /* Global dictionary */
976 shared_dict = readGlobalDomain("WindowMaker", True);
978 /* User dictionary */
979 dict = WMReadPropListFromFile(w_global.domain.wmaker->path);
981 if (dict) {
982 if (!WMIsPLDictionary(dict)) {
983 WMReleasePropList(dict);
984 dict = NULL;
985 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
986 "WindowMaker", w_global.domain.wmaker->path);
987 } else {
988 if (shared_dict) {
989 WMMergePLDictionaries(shared_dict, dict, True);
990 WMReleasePropList(dict);
991 dict = shared_dict;
992 shared_dict = NULL;
995 for (i = 0; i < w_global.screen_count; i++) {
996 scr = wScreenWithNumber(i);
997 if (scr)
998 wReadDefaults(scr, dict);
1001 if (w_global.domain.wmaker->dictionary)
1002 WMReleasePropList(w_global.domain.wmaker->dictionary);
1004 w_global.domain.wmaker->dictionary = dict;
1006 } else {
1007 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1010 if (shared_dict)
1011 WMReleasePropList(shared_dict);
1015 if (stat(w_global.domain.window_attr->path, &stbuf) >= 0 && w_global.domain.window_attr->timestamp < stbuf.st_mtime) {
1016 /* global dictionary */
1017 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1018 /* user dictionary */
1019 dict = WMReadPropListFromFile(w_global.domain.window_attr->path);
1020 if (dict) {
1021 if (!WMIsPLDictionary(dict)) {
1022 WMReleasePropList(dict);
1023 dict = NULL;
1024 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1025 "WMWindowAttributes", w_global.domain.window_attr->path);
1026 } else {
1027 if (shared_dict) {
1028 WMMergePLDictionaries(shared_dict, dict, True);
1029 WMReleasePropList(dict);
1030 dict = shared_dict;
1031 shared_dict = NULL;
1034 if (w_global.domain.window_attr->dictionary)
1035 WMReleasePropList(w_global.domain.window_attr->dictionary);
1037 w_global.domain.window_attr->dictionary = dict;
1038 for (i = 0; i < w_global.screen_count; i++) {
1039 scr = wScreenWithNumber(i);
1040 if (scr) {
1041 wDefaultUpdateIcons(scr);
1043 /* Update the panel image if changed */
1044 /* Don't worry. If the image is the same these
1045 * functions will have no performance impact. */
1046 create_logo_image(scr);
1050 } else {
1051 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1054 w_global.domain.window_attr->timestamp = stbuf.st_mtime;
1055 if (shared_dict)
1056 WMReleasePropList(shared_dict);
1059 if (stat(w_global.domain.root_menu->path, &stbuf) >= 0 && w_global.domain.root_menu->timestamp < stbuf.st_mtime) {
1060 dict = WMReadPropListFromFile(w_global.domain.root_menu->path);
1061 if (dict) {
1062 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1063 WMReleasePropList(dict);
1064 dict = NULL;
1065 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1066 "WMRootMenu", w_global.domain.root_menu->path);
1067 } else {
1068 if (w_global.domain.root_menu->dictionary)
1069 WMReleasePropList(w_global.domain.root_menu->dictionary);
1071 w_global.domain.root_menu->dictionary = dict;
1072 wDefaultsMergeGlobalMenus(w_global.domain.root_menu);
1074 } else {
1075 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1077 w_global.domain.root_menu->timestamp = stbuf.st_mtime;
1079 #ifndef HAVE_INOTIFY
1080 if (!arg)
1081 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1082 #endif
1085 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1087 WMPropList *plvalue, *old_value;
1088 WDefaultEntry *entry;
1089 unsigned int i;
1090 int update_workspace_back = 0; /* kluge :/ */
1091 unsigned int needs_refresh;
1092 void *tdata;
1093 WMPropList *old_dict = (w_global.domain.wmaker->dictionary != new_dict ? w_global.domain.wmaker->dictionary : NULL);
1095 needs_refresh = 0;
1097 for (i = 0; i < wlengthof(optionList); i++) {
1098 entry = &optionList[i];
1100 if (new_dict)
1101 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1102 else
1103 plvalue = NULL;
1105 if (!old_dict)
1106 old_value = NULL;
1107 else
1108 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1110 if (!plvalue && !old_value) {
1111 /* no default in the DB. Use builtin default */
1112 plvalue = entry->plvalue;
1113 if (plvalue && new_dict)
1114 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1116 } else if (!plvalue) {
1117 /* value was deleted from DB. Keep current value */
1118 continue;
1119 } else if (!old_value) {
1120 /* set value for the 1st time */
1121 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1122 /* value has changed */
1123 } else {
1124 if (strcmp(entry->key, "WorkspaceBack") == 0
1125 && update_workspace_back && scr->flags.backimage_helper_launched) {
1126 } else {
1127 /* value was not changed since last time */
1128 continue;
1132 if (plvalue) {
1133 /* convert data */
1134 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1136 * If the WorkspaceSpecificBack data has been changed
1137 * so that the helper will be launched now, we must be
1138 * sure to send the default background texture config
1139 * to the helper.
1141 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1142 !scr->flags.backimage_helper_launched)
1143 update_workspace_back = 1;
1145 if (entry->update)
1146 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1152 if (needs_refresh != 0 && !scr->flags.startup) {
1153 int foo;
1155 foo = 0;
1156 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1157 foo |= WTextureSettings;
1158 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1159 foo |= WFontSettings;
1160 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1161 foo |= WColorSettings;
1162 if (foo)
1163 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1164 (void *)(uintptr_t) foo);
1166 foo = 0;
1167 if (needs_refresh & REFRESH_MENU_TEXTURE)
1168 foo |= WTextureSettings;
1169 if (needs_refresh & REFRESH_MENU_FONT)
1170 foo |= WFontSettings;
1171 if (needs_refresh & REFRESH_MENU_COLOR)
1172 foo |= WColorSettings;
1173 if (foo)
1174 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1176 foo = 0;
1177 if (needs_refresh & REFRESH_WINDOW_FONT)
1178 foo |= WFontSettings;
1179 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1180 foo |= WTextureSettings;
1181 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1182 foo |= WColorSettings;
1183 if (foo)
1184 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1186 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1187 foo = 0;
1188 if (needs_refresh & REFRESH_ICON_FONT)
1189 foo |= WFontSettings;
1190 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1191 foo |= WTextureSettings;
1192 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1193 foo |= WTextureSettings;
1194 if (foo)
1195 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1196 (void *)(uintptr_t) foo);
1198 if (needs_refresh & REFRESH_ICON_TILE)
1199 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1201 if (needs_refresh & REFRESH_WORKSPACE_MENU) {
1202 if (w_global.workspace.menu)
1203 wWorkspaceMenuUpdate(w_global.workspace.menu);
1204 if (w_global.clip.ws_menu)
1205 wWorkspaceMenuUpdate(w_global.clip.ws_menu);
1206 if (w_global.workspace.submenu)
1207 w_global.workspace.submenu->flags.realized = 0;
1208 if (w_global.clip.submenu)
1209 w_global.clip.submenu->flags.realized = 0;
1214 void wDefaultUpdateIcons(WScreen *scr)
1216 WAppIcon *aicon = w_global.app_icon_list;
1217 WDrawerChain *dc;
1218 WWindow *wwin = scr->focused_window;
1220 while (aicon) {
1221 /* Get the application icon, default included */
1222 wIconChangeImageFile(aicon->icon, NULL);
1223 wAppIconPaint(aicon);
1224 aicon = aicon->next;
1227 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock)
1228 wClipIconPaint();
1230 for (dc = scr->drawers; dc != NULL; dc = dc->next)
1231 wDrawerIconPaint(dc->adrawer->icon_array[0]);
1233 while (wwin) {
1234 if (wwin->icon && wwin->flags.miniaturized)
1235 wIconChangeImageFile(wwin->icon, NULL);
1236 wwin = wwin->prev;
1240 /* --------------------------- Local ----------------------- */
1242 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1243 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1244 entry->key, x); \
1245 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1246 var = entry->default_value;\
1247 } else var = WMGetFromPLString(value)\
1250 static int string2index(WMPropList *key, WMPropList *val, const char *def, WOptionEnumeration * values)
1252 char *str;
1253 WOptionEnumeration *v;
1254 char buffer[TOTAL_VALUES_LENGTH];
1256 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1257 for (v = values; v->string != NULL; v++) {
1258 if (strcasecmp(v->string, str) == 0)
1259 return v->value;
1263 buffer[0] = 0;
1264 for (v = values; v->string != NULL; v++) {
1265 if (!v->is_alias) {
1266 if (buffer[0] != 0)
1267 strcat(buffer, ", ");
1268 snprintf(buffer+strlen(buffer),
1269 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1272 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1273 WMGetFromPLString(key),
1274 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1275 buffer);
1277 if (def) {
1278 return string2index(key, val, NULL, values);
1281 return -1;
1285 * value - is the value in the defaults DB
1286 * addr - is the address to store the data
1287 * ret - is the address to store a pointer to a temporary buffer. ret
1288 * must not be freed and is used by the set functions
1290 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1292 static char data;
1293 const char *val;
1294 int second_pass = 0;
1296 /* Parameter not used, but tell the compiler that it is ok */
1297 (void) scr;
1299 GET_STRING_OR_DEFAULT("Boolean", val);
1301 again:
1302 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1303 || strcasecmp(val, "YES") == 0) {
1305 data = 1;
1306 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1307 || strcasecmp(val, "NO") == 0) {
1308 data = 0;
1309 } else {
1310 int i;
1311 if (sscanf(val, "%i", &i) == 1) {
1312 if (i != 0)
1313 data = 1;
1314 else
1315 data = 0;
1316 } else {
1317 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1318 if (second_pass == 0) {
1319 val = WMGetFromPLString(entry->plvalue);
1320 second_pass = 1;
1321 wwarning(_("using default \"%s\" instead"), val);
1322 goto again;
1324 return False;
1328 if (ret)
1329 *ret = &data;
1330 if (addr)
1331 *(char *)addr = data;
1333 return True;
1336 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1338 static int data;
1339 const char *val;
1341 /* Parameter not used, but tell the compiler that it is ok */
1342 (void) scr;
1344 GET_STRING_OR_DEFAULT("Integer", val);
1346 if (sscanf(val, "%i", &data) != 1) {
1347 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1348 val = WMGetFromPLString(entry->plvalue);
1349 wwarning(_("using default \"%s\" instead"), val);
1350 if (sscanf(val, "%i", &data) != 1) {
1351 return False;
1355 if (ret)
1356 *ret = &data;
1357 if (addr)
1358 *(int *)addr = data;
1360 return True;
1363 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1365 static WCoord data;
1366 char *val_x, *val_y;
1367 int nelem, changed = 0;
1368 WMPropList *elem_x, *elem_y;
1370 again:
1371 if (!WMIsPLArray(value)) {
1372 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1373 if (changed == 0) {
1374 value = entry->plvalue;
1375 changed = 1;
1376 wwarning(_("using default \"%s\" instead"), entry->default_value);
1377 goto again;
1379 return False;
1382 nelem = WMGetPropListItemCount(value);
1383 if (nelem != 2) {
1384 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1385 if (changed == 0) {
1386 value = entry->plvalue;
1387 changed = 1;
1388 wwarning(_("using default \"%s\" instead"), entry->default_value);
1389 goto again;
1391 return False;
1394 elem_x = WMGetFromPLArray(value, 0);
1395 elem_y = WMGetFromPLArray(value, 1);
1397 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1398 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1399 if (changed == 0) {
1400 value = entry->plvalue;
1401 changed = 1;
1402 wwarning(_("using default \"%s\" instead"), entry->default_value);
1403 goto again;
1405 return False;
1408 val_x = WMGetFromPLString(elem_x);
1409 val_y = WMGetFromPLString(elem_y);
1411 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1412 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1413 if (changed == 0) {
1414 value = entry->plvalue;
1415 changed = 1;
1416 wwarning(_("using default \"%s\" instead"), entry->default_value);
1417 goto again;
1419 return False;
1422 if (data.x < 0)
1423 data.x = 0;
1424 else if (data.x > scr->scr_width / 3)
1425 data.x = scr->scr_width / 3;
1426 if (data.y < 0)
1427 data.y = 0;
1428 else if (data.y > scr->scr_height / 3)
1429 data.y = scr->scr_height / 3;
1431 if (ret)
1432 *ret = &data;
1433 if (addr)
1434 *(WCoord *) addr = data;
1436 return True;
1439 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1441 /* Parameter not used, but tell the compiler that it is ok */
1442 (void) scr;
1443 (void) entry;
1444 (void) addr;
1446 WMRetainPropList(value);
1448 *ret = value;
1450 return True;
1453 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1455 static char *data;
1456 int i, count, len;
1457 char *ptr;
1458 WMPropList *d;
1459 int changed = 0;
1461 /* Parameter not used, but tell the compiler that it is ok */
1462 (void) scr;
1463 (void) ret;
1465 again:
1466 if (!WMIsPLArray(value)) {
1467 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1468 if (changed == 0) {
1469 value = entry->plvalue;
1470 changed = 1;
1471 wwarning(_("using default \"%s\" instead"), entry->default_value);
1472 goto again;
1474 return False;
1477 i = 0;
1478 count = WMGetPropListItemCount(value);
1479 if (count < 1) {
1480 if (changed == 0) {
1481 value = entry->plvalue;
1482 changed = 1;
1483 wwarning(_("using default \"%s\" instead"), entry->default_value);
1484 goto again;
1486 return False;
1489 len = 0;
1490 for (i = 0; i < count; i++) {
1491 d = WMGetFromPLArray(value, i);
1492 if (!d || !WMIsPLString(d)) {
1493 count = i;
1494 break;
1496 len += strlen(WMGetFromPLString(d)) + 1;
1499 ptr = data = wmalloc(len + 1);
1501 for (i = 0; i < count; i++) {
1502 d = WMGetFromPLArray(value, i);
1503 if (!d || !WMIsPLString(d)) {
1504 break;
1506 strcpy(ptr, WMGetFromPLString(d));
1507 ptr += strlen(WMGetFromPLString(d));
1508 *ptr = ':';
1509 ptr++;
1511 ptr--;
1512 *(ptr--) = 0;
1514 if (*(char **)addr != NULL) {
1515 wfree(*(char **)addr);
1517 *(char **)addr = data;
1519 return True;
1522 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1524 static signed char data;
1526 /* Parameter not used, but tell the compiler that it is ok */
1527 (void) scr;
1529 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1530 if (data < 0)
1531 return False;
1533 if (ret)
1534 *ret = &data;
1535 if (addr)
1536 *(signed char *)addr = data;
1538 return True;
1542 * (solid <color>)
1543 * (hgradient <color> <color>)
1544 * (vgradient <color> <color>)
1545 * (dgradient <color> <color>)
1546 * (mhgradient <color> <color> ...)
1547 * (mvgradient <color> <color> ...)
1548 * (mdgradient <color> <color> ...)
1549 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1550 * (tpixmap <file> <color>)
1551 * (spixmap <file> <color>)
1552 * (cpixmap <file> <color>)
1553 * (thgradient <file> <opaqueness> <color> <color>)
1554 * (tvgradient <file> <opaqueness> <color> <color>)
1555 * (tdgradient <file> <opaqueness> <color> <color>)
1556 * (function <lib> <function> ...)
1559 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1561 WMPropList *elem;
1562 char *val;
1563 int nelem;
1564 WTexture *texture = NULL;
1566 nelem = WMGetPropListItemCount(pl);
1567 if (nelem < 1)
1568 return NULL;
1570 elem = WMGetFromPLArray(pl, 0);
1571 if (!elem || !WMIsPLString(elem))
1572 return NULL;
1573 val = WMGetFromPLString(elem);
1575 if (strcasecmp(val, "solid") == 0) {
1576 XColor color;
1578 if (nelem != 2)
1579 return NULL;
1581 /* get color */
1583 elem = WMGetFromPLArray(pl, 1);
1584 if (!elem || !WMIsPLString(elem))
1585 return NULL;
1586 val = WMGetFromPLString(elem);
1588 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1589 wwarning(_("\"%s\" is not a valid color name"), val);
1590 return NULL;
1593 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1594 } else if (strcasecmp(val, "dgradient") == 0
1595 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1596 RColor color1, color2;
1597 XColor xcolor;
1598 int type;
1600 if (nelem != 3) {
1601 wwarning(_("bad number of arguments in gradient specification"));
1602 return NULL;
1605 if (val[0] == 'd' || val[0] == 'D')
1606 type = WTEX_DGRADIENT;
1607 else if (val[0] == 'h' || val[0] == 'H')
1608 type = WTEX_HGRADIENT;
1609 else
1610 type = WTEX_VGRADIENT;
1612 /* get from color */
1613 elem = WMGetFromPLArray(pl, 1);
1614 if (!elem || !WMIsPLString(elem))
1615 return NULL;
1616 val = WMGetFromPLString(elem);
1618 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1619 wwarning(_("\"%s\" is not a valid color name"), val);
1620 return NULL;
1622 color1.alpha = 255;
1623 color1.red = xcolor.red >> 8;
1624 color1.green = xcolor.green >> 8;
1625 color1.blue = xcolor.blue >> 8;
1627 /* get to color */
1628 elem = WMGetFromPLArray(pl, 2);
1629 if (!elem || !WMIsPLString(elem)) {
1630 return NULL;
1632 val = WMGetFromPLString(elem);
1634 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1635 wwarning(_("\"%s\" is not a valid color name"), val);
1636 return NULL;
1638 color2.alpha = 255;
1639 color2.red = xcolor.red >> 8;
1640 color2.green = xcolor.green >> 8;
1641 color2.blue = xcolor.blue >> 8;
1643 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1645 } else if (strcasecmp(val, "igradient") == 0) {
1646 RColor colors1[2], colors2[2];
1647 int th1, th2;
1648 XColor xcolor;
1649 int i;
1651 if (nelem != 7) {
1652 wwarning(_("bad number of arguments in gradient specification"));
1653 return NULL;
1656 /* get from color */
1657 for (i = 0; i < 2; i++) {
1658 elem = WMGetFromPLArray(pl, 1 + i);
1659 if (!elem || !WMIsPLString(elem))
1660 return NULL;
1661 val = WMGetFromPLString(elem);
1663 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1664 wwarning(_("\"%s\" is not a valid color name"), val);
1665 return NULL;
1667 colors1[i].alpha = 255;
1668 colors1[i].red = xcolor.red >> 8;
1669 colors1[i].green = xcolor.green >> 8;
1670 colors1[i].blue = xcolor.blue >> 8;
1672 elem = WMGetFromPLArray(pl, 3);
1673 if (!elem || !WMIsPLString(elem))
1674 return NULL;
1675 val = WMGetFromPLString(elem);
1676 th1 = atoi(val);
1678 /* get from color */
1679 for (i = 0; i < 2; i++) {
1680 elem = WMGetFromPLArray(pl, 4 + i);
1681 if (!elem || !WMIsPLString(elem))
1682 return NULL;
1683 val = WMGetFromPLString(elem);
1685 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1686 wwarning(_("\"%s\" is not a valid color name"), val);
1687 return NULL;
1689 colors2[i].alpha = 255;
1690 colors2[i].red = xcolor.red >> 8;
1691 colors2[i].green = xcolor.green >> 8;
1692 colors2[i].blue = xcolor.blue >> 8;
1694 elem = WMGetFromPLArray(pl, 6);
1695 if (!elem || !WMIsPLString(elem))
1696 return NULL;
1697 val = WMGetFromPLString(elem);
1698 th2 = atoi(val);
1700 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1702 } else if (strcasecmp(val, "mhgradient") == 0
1703 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1704 XColor color;
1705 RColor **colors;
1706 int i, count;
1707 int type;
1709 if (nelem < 3) {
1710 wwarning(_("too few arguments in multicolor gradient specification"));
1711 return NULL;
1714 if (val[1] == 'h' || val[1] == 'H')
1715 type = WTEX_MHGRADIENT;
1716 else if (val[1] == 'v' || val[1] == 'V')
1717 type = WTEX_MVGRADIENT;
1718 else
1719 type = WTEX_MDGRADIENT;
1721 count = nelem - 1;
1723 colors = wmalloc(sizeof(RColor *) * (count + 1));
1725 for (i = 0; i < count; i++) {
1726 elem = WMGetFromPLArray(pl, i + 1);
1727 if (!elem || !WMIsPLString(elem)) {
1728 for (--i; i >= 0; --i) {
1729 wfree(colors[i]);
1731 wfree(colors);
1732 return NULL;
1734 val = WMGetFromPLString(elem);
1736 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1737 wwarning(_("\"%s\" is not a valid color name"), val);
1738 for (--i; i >= 0; --i) {
1739 wfree(colors[i]);
1741 wfree(colors);
1742 return NULL;
1743 } else {
1744 colors[i] = wmalloc(sizeof(RColor));
1745 colors[i]->red = color.red >> 8;
1746 colors[i]->green = color.green >> 8;
1747 colors[i]->blue = color.blue >> 8;
1750 colors[i] = NULL;
1752 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1753 } else if (strcasecmp(val, "spixmap") == 0 ||
1754 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1755 XColor color;
1756 int type;
1758 if (nelem != 3)
1759 return NULL;
1761 if (val[0] == 's' || val[0] == 'S')
1762 type = WTP_SCALE;
1763 else if (val[0] == 'c' || val[0] == 'C')
1764 type = WTP_CENTER;
1765 else
1766 type = WTP_TILE;
1768 /* get color */
1769 elem = WMGetFromPLArray(pl, 2);
1770 if (!elem || !WMIsPLString(elem)) {
1771 return NULL;
1773 val = WMGetFromPLString(elem);
1775 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1776 wwarning(_("\"%s\" is not a valid color name"), val);
1777 return NULL;
1780 /* file name */
1781 elem = WMGetFromPLArray(pl, 1);
1782 if (!elem || !WMIsPLString(elem))
1783 return NULL;
1784 val = WMGetFromPLString(elem);
1786 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1787 } else if (strcasecmp(val, "thgradient") == 0
1788 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1789 RColor color1, color2;
1790 XColor xcolor;
1791 int opacity;
1792 int style;
1794 if (val[1] == 'h' || val[1] == 'H')
1795 style = WTEX_THGRADIENT;
1796 else if (val[1] == 'v' || val[1] == 'V')
1797 style = WTEX_TVGRADIENT;
1798 else
1799 style = WTEX_TDGRADIENT;
1801 if (nelem != 5) {
1802 wwarning(_("bad number of arguments in textured gradient specification"));
1803 return NULL;
1806 /* get from color */
1807 elem = WMGetFromPLArray(pl, 3);
1808 if (!elem || !WMIsPLString(elem))
1809 return NULL;
1810 val = WMGetFromPLString(elem);
1812 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1813 wwarning(_("\"%s\" is not a valid color name"), val);
1814 return NULL;
1816 color1.alpha = 255;
1817 color1.red = xcolor.red >> 8;
1818 color1.green = xcolor.green >> 8;
1819 color1.blue = xcolor.blue >> 8;
1821 /* get to color */
1822 elem = WMGetFromPLArray(pl, 4);
1823 if (!elem || !WMIsPLString(elem)) {
1824 return NULL;
1826 val = WMGetFromPLString(elem);
1828 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1829 wwarning(_("\"%s\" is not a valid color name"), val);
1830 return NULL;
1832 color2.alpha = 255;
1833 color2.red = xcolor.red >> 8;
1834 color2.green = xcolor.green >> 8;
1835 color2.blue = xcolor.blue >> 8;
1837 /* get opacity */
1838 elem = WMGetFromPLArray(pl, 2);
1839 if (!elem || !WMIsPLString(elem))
1840 opacity = 128;
1841 else
1842 val = WMGetFromPLString(elem);
1844 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1845 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1846 opacity = 128;
1849 /* get file name */
1850 elem = WMGetFromPLArray(pl, 1);
1851 if (!elem || !WMIsPLString(elem))
1852 return NULL;
1853 val = WMGetFromPLString(elem);
1855 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1856 } else if (strcasecmp(val, "function") == 0) {
1857 /* Leave this in to handle the unlikely case of
1858 * someone actually having function textures configured */
1859 wwarning("function texture support has been removed");
1860 return NULL;
1861 } else {
1862 wwarning(_("invalid texture type %s"), val);
1863 return NULL;
1865 return texture;
1868 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1870 static WTexture *texture;
1871 int changed = 0;
1873 again:
1874 if (!WMIsPLArray(value)) {
1875 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1876 if (changed == 0) {
1877 value = entry->plvalue;
1878 changed = 1;
1879 wwarning(_("using default \"%s\" instead"), entry->default_value);
1880 goto again;
1882 return False;
1885 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1886 WMPropList *pl;
1888 pl = WMGetFromPLArray(value, 0);
1889 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1890 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1891 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1892 entry->key, "Solid Texture");
1894 value = entry->plvalue;
1895 changed = 1;
1896 wwarning(_("using default \"%s\" instead"), entry->default_value);
1897 goto again;
1901 texture = parse_texture(scr, value);
1903 if (!texture) {
1904 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1905 if (changed == 0) {
1906 value = entry->plvalue;
1907 changed = 1;
1908 wwarning(_("using default \"%s\" instead"), entry->default_value);
1909 goto again;
1911 return False;
1914 if (ret)
1915 *ret = &texture;
1917 if (addr)
1918 *(WTexture **) addr = texture;
1920 return True;
1923 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1925 WMPropList *elem;
1926 int changed = 0;
1927 char *val;
1928 int nelem;
1930 /* Parameter not used, but tell the compiler that it is ok */
1931 (void) scr;
1932 (void) addr;
1934 again:
1935 if (!WMIsPLArray(value)) {
1936 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1937 "WorkspaceBack", "Texture or None");
1938 if (changed == 0) {
1939 value = entry->plvalue;
1940 changed = 1;
1941 wwarning(_("using default \"%s\" instead"), entry->default_value);
1942 goto again;
1944 return False;
1947 /* only do basic error checking and verify for None texture */
1949 nelem = WMGetPropListItemCount(value);
1950 if (nelem > 0) {
1951 elem = WMGetFromPLArray(value, 0);
1952 if (!elem || !WMIsPLString(elem)) {
1953 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1954 if (changed == 0) {
1955 value = entry->plvalue;
1956 changed = 1;
1957 wwarning(_("using default \"%s\" instead"), entry->default_value);
1958 goto again;
1960 return False;
1962 val = WMGetFromPLString(elem);
1964 if (strcasecmp(val, "None") == 0)
1965 return True;
1967 *ret = WMRetainPropList(value);
1969 return True;
1972 static int
1973 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1975 WMPropList *elem;
1976 int nelem;
1977 int changed = 0;
1979 /* Parameter not used, but tell the compiler that it is ok */
1980 (void) scr;
1981 (void) addr;
1983 again:
1984 if (!WMIsPLArray(value)) {
1985 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1986 "WorkspaceSpecificBack", "an array of textures");
1987 if (changed == 0) {
1988 value = entry->plvalue;
1989 changed = 1;
1990 wwarning(_("using default \"%s\" instead"), entry->default_value);
1991 goto again;
1993 return False;
1996 /* only do basic error checking and verify for None texture */
1998 nelem = WMGetPropListItemCount(value);
1999 if (nelem > 0) {
2000 while (nelem--) {
2001 elem = WMGetFromPLArray(value, nelem);
2002 if (!elem || !WMIsPLArray(elem)) {
2003 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2004 nelem);
2009 *ret = WMRetainPropList(value);
2011 #ifdef notworking
2013 * Kluge to force wmsetbg helper to set the default background.
2014 * If the WorkspaceSpecificBack is changed once wmaker has started,
2015 * the WorkspaceBack won't be sent to the helper, unless the user
2016 * changes it's value too. So, we must force this by removing the
2017 * value from the defaults DB.
2019 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2020 WMPropList *key = WMCreatePLString("WorkspaceBack");
2022 WMRemoveFromPLDictionary(w_global.domain.wmaker->dictionary, key);
2024 WMReleasePropList(key);
2026 #endif
2027 return True;
2030 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2032 static WMFont *font;
2033 const char *val;
2035 GET_STRING_OR_DEFAULT("Font", val);
2037 font = WMCreateFont(scr->wmscreen, val);
2038 if (!font)
2039 font = WMCreateFont(scr->wmscreen, "fixed");
2041 if (!font) {
2042 wfatal(_("could not load any usable font!!!"));
2043 exit(1);
2046 if (ret)
2047 *ret = font;
2049 /* can't assign font value outside update function */
2050 wassertrv(addr == NULL, True);
2052 return True;
2055 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2057 static XColor color;
2058 const char *val;
2059 int second_pass = 0;
2061 GET_STRING_OR_DEFAULT("Color", val);
2063 again:
2064 if (!wGetColor(scr, val, &color)) {
2065 wwarning(_("could not get color for key \"%s\""), entry->key);
2066 if (second_pass == 0) {
2067 val = WMGetFromPLString(entry->plvalue);
2068 second_pass = 1;
2069 wwarning(_("using default \"%s\" instead"), val);
2070 goto again;
2072 return False;
2075 if (ret)
2076 *ret = &color;
2078 assert(addr == NULL);
2080 if (addr)
2081 *(unsigned long*)addr = pixel;
2084 return True;
2087 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2089 static WShortKey shortcut;
2090 KeySym ksym;
2091 const char *val;
2092 char *k;
2093 char buf[MAX_SHORTCUT_LENGTH], *b;
2095 /* Parameter not used, but tell the compiler that it is ok */
2096 (void) scr;
2097 (void) addr;
2099 GET_STRING_OR_DEFAULT("Key spec", val);
2101 if (!val || strcasecmp(val, "NONE") == 0) {
2102 shortcut.keycode = 0;
2103 shortcut.modifier = 0;
2104 if (ret)
2105 *ret = &shortcut;
2106 return True;
2109 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2111 b = (char *)buf;
2113 /* get modifiers */
2114 shortcut.modifier = 0;
2115 while ((k = strchr(b, '+')) != NULL) {
2116 int mod;
2118 *k = 0;
2119 mod = wXModifierFromKey(b);
2120 if (mod < 0) {
2121 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2122 return False;
2124 shortcut.modifier |= mod;
2126 b = k + 1;
2129 /* get key */
2130 ksym = XStringToKeysym(b);
2132 if (ksym == NoSymbol) {
2133 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2134 return False;
2137 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2138 if (shortcut.keycode == 0) {
2139 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2140 return False;
2143 if (ret)
2144 *ret = &shortcut;
2146 return True;
2149 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2151 static int mask;
2152 const char *str;
2154 /* Parameter not used, but tell the compiler that it is ok */
2155 (void) scr;
2157 GET_STRING_OR_DEFAULT("Modifier Key", str);
2159 if (!str)
2160 return False;
2162 mask = wXModifierFromKey(str);
2163 if (mask < 0) {
2164 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2165 mask = 0;
2166 return False;
2169 if (addr)
2170 *(int *)addr = mask;
2172 if (ret)
2173 *ret = &mask;
2175 return True;
2178 # include <X11/cursorfont.h>
2179 typedef struct {
2180 const char *name;
2181 int id;
2182 } WCursorLookup;
2184 #define CURSOR_ID_NONE (XC_num_glyphs)
2186 static const WCursorLookup cursor_table[] = {
2187 {"X_cursor", XC_X_cursor},
2188 {"arrow", XC_arrow},
2189 {"based_arrow_down", XC_based_arrow_down},
2190 {"based_arrow_up", XC_based_arrow_up},
2191 {"boat", XC_boat},
2192 {"bogosity", XC_bogosity},
2193 {"bottom_left_corner", XC_bottom_left_corner},
2194 {"bottom_right_corner", XC_bottom_right_corner},
2195 {"bottom_side", XC_bottom_side},
2196 {"bottom_tee", XC_bottom_tee},
2197 {"box_spiral", XC_box_spiral},
2198 {"center_ptr", XC_center_ptr},
2199 {"circle", XC_circle},
2200 {"clock", XC_clock},
2201 {"coffee_mug", XC_coffee_mug},
2202 {"cross", XC_cross},
2203 {"cross_reverse", XC_cross_reverse},
2204 {"crosshair", XC_crosshair},
2205 {"diamond_cross", XC_diamond_cross},
2206 {"dot", XC_dot},
2207 {"dotbox", XC_dotbox},
2208 {"double_arrow", XC_double_arrow},
2209 {"draft_large", XC_draft_large},
2210 {"draft_small", XC_draft_small},
2211 {"draped_box", XC_draped_box},
2212 {"exchange", XC_exchange},
2213 {"fleur", XC_fleur},
2214 {"gobbler", XC_gobbler},
2215 {"gumby", XC_gumby},
2216 {"hand1", XC_hand1},
2217 {"hand2", XC_hand2},
2218 {"heart", XC_heart},
2219 {"icon", XC_icon},
2220 {"iron_cross", XC_iron_cross},
2221 {"left_ptr", XC_left_ptr},
2222 {"left_side", XC_left_side},
2223 {"left_tee", XC_left_tee},
2224 {"leftbutton", XC_leftbutton},
2225 {"ll_angle", XC_ll_angle},
2226 {"lr_angle", XC_lr_angle},
2227 {"man", XC_man},
2228 {"middlebutton", XC_middlebutton},
2229 {"mouse", XC_mouse},
2230 {"pencil", XC_pencil},
2231 {"pirate", XC_pirate},
2232 {"plus", XC_plus},
2233 {"question_arrow", XC_question_arrow},
2234 {"right_ptr", XC_right_ptr},
2235 {"right_side", XC_right_side},
2236 {"right_tee", XC_right_tee},
2237 {"rightbutton", XC_rightbutton},
2238 {"rtl_logo", XC_rtl_logo},
2239 {"sailboat", XC_sailboat},
2240 {"sb_down_arrow", XC_sb_down_arrow},
2241 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2242 {"sb_left_arrow", XC_sb_left_arrow},
2243 {"sb_right_arrow", XC_sb_right_arrow},
2244 {"sb_up_arrow", XC_sb_up_arrow},
2245 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2246 {"shuttle", XC_shuttle},
2247 {"sizing", XC_sizing},
2248 {"spider", XC_spider},
2249 {"spraycan", XC_spraycan},
2250 {"star", XC_star},
2251 {"target", XC_target},
2252 {"tcross", XC_tcross},
2253 {"top_left_arrow", XC_top_left_arrow},
2254 {"top_left_corner", XC_top_left_corner},
2255 {"top_right_corner", XC_top_right_corner},
2256 {"top_side", XC_top_side},
2257 {"top_tee", XC_top_tee},
2258 {"trek", XC_trek},
2259 {"ul_angle", XC_ul_angle},
2260 {"umbrella", XC_umbrella},
2261 {"ur_angle", XC_ur_angle},
2262 {"watch", XC_watch},
2263 {"xterm", XC_xterm},
2264 {NULL, CURSOR_ID_NONE}
2267 static void check_bitmap_status(int status, const char *filename, Pixmap bitmap)
2269 switch (status) {
2270 case BitmapOpenFailed:
2271 wwarning(_("failed to open bitmap file \"%s\""), filename);
2272 break;
2273 case BitmapFileInvalid:
2274 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2275 break;
2276 case BitmapNoMemory:
2277 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2278 break;
2279 case BitmapSuccess:
2280 XFreePixmap(dpy, bitmap);
2281 break;
2286 * (none)
2287 * (builtin, <cursor_name>)
2288 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2290 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2292 WMPropList *elem;
2293 char *val;
2294 int nelem;
2295 int status = 0;
2297 nelem = WMGetPropListItemCount(pl);
2298 if (nelem < 1) {
2299 return (status);
2301 elem = WMGetFromPLArray(pl, 0);
2302 if (!elem || !WMIsPLString(elem)) {
2303 return (status);
2305 val = WMGetFromPLString(elem);
2307 if (strcasecmp(val, "none") == 0) {
2308 status = 1;
2309 *cursor = None;
2310 } else if (strcasecmp(val, "builtin") == 0) {
2311 int i;
2312 int cursor_id = CURSOR_ID_NONE;
2314 if (nelem != 2) {
2315 wwarning(_("bad number of arguments in cursor specification"));
2316 return (status);
2318 elem = WMGetFromPLArray(pl, 1);
2319 if (!elem || !WMIsPLString(elem)) {
2320 return (status);
2322 val = WMGetFromPLString(elem);
2324 for (i = 0; cursor_table[i].name != NULL; i++) {
2325 if (strcasecmp(val, cursor_table[i].name) == 0) {
2326 cursor_id = cursor_table[i].id;
2327 break;
2330 if (CURSOR_ID_NONE == cursor_id) {
2331 wwarning(_("unknown builtin cursor name \"%s\""), val);
2332 } else {
2333 *cursor = XCreateFontCursor(dpy, cursor_id);
2334 status = 1;
2336 } else if (strcasecmp(val, "bitmap") == 0) {
2337 char *bitmap_name;
2338 char *mask_name;
2339 int bitmap_status;
2340 int mask_status;
2341 Pixmap bitmap;
2342 Pixmap mask;
2343 unsigned int w, h;
2344 int x, y;
2345 XColor fg, bg;
2347 if (nelem != 3) {
2348 wwarning(_("bad number of arguments in cursor specification"));
2349 return (status);
2351 elem = WMGetFromPLArray(pl, 1);
2352 if (!elem || !WMIsPLString(elem)) {
2353 return (status);
2355 val = WMGetFromPLString(elem);
2356 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2357 if (!bitmap_name) {
2358 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2359 return (status);
2361 elem = WMGetFromPLArray(pl, 2);
2362 if (!elem || !WMIsPLString(elem)) {
2363 wfree(bitmap_name);
2364 return (status);
2366 val = WMGetFromPLString(elem);
2367 mask_name = FindImage(wPreferences.pixmap_path, val);
2368 if (!mask_name) {
2369 wfree(bitmap_name);
2370 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2371 return (status);
2373 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2374 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2375 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2376 fg.pixel = scr->black_pixel;
2377 bg.pixel = scr->white_pixel;
2378 XQueryColor(dpy, scr->w_colormap, &fg);
2379 XQueryColor(dpy, scr->w_colormap, &bg);
2380 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2381 status = 1;
2383 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2384 check_bitmap_status(mask_status, mask_name, mask);
2385 wfree(bitmap_name);
2386 wfree(mask_name);
2388 return (status);
2391 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2393 static Cursor cursor;
2394 int status;
2395 int changed = 0;
2397 again:
2398 if (!WMIsPLArray(value)) {
2399 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2400 entry->key, "cursor specification");
2401 if (!changed) {
2402 value = entry->plvalue;
2403 changed = 1;
2404 wwarning(_("using default \"%s\" instead"), entry->default_value);
2405 goto again;
2407 return (False);
2409 status = parse_cursor(scr, value, &cursor);
2410 if (!status) {
2411 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2412 if (!changed) {
2413 value = entry->plvalue;
2414 changed = 1;
2415 wwarning(_("using default \"%s\" instead"), entry->default_value);
2416 goto again;
2418 return (False);
2420 if (ret) {
2421 *ret = &cursor;
2423 if (addr) {
2424 *(Cursor *) addr = cursor;
2426 return (True);
2429 #undef CURSOR_ID_NONE
2431 /* ---------------- value setting functions --------------- */
2432 static int setJustify(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2434 /* Parameter not used, but tell the compiler that it is ok */
2435 (void) scr;
2436 (void) entry;
2437 (void) tdata;
2438 (void) extra_data;
2440 return REFRESH_WINDOW_TITLE_COLOR;
2443 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2445 /* Parameter not used, but tell the compiler that it is ok */
2446 (void) scr;
2447 (void) entry;
2448 (void) bar;
2449 (void) foo;
2451 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2454 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2456 char *flag = tdata;
2457 long which = (long) extra_data;
2459 /* Parameter not used, but tell the compiler that it is ok */
2460 (void) scr;
2461 (void) entry;
2463 switch (which) {
2464 case WM_DOCK:
2465 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2466 // Drawers require the dock
2467 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || wPreferences.flags.nodock;
2468 break;
2469 case WM_CLIP:
2470 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2471 break;
2472 case WM_DRAWER:
2473 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || *flag;
2474 break;
2475 default:
2476 break;
2478 return 0;
2481 static int setClipMergedInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2483 char *flag = tdata;
2485 /* Parameter not used, but tell the compiler that it is ok */
2486 (void) scr;
2487 (void) entry;
2488 (void) foo;
2490 wPreferences.flags.clip_merged_in_dock = *flag;
2491 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2492 return 0;
2495 static int setWrapAppiconsInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2497 char *flag = tdata;
2499 /* Parameter not used, but tell the compiler that it is ok */
2500 (void) scr;
2501 (void) entry;
2502 (void) foo;
2504 wPreferences.flags.wrap_appicons_in_dock = *flag;
2505 return 0;
2508 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2510 /* Parameter not used, but tell the compiler that it is ok */
2511 (void) entry;
2512 (void) bar;
2513 (void) foo;
2515 if (w_global.workspace.array) {
2516 wWorkspaceForceChange(scr, w_global.workspace.current);
2517 wArrangeIcons(scr, False);
2519 return 0;
2522 static int setIconTile(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2524 Pixmap pixmap;
2525 RImage *img;
2526 WTexture ** texture = tdata;
2527 int reset = 0;
2529 /* Parameter not used, but tell the compiler that it is ok */
2530 (void) foo;
2532 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2533 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2534 ? WREL_ICON : WREL_FLAT);
2535 if (!img) {
2536 wwarning(_("could not render texture for icon background"));
2537 if (!entry->addr)
2538 wTextureDestroy(scr, *texture);
2539 return 0;
2541 RConvertImage(scr->rcontext, img, &pixmap);
2543 if (scr->icon_tile) {
2544 reset = 1;
2545 RReleaseImage(scr->icon_tile);
2546 XFreePixmap(dpy, scr->icon_tile_pixmap);
2549 scr->icon_tile = img;
2551 /* put the icon in the noticeboard hint */
2552 PropSetIconTileHint(scr, img);
2554 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock) {
2555 if (scr->clip_tile) {
2556 RReleaseImage(scr->clip_tile);
2558 scr->clip_tile = wClipMakeTile(img);
2561 if (!wPreferences.flags.nodrawer) {
2562 if (scr->drawer_tile) {
2563 RReleaseImage(scr->drawer_tile);
2565 scr->drawer_tile = wDrawerMakeTile(scr, img);
2568 scr->icon_tile_pixmap = pixmap;
2570 if (scr->def_icon_rimage) {
2571 RReleaseImage(scr->def_icon_rimage);
2572 scr->def_icon_rimage = NULL;
2575 if (scr->icon_back_texture)
2576 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2578 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2580 /* Free the texture as nobody else will use it, nor refer to it. */
2581 if (!entry->addr)
2582 wTextureDestroy(scr, *texture);
2584 return (reset ? REFRESH_ICON_TILE : 0);
2587 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2589 WMFont *font = tdata;
2591 /* Parameter not used, but tell the compiler that it is ok */
2592 (void) entry;
2593 (void) foo;
2595 if (scr->title_font) {
2596 WMReleaseFont(scr->title_font);
2598 scr->title_font = font;
2600 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2603 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2605 WMFont *font = tdata;
2607 /* Parameter not used, but tell the compiler that it is ok */
2608 (void) entry;
2609 (void) foo;
2611 if (scr->menu_title_font) {
2612 WMReleaseFont(scr->menu_title_font);
2615 scr->menu_title_font = font;
2617 return REFRESH_MENU_TITLE_FONT;
2620 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2622 WMFont *font = tdata;
2624 /* Parameter not used, but tell the compiler that it is ok */
2625 (void) entry;
2626 (void) foo;
2628 if (scr->menu_entry_font) {
2629 WMReleaseFont(scr->menu_entry_font);
2631 scr->menu_entry_font = font;
2633 return REFRESH_MENU_FONT;
2636 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2638 WMFont *font = tdata;
2640 /* Parameter not used, but tell the compiler that it is ok */
2641 (void) entry;
2642 (void) foo;
2644 if (scr->icon_title_font) {
2645 WMReleaseFont(scr->icon_title_font);
2648 scr->icon_title_font = font;
2650 return REFRESH_ICON_FONT;
2653 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2655 WMFont *font = tdata;
2657 /* Parameter not used, but tell the compiler that it is ok */
2658 (void) entry;
2659 (void) foo;
2661 if (scr->clip_title_font) {
2662 WMReleaseFont(scr->clip_title_font);
2665 scr->clip_title_font = font;
2667 return REFRESH_ICON_FONT;
2670 static int setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2672 WMFont *font = tdata;
2674 /* Parameter not used, but tell the compiler that it is ok */
2675 (void) scr;
2676 (void) entry;
2677 (void) foo;
2679 if (w_global.workspace.font_for_name)
2680 WMReleaseFont(w_global.workspace.font_for_name);
2682 w_global.workspace.font_for_name = font;
2684 return 0;
2687 static int setHightlight(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2689 XColor *color = tdata;
2691 /* Parameter not used, but tell the compiler that it is ok */
2692 (void) entry;
2693 (void) foo;
2695 if (scr->select_color)
2696 WMReleaseColor(scr->select_color);
2698 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2700 wFreeColor(scr, color->pixel);
2702 return REFRESH_MENU_COLOR;
2705 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2707 XColor *color = tdata;
2709 /* Parameter not used, but tell the compiler that it is ok */
2710 (void) entry;
2711 (void) foo;
2713 if (scr->select_text_color)
2714 WMReleaseColor(scr->select_text_color);
2716 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2718 wFreeColor(scr, color->pixel);
2720 return REFRESH_MENU_COLOR;
2723 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2725 XColor *color = tdata;
2726 long widx = (long) extra_data;
2728 /* Parameter not used, but tell the compiler that it is ok */
2729 (void) entry;
2731 if (scr->clip_title_color[widx])
2732 WMReleaseColor(scr->clip_title_color[widx]);
2734 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2735 wFreeColor(scr, color->pixel);
2737 return REFRESH_ICON_TITLE_COLOR;
2740 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2742 XColor *color = tdata;
2743 long widx = (long) extra_data;
2745 /* Parameter not used, but tell the compiler that it is ok */
2746 (void) entry;
2748 if (scr->window_title_color[widx])
2749 WMReleaseColor(scr->window_title_color[widx]);
2751 scr->window_title_color[widx] =
2752 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2754 wFreeColor(scr, color->pixel);
2756 return REFRESH_WINDOW_TITLE_COLOR;
2759 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2761 XColor *color = tdata;
2763 /* Parameter not used, but tell the compiler that it is ok */
2764 (void) entry;
2765 (void) extra_data;
2767 if (scr->menu_title_color[0])
2768 WMReleaseColor(scr->menu_title_color[0]);
2770 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2772 wFreeColor(scr, color->pixel);
2774 return REFRESH_MENU_TITLE_COLOR;
2777 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2779 XColor *color = tdata;
2781 /* Parameter not used, but tell the compiler that it is ok */
2782 (void) entry;
2783 (void) foo;
2785 if (scr->mtext_color)
2786 WMReleaseColor(scr->mtext_color);
2788 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2790 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2791 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2792 } else {
2793 WMSetColorAlpha(scr->dtext_color, 0xffff);
2796 wFreeColor(scr, color->pixel);
2798 return REFRESH_MENU_COLOR;
2801 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2803 XColor *color = tdata;
2805 /* Parameter not used, but tell the compiler that it is ok */
2806 (void) entry;
2807 (void) foo;
2809 if (scr->dtext_color)
2810 WMReleaseColor(scr->dtext_color);
2812 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2814 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2815 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2816 } else {
2817 WMSetColorAlpha(scr->dtext_color, 0xffff);
2820 wFreeColor(scr, color->pixel);
2822 return REFRESH_MENU_COLOR;
2825 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2827 XColor *color = tdata;
2829 /* Parameter not used, but tell the compiler that it is ok */
2830 (void) entry;
2831 (void) foo;
2833 if (scr->icon_title_color)
2834 WMReleaseColor(scr->icon_title_color);
2835 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2837 wFreeColor(scr, color->pixel);
2839 return REFRESH_ICON_TITLE_COLOR;
2842 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2844 XColor *color = tdata;
2846 /* Parameter not used, but tell the compiler that it is ok */
2847 (void) entry;
2848 (void) foo;
2850 if (scr->icon_title_texture) {
2851 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2853 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2855 return REFRESH_ICON_TITLE_BACK;
2858 static int setFrameBorderWidth(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2860 int *value = tdata;
2862 /* Parameter not used, but tell the compiler that it is ok */
2863 (void) entry;
2864 (void) foo;
2866 scr->frame_border_width = *value;
2868 return REFRESH_FRAME_BORDER;
2871 static int setFrameBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2873 XColor *color = tdata;
2875 /* Parameter not used, but tell the compiler that it is ok */
2876 (void) entry;
2877 (void) foo;
2879 if (scr->frame_border_color)
2880 WMReleaseColor(scr->frame_border_color);
2881 scr->frame_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2883 wFreeColor(scr, color->pixel);
2885 return REFRESH_FRAME_BORDER;
2888 static int setFrameSelectedBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2890 XColor *color = tdata;
2892 /* Parameter not used, but tell the compiler that it is ok */
2893 (void) entry;
2894 (void) foo;
2896 if (scr->frame_selected_border_color)
2897 WMReleaseColor(scr->frame_selected_border_color);
2898 scr->frame_selected_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2900 wFreeColor(scr, color->pixel);
2902 return REFRESH_FRAME_BORDER;
2905 static void trackDeadProcess(pid_t pid, unsigned int status, void *client_data)
2907 WScreen *scr = (WScreen *) client_data;
2909 /* Parameter not used, but tell the compiler that it is ok */
2910 (void) pid;
2911 (void) status;
2913 close(scr->helper_fd);
2914 scr->helper_fd = 0;
2915 scr->helper_pid = 0;
2916 scr->flags.backimage_helper_launched = 0;
2919 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
2921 WMPropList *value = tdata;
2922 WMPropList *val;
2923 char *str;
2924 int i;
2926 /* Parameter not used, but tell the compiler that it is ok */
2927 (void) entry;
2928 (void) bar;
2930 if (scr->flags.backimage_helper_launched) {
2931 if (WMGetPropListItemCount(value) == 0) {
2932 SendHelperMessage(scr, 'C', 0, NULL);
2933 SendHelperMessage(scr, 'K', 0, NULL);
2935 WMReleasePropList(value);
2936 return 0;
2938 } else {
2939 pid_t pid;
2940 int filedes[2];
2942 if (WMGetPropListItemCount(value) == 0)
2943 return 0;
2945 if (pipe(filedes) < 0) {
2946 werror("pipe() failed:can't set workspace specific background image");
2948 WMReleasePropList(value);
2949 return 0;
2952 pid = fork();
2953 if (pid < 0) {
2954 werror("fork() failed:can't set workspace specific background image");
2955 if (close(filedes[0]) < 0)
2956 werror("could not close pipe");
2957 if (close(filedes[1]) < 0)
2958 werror("could not close pipe");
2960 } else if (pid == 0) {
2961 char *dither;
2963 SetupEnvironment(scr);
2965 if (close(0) < 0)
2966 werror("could not close pipe");
2967 if (dup(filedes[0]) < 0) {
2968 werror("dup() failed:can't set workspace specific background image");
2970 dither = wPreferences.no_dithering ? "-m" : "-d";
2971 if (wPreferences.smooth_workspace_back)
2972 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2973 else
2974 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2975 werror("could not execute wmsetbg");
2976 exit(1);
2977 } else {
2979 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2980 werror("error setting close-on-exec flag");
2982 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2983 werror("error setting close-on-exec flag");
2986 scr->helper_fd = filedes[1];
2987 scr->helper_pid = pid;
2988 scr->flags.backimage_helper_launched = 1;
2990 wAddDeathHandler(pid, trackDeadProcess, scr);
2992 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2997 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2998 val = WMGetFromPLArray(value, i);
2999 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
3000 str = WMGetPropListDescription(val, False);
3002 SendHelperMessage(scr, 'S', i + 1, str);
3004 wfree(str);
3005 } else {
3006 SendHelperMessage(scr, 'U', i + 1, NULL);
3009 sleep(1);
3011 WMReleasePropList(value);
3012 return 0;
3015 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
3017 WMPropList *value = tdata;
3019 /* Parameter not used, but tell the compiler that it is ok */
3020 (void) entry;
3021 (void) bar;
3023 if (scr->flags.backimage_helper_launched) {
3024 char *str;
3026 if (WMGetPropListItemCount(value) == 0) {
3027 SendHelperMessage(scr, 'U', 0, NULL);
3028 } else {
3029 /* set the default workspace background to this one */
3030 str = WMGetPropListDescription(value, False);
3031 if (str) {
3032 SendHelperMessage(scr, 'S', 0, str);
3033 wfree(str);
3034 SendHelperMessage(scr, 'C', w_global.workspace.current + 1, NULL);
3035 } else {
3036 SendHelperMessage(scr, 'U', 0, NULL);
3039 } else if (WMGetPropListItemCount(value) > 0) {
3040 char *command;
3041 char *text;
3042 char *dither;
3043 int len;
3045 text = WMGetPropListDescription(value, False);
3046 len = strlen(text) + 40;
3047 command = wmalloc(len);
3048 dither = wPreferences.no_dithering ? "-m" : "-d";
3049 if (wPreferences.smooth_workspace_back)
3050 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3051 else
3052 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3053 wfree(text);
3054 ExecuteShellCommand(scr, command);
3055 wfree(command);
3057 WMReleasePropList(value);
3059 return 0;
3062 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3064 WTexture **texture = tdata;
3066 /* Parameter not used, but tell the compiler that it is ok */
3067 (void) entry;
3068 (void) foo;
3070 if (scr->widget_texture) {
3071 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3073 scr->widget_texture = *(WTexSolid **) texture;
3075 return 0;
3078 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3080 WTexture **texture = tdata;
3082 /* Parameter not used, but tell the compiler that it is ok */
3083 (void) entry;
3084 (void) foo;
3086 if (scr->window_title_texture[WS_FOCUSED]) {
3087 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3089 scr->window_title_texture[WS_FOCUSED] = *texture;
3091 return REFRESH_WINDOW_TEXTURES;
3094 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3096 WTexture **texture = tdata;
3098 /* Parameter not used, but tell the compiler that it is ok */
3099 (void) entry;
3100 (void) foo;
3102 if (scr->window_title_texture[WS_PFOCUSED]) {
3103 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3105 scr->window_title_texture[WS_PFOCUSED] = *texture;
3107 return REFRESH_WINDOW_TEXTURES;
3110 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3112 WTexture **texture = tdata;
3114 /* Parameter not used, but tell the compiler that it is ok */
3115 (void) entry;
3116 (void) foo;
3118 if (scr->window_title_texture[WS_UNFOCUSED]) {
3119 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3121 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3123 return REFRESH_WINDOW_TEXTURES;
3126 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3128 WTexture **texture = tdata;
3130 /* Parameter not used, but tell the compiler that it is ok */
3131 (void) entry;
3132 (void) foo;
3134 if (scr->resizebar_texture[0]) {
3135 wTextureDestroy(scr, scr->resizebar_texture[0]);
3137 scr->resizebar_texture[0] = *texture;
3139 return REFRESH_WINDOW_TEXTURES;
3142 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3144 WTexture **texture = tdata;
3146 /* Parameter not used, but tell the compiler that it is ok */
3147 (void) entry;
3148 (void) foo;
3150 if (scr->menu_title_texture[0]) {
3151 wTextureDestroy(scr, scr->menu_title_texture[0]);
3153 scr->menu_title_texture[0] = *texture;
3155 return REFRESH_MENU_TITLE_TEXTURE;
3158 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3160 WTexture **texture = tdata;
3162 /* Parameter not used, but tell the compiler that it is ok */
3163 (void) entry;
3164 (void) foo;
3166 if (scr->menu_item_texture) {
3167 wTextureDestroy(scr, scr->menu_item_texture);
3168 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3170 scr->menu_item_texture = *texture;
3172 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3174 return REFRESH_MENU_TEXTURE;
3177 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3179 WShortKey *shortcut = tdata;
3180 WWindow *wwin;
3181 long widx = (long) extra_data;
3183 /* Parameter not used, but tell the compiler that it is ok */
3184 (void) entry;
3186 wKeyBindings[widx] = *shortcut;
3188 wwin = scr->focused_window;
3190 while (wwin != NULL) {
3191 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3193 if (!WFLAGP(wwin, no_bind_keys)) {
3194 wWindowSetKeyGrabs(wwin);
3196 wwin = wwin->prev;
3199 /* do we need to update window menus? */
3200 if (widx >= WKBD_WORKSPACE1 && widx <= WKBD_WORKSPACE10)
3201 return REFRESH_WORKSPACE_MENU;
3202 if (widx == WKBD_LASTWORKSPACE)
3203 return REFRESH_WORKSPACE_MENU;
3204 if (widx >= WKBD_MOVE_WORKSPACE1 && widx <= WKBD_MOVE_WORKSPACE10)
3205 return REFRESH_WORKSPACE_MENU;
3207 return 0;
3210 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3212 /* Parameter not used, but tell the compiler that it is ok */
3213 (void) entry;
3214 (void) bar;
3215 (void) foo;
3217 wScreenUpdateUsableArea(scr);
3218 wArrangeIcons(scr, True);
3220 return 0;
3223 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3225 /* Parameter not used, but tell the compiler that it is ok */
3226 (void) entry;
3227 (void) bar;
3228 (void) foo;
3230 wScreenUpdateUsableArea(scr);
3232 return 0;
3235 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3237 /* Parameter not used, but tell the compiler that it is ok */
3238 (void) scr;
3239 (void) entry;
3240 (void) tdata;
3241 (void) foo;
3243 return REFRESH_MENU_TEXTURE;
3246 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3248 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3250 RCopyArea(img, image, x, y, w, h, 0, 0);
3252 return img;
3255 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3257 WMPropList *array = tdata;
3258 char *path;
3259 RImage *bgimage;
3260 int cwidth, cheight;
3261 struct WPreferences *prefs = foo;
3263 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3264 if (prefs->swtileImage)
3265 RReleaseImage(prefs->swtileImage);
3266 prefs->swtileImage = NULL;
3268 WMReleasePropList(array);
3269 return 0;
3272 switch (WMGetPropListItemCount(array)) {
3273 case 4:
3274 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3275 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3276 break;
3277 } else
3278 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3280 if (!path) {
3281 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3282 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3283 } else {
3284 bgimage = RLoadImage(scr->rcontext, path, 0);
3285 if (!bgimage) {
3286 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3287 wfree(path);
3288 } else {
3289 wfree(path);
3291 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3292 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3294 if (cwidth <= 0 || cheight <= 0 ||
3295 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3296 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3297 else {
3298 int i;
3299 int swidth, theight;
3300 for (i = 0; i < 9; i++) {
3301 if (prefs->swbackImage[i])
3302 RReleaseImage(prefs->swbackImage[i]);
3303 prefs->swbackImage[i] = NULL;
3305 swidth = (bgimage->width - cwidth) / 2;
3306 theight = (bgimage->height - cheight) / 2;
3308 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3309 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3310 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3311 swidth, theight);
3313 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3314 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3315 cwidth, cheight);
3316 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3317 swidth, cheight);
3319 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3320 swidth, theight);
3321 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3322 cwidth, theight);
3323 prefs->swbackImage[8] =
3324 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3325 theight);
3327 // check if anything failed
3328 for (i = 0; i < 9; i++) {
3329 if (!prefs->swbackImage[i]) {
3330 for (; i >= 0; --i) {
3331 RReleaseImage(prefs->swbackImage[i]);
3332 prefs->swbackImage[i] = NULL;
3334 break;
3338 RReleaseImage(bgimage);
3342 case 1:
3343 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3344 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3345 break;
3346 } else
3347 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3349 if (!path) {
3350 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3351 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3352 } else {
3353 if (prefs->swtileImage)
3354 RReleaseImage(prefs->swtileImage);
3356 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3357 if (!prefs->swtileImage) {
3358 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3360 wfree(path);
3362 break;
3364 default:
3365 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3366 break;
3369 WMReleasePropList(array);
3371 return 0;
3374 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3376 WMPropList *array = tdata;
3377 int i;
3378 struct WPreferences *prefs = foo;
3380 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3381 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3382 WMReleasePropList(array);
3383 return 0;
3386 DestroyWindowMenu(scr);
3388 for (i = 0; i < 7; i++) {
3389 if (prefs->modifier_labels[i])
3390 wfree(prefs->modifier_labels[i]);
3392 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3393 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3394 } else {
3395 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3396 prefs->modifier_labels[i] = NULL;
3400 WMReleasePropList(array);
3402 return 0;
3405 static int setDoubleClick(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
3407 int *value = tdata;
3409 /* Parameter not used, but tell the compiler that it is ok */
3410 (void) entry;
3411 (void) scr;
3413 if (*value <= 0)
3414 *(int *)foo = 1;
3416 W_setconf_doubleClickDelay(*value);
3418 return 0;
3421 static int setCursor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3423 Cursor *cursor = tdata;
3424 long widx = (long) extra_data;
3426 /* Parameter not used, but tell the compiler that it is ok */
3427 (void) entry;
3429 if (wPreferences.cursor[widx] != None) {
3430 XFreeCursor(dpy, wPreferences.cursor[widx]);
3433 wPreferences.cursor[widx] = *cursor;
3435 if (widx == WCUR_ROOT && *cursor != None) {
3436 XDefineCursor(dpy, scr->root_win, *cursor);
3439 return 0;