apercu: Make preview size a configuration option
[wmaker-crm.git] / src / defaults.c
blob5e305c90e1dd0fabdde32e52b6b4a380cc678350
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <strings.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifndef PATH_MAX
40 #define PATH_MAX DEFAULT_PATH_MAX
41 #endif
43 #include <X11/Xlib.h>
44 #include <X11/Xutil.h>
45 #include <X11/keysym.h>
47 #include <wraster.h>
49 #include "WindowMaker.h"
50 #include "framewin.h"
51 #include "window.h"
52 #include "texture.h"
53 #include "screen.h"
54 #include "resources.h"
55 #include "defaults.h"
56 #include "keybind.h"
57 #include "xmodifier.h"
58 #include "icon.h"
59 #include "main.h"
60 #include "actions.h"
61 #include "dock.h"
62 #include "workspace.h"
63 #include "properties.h"
64 #include "misc.h"
65 #include "event.h"
66 #include "winmenu.h"
68 #define MAX_SHORTCUT_LENGTH 32
70 #ifndef GLOBAL_DEFAULTS_SUBDIR
71 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
72 #endif
75 typedef struct _WDefaultEntry WDefaultEntry;
76 typedef int (WDECallbackConvert) (WScreen *scr, WDefaultEntry *entry, WMPropList *plvalue, void *addr, void **tdata);
77 typedef int (WDECallbackUpdate) (WScreen *scr, WDefaultEntry *entry, void *tdata, void *extra_data);
79 struct _WDefaultEntry {
80 const char *key;
81 const char *default_value;
82 void *extra_data;
83 void *addr;
84 WDECallbackConvert *convert;
85 WDECallbackUpdate *update;
86 WMPropList *plkey;
87 WMPropList *plvalue; /* default value */
90 /* used to map strings to integers */
91 typedef struct {
92 const char *string;
93 short value;
94 char is_alias;
95 } WOptionEnumeration;
97 /* type converters */
98 static WDECallbackConvert getBool;
99 static WDECallbackConvert getInt;
100 static WDECallbackConvert getCoord;
101 static WDECallbackConvert getPathList;
102 static WDECallbackConvert getEnum;
103 static WDECallbackConvert getTexture;
104 static WDECallbackConvert getWSBackground;
105 static WDECallbackConvert getWSSpecificBackground;
106 static WDECallbackConvert getFont;
107 static WDECallbackConvert getColor;
108 static WDECallbackConvert getKeybind;
109 static WDECallbackConvert getModMask;
110 static WDECallbackConvert getPropList;
112 /* value setting functions */
113 static WDECallbackUpdate setJustify;
114 static WDECallbackUpdate setClearance;
115 static WDECallbackUpdate setIfDockPresent;
116 static WDECallbackUpdate setClipMergedInDock;
117 static WDECallbackUpdate setWrapAppiconsInDock;
118 static WDECallbackUpdate setStickyIcons;
119 static WDECallbackUpdate setWidgetColor;
120 static WDECallbackUpdate setIconTile;
121 static WDECallbackUpdate setWinTitleFont;
122 static WDECallbackUpdate setMenuTitleFont;
123 static WDECallbackUpdate setMenuTextFont;
124 static WDECallbackUpdate setIconTitleFont;
125 static WDECallbackUpdate setIconTitleColor;
126 static WDECallbackUpdate setIconTitleBack;
127 static WDECallbackUpdate setFrameBorderWidth;
128 static WDECallbackUpdate setFrameBorderColor;
129 static WDECallbackUpdate setFrameFocusedBorderColor;
130 static WDECallbackUpdate setFrameSelectedBorderColor;
131 static WDECallbackUpdate setLargeDisplayFont;
132 static WDECallbackUpdate setWTitleColor;
133 static WDECallbackUpdate setFTitleBack;
134 static WDECallbackUpdate setPTitleBack;
135 static WDECallbackUpdate setUTitleBack;
136 static WDECallbackUpdate setResizebarBack;
137 static WDECallbackUpdate setWorkspaceBack;
138 static WDECallbackUpdate setWorkspaceSpecificBack;
139 static WDECallbackUpdate setMenuTitleColor;
140 static WDECallbackUpdate setMenuTextColor;
141 static WDECallbackUpdate setMenuDisabledColor;
142 static WDECallbackUpdate setMenuTitleBack;
143 static WDECallbackUpdate setMenuTextBack;
144 static WDECallbackUpdate setHightlight;
145 static WDECallbackUpdate setHightlightText;
146 static WDECallbackUpdate setKeyGrab;
147 static WDECallbackUpdate setDoubleClick;
148 static WDECallbackUpdate setIconPosition;
150 static WDECallbackUpdate setClipTitleFont;
151 static WDECallbackUpdate setClipTitleColor;
153 static WDECallbackUpdate setMenuStyle;
154 static WDECallbackUpdate setSwPOptions;
155 static WDECallbackUpdate updateUsableArea;
157 static WDECallbackUpdate setModifierKeyLabels;
159 static WDECallbackConvert getCursor;
160 static WDECallbackUpdate setCursor;
163 * Tables to convert strings to enumeration values.
164 * Values stored are char
167 /* WARNING: sum of length of all value strings must not exceed
168 * this value */
169 #define TOTAL_VALUES_LENGTH 80
171 #define REFRESH_WINDOW_TEXTURES (1<<0)
172 #define REFRESH_MENU_TEXTURE (1<<1)
173 #define REFRESH_MENU_FONT (1<<2)
174 #define REFRESH_MENU_COLOR (1<<3)
175 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
176 #define REFRESH_MENU_TITLE_FONT (1<<5)
177 #define REFRESH_MENU_TITLE_COLOR (1<<6)
178 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
179 #define REFRESH_WINDOW_FONT (1<<8)
180 #define REFRESH_ICON_TILE (1<<9)
181 #define REFRESH_ICON_FONT (1<<10)
182 #define REFRESH_WORKSPACE_BACK (1<<11)
184 #define REFRESH_BUTTON_IMAGES (1<<12)
186 #define REFRESH_ICON_TITLE_COLOR (1<<13)
187 #define REFRESH_ICON_TITLE_BACK (1<<14)
189 #define REFRESH_WORKSPACE_MENU (1<<15)
191 #define REFRESH_FRAME_BORDER REFRESH_MENU_FONT|REFRESH_WINDOW_FONT
193 static WOptionEnumeration seFocusModes[] = {
194 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
195 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
196 {NULL, 0, 0}
199 static WOptionEnumeration seTitlebarModes[] = {
200 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
201 {"next", TS_NEXT, 0}, {NULL, 0, 0}
204 static WOptionEnumeration seColormapModes[] = {
205 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
206 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
207 {NULL, 0, 0}
210 static WOptionEnumeration sePlacements[] = {
211 {"Auto", WPM_AUTO, 0},
212 {"Smart", WPM_SMART, 0},
213 {"Cascade", WPM_CASCADE, 0},
214 {"Random", WPM_RANDOM, 0},
215 {"Manual", WPM_MANUAL, 0},
216 {"Center", WPM_CENTER, 0},
217 {NULL, 0, 0}
220 static WOptionEnumeration seGeomDisplays[] = {
221 {"None", WDIS_NONE, 0},
222 {"Center", WDIS_CENTER, 0},
223 {"Corner", WDIS_TOPLEFT, 0},
224 {"Floating", WDIS_FRAME_CENTER, 0},
225 {"Line", WDIS_NEW, 0},
226 {NULL, 0, 0}
229 static WOptionEnumeration seSpeeds[] = {
230 {"UltraFast", SPEED_ULTRAFAST, 0},
231 {"Fast", SPEED_FAST, 0},
232 {"Medium", SPEED_MEDIUM, 0},
233 {"Slow", SPEED_SLOW, 0},
234 {"UltraSlow", SPEED_ULTRASLOW, 0},
235 {NULL, 0, 0}
238 static WOptionEnumeration seMouseButtonActions[] = {
239 {"None", WA_NONE, 0},
240 {"SelectWindows", WA_SELECT_WINDOWS, 0},
241 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
242 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
243 {NULL, 0, 0}
246 static WOptionEnumeration seMouseWheelActions[] = {
247 {"None", WA_NONE, 0},
248 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
249 {NULL, 0, 0}
252 static WOptionEnumeration seIconificationStyles[] = {
253 {"Zoom", WIS_ZOOM, 0},
254 {"Twist", WIS_TWIST, 0},
255 {"Flip", WIS_FLIP, 0},
256 {"None", WIS_NONE, 0},
257 {"random", WIS_RANDOM, 0},
258 {NULL, 0, 0}
261 static WOptionEnumeration seJustifications[] = {
262 {"Left", WTJ_LEFT, 0},
263 {"Center", WTJ_CENTER, 0},
264 {"Right", WTJ_RIGHT, 0},
265 {NULL, 0, 0}
268 static WOptionEnumeration seIconPositions[] = {
269 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
270 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
271 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
272 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
273 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
274 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
275 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
276 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
277 {NULL, 0, 0}
280 static WOptionEnumeration seMenuStyles[] = {
281 {"normal", MS_NORMAL, 0},
282 {"singletexture", MS_SINGLE_TEXTURE, 0},
283 {"flat", MS_FLAT, 0},
284 {NULL, 0, 0}
287 static WOptionEnumeration seDisplayPositions[] = {
288 {"none", WD_NONE, 0},
289 {"center", WD_CENTER, 0},
290 {"top", WD_TOP, 0},
291 {"bottom", WD_BOTTOM, 0},
292 {"topleft", WD_TOPLEFT, 0},
293 {"topright", WD_TOPRIGHT, 0},
294 {"bottomleft", WD_BOTTOMLEFT, 0},
295 {"bottomright", WD_BOTTOMRIGHT, 0},
296 {NULL, 0, 0}
299 static WOptionEnumeration seWorkspaceBorder[] = {
300 {"None", WB_NONE, 0},
301 {"LeftRight", WB_LEFTRIGHT, 0},
302 {"TopBottom", WB_TOPBOTTOM, 0},
303 {"AllDirections", WB_ALLDIRS, 0},
304 {NULL, 0, 0}
308 * ALL entries in the tables bellow, NEED to have a default value
309 * defined, and this value needs to be correct.
312 /* these options will only affect the window manager on startup
314 * static defaults can't access the screen data, because it is
315 * created after these defaults are read
317 WDefaultEntry staticOptionList[] = {
319 {"ColormapSize", "4", NULL,
320 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
321 {"DisableDithering", "NO", NULL,
322 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
323 {"IconSize", "64", NULL,
324 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
325 {"ModifierKey", "Mod1", NULL,
326 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
327 {"DisableWSMouseActions", "NO", NULL,
328 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
329 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
330 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
331 {"NewStyle", "new", seTitlebarModes,
332 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
333 {"DisableDock", "NO", (void *)WM_DOCK,
334 NULL, getBool, setIfDockPresent, NULL, NULL},
335 {"DisableClip", "NO", (void *)WM_CLIP,
336 NULL, getBool, setIfDockPresent, NULL, NULL},
337 {"DisableDrawers", "NO", (void *)WM_DRAWER,
338 NULL, getBool, setIfDockPresent, NULL, NULL},
339 {"ClipMergedInDock", "NO", NULL,
340 NULL, getBool, setClipMergedInDock, NULL, NULL},
341 {"DisableMiniwindows", "NO", NULL,
342 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
345 #define NUM2STRING_(x) #x
346 #define NUM2STRING(x) NUM2STRING_(x)
348 WDefaultEntry optionList[] = {
350 /* dynamic options */
352 {"IconPosition", "blh", seIconPositions,
353 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
354 {"IconificationStyle", "Zoom", seIconificationStyles,
355 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
356 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
357 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
358 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
359 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
360 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
361 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
362 {"MouseWheelAction", "None", seMouseWheelActions,
363 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
364 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
365 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
366 {"IconPath", DEF_ICON_PATHS, NULL,
367 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
368 {"ColormapMode", "auto", seColormapModes,
369 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
370 {"AutoFocus", "NO", NULL,
371 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
372 {"RaiseDelay", "0", NULL,
373 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
374 {"CirculateRaise", "NO", NULL,
375 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
376 {"Superfluous", "NO", NULL,
377 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
378 {"AdvanceToNewWorkspace", "NO", NULL,
379 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
380 {"CycleWorkspaces", "NO", NULL,
381 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
382 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
383 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
384 {"WorkspaceBorder", "None", seWorkspaceBorder,
385 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
386 {"WorkspaceBorderSize", "0", NULL,
387 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
388 {"StickyIcons", "NO", NULL,
389 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
390 {"SaveSessionOnExit", "NO", NULL,
391 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
392 {"WrapMenus", "NO", NULL,
393 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
394 {"ScrollableMenus", "NO", NULL,
395 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
396 {"MenuScrollSpeed", "medium", seSpeeds,
397 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
398 {"IconSlideSpeed", "medium", seSpeeds,
399 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
400 {"ShadeSpeed", "medium", seSpeeds,
401 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
402 {"BounceAppIconsWhenUrgent", "YES", NULL,
403 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
404 {"RaiseAppIconsWhenBouncing", "NO", NULL,
405 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
406 {"DoNotMakeAppIconsBounce", "NO", NULL,
407 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
408 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
409 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
410 {"ClipAutoraiseDelay", "600", NULL,
411 &wPreferences.clip_auto_raise_delay, getInt, NULL, NULL, NULL},
412 {"ClipAutolowerDelay", "1000", NULL,
413 &wPreferences.clip_auto_lower_delay, getInt, NULL, NULL, NULL},
414 {"ClipAutoexpandDelay", "600", NULL,
415 &wPreferences.clip_auto_expand_delay, getInt, NULL, NULL, NULL},
416 {"ClipAutocollapseDelay", "1000", NULL,
417 &wPreferences.clip_auto_collapse_delay, getInt, NULL, NULL, NULL},
418 {"WrapAppiconsInDock", "YES", NULL,
419 NULL, getBool, setWrapAppiconsInDock, NULL, NULL},
420 {"AlignSubmenus", "NO", NULL,
421 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
422 {"ViKeyMenus", "NO", NULL,
423 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
424 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
425 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
426 {"WindowPlacement", "auto", sePlacements,
427 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
428 {"IgnoreFocusClick", "NO", NULL,
429 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
430 {"UseSaveUnders", "NO", NULL,
431 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
432 {"OpaqueMove", "NO", NULL,
433 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
434 {"OpaqueResize", "NO", NULL,
435 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
436 {"OpaqueMoveResizeKeyboard", "NO", NULL,
437 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
438 {"DisableAnimations", "NO", NULL,
439 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
440 {"DontLinkWorkspaces", "NO", NULL,
441 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
442 {"HighlightActiveApp", "YES", NULL,
443 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
444 {"AutoArrangeIcons", "NO", NULL,
445 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
446 {"NoWindowOverDock", "NO", NULL,
447 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
448 {"NoWindowOverIcons", "NO", NULL,
449 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
450 {"WindowPlaceOrigin", "(0, 0)", NULL,
451 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
452 {"ResizeDisplay", "corner", seGeomDisplays,
453 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
454 {"MoveDisplay", "corner", seGeomDisplays,
455 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
456 {"DontConfirmKill", "NO", NULL,
457 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
458 {"WindowTitleBalloons", "NO", NULL,
459 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
460 {"MiniwindowTitleBalloons", "NO", NULL,
461 &wPreferences.miniwin_title_balloon, getBool, NULL, NULL, NULL},
462 {"MiniwindowApercuBalloons", "NO", NULL,
463 &wPreferences.miniwin_apercu_balloon, getBool, NULL, NULL, NULL},
464 {"AppIconBalloons", "NO", NULL,
465 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
466 {"HelpBalloons", "NO", NULL,
467 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
468 {"EdgeResistance", "30", NULL,
469 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
470 {"ResizeIncrement", "0", NULL,
471 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
472 {"Attraction", "NO", NULL,
473 &wPreferences.attract, getBool, NULL, NULL, NULL},
474 {"DisableBlinking", "NO", NULL,
475 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
476 {"SingleClickLaunch", "NO", NULL,
477 &wPreferences.single_click, getBool, NULL, NULL, NULL},
478 {"StrictWindozeCycle", "YES", NULL,
479 &wPreferences.strict_windoze_cycle, getBool, NULL, NULL, NULL},
480 {"SwitchPanelOnlyOpen", "NO", NULL,
481 &wPreferences.panel_only_open, getBool, NULL, NULL, NULL},
482 {"ApercuSize", "2", NULL,
483 &wPreferences.apercu_size, getInt, NULL, NULL, NULL},
485 /* style options */
487 {"MenuStyle", "normal", seMenuStyles,
488 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
489 {"WidgetColor", "(solid, gray)", NULL,
490 NULL, getTexture, setWidgetColor, NULL, NULL},
491 {"WorkspaceSpecificBack", "()", NULL,
492 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
493 /* WorkspaceBack must come after WorkspaceSpecificBack or
494 * WorkspaceBack wont know WorkspaceSpecificBack was also
495 * specified and 2 copies of wmsetbg will be launched */
496 {"WorkspaceBack", "(solid, black)", NULL,
497 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
498 {"SmoothWorkspaceBack", "NO", NULL,
499 NULL, getBool, NULL, NULL, NULL},
500 {"IconBack", "(solid, gray)", NULL,
501 NULL, getTexture, setIconTile, NULL, NULL},
502 {"TitleJustify", "center", seJustifications,
503 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
504 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
505 NULL, getFont, setWinTitleFont, NULL, NULL},
506 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
507 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
508 {"WindowTitleMinHeight", "0", NULL,
509 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
510 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
511 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
512 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
513 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
514 {"MenuTitleMinHeight", "0", NULL,
515 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
516 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
517 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
518 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
519 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
520 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
521 NULL, getFont, setMenuTitleFont, NULL, NULL},
522 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
523 NULL, getFont, setMenuTextFont, NULL, NULL},
524 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
525 NULL, getFont, setIconTitleFont, NULL, NULL},
526 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
527 NULL, getFont, setClipTitleFont, NULL, NULL},
528 {"ShowClipTitle", "YES", NULL,
529 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
530 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
531 NULL, getFont, setLargeDisplayFont, NULL, NULL},
532 {"HighlightColor", "white", NULL,
533 NULL, getColor, setHightlight, NULL, NULL},
534 {"HighlightTextColor", "black", NULL,
535 NULL, getColor, setHightlightText, NULL, NULL},
536 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
537 NULL, getColor, setClipTitleColor, NULL, NULL},
538 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
539 NULL, getColor, setClipTitleColor, NULL, NULL},
540 {"FTitleColor", "white", (void *)WS_FOCUSED,
541 NULL, getColor, setWTitleColor, NULL, NULL},
542 {"PTitleColor", "white", (void *)WS_PFOCUSED,
543 NULL, getColor, setWTitleColor, NULL, NULL},
544 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
545 NULL, getColor, setWTitleColor, NULL, NULL},
546 {"FTitleBack", "(solid, black)", NULL,
547 NULL, getTexture, setFTitleBack, NULL, NULL},
548 {"PTitleBack", "(solid, \"#616161\")", NULL,
549 NULL, getTexture, setPTitleBack, NULL, NULL},
550 {"UTitleBack", "(solid, gray)", NULL,
551 NULL, getTexture, setUTitleBack, NULL, NULL},
552 {"ResizebarBack", "(solid, gray)", NULL,
553 NULL, getTexture, setResizebarBack, NULL, NULL},
554 {"MenuTitleColor", "white", NULL,
555 NULL, getColor, setMenuTitleColor, NULL, NULL},
556 {"MenuTextColor", "black", NULL,
557 NULL, getColor, setMenuTextColor, NULL, NULL},
558 {"MenuDisabledColor", "\"#616161\"", NULL,
559 NULL, getColor, setMenuDisabledColor, NULL, NULL},
560 {"MenuTitleBack", "(solid, black)", NULL,
561 NULL, getTexture, setMenuTitleBack, NULL, NULL},
562 {"MenuTextBack", "(solid, gray)", NULL,
563 NULL, getTexture, setMenuTextBack, NULL, NULL},
564 {"IconTitleColor", "white", NULL,
565 NULL, getColor, setIconTitleColor, NULL, NULL},
566 {"IconTitleBack", "black", NULL,
567 NULL, getColor, setIconTitleBack, NULL, NULL},
568 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
569 NULL, getPropList, setSwPOptions, NULL, NULL},
570 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
571 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
572 {"FrameBorderWidth", "1", NULL,
573 NULL, getInt, setFrameBorderWidth, NULL, NULL},
574 {"FrameBorderColor", "black", NULL,
575 NULL, getColor, setFrameBorderColor, NULL, NULL},
576 {"FrameFocusedBorderColor", "black", NULL,
577 NULL, getColor, setFrameFocusedBorderColor, NULL, NULL},
578 {"FrameSelectedBorderColor", "white", NULL,
579 NULL, getColor, setFrameSelectedBorderColor, NULL, NULL},
581 /* keybindings */
583 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
584 NULL, getKeybind, setKeyGrab, NULL, NULL},
585 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
586 NULL, getKeybind, setKeyGrab, NULL, NULL},
587 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
588 NULL, getKeybind, setKeyGrab, NULL, NULL},
589 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
590 NULL, getKeybind, setKeyGrab, NULL, NULL},
591 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
592 NULL, getKeybind, setKeyGrab, NULL, NULL},
593 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
594 NULL, getKeybind, setKeyGrab, NULL, NULL},
595 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
596 NULL, getKeybind, setKeyGrab, NULL, NULL },
597 {"HideKey", "None", (void *)WKBD_HIDE,
598 NULL, getKeybind, setKeyGrab, NULL, NULL},
599 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
600 NULL, getKeybind, setKeyGrab, NULL, NULL},
601 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
602 NULL, getKeybind, setKeyGrab, NULL, NULL},
603 {"CloseKey", "None", (void *)WKBD_CLOSE,
604 NULL, getKeybind, setKeyGrab, NULL, NULL},
605 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
606 NULL, getKeybind, setKeyGrab, NULL, NULL},
607 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
608 NULL, getKeybind, setKeyGrab, NULL, NULL},
609 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
610 NULL, getKeybind, setKeyGrab, NULL, NULL},
611 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
612 NULL, getKeybind, setKeyGrab, NULL, NULL},
613 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
614 NULL, getKeybind, setKeyGrab, NULL, NULL},
615 {"THMaximizeKey", "None", (void*)WKBD_THMAXIMIZE,
616 NULL, getKeybind, setKeyGrab, NULL, NULL},
617 {"BHMaximizeKey", "None", (void*)WKBD_BHMAXIMIZE,
618 NULL, getKeybind, setKeyGrab, NULL, NULL},
619 {"LTCMaximizeKey", "None", (void*)WKBD_LTCMAXIMIZE,
620 NULL, getKeybind, setKeyGrab, NULL, NULL},
621 {"RTCMaximizeKey", "None", (void*)WKBD_RTCMAXIMIZE,
622 NULL, getKeybind, setKeyGrab, NULL, NULL},
623 {"LBCMaximizeKey", "None", (void*)WKBD_LBCMAXIMIZE,
624 NULL, getKeybind, setKeyGrab, NULL, NULL},
625 {"RBCMaximizeKey", "None", (void*)WKBD_RBCMAXIMIZE,
626 NULL, getKeybind, setKeyGrab, NULL, NULL},
627 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
628 NULL, getKeybind, setKeyGrab, NULL, NULL},
629 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
630 NULL, getKeybind, setKeyGrab, NULL, NULL},
631 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
632 NULL, getKeybind, setKeyGrab, NULL, NULL},
633 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
634 NULL, getKeybind, setKeyGrab, NULL, NULL},
635 {"ShadeKey", "None", (void *)WKBD_SHADE,
636 NULL, getKeybind, setKeyGrab, NULL, NULL},
637 {"SelectKey", "None", (void *)WKBD_SELECT,
638 NULL, getKeybind, setKeyGrab, NULL, NULL},
639 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
640 NULL, getKeybind, setKeyGrab, NULL, NULL},
641 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
642 NULL, getKeybind, setKeyGrab, NULL, NULL},
643 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
644 NULL, getKeybind, setKeyGrab, NULL, NULL},
645 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
646 NULL, getKeybind, setKeyGrab, NULL, NULL},
647 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
648 NULL, getKeybind, setKeyGrab, NULL, NULL},
649 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
650 NULL, getKeybind, setKeyGrab, NULL, NULL},
651 {"LastWorkspaceKey", "None", (void *)WKBD_LASTWORKSPACE,
652 NULL, getKeybind, setKeyGrab, NULL, NULL},
653 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
654 NULL, getKeybind, setKeyGrab, NULL, NULL},
655 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
656 NULL, getKeybind, setKeyGrab, NULL, NULL},
657 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
658 NULL, getKeybind, setKeyGrab, NULL, NULL},
659 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
660 NULL, getKeybind, setKeyGrab, NULL, NULL},
661 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
662 NULL, getKeybind, setKeyGrab, NULL, NULL},
663 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
664 NULL, getKeybind, setKeyGrab, NULL, NULL},
665 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
666 NULL, getKeybind, setKeyGrab, NULL, NULL},
667 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
668 NULL, getKeybind, setKeyGrab, NULL, NULL},
669 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
670 NULL, getKeybind, setKeyGrab, NULL, NULL},
671 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
672 NULL, getKeybind, setKeyGrab, NULL, NULL},
673 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
674 NULL, getKeybind, setKeyGrab, NULL, NULL},
675 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
676 NULL, getKeybind, setKeyGrab, NULL, NULL},
677 {"MoveToWorkspace1Key", "None", (void *)WKBD_MOVE_WORKSPACE1,
678 NULL, getKeybind, setKeyGrab, NULL, NULL},
679 {"MoveToWorkspace2Key", "None", (void *)WKBD_MOVE_WORKSPACE2,
680 NULL, getKeybind, setKeyGrab, NULL, NULL},
681 {"MoveToWorkspace3Key", "None", (void *)WKBD_MOVE_WORKSPACE3,
682 NULL, getKeybind, setKeyGrab, NULL, NULL},
683 {"MoveToWorkspace4Key", "None", (void *)WKBD_MOVE_WORKSPACE4,
684 NULL, getKeybind, setKeyGrab, NULL, NULL},
685 {"MoveToWorkspace5Key", "None", (void *)WKBD_MOVE_WORKSPACE5,
686 NULL, getKeybind, setKeyGrab, NULL, NULL},
687 {"MoveToWorkspace6Key", "None", (void *)WKBD_MOVE_WORKSPACE6,
688 NULL, getKeybind, setKeyGrab, NULL, NULL},
689 {"MoveToWorkspace7Key", "None", (void *)WKBD_MOVE_WORKSPACE7,
690 NULL, getKeybind, setKeyGrab, NULL, NULL},
691 {"MoveToWorkspace8Key", "None", (void *)WKBD_MOVE_WORKSPACE8,
692 NULL, getKeybind, setKeyGrab, NULL, NULL},
693 {"MoveToWorkspace9Key", "None", (void *)WKBD_MOVE_WORKSPACE9,
694 NULL, getKeybind, setKeyGrab, NULL, NULL},
695 {"MoveToWorkspace10Key", "None", (void *)WKBD_MOVE_WORKSPACE10,
696 NULL, getKeybind, setKeyGrab, NULL, NULL},
697 {"MoveToNextWorkspaceKey", "None", (void *)WKBD_MOVE_NEXTWORKSPACE,
698 NULL, getKeybind, setKeyGrab, NULL, NULL},
699 {"MoveToPrevWorkspaceKey", "None", (void *)WKBD_MOVE_PREVWORKSPACE,
700 NULL, getKeybind, setKeyGrab, NULL, NULL},
701 {"MoveToLastWorkspaceKey", "None", (void *)WKBD_MOVE_LASTWORKSPACE,
702 NULL, getKeybind, setKeyGrab, NULL, NULL},
703 {"MoveToNextWorkspaceLayerKey", "None", (void *)WKBD_MOVE_NEXTWSLAYER,
704 NULL, getKeybind, setKeyGrab, NULL, NULL},
705 {"MoveToPrevWorkspaceLayerKey", "None", (void *)WKBD_MOVE_PREVWSLAYER,
706 NULL, getKeybind, setKeyGrab, NULL, NULL},
707 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
708 NULL, getKeybind, setKeyGrab, NULL, NULL},
709 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
710 NULL, getKeybind, setKeyGrab, NULL, NULL},
711 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
712 NULL, getKeybind, setKeyGrab, NULL, NULL},
713 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
714 NULL, getKeybind, setKeyGrab, NULL, NULL},
715 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
716 NULL, getKeybind, setKeyGrab, NULL, NULL},
717 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
718 NULL, getKeybind, setKeyGrab, NULL, NULL},
719 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
720 NULL, getKeybind, setKeyGrab, NULL, NULL},
721 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
722 NULL, getKeybind, setKeyGrab, NULL, NULL},
723 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
724 NULL, getKeybind, setKeyGrab, NULL, NULL},
725 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
726 NULL, getKeybind, setKeyGrab, NULL, NULL},
727 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
728 NULL, getKeybind, setKeyGrab, NULL, NULL},
729 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
730 NULL, getKeybind, setKeyGrab, NULL, NULL},
731 {"RunKey", "None", (void *)WKBD_RUN,
732 NULL, getKeybind, setKeyGrab, NULL, NULL},
734 #ifdef KEEP_XKB_LOCK_STATUS
735 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
736 NULL, getKeybind, setKeyGrab, NULL, NULL},
737 {"KbdModeLock", "NO", NULL,
738 &wPreferences.modelock, getBool, NULL, NULL, NULL},
739 #endif /* KEEP_XKB_LOCK_STATUS */
741 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
742 NULL, getCursor, setCursor, NULL, NULL},
743 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
744 NULL, getCursor, setCursor, NULL, NULL},
745 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
746 NULL, getCursor, setCursor, NULL, NULL},
747 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
748 NULL, getCursor, setCursor, NULL, NULL},
749 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
750 NULL, getCursor, setCursor, NULL, NULL},
751 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
752 NULL, getCursor, setCursor, NULL, NULL},
753 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
754 NULL, getCursor, setCursor, NULL, NULL},
755 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
756 NULL, getCursor, setCursor, NULL, NULL},
757 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
758 NULL, getCursor, setCursor, NULL, NULL},
759 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
760 NULL, getCursor, setCursor, NULL, NULL},
761 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
762 NULL, getCursor, setCursor, NULL, NULL},
763 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
764 NULL, getCursor, setCursor, NULL, NULL},
765 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
766 NULL, getCursor, setCursor, NULL, NULL},
767 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
768 NULL, getCursor, setCursor, NULL, NULL},
769 {"DialogHistoryLines", "500", NULL,
770 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
771 {"CycleActiveHeadOnly", "NO", NULL,
772 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL},
773 {"CycleIgnoreMinimized", "NO", NULL,
774 &wPreferences.cycle_ignore_minimized, getBool, NULL, NULL, NULL}
777 static void initDefaults(void)
779 unsigned int i;
780 WDefaultEntry *entry;
782 WMPLSetCaseSensitive(False);
784 for (i = 0; i < wlengthof(optionList); i++) {
785 entry = &optionList[i];
787 entry->plkey = WMCreatePLString(entry->key);
788 if (entry->default_value)
789 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
790 else
791 entry->plvalue = NULL;
794 for (i = 0; i < wlengthof(staticOptionList); i++) {
795 entry = &staticOptionList[i];
797 entry->plkey = WMCreatePLString(entry->key);
798 if (entry->default_value)
799 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
800 else
801 entry->plvalue = NULL;
805 static WMPropList *readGlobalDomain(const char *domainName, Bool requireDictionary)
807 WMPropList *globalDict = NULL;
808 char path[PATH_MAX];
809 struct stat stbuf;
811 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
812 if (stat(path, &stbuf) >= 0) {
813 globalDict = WMReadPropListFromFile(path);
814 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
815 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
816 WMReleasePropList(globalDict);
817 globalDict = NULL;
818 } else if (!globalDict) {
819 wwarning(_("could not load domain %s from global defaults database"), domainName);
823 return globalDict;
826 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
827 static void prependMenu(WMPropList * destarr, WMPropList * array)
829 WMPropList *item;
830 int i;
832 for (i = 0; i < WMGetPropListItemCount(array); i++) {
833 item = WMGetFromPLArray(array, i);
834 if (item)
835 WMInsertInPLArray(destarr, i + 1, item);
839 static void appendMenu(WMPropList * destarr, WMPropList * array)
841 WMPropList *item;
842 int i;
844 for (i = 0; i < WMGetPropListItemCount(array); i++) {
845 item = WMGetFromPLArray(array, i);
846 if (item)
847 WMAddToPLArray(destarr, item);
850 #endif
852 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
854 WMPropList *menu = menuDomain->dictionary;
855 WMPropList *submenu;
857 if (!menu || !WMIsPLArray(menu))
858 return;
860 #ifdef GLOBAL_PREAMBLE_MENU_FILE
861 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
863 if (submenu && !WMIsPLArray(submenu)) {
864 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
865 WMReleasePropList(submenu);
866 submenu = NULL;
868 if (submenu) {
869 prependMenu(menu, submenu);
870 WMReleasePropList(submenu);
872 #endif
874 #ifdef GLOBAL_EPILOGUE_MENU_FILE
875 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
877 if (submenu && !WMIsPLArray(submenu)) {
878 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
879 WMReleasePropList(submenu);
880 submenu = NULL;
882 if (submenu) {
883 appendMenu(menu, submenu);
884 WMReleasePropList(submenu);
886 #endif
888 menuDomain->dictionary = menu;
891 WDDomain *wDefaultsInitDomain(const char *domain, Bool requireDictionary)
893 WDDomain *db;
894 struct stat stbuf;
895 static int inited = 0;
896 WMPropList *shared_dict = NULL;
898 if (!inited) {
899 inited = 1;
900 initDefaults();
903 db = wmalloc(sizeof(WDDomain));
904 db->domain_name = domain;
905 db->path = wdefaultspathfordomain(domain);
907 if (stat(db->path, &stbuf) >= 0) {
908 db->dictionary = WMReadPropListFromFile(db->path);
909 if (db->dictionary) {
910 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
911 WMReleasePropList(db->dictionary);
912 db->dictionary = NULL;
913 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, db->path);
915 db->timestamp = stbuf.st_mtime;
916 } else {
917 wwarning(_("could not load domain %s from user defaults database"), domain);
921 /* global system dictionary */
922 shared_dict = readGlobalDomain(domain, requireDictionary);
924 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
925 WMIsPLDictionary(db->dictionary)) {
926 WMMergePLDictionaries(shared_dict, db->dictionary, True);
927 WMReleasePropList(db->dictionary);
928 db->dictionary = shared_dict;
929 if (stbuf.st_mtime > db->timestamp)
930 db->timestamp = stbuf.st_mtime;
931 } else if (!db->dictionary) {
932 db->dictionary = shared_dict;
933 if (stbuf.st_mtime > db->timestamp)
934 db->timestamp = stbuf.st_mtime;
937 return db;
940 void wReadStaticDefaults(WMPropList * dict)
942 WMPropList *plvalue;
943 WDefaultEntry *entry;
944 unsigned int i;
945 void *tdata;
947 for (i = 0; i < wlengthof(staticOptionList); i++) {
948 entry = &staticOptionList[i];
950 if (dict)
951 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
952 else
953 plvalue = NULL;
955 /* no default in the DB. Use builtin default */
956 if (!plvalue)
957 plvalue = entry->plvalue;
959 if (plvalue) {
960 /* convert data */
961 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
962 if (entry->update)
963 (*entry->update) (NULL, entry, tdata, entry->extra_data);
968 void wDefaultsCheckDomains(void* arg)
970 WScreen *scr;
971 struct stat stbuf;
972 WMPropList *shared_dict = NULL;
973 WMPropList *dict;
974 int i;
976 /* Parameter not used, but tell the compiler that it is ok */
977 (void) arg;
979 if (stat(w_global.domain.wmaker->path, &stbuf) >= 0 && w_global.domain.wmaker->timestamp < stbuf.st_mtime) {
980 w_global.domain.wmaker->timestamp = stbuf.st_mtime;
982 /* Global dictionary */
983 shared_dict = readGlobalDomain("WindowMaker", True);
985 /* User dictionary */
986 dict = WMReadPropListFromFile(w_global.domain.wmaker->path);
988 if (dict) {
989 if (!WMIsPLDictionary(dict)) {
990 WMReleasePropList(dict);
991 dict = NULL;
992 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
993 "WindowMaker", w_global.domain.wmaker->path);
994 } else {
995 if (shared_dict) {
996 WMMergePLDictionaries(shared_dict, dict, True);
997 WMReleasePropList(dict);
998 dict = shared_dict;
999 shared_dict = NULL;
1002 for (i = 0; i < w_global.screen_count; i++) {
1003 scr = wScreenWithNumber(i);
1004 if (scr)
1005 wReadDefaults(scr, dict);
1008 if (w_global.domain.wmaker->dictionary)
1009 WMReleasePropList(w_global.domain.wmaker->dictionary);
1011 w_global.domain.wmaker->dictionary = dict;
1013 } else {
1014 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1017 if (shared_dict)
1018 WMReleasePropList(shared_dict);
1022 if (stat(w_global.domain.window_attr->path, &stbuf) >= 0 && w_global.domain.window_attr->timestamp < stbuf.st_mtime) {
1023 /* global dictionary */
1024 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1025 /* user dictionary */
1026 dict = WMReadPropListFromFile(w_global.domain.window_attr->path);
1027 if (dict) {
1028 if (!WMIsPLDictionary(dict)) {
1029 WMReleasePropList(dict);
1030 dict = NULL;
1031 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1032 "WMWindowAttributes", w_global.domain.window_attr->path);
1033 } else {
1034 if (shared_dict) {
1035 WMMergePLDictionaries(shared_dict, dict, True);
1036 WMReleasePropList(dict);
1037 dict = shared_dict;
1038 shared_dict = NULL;
1041 if (w_global.domain.window_attr->dictionary)
1042 WMReleasePropList(w_global.domain.window_attr->dictionary);
1044 w_global.domain.window_attr->dictionary = dict;
1045 for (i = 0; i < w_global.screen_count; i++) {
1046 scr = wScreenWithNumber(i);
1047 if (scr) {
1048 wDefaultUpdateIcons(scr);
1050 /* Update the panel image if changed */
1051 /* Don't worry. If the image is the same these
1052 * functions will have no performance impact. */
1053 create_logo_image(scr);
1057 } else {
1058 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1061 w_global.domain.window_attr->timestamp = stbuf.st_mtime;
1062 if (shared_dict)
1063 WMReleasePropList(shared_dict);
1066 if (stat(w_global.domain.root_menu->path, &stbuf) >= 0 && w_global.domain.root_menu->timestamp < stbuf.st_mtime) {
1067 dict = WMReadPropListFromFile(w_global.domain.root_menu->path);
1068 if (dict) {
1069 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1070 WMReleasePropList(dict);
1071 dict = NULL;
1072 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1073 "WMRootMenu", w_global.domain.root_menu->path);
1074 } else {
1075 if (w_global.domain.root_menu->dictionary)
1076 WMReleasePropList(w_global.domain.root_menu->dictionary);
1078 w_global.domain.root_menu->dictionary = dict;
1079 wDefaultsMergeGlobalMenus(w_global.domain.root_menu);
1081 } else {
1082 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1084 w_global.domain.root_menu->timestamp = stbuf.st_mtime;
1086 #ifndef HAVE_INOTIFY
1087 if (!arg)
1088 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1089 #endif
1092 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1094 WMPropList *plvalue, *old_value;
1095 WDefaultEntry *entry;
1096 unsigned int i;
1097 int update_workspace_back = 0; /* kluge :/ */
1098 unsigned int needs_refresh;
1099 void *tdata;
1100 WMPropList *old_dict = (w_global.domain.wmaker->dictionary != new_dict ? w_global.domain.wmaker->dictionary : NULL);
1102 needs_refresh = 0;
1104 for (i = 0; i < wlengthof(optionList); i++) {
1105 entry = &optionList[i];
1107 if (new_dict)
1108 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1109 else
1110 plvalue = NULL;
1112 if (!old_dict)
1113 old_value = NULL;
1114 else
1115 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1117 if (!plvalue && !old_value) {
1118 /* no default in the DB. Use builtin default */
1119 plvalue = entry->plvalue;
1120 if (plvalue && new_dict)
1121 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1123 } else if (!plvalue) {
1124 /* value was deleted from DB. Keep current value */
1125 continue;
1126 } else if (!old_value) {
1127 /* set value for the 1st time */
1128 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1129 /* value has changed */
1130 } else {
1131 if (strcmp(entry->key, "WorkspaceBack") == 0
1132 && update_workspace_back && scr->flags.backimage_helper_launched) {
1133 } else {
1134 /* value was not changed since last time */
1135 continue;
1139 if (plvalue) {
1140 /* convert data */
1141 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1143 * If the WorkspaceSpecificBack data has been changed
1144 * so that the helper will be launched now, we must be
1145 * sure to send the default background texture config
1146 * to the helper.
1148 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1149 !scr->flags.backimage_helper_launched)
1150 update_workspace_back = 1;
1152 if (entry->update)
1153 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1159 if (needs_refresh != 0 && !scr->flags.startup) {
1160 int foo;
1162 foo = 0;
1163 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1164 foo |= WTextureSettings;
1165 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1166 foo |= WFontSettings;
1167 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1168 foo |= WColorSettings;
1169 if (foo)
1170 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1171 (void *)(uintptr_t) foo);
1173 foo = 0;
1174 if (needs_refresh & REFRESH_MENU_TEXTURE)
1175 foo |= WTextureSettings;
1176 if (needs_refresh & REFRESH_MENU_FONT)
1177 foo |= WFontSettings;
1178 if (needs_refresh & REFRESH_MENU_COLOR)
1179 foo |= WColorSettings;
1180 if (foo)
1181 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1183 foo = 0;
1184 if (needs_refresh & REFRESH_WINDOW_FONT)
1185 foo |= WFontSettings;
1186 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1187 foo |= WTextureSettings;
1188 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1189 foo |= WColorSettings;
1190 if (foo)
1191 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1193 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1194 foo = 0;
1195 if (needs_refresh & REFRESH_ICON_FONT)
1196 foo |= WFontSettings;
1197 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1198 foo |= WTextureSettings;
1199 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1200 foo |= WTextureSettings;
1201 if (foo)
1202 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1203 (void *)(uintptr_t) foo);
1205 if (needs_refresh & REFRESH_ICON_TILE)
1206 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1208 if (needs_refresh & REFRESH_WORKSPACE_MENU) {
1209 if (w_global.workspace.menu)
1210 wWorkspaceMenuUpdate(w_global.workspace.menu);
1211 if (w_global.clip.ws_menu)
1212 wWorkspaceMenuUpdate(w_global.clip.ws_menu);
1213 if (w_global.workspace.submenu)
1214 w_global.workspace.submenu->flags.realized = 0;
1215 if (w_global.clip.submenu)
1216 w_global.clip.submenu->flags.realized = 0;
1221 void wDefaultUpdateIcons(WScreen *scr)
1223 WAppIcon *aicon = w_global.app_icon_list;
1224 WDrawerChain *dc;
1225 WWindow *wwin = scr->focused_window;
1227 while (aicon) {
1228 /* Get the application icon, default included */
1229 wIconChangeImageFile(aicon->icon, NULL);
1230 wAppIconPaint(aicon);
1231 aicon = aicon->next;
1234 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock)
1235 wClipIconPaint();
1237 for (dc = scr->drawers; dc != NULL; dc = dc->next)
1238 wDrawerIconPaint(dc->adrawer->icon_array[0]);
1240 while (wwin) {
1241 if (wwin->icon && wwin->flags.miniaturized)
1242 wIconChangeImageFile(wwin->icon, NULL);
1243 wwin = wwin->prev;
1247 /* --------------------------- Local ----------------------- */
1249 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1250 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1251 entry->key, x); \
1252 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1253 var = entry->default_value;\
1254 } else var = WMGetFromPLString(value)\
1257 static int string2index(WMPropList *key, WMPropList *val, const char *def, WOptionEnumeration * values)
1259 char *str;
1260 WOptionEnumeration *v;
1261 char buffer[TOTAL_VALUES_LENGTH];
1263 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1264 for (v = values; v->string != NULL; v++) {
1265 if (strcasecmp(v->string, str) == 0)
1266 return v->value;
1270 buffer[0] = 0;
1271 for (v = values; v->string != NULL; v++) {
1272 if (!v->is_alias) {
1273 if (buffer[0] != 0)
1274 strcat(buffer, ", ");
1275 snprintf(buffer+strlen(buffer),
1276 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1279 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1280 WMGetFromPLString(key),
1281 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1282 buffer);
1284 if (def) {
1285 return string2index(key, val, NULL, values);
1288 return -1;
1292 * value - is the value in the defaults DB
1293 * addr - is the address to store the data
1294 * ret - is the address to store a pointer to a temporary buffer. ret
1295 * must not be freed and is used by the set functions
1297 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1299 static char data;
1300 const char *val;
1301 int second_pass = 0;
1303 /* Parameter not used, but tell the compiler that it is ok */
1304 (void) scr;
1306 GET_STRING_OR_DEFAULT("Boolean", val);
1308 again:
1309 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1310 || strcasecmp(val, "YES") == 0) {
1312 data = 1;
1313 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1314 || strcasecmp(val, "NO") == 0) {
1315 data = 0;
1316 } else {
1317 int i;
1318 if (sscanf(val, "%i", &i) == 1) {
1319 if (i != 0)
1320 data = 1;
1321 else
1322 data = 0;
1323 } else {
1324 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1325 if (second_pass == 0) {
1326 val = WMGetFromPLString(entry->plvalue);
1327 second_pass = 1;
1328 wwarning(_("using default \"%s\" instead"), val);
1329 goto again;
1331 return False;
1335 if (ret)
1336 *ret = &data;
1337 if (addr)
1338 *(char *)addr = data;
1340 return True;
1343 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1345 static int data;
1346 const char *val;
1348 /* Parameter not used, but tell the compiler that it is ok */
1349 (void) scr;
1351 GET_STRING_OR_DEFAULT("Integer", val);
1353 if (sscanf(val, "%i", &data) != 1) {
1354 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1355 val = WMGetFromPLString(entry->plvalue);
1356 wwarning(_("using default \"%s\" instead"), val);
1357 if (sscanf(val, "%i", &data) != 1) {
1358 return False;
1362 if (ret)
1363 *ret = &data;
1364 if (addr)
1365 *(int *)addr = data;
1367 return True;
1370 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1372 static WCoord data;
1373 char *val_x, *val_y;
1374 int nelem, changed = 0;
1375 WMPropList *elem_x, *elem_y;
1377 again:
1378 if (!WMIsPLArray(value)) {
1379 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1380 if (changed == 0) {
1381 value = entry->plvalue;
1382 changed = 1;
1383 wwarning(_("using default \"%s\" instead"), entry->default_value);
1384 goto again;
1386 return False;
1389 nelem = WMGetPropListItemCount(value);
1390 if (nelem != 2) {
1391 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1392 if (changed == 0) {
1393 value = entry->plvalue;
1394 changed = 1;
1395 wwarning(_("using default \"%s\" instead"), entry->default_value);
1396 goto again;
1398 return False;
1401 elem_x = WMGetFromPLArray(value, 0);
1402 elem_y = WMGetFromPLArray(value, 1);
1404 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1405 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1406 if (changed == 0) {
1407 value = entry->plvalue;
1408 changed = 1;
1409 wwarning(_("using default \"%s\" instead"), entry->default_value);
1410 goto again;
1412 return False;
1415 val_x = WMGetFromPLString(elem_x);
1416 val_y = WMGetFromPLString(elem_y);
1418 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1419 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1420 if (changed == 0) {
1421 value = entry->plvalue;
1422 changed = 1;
1423 wwarning(_("using default \"%s\" instead"), entry->default_value);
1424 goto again;
1426 return False;
1429 if (data.x < 0)
1430 data.x = 0;
1431 else if (data.x > scr->scr_width / 3)
1432 data.x = scr->scr_width / 3;
1433 if (data.y < 0)
1434 data.y = 0;
1435 else if (data.y > scr->scr_height / 3)
1436 data.y = scr->scr_height / 3;
1438 if (ret)
1439 *ret = &data;
1440 if (addr)
1441 *(WCoord *) addr = data;
1443 return True;
1446 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1448 /* Parameter not used, but tell the compiler that it is ok */
1449 (void) scr;
1450 (void) entry;
1451 (void) addr;
1453 WMRetainPropList(value);
1455 *ret = value;
1457 return True;
1460 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1462 static char *data;
1463 int i, count, len;
1464 char *ptr;
1465 WMPropList *d;
1466 int changed = 0;
1468 /* Parameter not used, but tell the compiler that it is ok */
1469 (void) scr;
1470 (void) ret;
1472 again:
1473 if (!WMIsPLArray(value)) {
1474 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1475 if (changed == 0) {
1476 value = entry->plvalue;
1477 changed = 1;
1478 wwarning(_("using default \"%s\" instead"), entry->default_value);
1479 goto again;
1481 return False;
1484 i = 0;
1485 count = WMGetPropListItemCount(value);
1486 if (count < 1) {
1487 if (changed == 0) {
1488 value = entry->plvalue;
1489 changed = 1;
1490 wwarning(_("using default \"%s\" instead"), entry->default_value);
1491 goto again;
1493 return False;
1496 len = 0;
1497 for (i = 0; i < count; i++) {
1498 d = WMGetFromPLArray(value, i);
1499 if (!d || !WMIsPLString(d)) {
1500 count = i;
1501 break;
1503 len += strlen(WMGetFromPLString(d)) + 1;
1506 ptr = data = wmalloc(len + 1);
1508 for (i = 0; i < count; i++) {
1509 d = WMGetFromPLArray(value, i);
1510 if (!d || !WMIsPLString(d)) {
1511 break;
1513 strcpy(ptr, WMGetFromPLString(d));
1514 ptr += strlen(WMGetFromPLString(d));
1515 *ptr = ':';
1516 ptr++;
1518 ptr--;
1519 *(ptr--) = 0;
1521 if (*(char **)addr != NULL) {
1522 wfree(*(char **)addr);
1524 *(char **)addr = data;
1526 return True;
1529 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1531 static signed char data;
1533 /* Parameter not used, but tell the compiler that it is ok */
1534 (void) scr;
1536 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1537 if (data < 0)
1538 return False;
1540 if (ret)
1541 *ret = &data;
1542 if (addr)
1543 *(signed char *)addr = data;
1545 return True;
1549 * (solid <color>)
1550 * (hgradient <color> <color>)
1551 * (vgradient <color> <color>)
1552 * (dgradient <color> <color>)
1553 * (mhgradient <color> <color> ...)
1554 * (mvgradient <color> <color> ...)
1555 * (mdgradient <color> <color> ...)
1556 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1557 * (tpixmap <file> <color>)
1558 * (spixmap <file> <color>)
1559 * (cpixmap <file> <color>)
1560 * (thgradient <file> <opaqueness> <color> <color>)
1561 * (tvgradient <file> <opaqueness> <color> <color>)
1562 * (tdgradient <file> <opaqueness> <color> <color>)
1563 * (function <lib> <function> ...)
1566 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1568 WMPropList *elem;
1569 char *val;
1570 int nelem;
1571 WTexture *texture = NULL;
1573 nelem = WMGetPropListItemCount(pl);
1574 if (nelem < 1)
1575 return NULL;
1577 elem = WMGetFromPLArray(pl, 0);
1578 if (!elem || !WMIsPLString(elem))
1579 return NULL;
1580 val = WMGetFromPLString(elem);
1582 if (strcasecmp(val, "solid") == 0) {
1583 XColor color;
1585 if (nelem != 2)
1586 return NULL;
1588 /* get color */
1590 elem = WMGetFromPLArray(pl, 1);
1591 if (!elem || !WMIsPLString(elem))
1592 return NULL;
1593 val = WMGetFromPLString(elem);
1595 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1596 wwarning(_("\"%s\" is not a valid color name"), val);
1597 return NULL;
1600 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1601 } else if (strcasecmp(val, "dgradient") == 0
1602 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1603 RColor color1, color2;
1604 XColor xcolor;
1605 int type;
1607 if (nelem != 3) {
1608 wwarning(_("bad number of arguments in gradient specification"));
1609 return NULL;
1612 if (val[0] == 'd' || val[0] == 'D')
1613 type = WTEX_DGRADIENT;
1614 else if (val[0] == 'h' || val[0] == 'H')
1615 type = WTEX_HGRADIENT;
1616 else
1617 type = WTEX_VGRADIENT;
1619 /* get from color */
1620 elem = WMGetFromPLArray(pl, 1);
1621 if (!elem || !WMIsPLString(elem))
1622 return NULL;
1623 val = WMGetFromPLString(elem);
1625 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1626 wwarning(_("\"%s\" is not a valid color name"), val);
1627 return NULL;
1629 color1.alpha = 255;
1630 color1.red = xcolor.red >> 8;
1631 color1.green = xcolor.green >> 8;
1632 color1.blue = xcolor.blue >> 8;
1634 /* get to color */
1635 elem = WMGetFromPLArray(pl, 2);
1636 if (!elem || !WMIsPLString(elem)) {
1637 return NULL;
1639 val = WMGetFromPLString(elem);
1641 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1642 wwarning(_("\"%s\" is not a valid color name"), val);
1643 return NULL;
1645 color2.alpha = 255;
1646 color2.red = xcolor.red >> 8;
1647 color2.green = xcolor.green >> 8;
1648 color2.blue = xcolor.blue >> 8;
1650 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1652 } else if (strcasecmp(val, "igradient") == 0) {
1653 RColor colors1[2], colors2[2];
1654 int th1, th2;
1655 XColor xcolor;
1656 int i;
1658 if (nelem != 7) {
1659 wwarning(_("bad number of arguments in gradient specification"));
1660 return NULL;
1663 /* get from color */
1664 for (i = 0; i < 2; i++) {
1665 elem = WMGetFromPLArray(pl, 1 + i);
1666 if (!elem || !WMIsPLString(elem))
1667 return NULL;
1668 val = WMGetFromPLString(elem);
1670 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1671 wwarning(_("\"%s\" is not a valid color name"), val);
1672 return NULL;
1674 colors1[i].alpha = 255;
1675 colors1[i].red = xcolor.red >> 8;
1676 colors1[i].green = xcolor.green >> 8;
1677 colors1[i].blue = xcolor.blue >> 8;
1679 elem = WMGetFromPLArray(pl, 3);
1680 if (!elem || !WMIsPLString(elem))
1681 return NULL;
1682 val = WMGetFromPLString(elem);
1683 th1 = atoi(val);
1685 /* get from color */
1686 for (i = 0; i < 2; i++) {
1687 elem = WMGetFromPLArray(pl, 4 + i);
1688 if (!elem || !WMIsPLString(elem))
1689 return NULL;
1690 val = WMGetFromPLString(elem);
1692 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1693 wwarning(_("\"%s\" is not a valid color name"), val);
1694 return NULL;
1696 colors2[i].alpha = 255;
1697 colors2[i].red = xcolor.red >> 8;
1698 colors2[i].green = xcolor.green >> 8;
1699 colors2[i].blue = xcolor.blue >> 8;
1701 elem = WMGetFromPLArray(pl, 6);
1702 if (!elem || !WMIsPLString(elem))
1703 return NULL;
1704 val = WMGetFromPLString(elem);
1705 th2 = atoi(val);
1707 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1709 } else if (strcasecmp(val, "mhgradient") == 0
1710 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1711 XColor color;
1712 RColor **colors;
1713 int i, count;
1714 int type;
1716 if (nelem < 3) {
1717 wwarning(_("too few arguments in multicolor gradient specification"));
1718 return NULL;
1721 if (val[1] == 'h' || val[1] == 'H')
1722 type = WTEX_MHGRADIENT;
1723 else if (val[1] == 'v' || val[1] == 'V')
1724 type = WTEX_MVGRADIENT;
1725 else
1726 type = WTEX_MDGRADIENT;
1728 count = nelem - 1;
1730 colors = wmalloc(sizeof(RColor *) * (count + 1));
1732 for (i = 0; i < count; i++) {
1733 elem = WMGetFromPLArray(pl, i + 1);
1734 if (!elem || !WMIsPLString(elem)) {
1735 for (--i; i >= 0; --i) {
1736 wfree(colors[i]);
1738 wfree(colors);
1739 return NULL;
1741 val = WMGetFromPLString(elem);
1743 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1744 wwarning(_("\"%s\" is not a valid color name"), val);
1745 for (--i; i >= 0; --i) {
1746 wfree(colors[i]);
1748 wfree(colors);
1749 return NULL;
1750 } else {
1751 colors[i] = wmalloc(sizeof(RColor));
1752 colors[i]->red = color.red >> 8;
1753 colors[i]->green = color.green >> 8;
1754 colors[i]->blue = color.blue >> 8;
1757 colors[i] = NULL;
1759 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1760 } else if (strcasecmp(val, "spixmap") == 0 ||
1761 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1762 XColor color;
1763 int type;
1765 if (nelem != 3)
1766 return NULL;
1768 if (val[0] == 's' || val[0] == 'S')
1769 type = WTP_SCALE;
1770 else if (val[0] == 'c' || val[0] == 'C')
1771 type = WTP_CENTER;
1772 else
1773 type = WTP_TILE;
1775 /* get color */
1776 elem = WMGetFromPLArray(pl, 2);
1777 if (!elem || !WMIsPLString(elem)) {
1778 return NULL;
1780 val = WMGetFromPLString(elem);
1782 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1783 wwarning(_("\"%s\" is not a valid color name"), val);
1784 return NULL;
1787 /* file name */
1788 elem = WMGetFromPLArray(pl, 1);
1789 if (!elem || !WMIsPLString(elem))
1790 return NULL;
1791 val = WMGetFromPLString(elem);
1793 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1794 } else if (strcasecmp(val, "thgradient") == 0
1795 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1796 RColor color1, color2;
1797 XColor xcolor;
1798 int opacity;
1799 int style;
1801 if (val[1] == 'h' || val[1] == 'H')
1802 style = WTEX_THGRADIENT;
1803 else if (val[1] == 'v' || val[1] == 'V')
1804 style = WTEX_TVGRADIENT;
1805 else
1806 style = WTEX_TDGRADIENT;
1808 if (nelem != 5) {
1809 wwarning(_("bad number of arguments in textured gradient specification"));
1810 return NULL;
1813 /* get from color */
1814 elem = WMGetFromPLArray(pl, 3);
1815 if (!elem || !WMIsPLString(elem))
1816 return NULL;
1817 val = WMGetFromPLString(elem);
1819 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1820 wwarning(_("\"%s\" is not a valid color name"), val);
1821 return NULL;
1823 color1.alpha = 255;
1824 color1.red = xcolor.red >> 8;
1825 color1.green = xcolor.green >> 8;
1826 color1.blue = xcolor.blue >> 8;
1828 /* get to color */
1829 elem = WMGetFromPLArray(pl, 4);
1830 if (!elem || !WMIsPLString(elem)) {
1831 return NULL;
1833 val = WMGetFromPLString(elem);
1835 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1836 wwarning(_("\"%s\" is not a valid color name"), val);
1837 return NULL;
1839 color2.alpha = 255;
1840 color2.red = xcolor.red >> 8;
1841 color2.green = xcolor.green >> 8;
1842 color2.blue = xcolor.blue >> 8;
1844 /* get opacity */
1845 elem = WMGetFromPLArray(pl, 2);
1846 if (!elem || !WMIsPLString(elem))
1847 opacity = 128;
1848 else
1849 val = WMGetFromPLString(elem);
1851 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1852 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1853 opacity = 128;
1856 /* get file name */
1857 elem = WMGetFromPLArray(pl, 1);
1858 if (!elem || !WMIsPLString(elem))
1859 return NULL;
1860 val = WMGetFromPLString(elem);
1862 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1863 } else if (strcasecmp(val, "function") == 0) {
1864 /* Leave this in to handle the unlikely case of
1865 * someone actually having function textures configured */
1866 wwarning("function texture support has been removed");
1867 return NULL;
1868 } else {
1869 wwarning(_("invalid texture type %s"), val);
1870 return NULL;
1872 return texture;
1875 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1877 static WTexture *texture;
1878 int changed = 0;
1880 again:
1881 if (!WMIsPLArray(value)) {
1882 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1883 if (changed == 0) {
1884 value = entry->plvalue;
1885 changed = 1;
1886 wwarning(_("using default \"%s\" instead"), entry->default_value);
1887 goto again;
1889 return False;
1892 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1893 WMPropList *pl;
1895 pl = WMGetFromPLArray(value, 0);
1896 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1897 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1898 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1899 entry->key, "Solid Texture");
1901 value = entry->plvalue;
1902 changed = 1;
1903 wwarning(_("using default \"%s\" instead"), entry->default_value);
1904 goto again;
1908 texture = parse_texture(scr, value);
1910 if (!texture) {
1911 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1912 if (changed == 0) {
1913 value = entry->plvalue;
1914 changed = 1;
1915 wwarning(_("using default \"%s\" instead"), entry->default_value);
1916 goto again;
1918 return False;
1921 if (ret)
1922 *ret = &texture;
1924 if (addr)
1925 *(WTexture **) addr = texture;
1927 return True;
1930 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1932 WMPropList *elem;
1933 int changed = 0;
1934 char *val;
1935 int nelem;
1937 /* Parameter not used, but tell the compiler that it is ok */
1938 (void) scr;
1939 (void) addr;
1941 again:
1942 if (!WMIsPLArray(value)) {
1943 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1944 "WorkspaceBack", "Texture or None");
1945 if (changed == 0) {
1946 value = entry->plvalue;
1947 changed = 1;
1948 wwarning(_("using default \"%s\" instead"), entry->default_value);
1949 goto again;
1951 return False;
1954 /* only do basic error checking and verify for None texture */
1956 nelem = WMGetPropListItemCount(value);
1957 if (nelem > 0) {
1958 elem = WMGetFromPLArray(value, 0);
1959 if (!elem || !WMIsPLString(elem)) {
1960 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1961 if (changed == 0) {
1962 value = entry->plvalue;
1963 changed = 1;
1964 wwarning(_("using default \"%s\" instead"), entry->default_value);
1965 goto again;
1967 return False;
1969 val = WMGetFromPLString(elem);
1971 if (strcasecmp(val, "None") == 0)
1972 return True;
1974 *ret = WMRetainPropList(value);
1976 return True;
1979 static int
1980 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1982 WMPropList *elem;
1983 int nelem;
1984 int changed = 0;
1986 /* Parameter not used, but tell the compiler that it is ok */
1987 (void) scr;
1988 (void) addr;
1990 again:
1991 if (!WMIsPLArray(value)) {
1992 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1993 "WorkspaceSpecificBack", "an array of textures");
1994 if (changed == 0) {
1995 value = entry->plvalue;
1996 changed = 1;
1997 wwarning(_("using default \"%s\" instead"), entry->default_value);
1998 goto again;
2000 return False;
2003 /* only do basic error checking and verify for None texture */
2005 nelem = WMGetPropListItemCount(value);
2006 if (nelem > 0) {
2007 while (nelem--) {
2008 elem = WMGetFromPLArray(value, nelem);
2009 if (!elem || !WMIsPLArray(elem)) {
2010 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2011 nelem);
2016 *ret = WMRetainPropList(value);
2018 #ifdef notworking
2020 * Kluge to force wmsetbg helper to set the default background.
2021 * If the WorkspaceSpecificBack is changed once wmaker has started,
2022 * the WorkspaceBack won't be sent to the helper, unless the user
2023 * changes it's value too. So, we must force this by removing the
2024 * value from the defaults DB.
2026 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2027 WMPropList *key = WMCreatePLString("WorkspaceBack");
2029 WMRemoveFromPLDictionary(w_global.domain.wmaker->dictionary, key);
2031 WMReleasePropList(key);
2033 #endif
2034 return True;
2037 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2039 static WMFont *font;
2040 const char *val;
2042 (void) addr;
2044 GET_STRING_OR_DEFAULT("Font", val);
2046 font = WMCreateFont(scr->wmscreen, val);
2047 if (!font)
2048 font = WMCreateFont(scr->wmscreen, "fixed");
2050 if (!font) {
2051 wfatal(_("could not load any usable font!!!"));
2052 exit(1);
2055 if (ret)
2056 *ret = font;
2058 /* can't assign font value outside update function */
2059 wassertrv(addr == NULL, True);
2061 return True;
2064 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2066 static XColor color;
2067 const char *val;
2068 int second_pass = 0;
2070 (void) addr;
2072 GET_STRING_OR_DEFAULT("Color", val);
2074 again:
2075 if (!wGetColor(scr, val, &color)) {
2076 wwarning(_("could not get color for key \"%s\""), entry->key);
2077 if (second_pass == 0) {
2078 val = WMGetFromPLString(entry->plvalue);
2079 second_pass = 1;
2080 wwarning(_("using default \"%s\" instead"), val);
2081 goto again;
2083 return False;
2086 if (ret)
2087 *ret = &color;
2089 assert(addr == NULL);
2091 if (addr)
2092 *(unsigned long*)addr = pixel;
2095 return True;
2098 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2100 static WShortKey shortcut;
2101 KeySym ksym;
2102 const char *val;
2103 char *k;
2104 char buf[MAX_SHORTCUT_LENGTH], *b;
2106 /* Parameter not used, but tell the compiler that it is ok */
2107 (void) scr;
2108 (void) addr;
2110 GET_STRING_OR_DEFAULT("Key spec", val);
2112 if (!val || strcasecmp(val, "NONE") == 0) {
2113 shortcut.keycode = 0;
2114 shortcut.modifier = 0;
2115 if (ret)
2116 *ret = &shortcut;
2117 return True;
2120 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2122 b = (char *)buf;
2124 /* get modifiers */
2125 shortcut.modifier = 0;
2126 while ((k = strchr(b, '+')) != NULL) {
2127 int mod;
2129 *k = 0;
2130 mod = wXModifierFromKey(b);
2131 if (mod < 0) {
2132 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2133 return False;
2135 shortcut.modifier |= mod;
2137 b = k + 1;
2140 /* get key */
2141 ksym = XStringToKeysym(b);
2143 if (ksym == NoSymbol) {
2144 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2145 return False;
2148 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2149 if (shortcut.keycode == 0) {
2150 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2151 return False;
2154 if (ret)
2155 *ret = &shortcut;
2157 return True;
2160 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2162 static int mask;
2163 const char *str;
2165 /* Parameter not used, but tell the compiler that it is ok */
2166 (void) scr;
2168 GET_STRING_OR_DEFAULT("Modifier Key", str);
2170 if (!str)
2171 return False;
2173 mask = wXModifierFromKey(str);
2174 if (mask < 0) {
2175 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2176 mask = 0;
2177 return False;
2180 if (addr)
2181 *(int *)addr = mask;
2183 if (ret)
2184 *ret = &mask;
2186 return True;
2189 # include <X11/cursorfont.h>
2190 typedef struct {
2191 const char *name;
2192 int id;
2193 } WCursorLookup;
2195 #define CURSOR_ID_NONE (XC_num_glyphs)
2197 static const WCursorLookup cursor_table[] = {
2198 {"X_cursor", XC_X_cursor},
2199 {"arrow", XC_arrow},
2200 {"based_arrow_down", XC_based_arrow_down},
2201 {"based_arrow_up", XC_based_arrow_up},
2202 {"boat", XC_boat},
2203 {"bogosity", XC_bogosity},
2204 {"bottom_left_corner", XC_bottom_left_corner},
2205 {"bottom_right_corner", XC_bottom_right_corner},
2206 {"bottom_side", XC_bottom_side},
2207 {"bottom_tee", XC_bottom_tee},
2208 {"box_spiral", XC_box_spiral},
2209 {"center_ptr", XC_center_ptr},
2210 {"circle", XC_circle},
2211 {"clock", XC_clock},
2212 {"coffee_mug", XC_coffee_mug},
2213 {"cross", XC_cross},
2214 {"cross_reverse", XC_cross_reverse},
2215 {"crosshair", XC_crosshair},
2216 {"diamond_cross", XC_diamond_cross},
2217 {"dot", XC_dot},
2218 {"dotbox", XC_dotbox},
2219 {"double_arrow", XC_double_arrow},
2220 {"draft_large", XC_draft_large},
2221 {"draft_small", XC_draft_small},
2222 {"draped_box", XC_draped_box},
2223 {"exchange", XC_exchange},
2224 {"fleur", XC_fleur},
2225 {"gobbler", XC_gobbler},
2226 {"gumby", XC_gumby},
2227 {"hand1", XC_hand1},
2228 {"hand2", XC_hand2},
2229 {"heart", XC_heart},
2230 {"icon", XC_icon},
2231 {"iron_cross", XC_iron_cross},
2232 {"left_ptr", XC_left_ptr},
2233 {"left_side", XC_left_side},
2234 {"left_tee", XC_left_tee},
2235 {"leftbutton", XC_leftbutton},
2236 {"ll_angle", XC_ll_angle},
2237 {"lr_angle", XC_lr_angle},
2238 {"man", XC_man},
2239 {"middlebutton", XC_middlebutton},
2240 {"mouse", XC_mouse},
2241 {"pencil", XC_pencil},
2242 {"pirate", XC_pirate},
2243 {"plus", XC_plus},
2244 {"question_arrow", XC_question_arrow},
2245 {"right_ptr", XC_right_ptr},
2246 {"right_side", XC_right_side},
2247 {"right_tee", XC_right_tee},
2248 {"rightbutton", XC_rightbutton},
2249 {"rtl_logo", XC_rtl_logo},
2250 {"sailboat", XC_sailboat},
2251 {"sb_down_arrow", XC_sb_down_arrow},
2252 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2253 {"sb_left_arrow", XC_sb_left_arrow},
2254 {"sb_right_arrow", XC_sb_right_arrow},
2255 {"sb_up_arrow", XC_sb_up_arrow},
2256 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2257 {"shuttle", XC_shuttle},
2258 {"sizing", XC_sizing},
2259 {"spider", XC_spider},
2260 {"spraycan", XC_spraycan},
2261 {"star", XC_star},
2262 {"target", XC_target},
2263 {"tcross", XC_tcross},
2264 {"top_left_arrow", XC_top_left_arrow},
2265 {"top_left_corner", XC_top_left_corner},
2266 {"top_right_corner", XC_top_right_corner},
2267 {"top_side", XC_top_side},
2268 {"top_tee", XC_top_tee},
2269 {"trek", XC_trek},
2270 {"ul_angle", XC_ul_angle},
2271 {"umbrella", XC_umbrella},
2272 {"ur_angle", XC_ur_angle},
2273 {"watch", XC_watch},
2274 {"xterm", XC_xterm},
2275 {NULL, CURSOR_ID_NONE}
2278 static void check_bitmap_status(int status, const char *filename, Pixmap bitmap)
2280 switch (status) {
2281 case BitmapOpenFailed:
2282 wwarning(_("failed to open bitmap file \"%s\""), filename);
2283 break;
2284 case BitmapFileInvalid:
2285 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2286 break;
2287 case BitmapNoMemory:
2288 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2289 break;
2290 case BitmapSuccess:
2291 XFreePixmap(dpy, bitmap);
2292 break;
2297 * (none)
2298 * (builtin, <cursor_name>)
2299 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2301 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2303 WMPropList *elem;
2304 char *val;
2305 int nelem;
2306 int status = 0;
2308 nelem = WMGetPropListItemCount(pl);
2309 if (nelem < 1) {
2310 return (status);
2312 elem = WMGetFromPLArray(pl, 0);
2313 if (!elem || !WMIsPLString(elem)) {
2314 return (status);
2316 val = WMGetFromPLString(elem);
2318 if (strcasecmp(val, "none") == 0) {
2319 status = 1;
2320 *cursor = None;
2321 } else if (strcasecmp(val, "builtin") == 0) {
2322 int i;
2323 int cursor_id = CURSOR_ID_NONE;
2325 if (nelem != 2) {
2326 wwarning(_("bad number of arguments in cursor specification"));
2327 return (status);
2329 elem = WMGetFromPLArray(pl, 1);
2330 if (!elem || !WMIsPLString(elem)) {
2331 return (status);
2333 val = WMGetFromPLString(elem);
2335 for (i = 0; cursor_table[i].name != NULL; i++) {
2336 if (strcasecmp(val, cursor_table[i].name) == 0) {
2337 cursor_id = cursor_table[i].id;
2338 break;
2341 if (CURSOR_ID_NONE == cursor_id) {
2342 wwarning(_("unknown builtin cursor name \"%s\""), val);
2343 } else {
2344 *cursor = XCreateFontCursor(dpy, cursor_id);
2345 status = 1;
2347 } else if (strcasecmp(val, "bitmap") == 0) {
2348 char *bitmap_name;
2349 char *mask_name;
2350 int bitmap_status;
2351 int mask_status;
2352 Pixmap bitmap;
2353 Pixmap mask;
2354 unsigned int w, h;
2355 int x, y;
2356 XColor fg, bg;
2358 if (nelem != 3) {
2359 wwarning(_("bad number of arguments in cursor specification"));
2360 return (status);
2362 elem = WMGetFromPLArray(pl, 1);
2363 if (!elem || !WMIsPLString(elem)) {
2364 return (status);
2366 val = WMGetFromPLString(elem);
2367 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2368 if (!bitmap_name) {
2369 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2370 return (status);
2372 elem = WMGetFromPLArray(pl, 2);
2373 if (!elem || !WMIsPLString(elem)) {
2374 wfree(bitmap_name);
2375 return (status);
2377 val = WMGetFromPLString(elem);
2378 mask_name = FindImage(wPreferences.pixmap_path, val);
2379 if (!mask_name) {
2380 wfree(bitmap_name);
2381 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2382 return (status);
2384 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2385 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2386 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2387 fg.pixel = scr->black_pixel;
2388 bg.pixel = scr->white_pixel;
2389 XQueryColor(dpy, scr->w_colormap, &fg);
2390 XQueryColor(dpy, scr->w_colormap, &bg);
2391 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2392 status = 1;
2394 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2395 check_bitmap_status(mask_status, mask_name, mask);
2396 wfree(bitmap_name);
2397 wfree(mask_name);
2399 return (status);
2402 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2404 static Cursor cursor;
2405 int status;
2406 int changed = 0;
2408 again:
2409 if (!WMIsPLArray(value)) {
2410 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2411 entry->key, "cursor specification");
2412 if (!changed) {
2413 value = entry->plvalue;
2414 changed = 1;
2415 wwarning(_("using default \"%s\" instead"), entry->default_value);
2416 goto again;
2418 return (False);
2420 status = parse_cursor(scr, value, &cursor);
2421 if (!status) {
2422 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2423 if (!changed) {
2424 value = entry->plvalue;
2425 changed = 1;
2426 wwarning(_("using default \"%s\" instead"), entry->default_value);
2427 goto again;
2429 return (False);
2431 if (ret) {
2432 *ret = &cursor;
2434 if (addr) {
2435 *(Cursor *) addr = cursor;
2437 return (True);
2440 #undef CURSOR_ID_NONE
2442 /* ---------------- value setting functions --------------- */
2443 static int setJustify(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2445 /* Parameter not used, but tell the compiler that it is ok */
2446 (void) scr;
2447 (void) entry;
2448 (void) tdata;
2449 (void) extra_data;
2451 return REFRESH_WINDOW_TITLE_COLOR;
2454 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2456 /* Parameter not used, but tell the compiler that it is ok */
2457 (void) scr;
2458 (void) entry;
2459 (void) bar;
2460 (void) foo;
2462 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2465 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2467 char *flag = tdata;
2468 long which = (long) extra_data;
2470 /* Parameter not used, but tell the compiler that it is ok */
2471 (void) scr;
2472 (void) entry;
2474 switch (which) {
2475 case WM_DOCK:
2476 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2477 // Drawers require the dock
2478 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || wPreferences.flags.nodock;
2479 break;
2480 case WM_CLIP:
2481 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2482 break;
2483 case WM_DRAWER:
2484 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || *flag;
2485 break;
2486 default:
2487 break;
2489 return 0;
2492 static int setClipMergedInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2494 char *flag = tdata;
2496 /* Parameter not used, but tell the compiler that it is ok */
2497 (void) scr;
2498 (void) entry;
2499 (void) foo;
2501 wPreferences.flags.clip_merged_in_dock = *flag;
2502 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2503 return 0;
2506 static int setWrapAppiconsInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2508 char *flag = tdata;
2510 /* Parameter not used, but tell the compiler that it is ok */
2511 (void) scr;
2512 (void) entry;
2513 (void) foo;
2515 wPreferences.flags.wrap_appicons_in_dock = *flag;
2516 return 0;
2519 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2521 /* Parameter not used, but tell the compiler that it is ok */
2522 (void) entry;
2523 (void) bar;
2524 (void) foo;
2526 if (w_global.workspace.array) {
2527 wWorkspaceForceChange(scr, w_global.workspace.current);
2528 wArrangeIcons(scr, False);
2530 return 0;
2533 static int setIconTile(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2535 Pixmap pixmap;
2536 RImage *img;
2537 WTexture ** texture = tdata;
2538 int reset = 0;
2540 /* Parameter not used, but tell the compiler that it is ok */
2541 (void) foo;
2543 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2544 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2545 ? WREL_ICON : WREL_FLAT);
2546 if (!img) {
2547 wwarning(_("could not render texture for icon background"));
2548 if (!entry->addr)
2549 wTextureDestroy(scr, *texture);
2550 return 0;
2552 RConvertImage(scr->rcontext, img, &pixmap);
2554 if (scr->icon_tile) {
2555 reset = 1;
2556 RReleaseImage(scr->icon_tile);
2557 XFreePixmap(dpy, scr->icon_tile_pixmap);
2560 scr->icon_tile = img;
2562 /* put the icon in the noticeboard hint */
2563 PropSetIconTileHint(scr, img);
2565 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock) {
2566 if (scr->clip_tile) {
2567 RReleaseImage(scr->clip_tile);
2569 scr->clip_tile = wClipMakeTile(img);
2572 if (!wPreferences.flags.nodrawer) {
2573 if (scr->drawer_tile) {
2574 RReleaseImage(scr->drawer_tile);
2576 scr->drawer_tile = wDrawerMakeTile(scr, img);
2579 scr->icon_tile_pixmap = pixmap;
2581 if (scr->def_icon_rimage) {
2582 RReleaseImage(scr->def_icon_rimage);
2583 scr->def_icon_rimage = NULL;
2586 if (scr->icon_back_texture)
2587 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2589 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2591 /* Free the texture as nobody else will use it, nor refer to it. */
2592 if (!entry->addr)
2593 wTextureDestroy(scr, *texture);
2595 return (reset ? REFRESH_ICON_TILE : 0);
2598 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2600 WMFont *font = tdata;
2602 /* Parameter not used, but tell the compiler that it is ok */
2603 (void) entry;
2604 (void) foo;
2606 if (scr->title_font) {
2607 WMReleaseFont(scr->title_font);
2609 scr->title_font = font;
2611 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2614 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2616 WMFont *font = tdata;
2618 /* Parameter not used, but tell the compiler that it is ok */
2619 (void) entry;
2620 (void) foo;
2622 if (scr->menu_title_font) {
2623 WMReleaseFont(scr->menu_title_font);
2626 scr->menu_title_font = font;
2628 return REFRESH_MENU_TITLE_FONT;
2631 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2633 WMFont *font = tdata;
2635 /* Parameter not used, but tell the compiler that it is ok */
2636 (void) entry;
2637 (void) foo;
2639 if (scr->menu_entry_font) {
2640 WMReleaseFont(scr->menu_entry_font);
2642 scr->menu_entry_font = font;
2644 return REFRESH_MENU_FONT;
2647 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2649 WMFont *font = tdata;
2651 /* Parameter not used, but tell the compiler that it is ok */
2652 (void) entry;
2653 (void) foo;
2655 if (scr->icon_title_font) {
2656 WMReleaseFont(scr->icon_title_font);
2659 scr->icon_title_font = font;
2661 return REFRESH_ICON_FONT;
2664 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2666 WMFont *font = tdata;
2668 /* Parameter not used, but tell the compiler that it is ok */
2669 (void) entry;
2670 (void) foo;
2672 if (scr->clip_title_font) {
2673 WMReleaseFont(scr->clip_title_font);
2676 scr->clip_title_font = font;
2678 return REFRESH_ICON_FONT;
2681 static int setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2683 WMFont *font = tdata;
2685 /* Parameter not used, but tell the compiler that it is ok */
2686 (void) scr;
2687 (void) entry;
2688 (void) foo;
2690 if (w_global.workspace.font_for_name)
2691 WMReleaseFont(w_global.workspace.font_for_name);
2693 w_global.workspace.font_for_name = font;
2695 return 0;
2698 static int setHightlight(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2700 XColor *color = tdata;
2702 /* Parameter not used, but tell the compiler that it is ok */
2703 (void) entry;
2704 (void) foo;
2706 if (scr->select_color)
2707 WMReleaseColor(scr->select_color);
2709 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2711 wFreeColor(scr, color->pixel);
2713 return REFRESH_MENU_COLOR;
2716 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2718 XColor *color = tdata;
2720 /* Parameter not used, but tell the compiler that it is ok */
2721 (void) entry;
2722 (void) foo;
2724 if (scr->select_text_color)
2725 WMReleaseColor(scr->select_text_color);
2727 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2729 wFreeColor(scr, color->pixel);
2731 return REFRESH_MENU_COLOR;
2734 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2736 XColor *color = tdata;
2737 long widx = (long) extra_data;
2739 /* Parameter not used, but tell the compiler that it is ok */
2740 (void) entry;
2742 if (scr->clip_title_color[widx])
2743 WMReleaseColor(scr->clip_title_color[widx]);
2745 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2746 wFreeColor(scr, color->pixel);
2748 return REFRESH_ICON_TITLE_COLOR;
2751 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2753 XColor *color = tdata;
2754 long widx = (long) extra_data;
2756 /* Parameter not used, but tell the compiler that it is ok */
2757 (void) entry;
2759 if (scr->window_title_color[widx])
2760 WMReleaseColor(scr->window_title_color[widx]);
2762 scr->window_title_color[widx] =
2763 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2765 wFreeColor(scr, color->pixel);
2767 return REFRESH_WINDOW_TITLE_COLOR;
2770 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2772 XColor *color = tdata;
2774 /* Parameter not used, but tell the compiler that it is ok */
2775 (void) entry;
2776 (void) extra_data;
2778 if (scr->menu_title_color[0])
2779 WMReleaseColor(scr->menu_title_color[0]);
2781 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2783 wFreeColor(scr, color->pixel);
2785 return REFRESH_MENU_TITLE_COLOR;
2788 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2790 XColor *color = tdata;
2792 /* Parameter not used, but tell the compiler that it is ok */
2793 (void) entry;
2794 (void) foo;
2796 if (scr->mtext_color)
2797 WMReleaseColor(scr->mtext_color);
2799 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2801 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2802 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2803 } else {
2804 WMSetColorAlpha(scr->dtext_color, 0xffff);
2807 wFreeColor(scr, color->pixel);
2809 return REFRESH_MENU_COLOR;
2812 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2814 XColor *color = tdata;
2816 /* Parameter not used, but tell the compiler that it is ok */
2817 (void) entry;
2818 (void) foo;
2820 if (scr->dtext_color)
2821 WMReleaseColor(scr->dtext_color);
2823 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2825 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2826 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2827 } else {
2828 WMSetColorAlpha(scr->dtext_color, 0xffff);
2831 wFreeColor(scr, color->pixel);
2833 return REFRESH_MENU_COLOR;
2836 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2838 XColor *color = tdata;
2840 /* Parameter not used, but tell the compiler that it is ok */
2841 (void) entry;
2842 (void) foo;
2844 if (scr->icon_title_color)
2845 WMReleaseColor(scr->icon_title_color);
2846 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2848 wFreeColor(scr, color->pixel);
2850 return REFRESH_ICON_TITLE_COLOR;
2853 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2855 XColor *color = tdata;
2857 /* Parameter not used, but tell the compiler that it is ok */
2858 (void) entry;
2859 (void) foo;
2861 if (scr->icon_title_texture) {
2862 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2864 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2866 return REFRESH_ICON_TITLE_BACK;
2869 static int setFrameBorderWidth(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2871 int *value = tdata;
2873 /* Parameter not used, but tell the compiler that it is ok */
2874 (void) entry;
2875 (void) foo;
2877 scr->frame_border_width = *value;
2879 return REFRESH_FRAME_BORDER;
2882 static int setFrameBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2884 XColor *color = tdata;
2886 /* Parameter not used, but tell the compiler that it is ok */
2887 (void) entry;
2888 (void) foo;
2890 if (scr->frame_border_color)
2891 WMReleaseColor(scr->frame_border_color);
2892 scr->frame_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2894 wFreeColor(scr, color->pixel);
2896 return REFRESH_FRAME_BORDER;
2899 static int setFrameFocusedBorderColor(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2901 XColor *color = tdata;
2903 /* Parameter not used, but tell the compiler that it is ok */
2904 (void) entry;
2905 (void) foo;
2907 if (scr->frame_focused_border_color)
2908 WMReleaseColor(scr->frame_focused_border_color);
2909 scr->frame_focused_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2911 wFreeColor(scr, color->pixel);
2913 return REFRESH_FRAME_BORDER;
2916 static int setFrameSelectedBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2918 XColor *color = tdata;
2920 /* Parameter not used, but tell the compiler that it is ok */
2921 (void) entry;
2922 (void) foo;
2924 if (scr->frame_selected_border_color)
2925 WMReleaseColor(scr->frame_selected_border_color);
2926 scr->frame_selected_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2928 wFreeColor(scr, color->pixel);
2930 return REFRESH_FRAME_BORDER;
2933 static void trackDeadProcess(pid_t pid, unsigned int status, void *client_data)
2935 WScreen *scr = (WScreen *) client_data;
2937 /* Parameter not used, but tell the compiler that it is ok */
2938 (void) pid;
2939 (void) status;
2941 close(scr->helper_fd);
2942 scr->helper_fd = 0;
2943 scr->helper_pid = 0;
2944 scr->flags.backimage_helper_launched = 0;
2947 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
2949 WMPropList *value = tdata;
2950 WMPropList *val;
2951 char *str;
2952 int i;
2954 /* Parameter not used, but tell the compiler that it is ok */
2955 (void) entry;
2956 (void) bar;
2958 if (scr->flags.backimage_helper_launched) {
2959 if (WMGetPropListItemCount(value) == 0) {
2960 SendHelperMessage(scr, 'C', 0, NULL);
2961 SendHelperMessage(scr, 'K', 0, NULL);
2963 WMReleasePropList(value);
2964 return 0;
2966 } else {
2967 pid_t pid;
2968 int filedes[2];
2970 if (WMGetPropListItemCount(value) == 0)
2971 return 0;
2973 if (pipe(filedes) < 0) {
2974 werror("pipe() failed:can't set workspace specific background image");
2976 WMReleasePropList(value);
2977 return 0;
2980 pid = fork();
2981 if (pid < 0) {
2982 werror("fork() failed:can't set workspace specific background image");
2983 if (close(filedes[0]) < 0)
2984 werror("could not close pipe");
2985 if (close(filedes[1]) < 0)
2986 werror("could not close pipe");
2988 } else if (pid == 0) {
2989 char *dither;
2991 SetupEnvironment(scr);
2993 if (close(0) < 0)
2994 werror("could not close pipe");
2995 if (dup(filedes[0]) < 0) {
2996 werror("dup() failed:can't set workspace specific background image");
2998 dither = wPreferences.no_dithering ? "-m" : "-d";
2999 if (wPreferences.smooth_workspace_back)
3000 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3001 else
3002 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3003 werror("could not execute wmsetbg");
3004 exit(1);
3005 } else {
3007 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3008 werror("error setting close-on-exec flag");
3010 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3011 werror("error setting close-on-exec flag");
3014 scr->helper_fd = filedes[1];
3015 scr->helper_pid = pid;
3016 scr->flags.backimage_helper_launched = 1;
3018 wAddDeathHandler(pid, trackDeadProcess, scr);
3020 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3025 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3026 val = WMGetFromPLArray(value, i);
3027 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
3028 str = WMGetPropListDescription(val, False);
3030 SendHelperMessage(scr, 'S', i + 1, str);
3032 wfree(str);
3033 } else {
3034 SendHelperMessage(scr, 'U', i + 1, NULL);
3037 sleep(1);
3039 WMReleasePropList(value);
3040 return 0;
3043 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
3045 WMPropList *value = tdata;
3047 /* Parameter not used, but tell the compiler that it is ok */
3048 (void) entry;
3049 (void) bar;
3051 if (scr->flags.backimage_helper_launched) {
3052 char *str;
3054 if (WMGetPropListItemCount(value) == 0) {
3055 SendHelperMessage(scr, 'U', 0, NULL);
3056 } else {
3057 /* set the default workspace background to this one */
3058 str = WMGetPropListDescription(value, False);
3059 if (str) {
3060 SendHelperMessage(scr, 'S', 0, str);
3061 wfree(str);
3062 SendHelperMessage(scr, 'C', w_global.workspace.current + 1, NULL);
3063 } else {
3064 SendHelperMessage(scr, 'U', 0, NULL);
3067 } else if (WMGetPropListItemCount(value) > 0) {
3068 char *command;
3069 char *text;
3070 char *dither;
3071 int len;
3073 text = WMGetPropListDescription(value, False);
3074 len = strlen(text) + 40;
3075 command = wmalloc(len);
3076 dither = wPreferences.no_dithering ? "-m" : "-d";
3077 if (wPreferences.smooth_workspace_back)
3078 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3079 else
3080 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3081 wfree(text);
3082 ExecuteShellCommand(scr, command);
3083 wfree(command);
3085 WMReleasePropList(value);
3087 return 0;
3090 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3092 WTexture **texture = tdata;
3094 /* Parameter not used, but tell the compiler that it is ok */
3095 (void) entry;
3096 (void) foo;
3098 if (scr->widget_texture) {
3099 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3101 scr->widget_texture = *(WTexSolid **) texture;
3103 return 0;
3106 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3108 WTexture **texture = tdata;
3110 /* Parameter not used, but tell the compiler that it is ok */
3111 (void) entry;
3112 (void) foo;
3114 if (scr->window_title_texture[WS_FOCUSED]) {
3115 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3117 scr->window_title_texture[WS_FOCUSED] = *texture;
3119 return REFRESH_WINDOW_TEXTURES;
3122 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3124 WTexture **texture = tdata;
3126 /* Parameter not used, but tell the compiler that it is ok */
3127 (void) entry;
3128 (void) foo;
3130 if (scr->window_title_texture[WS_PFOCUSED]) {
3131 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3133 scr->window_title_texture[WS_PFOCUSED] = *texture;
3135 return REFRESH_WINDOW_TEXTURES;
3138 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3140 WTexture **texture = tdata;
3142 /* Parameter not used, but tell the compiler that it is ok */
3143 (void) entry;
3144 (void) foo;
3146 if (scr->window_title_texture[WS_UNFOCUSED]) {
3147 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3149 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3151 return REFRESH_WINDOW_TEXTURES;
3154 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3156 WTexture **texture = tdata;
3158 /* Parameter not used, but tell the compiler that it is ok */
3159 (void) entry;
3160 (void) foo;
3162 if (scr->resizebar_texture[0]) {
3163 wTextureDestroy(scr, scr->resizebar_texture[0]);
3165 scr->resizebar_texture[0] = *texture;
3167 return REFRESH_WINDOW_TEXTURES;
3170 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3172 WTexture **texture = tdata;
3174 /* Parameter not used, but tell the compiler that it is ok */
3175 (void) entry;
3176 (void) foo;
3178 if (scr->menu_title_texture[0]) {
3179 wTextureDestroy(scr, scr->menu_title_texture[0]);
3181 scr->menu_title_texture[0] = *texture;
3183 return REFRESH_MENU_TITLE_TEXTURE;
3186 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3188 WTexture **texture = tdata;
3190 /* Parameter not used, but tell the compiler that it is ok */
3191 (void) entry;
3192 (void) foo;
3194 if (scr->menu_item_texture) {
3195 wTextureDestroy(scr, scr->menu_item_texture);
3196 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3198 scr->menu_item_texture = *texture;
3200 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3202 return REFRESH_MENU_TEXTURE;
3205 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3207 WShortKey *shortcut = tdata;
3208 WWindow *wwin;
3209 long widx = (long) extra_data;
3211 /* Parameter not used, but tell the compiler that it is ok */
3212 (void) entry;
3214 wKeyBindings[widx] = *shortcut;
3216 wwin = scr->focused_window;
3218 while (wwin != NULL) {
3219 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3221 if (!WFLAGP(wwin, no_bind_keys)) {
3222 wWindowSetKeyGrabs(wwin);
3224 wwin = wwin->prev;
3227 /* do we need to update window menus? */
3228 if (widx >= WKBD_WORKSPACE1 && widx <= WKBD_WORKSPACE10)
3229 return REFRESH_WORKSPACE_MENU;
3230 if (widx == WKBD_LASTWORKSPACE)
3231 return REFRESH_WORKSPACE_MENU;
3232 if (widx >= WKBD_MOVE_WORKSPACE1 && widx <= WKBD_MOVE_WORKSPACE10)
3233 return REFRESH_WORKSPACE_MENU;
3235 return 0;
3238 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3240 /* Parameter not used, but tell the compiler that it is ok */
3241 (void) entry;
3242 (void) bar;
3243 (void) foo;
3245 wScreenUpdateUsableArea(scr);
3246 wArrangeIcons(scr, True);
3248 return 0;
3251 static int updateUsableArea(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);
3260 return 0;
3263 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3265 /* Parameter not used, but tell the compiler that it is ok */
3266 (void) scr;
3267 (void) entry;
3268 (void) tdata;
3269 (void) foo;
3271 return REFRESH_MENU_TEXTURE;
3274 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3276 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3278 RCopyArea(img, image, x, y, w, h, 0, 0);
3280 return img;
3283 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3285 WMPropList *array = tdata;
3286 char *path;
3287 RImage *bgimage;
3288 int cwidth, cheight;
3289 struct WPreferences *prefs = foo;
3291 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3292 if (prefs->swtileImage)
3293 RReleaseImage(prefs->swtileImage);
3294 prefs->swtileImage = NULL;
3296 WMReleasePropList(array);
3297 return 0;
3300 switch (WMGetPropListItemCount(array)) {
3301 case 4:
3302 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3303 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3304 break;
3305 } else
3306 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3308 if (!path) {
3309 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3310 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3311 } else {
3312 bgimage = RLoadImage(scr->rcontext, path, 0);
3313 if (!bgimage) {
3314 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3315 wfree(path);
3316 } else {
3317 wfree(path);
3319 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3320 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3322 if (cwidth <= 0 || cheight <= 0 ||
3323 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3324 wwarning(_("Invalid split sizes for switch panel back image."));
3325 else {
3326 int i;
3327 int swidth, theight;
3328 for (i = 0; i < 9; i++) {
3329 if (prefs->swbackImage[i])
3330 RReleaseImage(prefs->swbackImage[i]);
3331 prefs->swbackImage[i] = NULL;
3333 swidth = (bgimage->width - cwidth) / 2;
3334 theight = (bgimage->height - cheight) / 2;
3336 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3337 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3338 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3339 swidth, theight);
3341 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3342 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3343 cwidth, cheight);
3344 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3345 swidth, cheight);
3347 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3348 swidth, theight);
3349 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3350 cwidth, theight);
3351 prefs->swbackImage[8] =
3352 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3353 theight);
3355 // check if anything failed
3356 for (i = 0; i < 9; i++) {
3357 if (!prefs->swbackImage[i]) {
3358 for (; i >= 0; --i) {
3359 RReleaseImage(prefs->swbackImage[i]);
3360 prefs->swbackImage[i] = NULL;
3362 break;
3366 RReleaseImage(bgimage);
3370 case 1:
3371 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3372 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3373 break;
3374 } else
3375 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3377 if (!path) {
3378 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3379 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3380 } else {
3381 if (prefs->swtileImage)
3382 RReleaseImage(prefs->swtileImage);
3384 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3385 if (!prefs->swtileImage) {
3386 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3388 wfree(path);
3390 break;
3392 default:
3393 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3394 break;
3397 WMReleasePropList(array);
3399 return 0;
3402 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3404 WMPropList *array = tdata;
3405 int i;
3406 struct WPreferences *prefs = foo;
3408 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3409 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3410 WMReleasePropList(array);
3411 return 0;
3414 DestroyWindowMenu(scr);
3416 for (i = 0; i < 7; i++) {
3417 if (prefs->modifier_labels[i])
3418 wfree(prefs->modifier_labels[i]);
3420 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3421 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3422 } else {
3423 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3424 prefs->modifier_labels[i] = NULL;
3428 WMReleasePropList(array);
3430 return 0;
3433 static int setDoubleClick(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
3435 int *value = tdata;
3437 /* Parameter not used, but tell the compiler that it is ok */
3438 (void) entry;
3439 (void) scr;
3441 if (*value <= 0)
3442 *(int *)foo = 1;
3444 W_setconf_doubleClickDelay(*value);
3446 return 0;
3449 static int setCursor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3451 Cursor *cursor = tdata;
3452 long widx = (long) extra_data;
3454 /* Parameter not used, but tell the compiler that it is ok */
3455 (void) entry;
3457 if (wPreferences.cursor[widx] != None) {
3458 XFreeCursor(dpy, wPreferences.cursor[widx]);
3461 wPreferences.cursor[widx] = *cursor;
3463 if (widx == WCUR_ROOT && *cursor != None) {
3464 XDefineCursor(dpy, scr->root_win, *cursor);
3467 return 0;