wmaker: Add window snapping feature.
[wmaker-crm.git] / src / defaults.c
blob7349443ed21b23426dd79983ebd8e18992c195c4
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <strings.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifndef PATH_MAX
40 #define PATH_MAX DEFAULT_PATH_MAX
41 #endif
43 #include <X11/Xlib.h>
44 #include <X11/Xutil.h>
45 #include <X11/keysym.h>
47 #include <wraster.h>
49 #include "WindowMaker.h"
50 #include "framewin.h"
51 #include "window.h"
52 #include "texture.h"
53 #include "screen.h"
54 #include "resources.h"
55 #include "defaults.h"
56 #include "keybind.h"
57 #include "xmodifier.h"
58 #include "icon.h"
59 #include "main.h"
60 #include "actions.h"
61 #include "dock.h"
62 #include "workspace.h"
63 #include "properties.h"
64 #include "misc.h"
65 #include "event.h"
66 #include "winmenu.h"
68 #define MAX_SHORTCUT_LENGTH 32
70 #ifndef GLOBAL_DEFAULTS_SUBDIR
71 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
72 #endif
75 typedef struct _WDefaultEntry WDefaultEntry;
76 typedef int (WDECallbackConvert) (WScreen *scr, WDefaultEntry *entry, WMPropList *plvalue, void *addr, void **tdata);
77 typedef int (WDECallbackUpdate) (WScreen *scr, WDefaultEntry *entry, void *tdata, void *extra_data);
79 struct _WDefaultEntry {
80 const char *key;
81 const char *default_value;
82 void *extra_data;
83 void *addr;
84 WDECallbackConvert *convert;
85 WDECallbackUpdate *update;
86 WMPropList *plkey;
87 WMPropList *plvalue; /* default value */
90 /* used to map strings to integers */
91 typedef struct {
92 const char *string;
93 short value;
94 char is_alias;
95 } WOptionEnumeration;
97 /* type converters */
98 static WDECallbackConvert getBool;
99 static WDECallbackConvert getInt;
100 static WDECallbackConvert getCoord;
101 static WDECallbackConvert getPathList;
102 static WDECallbackConvert getEnum;
103 static WDECallbackConvert getTexture;
104 static WDECallbackConvert getWSBackground;
105 static WDECallbackConvert getWSSpecificBackground;
106 static WDECallbackConvert getFont;
107 static WDECallbackConvert getColor;
108 static WDECallbackConvert getKeybind;
109 static WDECallbackConvert getModMask;
110 static WDECallbackConvert getPropList;
112 /* value setting functions */
113 static WDECallbackUpdate setJustify;
114 static WDECallbackUpdate setClearance;
115 static WDECallbackUpdate setIfDockPresent;
116 static WDECallbackUpdate setClipMergedInDock;
117 static WDECallbackUpdate setWrapAppiconsInDock;
118 static WDECallbackUpdate setStickyIcons;
119 static WDECallbackUpdate setWidgetColor;
120 static WDECallbackUpdate setIconTile;
121 static WDECallbackUpdate setWinTitleFont;
122 static WDECallbackUpdate setMenuTitleFont;
123 static WDECallbackUpdate setMenuTextFont;
124 static WDECallbackUpdate setIconTitleFont;
125 static WDECallbackUpdate setIconTitleColor;
126 static WDECallbackUpdate setIconTitleBack;
127 static WDECallbackUpdate setFrameBorderWidth;
128 static WDECallbackUpdate setFrameBorderColor;
129 static WDECallbackUpdate setFrameFocusedBorderColor;
130 static WDECallbackUpdate setFrameSelectedBorderColor;
131 static WDECallbackUpdate setLargeDisplayFont;
132 static WDECallbackUpdate setWTitleColor;
133 static WDECallbackUpdate setFTitleBack;
134 static WDECallbackUpdate setPTitleBack;
135 static WDECallbackUpdate setUTitleBack;
136 static WDECallbackUpdate setResizebarBack;
137 static WDECallbackUpdate setWorkspaceBack;
138 static WDECallbackUpdate setWorkspaceSpecificBack;
139 static WDECallbackUpdate setMenuTitleColor;
140 static WDECallbackUpdate setMenuTextColor;
141 static WDECallbackUpdate setMenuDisabledColor;
142 static WDECallbackUpdate setMenuTitleBack;
143 static WDECallbackUpdate setMenuTextBack;
144 static WDECallbackUpdate setHightlight;
145 static WDECallbackUpdate setHightlightText;
146 static WDECallbackUpdate setKeyGrab;
147 static WDECallbackUpdate setDoubleClick;
148 static WDECallbackUpdate setIconPosition;
150 static WDECallbackUpdate setClipTitleFont;
151 static WDECallbackUpdate setClipTitleColor;
153 static WDECallbackUpdate setMenuStyle;
154 static WDECallbackUpdate setSwPOptions;
155 static WDECallbackUpdate updateUsableArea;
157 static WDECallbackUpdate setModifierKeyLabels;
159 static WDECallbackConvert getCursor;
160 static WDECallbackUpdate setCursor;
163 * Tables to convert strings to enumeration values.
164 * Values stored are char
167 /* WARNING: sum of length of all value strings must not exceed
168 * this value */
169 #define TOTAL_VALUES_LENGTH 80
171 #define REFRESH_WINDOW_TEXTURES (1<<0)
172 #define REFRESH_MENU_TEXTURE (1<<1)
173 #define REFRESH_MENU_FONT (1<<2)
174 #define REFRESH_MENU_COLOR (1<<3)
175 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
176 #define REFRESH_MENU_TITLE_FONT (1<<5)
177 #define REFRESH_MENU_TITLE_COLOR (1<<6)
178 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
179 #define REFRESH_WINDOW_FONT (1<<8)
180 #define REFRESH_ICON_TILE (1<<9)
181 #define REFRESH_ICON_FONT (1<<10)
182 #define REFRESH_WORKSPACE_BACK (1<<11)
184 #define REFRESH_BUTTON_IMAGES (1<<12)
186 #define REFRESH_ICON_TITLE_COLOR (1<<13)
187 #define REFRESH_ICON_TITLE_BACK (1<<14)
189 #define REFRESH_WORKSPACE_MENU (1<<15)
191 #define REFRESH_FRAME_BORDER REFRESH_MENU_FONT|REFRESH_WINDOW_FONT
193 static WOptionEnumeration seFocusModes[] = {
194 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
195 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
196 {NULL, 0, 0}
199 static WOptionEnumeration seTitlebarModes[] = {
200 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
201 {"next", TS_NEXT, 0}, {NULL, 0, 0}
204 static WOptionEnumeration seColormapModes[] = {
205 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
206 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
207 {NULL, 0, 0}
210 static WOptionEnumeration sePlacements[] = {
211 {"Auto", WPM_AUTO, 0},
212 {"Smart", WPM_SMART, 0},
213 {"Cascade", WPM_CASCADE, 0},
214 {"Random", WPM_RANDOM, 0},
215 {"Manual", WPM_MANUAL, 0},
216 {"Center", WPM_CENTER, 0},
217 {NULL, 0, 0}
220 static WOptionEnumeration seGeomDisplays[] = {
221 {"None", WDIS_NONE, 0},
222 {"Center", WDIS_CENTER, 0},
223 {"Corner", WDIS_TOPLEFT, 0},
224 {"Floating", WDIS_FRAME_CENTER, 0},
225 {"Line", WDIS_NEW, 0},
226 {NULL, 0, 0}
229 static WOptionEnumeration seSpeeds[] = {
230 {"UltraFast", SPEED_ULTRAFAST, 0},
231 {"Fast", SPEED_FAST, 0},
232 {"Medium", SPEED_MEDIUM, 0},
233 {"Slow", SPEED_SLOW, 0},
234 {"UltraSlow", SPEED_ULTRASLOW, 0},
235 {NULL, 0, 0}
238 static WOptionEnumeration seMouseButtonActions[] = {
239 {"None", WA_NONE, 0},
240 {"SelectWindows", WA_SELECT_WINDOWS, 0},
241 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
242 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
243 {"MoveToPrevWorkspace", WA_MOVE_PREVWORKSPACE, 0},
244 {"MoveToNextWorkspace", WA_MOVE_NEXTWORKSPACE, 0},
245 {"MoveToPrevWindow", WA_MOVE_PREVWINDOW, 0},
246 {"MoveToNextWindow", WA_MOVE_NEXTWINDOW, 0},
247 {NULL, 0, 0}
250 static WOptionEnumeration seMouseWheelActions[] = {
251 {"None", WA_NONE, 0},
252 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
253 {"SwitchWindows", WA_SWITCH_WINDOWS, 0},
254 {NULL, 0, 0}
257 static WOptionEnumeration seIconificationStyles[] = {
258 {"Zoom", WIS_ZOOM, 0},
259 {"Twist", WIS_TWIST, 0},
260 {"Flip", WIS_FLIP, 0},
261 {"None", WIS_NONE, 0},
262 {"random", WIS_RANDOM, 0},
263 {NULL, 0, 0}
266 static WOptionEnumeration seJustifications[] = {
267 {"Left", WTJ_LEFT, 0},
268 {"Center", WTJ_CENTER, 0},
269 {"Right", WTJ_RIGHT, 0},
270 {NULL, 0, 0}
273 static WOptionEnumeration seIconPositions[] = {
274 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
275 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
276 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
277 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
278 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
279 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
280 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
281 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
282 {NULL, 0, 0}
285 static WOptionEnumeration seMenuStyles[] = {
286 {"normal", MS_NORMAL, 0},
287 {"singletexture", MS_SINGLE_TEXTURE, 0},
288 {"flat", MS_FLAT, 0},
289 {NULL, 0, 0}
292 static WOptionEnumeration seDisplayPositions[] = {
293 {"none", WD_NONE, 0},
294 {"center", WD_CENTER, 0},
295 {"top", WD_TOP, 0},
296 {"bottom", WD_BOTTOM, 0},
297 {"topleft", WD_TOPLEFT, 0},
298 {"topright", WD_TOPRIGHT, 0},
299 {"bottomleft", WD_BOTTOMLEFT, 0},
300 {"bottomright", WD_BOTTOMRIGHT, 0},
301 {NULL, 0, 0}
304 static WOptionEnumeration seWorkspaceBorder[] = {
305 {"None", WB_NONE, 0},
306 {"LeftRight", WB_LEFTRIGHT, 0},
307 {"TopBottom", WB_TOPBOTTOM, 0},
308 {"AllDirections", WB_ALLDIRS, 0},
309 {NULL, 0, 0}
313 * ALL entries in the tables bellow, NEED to have a default value
314 * defined, and this value needs to be correct.
317 /* these options will only affect the window manager on startup
319 * static defaults can't access the screen data, because it is
320 * created after these defaults are read
322 WDefaultEntry staticOptionList[] = {
324 {"ColormapSize", "4", NULL,
325 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
326 {"DisableDithering", "NO", NULL,
327 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
328 {"IconSize", "64", NULL,
329 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
330 {"ModifierKey", "Mod1", NULL,
331 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
332 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
333 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
334 {"NewStyle", "new", seTitlebarModes,
335 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
336 {"DisableDock", "NO", (void *)WM_DOCK,
337 NULL, getBool, setIfDockPresent, NULL, NULL},
338 {"DisableClip", "NO", (void *)WM_CLIP,
339 NULL, getBool, setIfDockPresent, NULL, NULL},
340 {"DisableDrawers", "NO", (void *)WM_DRAWER,
341 NULL, getBool, setIfDockPresent, NULL, NULL},
342 {"ClipMergedInDock", "NO", NULL,
343 NULL, getBool, setClipMergedInDock, NULL, NULL},
344 {"DisableMiniwindows", "NO", NULL,
345 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
348 #define NUM2STRING_(x) #x
349 #define NUM2STRING(x) NUM2STRING_(x)
351 WDefaultEntry optionList[] = {
353 /* dynamic options */
355 {"IconPosition", "blh", seIconPositions,
356 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
357 {"IconificationStyle", "Zoom", seIconificationStyles,
358 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
359 {"DisableWSMouseActions", "NO", NULL,
360 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
361 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
362 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
363 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
364 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
365 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
366 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
367 {"MouseBackwardButtonAction", "None", seMouseButtonActions,
368 &wPreferences.mouse_button8, getEnum, NULL, NULL, NULL},
369 {"MouseForwardButtonAction", "None", seMouseButtonActions,
370 &wPreferences.mouse_button9, getEnum, NULL, NULL, NULL},
371 {"MouseWheelAction", "None", seMouseWheelActions,
372 &wPreferences.mouse_wheel_scroll, getEnum, NULL, NULL, NULL},
373 {"MouseWheelTiltAction", "None", seMouseWheelActions,
374 &wPreferences.mouse_wheel_tilt, getEnum, NULL, NULL, NULL},
375 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
376 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
377 {"IconPath", DEF_ICON_PATHS, NULL,
378 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
379 {"ColormapMode", "auto", seColormapModes,
380 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
381 {"AutoFocus", "NO", NULL,
382 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
383 {"RaiseDelay", "0", NULL,
384 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
385 {"CirculateRaise", "NO", NULL,
386 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
387 {"Superfluous", "NO", NULL,
388 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
389 {"AdvanceToNewWorkspace", "NO", NULL,
390 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
391 {"CycleWorkspaces", "NO", NULL,
392 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
393 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
394 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
395 {"WorkspaceBorder", "None", seWorkspaceBorder,
396 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
397 {"WorkspaceBorderSize", "0", NULL,
398 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
399 {"StickyIcons", "NO", NULL,
400 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
401 {"SaveSessionOnExit", "NO", NULL,
402 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
403 {"WrapMenus", "NO", NULL,
404 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
405 {"ScrollableMenus", "NO", NULL,
406 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
407 {"MenuScrollSpeed", "medium", seSpeeds,
408 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
409 {"IconSlideSpeed", "medium", seSpeeds,
410 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
411 {"ShadeSpeed", "medium", seSpeeds,
412 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
413 {"BounceAppIconsWhenUrgent", "YES", NULL,
414 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
415 {"RaiseAppIconsWhenBouncing", "NO", NULL,
416 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
417 {"DoNotMakeAppIconsBounce", "NO", NULL,
418 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
419 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
420 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
421 {"ClipAutoraiseDelay", "600", NULL,
422 &wPreferences.clip_auto_raise_delay, getInt, NULL, NULL, NULL},
423 {"ClipAutolowerDelay", "1000", NULL,
424 &wPreferences.clip_auto_lower_delay, getInt, NULL, NULL, NULL},
425 {"ClipAutoexpandDelay", "600", NULL,
426 &wPreferences.clip_auto_expand_delay, getInt, NULL, NULL, NULL},
427 {"ClipAutocollapseDelay", "1000", NULL,
428 &wPreferences.clip_auto_collapse_delay, getInt, NULL, NULL, NULL},
429 {"WrapAppiconsInDock", "YES", NULL,
430 NULL, getBool, setWrapAppiconsInDock, NULL, NULL},
431 {"AlignSubmenus", "NO", NULL,
432 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
433 {"ViKeyMenus", "NO", NULL,
434 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
435 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
436 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
437 {"WindowPlacement", "auto", sePlacements,
438 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
439 {"IgnoreFocusClick", "NO", NULL,
440 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
441 {"UseSaveUnders", "NO", NULL,
442 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
443 {"OpaqueMove", "NO", NULL,
444 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
445 {"OpaqueResize", "NO", NULL,
446 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
447 {"OpaqueMoveResizeKeyboard", "NO", NULL,
448 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
449 {"DisableAnimations", "NO", NULL,
450 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
451 {"DontLinkWorkspaces", "NO", NULL,
452 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
453 {"WindowSnapping", "NO", NULL,
454 &wPreferences.window_snapping, getBool, NULL, NULL, NULL},
455 {"HighlightActiveApp", "YES", NULL,
456 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
457 {"AutoArrangeIcons", "NO", NULL,
458 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
459 {"NoWindowOverDock", "NO", NULL,
460 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
461 {"NoWindowOverIcons", "NO", NULL,
462 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
463 {"WindowPlaceOrigin", "(0, 0)", NULL,
464 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
465 {"ResizeDisplay", "corner", seGeomDisplays,
466 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
467 {"MoveDisplay", "corner", seGeomDisplays,
468 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
469 {"DontConfirmKill", "NO", NULL,
470 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
471 {"WindowTitleBalloons", "NO", NULL,
472 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
473 {"MiniwindowTitleBalloons", "NO", NULL,
474 &wPreferences.miniwin_title_balloon, getBool, NULL, NULL, NULL},
475 {"MiniwindowApercuBalloons", "NO", NULL,
476 &wPreferences.miniwin_apercu_balloon, getBool, NULL, NULL, NULL},
477 {"AppIconBalloons", "NO", NULL,
478 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
479 {"HelpBalloons", "NO", NULL,
480 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
481 {"EdgeResistance", "30", NULL,
482 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
483 {"ResizeIncrement", "0", NULL,
484 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
485 {"Attraction", "NO", NULL,
486 &wPreferences.attract, getBool, NULL, NULL, NULL},
487 {"DisableBlinking", "NO", NULL,
488 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
489 {"SingleClickLaunch", "NO", NULL,
490 &wPreferences.single_click, getBool, NULL, NULL, NULL},
491 {"StrictWindozeCycle", "YES", NULL,
492 &wPreferences.strict_windoze_cycle, getBool, NULL, NULL, NULL},
493 {"SwitchPanelOnlyOpen", "NO", NULL,
494 &wPreferences.panel_only_open, getBool, NULL, NULL, NULL},
495 {"ApercuSize", "2", NULL,
496 &wPreferences.apercu_size, getInt, NULL, NULL, NULL},
498 /* style options */
500 {"MenuStyle", "normal", seMenuStyles,
501 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
502 {"WidgetColor", "(solid, gray)", NULL,
503 NULL, getTexture, setWidgetColor, NULL, NULL},
504 {"WorkspaceSpecificBack", "()", NULL,
505 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
506 /* WorkspaceBack must come after WorkspaceSpecificBack or
507 * WorkspaceBack wont know WorkspaceSpecificBack was also
508 * specified and 2 copies of wmsetbg will be launched */
509 {"WorkspaceBack", "(solid, black)", NULL,
510 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
511 {"SmoothWorkspaceBack", "NO", NULL,
512 NULL, getBool, NULL, NULL, NULL},
513 {"IconBack", "(solid, gray)", NULL,
514 NULL, getTexture, setIconTile, NULL, NULL},
515 {"TitleJustify", "center", seJustifications,
516 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
517 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
518 NULL, getFont, setWinTitleFont, NULL, NULL},
519 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
520 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
521 {"WindowTitleMinHeight", "0", NULL,
522 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
523 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
524 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
525 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
526 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
527 {"MenuTitleMinHeight", "0", NULL,
528 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
529 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
530 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
531 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
532 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
533 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
534 NULL, getFont, setMenuTitleFont, NULL, NULL},
535 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
536 NULL, getFont, setMenuTextFont, NULL, NULL},
537 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
538 NULL, getFont, setIconTitleFont, NULL, NULL},
539 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
540 NULL, getFont, setClipTitleFont, NULL, NULL},
541 {"ShowClipTitle", "YES", NULL,
542 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
543 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
544 NULL, getFont, setLargeDisplayFont, NULL, NULL},
545 {"HighlightColor", "white", NULL,
546 NULL, getColor, setHightlight, NULL, NULL},
547 {"HighlightTextColor", "black", NULL,
548 NULL, getColor, setHightlightText, NULL, NULL},
549 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
550 NULL, getColor, setClipTitleColor, NULL, NULL},
551 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
552 NULL, getColor, setClipTitleColor, NULL, NULL},
553 {"FTitleColor", "white", (void *)WS_FOCUSED,
554 NULL, getColor, setWTitleColor, NULL, NULL},
555 {"PTitleColor", "white", (void *)WS_PFOCUSED,
556 NULL, getColor, setWTitleColor, NULL, NULL},
557 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
558 NULL, getColor, setWTitleColor, NULL, NULL},
559 {"FTitleBack", "(solid, black)", NULL,
560 NULL, getTexture, setFTitleBack, NULL, NULL},
561 {"PTitleBack", "(solid, \"#616161\")", NULL,
562 NULL, getTexture, setPTitleBack, NULL, NULL},
563 {"UTitleBack", "(solid, gray)", NULL,
564 NULL, getTexture, setUTitleBack, NULL, NULL},
565 {"ResizebarBack", "(solid, gray)", NULL,
566 NULL, getTexture, setResizebarBack, NULL, NULL},
567 {"MenuTitleColor", "white", NULL,
568 NULL, getColor, setMenuTitleColor, NULL, NULL},
569 {"MenuTextColor", "black", NULL,
570 NULL, getColor, setMenuTextColor, NULL, NULL},
571 {"MenuDisabledColor", "\"#616161\"", NULL,
572 NULL, getColor, setMenuDisabledColor, NULL, NULL},
573 {"MenuTitleBack", "(solid, black)", NULL,
574 NULL, getTexture, setMenuTitleBack, NULL, NULL},
575 {"MenuTextBack", "(solid, gray)", NULL,
576 NULL, getTexture, setMenuTextBack, NULL, NULL},
577 {"IconTitleColor", "white", NULL,
578 NULL, getColor, setIconTitleColor, NULL, NULL},
579 {"IconTitleBack", "black", NULL,
580 NULL, getColor, setIconTitleBack, NULL, NULL},
581 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
582 NULL, getPropList, setSwPOptions, NULL, NULL},
583 {"ModifierKeyLabels", "(\"Shift+\", \"Control+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
584 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
585 {"FrameBorderWidth", "1", NULL,
586 NULL, getInt, setFrameBorderWidth, NULL, NULL},
587 {"FrameBorderColor", "black", NULL,
588 NULL, getColor, setFrameBorderColor, NULL, NULL},
589 {"FrameFocusedBorderColor", "black", NULL,
590 NULL, getColor, setFrameFocusedBorderColor, NULL, NULL},
591 {"FrameSelectedBorderColor", "white", NULL,
592 NULL, getColor, setFrameSelectedBorderColor, NULL, NULL},
594 /* keybindings */
596 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
597 NULL, getKeybind, setKeyGrab, NULL, NULL},
598 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
599 NULL, getKeybind, setKeyGrab, NULL, NULL},
600 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
601 NULL, getKeybind, setKeyGrab, NULL, NULL},
602 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
603 NULL, getKeybind, setKeyGrab, NULL, NULL},
604 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
605 NULL, getKeybind, setKeyGrab, NULL, NULL},
606 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
607 NULL, getKeybind, setKeyGrab, NULL, NULL},
608 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
609 NULL, getKeybind, setKeyGrab, NULL, NULL },
610 {"HideKey", "None", (void *)WKBD_HIDE,
611 NULL, getKeybind, setKeyGrab, NULL, NULL},
612 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
613 NULL, getKeybind, setKeyGrab, NULL, NULL},
614 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
615 NULL, getKeybind, setKeyGrab, NULL, NULL},
616 {"CloseKey", "None", (void *)WKBD_CLOSE,
617 NULL, getKeybind, setKeyGrab, NULL, NULL},
618 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
619 NULL, getKeybind, setKeyGrab, NULL, NULL},
620 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
621 NULL, getKeybind, setKeyGrab, NULL, NULL},
622 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
623 NULL, getKeybind, setKeyGrab, NULL, NULL},
624 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
625 NULL, getKeybind, setKeyGrab, NULL, NULL},
626 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
627 NULL, getKeybind, setKeyGrab, NULL, NULL},
628 {"THMaximizeKey", "None", (void*)WKBD_THMAXIMIZE,
629 NULL, getKeybind, setKeyGrab, NULL, NULL},
630 {"BHMaximizeKey", "None", (void*)WKBD_BHMAXIMIZE,
631 NULL, getKeybind, setKeyGrab, NULL, NULL},
632 {"LTCMaximizeKey", "None", (void*)WKBD_LTCMAXIMIZE,
633 NULL, getKeybind, setKeyGrab, NULL, NULL},
634 {"RTCMaximizeKey", "None", (void*)WKBD_RTCMAXIMIZE,
635 NULL, getKeybind, setKeyGrab, NULL, NULL},
636 {"LBCMaximizeKey", "None", (void*)WKBD_LBCMAXIMIZE,
637 NULL, getKeybind, setKeyGrab, NULL, NULL},
638 {"RBCMaximizeKey", "None", (void*)WKBD_RBCMAXIMIZE,
639 NULL, getKeybind, setKeyGrab, NULL, NULL},
640 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
641 NULL, getKeybind, setKeyGrab, NULL, NULL},
642 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
643 NULL, getKeybind, setKeyGrab, NULL, NULL},
644 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
645 NULL, getKeybind, setKeyGrab, NULL, NULL},
646 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
647 NULL, getKeybind, setKeyGrab, NULL, NULL},
648 {"ShadeKey", "None", (void *)WKBD_SHADE,
649 NULL, getKeybind, setKeyGrab, NULL, NULL},
650 {"SelectKey", "None", (void *)WKBD_SELECT,
651 NULL, getKeybind, setKeyGrab, NULL, NULL},
652 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
653 NULL, getKeybind, setKeyGrab, NULL, NULL},
654 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
655 NULL, getKeybind, setKeyGrab, NULL, NULL},
656 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
657 NULL, getKeybind, setKeyGrab, NULL, NULL},
658 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
659 NULL, getKeybind, setKeyGrab, NULL, NULL},
660 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
661 NULL, getKeybind, setKeyGrab, NULL, NULL},
662 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
663 NULL, getKeybind, setKeyGrab, NULL, NULL},
664 {"LastWorkspaceKey", "None", (void *)WKBD_LASTWORKSPACE,
665 NULL, getKeybind, setKeyGrab, NULL, NULL},
666 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
667 NULL, getKeybind, setKeyGrab, NULL, NULL},
668 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
669 NULL, getKeybind, setKeyGrab, NULL, NULL},
670 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
671 NULL, getKeybind, setKeyGrab, NULL, NULL},
672 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
673 NULL, getKeybind, setKeyGrab, NULL, NULL},
674 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
675 NULL, getKeybind, setKeyGrab, NULL, NULL},
676 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
677 NULL, getKeybind, setKeyGrab, NULL, NULL},
678 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
679 NULL, getKeybind, setKeyGrab, NULL, NULL},
680 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
681 NULL, getKeybind, setKeyGrab, NULL, NULL},
682 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
683 NULL, getKeybind, setKeyGrab, NULL, NULL},
684 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
685 NULL, getKeybind, setKeyGrab, NULL, NULL},
686 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
687 NULL, getKeybind, setKeyGrab, NULL, NULL},
688 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
689 NULL, getKeybind, setKeyGrab, NULL, NULL},
690 {"MoveToWorkspace1Key", "None", (void *)WKBD_MOVE_WORKSPACE1,
691 NULL, getKeybind, setKeyGrab, NULL, NULL},
692 {"MoveToWorkspace2Key", "None", (void *)WKBD_MOVE_WORKSPACE2,
693 NULL, getKeybind, setKeyGrab, NULL, NULL},
694 {"MoveToWorkspace3Key", "None", (void *)WKBD_MOVE_WORKSPACE3,
695 NULL, getKeybind, setKeyGrab, NULL, NULL},
696 {"MoveToWorkspace4Key", "None", (void *)WKBD_MOVE_WORKSPACE4,
697 NULL, getKeybind, setKeyGrab, NULL, NULL},
698 {"MoveToWorkspace5Key", "None", (void *)WKBD_MOVE_WORKSPACE5,
699 NULL, getKeybind, setKeyGrab, NULL, NULL},
700 {"MoveToWorkspace6Key", "None", (void *)WKBD_MOVE_WORKSPACE6,
701 NULL, getKeybind, setKeyGrab, NULL, NULL},
702 {"MoveToWorkspace7Key", "None", (void *)WKBD_MOVE_WORKSPACE7,
703 NULL, getKeybind, setKeyGrab, NULL, NULL},
704 {"MoveToWorkspace8Key", "None", (void *)WKBD_MOVE_WORKSPACE8,
705 NULL, getKeybind, setKeyGrab, NULL, NULL},
706 {"MoveToWorkspace9Key", "None", (void *)WKBD_MOVE_WORKSPACE9,
707 NULL, getKeybind, setKeyGrab, NULL, NULL},
708 {"MoveToWorkspace10Key", "None", (void *)WKBD_MOVE_WORKSPACE10,
709 NULL, getKeybind, setKeyGrab, NULL, NULL},
710 {"MoveToNextWorkspaceKey", "None", (void *)WKBD_MOVE_NEXTWORKSPACE,
711 NULL, getKeybind, setKeyGrab, NULL, NULL},
712 {"MoveToPrevWorkspaceKey", "None", (void *)WKBD_MOVE_PREVWORKSPACE,
713 NULL, getKeybind, setKeyGrab, NULL, NULL},
714 {"MoveToLastWorkspaceKey", "None", (void *)WKBD_MOVE_LASTWORKSPACE,
715 NULL, getKeybind, setKeyGrab, NULL, NULL},
716 {"MoveToNextWorkspaceLayerKey", "None", (void *)WKBD_MOVE_NEXTWSLAYER,
717 NULL, getKeybind, setKeyGrab, NULL, NULL},
718 {"MoveToPrevWorkspaceLayerKey", "None", (void *)WKBD_MOVE_PREVWSLAYER,
719 NULL, getKeybind, setKeyGrab, NULL, NULL},
720 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
721 NULL, getKeybind, setKeyGrab, NULL, NULL},
722 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
723 NULL, getKeybind, setKeyGrab, NULL, NULL},
724 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
725 NULL, getKeybind, setKeyGrab, NULL, NULL},
726 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
727 NULL, getKeybind, setKeyGrab, NULL, NULL},
728 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
729 NULL, getKeybind, setKeyGrab, NULL, NULL},
730 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
731 NULL, getKeybind, setKeyGrab, NULL, NULL},
732 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
733 NULL, getKeybind, setKeyGrab, NULL, NULL},
734 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
735 NULL, getKeybind, setKeyGrab, NULL, NULL},
736 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
737 NULL, getKeybind, setKeyGrab, NULL, NULL},
738 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
739 NULL, getKeybind, setKeyGrab, NULL, NULL},
740 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
741 NULL, getKeybind, setKeyGrab, NULL, NULL},
742 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
743 NULL, getKeybind, setKeyGrab, NULL, NULL},
744 {"RunKey", "None", (void *)WKBD_RUN,
745 NULL, getKeybind, setKeyGrab, NULL, NULL},
747 #ifdef KEEP_XKB_LOCK_STATUS
748 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
749 NULL, getKeybind, setKeyGrab, NULL, NULL},
750 {"KbdModeLock", "NO", NULL,
751 &wPreferences.modelock, getBool, NULL, NULL, NULL},
752 #endif /* KEEP_XKB_LOCK_STATUS */
754 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
755 NULL, getCursor, setCursor, NULL, NULL},
756 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
757 NULL, getCursor, setCursor, NULL, NULL},
758 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
759 NULL, getCursor, setCursor, NULL, NULL},
760 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
761 NULL, getCursor, setCursor, NULL, NULL},
762 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
763 NULL, getCursor, setCursor, NULL, NULL},
764 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
765 NULL, getCursor, setCursor, NULL, NULL},
766 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
767 NULL, getCursor, setCursor, NULL, NULL},
768 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
769 NULL, getCursor, setCursor, NULL, NULL},
770 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
771 NULL, getCursor, setCursor, NULL, NULL},
772 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
773 NULL, getCursor, setCursor, NULL, NULL},
774 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
775 NULL, getCursor, setCursor, NULL, NULL},
776 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
777 NULL, getCursor, setCursor, NULL, NULL},
778 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
779 NULL, getCursor, setCursor, NULL, NULL},
780 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
781 NULL, getCursor, setCursor, NULL, NULL},
782 {"DialogHistoryLines", "500", NULL,
783 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
784 {"CycleActiveHeadOnly", "NO", NULL,
785 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL},
786 {"CycleIgnoreMinimized", "NO", NULL,
787 &wPreferences.cycle_ignore_minimized, getBool, NULL, NULL, NULL}
790 static void initDefaults(void)
792 unsigned int i;
793 WDefaultEntry *entry;
795 WMPLSetCaseSensitive(False);
797 for (i = 0; i < wlengthof(optionList); i++) {
798 entry = &optionList[i];
800 entry->plkey = WMCreatePLString(entry->key);
801 if (entry->default_value)
802 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
803 else
804 entry->plvalue = NULL;
807 for (i = 0; i < wlengthof(staticOptionList); i++) {
808 entry = &staticOptionList[i];
810 entry->plkey = WMCreatePLString(entry->key);
811 if (entry->default_value)
812 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
813 else
814 entry->plvalue = NULL;
818 static WMPropList *readGlobalDomain(const char *domainName, Bool requireDictionary)
820 WMPropList *globalDict = NULL;
821 char path[PATH_MAX];
822 struct stat stbuf;
824 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
825 if (stat(path, &stbuf) >= 0) {
826 globalDict = WMReadPropListFromFile(path);
827 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
828 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
829 WMReleasePropList(globalDict);
830 globalDict = NULL;
831 } else if (!globalDict) {
832 wwarning(_("could not load domain %s from global defaults database"), domainName);
836 return globalDict;
839 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
840 static void prependMenu(WMPropList * destarr, WMPropList * array)
842 WMPropList *item;
843 int i;
845 for (i = 0; i < WMGetPropListItemCount(array); i++) {
846 item = WMGetFromPLArray(array, i);
847 if (item)
848 WMInsertInPLArray(destarr, i + 1, item);
852 static void appendMenu(WMPropList * destarr, WMPropList * array)
854 WMPropList *item;
855 int i;
857 for (i = 0; i < WMGetPropListItemCount(array); i++) {
858 item = WMGetFromPLArray(array, i);
859 if (item)
860 WMAddToPLArray(destarr, item);
863 #endif
865 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
867 WMPropList *menu = menuDomain->dictionary;
868 WMPropList *submenu;
870 if (!menu || !WMIsPLArray(menu))
871 return;
873 #ifdef GLOBAL_PREAMBLE_MENU_FILE
874 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
876 if (submenu && !WMIsPLArray(submenu)) {
877 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
878 WMReleasePropList(submenu);
879 submenu = NULL;
881 if (submenu) {
882 prependMenu(menu, submenu);
883 WMReleasePropList(submenu);
885 #endif
887 #ifdef GLOBAL_EPILOGUE_MENU_FILE
888 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
890 if (submenu && !WMIsPLArray(submenu)) {
891 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
892 WMReleasePropList(submenu);
893 submenu = NULL;
895 if (submenu) {
896 appendMenu(menu, submenu);
897 WMReleasePropList(submenu);
899 #endif
901 menuDomain->dictionary = menu;
904 WDDomain *wDefaultsInitDomain(const char *domain, Bool requireDictionary)
906 WDDomain *db;
907 struct stat stbuf;
908 static int inited = 0;
909 WMPropList *shared_dict = NULL;
911 if (!inited) {
912 inited = 1;
913 initDefaults();
916 db = wmalloc(sizeof(WDDomain));
917 db->domain_name = domain;
918 db->path = wdefaultspathfordomain(domain);
920 if (stat(db->path, &stbuf) >= 0) {
921 db->dictionary = WMReadPropListFromFile(db->path);
922 if (db->dictionary) {
923 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
924 WMReleasePropList(db->dictionary);
925 db->dictionary = NULL;
926 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, db->path);
928 db->timestamp = stbuf.st_mtime;
929 } else {
930 wwarning(_("could not load domain %s from user defaults database"), domain);
934 /* global system dictionary */
935 shared_dict = readGlobalDomain(domain, requireDictionary);
937 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
938 WMIsPLDictionary(db->dictionary)) {
939 WMMergePLDictionaries(shared_dict, db->dictionary, True);
940 WMReleasePropList(db->dictionary);
941 db->dictionary = shared_dict;
942 if (stbuf.st_mtime > db->timestamp)
943 db->timestamp = stbuf.st_mtime;
944 } else if (!db->dictionary) {
945 db->dictionary = shared_dict;
946 if (stbuf.st_mtime > db->timestamp)
947 db->timestamp = stbuf.st_mtime;
950 return db;
953 void wReadStaticDefaults(WMPropList * dict)
955 WMPropList *plvalue;
956 WDefaultEntry *entry;
957 unsigned int i;
958 void *tdata;
960 for (i = 0; i < wlengthof(staticOptionList); i++) {
961 entry = &staticOptionList[i];
963 if (dict)
964 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
965 else
966 plvalue = NULL;
968 /* no default in the DB. Use builtin default */
969 if (!plvalue)
970 plvalue = entry->plvalue;
972 if (plvalue) {
973 /* convert data */
974 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
975 if (entry->update)
976 (*entry->update) (NULL, entry, tdata, entry->extra_data);
981 void wDefaultsCheckDomains(void* arg)
983 WScreen *scr;
984 struct stat stbuf;
985 WMPropList *shared_dict = NULL;
986 WMPropList *dict;
987 int i;
989 /* Parameter not used, but tell the compiler that it is ok */
990 (void) arg;
992 if (stat(w_global.domain.wmaker->path, &stbuf) >= 0 && w_global.domain.wmaker->timestamp < stbuf.st_mtime) {
993 w_global.domain.wmaker->timestamp = stbuf.st_mtime;
995 /* Global dictionary */
996 shared_dict = readGlobalDomain("WindowMaker", True);
998 /* User dictionary */
999 dict = WMReadPropListFromFile(w_global.domain.wmaker->path);
1001 if (dict) {
1002 if (!WMIsPLDictionary(dict)) {
1003 WMReleasePropList(dict);
1004 dict = NULL;
1005 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1006 "WindowMaker", w_global.domain.wmaker->path);
1007 } else {
1008 if (shared_dict) {
1009 WMMergePLDictionaries(shared_dict, dict, True);
1010 WMReleasePropList(dict);
1011 dict = shared_dict;
1012 shared_dict = NULL;
1015 for (i = 0; i < w_global.screen_count; i++) {
1016 scr = wScreenWithNumber(i);
1017 if (scr)
1018 wReadDefaults(scr, dict);
1021 if (w_global.domain.wmaker->dictionary)
1022 WMReleasePropList(w_global.domain.wmaker->dictionary);
1024 w_global.domain.wmaker->dictionary = dict;
1026 } else {
1027 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1030 if (shared_dict)
1031 WMReleasePropList(shared_dict);
1035 if (stat(w_global.domain.window_attr->path, &stbuf) >= 0 && w_global.domain.window_attr->timestamp < stbuf.st_mtime) {
1036 /* global dictionary */
1037 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1038 /* user dictionary */
1039 dict = WMReadPropListFromFile(w_global.domain.window_attr->path);
1040 if (dict) {
1041 if (!WMIsPLDictionary(dict)) {
1042 WMReleasePropList(dict);
1043 dict = NULL;
1044 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1045 "WMWindowAttributes", w_global.domain.window_attr->path);
1046 } else {
1047 if (shared_dict) {
1048 WMMergePLDictionaries(shared_dict, dict, True);
1049 WMReleasePropList(dict);
1050 dict = shared_dict;
1051 shared_dict = NULL;
1054 if (w_global.domain.window_attr->dictionary)
1055 WMReleasePropList(w_global.domain.window_attr->dictionary);
1057 w_global.domain.window_attr->dictionary = dict;
1058 for (i = 0; i < w_global.screen_count; i++) {
1059 scr = wScreenWithNumber(i);
1060 if (scr) {
1061 wDefaultUpdateIcons(scr);
1063 /* Update the panel image if changed */
1064 /* Don't worry. If the image is the same these
1065 * functions will have no performance impact. */
1066 create_logo_image(scr);
1070 } else {
1071 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1074 w_global.domain.window_attr->timestamp = stbuf.st_mtime;
1075 if (shared_dict)
1076 WMReleasePropList(shared_dict);
1079 if (stat(w_global.domain.root_menu->path, &stbuf) >= 0 && w_global.domain.root_menu->timestamp < stbuf.st_mtime) {
1080 dict = WMReadPropListFromFile(w_global.domain.root_menu->path);
1081 if (dict) {
1082 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1083 WMReleasePropList(dict);
1084 dict = NULL;
1085 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1086 "WMRootMenu", w_global.domain.root_menu->path);
1087 } else {
1088 if (w_global.domain.root_menu->dictionary)
1089 WMReleasePropList(w_global.domain.root_menu->dictionary);
1091 w_global.domain.root_menu->dictionary = dict;
1092 wDefaultsMergeGlobalMenus(w_global.domain.root_menu);
1094 } else {
1095 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1097 w_global.domain.root_menu->timestamp = stbuf.st_mtime;
1099 #ifndef HAVE_INOTIFY
1100 if (!arg)
1101 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1102 #endif
1105 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1107 WMPropList *plvalue, *old_value;
1108 WDefaultEntry *entry;
1109 unsigned int i;
1110 int update_workspace_back = 0; /* kluge :/ */
1111 unsigned int needs_refresh;
1112 void *tdata;
1113 WMPropList *old_dict = (w_global.domain.wmaker->dictionary != new_dict ? w_global.domain.wmaker->dictionary : NULL);
1115 needs_refresh = 0;
1117 for (i = 0; i < wlengthof(optionList); i++) {
1118 entry = &optionList[i];
1120 if (new_dict)
1121 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1122 else
1123 plvalue = NULL;
1125 if (!old_dict)
1126 old_value = NULL;
1127 else
1128 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1130 if (!plvalue && !old_value) {
1131 /* no default in the DB. Use builtin default */
1132 plvalue = entry->plvalue;
1133 if (plvalue && new_dict)
1134 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1136 } else if (!plvalue) {
1137 /* value was deleted from DB. Keep current value */
1138 continue;
1139 } else if (!old_value) {
1140 /* set value for the 1st time */
1141 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1142 /* value has changed */
1143 } else {
1144 if (strcmp(entry->key, "WorkspaceBack") == 0
1145 && update_workspace_back && scr->flags.backimage_helper_launched) {
1146 } else {
1147 /* value was not changed since last time */
1148 continue;
1152 if (plvalue) {
1153 /* convert data */
1154 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1156 * If the WorkspaceSpecificBack data has been changed
1157 * so that the helper will be launched now, we must be
1158 * sure to send the default background texture config
1159 * to the helper.
1161 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1162 !scr->flags.backimage_helper_launched)
1163 update_workspace_back = 1;
1165 if (entry->update)
1166 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1172 if (needs_refresh != 0 && !scr->flags.startup) {
1173 int foo;
1175 foo = 0;
1176 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1177 foo |= WTextureSettings;
1178 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1179 foo |= WFontSettings;
1180 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1181 foo |= WColorSettings;
1182 if (foo)
1183 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1184 (void *)(uintptr_t) foo);
1186 foo = 0;
1187 if (needs_refresh & REFRESH_MENU_TEXTURE)
1188 foo |= WTextureSettings;
1189 if (needs_refresh & REFRESH_MENU_FONT)
1190 foo |= WFontSettings;
1191 if (needs_refresh & REFRESH_MENU_COLOR)
1192 foo |= WColorSettings;
1193 if (foo)
1194 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1196 foo = 0;
1197 if (needs_refresh & REFRESH_WINDOW_FONT)
1198 foo |= WFontSettings;
1199 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1200 foo |= WTextureSettings;
1201 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1202 foo |= WColorSettings;
1203 if (foo)
1204 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1206 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1207 foo = 0;
1208 if (needs_refresh & REFRESH_ICON_FONT)
1209 foo |= WFontSettings;
1210 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1211 foo |= WTextureSettings;
1212 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1213 foo |= WTextureSettings;
1214 if (foo)
1215 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1216 (void *)(uintptr_t) foo);
1218 if (needs_refresh & REFRESH_ICON_TILE)
1219 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1221 if (needs_refresh & REFRESH_WORKSPACE_MENU) {
1222 if (w_global.workspace.menu)
1223 wWorkspaceMenuUpdate(w_global.workspace.menu);
1224 if (w_global.clip.ws_menu)
1225 wWorkspaceMenuUpdate(w_global.clip.ws_menu);
1226 if (w_global.workspace.submenu)
1227 w_global.workspace.submenu->flags.realized = 0;
1228 if (w_global.clip.submenu)
1229 w_global.clip.submenu->flags.realized = 0;
1234 void wDefaultUpdateIcons(WScreen *scr)
1236 WAppIcon *aicon = w_global.app_icon_list;
1237 WDrawerChain *dc;
1238 WWindow *wwin = scr->focused_window;
1240 while (aicon) {
1241 /* Get the application icon, default included */
1242 wIconChangeImageFile(aicon->icon, NULL);
1243 wAppIconPaint(aicon);
1244 aicon = aicon->next;
1247 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock)
1248 wClipIconPaint();
1250 for (dc = scr->drawers; dc != NULL; dc = dc->next)
1251 wDrawerIconPaint(dc->adrawer->icon_array[0]);
1253 while (wwin) {
1254 if (wwin->icon && wwin->flags.miniaturized)
1255 wIconChangeImageFile(wwin->icon, NULL);
1256 wwin = wwin->prev;
1260 /* --------------------------- Local ----------------------- */
1262 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1263 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1264 entry->key, x); \
1265 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1266 var = entry->default_value;\
1267 } else var = WMGetFromPLString(value)\
1270 static int string2index(WMPropList *key, WMPropList *val, const char *def, WOptionEnumeration * values)
1272 char *str;
1273 WOptionEnumeration *v;
1274 char buffer[TOTAL_VALUES_LENGTH];
1276 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1277 for (v = values; v->string != NULL; v++) {
1278 if (strcasecmp(v->string, str) == 0)
1279 return v->value;
1283 buffer[0] = 0;
1284 for (v = values; v->string != NULL; v++) {
1285 if (!v->is_alias) {
1286 if (buffer[0] != 0)
1287 strcat(buffer, ", ");
1288 snprintf(buffer+strlen(buffer),
1289 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1292 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1293 WMGetFromPLString(key),
1294 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1295 buffer);
1297 if (def) {
1298 return string2index(key, val, NULL, values);
1301 return -1;
1305 * value - is the value in the defaults DB
1306 * addr - is the address to store the data
1307 * ret - is the address to store a pointer to a temporary buffer. ret
1308 * must not be freed and is used by the set functions
1310 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1312 static char data;
1313 const char *val;
1314 int second_pass = 0;
1316 /* Parameter not used, but tell the compiler that it is ok */
1317 (void) scr;
1319 GET_STRING_OR_DEFAULT("Boolean", val);
1321 again:
1322 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1323 || strcasecmp(val, "YES") == 0) {
1325 data = 1;
1326 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1327 || strcasecmp(val, "NO") == 0) {
1328 data = 0;
1329 } else {
1330 int i;
1331 if (sscanf(val, "%i", &i) == 1) {
1332 if (i != 0)
1333 data = 1;
1334 else
1335 data = 0;
1336 } else {
1337 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1338 if (second_pass == 0) {
1339 val = WMGetFromPLString(entry->plvalue);
1340 second_pass = 1;
1341 wwarning(_("using default \"%s\" instead"), val);
1342 goto again;
1344 return False;
1348 if (ret)
1349 *ret = &data;
1350 if (addr)
1351 *(char *)addr = data;
1353 return True;
1356 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1358 static int data;
1359 const char *val;
1361 /* Parameter not used, but tell the compiler that it is ok */
1362 (void) scr;
1364 GET_STRING_OR_DEFAULT("Integer", val);
1366 if (sscanf(val, "%i", &data) != 1) {
1367 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1368 val = WMGetFromPLString(entry->plvalue);
1369 wwarning(_("using default \"%s\" instead"), val);
1370 if (sscanf(val, "%i", &data) != 1) {
1371 return False;
1375 if (ret)
1376 *ret = &data;
1377 if (addr)
1378 *(int *)addr = data;
1380 return True;
1383 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1385 static WCoord data;
1386 char *val_x, *val_y;
1387 int nelem, changed = 0;
1388 WMPropList *elem_x, *elem_y;
1390 again:
1391 if (!WMIsPLArray(value)) {
1392 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1393 if (changed == 0) {
1394 value = entry->plvalue;
1395 changed = 1;
1396 wwarning(_("using default \"%s\" instead"), entry->default_value);
1397 goto again;
1399 return False;
1402 nelem = WMGetPropListItemCount(value);
1403 if (nelem != 2) {
1404 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1405 if (changed == 0) {
1406 value = entry->plvalue;
1407 changed = 1;
1408 wwarning(_("using default \"%s\" instead"), entry->default_value);
1409 goto again;
1411 return False;
1414 elem_x = WMGetFromPLArray(value, 0);
1415 elem_y = WMGetFromPLArray(value, 1);
1417 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1418 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1419 if (changed == 0) {
1420 value = entry->plvalue;
1421 changed = 1;
1422 wwarning(_("using default \"%s\" instead"), entry->default_value);
1423 goto again;
1425 return False;
1428 val_x = WMGetFromPLString(elem_x);
1429 val_y = WMGetFromPLString(elem_y);
1431 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1432 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1433 if (changed == 0) {
1434 value = entry->plvalue;
1435 changed = 1;
1436 wwarning(_("using default \"%s\" instead"), entry->default_value);
1437 goto again;
1439 return False;
1442 if (data.x < 0)
1443 data.x = 0;
1444 else if (data.x > scr->scr_width / 3)
1445 data.x = scr->scr_width / 3;
1446 if (data.y < 0)
1447 data.y = 0;
1448 else if (data.y > scr->scr_height / 3)
1449 data.y = scr->scr_height / 3;
1451 if (ret)
1452 *ret = &data;
1453 if (addr)
1454 *(WCoord *) addr = data;
1456 return True;
1459 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1461 /* Parameter not used, but tell the compiler that it is ok */
1462 (void) scr;
1463 (void) entry;
1464 (void) addr;
1466 WMRetainPropList(value);
1468 *ret = value;
1470 return True;
1473 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1475 static char *data;
1476 int i, count, len;
1477 char *ptr;
1478 WMPropList *d;
1479 int changed = 0;
1481 /* Parameter not used, but tell the compiler that it is ok */
1482 (void) scr;
1483 (void) ret;
1485 again:
1486 if (!WMIsPLArray(value)) {
1487 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1488 if (changed == 0) {
1489 value = entry->plvalue;
1490 changed = 1;
1491 wwarning(_("using default \"%s\" instead"), entry->default_value);
1492 goto again;
1494 return False;
1497 i = 0;
1498 count = WMGetPropListItemCount(value);
1499 if (count < 1) {
1500 if (changed == 0) {
1501 value = entry->plvalue;
1502 changed = 1;
1503 wwarning(_("using default \"%s\" instead"), entry->default_value);
1504 goto again;
1506 return False;
1509 len = 0;
1510 for (i = 0; i < count; i++) {
1511 d = WMGetFromPLArray(value, i);
1512 if (!d || !WMIsPLString(d)) {
1513 count = i;
1514 break;
1516 len += strlen(WMGetFromPLString(d)) + 1;
1519 ptr = data = wmalloc(len + 1);
1521 for (i = 0; i < count; i++) {
1522 d = WMGetFromPLArray(value, i);
1523 if (!d || !WMIsPLString(d)) {
1524 break;
1526 strcpy(ptr, WMGetFromPLString(d));
1527 ptr += strlen(WMGetFromPLString(d));
1528 *ptr = ':';
1529 ptr++;
1531 ptr--;
1532 *(ptr--) = 0;
1534 if (*(char **)addr != NULL) {
1535 wfree(*(char **)addr);
1537 *(char **)addr = data;
1539 return True;
1542 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1544 static signed char data;
1546 /* Parameter not used, but tell the compiler that it is ok */
1547 (void) scr;
1549 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1550 if (data < 0)
1551 return False;
1553 if (ret)
1554 *ret = &data;
1555 if (addr)
1556 *(signed char *)addr = data;
1558 return True;
1562 * (solid <color>)
1563 * (hgradient <color> <color>)
1564 * (vgradient <color> <color>)
1565 * (dgradient <color> <color>)
1566 * (mhgradient <color> <color> ...)
1567 * (mvgradient <color> <color> ...)
1568 * (mdgradient <color> <color> ...)
1569 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1570 * (tpixmap <file> <color>)
1571 * (spixmap <file> <color>)
1572 * (cpixmap <file> <color>)
1573 * (thgradient <file> <opaqueness> <color> <color>)
1574 * (tvgradient <file> <opaqueness> <color> <color>)
1575 * (tdgradient <file> <opaqueness> <color> <color>)
1576 * (function <lib> <function> ...)
1579 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1581 WMPropList *elem;
1582 char *val;
1583 int nelem;
1584 WTexture *texture = NULL;
1586 nelem = WMGetPropListItemCount(pl);
1587 if (nelem < 1)
1588 return NULL;
1590 elem = WMGetFromPLArray(pl, 0);
1591 if (!elem || !WMIsPLString(elem))
1592 return NULL;
1593 val = WMGetFromPLString(elem);
1595 if (strcasecmp(val, "solid") == 0) {
1596 XColor color;
1598 if (nelem != 2)
1599 return NULL;
1601 /* get color */
1603 elem = WMGetFromPLArray(pl, 1);
1604 if (!elem || !WMIsPLString(elem))
1605 return NULL;
1606 val = WMGetFromPLString(elem);
1608 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1609 wwarning(_("\"%s\" is not a valid color name"), val);
1610 return NULL;
1613 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1614 } else if (strcasecmp(val, "dgradient") == 0
1615 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1616 RColor color1, color2;
1617 XColor xcolor;
1618 int type;
1620 if (nelem != 3) {
1621 wwarning(_("bad number of arguments in gradient specification"));
1622 return NULL;
1625 if (val[0] == 'd' || val[0] == 'D')
1626 type = WTEX_DGRADIENT;
1627 else if (val[0] == 'h' || val[0] == 'H')
1628 type = WTEX_HGRADIENT;
1629 else
1630 type = WTEX_VGRADIENT;
1632 /* get from color */
1633 elem = WMGetFromPLArray(pl, 1);
1634 if (!elem || !WMIsPLString(elem))
1635 return NULL;
1636 val = WMGetFromPLString(elem);
1638 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1639 wwarning(_("\"%s\" is not a valid color name"), val);
1640 return NULL;
1642 color1.alpha = 255;
1643 color1.red = xcolor.red >> 8;
1644 color1.green = xcolor.green >> 8;
1645 color1.blue = xcolor.blue >> 8;
1647 /* get to color */
1648 elem = WMGetFromPLArray(pl, 2);
1649 if (!elem || !WMIsPLString(elem)) {
1650 return NULL;
1652 val = WMGetFromPLString(elem);
1654 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1655 wwarning(_("\"%s\" is not a valid color name"), val);
1656 return NULL;
1658 color2.alpha = 255;
1659 color2.red = xcolor.red >> 8;
1660 color2.green = xcolor.green >> 8;
1661 color2.blue = xcolor.blue >> 8;
1663 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1665 } else if (strcasecmp(val, "igradient") == 0) {
1666 RColor colors1[2], colors2[2];
1667 int th1, th2;
1668 XColor xcolor;
1669 int i;
1671 if (nelem != 7) {
1672 wwarning(_("bad number of arguments in gradient specification"));
1673 return NULL;
1676 /* get from color */
1677 for (i = 0; i < 2; i++) {
1678 elem = WMGetFromPLArray(pl, 1 + i);
1679 if (!elem || !WMIsPLString(elem))
1680 return NULL;
1681 val = WMGetFromPLString(elem);
1683 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1684 wwarning(_("\"%s\" is not a valid color name"), val);
1685 return NULL;
1687 colors1[i].alpha = 255;
1688 colors1[i].red = xcolor.red >> 8;
1689 colors1[i].green = xcolor.green >> 8;
1690 colors1[i].blue = xcolor.blue >> 8;
1692 elem = WMGetFromPLArray(pl, 3);
1693 if (!elem || !WMIsPLString(elem))
1694 return NULL;
1695 val = WMGetFromPLString(elem);
1696 th1 = atoi(val);
1698 /* get from color */
1699 for (i = 0; i < 2; i++) {
1700 elem = WMGetFromPLArray(pl, 4 + i);
1701 if (!elem || !WMIsPLString(elem))
1702 return NULL;
1703 val = WMGetFromPLString(elem);
1705 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1706 wwarning(_("\"%s\" is not a valid color name"), val);
1707 return NULL;
1709 colors2[i].alpha = 255;
1710 colors2[i].red = xcolor.red >> 8;
1711 colors2[i].green = xcolor.green >> 8;
1712 colors2[i].blue = xcolor.blue >> 8;
1714 elem = WMGetFromPLArray(pl, 6);
1715 if (!elem || !WMIsPLString(elem))
1716 return NULL;
1717 val = WMGetFromPLString(elem);
1718 th2 = atoi(val);
1720 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1722 } else if (strcasecmp(val, "mhgradient") == 0
1723 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1724 XColor color;
1725 RColor **colors;
1726 int i, count;
1727 int type;
1729 if (nelem < 3) {
1730 wwarning(_("too few arguments in multicolor gradient specification"));
1731 return NULL;
1734 if (val[1] == 'h' || val[1] == 'H')
1735 type = WTEX_MHGRADIENT;
1736 else if (val[1] == 'v' || val[1] == 'V')
1737 type = WTEX_MVGRADIENT;
1738 else
1739 type = WTEX_MDGRADIENT;
1741 count = nelem - 1;
1743 colors = wmalloc(sizeof(RColor *) * (count + 1));
1745 for (i = 0; i < count; i++) {
1746 elem = WMGetFromPLArray(pl, i + 1);
1747 if (!elem || !WMIsPLString(elem)) {
1748 for (--i; i >= 0; --i) {
1749 wfree(colors[i]);
1751 wfree(colors);
1752 return NULL;
1754 val = WMGetFromPLString(elem);
1756 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1757 wwarning(_("\"%s\" is not a valid color name"), val);
1758 for (--i; i >= 0; --i) {
1759 wfree(colors[i]);
1761 wfree(colors);
1762 return NULL;
1763 } else {
1764 colors[i] = wmalloc(sizeof(RColor));
1765 colors[i]->red = color.red >> 8;
1766 colors[i]->green = color.green >> 8;
1767 colors[i]->blue = color.blue >> 8;
1770 colors[i] = NULL;
1772 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1773 } else if (strcasecmp(val, "spixmap") == 0 ||
1774 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1775 XColor color;
1776 int type;
1778 if (nelem != 3)
1779 return NULL;
1781 if (val[0] == 's' || val[0] == 'S')
1782 type = WTP_SCALE;
1783 else if (val[0] == 'c' || val[0] == 'C')
1784 type = WTP_CENTER;
1785 else
1786 type = WTP_TILE;
1788 /* get color */
1789 elem = WMGetFromPLArray(pl, 2);
1790 if (!elem || !WMIsPLString(elem)) {
1791 return NULL;
1793 val = WMGetFromPLString(elem);
1795 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1796 wwarning(_("\"%s\" is not a valid color name"), val);
1797 return NULL;
1800 /* file name */
1801 elem = WMGetFromPLArray(pl, 1);
1802 if (!elem || !WMIsPLString(elem))
1803 return NULL;
1804 val = WMGetFromPLString(elem);
1806 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1807 } else if (strcasecmp(val, "thgradient") == 0
1808 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1809 RColor color1, color2;
1810 XColor xcolor;
1811 int opacity;
1812 int style;
1814 if (val[1] == 'h' || val[1] == 'H')
1815 style = WTEX_THGRADIENT;
1816 else if (val[1] == 'v' || val[1] == 'V')
1817 style = WTEX_TVGRADIENT;
1818 else
1819 style = WTEX_TDGRADIENT;
1821 if (nelem != 5) {
1822 wwarning(_("bad number of arguments in textured gradient specification"));
1823 return NULL;
1826 /* get from color */
1827 elem = WMGetFromPLArray(pl, 3);
1828 if (!elem || !WMIsPLString(elem))
1829 return NULL;
1830 val = WMGetFromPLString(elem);
1832 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1833 wwarning(_("\"%s\" is not a valid color name"), val);
1834 return NULL;
1836 color1.alpha = 255;
1837 color1.red = xcolor.red >> 8;
1838 color1.green = xcolor.green >> 8;
1839 color1.blue = xcolor.blue >> 8;
1841 /* get to color */
1842 elem = WMGetFromPLArray(pl, 4);
1843 if (!elem || !WMIsPLString(elem)) {
1844 return NULL;
1846 val = WMGetFromPLString(elem);
1848 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1849 wwarning(_("\"%s\" is not a valid color name"), val);
1850 return NULL;
1852 color2.alpha = 255;
1853 color2.red = xcolor.red >> 8;
1854 color2.green = xcolor.green >> 8;
1855 color2.blue = xcolor.blue >> 8;
1857 /* get opacity */
1858 elem = WMGetFromPLArray(pl, 2);
1859 if (!elem || !WMIsPLString(elem))
1860 opacity = 128;
1861 else
1862 val = WMGetFromPLString(elem);
1864 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1865 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1866 opacity = 128;
1869 /* get file name */
1870 elem = WMGetFromPLArray(pl, 1);
1871 if (!elem || !WMIsPLString(elem))
1872 return NULL;
1873 val = WMGetFromPLString(elem);
1875 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1876 } else if (strcasecmp(val, "function") == 0) {
1877 /* Leave this in to handle the unlikely case of
1878 * someone actually having function textures configured */
1879 wwarning("function texture support has been removed");
1880 return NULL;
1881 } else {
1882 wwarning(_("invalid texture type %s"), val);
1883 return NULL;
1885 return texture;
1888 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1890 static WTexture *texture;
1891 int changed = 0;
1893 again:
1894 if (!WMIsPLArray(value)) {
1895 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1896 if (changed == 0) {
1897 value = entry->plvalue;
1898 changed = 1;
1899 wwarning(_("using default \"%s\" instead"), entry->default_value);
1900 goto again;
1902 return False;
1905 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1906 WMPropList *pl;
1908 pl = WMGetFromPLArray(value, 0);
1909 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1910 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1911 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1912 entry->key, "Solid Texture");
1914 value = entry->plvalue;
1915 changed = 1;
1916 wwarning(_("using default \"%s\" instead"), entry->default_value);
1917 goto again;
1921 texture = parse_texture(scr, value);
1923 if (!texture) {
1924 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1925 if (changed == 0) {
1926 value = entry->plvalue;
1927 changed = 1;
1928 wwarning(_("using default \"%s\" instead"), entry->default_value);
1929 goto again;
1931 return False;
1934 if (ret)
1935 *ret = &texture;
1937 if (addr)
1938 *(WTexture **) addr = texture;
1940 return True;
1943 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1945 WMPropList *elem;
1946 int changed = 0;
1947 char *val;
1948 int nelem;
1950 /* Parameter not used, but tell the compiler that it is ok */
1951 (void) scr;
1952 (void) addr;
1954 again:
1955 if (!WMIsPLArray(value)) {
1956 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1957 "WorkspaceBack", "Texture or None");
1958 if (changed == 0) {
1959 value = entry->plvalue;
1960 changed = 1;
1961 wwarning(_("using default \"%s\" instead"), entry->default_value);
1962 goto again;
1964 return False;
1967 /* only do basic error checking and verify for None texture */
1969 nelem = WMGetPropListItemCount(value);
1970 if (nelem > 0) {
1971 elem = WMGetFromPLArray(value, 0);
1972 if (!elem || !WMIsPLString(elem)) {
1973 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1974 if (changed == 0) {
1975 value = entry->plvalue;
1976 changed = 1;
1977 wwarning(_("using default \"%s\" instead"), entry->default_value);
1978 goto again;
1980 return False;
1982 val = WMGetFromPLString(elem);
1984 if (strcasecmp(val, "None") == 0)
1985 return True;
1987 *ret = WMRetainPropList(value);
1989 return True;
1992 static int
1993 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1995 WMPropList *elem;
1996 int nelem;
1997 int changed = 0;
1999 /* Parameter not used, but tell the compiler that it is ok */
2000 (void) scr;
2001 (void) addr;
2003 again:
2004 if (!WMIsPLArray(value)) {
2005 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2006 "WorkspaceSpecificBack", "an array of textures");
2007 if (changed == 0) {
2008 value = entry->plvalue;
2009 changed = 1;
2010 wwarning(_("using default \"%s\" instead"), entry->default_value);
2011 goto again;
2013 return False;
2016 /* only do basic error checking and verify for None texture */
2018 nelem = WMGetPropListItemCount(value);
2019 if (nelem > 0) {
2020 while (nelem--) {
2021 elem = WMGetFromPLArray(value, nelem);
2022 if (!elem || !WMIsPLArray(elem)) {
2023 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2024 nelem);
2029 *ret = WMRetainPropList(value);
2031 #ifdef notworking
2033 * Kluge to force wmsetbg helper to set the default background.
2034 * If the WorkspaceSpecificBack is changed once wmaker has started,
2035 * the WorkspaceBack won't be sent to the helper, unless the user
2036 * changes it's value too. So, we must force this by removing the
2037 * value from the defaults DB.
2039 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2040 WMPropList *key = WMCreatePLString("WorkspaceBack");
2042 WMRemoveFromPLDictionary(w_global.domain.wmaker->dictionary, key);
2044 WMReleasePropList(key);
2046 #endif
2047 return True;
2050 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2052 static WMFont *font;
2053 const char *val;
2055 (void) addr;
2057 GET_STRING_OR_DEFAULT("Font", val);
2059 font = WMCreateFont(scr->wmscreen, val);
2060 if (!font)
2061 font = WMCreateFont(scr->wmscreen, "fixed");
2063 if (!font) {
2064 wfatal(_("could not load any usable font!!!"));
2065 exit(1);
2068 if (ret)
2069 *ret = font;
2071 /* can't assign font value outside update function */
2072 wassertrv(addr == NULL, True);
2074 return True;
2077 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2079 static XColor color;
2080 const char *val;
2081 int second_pass = 0;
2083 (void) addr;
2085 GET_STRING_OR_DEFAULT("Color", val);
2087 again:
2088 if (!wGetColor(scr, val, &color)) {
2089 wwarning(_("could not get color for key \"%s\""), entry->key);
2090 if (second_pass == 0) {
2091 val = WMGetFromPLString(entry->plvalue);
2092 second_pass = 1;
2093 wwarning(_("using default \"%s\" instead"), val);
2094 goto again;
2096 return False;
2099 if (ret)
2100 *ret = &color;
2102 assert(addr == NULL);
2104 if (addr)
2105 *(unsigned long*)addr = pixel;
2108 return True;
2111 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2113 static WShortKey shortcut;
2114 KeySym ksym;
2115 const char *val;
2116 char *k;
2117 char buf[MAX_SHORTCUT_LENGTH], *b;
2119 /* Parameter not used, but tell the compiler that it is ok */
2120 (void) scr;
2121 (void) addr;
2123 GET_STRING_OR_DEFAULT("Key spec", val);
2125 if (!val || strcasecmp(val, "NONE") == 0) {
2126 shortcut.keycode = 0;
2127 shortcut.modifier = 0;
2128 if (ret)
2129 *ret = &shortcut;
2130 return True;
2133 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2135 b = (char *)buf;
2137 /* get modifiers */
2138 shortcut.modifier = 0;
2139 while ((k = strchr(b, '+')) != NULL) {
2140 int mod;
2142 *k = 0;
2143 mod = wXModifierFromKey(b);
2144 if (mod < 0) {
2145 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2146 return False;
2148 shortcut.modifier |= mod;
2150 b = k + 1;
2153 /* get key */
2154 ksym = XStringToKeysym(b);
2156 if (ksym == NoSymbol) {
2157 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2158 return False;
2161 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2162 if (shortcut.keycode == 0) {
2163 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2164 return False;
2167 if (ret)
2168 *ret = &shortcut;
2170 return True;
2173 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2175 static int mask;
2176 const char *str;
2178 /* Parameter not used, but tell the compiler that it is ok */
2179 (void) scr;
2181 GET_STRING_OR_DEFAULT("Modifier Key", str);
2183 if (!str)
2184 return False;
2186 mask = wXModifierFromKey(str);
2187 if (mask < 0) {
2188 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2189 mask = 0;
2190 return False;
2193 if (addr)
2194 *(int *)addr = mask;
2196 if (ret)
2197 *ret = &mask;
2199 return True;
2202 # include <X11/cursorfont.h>
2203 typedef struct {
2204 const char *name;
2205 int id;
2206 } WCursorLookup;
2208 #define CURSOR_ID_NONE (XC_num_glyphs)
2210 static const WCursorLookup cursor_table[] = {
2211 {"X_cursor", XC_X_cursor},
2212 {"arrow", XC_arrow},
2213 {"based_arrow_down", XC_based_arrow_down},
2214 {"based_arrow_up", XC_based_arrow_up},
2215 {"boat", XC_boat},
2216 {"bogosity", XC_bogosity},
2217 {"bottom_left_corner", XC_bottom_left_corner},
2218 {"bottom_right_corner", XC_bottom_right_corner},
2219 {"bottom_side", XC_bottom_side},
2220 {"bottom_tee", XC_bottom_tee},
2221 {"box_spiral", XC_box_spiral},
2222 {"center_ptr", XC_center_ptr},
2223 {"circle", XC_circle},
2224 {"clock", XC_clock},
2225 {"coffee_mug", XC_coffee_mug},
2226 {"cross", XC_cross},
2227 {"cross_reverse", XC_cross_reverse},
2228 {"crosshair", XC_crosshair},
2229 {"diamond_cross", XC_diamond_cross},
2230 {"dot", XC_dot},
2231 {"dotbox", XC_dotbox},
2232 {"double_arrow", XC_double_arrow},
2233 {"draft_large", XC_draft_large},
2234 {"draft_small", XC_draft_small},
2235 {"draped_box", XC_draped_box},
2236 {"exchange", XC_exchange},
2237 {"fleur", XC_fleur},
2238 {"gobbler", XC_gobbler},
2239 {"gumby", XC_gumby},
2240 {"hand1", XC_hand1},
2241 {"hand2", XC_hand2},
2242 {"heart", XC_heart},
2243 {"icon", XC_icon},
2244 {"iron_cross", XC_iron_cross},
2245 {"left_ptr", XC_left_ptr},
2246 {"left_side", XC_left_side},
2247 {"left_tee", XC_left_tee},
2248 {"leftbutton", XC_leftbutton},
2249 {"ll_angle", XC_ll_angle},
2250 {"lr_angle", XC_lr_angle},
2251 {"man", XC_man},
2252 {"middlebutton", XC_middlebutton},
2253 {"mouse", XC_mouse},
2254 {"pencil", XC_pencil},
2255 {"pirate", XC_pirate},
2256 {"plus", XC_plus},
2257 {"question_arrow", XC_question_arrow},
2258 {"right_ptr", XC_right_ptr},
2259 {"right_side", XC_right_side},
2260 {"right_tee", XC_right_tee},
2261 {"rightbutton", XC_rightbutton},
2262 {"rtl_logo", XC_rtl_logo},
2263 {"sailboat", XC_sailboat},
2264 {"sb_down_arrow", XC_sb_down_arrow},
2265 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2266 {"sb_left_arrow", XC_sb_left_arrow},
2267 {"sb_right_arrow", XC_sb_right_arrow},
2268 {"sb_up_arrow", XC_sb_up_arrow},
2269 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2270 {"shuttle", XC_shuttle},
2271 {"sizing", XC_sizing},
2272 {"spider", XC_spider},
2273 {"spraycan", XC_spraycan},
2274 {"star", XC_star},
2275 {"target", XC_target},
2276 {"tcross", XC_tcross},
2277 {"top_left_arrow", XC_top_left_arrow},
2278 {"top_left_corner", XC_top_left_corner},
2279 {"top_right_corner", XC_top_right_corner},
2280 {"top_side", XC_top_side},
2281 {"top_tee", XC_top_tee},
2282 {"trek", XC_trek},
2283 {"ul_angle", XC_ul_angle},
2284 {"umbrella", XC_umbrella},
2285 {"ur_angle", XC_ur_angle},
2286 {"watch", XC_watch},
2287 {"xterm", XC_xterm},
2288 {NULL, CURSOR_ID_NONE}
2291 static void check_bitmap_status(int status, const char *filename, Pixmap bitmap)
2293 switch (status) {
2294 case BitmapOpenFailed:
2295 wwarning(_("failed to open bitmap file \"%s\""), filename);
2296 break;
2297 case BitmapFileInvalid:
2298 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2299 break;
2300 case BitmapNoMemory:
2301 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2302 break;
2303 case BitmapSuccess:
2304 XFreePixmap(dpy, bitmap);
2305 break;
2310 * (none)
2311 * (builtin, <cursor_name>)
2312 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2314 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2316 WMPropList *elem;
2317 char *val;
2318 int nelem;
2319 int status = 0;
2321 nelem = WMGetPropListItemCount(pl);
2322 if (nelem < 1) {
2323 return (status);
2325 elem = WMGetFromPLArray(pl, 0);
2326 if (!elem || !WMIsPLString(elem)) {
2327 return (status);
2329 val = WMGetFromPLString(elem);
2331 if (strcasecmp(val, "none") == 0) {
2332 status = 1;
2333 *cursor = None;
2334 } else if (strcasecmp(val, "builtin") == 0) {
2335 int i;
2336 int cursor_id = CURSOR_ID_NONE;
2338 if (nelem != 2) {
2339 wwarning(_("bad number of arguments in cursor specification"));
2340 return (status);
2342 elem = WMGetFromPLArray(pl, 1);
2343 if (!elem || !WMIsPLString(elem)) {
2344 return (status);
2346 val = WMGetFromPLString(elem);
2348 for (i = 0; cursor_table[i].name != NULL; i++) {
2349 if (strcasecmp(val, cursor_table[i].name) == 0) {
2350 cursor_id = cursor_table[i].id;
2351 break;
2354 if (CURSOR_ID_NONE == cursor_id) {
2355 wwarning(_("unknown builtin cursor name \"%s\""), val);
2356 } else {
2357 *cursor = XCreateFontCursor(dpy, cursor_id);
2358 status = 1;
2360 } else if (strcasecmp(val, "bitmap") == 0) {
2361 char *bitmap_name;
2362 char *mask_name;
2363 int bitmap_status;
2364 int mask_status;
2365 Pixmap bitmap;
2366 Pixmap mask;
2367 unsigned int w, h;
2368 int x, y;
2369 XColor fg, bg;
2371 if (nelem != 3) {
2372 wwarning(_("bad number of arguments in cursor specification"));
2373 return (status);
2375 elem = WMGetFromPLArray(pl, 1);
2376 if (!elem || !WMIsPLString(elem)) {
2377 return (status);
2379 val = WMGetFromPLString(elem);
2380 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2381 if (!bitmap_name) {
2382 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2383 return (status);
2385 elem = WMGetFromPLArray(pl, 2);
2386 if (!elem || !WMIsPLString(elem)) {
2387 wfree(bitmap_name);
2388 return (status);
2390 val = WMGetFromPLString(elem);
2391 mask_name = FindImage(wPreferences.pixmap_path, val);
2392 if (!mask_name) {
2393 wfree(bitmap_name);
2394 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2395 return (status);
2397 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2398 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2399 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2400 fg.pixel = scr->black_pixel;
2401 bg.pixel = scr->white_pixel;
2402 XQueryColor(dpy, scr->w_colormap, &fg);
2403 XQueryColor(dpy, scr->w_colormap, &bg);
2404 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2405 status = 1;
2407 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2408 check_bitmap_status(mask_status, mask_name, mask);
2409 wfree(bitmap_name);
2410 wfree(mask_name);
2412 return (status);
2415 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2417 static Cursor cursor;
2418 int status;
2419 int changed = 0;
2421 again:
2422 if (!WMIsPLArray(value)) {
2423 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2424 entry->key, "cursor specification");
2425 if (!changed) {
2426 value = entry->plvalue;
2427 changed = 1;
2428 wwarning(_("using default \"%s\" instead"), entry->default_value);
2429 goto again;
2431 return (False);
2433 status = parse_cursor(scr, value, &cursor);
2434 if (!status) {
2435 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2436 if (!changed) {
2437 value = entry->plvalue;
2438 changed = 1;
2439 wwarning(_("using default \"%s\" instead"), entry->default_value);
2440 goto again;
2442 return (False);
2444 if (ret) {
2445 *ret = &cursor;
2447 if (addr) {
2448 *(Cursor *) addr = cursor;
2450 return (True);
2453 #undef CURSOR_ID_NONE
2455 /* ---------------- value setting functions --------------- */
2456 static int setJustify(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2458 /* Parameter not used, but tell the compiler that it is ok */
2459 (void) scr;
2460 (void) entry;
2461 (void) tdata;
2462 (void) extra_data;
2464 return REFRESH_WINDOW_TITLE_COLOR;
2467 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2469 /* Parameter not used, but tell the compiler that it is ok */
2470 (void) scr;
2471 (void) entry;
2472 (void) bar;
2473 (void) foo;
2475 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2478 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2480 char *flag = tdata;
2481 long which = (long) extra_data;
2483 /* Parameter not used, but tell the compiler that it is ok */
2484 (void) scr;
2485 (void) entry;
2487 switch (which) {
2488 case WM_DOCK:
2489 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2490 // Drawers require the dock
2491 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || wPreferences.flags.nodock;
2492 break;
2493 case WM_CLIP:
2494 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2495 break;
2496 case WM_DRAWER:
2497 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || *flag;
2498 break;
2499 default:
2500 break;
2502 return 0;
2505 static int setClipMergedInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2507 char *flag = tdata;
2509 /* Parameter not used, but tell the compiler that it is ok */
2510 (void) scr;
2511 (void) entry;
2512 (void) foo;
2514 wPreferences.flags.clip_merged_in_dock = *flag;
2515 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2516 return 0;
2519 static int setWrapAppiconsInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2521 char *flag = tdata;
2523 /* Parameter not used, but tell the compiler that it is ok */
2524 (void) scr;
2525 (void) entry;
2526 (void) foo;
2528 wPreferences.flags.wrap_appicons_in_dock = *flag;
2529 return 0;
2532 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2534 /* Parameter not used, but tell the compiler that it is ok */
2535 (void) entry;
2536 (void) bar;
2537 (void) foo;
2539 if (w_global.workspace.array) {
2540 wWorkspaceForceChange(scr, w_global.workspace.current);
2541 wArrangeIcons(scr, False);
2543 return 0;
2546 static int setIconTile(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2548 Pixmap pixmap;
2549 RImage *img;
2550 WTexture ** texture = tdata;
2551 int reset = 0;
2553 /* Parameter not used, but tell the compiler that it is ok */
2554 (void) foo;
2556 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2557 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2558 ? WREL_ICON : WREL_FLAT);
2559 if (!img) {
2560 wwarning(_("could not render texture for icon background"));
2561 if (!entry->addr)
2562 wTextureDestroy(scr, *texture);
2563 return 0;
2565 RConvertImage(scr->rcontext, img, &pixmap);
2567 if (scr->icon_tile) {
2568 reset = 1;
2569 RReleaseImage(scr->icon_tile);
2570 XFreePixmap(dpy, scr->icon_tile_pixmap);
2573 scr->icon_tile = img;
2575 /* put the icon in the noticeboard hint */
2576 PropSetIconTileHint(scr, img);
2578 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock) {
2579 if (scr->clip_tile) {
2580 RReleaseImage(scr->clip_tile);
2582 scr->clip_tile = wClipMakeTile(img);
2585 if (!wPreferences.flags.nodrawer) {
2586 if (scr->drawer_tile) {
2587 RReleaseImage(scr->drawer_tile);
2589 scr->drawer_tile = wDrawerMakeTile(scr, img);
2592 scr->icon_tile_pixmap = pixmap;
2594 if (scr->def_icon_rimage) {
2595 RReleaseImage(scr->def_icon_rimage);
2596 scr->def_icon_rimage = NULL;
2599 if (scr->icon_back_texture)
2600 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2602 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2604 /* Free the texture as nobody else will use it, nor refer to it. */
2605 if (!entry->addr)
2606 wTextureDestroy(scr, *texture);
2608 return (reset ? REFRESH_ICON_TILE : 0);
2611 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2613 WMFont *font = tdata;
2615 /* Parameter not used, but tell the compiler that it is ok */
2616 (void) entry;
2617 (void) foo;
2619 if (scr->title_font) {
2620 WMReleaseFont(scr->title_font);
2622 scr->title_font = font;
2624 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2627 static int setMenuTitleFont(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_title_font) {
2636 WMReleaseFont(scr->menu_title_font);
2639 scr->menu_title_font = font;
2641 return REFRESH_MENU_TITLE_FONT;
2644 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2646 WMFont *font = tdata;
2648 /* Parameter not used, but tell the compiler that it is ok */
2649 (void) entry;
2650 (void) foo;
2652 if (scr->menu_entry_font) {
2653 WMReleaseFont(scr->menu_entry_font);
2655 scr->menu_entry_font = font;
2657 return REFRESH_MENU_FONT;
2660 static int setIconTitleFont(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->icon_title_font) {
2669 WMReleaseFont(scr->icon_title_font);
2672 scr->icon_title_font = font;
2674 return REFRESH_ICON_FONT;
2677 static int setClipTitleFont(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) entry;
2683 (void) foo;
2685 if (scr->clip_title_font) {
2686 WMReleaseFont(scr->clip_title_font);
2689 scr->clip_title_font = font;
2691 return REFRESH_ICON_FONT;
2694 static int setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2696 WMFont *font = tdata;
2698 /* Parameter not used, but tell the compiler that it is ok */
2699 (void) scr;
2700 (void) entry;
2701 (void) foo;
2703 if (w_global.workspace.font_for_name)
2704 WMReleaseFont(w_global.workspace.font_for_name);
2706 w_global.workspace.font_for_name = font;
2708 return 0;
2711 static int setHightlight(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2713 XColor *color = tdata;
2715 /* Parameter not used, but tell the compiler that it is ok */
2716 (void) entry;
2717 (void) foo;
2719 if (scr->select_color)
2720 WMReleaseColor(scr->select_color);
2722 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2724 wFreeColor(scr, color->pixel);
2726 return REFRESH_MENU_COLOR;
2729 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2731 XColor *color = tdata;
2733 /* Parameter not used, but tell the compiler that it is ok */
2734 (void) entry;
2735 (void) foo;
2737 if (scr->select_text_color)
2738 WMReleaseColor(scr->select_text_color);
2740 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2742 wFreeColor(scr, color->pixel);
2744 return REFRESH_MENU_COLOR;
2747 static int setClipTitleColor(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->clip_title_color[widx])
2756 WMReleaseColor(scr->clip_title_color[widx]);
2758 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2759 wFreeColor(scr, color->pixel);
2761 return REFRESH_ICON_TITLE_COLOR;
2764 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2766 XColor *color = tdata;
2767 long widx = (long) extra_data;
2769 /* Parameter not used, but tell the compiler that it is ok */
2770 (void) entry;
2772 if (scr->window_title_color[widx])
2773 WMReleaseColor(scr->window_title_color[widx]);
2775 scr->window_title_color[widx] =
2776 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2778 wFreeColor(scr, color->pixel);
2780 return REFRESH_WINDOW_TITLE_COLOR;
2783 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2785 XColor *color = tdata;
2787 /* Parameter not used, but tell the compiler that it is ok */
2788 (void) entry;
2789 (void) extra_data;
2791 if (scr->menu_title_color[0])
2792 WMReleaseColor(scr->menu_title_color[0]);
2794 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2796 wFreeColor(scr, color->pixel);
2798 return REFRESH_MENU_TITLE_COLOR;
2801 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2803 XColor *color = tdata;
2805 /* Parameter not used, but tell the compiler that it is ok */
2806 (void) entry;
2807 (void) foo;
2809 if (scr->mtext_color)
2810 WMReleaseColor(scr->mtext_color);
2812 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2814 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2815 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2816 } else {
2817 WMSetColorAlpha(scr->dtext_color, 0xffff);
2820 wFreeColor(scr, color->pixel);
2822 return REFRESH_MENU_COLOR;
2825 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2827 XColor *color = tdata;
2829 /* Parameter not used, but tell the compiler that it is ok */
2830 (void) entry;
2831 (void) foo;
2833 if (scr->dtext_color)
2834 WMReleaseColor(scr->dtext_color);
2836 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2838 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2839 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2840 } else {
2841 WMSetColorAlpha(scr->dtext_color, 0xffff);
2844 wFreeColor(scr, color->pixel);
2846 return REFRESH_MENU_COLOR;
2849 static int setIconTitleColor(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_color)
2858 WMReleaseColor(scr->icon_title_color);
2859 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2861 wFreeColor(scr, color->pixel);
2863 return REFRESH_ICON_TITLE_COLOR;
2866 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2868 XColor *color = tdata;
2870 /* Parameter not used, but tell the compiler that it is ok */
2871 (void) entry;
2872 (void) foo;
2874 if (scr->icon_title_texture) {
2875 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2877 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2879 return REFRESH_ICON_TITLE_BACK;
2882 static int setFrameBorderWidth(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2884 int *value = tdata;
2886 /* Parameter not used, but tell the compiler that it is ok */
2887 (void) entry;
2888 (void) foo;
2890 scr->frame_border_width = *value;
2892 return REFRESH_FRAME_BORDER;
2895 static int setFrameBorderColor(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_border_color)
2904 WMReleaseColor(scr->frame_border_color);
2905 scr->frame_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 setFrameFocusedBorderColor(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_focused_border_color)
2921 WMReleaseColor(scr->frame_focused_border_color);
2922 scr->frame_focused_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2924 wFreeColor(scr, color->pixel);
2926 return REFRESH_FRAME_BORDER;
2929 static int setFrameSelectedBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2931 XColor *color = tdata;
2933 /* Parameter not used, but tell the compiler that it is ok */
2934 (void) entry;
2935 (void) foo;
2937 if (scr->frame_selected_border_color)
2938 WMReleaseColor(scr->frame_selected_border_color);
2939 scr->frame_selected_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2941 wFreeColor(scr, color->pixel);
2943 return REFRESH_FRAME_BORDER;
2946 static void trackDeadProcess(pid_t pid, unsigned int status, void *client_data)
2948 WScreen *scr = (WScreen *) client_data;
2950 /* Parameter not used, but tell the compiler that it is ok */
2951 (void) pid;
2952 (void) status;
2954 close(scr->helper_fd);
2955 scr->helper_fd = 0;
2956 scr->helper_pid = 0;
2957 scr->flags.backimage_helper_launched = 0;
2960 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
2962 WMPropList *value = tdata;
2963 WMPropList *val;
2964 char *str;
2965 int i;
2967 /* Parameter not used, but tell the compiler that it is ok */
2968 (void) entry;
2969 (void) bar;
2971 if (scr->flags.backimage_helper_launched) {
2972 if (WMGetPropListItemCount(value) == 0) {
2973 SendHelperMessage(scr, 'C', 0, NULL);
2974 SendHelperMessage(scr, 'K', 0, NULL);
2976 WMReleasePropList(value);
2977 return 0;
2979 } else {
2980 pid_t pid;
2981 int filedes[2];
2983 if (WMGetPropListItemCount(value) == 0)
2984 return 0;
2986 if (pipe(filedes) < 0) {
2987 werror("pipe() failed:can't set workspace specific background image");
2989 WMReleasePropList(value);
2990 return 0;
2993 pid = fork();
2994 if (pid < 0) {
2995 werror("fork() failed:can't set workspace specific background image");
2996 if (close(filedes[0]) < 0)
2997 werror("could not close pipe");
2998 if (close(filedes[1]) < 0)
2999 werror("could not close pipe");
3001 } else if (pid == 0) {
3002 char *dither;
3004 SetupEnvironment(scr);
3006 if (close(0) < 0)
3007 werror("could not close pipe");
3008 if (dup(filedes[0]) < 0) {
3009 werror("dup() failed:can't set workspace specific background image");
3011 dither = wPreferences.no_dithering ? "-m" : "-d";
3012 if (wPreferences.smooth_workspace_back)
3013 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3014 else
3015 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3016 werror("could not execute wmsetbg");
3017 exit(1);
3018 } else {
3020 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3021 werror("error setting close-on-exec flag");
3023 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3024 werror("error setting close-on-exec flag");
3027 scr->helper_fd = filedes[1];
3028 scr->helper_pid = pid;
3029 scr->flags.backimage_helper_launched = 1;
3031 wAddDeathHandler(pid, trackDeadProcess, scr);
3033 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3038 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3039 val = WMGetFromPLArray(value, i);
3040 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
3041 str = WMGetPropListDescription(val, False);
3043 SendHelperMessage(scr, 'S', i + 1, str);
3045 wfree(str);
3046 } else {
3047 SendHelperMessage(scr, 'U', i + 1, NULL);
3050 sleep(1);
3052 WMReleasePropList(value);
3053 return 0;
3056 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
3058 WMPropList *value = tdata;
3060 /* Parameter not used, but tell the compiler that it is ok */
3061 (void) entry;
3062 (void) bar;
3064 if (scr->flags.backimage_helper_launched) {
3065 char *str;
3067 if (WMGetPropListItemCount(value) == 0) {
3068 SendHelperMessage(scr, 'U', 0, NULL);
3069 } else {
3070 /* set the default workspace background to this one */
3071 str = WMGetPropListDescription(value, False);
3072 if (str) {
3073 SendHelperMessage(scr, 'S', 0, str);
3074 wfree(str);
3075 SendHelperMessage(scr, 'C', w_global.workspace.current + 1, NULL);
3076 } else {
3077 SendHelperMessage(scr, 'U', 0, NULL);
3080 } else if (WMGetPropListItemCount(value) > 0) {
3081 char *command;
3082 char *text;
3083 char *dither;
3084 int len;
3086 text = WMGetPropListDescription(value, False);
3087 len = strlen(text) + 40;
3088 command = wmalloc(len);
3089 dither = wPreferences.no_dithering ? "-m" : "-d";
3090 if (wPreferences.smooth_workspace_back)
3091 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3092 else
3093 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3094 wfree(text);
3095 ExecuteShellCommand(scr, command);
3096 wfree(command);
3098 WMReleasePropList(value);
3100 return 0;
3103 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3105 WTexture **texture = tdata;
3107 /* Parameter not used, but tell the compiler that it is ok */
3108 (void) entry;
3109 (void) foo;
3111 if (scr->widget_texture) {
3112 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3114 scr->widget_texture = *(WTexSolid **) texture;
3116 return 0;
3119 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3121 WTexture **texture = tdata;
3123 /* Parameter not used, but tell the compiler that it is ok */
3124 (void) entry;
3125 (void) foo;
3127 if (scr->window_title_texture[WS_FOCUSED]) {
3128 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3130 scr->window_title_texture[WS_FOCUSED] = *texture;
3132 return REFRESH_WINDOW_TEXTURES;
3135 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3137 WTexture **texture = tdata;
3139 /* Parameter not used, but tell the compiler that it is ok */
3140 (void) entry;
3141 (void) foo;
3143 if (scr->window_title_texture[WS_PFOCUSED]) {
3144 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3146 scr->window_title_texture[WS_PFOCUSED] = *texture;
3148 return REFRESH_WINDOW_TEXTURES;
3151 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3153 WTexture **texture = tdata;
3155 /* Parameter not used, but tell the compiler that it is ok */
3156 (void) entry;
3157 (void) foo;
3159 if (scr->window_title_texture[WS_UNFOCUSED]) {
3160 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3162 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3164 return REFRESH_WINDOW_TEXTURES;
3167 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3169 WTexture **texture = tdata;
3171 /* Parameter not used, but tell the compiler that it is ok */
3172 (void) entry;
3173 (void) foo;
3175 if (scr->resizebar_texture[0]) {
3176 wTextureDestroy(scr, scr->resizebar_texture[0]);
3178 scr->resizebar_texture[0] = *texture;
3180 return REFRESH_WINDOW_TEXTURES;
3183 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3185 WTexture **texture = tdata;
3187 /* Parameter not used, but tell the compiler that it is ok */
3188 (void) entry;
3189 (void) foo;
3191 if (scr->menu_title_texture[0]) {
3192 wTextureDestroy(scr, scr->menu_title_texture[0]);
3194 scr->menu_title_texture[0] = *texture;
3196 return REFRESH_MENU_TITLE_TEXTURE;
3199 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3201 WTexture **texture = tdata;
3203 /* Parameter not used, but tell the compiler that it is ok */
3204 (void) entry;
3205 (void) foo;
3207 if (scr->menu_item_texture) {
3208 wTextureDestroy(scr, scr->menu_item_texture);
3209 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3211 scr->menu_item_texture = *texture;
3213 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3215 return REFRESH_MENU_TEXTURE;
3218 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3220 WShortKey *shortcut = tdata;
3221 WWindow *wwin;
3222 long widx = (long) extra_data;
3224 /* Parameter not used, but tell the compiler that it is ok */
3225 (void) entry;
3227 wKeyBindings[widx] = *shortcut;
3229 wwin = scr->focused_window;
3231 while (wwin != NULL) {
3232 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3234 if (!WFLAGP(wwin, no_bind_keys)) {
3235 wWindowSetKeyGrabs(wwin);
3237 wwin = wwin->prev;
3240 /* do we need to update window menus? */
3241 if (widx >= WKBD_WORKSPACE1 && widx <= WKBD_WORKSPACE10)
3242 return REFRESH_WORKSPACE_MENU;
3243 if (widx == WKBD_LASTWORKSPACE)
3244 return REFRESH_WORKSPACE_MENU;
3245 if (widx >= WKBD_MOVE_WORKSPACE1 && widx <= WKBD_MOVE_WORKSPACE10)
3246 return REFRESH_WORKSPACE_MENU;
3248 return 0;
3251 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3253 /* Parameter not used, but tell the compiler that it is ok */
3254 (void) entry;
3255 (void) bar;
3256 (void) foo;
3258 wScreenUpdateUsableArea(scr);
3259 wArrangeIcons(scr, True);
3261 return 0;
3264 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3266 /* Parameter not used, but tell the compiler that it is ok */
3267 (void) entry;
3268 (void) bar;
3269 (void) foo;
3271 wScreenUpdateUsableArea(scr);
3273 return 0;
3276 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3278 /* Parameter not used, but tell the compiler that it is ok */
3279 (void) scr;
3280 (void) entry;
3281 (void) tdata;
3282 (void) foo;
3284 return REFRESH_MENU_TEXTURE;
3287 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3289 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3291 RCopyArea(img, image, x, y, w, h, 0, 0);
3293 return img;
3296 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3298 WMPropList *array = tdata;
3299 char *path;
3300 RImage *bgimage;
3301 int cwidth, cheight;
3302 struct WPreferences *prefs = foo;
3304 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3305 if (prefs->swtileImage)
3306 RReleaseImage(prefs->swtileImage);
3307 prefs->swtileImage = NULL;
3309 WMReleasePropList(array);
3310 return 0;
3313 switch (WMGetPropListItemCount(array)) {
3314 case 4:
3315 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3316 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3317 break;
3318 } else
3319 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3321 if (!path) {
3322 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3323 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3324 } else {
3325 bgimage = RLoadImage(scr->rcontext, path, 0);
3326 if (!bgimage) {
3327 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3328 wfree(path);
3329 } else {
3330 wfree(path);
3332 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3333 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3335 if (cwidth <= 0 || cheight <= 0 ||
3336 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3337 wwarning(_("Invalid split sizes for switch panel back image."));
3338 else {
3339 int i;
3340 int swidth, theight;
3341 for (i = 0; i < 9; i++) {
3342 if (prefs->swbackImage[i])
3343 RReleaseImage(prefs->swbackImage[i]);
3344 prefs->swbackImage[i] = NULL;
3346 swidth = (bgimage->width - cwidth) / 2;
3347 theight = (bgimage->height - cheight) / 2;
3349 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3350 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3351 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3352 swidth, theight);
3354 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3355 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3356 cwidth, cheight);
3357 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3358 swidth, cheight);
3360 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3361 swidth, theight);
3362 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3363 cwidth, theight);
3364 prefs->swbackImage[8] =
3365 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3366 theight);
3368 // check if anything failed
3369 for (i = 0; i < 9; i++) {
3370 if (!prefs->swbackImage[i]) {
3371 for (; i >= 0; --i) {
3372 RReleaseImage(prefs->swbackImage[i]);
3373 prefs->swbackImage[i] = NULL;
3375 break;
3379 RReleaseImage(bgimage);
3383 case 1:
3384 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3385 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3386 break;
3387 } else
3388 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3390 if (!path) {
3391 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3392 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3393 } else {
3394 if (prefs->swtileImage)
3395 RReleaseImage(prefs->swtileImage);
3397 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3398 if (!prefs->swtileImage) {
3399 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3401 wfree(path);
3403 break;
3405 default:
3406 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3407 break;
3410 WMReleasePropList(array);
3412 return 0;
3415 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3417 WMPropList *array = tdata;
3418 int i;
3419 struct WPreferences *prefs = foo;
3421 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3422 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3423 WMReleasePropList(array);
3424 return 0;
3427 DestroyWindowMenu(scr);
3429 for (i = 0; i < 7; i++) {
3430 if (prefs->modifier_labels[i])
3431 wfree(prefs->modifier_labels[i]);
3433 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3434 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3435 } else {
3436 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3437 prefs->modifier_labels[i] = NULL;
3441 WMReleasePropList(array);
3443 return 0;
3446 static int setDoubleClick(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
3448 int *value = tdata;
3450 /* Parameter not used, but tell the compiler that it is ok */
3451 (void) entry;
3452 (void) scr;
3454 if (*value <= 0)
3455 *(int *)foo = 1;
3457 W_setconf_doubleClickDelay(*value);
3459 return 0;
3462 static int setCursor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3464 Cursor *cursor = tdata;
3465 long widx = (long) extra_data;
3467 /* Parameter not used, but tell the compiler that it is ok */
3468 (void) entry;
3470 if (wPreferences.cursor[widx] != None) {
3471 XFreeCursor(dpy, wPreferences.cursor[widx]);
3474 wPreferences.cursor[widx] = *cursor;
3476 if (widx == WCUR_ROOT && *cursor != None) {
3477 XDefineCursor(dpy, scr->root_win, *cursor);
3480 return 0;