wrlib: return NULL if XImage could not be taken, for consistency
[wmaker-crm.git] / src / defaults.c
blob2f4626fe547846806ca819d410058586afe961ba
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <strings.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifndef PATH_MAX
40 #define PATH_MAX DEFAULT_PATH_MAX
41 #endif
43 #include <X11/Xlib.h>
44 #include <X11/Xutil.h>
45 #include <X11/keysym.h>
47 #include <wraster.h>
49 #include "WindowMaker.h"
50 #include "framewin.h"
51 #include "window.h"
52 #include "texture.h"
53 #include "screen.h"
54 #include "resources.h"
55 #include "defaults.h"
56 #include "keybind.h"
57 #include "xmodifier.h"
58 #include "icon.h"
59 #include "main.h"
60 #include "actions.h"
61 #include "dock.h"
62 #include "workspace.h"
63 #include "properties.h"
64 #include "misc.h"
65 #include "event.h"
66 #include "winmenu.h"
68 #define MAX_SHORTCUT_LENGTH 32
70 #ifndef GLOBAL_DEFAULTS_SUBDIR
71 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
72 #endif
75 typedef struct _WDefaultEntry WDefaultEntry;
76 typedef int (WDECallbackConvert) (WScreen *scr, WDefaultEntry *entry, WMPropList *plvalue, void *addr, void **tdata);
77 typedef int (WDECallbackUpdate) (WScreen *scr, WDefaultEntry *entry, void *tdata, void *extra_data);
79 struct _WDefaultEntry {
80 const char *key;
81 const char *default_value;
82 void *extra_data;
83 void *addr;
84 WDECallbackConvert *convert;
85 WDECallbackUpdate *update;
86 WMPropList *plkey;
87 WMPropList *plvalue; /* default value */
90 /* used to map strings to integers */
91 typedef struct {
92 const char *string;
93 short value;
94 char is_alias;
95 } WOptionEnumeration;
97 /* type converters */
98 static WDECallbackConvert getBool;
99 static WDECallbackConvert getInt;
100 static WDECallbackConvert getCoord;
101 static WDECallbackConvert getPathList;
102 static WDECallbackConvert getEnum;
103 static WDECallbackConvert getTexture;
104 static WDECallbackConvert getWSBackground;
105 static WDECallbackConvert getWSSpecificBackground;
106 static WDECallbackConvert getFont;
107 static WDECallbackConvert getColor;
108 static WDECallbackConvert getKeybind;
109 static WDECallbackConvert getModMask;
110 static WDECallbackConvert getPropList;
112 /* value setting functions */
113 static WDECallbackUpdate setJustify;
114 static WDECallbackUpdate setClearance;
115 static WDECallbackUpdate setIfDockPresent;
116 static WDECallbackUpdate setClipMergedInDock;
117 static WDECallbackUpdate setWrapAppiconsInDock;
118 static WDECallbackUpdate setStickyIcons;
119 static WDECallbackUpdate setWidgetColor;
120 static WDECallbackUpdate setIconTile;
121 static WDECallbackUpdate setWinTitleFont;
122 static WDECallbackUpdate setMenuTitleFont;
123 static WDECallbackUpdate setMenuTextFont;
124 static WDECallbackUpdate setIconTitleFont;
125 static WDECallbackUpdate setIconTitleColor;
126 static WDECallbackUpdate setIconTitleBack;
127 static WDECallbackUpdate setFrameBorderWidth;
128 static WDECallbackUpdate setFrameBorderColor;
129 static WDECallbackUpdate setFrameFocusedBorderColor;
130 static WDECallbackUpdate setFrameSelectedBorderColor;
131 static WDECallbackUpdate setLargeDisplayFont;
132 static WDECallbackUpdate setWTitleColor;
133 static WDECallbackUpdate setFTitleBack;
134 static WDECallbackUpdate setPTitleBack;
135 static WDECallbackUpdate setUTitleBack;
136 static WDECallbackUpdate setResizebarBack;
137 static WDECallbackUpdate setWorkspaceBack;
138 static WDECallbackUpdate setWorkspaceSpecificBack;
139 static WDECallbackUpdate setMenuTitleColor;
140 static WDECallbackUpdate setMenuTextColor;
141 static WDECallbackUpdate setMenuDisabledColor;
142 static WDECallbackUpdate setMenuTitleBack;
143 static WDECallbackUpdate setMenuTextBack;
144 static WDECallbackUpdate setHightlight;
145 static WDECallbackUpdate setHightlightText;
146 static WDECallbackUpdate setKeyGrab;
147 static WDECallbackUpdate setDoubleClick;
148 static WDECallbackUpdate setIconPosition;
150 static WDECallbackUpdate setClipTitleFont;
151 static WDECallbackUpdate setClipTitleColor;
153 static WDECallbackUpdate setMenuStyle;
154 static WDECallbackUpdate setSwPOptions;
155 static WDECallbackUpdate updateUsableArea;
157 static WDECallbackUpdate setModifierKeyLabels;
159 static WDECallbackConvert getCursor;
160 static WDECallbackUpdate setCursor;
163 * Tables to convert strings to enumeration values.
164 * Values stored are char
167 /* WARNING: sum of length of all value strings must not exceed
168 * this value */
169 #define TOTAL_VALUES_LENGTH 80
171 #define REFRESH_WINDOW_TEXTURES (1<<0)
172 #define REFRESH_MENU_TEXTURE (1<<1)
173 #define REFRESH_MENU_FONT (1<<2)
174 #define REFRESH_MENU_COLOR (1<<3)
175 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
176 #define REFRESH_MENU_TITLE_FONT (1<<5)
177 #define REFRESH_MENU_TITLE_COLOR (1<<6)
178 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
179 #define REFRESH_WINDOW_FONT (1<<8)
180 #define REFRESH_ICON_TILE (1<<9)
181 #define REFRESH_ICON_FONT (1<<10)
182 #define REFRESH_WORKSPACE_BACK (1<<11)
184 #define REFRESH_BUTTON_IMAGES (1<<12)
186 #define REFRESH_ICON_TITLE_COLOR (1<<13)
187 #define REFRESH_ICON_TITLE_BACK (1<<14)
189 #define REFRESH_WORKSPACE_MENU (1<<15)
191 #define REFRESH_FRAME_BORDER REFRESH_MENU_FONT|REFRESH_WINDOW_FONT
193 static WOptionEnumeration seFocusModes[] = {
194 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
195 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
196 {NULL, 0, 0}
199 static WOptionEnumeration seTitlebarModes[] = {
200 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
201 {"next", TS_NEXT, 0}, {NULL, 0, 0}
204 static WOptionEnumeration seColormapModes[] = {
205 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
206 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
207 {NULL, 0, 0}
210 static WOptionEnumeration sePlacements[] = {
211 {"Auto", WPM_AUTO, 0},
212 {"Smart", WPM_SMART, 0},
213 {"Cascade", WPM_CASCADE, 0},
214 {"Random", WPM_RANDOM, 0},
215 {"Manual", WPM_MANUAL, 0},
216 {"Center", WPM_CENTER, 0},
217 {NULL, 0, 0}
220 static WOptionEnumeration seGeomDisplays[] = {
221 {"None", WDIS_NONE, 0},
222 {"Center", WDIS_CENTER, 0},
223 {"Corner", WDIS_TOPLEFT, 0},
224 {"Floating", WDIS_FRAME_CENTER, 0},
225 {"Line", WDIS_NEW, 0},
226 {NULL, 0, 0}
229 static WOptionEnumeration seSpeeds[] = {
230 {"UltraFast", SPEED_ULTRAFAST, 0},
231 {"Fast", SPEED_FAST, 0},
232 {"Medium", SPEED_MEDIUM, 0},
233 {"Slow", SPEED_SLOW, 0},
234 {"UltraSlow", SPEED_ULTRASLOW, 0},
235 {NULL, 0, 0}
238 static WOptionEnumeration seMouseButtonActions[] = {
239 {"None", WA_NONE, 0},
240 {"SelectWindows", WA_SELECT_WINDOWS, 0},
241 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
242 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
243 {NULL, 0, 0}
246 static WOptionEnumeration seMouseWheelActions[] = {
247 {"None", WA_NONE, 0},
248 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
249 {NULL, 0, 0}
252 static WOptionEnumeration seIconificationStyles[] = {
253 {"Zoom", WIS_ZOOM, 0},
254 {"Twist", WIS_TWIST, 0},
255 {"Flip", WIS_FLIP, 0},
256 {"None", WIS_NONE, 0},
257 {"random", WIS_RANDOM, 0},
258 {NULL, 0, 0}
261 static WOptionEnumeration seJustifications[] = {
262 {"Left", WTJ_LEFT, 0},
263 {"Center", WTJ_CENTER, 0},
264 {"Right", WTJ_RIGHT, 0},
265 {NULL, 0, 0}
268 static WOptionEnumeration seIconPositions[] = {
269 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
270 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
271 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
272 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
273 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
274 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
275 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
276 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
277 {NULL, 0, 0}
280 static WOptionEnumeration seMenuStyles[] = {
281 {"normal", MS_NORMAL, 0},
282 {"singletexture", MS_SINGLE_TEXTURE, 0},
283 {"flat", MS_FLAT, 0},
284 {NULL, 0, 0}
287 static WOptionEnumeration seDisplayPositions[] = {
288 {"none", WD_NONE, 0},
289 {"center", WD_CENTER, 0},
290 {"top", WD_TOP, 0},
291 {"bottom", WD_BOTTOM, 0},
292 {"topleft", WD_TOPLEFT, 0},
293 {"topright", WD_TOPRIGHT, 0},
294 {"bottomleft", WD_BOTTOMLEFT, 0},
295 {"bottomright", WD_BOTTOMRIGHT, 0},
296 {NULL, 0, 0}
299 static WOptionEnumeration seWorkspaceBorder[] = {
300 {"None", WB_NONE, 0},
301 {"LeftRight", WB_LEFTRIGHT, 0},
302 {"TopBottom", WB_TOPBOTTOM, 0},
303 {"AllDirections", WB_ALLDIRS, 0},
304 {NULL, 0, 0}
308 * ALL entries in the tables bellow, NEED to have a default value
309 * defined, and this value needs to be correct.
312 /* these options will only affect the window manager on startup
314 * static defaults can't access the screen data, because it is
315 * created after these defaults are read
317 WDefaultEntry staticOptionList[] = {
319 {"ColormapSize", "4", NULL,
320 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
321 {"DisableDithering", "NO", NULL,
322 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
323 {"IconSize", "64", NULL,
324 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
325 {"ModifierKey", "Mod1", NULL,
326 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
327 {"DisableWSMouseActions", "NO", NULL,
328 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
329 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
330 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
331 {"NewStyle", "new", seTitlebarModes,
332 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
333 {"DisableDock", "NO", (void *)WM_DOCK,
334 NULL, getBool, setIfDockPresent, NULL, NULL},
335 {"DisableClip", "NO", (void *)WM_CLIP,
336 NULL, getBool, setIfDockPresent, NULL, NULL},
337 {"DisableDrawers", "NO", (void *)WM_DRAWER,
338 NULL, getBool, setIfDockPresent, NULL, NULL},
339 {"ClipMergedInDock", "NO", NULL,
340 NULL, getBool, setClipMergedInDock, NULL, NULL},
341 {"DisableMiniwindows", "NO", NULL,
342 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
345 #define NUM2STRING_(x) #x
346 #define NUM2STRING(x) NUM2STRING_(x)
348 WDefaultEntry optionList[] = {
350 /* dynamic options */
352 {"IconPosition", "blh", seIconPositions,
353 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
354 {"IconificationStyle", "Zoom", seIconificationStyles,
355 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
356 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
357 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
358 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
359 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
360 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
361 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
362 {"MouseWheelAction", "None", seMouseWheelActions,
363 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
364 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
365 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
366 {"IconPath", DEF_ICON_PATHS, NULL,
367 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
368 {"ColormapMode", "auto", seColormapModes,
369 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
370 {"AutoFocus", "NO", NULL,
371 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
372 {"RaiseDelay", "0", NULL,
373 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
374 {"CirculateRaise", "NO", NULL,
375 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
376 {"Superfluous", "NO", NULL,
377 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
378 {"AdvanceToNewWorkspace", "NO", NULL,
379 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
380 {"CycleWorkspaces", "NO", NULL,
381 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
382 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
383 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
384 {"WorkspaceBorder", "None", seWorkspaceBorder,
385 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
386 {"WorkspaceBorderSize", "0", NULL,
387 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
388 {"StickyIcons", "NO", NULL,
389 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
390 {"SaveSessionOnExit", "NO", NULL,
391 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
392 {"WrapMenus", "NO", NULL,
393 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
394 {"ScrollableMenus", "NO", NULL,
395 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
396 {"MenuScrollSpeed", "medium", seSpeeds,
397 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
398 {"IconSlideSpeed", "medium", seSpeeds,
399 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
400 {"ShadeSpeed", "medium", seSpeeds,
401 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
402 {"BounceAppIconsWhenUrgent", "YES", NULL,
403 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
404 {"RaiseAppIconsWhenBouncing", "NO", NULL,
405 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
406 {"DoNotMakeAppIconsBounce", "NO", NULL,
407 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
408 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
409 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
410 {"ClipAutoraiseDelay", "600", NULL,
411 &wPreferences.clip_auto_raise_delay, getInt, NULL, NULL, NULL},
412 {"ClipAutolowerDelay", "1000", NULL,
413 &wPreferences.clip_auto_lower_delay, getInt, NULL, NULL, NULL},
414 {"ClipAutoexpandDelay", "600", NULL,
415 &wPreferences.clip_auto_expand_delay, getInt, NULL, NULL, NULL},
416 {"ClipAutocollapseDelay", "1000", NULL,
417 &wPreferences.clip_auto_collapse_delay, getInt, NULL, NULL, NULL},
418 {"WrapAppiconsInDock", "YES", NULL,
419 NULL, getBool, setWrapAppiconsInDock, NULL, NULL},
420 {"AlignSubmenus", "NO", NULL,
421 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
422 {"ViKeyMenus", "NO", NULL,
423 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
424 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
425 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
426 {"WindowPlacement", "auto", sePlacements,
427 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
428 {"IgnoreFocusClick", "NO", NULL,
429 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
430 {"UseSaveUnders", "NO", NULL,
431 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
432 {"OpaqueMove", "NO", NULL,
433 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
434 {"OpaqueResize", "NO", NULL,
435 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
436 {"OpaqueMoveResizeKeyboard", "NO", NULL,
437 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
438 {"DisableAnimations", "NO", NULL,
439 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
440 {"DontLinkWorkspaces", "NO", NULL,
441 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
442 {"HighlightActiveApp", "YES", NULL,
443 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
444 {"AutoArrangeIcons", "NO", NULL,
445 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
446 {"NoWindowOverDock", "NO", NULL,
447 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
448 {"NoWindowOverIcons", "NO", NULL,
449 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
450 {"WindowPlaceOrigin", "(0, 0)", NULL,
451 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
452 {"ResizeDisplay", "corner", seGeomDisplays,
453 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
454 {"MoveDisplay", "corner", seGeomDisplays,
455 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
456 {"DontConfirmKill", "NO", NULL,
457 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
458 {"WindowTitleBalloons", "NO", NULL,
459 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
460 {"MiniwindowTitleBalloons", "NO", NULL,
461 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
462 {"AppIconBalloons", "NO", NULL,
463 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
464 {"HelpBalloons", "NO", NULL,
465 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
466 {"EdgeResistance", "30", NULL,
467 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
468 {"ResizeIncrement", "0", NULL,
469 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
470 {"Attraction", "NO", NULL,
471 &wPreferences.attract, getBool, NULL, NULL, NULL},
472 {"DisableBlinking", "NO", NULL,
473 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
474 {"SingleClickLaunch", "NO", NULL,
475 &wPreferences.single_click, getBool, NULL, NULL, NULL},
476 {"StrictWindozeCycle", "YES", NULL,
477 &wPreferences.strict_windoze_cycle, getBool, NULL, NULL, NULL},
478 {"SwitchPanelOnlyOpen", "NO", NULL,
479 &wPreferences.panel_only_open, getBool, NULL, NULL, NULL},
481 /* style options */
483 {"MenuStyle", "normal", seMenuStyles,
484 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
485 {"WidgetColor", "(solid, gray)", NULL,
486 NULL, getTexture, setWidgetColor, NULL, NULL},
487 {"WorkspaceSpecificBack", "()", NULL,
488 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
489 /* WorkspaceBack must come after WorkspaceSpecificBack or
490 * WorkspaceBack wont know WorkspaceSpecificBack was also
491 * specified and 2 copies of wmsetbg will be launched */
492 {"WorkspaceBack", "(solid, black)", NULL,
493 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
494 {"SmoothWorkspaceBack", "NO", NULL,
495 NULL, getBool, NULL, NULL, NULL},
496 {"IconBack", "(solid, gray)", NULL,
497 NULL, getTexture, setIconTile, NULL, NULL},
498 {"TitleJustify", "center", seJustifications,
499 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
500 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
501 NULL, getFont, setWinTitleFont, NULL, NULL},
502 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
503 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
504 {"WindowTitleMinHeight", "0", NULL,
505 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
506 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
507 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
508 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
509 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
510 {"MenuTitleMinHeight", "0", NULL,
511 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
512 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
513 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
514 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
515 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
516 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
517 NULL, getFont, setMenuTitleFont, NULL, NULL},
518 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
519 NULL, getFont, setMenuTextFont, NULL, NULL},
520 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
521 NULL, getFont, setIconTitleFont, NULL, NULL},
522 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
523 NULL, getFont, setClipTitleFont, NULL, NULL},
524 {"ShowClipTitle", "YES", NULL,
525 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
526 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
527 NULL, getFont, setLargeDisplayFont, NULL, NULL},
528 {"HighlightColor", "white", NULL,
529 NULL, getColor, setHightlight, NULL, NULL},
530 {"HighlightTextColor", "black", NULL,
531 NULL, getColor, setHightlightText, NULL, NULL},
532 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
533 NULL, getColor, setClipTitleColor, NULL, NULL},
534 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
535 NULL, getColor, setClipTitleColor, NULL, NULL},
536 {"FTitleColor", "white", (void *)WS_FOCUSED,
537 NULL, getColor, setWTitleColor, NULL, NULL},
538 {"PTitleColor", "white", (void *)WS_PFOCUSED,
539 NULL, getColor, setWTitleColor, NULL, NULL},
540 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
541 NULL, getColor, setWTitleColor, NULL, NULL},
542 {"FTitleBack", "(solid, black)", NULL,
543 NULL, getTexture, setFTitleBack, NULL, NULL},
544 {"PTitleBack", "(solid, \"#616161\")", NULL,
545 NULL, getTexture, setPTitleBack, NULL, NULL},
546 {"UTitleBack", "(solid, gray)", NULL,
547 NULL, getTexture, setUTitleBack, NULL, NULL},
548 {"ResizebarBack", "(solid, gray)", NULL,
549 NULL, getTexture, setResizebarBack, NULL, NULL},
550 {"MenuTitleColor", "white", NULL,
551 NULL, getColor, setMenuTitleColor, NULL, NULL},
552 {"MenuTextColor", "black", NULL,
553 NULL, getColor, setMenuTextColor, NULL, NULL},
554 {"MenuDisabledColor", "\"#616161\"", NULL,
555 NULL, getColor, setMenuDisabledColor, NULL, NULL},
556 {"MenuTitleBack", "(solid, black)", NULL,
557 NULL, getTexture, setMenuTitleBack, NULL, NULL},
558 {"MenuTextBack", "(solid, gray)", NULL,
559 NULL, getTexture, setMenuTextBack, NULL, NULL},
560 {"IconTitleColor", "white", NULL,
561 NULL, getColor, setIconTitleColor, NULL, NULL},
562 {"IconTitleBack", "black", NULL,
563 NULL, getColor, setIconTitleBack, NULL, NULL},
564 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
565 NULL, getPropList, setSwPOptions, NULL, NULL},
566 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
567 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
568 {"FrameBorderWidth", "1", NULL,
569 NULL, getInt, setFrameBorderWidth, NULL, NULL},
570 {"FrameBorderColor", "black", NULL,
571 NULL, getColor, setFrameBorderColor, NULL, NULL},
572 {"FrameFocusedBorderColor", "black", NULL,
573 NULL, getColor, setFrameFocusedBorderColor, NULL, NULL},
574 {"FrameSelectedBorderColor", "white", NULL,
575 NULL, getColor, setFrameSelectedBorderColor, NULL, NULL},
577 /* keybindings */
579 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
580 NULL, getKeybind, setKeyGrab, NULL, NULL},
581 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
582 NULL, getKeybind, setKeyGrab, NULL, NULL},
583 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
584 NULL, getKeybind, setKeyGrab, NULL, NULL},
585 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
586 NULL, getKeybind, setKeyGrab, NULL, NULL},
587 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
588 NULL, getKeybind, setKeyGrab, NULL, NULL},
589 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
590 NULL, getKeybind, setKeyGrab, NULL, NULL},
591 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
592 NULL, getKeybind, setKeyGrab, NULL, NULL },
593 {"HideKey", "None", (void *)WKBD_HIDE,
594 NULL, getKeybind, setKeyGrab, NULL, NULL},
595 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
596 NULL, getKeybind, setKeyGrab, NULL, NULL},
597 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
598 NULL, getKeybind, setKeyGrab, NULL, NULL},
599 {"CloseKey", "None", (void *)WKBD_CLOSE,
600 NULL, getKeybind, setKeyGrab, NULL, NULL},
601 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
602 NULL, getKeybind, setKeyGrab, NULL, NULL},
603 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
604 NULL, getKeybind, setKeyGrab, NULL, NULL},
605 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
606 NULL, getKeybind, setKeyGrab, NULL, NULL},
607 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
608 NULL, getKeybind, setKeyGrab, NULL, NULL},
609 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
610 NULL, getKeybind, setKeyGrab, NULL, NULL},
611 {"THMaximizeKey", "None", (void*)WKBD_THMAXIMIZE,
612 NULL, getKeybind, setKeyGrab, NULL, NULL},
613 {"BHMaximizeKey", "None", (void*)WKBD_BHMAXIMIZE,
614 NULL, getKeybind, setKeyGrab, NULL, NULL},
615 {"LTCMaximizeKey", "None", (void*)WKBD_LTCMAXIMIZE,
616 NULL, getKeybind, setKeyGrab, NULL, NULL},
617 {"RTCMaximizeKey", "None", (void*)WKBD_RTCMAXIMIZE,
618 NULL, getKeybind, setKeyGrab, NULL, NULL},
619 {"LBCMaximizeKey", "None", (void*)WKBD_LBCMAXIMIZE,
620 NULL, getKeybind, setKeyGrab, NULL, NULL},
621 {"RBCMaximizeKey", "None", (void*)WKBD_RBCMAXIMIZE,
622 NULL, getKeybind, setKeyGrab, NULL, NULL},
623 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
624 NULL, getKeybind, setKeyGrab, NULL, NULL},
625 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
626 NULL, getKeybind, setKeyGrab, NULL, NULL},
627 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
628 NULL, getKeybind, setKeyGrab, NULL, NULL},
629 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
630 NULL, getKeybind, setKeyGrab, NULL, NULL},
631 {"ShadeKey", "None", (void *)WKBD_SHADE,
632 NULL, getKeybind, setKeyGrab, NULL, NULL},
633 {"SelectKey", "None", (void *)WKBD_SELECT,
634 NULL, getKeybind, setKeyGrab, NULL, NULL},
635 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
636 NULL, getKeybind, setKeyGrab, NULL, NULL},
637 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
638 NULL, getKeybind, setKeyGrab, NULL, NULL},
639 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
640 NULL, getKeybind, setKeyGrab, NULL, NULL},
641 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
642 NULL, getKeybind, setKeyGrab, NULL, NULL},
643 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
644 NULL, getKeybind, setKeyGrab, NULL, NULL},
645 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
646 NULL, getKeybind, setKeyGrab, NULL, NULL},
647 {"LastWorkspaceKey", "None", (void *)WKBD_LASTWORKSPACE,
648 NULL, getKeybind, setKeyGrab, NULL, NULL},
649 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
650 NULL, getKeybind, setKeyGrab, NULL, NULL},
651 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
652 NULL, getKeybind, setKeyGrab, NULL, NULL},
653 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
654 NULL, getKeybind, setKeyGrab, NULL, NULL},
655 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
656 NULL, getKeybind, setKeyGrab, NULL, NULL},
657 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
658 NULL, getKeybind, setKeyGrab, NULL, NULL},
659 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
660 NULL, getKeybind, setKeyGrab, NULL, NULL},
661 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
662 NULL, getKeybind, setKeyGrab, NULL, NULL},
663 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
664 NULL, getKeybind, setKeyGrab, NULL, NULL},
665 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
666 NULL, getKeybind, setKeyGrab, NULL, NULL},
667 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
668 NULL, getKeybind, setKeyGrab, NULL, NULL},
669 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
670 NULL, getKeybind, setKeyGrab, NULL, NULL},
671 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
672 NULL, getKeybind, setKeyGrab, NULL, NULL},
673 {"MoveToWorkspace1Key", "None", (void *)WKBD_MOVE_WORKSPACE1,
674 NULL, getKeybind, setKeyGrab, NULL, NULL},
675 {"MoveToWorkspace2Key", "None", (void *)WKBD_MOVE_WORKSPACE2,
676 NULL, getKeybind, setKeyGrab, NULL, NULL},
677 {"MoveToWorkspace3Key", "None", (void *)WKBD_MOVE_WORKSPACE3,
678 NULL, getKeybind, setKeyGrab, NULL, NULL},
679 {"MoveToWorkspace4Key", "None", (void *)WKBD_MOVE_WORKSPACE4,
680 NULL, getKeybind, setKeyGrab, NULL, NULL},
681 {"MoveToWorkspace5Key", "None", (void *)WKBD_MOVE_WORKSPACE5,
682 NULL, getKeybind, setKeyGrab, NULL, NULL},
683 {"MoveToWorkspace6Key", "None", (void *)WKBD_MOVE_WORKSPACE6,
684 NULL, getKeybind, setKeyGrab, NULL, NULL},
685 {"MoveToWorkspace7Key", "None", (void *)WKBD_MOVE_WORKSPACE7,
686 NULL, getKeybind, setKeyGrab, NULL, NULL},
687 {"MoveToWorkspace8Key", "None", (void *)WKBD_MOVE_WORKSPACE8,
688 NULL, getKeybind, setKeyGrab, NULL, NULL},
689 {"MoveToWorkspace9Key", "None", (void *)WKBD_MOVE_WORKSPACE9,
690 NULL, getKeybind, setKeyGrab, NULL, NULL},
691 {"MoveToWorkspace10Key", "None", (void *)WKBD_MOVE_WORKSPACE10,
692 NULL, getKeybind, setKeyGrab, NULL, NULL},
693 {"MoveToNextWorkspaceKey", "None", (void *)WKBD_MOVE_NEXTWORKSPACE,
694 NULL, getKeybind, setKeyGrab, NULL, NULL},
695 {"MoveToPrevWorkspaceKey", "None", (void *)WKBD_MOVE_PREVWORKSPACE,
696 NULL, getKeybind, setKeyGrab, NULL, NULL},
697 {"MoveToLastWorkspaceKey", "None", (void *)WKBD_MOVE_LASTWORKSPACE,
698 NULL, getKeybind, setKeyGrab, NULL, NULL},
699 {"MoveToNextWorkspaceLayerKey", "None", (void *)WKBD_MOVE_NEXTWSLAYER,
700 NULL, getKeybind, setKeyGrab, NULL, NULL},
701 {"MoveToPrevWorkspaceLayerKey", "None", (void *)WKBD_MOVE_PREVWSLAYER,
702 NULL, getKeybind, setKeyGrab, NULL, NULL},
703 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
704 NULL, getKeybind, setKeyGrab, NULL, NULL},
705 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
706 NULL, getKeybind, setKeyGrab, NULL, NULL},
707 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
708 NULL, getKeybind, setKeyGrab, NULL, NULL},
709 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
710 NULL, getKeybind, setKeyGrab, NULL, NULL},
711 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
712 NULL, getKeybind, setKeyGrab, NULL, NULL},
713 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
714 NULL, getKeybind, setKeyGrab, NULL, NULL},
715 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
716 NULL, getKeybind, setKeyGrab, NULL, NULL},
717 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
718 NULL, getKeybind, setKeyGrab, NULL, NULL},
719 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
720 NULL, getKeybind, setKeyGrab, NULL, NULL},
721 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
722 NULL, getKeybind, setKeyGrab, NULL, NULL},
723 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
724 NULL, getKeybind, setKeyGrab, NULL, NULL},
725 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
726 NULL, getKeybind, setKeyGrab, NULL, NULL},
727 {"RunKey", "None", (void *)WKBD_RUN,
728 NULL, getKeybind, setKeyGrab, NULL, NULL},
730 #ifdef KEEP_XKB_LOCK_STATUS
731 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
732 NULL, getKeybind, setKeyGrab, NULL, NULL},
733 {"KbdModeLock", "NO", NULL,
734 &wPreferences.modelock, getBool, NULL, NULL, NULL},
735 #endif /* KEEP_XKB_LOCK_STATUS */
737 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
738 NULL, getCursor, setCursor, NULL, NULL},
739 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
740 NULL, getCursor, setCursor, NULL, NULL},
741 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
742 NULL, getCursor, setCursor, NULL, NULL},
743 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
744 NULL, getCursor, setCursor, NULL, NULL},
745 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
746 NULL, getCursor, setCursor, NULL, NULL},
747 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
748 NULL, getCursor, setCursor, NULL, NULL},
749 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
750 NULL, getCursor, setCursor, NULL, NULL},
751 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
752 NULL, getCursor, setCursor, NULL, NULL},
753 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
754 NULL, getCursor, setCursor, NULL, NULL},
755 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
756 NULL, getCursor, setCursor, NULL, NULL},
757 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
758 NULL, getCursor, setCursor, NULL, NULL},
759 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
760 NULL, getCursor, setCursor, NULL, NULL},
761 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
762 NULL, getCursor, setCursor, NULL, NULL},
763 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
764 NULL, getCursor, setCursor, NULL, NULL},
765 {"DialogHistoryLines", "500", NULL,
766 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
767 {"CycleActiveHeadOnly", "NO", NULL,
768 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL},
769 {"CycleIgnoreMinimized", "NO", NULL,
770 &wPreferences.cycle_ignore_minimized, getBool, NULL, NULL, NULL}
773 static void initDefaults(void)
775 unsigned int i;
776 WDefaultEntry *entry;
778 WMPLSetCaseSensitive(False);
780 for (i = 0; i < wlengthof(optionList); i++) {
781 entry = &optionList[i];
783 entry->plkey = WMCreatePLString(entry->key);
784 if (entry->default_value)
785 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
786 else
787 entry->plvalue = NULL;
790 for (i = 0; i < wlengthof(staticOptionList); i++) {
791 entry = &staticOptionList[i];
793 entry->plkey = WMCreatePLString(entry->key);
794 if (entry->default_value)
795 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
796 else
797 entry->plvalue = NULL;
801 static WMPropList *readGlobalDomain(const char *domainName, Bool requireDictionary)
803 WMPropList *globalDict = NULL;
804 char path[PATH_MAX];
805 struct stat stbuf;
807 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
808 if (stat(path, &stbuf) >= 0) {
809 globalDict = WMReadPropListFromFile(path);
810 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
811 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
812 WMReleasePropList(globalDict);
813 globalDict = NULL;
814 } else if (!globalDict) {
815 wwarning(_("could not load domain %s from global defaults database"), domainName);
819 return globalDict;
822 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
823 static void prependMenu(WMPropList * destarr, WMPropList * array)
825 WMPropList *item;
826 int i;
828 for (i = 0; i < WMGetPropListItemCount(array); i++) {
829 item = WMGetFromPLArray(array, i);
830 if (item)
831 WMInsertInPLArray(destarr, i + 1, item);
835 static void appendMenu(WMPropList * destarr, WMPropList * array)
837 WMPropList *item;
838 int i;
840 for (i = 0; i < WMGetPropListItemCount(array); i++) {
841 item = WMGetFromPLArray(array, i);
842 if (item)
843 WMAddToPLArray(destarr, item);
846 #endif
848 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
850 WMPropList *menu = menuDomain->dictionary;
851 WMPropList *submenu;
853 if (!menu || !WMIsPLArray(menu))
854 return;
856 #ifdef GLOBAL_PREAMBLE_MENU_FILE
857 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
859 if (submenu && !WMIsPLArray(submenu)) {
860 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
861 WMReleasePropList(submenu);
862 submenu = NULL;
864 if (submenu) {
865 prependMenu(menu, submenu);
866 WMReleasePropList(submenu);
868 #endif
870 #ifdef GLOBAL_EPILOGUE_MENU_FILE
871 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
873 if (submenu && !WMIsPLArray(submenu)) {
874 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
875 WMReleasePropList(submenu);
876 submenu = NULL;
878 if (submenu) {
879 appendMenu(menu, submenu);
880 WMReleasePropList(submenu);
882 #endif
884 menuDomain->dictionary = menu;
887 WDDomain *wDefaultsInitDomain(const char *domain, Bool requireDictionary)
889 WDDomain *db;
890 struct stat stbuf;
891 static int inited = 0;
892 WMPropList *shared_dict = NULL;
894 if (!inited) {
895 inited = 1;
896 initDefaults();
899 db = wmalloc(sizeof(WDDomain));
900 db->domain_name = domain;
901 db->path = wdefaultspathfordomain(domain);
903 if (stat(db->path, &stbuf) >= 0) {
904 db->dictionary = WMReadPropListFromFile(db->path);
905 if (db->dictionary) {
906 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
907 WMReleasePropList(db->dictionary);
908 db->dictionary = NULL;
909 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, db->path);
911 db->timestamp = stbuf.st_mtime;
912 } else {
913 wwarning(_("could not load domain %s from user defaults database"), domain);
917 /* global system dictionary */
918 shared_dict = readGlobalDomain(domain, requireDictionary);
920 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
921 WMIsPLDictionary(db->dictionary)) {
922 WMMergePLDictionaries(shared_dict, db->dictionary, True);
923 WMReleasePropList(db->dictionary);
924 db->dictionary = shared_dict;
925 if (stbuf.st_mtime > db->timestamp)
926 db->timestamp = stbuf.st_mtime;
927 } else if (!db->dictionary) {
928 db->dictionary = shared_dict;
929 if (stbuf.st_mtime > db->timestamp)
930 db->timestamp = stbuf.st_mtime;
933 return db;
936 void wReadStaticDefaults(WMPropList * dict)
938 WMPropList *plvalue;
939 WDefaultEntry *entry;
940 unsigned int i;
941 void *tdata;
943 for (i = 0; i < wlengthof(staticOptionList); i++) {
944 entry = &staticOptionList[i];
946 if (dict)
947 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
948 else
949 plvalue = NULL;
951 /* no default in the DB. Use builtin default */
952 if (!plvalue)
953 plvalue = entry->plvalue;
955 if (plvalue) {
956 /* convert data */
957 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
958 if (entry->update)
959 (*entry->update) (NULL, entry, tdata, entry->extra_data);
964 void wDefaultsCheckDomains(void* arg)
966 WScreen *scr;
967 struct stat stbuf;
968 WMPropList *shared_dict = NULL;
969 WMPropList *dict;
970 int i;
972 /* Parameter not used, but tell the compiler that it is ok */
973 (void) arg;
975 if (stat(w_global.domain.wmaker->path, &stbuf) >= 0 && w_global.domain.wmaker->timestamp < stbuf.st_mtime) {
976 w_global.domain.wmaker->timestamp = stbuf.st_mtime;
978 /* Global dictionary */
979 shared_dict = readGlobalDomain("WindowMaker", True);
981 /* User dictionary */
982 dict = WMReadPropListFromFile(w_global.domain.wmaker->path);
984 if (dict) {
985 if (!WMIsPLDictionary(dict)) {
986 WMReleasePropList(dict);
987 dict = NULL;
988 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
989 "WindowMaker", w_global.domain.wmaker->path);
990 } else {
991 if (shared_dict) {
992 WMMergePLDictionaries(shared_dict, dict, True);
993 WMReleasePropList(dict);
994 dict = shared_dict;
995 shared_dict = NULL;
998 for (i = 0; i < w_global.screen_count; i++) {
999 scr = wScreenWithNumber(i);
1000 if (scr)
1001 wReadDefaults(scr, dict);
1004 if (w_global.domain.wmaker->dictionary)
1005 WMReleasePropList(w_global.domain.wmaker->dictionary);
1007 w_global.domain.wmaker->dictionary = dict;
1009 } else {
1010 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1013 if (shared_dict)
1014 WMReleasePropList(shared_dict);
1018 if (stat(w_global.domain.window_attr->path, &stbuf) >= 0 && w_global.domain.window_attr->timestamp < stbuf.st_mtime) {
1019 /* global dictionary */
1020 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1021 /* user dictionary */
1022 dict = WMReadPropListFromFile(w_global.domain.window_attr->path);
1023 if (dict) {
1024 if (!WMIsPLDictionary(dict)) {
1025 WMReleasePropList(dict);
1026 dict = NULL;
1027 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1028 "WMWindowAttributes", w_global.domain.window_attr->path);
1029 } else {
1030 if (shared_dict) {
1031 WMMergePLDictionaries(shared_dict, dict, True);
1032 WMReleasePropList(dict);
1033 dict = shared_dict;
1034 shared_dict = NULL;
1037 if (w_global.domain.window_attr->dictionary)
1038 WMReleasePropList(w_global.domain.window_attr->dictionary);
1040 w_global.domain.window_attr->dictionary = dict;
1041 for (i = 0; i < w_global.screen_count; i++) {
1042 scr = wScreenWithNumber(i);
1043 if (scr) {
1044 wDefaultUpdateIcons(scr);
1046 /* Update the panel image if changed */
1047 /* Don't worry. If the image is the same these
1048 * functions will have no performance impact. */
1049 create_logo_image(scr);
1053 } else {
1054 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1057 w_global.domain.window_attr->timestamp = stbuf.st_mtime;
1058 if (shared_dict)
1059 WMReleasePropList(shared_dict);
1062 if (stat(w_global.domain.root_menu->path, &stbuf) >= 0 && w_global.domain.root_menu->timestamp < stbuf.st_mtime) {
1063 dict = WMReadPropListFromFile(w_global.domain.root_menu->path);
1064 if (dict) {
1065 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1066 WMReleasePropList(dict);
1067 dict = NULL;
1068 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1069 "WMRootMenu", w_global.domain.root_menu->path);
1070 } else {
1071 if (w_global.domain.root_menu->dictionary)
1072 WMReleasePropList(w_global.domain.root_menu->dictionary);
1074 w_global.domain.root_menu->dictionary = dict;
1075 wDefaultsMergeGlobalMenus(w_global.domain.root_menu);
1077 } else {
1078 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1080 w_global.domain.root_menu->timestamp = stbuf.st_mtime;
1082 #ifndef HAVE_INOTIFY
1083 if (!arg)
1084 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1085 #endif
1088 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1090 WMPropList *plvalue, *old_value;
1091 WDefaultEntry *entry;
1092 unsigned int i;
1093 int update_workspace_back = 0; /* kluge :/ */
1094 unsigned int needs_refresh;
1095 void *tdata;
1096 WMPropList *old_dict = (w_global.domain.wmaker->dictionary != new_dict ? w_global.domain.wmaker->dictionary : NULL);
1098 needs_refresh = 0;
1100 for (i = 0; i < wlengthof(optionList); i++) {
1101 entry = &optionList[i];
1103 if (new_dict)
1104 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1105 else
1106 plvalue = NULL;
1108 if (!old_dict)
1109 old_value = NULL;
1110 else
1111 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1113 if (!plvalue && !old_value) {
1114 /* no default in the DB. Use builtin default */
1115 plvalue = entry->plvalue;
1116 if (plvalue && new_dict)
1117 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1119 } else if (!plvalue) {
1120 /* value was deleted from DB. Keep current value */
1121 continue;
1122 } else if (!old_value) {
1123 /* set value for the 1st time */
1124 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1125 /* value has changed */
1126 } else {
1127 if (strcmp(entry->key, "WorkspaceBack") == 0
1128 && update_workspace_back && scr->flags.backimage_helper_launched) {
1129 } else {
1130 /* value was not changed since last time */
1131 continue;
1135 if (plvalue) {
1136 /* convert data */
1137 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1139 * If the WorkspaceSpecificBack data has been changed
1140 * so that the helper will be launched now, we must be
1141 * sure to send the default background texture config
1142 * to the helper.
1144 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1145 !scr->flags.backimage_helper_launched)
1146 update_workspace_back = 1;
1148 if (entry->update)
1149 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1155 if (needs_refresh != 0 && !scr->flags.startup) {
1156 int foo;
1158 foo = 0;
1159 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1160 foo |= WTextureSettings;
1161 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1162 foo |= WFontSettings;
1163 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1164 foo |= WColorSettings;
1165 if (foo)
1166 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1167 (void *)(uintptr_t) foo);
1169 foo = 0;
1170 if (needs_refresh & REFRESH_MENU_TEXTURE)
1171 foo |= WTextureSettings;
1172 if (needs_refresh & REFRESH_MENU_FONT)
1173 foo |= WFontSettings;
1174 if (needs_refresh & REFRESH_MENU_COLOR)
1175 foo |= WColorSettings;
1176 if (foo)
1177 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1179 foo = 0;
1180 if (needs_refresh & REFRESH_WINDOW_FONT)
1181 foo |= WFontSettings;
1182 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1183 foo |= WTextureSettings;
1184 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1185 foo |= WColorSettings;
1186 if (foo)
1187 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1189 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1190 foo = 0;
1191 if (needs_refresh & REFRESH_ICON_FONT)
1192 foo |= WFontSettings;
1193 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1194 foo |= WTextureSettings;
1195 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1196 foo |= WTextureSettings;
1197 if (foo)
1198 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1199 (void *)(uintptr_t) foo);
1201 if (needs_refresh & REFRESH_ICON_TILE)
1202 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1204 if (needs_refresh & REFRESH_WORKSPACE_MENU) {
1205 if (w_global.workspace.menu)
1206 wWorkspaceMenuUpdate(w_global.workspace.menu);
1207 if (w_global.clip.ws_menu)
1208 wWorkspaceMenuUpdate(w_global.clip.ws_menu);
1209 if (w_global.workspace.submenu)
1210 w_global.workspace.submenu->flags.realized = 0;
1211 if (w_global.clip.submenu)
1212 w_global.clip.submenu->flags.realized = 0;
1217 void wDefaultUpdateIcons(WScreen *scr)
1219 WAppIcon *aicon = w_global.app_icon_list;
1220 WDrawerChain *dc;
1221 WWindow *wwin = scr->focused_window;
1223 while (aicon) {
1224 /* Get the application icon, default included */
1225 wIconChangeImageFile(aicon->icon, NULL);
1226 wAppIconPaint(aicon);
1227 aicon = aicon->next;
1230 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock)
1231 wClipIconPaint();
1233 for (dc = scr->drawers; dc != NULL; dc = dc->next)
1234 wDrawerIconPaint(dc->adrawer->icon_array[0]);
1236 while (wwin) {
1237 if (wwin->icon && wwin->flags.miniaturized)
1238 wIconChangeImageFile(wwin->icon, NULL);
1239 wwin = wwin->prev;
1243 /* --------------------------- Local ----------------------- */
1245 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1246 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1247 entry->key, x); \
1248 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1249 var = entry->default_value;\
1250 } else var = WMGetFromPLString(value)\
1253 static int string2index(WMPropList *key, WMPropList *val, const char *def, WOptionEnumeration * values)
1255 char *str;
1256 WOptionEnumeration *v;
1257 char buffer[TOTAL_VALUES_LENGTH];
1259 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1260 for (v = values; v->string != NULL; v++) {
1261 if (strcasecmp(v->string, str) == 0)
1262 return v->value;
1266 buffer[0] = 0;
1267 for (v = values; v->string != NULL; v++) {
1268 if (!v->is_alias) {
1269 if (buffer[0] != 0)
1270 strcat(buffer, ", ");
1271 snprintf(buffer+strlen(buffer),
1272 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1275 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1276 WMGetFromPLString(key),
1277 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1278 buffer);
1280 if (def) {
1281 return string2index(key, val, NULL, values);
1284 return -1;
1288 * value - is the value in the defaults DB
1289 * addr - is the address to store the data
1290 * ret - is the address to store a pointer to a temporary buffer. ret
1291 * must not be freed and is used by the set functions
1293 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1295 static char data;
1296 const char *val;
1297 int second_pass = 0;
1299 /* Parameter not used, but tell the compiler that it is ok */
1300 (void) scr;
1302 GET_STRING_OR_DEFAULT("Boolean", val);
1304 again:
1305 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1306 || strcasecmp(val, "YES") == 0) {
1308 data = 1;
1309 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1310 || strcasecmp(val, "NO") == 0) {
1311 data = 0;
1312 } else {
1313 int i;
1314 if (sscanf(val, "%i", &i) == 1) {
1315 if (i != 0)
1316 data = 1;
1317 else
1318 data = 0;
1319 } else {
1320 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1321 if (second_pass == 0) {
1322 val = WMGetFromPLString(entry->plvalue);
1323 second_pass = 1;
1324 wwarning(_("using default \"%s\" instead"), val);
1325 goto again;
1327 return False;
1331 if (ret)
1332 *ret = &data;
1333 if (addr)
1334 *(char *)addr = data;
1336 return True;
1339 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1341 static int data;
1342 const char *val;
1344 /* Parameter not used, but tell the compiler that it is ok */
1345 (void) scr;
1347 GET_STRING_OR_DEFAULT("Integer", val);
1349 if (sscanf(val, "%i", &data) != 1) {
1350 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1351 val = WMGetFromPLString(entry->plvalue);
1352 wwarning(_("using default \"%s\" instead"), val);
1353 if (sscanf(val, "%i", &data) != 1) {
1354 return False;
1358 if (ret)
1359 *ret = &data;
1360 if (addr)
1361 *(int *)addr = data;
1363 return True;
1366 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1368 static WCoord data;
1369 char *val_x, *val_y;
1370 int nelem, changed = 0;
1371 WMPropList *elem_x, *elem_y;
1373 again:
1374 if (!WMIsPLArray(value)) {
1375 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1376 if (changed == 0) {
1377 value = entry->plvalue;
1378 changed = 1;
1379 wwarning(_("using default \"%s\" instead"), entry->default_value);
1380 goto again;
1382 return False;
1385 nelem = WMGetPropListItemCount(value);
1386 if (nelem != 2) {
1387 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1388 if (changed == 0) {
1389 value = entry->plvalue;
1390 changed = 1;
1391 wwarning(_("using default \"%s\" instead"), entry->default_value);
1392 goto again;
1394 return False;
1397 elem_x = WMGetFromPLArray(value, 0);
1398 elem_y = WMGetFromPLArray(value, 1);
1400 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1401 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1402 if (changed == 0) {
1403 value = entry->plvalue;
1404 changed = 1;
1405 wwarning(_("using default \"%s\" instead"), entry->default_value);
1406 goto again;
1408 return False;
1411 val_x = WMGetFromPLString(elem_x);
1412 val_y = WMGetFromPLString(elem_y);
1414 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1415 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1416 if (changed == 0) {
1417 value = entry->plvalue;
1418 changed = 1;
1419 wwarning(_("using default \"%s\" instead"), entry->default_value);
1420 goto again;
1422 return False;
1425 if (data.x < 0)
1426 data.x = 0;
1427 else if (data.x > scr->scr_width / 3)
1428 data.x = scr->scr_width / 3;
1429 if (data.y < 0)
1430 data.y = 0;
1431 else if (data.y > scr->scr_height / 3)
1432 data.y = scr->scr_height / 3;
1434 if (ret)
1435 *ret = &data;
1436 if (addr)
1437 *(WCoord *) addr = data;
1439 return True;
1442 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1444 /* Parameter not used, but tell the compiler that it is ok */
1445 (void) scr;
1446 (void) entry;
1447 (void) addr;
1449 WMRetainPropList(value);
1451 *ret = value;
1453 return True;
1456 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1458 static char *data;
1459 int i, count, len;
1460 char *ptr;
1461 WMPropList *d;
1462 int changed = 0;
1464 /* Parameter not used, but tell the compiler that it is ok */
1465 (void) scr;
1466 (void) ret;
1468 again:
1469 if (!WMIsPLArray(value)) {
1470 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1471 if (changed == 0) {
1472 value = entry->plvalue;
1473 changed = 1;
1474 wwarning(_("using default \"%s\" instead"), entry->default_value);
1475 goto again;
1477 return False;
1480 i = 0;
1481 count = WMGetPropListItemCount(value);
1482 if (count < 1) {
1483 if (changed == 0) {
1484 value = entry->plvalue;
1485 changed = 1;
1486 wwarning(_("using default \"%s\" instead"), entry->default_value);
1487 goto again;
1489 return False;
1492 len = 0;
1493 for (i = 0; i < count; i++) {
1494 d = WMGetFromPLArray(value, i);
1495 if (!d || !WMIsPLString(d)) {
1496 count = i;
1497 break;
1499 len += strlen(WMGetFromPLString(d)) + 1;
1502 ptr = data = wmalloc(len + 1);
1504 for (i = 0; i < count; i++) {
1505 d = WMGetFromPLArray(value, i);
1506 if (!d || !WMIsPLString(d)) {
1507 break;
1509 strcpy(ptr, WMGetFromPLString(d));
1510 ptr += strlen(WMGetFromPLString(d));
1511 *ptr = ':';
1512 ptr++;
1514 ptr--;
1515 *(ptr--) = 0;
1517 if (*(char **)addr != NULL) {
1518 wfree(*(char **)addr);
1520 *(char **)addr = data;
1522 return True;
1525 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1527 static signed char data;
1529 /* Parameter not used, but tell the compiler that it is ok */
1530 (void) scr;
1532 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1533 if (data < 0)
1534 return False;
1536 if (ret)
1537 *ret = &data;
1538 if (addr)
1539 *(signed char *)addr = data;
1541 return True;
1545 * (solid <color>)
1546 * (hgradient <color> <color>)
1547 * (vgradient <color> <color>)
1548 * (dgradient <color> <color>)
1549 * (mhgradient <color> <color> ...)
1550 * (mvgradient <color> <color> ...)
1551 * (mdgradient <color> <color> ...)
1552 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1553 * (tpixmap <file> <color>)
1554 * (spixmap <file> <color>)
1555 * (cpixmap <file> <color>)
1556 * (thgradient <file> <opaqueness> <color> <color>)
1557 * (tvgradient <file> <opaqueness> <color> <color>)
1558 * (tdgradient <file> <opaqueness> <color> <color>)
1559 * (function <lib> <function> ...)
1562 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1564 WMPropList *elem;
1565 char *val;
1566 int nelem;
1567 WTexture *texture = NULL;
1569 nelem = WMGetPropListItemCount(pl);
1570 if (nelem < 1)
1571 return NULL;
1573 elem = WMGetFromPLArray(pl, 0);
1574 if (!elem || !WMIsPLString(elem))
1575 return NULL;
1576 val = WMGetFromPLString(elem);
1578 if (strcasecmp(val, "solid") == 0) {
1579 XColor color;
1581 if (nelem != 2)
1582 return NULL;
1584 /* get color */
1586 elem = WMGetFromPLArray(pl, 1);
1587 if (!elem || !WMIsPLString(elem))
1588 return NULL;
1589 val = WMGetFromPLString(elem);
1591 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1592 wwarning(_("\"%s\" is not a valid color name"), val);
1593 return NULL;
1596 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1597 } else if (strcasecmp(val, "dgradient") == 0
1598 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1599 RColor color1, color2;
1600 XColor xcolor;
1601 int type;
1603 if (nelem != 3) {
1604 wwarning(_("bad number of arguments in gradient specification"));
1605 return NULL;
1608 if (val[0] == 'd' || val[0] == 'D')
1609 type = WTEX_DGRADIENT;
1610 else if (val[0] == 'h' || val[0] == 'H')
1611 type = WTEX_HGRADIENT;
1612 else
1613 type = WTEX_VGRADIENT;
1615 /* get from color */
1616 elem = WMGetFromPLArray(pl, 1);
1617 if (!elem || !WMIsPLString(elem))
1618 return NULL;
1619 val = WMGetFromPLString(elem);
1621 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1622 wwarning(_("\"%s\" is not a valid color name"), val);
1623 return NULL;
1625 color1.alpha = 255;
1626 color1.red = xcolor.red >> 8;
1627 color1.green = xcolor.green >> 8;
1628 color1.blue = xcolor.blue >> 8;
1630 /* get to color */
1631 elem = WMGetFromPLArray(pl, 2);
1632 if (!elem || !WMIsPLString(elem)) {
1633 return NULL;
1635 val = WMGetFromPLString(elem);
1637 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1638 wwarning(_("\"%s\" is not a valid color name"), val);
1639 return NULL;
1641 color2.alpha = 255;
1642 color2.red = xcolor.red >> 8;
1643 color2.green = xcolor.green >> 8;
1644 color2.blue = xcolor.blue >> 8;
1646 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1648 } else if (strcasecmp(val, "igradient") == 0) {
1649 RColor colors1[2], colors2[2];
1650 int th1, th2;
1651 XColor xcolor;
1652 int i;
1654 if (nelem != 7) {
1655 wwarning(_("bad number of arguments in gradient specification"));
1656 return NULL;
1659 /* get from color */
1660 for (i = 0; i < 2; i++) {
1661 elem = WMGetFromPLArray(pl, 1 + i);
1662 if (!elem || !WMIsPLString(elem))
1663 return NULL;
1664 val = WMGetFromPLString(elem);
1666 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1667 wwarning(_("\"%s\" is not a valid color name"), val);
1668 return NULL;
1670 colors1[i].alpha = 255;
1671 colors1[i].red = xcolor.red >> 8;
1672 colors1[i].green = xcolor.green >> 8;
1673 colors1[i].blue = xcolor.blue >> 8;
1675 elem = WMGetFromPLArray(pl, 3);
1676 if (!elem || !WMIsPLString(elem))
1677 return NULL;
1678 val = WMGetFromPLString(elem);
1679 th1 = atoi(val);
1681 /* get from color */
1682 for (i = 0; i < 2; i++) {
1683 elem = WMGetFromPLArray(pl, 4 + i);
1684 if (!elem || !WMIsPLString(elem))
1685 return NULL;
1686 val = WMGetFromPLString(elem);
1688 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1689 wwarning(_("\"%s\" is not a valid color name"), val);
1690 return NULL;
1692 colors2[i].alpha = 255;
1693 colors2[i].red = xcolor.red >> 8;
1694 colors2[i].green = xcolor.green >> 8;
1695 colors2[i].blue = xcolor.blue >> 8;
1697 elem = WMGetFromPLArray(pl, 6);
1698 if (!elem || !WMIsPLString(elem))
1699 return NULL;
1700 val = WMGetFromPLString(elem);
1701 th2 = atoi(val);
1703 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1705 } else if (strcasecmp(val, "mhgradient") == 0
1706 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1707 XColor color;
1708 RColor **colors;
1709 int i, count;
1710 int type;
1712 if (nelem < 3) {
1713 wwarning(_("too few arguments in multicolor gradient specification"));
1714 return NULL;
1717 if (val[1] == 'h' || val[1] == 'H')
1718 type = WTEX_MHGRADIENT;
1719 else if (val[1] == 'v' || val[1] == 'V')
1720 type = WTEX_MVGRADIENT;
1721 else
1722 type = WTEX_MDGRADIENT;
1724 count = nelem - 1;
1726 colors = wmalloc(sizeof(RColor *) * (count + 1));
1728 for (i = 0; i < count; i++) {
1729 elem = WMGetFromPLArray(pl, i + 1);
1730 if (!elem || !WMIsPLString(elem)) {
1731 for (--i; i >= 0; --i) {
1732 wfree(colors[i]);
1734 wfree(colors);
1735 return NULL;
1737 val = WMGetFromPLString(elem);
1739 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1740 wwarning(_("\"%s\" is not a valid color name"), val);
1741 for (--i; i >= 0; --i) {
1742 wfree(colors[i]);
1744 wfree(colors);
1745 return NULL;
1746 } else {
1747 colors[i] = wmalloc(sizeof(RColor));
1748 colors[i]->red = color.red >> 8;
1749 colors[i]->green = color.green >> 8;
1750 colors[i]->blue = color.blue >> 8;
1753 colors[i] = NULL;
1755 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1756 } else if (strcasecmp(val, "spixmap") == 0 ||
1757 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1758 XColor color;
1759 int type;
1761 if (nelem != 3)
1762 return NULL;
1764 if (val[0] == 's' || val[0] == 'S')
1765 type = WTP_SCALE;
1766 else if (val[0] == 'c' || val[0] == 'C')
1767 type = WTP_CENTER;
1768 else
1769 type = WTP_TILE;
1771 /* get color */
1772 elem = WMGetFromPLArray(pl, 2);
1773 if (!elem || !WMIsPLString(elem)) {
1774 return NULL;
1776 val = WMGetFromPLString(elem);
1778 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1779 wwarning(_("\"%s\" is not a valid color name"), val);
1780 return NULL;
1783 /* file name */
1784 elem = WMGetFromPLArray(pl, 1);
1785 if (!elem || !WMIsPLString(elem))
1786 return NULL;
1787 val = WMGetFromPLString(elem);
1789 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1790 } else if (strcasecmp(val, "thgradient") == 0
1791 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1792 RColor color1, color2;
1793 XColor xcolor;
1794 int opacity;
1795 int style;
1797 if (val[1] == 'h' || val[1] == 'H')
1798 style = WTEX_THGRADIENT;
1799 else if (val[1] == 'v' || val[1] == 'V')
1800 style = WTEX_TVGRADIENT;
1801 else
1802 style = WTEX_TDGRADIENT;
1804 if (nelem != 5) {
1805 wwarning(_("bad number of arguments in textured gradient specification"));
1806 return NULL;
1809 /* get from color */
1810 elem = WMGetFromPLArray(pl, 3);
1811 if (!elem || !WMIsPLString(elem))
1812 return NULL;
1813 val = WMGetFromPLString(elem);
1815 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1816 wwarning(_("\"%s\" is not a valid color name"), val);
1817 return NULL;
1819 color1.alpha = 255;
1820 color1.red = xcolor.red >> 8;
1821 color1.green = xcolor.green >> 8;
1822 color1.blue = xcolor.blue >> 8;
1824 /* get to color */
1825 elem = WMGetFromPLArray(pl, 4);
1826 if (!elem || !WMIsPLString(elem)) {
1827 return NULL;
1829 val = WMGetFromPLString(elem);
1831 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1832 wwarning(_("\"%s\" is not a valid color name"), val);
1833 return NULL;
1835 color2.alpha = 255;
1836 color2.red = xcolor.red >> 8;
1837 color2.green = xcolor.green >> 8;
1838 color2.blue = xcolor.blue >> 8;
1840 /* get opacity */
1841 elem = WMGetFromPLArray(pl, 2);
1842 if (!elem || !WMIsPLString(elem))
1843 opacity = 128;
1844 else
1845 val = WMGetFromPLString(elem);
1847 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1848 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1849 opacity = 128;
1852 /* get file name */
1853 elem = WMGetFromPLArray(pl, 1);
1854 if (!elem || !WMIsPLString(elem))
1855 return NULL;
1856 val = WMGetFromPLString(elem);
1858 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1859 } else if (strcasecmp(val, "function") == 0) {
1860 /* Leave this in to handle the unlikely case of
1861 * someone actually having function textures configured */
1862 wwarning("function texture support has been removed");
1863 return NULL;
1864 } else {
1865 wwarning(_("invalid texture type %s"), val);
1866 return NULL;
1868 return texture;
1871 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1873 static WTexture *texture;
1874 int changed = 0;
1876 again:
1877 if (!WMIsPLArray(value)) {
1878 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1879 if (changed == 0) {
1880 value = entry->plvalue;
1881 changed = 1;
1882 wwarning(_("using default \"%s\" instead"), entry->default_value);
1883 goto again;
1885 return False;
1888 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1889 WMPropList *pl;
1891 pl = WMGetFromPLArray(value, 0);
1892 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1893 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1894 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1895 entry->key, "Solid Texture");
1897 value = entry->plvalue;
1898 changed = 1;
1899 wwarning(_("using default \"%s\" instead"), entry->default_value);
1900 goto again;
1904 texture = parse_texture(scr, value);
1906 if (!texture) {
1907 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1908 if (changed == 0) {
1909 value = entry->plvalue;
1910 changed = 1;
1911 wwarning(_("using default \"%s\" instead"), entry->default_value);
1912 goto again;
1914 return False;
1917 if (ret)
1918 *ret = &texture;
1920 if (addr)
1921 *(WTexture **) addr = texture;
1923 return True;
1926 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1928 WMPropList *elem;
1929 int changed = 0;
1930 char *val;
1931 int nelem;
1933 /* Parameter not used, but tell the compiler that it is ok */
1934 (void) scr;
1935 (void) addr;
1937 again:
1938 if (!WMIsPLArray(value)) {
1939 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1940 "WorkspaceBack", "Texture or None");
1941 if (changed == 0) {
1942 value = entry->plvalue;
1943 changed = 1;
1944 wwarning(_("using default \"%s\" instead"), entry->default_value);
1945 goto again;
1947 return False;
1950 /* only do basic error checking and verify for None texture */
1952 nelem = WMGetPropListItemCount(value);
1953 if (nelem > 0) {
1954 elem = WMGetFromPLArray(value, 0);
1955 if (!elem || !WMIsPLString(elem)) {
1956 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1957 if (changed == 0) {
1958 value = entry->plvalue;
1959 changed = 1;
1960 wwarning(_("using default \"%s\" instead"), entry->default_value);
1961 goto again;
1963 return False;
1965 val = WMGetFromPLString(elem);
1967 if (strcasecmp(val, "None") == 0)
1968 return True;
1970 *ret = WMRetainPropList(value);
1972 return True;
1975 static int
1976 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1978 WMPropList *elem;
1979 int nelem;
1980 int changed = 0;
1982 /* Parameter not used, but tell the compiler that it is ok */
1983 (void) scr;
1984 (void) addr;
1986 again:
1987 if (!WMIsPLArray(value)) {
1988 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1989 "WorkspaceSpecificBack", "an array of textures");
1990 if (changed == 0) {
1991 value = entry->plvalue;
1992 changed = 1;
1993 wwarning(_("using default \"%s\" instead"), entry->default_value);
1994 goto again;
1996 return False;
1999 /* only do basic error checking and verify for None texture */
2001 nelem = WMGetPropListItemCount(value);
2002 if (nelem > 0) {
2003 while (nelem--) {
2004 elem = WMGetFromPLArray(value, nelem);
2005 if (!elem || !WMIsPLArray(elem)) {
2006 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2007 nelem);
2012 *ret = WMRetainPropList(value);
2014 #ifdef notworking
2016 * Kluge to force wmsetbg helper to set the default background.
2017 * If the WorkspaceSpecificBack is changed once wmaker has started,
2018 * the WorkspaceBack won't be sent to the helper, unless the user
2019 * changes it's value too. So, we must force this by removing the
2020 * value from the defaults DB.
2022 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2023 WMPropList *key = WMCreatePLString("WorkspaceBack");
2025 WMRemoveFromPLDictionary(w_global.domain.wmaker->dictionary, key);
2027 WMReleasePropList(key);
2029 #endif
2030 return True;
2033 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2035 static WMFont *font;
2036 const char *val;
2038 (void) addr;
2040 GET_STRING_OR_DEFAULT("Font", val);
2042 font = WMCreateFont(scr->wmscreen, val);
2043 if (!font)
2044 font = WMCreateFont(scr->wmscreen, "fixed");
2046 if (!font) {
2047 wfatal(_("could not load any usable font!!!"));
2048 exit(1);
2051 if (ret)
2052 *ret = font;
2054 /* can't assign font value outside update function */
2055 wassertrv(addr == NULL, True);
2057 return True;
2060 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2062 static XColor color;
2063 const char *val;
2064 int second_pass = 0;
2066 (void) addr;
2068 GET_STRING_OR_DEFAULT("Color", val);
2070 again:
2071 if (!wGetColor(scr, val, &color)) {
2072 wwarning(_("could not get color for key \"%s\""), entry->key);
2073 if (second_pass == 0) {
2074 val = WMGetFromPLString(entry->plvalue);
2075 second_pass = 1;
2076 wwarning(_("using default \"%s\" instead"), val);
2077 goto again;
2079 return False;
2082 if (ret)
2083 *ret = &color;
2085 assert(addr == NULL);
2087 if (addr)
2088 *(unsigned long*)addr = pixel;
2091 return True;
2094 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2096 static WShortKey shortcut;
2097 KeySym ksym;
2098 const char *val;
2099 char *k;
2100 char buf[MAX_SHORTCUT_LENGTH], *b;
2102 /* Parameter not used, but tell the compiler that it is ok */
2103 (void) scr;
2104 (void) addr;
2106 GET_STRING_OR_DEFAULT("Key spec", val);
2108 if (!val || strcasecmp(val, "NONE") == 0) {
2109 shortcut.keycode = 0;
2110 shortcut.modifier = 0;
2111 if (ret)
2112 *ret = &shortcut;
2113 return True;
2116 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2118 b = (char *)buf;
2120 /* get modifiers */
2121 shortcut.modifier = 0;
2122 while ((k = strchr(b, '+')) != NULL) {
2123 int mod;
2125 *k = 0;
2126 mod = wXModifierFromKey(b);
2127 if (mod < 0) {
2128 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2129 return False;
2131 shortcut.modifier |= mod;
2133 b = k + 1;
2136 /* get key */
2137 ksym = XStringToKeysym(b);
2139 if (ksym == NoSymbol) {
2140 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2141 return False;
2144 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2145 if (shortcut.keycode == 0) {
2146 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2147 return False;
2150 if (ret)
2151 *ret = &shortcut;
2153 return True;
2156 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2158 static int mask;
2159 const char *str;
2161 /* Parameter not used, but tell the compiler that it is ok */
2162 (void) scr;
2164 GET_STRING_OR_DEFAULT("Modifier Key", str);
2166 if (!str)
2167 return False;
2169 mask = wXModifierFromKey(str);
2170 if (mask < 0) {
2171 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2172 mask = 0;
2173 return False;
2176 if (addr)
2177 *(int *)addr = mask;
2179 if (ret)
2180 *ret = &mask;
2182 return True;
2185 # include <X11/cursorfont.h>
2186 typedef struct {
2187 const char *name;
2188 int id;
2189 } WCursorLookup;
2191 #define CURSOR_ID_NONE (XC_num_glyphs)
2193 static const WCursorLookup cursor_table[] = {
2194 {"X_cursor", XC_X_cursor},
2195 {"arrow", XC_arrow},
2196 {"based_arrow_down", XC_based_arrow_down},
2197 {"based_arrow_up", XC_based_arrow_up},
2198 {"boat", XC_boat},
2199 {"bogosity", XC_bogosity},
2200 {"bottom_left_corner", XC_bottom_left_corner},
2201 {"bottom_right_corner", XC_bottom_right_corner},
2202 {"bottom_side", XC_bottom_side},
2203 {"bottom_tee", XC_bottom_tee},
2204 {"box_spiral", XC_box_spiral},
2205 {"center_ptr", XC_center_ptr},
2206 {"circle", XC_circle},
2207 {"clock", XC_clock},
2208 {"coffee_mug", XC_coffee_mug},
2209 {"cross", XC_cross},
2210 {"cross_reverse", XC_cross_reverse},
2211 {"crosshair", XC_crosshair},
2212 {"diamond_cross", XC_diamond_cross},
2213 {"dot", XC_dot},
2214 {"dotbox", XC_dotbox},
2215 {"double_arrow", XC_double_arrow},
2216 {"draft_large", XC_draft_large},
2217 {"draft_small", XC_draft_small},
2218 {"draped_box", XC_draped_box},
2219 {"exchange", XC_exchange},
2220 {"fleur", XC_fleur},
2221 {"gobbler", XC_gobbler},
2222 {"gumby", XC_gumby},
2223 {"hand1", XC_hand1},
2224 {"hand2", XC_hand2},
2225 {"heart", XC_heart},
2226 {"icon", XC_icon},
2227 {"iron_cross", XC_iron_cross},
2228 {"left_ptr", XC_left_ptr},
2229 {"left_side", XC_left_side},
2230 {"left_tee", XC_left_tee},
2231 {"leftbutton", XC_leftbutton},
2232 {"ll_angle", XC_ll_angle},
2233 {"lr_angle", XC_lr_angle},
2234 {"man", XC_man},
2235 {"middlebutton", XC_middlebutton},
2236 {"mouse", XC_mouse},
2237 {"pencil", XC_pencil},
2238 {"pirate", XC_pirate},
2239 {"plus", XC_plus},
2240 {"question_arrow", XC_question_arrow},
2241 {"right_ptr", XC_right_ptr},
2242 {"right_side", XC_right_side},
2243 {"right_tee", XC_right_tee},
2244 {"rightbutton", XC_rightbutton},
2245 {"rtl_logo", XC_rtl_logo},
2246 {"sailboat", XC_sailboat},
2247 {"sb_down_arrow", XC_sb_down_arrow},
2248 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2249 {"sb_left_arrow", XC_sb_left_arrow},
2250 {"sb_right_arrow", XC_sb_right_arrow},
2251 {"sb_up_arrow", XC_sb_up_arrow},
2252 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2253 {"shuttle", XC_shuttle},
2254 {"sizing", XC_sizing},
2255 {"spider", XC_spider},
2256 {"spraycan", XC_spraycan},
2257 {"star", XC_star},
2258 {"target", XC_target},
2259 {"tcross", XC_tcross},
2260 {"top_left_arrow", XC_top_left_arrow},
2261 {"top_left_corner", XC_top_left_corner},
2262 {"top_right_corner", XC_top_right_corner},
2263 {"top_side", XC_top_side},
2264 {"top_tee", XC_top_tee},
2265 {"trek", XC_trek},
2266 {"ul_angle", XC_ul_angle},
2267 {"umbrella", XC_umbrella},
2268 {"ur_angle", XC_ur_angle},
2269 {"watch", XC_watch},
2270 {"xterm", XC_xterm},
2271 {NULL, CURSOR_ID_NONE}
2274 static void check_bitmap_status(int status, const char *filename, Pixmap bitmap)
2276 switch (status) {
2277 case BitmapOpenFailed:
2278 wwarning(_("failed to open bitmap file \"%s\""), filename);
2279 break;
2280 case BitmapFileInvalid:
2281 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2282 break;
2283 case BitmapNoMemory:
2284 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2285 break;
2286 case BitmapSuccess:
2287 XFreePixmap(dpy, bitmap);
2288 break;
2293 * (none)
2294 * (builtin, <cursor_name>)
2295 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2297 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2299 WMPropList *elem;
2300 char *val;
2301 int nelem;
2302 int status = 0;
2304 nelem = WMGetPropListItemCount(pl);
2305 if (nelem < 1) {
2306 return (status);
2308 elem = WMGetFromPLArray(pl, 0);
2309 if (!elem || !WMIsPLString(elem)) {
2310 return (status);
2312 val = WMGetFromPLString(elem);
2314 if (strcasecmp(val, "none") == 0) {
2315 status = 1;
2316 *cursor = None;
2317 } else if (strcasecmp(val, "builtin") == 0) {
2318 int i;
2319 int cursor_id = CURSOR_ID_NONE;
2321 if (nelem != 2) {
2322 wwarning(_("bad number of arguments in cursor specification"));
2323 return (status);
2325 elem = WMGetFromPLArray(pl, 1);
2326 if (!elem || !WMIsPLString(elem)) {
2327 return (status);
2329 val = WMGetFromPLString(elem);
2331 for (i = 0; cursor_table[i].name != NULL; i++) {
2332 if (strcasecmp(val, cursor_table[i].name) == 0) {
2333 cursor_id = cursor_table[i].id;
2334 break;
2337 if (CURSOR_ID_NONE == cursor_id) {
2338 wwarning(_("unknown builtin cursor name \"%s\""), val);
2339 } else {
2340 *cursor = XCreateFontCursor(dpy, cursor_id);
2341 status = 1;
2343 } else if (strcasecmp(val, "bitmap") == 0) {
2344 char *bitmap_name;
2345 char *mask_name;
2346 int bitmap_status;
2347 int mask_status;
2348 Pixmap bitmap;
2349 Pixmap mask;
2350 unsigned int w, h;
2351 int x, y;
2352 XColor fg, bg;
2354 if (nelem != 3) {
2355 wwarning(_("bad number of arguments in cursor specification"));
2356 return (status);
2358 elem = WMGetFromPLArray(pl, 1);
2359 if (!elem || !WMIsPLString(elem)) {
2360 return (status);
2362 val = WMGetFromPLString(elem);
2363 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2364 if (!bitmap_name) {
2365 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2366 return (status);
2368 elem = WMGetFromPLArray(pl, 2);
2369 if (!elem || !WMIsPLString(elem)) {
2370 wfree(bitmap_name);
2371 return (status);
2373 val = WMGetFromPLString(elem);
2374 mask_name = FindImage(wPreferences.pixmap_path, val);
2375 if (!mask_name) {
2376 wfree(bitmap_name);
2377 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2378 return (status);
2380 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2381 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2382 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2383 fg.pixel = scr->black_pixel;
2384 bg.pixel = scr->white_pixel;
2385 XQueryColor(dpy, scr->w_colormap, &fg);
2386 XQueryColor(dpy, scr->w_colormap, &bg);
2387 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2388 status = 1;
2390 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2391 check_bitmap_status(mask_status, mask_name, mask);
2392 wfree(bitmap_name);
2393 wfree(mask_name);
2395 return (status);
2398 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2400 static Cursor cursor;
2401 int status;
2402 int changed = 0;
2404 again:
2405 if (!WMIsPLArray(value)) {
2406 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2407 entry->key, "cursor specification");
2408 if (!changed) {
2409 value = entry->plvalue;
2410 changed = 1;
2411 wwarning(_("using default \"%s\" instead"), entry->default_value);
2412 goto again;
2414 return (False);
2416 status = parse_cursor(scr, value, &cursor);
2417 if (!status) {
2418 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2419 if (!changed) {
2420 value = entry->plvalue;
2421 changed = 1;
2422 wwarning(_("using default \"%s\" instead"), entry->default_value);
2423 goto again;
2425 return (False);
2427 if (ret) {
2428 *ret = &cursor;
2430 if (addr) {
2431 *(Cursor *) addr = cursor;
2433 return (True);
2436 #undef CURSOR_ID_NONE
2438 /* ---------------- value setting functions --------------- */
2439 static int setJustify(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2441 /* Parameter not used, but tell the compiler that it is ok */
2442 (void) scr;
2443 (void) entry;
2444 (void) tdata;
2445 (void) extra_data;
2447 return REFRESH_WINDOW_TITLE_COLOR;
2450 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2452 /* Parameter not used, but tell the compiler that it is ok */
2453 (void) scr;
2454 (void) entry;
2455 (void) bar;
2456 (void) foo;
2458 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2461 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2463 char *flag = tdata;
2464 long which = (long) extra_data;
2466 /* Parameter not used, but tell the compiler that it is ok */
2467 (void) scr;
2468 (void) entry;
2470 switch (which) {
2471 case WM_DOCK:
2472 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2473 // Drawers require the dock
2474 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || wPreferences.flags.nodock;
2475 break;
2476 case WM_CLIP:
2477 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2478 break;
2479 case WM_DRAWER:
2480 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || *flag;
2481 break;
2482 default:
2483 break;
2485 return 0;
2488 static int setClipMergedInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2490 char *flag = tdata;
2492 /* Parameter not used, but tell the compiler that it is ok */
2493 (void) scr;
2494 (void) entry;
2495 (void) foo;
2497 wPreferences.flags.clip_merged_in_dock = *flag;
2498 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2499 return 0;
2502 static int setWrapAppiconsInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2504 char *flag = tdata;
2506 /* Parameter not used, but tell the compiler that it is ok */
2507 (void) scr;
2508 (void) entry;
2509 (void) foo;
2511 wPreferences.flags.wrap_appicons_in_dock = *flag;
2512 return 0;
2515 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2517 /* Parameter not used, but tell the compiler that it is ok */
2518 (void) entry;
2519 (void) bar;
2520 (void) foo;
2522 if (w_global.workspace.array) {
2523 wWorkspaceForceChange(scr, w_global.workspace.current);
2524 wArrangeIcons(scr, False);
2526 return 0;
2529 static int setIconTile(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2531 Pixmap pixmap;
2532 RImage *img;
2533 WTexture ** texture = tdata;
2534 int reset = 0;
2536 /* Parameter not used, but tell the compiler that it is ok */
2537 (void) foo;
2539 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2540 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2541 ? WREL_ICON : WREL_FLAT);
2542 if (!img) {
2543 wwarning(_("could not render texture for icon background"));
2544 if (!entry->addr)
2545 wTextureDestroy(scr, *texture);
2546 return 0;
2548 RConvertImage(scr->rcontext, img, &pixmap);
2550 if (scr->icon_tile) {
2551 reset = 1;
2552 RReleaseImage(scr->icon_tile);
2553 XFreePixmap(dpy, scr->icon_tile_pixmap);
2556 scr->icon_tile = img;
2558 /* put the icon in the noticeboard hint */
2559 PropSetIconTileHint(scr, img);
2561 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock) {
2562 if (scr->clip_tile) {
2563 RReleaseImage(scr->clip_tile);
2565 scr->clip_tile = wClipMakeTile(img);
2568 if (!wPreferences.flags.nodrawer) {
2569 if (scr->drawer_tile) {
2570 RReleaseImage(scr->drawer_tile);
2572 scr->drawer_tile = wDrawerMakeTile(scr, img);
2575 scr->icon_tile_pixmap = pixmap;
2577 if (scr->def_icon_rimage) {
2578 RReleaseImage(scr->def_icon_rimage);
2579 scr->def_icon_rimage = NULL;
2582 if (scr->icon_back_texture)
2583 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2585 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2587 /* Free the texture as nobody else will use it, nor refer to it. */
2588 if (!entry->addr)
2589 wTextureDestroy(scr, *texture);
2591 return (reset ? REFRESH_ICON_TILE : 0);
2594 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2596 WMFont *font = tdata;
2598 /* Parameter not used, but tell the compiler that it is ok */
2599 (void) entry;
2600 (void) foo;
2602 if (scr->title_font) {
2603 WMReleaseFont(scr->title_font);
2605 scr->title_font = font;
2607 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2610 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2612 WMFont *font = tdata;
2614 /* Parameter not used, but tell the compiler that it is ok */
2615 (void) entry;
2616 (void) foo;
2618 if (scr->menu_title_font) {
2619 WMReleaseFont(scr->menu_title_font);
2622 scr->menu_title_font = font;
2624 return REFRESH_MENU_TITLE_FONT;
2627 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2629 WMFont *font = tdata;
2631 /* Parameter not used, but tell the compiler that it is ok */
2632 (void) entry;
2633 (void) foo;
2635 if (scr->menu_entry_font) {
2636 WMReleaseFont(scr->menu_entry_font);
2638 scr->menu_entry_font = font;
2640 return REFRESH_MENU_FONT;
2643 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2645 WMFont *font = tdata;
2647 /* Parameter not used, but tell the compiler that it is ok */
2648 (void) entry;
2649 (void) foo;
2651 if (scr->icon_title_font) {
2652 WMReleaseFont(scr->icon_title_font);
2655 scr->icon_title_font = font;
2657 return REFRESH_ICON_FONT;
2660 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2662 WMFont *font = tdata;
2664 /* Parameter not used, but tell the compiler that it is ok */
2665 (void) entry;
2666 (void) foo;
2668 if (scr->clip_title_font) {
2669 WMReleaseFont(scr->clip_title_font);
2672 scr->clip_title_font = font;
2674 return REFRESH_ICON_FONT;
2677 static int setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2679 WMFont *font = tdata;
2681 /* Parameter not used, but tell the compiler that it is ok */
2682 (void) scr;
2683 (void) entry;
2684 (void) foo;
2686 if (w_global.workspace.font_for_name)
2687 WMReleaseFont(w_global.workspace.font_for_name);
2689 w_global.workspace.font_for_name = font;
2691 return 0;
2694 static int setHightlight(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2696 XColor *color = tdata;
2698 /* Parameter not used, but tell the compiler that it is ok */
2699 (void) entry;
2700 (void) foo;
2702 if (scr->select_color)
2703 WMReleaseColor(scr->select_color);
2705 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2707 wFreeColor(scr, color->pixel);
2709 return REFRESH_MENU_COLOR;
2712 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2714 XColor *color = tdata;
2716 /* Parameter not used, but tell the compiler that it is ok */
2717 (void) entry;
2718 (void) foo;
2720 if (scr->select_text_color)
2721 WMReleaseColor(scr->select_text_color);
2723 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2725 wFreeColor(scr, color->pixel);
2727 return REFRESH_MENU_COLOR;
2730 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2732 XColor *color = tdata;
2733 long widx = (long) extra_data;
2735 /* Parameter not used, but tell the compiler that it is ok */
2736 (void) entry;
2738 if (scr->clip_title_color[widx])
2739 WMReleaseColor(scr->clip_title_color[widx]);
2741 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2742 wFreeColor(scr, color->pixel);
2744 return REFRESH_ICON_TITLE_COLOR;
2747 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2749 XColor *color = tdata;
2750 long widx = (long) extra_data;
2752 /* Parameter not used, but tell the compiler that it is ok */
2753 (void) entry;
2755 if (scr->window_title_color[widx])
2756 WMReleaseColor(scr->window_title_color[widx]);
2758 scr->window_title_color[widx] =
2759 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2761 wFreeColor(scr, color->pixel);
2763 return REFRESH_WINDOW_TITLE_COLOR;
2766 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2768 XColor *color = tdata;
2770 /* Parameter not used, but tell the compiler that it is ok */
2771 (void) entry;
2772 (void) extra_data;
2774 if (scr->menu_title_color[0])
2775 WMReleaseColor(scr->menu_title_color[0]);
2777 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2779 wFreeColor(scr, color->pixel);
2781 return REFRESH_MENU_TITLE_COLOR;
2784 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2786 XColor *color = tdata;
2788 /* Parameter not used, but tell the compiler that it is ok */
2789 (void) entry;
2790 (void) foo;
2792 if (scr->mtext_color)
2793 WMReleaseColor(scr->mtext_color);
2795 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2797 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2798 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2799 } else {
2800 WMSetColorAlpha(scr->dtext_color, 0xffff);
2803 wFreeColor(scr, color->pixel);
2805 return REFRESH_MENU_COLOR;
2808 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2810 XColor *color = tdata;
2812 /* Parameter not used, but tell the compiler that it is ok */
2813 (void) entry;
2814 (void) foo;
2816 if (scr->dtext_color)
2817 WMReleaseColor(scr->dtext_color);
2819 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2821 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2822 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2823 } else {
2824 WMSetColorAlpha(scr->dtext_color, 0xffff);
2827 wFreeColor(scr, color->pixel);
2829 return REFRESH_MENU_COLOR;
2832 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2834 XColor *color = tdata;
2836 /* Parameter not used, but tell the compiler that it is ok */
2837 (void) entry;
2838 (void) foo;
2840 if (scr->icon_title_color)
2841 WMReleaseColor(scr->icon_title_color);
2842 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2844 wFreeColor(scr, color->pixel);
2846 return REFRESH_ICON_TITLE_COLOR;
2849 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2851 XColor *color = tdata;
2853 /* Parameter not used, but tell the compiler that it is ok */
2854 (void) entry;
2855 (void) foo;
2857 if (scr->icon_title_texture) {
2858 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2860 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2862 return REFRESH_ICON_TITLE_BACK;
2865 static int setFrameBorderWidth(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2867 int *value = tdata;
2869 /* Parameter not used, but tell the compiler that it is ok */
2870 (void) entry;
2871 (void) foo;
2873 scr->frame_border_width = *value;
2875 return REFRESH_FRAME_BORDER;
2878 static int setFrameBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2880 XColor *color = tdata;
2882 /* Parameter not used, but tell the compiler that it is ok */
2883 (void) entry;
2884 (void) foo;
2886 if (scr->frame_border_color)
2887 WMReleaseColor(scr->frame_border_color);
2888 scr->frame_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2890 wFreeColor(scr, color->pixel);
2892 return REFRESH_FRAME_BORDER;
2895 static int setFrameFocusedBorderColor(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2897 XColor *color = tdata;
2899 /* Parameter not used, but tell the compiler that it is ok */
2900 (void) entry;
2901 (void) foo;
2903 if (scr->frame_focused_border_color)
2904 WMReleaseColor(scr->frame_focused_border_color);
2905 scr->frame_focused_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2907 wFreeColor(scr, color->pixel);
2909 return REFRESH_FRAME_BORDER;
2912 static int setFrameSelectedBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2914 XColor *color = tdata;
2916 /* Parameter not used, but tell the compiler that it is ok */
2917 (void) entry;
2918 (void) foo;
2920 if (scr->frame_selected_border_color)
2921 WMReleaseColor(scr->frame_selected_border_color);
2922 scr->frame_selected_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2924 wFreeColor(scr, color->pixel);
2926 return REFRESH_FRAME_BORDER;
2929 static void trackDeadProcess(pid_t pid, unsigned int status, void *client_data)
2931 WScreen *scr = (WScreen *) client_data;
2933 /* Parameter not used, but tell the compiler that it is ok */
2934 (void) pid;
2935 (void) status;
2937 close(scr->helper_fd);
2938 scr->helper_fd = 0;
2939 scr->helper_pid = 0;
2940 scr->flags.backimage_helper_launched = 0;
2943 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
2945 WMPropList *value = tdata;
2946 WMPropList *val;
2947 char *str;
2948 int i;
2950 /* Parameter not used, but tell the compiler that it is ok */
2951 (void) entry;
2952 (void) bar;
2954 if (scr->flags.backimage_helper_launched) {
2955 if (WMGetPropListItemCount(value) == 0) {
2956 SendHelperMessage(scr, 'C', 0, NULL);
2957 SendHelperMessage(scr, 'K', 0, NULL);
2959 WMReleasePropList(value);
2960 return 0;
2962 } else {
2963 pid_t pid;
2964 int filedes[2];
2966 if (WMGetPropListItemCount(value) == 0)
2967 return 0;
2969 if (pipe(filedes) < 0) {
2970 werror("pipe() failed:can't set workspace specific background image");
2972 WMReleasePropList(value);
2973 return 0;
2976 pid = fork();
2977 if (pid < 0) {
2978 werror("fork() failed:can't set workspace specific background image");
2979 if (close(filedes[0]) < 0)
2980 werror("could not close pipe");
2981 if (close(filedes[1]) < 0)
2982 werror("could not close pipe");
2984 } else if (pid == 0) {
2985 char *dither;
2987 SetupEnvironment(scr);
2989 if (close(0) < 0)
2990 werror("could not close pipe");
2991 if (dup(filedes[0]) < 0) {
2992 werror("dup() failed:can't set workspace specific background image");
2994 dither = wPreferences.no_dithering ? "-m" : "-d";
2995 if (wPreferences.smooth_workspace_back)
2996 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2997 else
2998 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2999 werror("could not execute wmsetbg");
3000 exit(1);
3001 } else {
3003 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3004 werror("error setting close-on-exec flag");
3006 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3007 werror("error setting close-on-exec flag");
3010 scr->helper_fd = filedes[1];
3011 scr->helper_pid = pid;
3012 scr->flags.backimage_helper_launched = 1;
3014 wAddDeathHandler(pid, trackDeadProcess, scr);
3016 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3021 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3022 val = WMGetFromPLArray(value, i);
3023 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
3024 str = WMGetPropListDescription(val, False);
3026 SendHelperMessage(scr, 'S', i + 1, str);
3028 wfree(str);
3029 } else {
3030 SendHelperMessage(scr, 'U', i + 1, NULL);
3033 sleep(1);
3035 WMReleasePropList(value);
3036 return 0;
3039 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
3041 WMPropList *value = tdata;
3043 /* Parameter not used, but tell the compiler that it is ok */
3044 (void) entry;
3045 (void) bar;
3047 if (scr->flags.backimage_helper_launched) {
3048 char *str;
3050 if (WMGetPropListItemCount(value) == 0) {
3051 SendHelperMessage(scr, 'U', 0, NULL);
3052 } else {
3053 /* set the default workspace background to this one */
3054 str = WMGetPropListDescription(value, False);
3055 if (str) {
3056 SendHelperMessage(scr, 'S', 0, str);
3057 wfree(str);
3058 SendHelperMessage(scr, 'C', w_global.workspace.current + 1, NULL);
3059 } else {
3060 SendHelperMessage(scr, 'U', 0, NULL);
3063 } else if (WMGetPropListItemCount(value) > 0) {
3064 char *command;
3065 char *text;
3066 char *dither;
3067 int len;
3069 text = WMGetPropListDescription(value, False);
3070 len = strlen(text) + 40;
3071 command = wmalloc(len);
3072 dither = wPreferences.no_dithering ? "-m" : "-d";
3073 if (wPreferences.smooth_workspace_back)
3074 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3075 else
3076 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3077 wfree(text);
3078 ExecuteShellCommand(scr, command);
3079 wfree(command);
3081 WMReleasePropList(value);
3083 return 0;
3086 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3088 WTexture **texture = tdata;
3090 /* Parameter not used, but tell the compiler that it is ok */
3091 (void) entry;
3092 (void) foo;
3094 if (scr->widget_texture) {
3095 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3097 scr->widget_texture = *(WTexSolid **) texture;
3099 return 0;
3102 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3104 WTexture **texture = tdata;
3106 /* Parameter not used, but tell the compiler that it is ok */
3107 (void) entry;
3108 (void) foo;
3110 if (scr->window_title_texture[WS_FOCUSED]) {
3111 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3113 scr->window_title_texture[WS_FOCUSED] = *texture;
3115 return REFRESH_WINDOW_TEXTURES;
3118 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3120 WTexture **texture = tdata;
3122 /* Parameter not used, but tell the compiler that it is ok */
3123 (void) entry;
3124 (void) foo;
3126 if (scr->window_title_texture[WS_PFOCUSED]) {
3127 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3129 scr->window_title_texture[WS_PFOCUSED] = *texture;
3131 return REFRESH_WINDOW_TEXTURES;
3134 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3136 WTexture **texture = tdata;
3138 /* Parameter not used, but tell the compiler that it is ok */
3139 (void) entry;
3140 (void) foo;
3142 if (scr->window_title_texture[WS_UNFOCUSED]) {
3143 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3145 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3147 return REFRESH_WINDOW_TEXTURES;
3150 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3152 WTexture **texture = tdata;
3154 /* Parameter not used, but tell the compiler that it is ok */
3155 (void) entry;
3156 (void) foo;
3158 if (scr->resizebar_texture[0]) {
3159 wTextureDestroy(scr, scr->resizebar_texture[0]);
3161 scr->resizebar_texture[0] = *texture;
3163 return REFRESH_WINDOW_TEXTURES;
3166 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3168 WTexture **texture = tdata;
3170 /* Parameter not used, but tell the compiler that it is ok */
3171 (void) entry;
3172 (void) foo;
3174 if (scr->menu_title_texture[0]) {
3175 wTextureDestroy(scr, scr->menu_title_texture[0]);
3177 scr->menu_title_texture[0] = *texture;
3179 return REFRESH_MENU_TITLE_TEXTURE;
3182 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3184 WTexture **texture = tdata;
3186 /* Parameter not used, but tell the compiler that it is ok */
3187 (void) entry;
3188 (void) foo;
3190 if (scr->menu_item_texture) {
3191 wTextureDestroy(scr, scr->menu_item_texture);
3192 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3194 scr->menu_item_texture = *texture;
3196 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3198 return REFRESH_MENU_TEXTURE;
3201 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3203 WShortKey *shortcut = tdata;
3204 WWindow *wwin;
3205 long widx = (long) extra_data;
3207 /* Parameter not used, but tell the compiler that it is ok */
3208 (void) entry;
3210 wKeyBindings[widx] = *shortcut;
3212 wwin = scr->focused_window;
3214 while (wwin != NULL) {
3215 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3217 if (!WFLAGP(wwin, no_bind_keys)) {
3218 wWindowSetKeyGrabs(wwin);
3220 wwin = wwin->prev;
3223 /* do we need to update window menus? */
3224 if (widx >= WKBD_WORKSPACE1 && widx <= WKBD_WORKSPACE10)
3225 return REFRESH_WORKSPACE_MENU;
3226 if (widx == WKBD_LASTWORKSPACE)
3227 return REFRESH_WORKSPACE_MENU;
3228 if (widx >= WKBD_MOVE_WORKSPACE1 && widx <= WKBD_MOVE_WORKSPACE10)
3229 return REFRESH_WORKSPACE_MENU;
3231 return 0;
3234 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3236 /* Parameter not used, but tell the compiler that it is ok */
3237 (void) entry;
3238 (void) bar;
3239 (void) foo;
3241 wScreenUpdateUsableArea(scr);
3242 wArrangeIcons(scr, True);
3244 return 0;
3247 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3249 /* Parameter not used, but tell the compiler that it is ok */
3250 (void) entry;
3251 (void) bar;
3252 (void) foo;
3254 wScreenUpdateUsableArea(scr);
3256 return 0;
3259 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3261 /* Parameter not used, but tell the compiler that it is ok */
3262 (void) scr;
3263 (void) entry;
3264 (void) tdata;
3265 (void) foo;
3267 return REFRESH_MENU_TEXTURE;
3270 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3272 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3274 RCopyArea(img, image, x, y, w, h, 0, 0);
3276 return img;
3279 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3281 WMPropList *array = tdata;
3282 char *path;
3283 RImage *bgimage;
3284 int cwidth, cheight;
3285 struct WPreferences *prefs = foo;
3287 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3288 if (prefs->swtileImage)
3289 RReleaseImage(prefs->swtileImage);
3290 prefs->swtileImage = NULL;
3292 WMReleasePropList(array);
3293 return 0;
3296 switch (WMGetPropListItemCount(array)) {
3297 case 4:
3298 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3299 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3300 break;
3301 } else
3302 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3304 if (!path) {
3305 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3306 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3307 } else {
3308 bgimage = RLoadImage(scr->rcontext, path, 0);
3309 if (!bgimage) {
3310 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3311 wfree(path);
3312 } else {
3313 wfree(path);
3315 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3316 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3318 if (cwidth <= 0 || cheight <= 0 ||
3319 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3320 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3321 else {
3322 int i;
3323 int swidth, theight;
3324 for (i = 0; i < 9; i++) {
3325 if (prefs->swbackImage[i])
3326 RReleaseImage(prefs->swbackImage[i]);
3327 prefs->swbackImage[i] = NULL;
3329 swidth = (bgimage->width - cwidth) / 2;
3330 theight = (bgimage->height - cheight) / 2;
3332 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3333 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3334 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3335 swidth, theight);
3337 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3338 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3339 cwidth, cheight);
3340 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3341 swidth, cheight);
3343 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3344 swidth, theight);
3345 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3346 cwidth, theight);
3347 prefs->swbackImage[8] =
3348 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3349 theight);
3351 // check if anything failed
3352 for (i = 0; i < 9; i++) {
3353 if (!prefs->swbackImage[i]) {
3354 for (; i >= 0; --i) {
3355 RReleaseImage(prefs->swbackImage[i]);
3356 prefs->swbackImage[i] = NULL;
3358 break;
3362 RReleaseImage(bgimage);
3366 case 1:
3367 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3368 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3369 break;
3370 } else
3371 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3373 if (!path) {
3374 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3375 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3376 } else {
3377 if (prefs->swtileImage)
3378 RReleaseImage(prefs->swtileImage);
3380 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3381 if (!prefs->swtileImage) {
3382 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3384 wfree(path);
3386 break;
3388 default:
3389 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3390 break;
3393 WMReleasePropList(array);
3395 return 0;
3398 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3400 WMPropList *array = tdata;
3401 int i;
3402 struct WPreferences *prefs = foo;
3404 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3405 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3406 WMReleasePropList(array);
3407 return 0;
3410 DestroyWindowMenu(scr);
3412 for (i = 0; i < 7; i++) {
3413 if (prefs->modifier_labels[i])
3414 wfree(prefs->modifier_labels[i]);
3416 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3417 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3418 } else {
3419 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3420 prefs->modifier_labels[i] = NULL;
3424 WMReleasePropList(array);
3426 return 0;
3429 static int setDoubleClick(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
3431 int *value = tdata;
3433 /* Parameter not used, but tell the compiler that it is ok */
3434 (void) entry;
3435 (void) scr;
3437 if (*value <= 0)
3438 *(int *)foo = 1;
3440 W_setconf_doubleClickDelay(*value);
3442 return 0;
3445 static int setCursor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3447 Cursor *cursor = tdata;
3448 long widx = (long) extra_data;
3450 /* Parameter not used, but tell the compiler that it is ok */
3451 (void) entry;
3453 if (wPreferences.cursor[widx] != None) {
3454 XFreeCursor(dpy, wPreferences.cursor[widx]);
3457 wPreferences.cursor[widx] = *cursor;
3459 if (widx == WCUR_ROOT && *cursor != None) {
3460 XDefineCursor(dpy, scr->root_win, *cursor);
3463 return 0;