Allow setting separate border color for focused windows
[wmaker-crm.git] / src / defaults.c
blob436cb20323a408e67bda275ab2e4f1ae2cd87c22
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <strings.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifndef PATH_MAX
40 #define PATH_MAX DEFAULT_PATH_MAX
41 #endif
43 #include <X11/Xlib.h>
44 #include <X11/Xutil.h>
45 #include <X11/keysym.h>
47 #include <wraster.h>
49 #include "WindowMaker.h"
50 #include "framewin.h"
51 #include "window.h"
52 #include "texture.h"
53 #include "screen.h"
54 #include "resources.h"
55 #include "defaults.h"
56 #include "keybind.h"
57 #include "xmodifier.h"
58 #include "icon.h"
59 #include "main.h"
60 #include "actions.h"
61 #include "dock.h"
62 #include "workspace.h"
63 #include "properties.h"
64 #include "misc.h"
65 #include "event.h"
66 #include "winmenu.h"
68 #define MAX_SHORTCUT_LENGTH 32
70 #ifndef GLOBAL_DEFAULTS_SUBDIR
71 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
72 #endif
75 typedef struct _WDefaultEntry WDefaultEntry;
76 typedef int (WDECallbackConvert) (WScreen *scr, WDefaultEntry *entry, WMPropList *plvalue, void *addr, void **tdata);
77 typedef int (WDECallbackUpdate) (WScreen *scr, WDefaultEntry *entry, void *tdata, void *extra_data);
79 struct _WDefaultEntry {
80 const char *key;
81 const char *default_value;
82 void *extra_data;
83 void *addr;
84 WDECallbackConvert *convert;
85 WDECallbackUpdate *update;
86 WMPropList *plkey;
87 WMPropList *plvalue; /* default value */
90 /* used to map strings to integers */
91 typedef struct {
92 const char *string;
93 short value;
94 char is_alias;
95 } WOptionEnumeration;
97 /* type converters */
98 static WDECallbackConvert getBool;
99 static WDECallbackConvert getInt;
100 static WDECallbackConvert getCoord;
101 static WDECallbackConvert getPathList;
102 static WDECallbackConvert getEnum;
103 static WDECallbackConvert getTexture;
104 static WDECallbackConvert getWSBackground;
105 static WDECallbackConvert getWSSpecificBackground;
106 static WDECallbackConvert getFont;
107 static WDECallbackConvert getColor;
108 static WDECallbackConvert getKeybind;
109 static WDECallbackConvert getModMask;
110 static WDECallbackConvert getPropList;
112 /* value setting functions */
113 static WDECallbackUpdate setJustify;
114 static WDECallbackUpdate setClearance;
115 static WDECallbackUpdate setIfDockPresent;
116 static WDECallbackUpdate setClipMergedInDock;
117 static WDECallbackUpdate setWrapAppiconsInDock;
118 static WDECallbackUpdate setStickyIcons;
119 static WDECallbackUpdate setWidgetColor;
120 static WDECallbackUpdate setIconTile;
121 static WDECallbackUpdate setWinTitleFont;
122 static WDECallbackUpdate setMenuTitleFont;
123 static WDECallbackUpdate setMenuTextFont;
124 static WDECallbackUpdate setIconTitleFont;
125 static WDECallbackUpdate setIconTitleColor;
126 static WDECallbackUpdate setIconTitleBack;
127 static WDECallbackUpdate setFrameBorderWidth;
128 static WDECallbackUpdate setFrameBorderColor;
129 static WDECallbackUpdate setFrameFocusedBorderColor;
130 static WDECallbackUpdate setFrameSelectedBorderColor;
131 static WDECallbackUpdate setLargeDisplayFont;
132 static WDECallbackUpdate setWTitleColor;
133 static WDECallbackUpdate setFTitleBack;
134 static WDECallbackUpdate setPTitleBack;
135 static WDECallbackUpdate setUTitleBack;
136 static WDECallbackUpdate setResizebarBack;
137 static WDECallbackUpdate setWorkspaceBack;
138 static WDECallbackUpdate setWorkspaceSpecificBack;
139 static WDECallbackUpdate setMenuTitleColor;
140 static WDECallbackUpdate setMenuTextColor;
141 static WDECallbackUpdate setMenuDisabledColor;
142 static WDECallbackUpdate setMenuTitleBack;
143 static WDECallbackUpdate setMenuTextBack;
144 static WDECallbackUpdate setHightlight;
145 static WDECallbackUpdate setHightlightText;
146 static WDECallbackUpdate setKeyGrab;
147 static WDECallbackUpdate setDoubleClick;
148 static WDECallbackUpdate setIconPosition;
150 static WDECallbackUpdate setClipTitleFont;
151 static WDECallbackUpdate setClipTitleColor;
153 static WDECallbackUpdate setMenuStyle;
154 static WDECallbackUpdate setSwPOptions;
155 static WDECallbackUpdate updateUsableArea;
157 static WDECallbackUpdate setModifierKeyLabels;
159 static WDECallbackConvert getCursor;
160 static WDECallbackUpdate setCursor;
163 * Tables to convert strings to enumeration values.
164 * Values stored are char
167 /* WARNING: sum of length of all value strings must not exceed
168 * this value */
169 #define TOTAL_VALUES_LENGTH 80
171 #define REFRESH_WINDOW_TEXTURES (1<<0)
172 #define REFRESH_MENU_TEXTURE (1<<1)
173 #define REFRESH_MENU_FONT (1<<2)
174 #define REFRESH_MENU_COLOR (1<<3)
175 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
176 #define REFRESH_MENU_TITLE_FONT (1<<5)
177 #define REFRESH_MENU_TITLE_COLOR (1<<6)
178 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
179 #define REFRESH_WINDOW_FONT (1<<8)
180 #define REFRESH_ICON_TILE (1<<9)
181 #define REFRESH_ICON_FONT (1<<10)
182 #define REFRESH_WORKSPACE_BACK (1<<11)
184 #define REFRESH_BUTTON_IMAGES (1<<12)
186 #define REFRESH_ICON_TITLE_COLOR (1<<13)
187 #define REFRESH_ICON_TITLE_BACK (1<<14)
189 #define REFRESH_WORKSPACE_MENU (1<<15)
191 #define REFRESH_FRAME_BORDER REFRESH_MENU_FONT|REFRESH_WINDOW_FONT
193 static WOptionEnumeration seFocusModes[] = {
194 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
195 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
196 {NULL, 0, 0}
199 static WOptionEnumeration seTitlebarModes[] = {
200 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
201 {"next", TS_NEXT, 0}, {NULL, 0, 0}
204 static WOptionEnumeration seColormapModes[] = {
205 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
206 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
207 {NULL, 0, 0}
210 static WOptionEnumeration sePlacements[] = {
211 {"Auto", WPM_AUTO, 0},
212 {"Smart", WPM_SMART, 0},
213 {"Cascade", WPM_CASCADE, 0},
214 {"Random", WPM_RANDOM, 0},
215 {"Manual", WPM_MANUAL, 0},
216 {"Center", WPM_CENTER, 0},
217 {NULL, 0, 0}
220 static WOptionEnumeration seGeomDisplays[] = {
221 {"None", WDIS_NONE, 0},
222 {"Center", WDIS_CENTER, 0},
223 {"Corner", WDIS_TOPLEFT, 0},
224 {"Floating", WDIS_FRAME_CENTER, 0},
225 {"Line", WDIS_NEW, 0},
226 {NULL, 0, 0}
229 static WOptionEnumeration seSpeeds[] = {
230 {"UltraFast", SPEED_ULTRAFAST, 0},
231 {"Fast", SPEED_FAST, 0},
232 {"Medium", SPEED_MEDIUM, 0},
233 {"Slow", SPEED_SLOW, 0},
234 {"UltraSlow", SPEED_ULTRASLOW, 0},
235 {NULL, 0, 0}
238 static WOptionEnumeration seMouseButtonActions[] = {
239 {"None", WA_NONE, 0},
240 {"SelectWindows", WA_SELECT_WINDOWS, 0},
241 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
242 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
243 {NULL, 0, 0}
246 static WOptionEnumeration seMouseWheelActions[] = {
247 {"None", WA_NONE, 0},
248 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
249 {NULL, 0, 0}
252 static WOptionEnumeration seIconificationStyles[] = {
253 {"Zoom", WIS_ZOOM, 0},
254 {"Twist", WIS_TWIST, 0},
255 {"Flip", WIS_FLIP, 0},
256 {"None", WIS_NONE, 0},
257 {"random", WIS_RANDOM, 0},
258 {NULL, 0, 0}
261 static WOptionEnumeration seJustifications[] = {
262 {"Left", WTJ_LEFT, 0},
263 {"Center", WTJ_CENTER, 0},
264 {"Right", WTJ_RIGHT, 0},
265 {NULL, 0, 0}
268 static WOptionEnumeration seIconPositions[] = {
269 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
270 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
271 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
272 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
273 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
274 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
275 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
276 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
277 {NULL, 0, 0}
280 static WOptionEnumeration seMenuStyles[] = {
281 {"normal", MS_NORMAL, 0},
282 {"singletexture", MS_SINGLE_TEXTURE, 0},
283 {"flat", MS_FLAT, 0},
284 {NULL, 0, 0}
287 static WOptionEnumeration seDisplayPositions[] = {
288 {"none", WD_NONE, 0},
289 {"center", WD_CENTER, 0},
290 {"top", WD_TOP, 0},
291 {"bottom", WD_BOTTOM, 0},
292 {"topleft", WD_TOPLEFT, 0},
293 {"topright", WD_TOPRIGHT, 0},
294 {"bottomleft", WD_BOTTOMLEFT, 0},
295 {"bottomright", WD_BOTTOMRIGHT, 0},
296 {NULL, 0, 0}
299 static WOptionEnumeration seWorkspaceBorder[] = {
300 {"None", WB_NONE, 0},
301 {"LeftRight", WB_LEFTRIGHT, 0},
302 {"TopBottom", WB_TOPBOTTOM, 0},
303 {"AllDirections", WB_ALLDIRS, 0},
304 {NULL, 0, 0}
308 * ALL entries in the tables bellow, NEED to have a default value
309 * defined, and this value needs to be correct.
312 /* these options will only affect the window manager on startup
314 * static defaults can't access the screen data, because it is
315 * created after these defaults are read
317 WDefaultEntry staticOptionList[] = {
319 {"ColormapSize", "4", NULL,
320 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
321 {"DisableDithering", "NO", NULL,
322 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
323 {"IconSize", "64", NULL,
324 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
325 {"ModifierKey", "Mod1", NULL,
326 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
327 {"DisableWSMouseActions", "NO", NULL,
328 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
329 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
330 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
331 {"NewStyle", "new", seTitlebarModes,
332 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
333 {"DisableDock", "NO", (void *)WM_DOCK,
334 NULL, getBool, setIfDockPresent, NULL, NULL},
335 {"DisableClip", "NO", (void *)WM_CLIP,
336 NULL, getBool, setIfDockPresent, NULL, NULL},
337 {"DisableDrawers", "NO", (void *)WM_DRAWER,
338 NULL, getBool, setIfDockPresent, NULL, NULL},
339 {"ClipMergedInDock", "NO", NULL,
340 NULL, getBool, setClipMergedInDock, NULL, NULL},
341 {"DisableMiniwindows", "NO", NULL,
342 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
345 #define NUM2STRING_(x) #x
346 #define NUM2STRING(x) NUM2STRING_(x)
348 WDefaultEntry optionList[] = {
350 /* dynamic options */
352 {"IconPosition", "blh", seIconPositions,
353 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
354 {"IconificationStyle", "Zoom", seIconificationStyles,
355 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
356 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
357 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
358 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
359 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
360 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
361 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
362 {"MouseWheelAction", "None", seMouseWheelActions,
363 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
364 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
365 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
366 {"IconPath", DEF_ICON_PATHS, NULL,
367 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
368 {"ColormapMode", "auto", seColormapModes,
369 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
370 {"AutoFocus", "NO", NULL,
371 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
372 {"RaiseDelay", "0", NULL,
373 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
374 {"CirculateRaise", "NO", NULL,
375 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
376 {"Superfluous", "NO", NULL,
377 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
378 {"AdvanceToNewWorkspace", "NO", NULL,
379 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
380 {"CycleWorkspaces", "NO", NULL,
381 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
382 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
383 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
384 {"WorkspaceBorder", "None", seWorkspaceBorder,
385 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
386 {"WorkspaceBorderSize", "0", NULL,
387 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
388 {"StickyIcons", "NO", NULL,
389 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
390 {"SaveSessionOnExit", "NO", NULL,
391 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
392 {"WrapMenus", "NO", NULL,
393 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
394 {"ScrollableMenus", "NO", NULL,
395 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
396 {"MenuScrollSpeed", "medium", seSpeeds,
397 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
398 {"IconSlideSpeed", "medium", seSpeeds,
399 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
400 {"ShadeSpeed", "medium", seSpeeds,
401 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
402 {"BounceAppIconsWhenUrgent", "YES", NULL,
403 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
404 {"RaiseAppIconsWhenBouncing", "NO", NULL,
405 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
406 {"DoNotMakeAppIconsBounce", "NO", NULL,
407 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
408 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
409 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
410 {"ClipAutoraiseDelay", "600", NULL,
411 &wPreferences.clip_auto_raise_delay, getInt, NULL, NULL, NULL},
412 {"ClipAutolowerDelay", "1000", NULL,
413 &wPreferences.clip_auto_lower_delay, getInt, NULL, NULL, NULL},
414 {"ClipAutoexpandDelay", "600", NULL,
415 &wPreferences.clip_auto_expand_delay, getInt, NULL, NULL, NULL},
416 {"ClipAutocollapseDelay", "1000", NULL,
417 &wPreferences.clip_auto_collapse_delay, getInt, NULL, NULL, NULL},
418 {"WrapAppiconsInDock", "YES", NULL,
419 NULL, getBool, setWrapAppiconsInDock, NULL, NULL},
420 {"AlignSubmenus", "NO", NULL,
421 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
422 {"ViKeyMenus", "NO", NULL,
423 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
424 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
425 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
426 {"WindowPlacement", "auto", sePlacements,
427 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
428 {"IgnoreFocusClick", "NO", NULL,
429 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
430 {"UseSaveUnders", "NO", NULL,
431 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
432 {"OpaqueMove", "NO", NULL,
433 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
434 {"OpaqueResize", "NO", NULL,
435 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
436 {"OpaqueMoveResizeKeyboard", "NO", NULL,
437 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
438 {"DisableAnimations", "NO", NULL,
439 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
440 {"DontLinkWorkspaces", "NO", NULL,
441 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
442 {"HighlightActiveApp", "YES", NULL,
443 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
444 {"AutoArrangeIcons", "NO", NULL,
445 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
446 {"NoWindowOverDock", "NO", NULL,
447 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
448 {"NoWindowOverIcons", "NO", NULL,
449 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
450 {"WindowPlaceOrigin", "(0, 0)", NULL,
451 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
452 {"ResizeDisplay", "corner", seGeomDisplays,
453 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
454 {"MoveDisplay", "corner", seGeomDisplays,
455 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
456 {"DontConfirmKill", "NO", NULL,
457 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
458 {"WindowTitleBalloons", "NO", NULL,
459 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
460 {"MiniwindowTitleBalloons", "NO", NULL,
461 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
462 {"AppIconBalloons", "NO", NULL,
463 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
464 {"HelpBalloons", "NO", NULL,
465 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
466 {"EdgeResistance", "30", NULL,
467 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
468 {"ResizeIncrement", "0", NULL,
469 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
470 {"Attraction", "NO", NULL,
471 &wPreferences.attract, getBool, NULL, NULL, NULL},
472 {"DisableBlinking", "NO", NULL,
473 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
474 {"SingleClickLaunch", "NO", NULL,
475 &wPreferences.single_click, getBool, NULL, NULL, NULL},
476 {"StrictWindozeCycle", "YES", NULL,
477 &wPreferences.strict_windoze_cycle, getBool, NULL, NULL, NULL},
478 {"SwitchPanelOnlyOpen", "NO", NULL,
479 &wPreferences.panel_only_open, getBool, NULL, NULL, NULL},
481 /* style options */
483 {"MenuStyle", "normal", seMenuStyles,
484 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
485 {"WidgetColor", "(solid, gray)", NULL,
486 NULL, getTexture, setWidgetColor, NULL, NULL},
487 {"WorkspaceSpecificBack", "()", NULL,
488 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
489 /* WorkspaceBack must come after WorkspaceSpecificBack or
490 * WorkspaceBack wont know WorkspaceSpecificBack was also
491 * specified and 2 copies of wmsetbg will be launched */
492 {"WorkspaceBack", "(solid, black)", NULL,
493 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
494 {"SmoothWorkspaceBack", "NO", NULL,
495 NULL, getBool, NULL, NULL, NULL},
496 {"IconBack", "(solid, gray)", NULL,
497 NULL, getTexture, setIconTile, NULL, NULL},
498 {"TitleJustify", "center", seJustifications,
499 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
500 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
501 NULL, getFont, setWinTitleFont, NULL, NULL},
502 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
503 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
504 {"WindowTitleMinHeight", "0", NULL,
505 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
506 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
507 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
508 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
509 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
510 {"MenuTitleMinHeight", "0", NULL,
511 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
512 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
513 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
514 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
515 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
516 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
517 NULL, getFont, setMenuTitleFont, NULL, NULL},
518 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
519 NULL, getFont, setMenuTextFont, NULL, NULL},
520 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
521 NULL, getFont, setIconTitleFont, NULL, NULL},
522 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
523 NULL, getFont, setClipTitleFont, NULL, NULL},
524 {"ShowClipTitle", "YES", NULL,
525 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
526 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
527 NULL, getFont, setLargeDisplayFont, NULL, NULL},
528 {"HighlightColor", "white", NULL,
529 NULL, getColor, setHightlight, NULL, NULL},
530 {"HighlightTextColor", "black", NULL,
531 NULL, getColor, setHightlightText, NULL, NULL},
532 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
533 NULL, getColor, setClipTitleColor, NULL, NULL},
534 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
535 NULL, getColor, setClipTitleColor, NULL, NULL},
536 {"FTitleColor", "white", (void *)WS_FOCUSED,
537 NULL, getColor, setWTitleColor, NULL, NULL},
538 {"PTitleColor", "white", (void *)WS_PFOCUSED,
539 NULL, getColor, setWTitleColor, NULL, NULL},
540 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
541 NULL, getColor, setWTitleColor, NULL, NULL},
542 {"FTitleBack", "(solid, black)", NULL,
543 NULL, getTexture, setFTitleBack, NULL, NULL},
544 {"PTitleBack", "(solid, \"#616161\")", NULL,
545 NULL, getTexture, setPTitleBack, NULL, NULL},
546 {"UTitleBack", "(solid, gray)", NULL,
547 NULL, getTexture, setUTitleBack, NULL, NULL},
548 {"ResizebarBack", "(solid, gray)", NULL,
549 NULL, getTexture, setResizebarBack, NULL, NULL},
550 {"MenuTitleColor", "white", NULL,
551 NULL, getColor, setMenuTitleColor, NULL, NULL},
552 {"MenuTextColor", "black", NULL,
553 NULL, getColor, setMenuTextColor, NULL, NULL},
554 {"MenuDisabledColor", "\"#616161\"", NULL,
555 NULL, getColor, setMenuDisabledColor, NULL, NULL},
556 {"MenuTitleBack", "(solid, black)", NULL,
557 NULL, getTexture, setMenuTitleBack, NULL, NULL},
558 {"MenuTextBack", "(solid, gray)", NULL,
559 NULL, getTexture, setMenuTextBack, NULL, NULL},
560 {"IconTitleColor", "white", NULL,
561 NULL, getColor, setIconTitleColor, NULL, NULL},
562 {"IconTitleBack", "black", NULL,
563 NULL, getColor, setIconTitleBack, NULL, NULL},
564 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
565 NULL, getPropList, setSwPOptions, NULL, NULL},
566 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
567 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
568 {"FrameBorderWidth", "1", NULL,
569 NULL, getInt, setFrameBorderWidth, NULL, NULL},
570 {"FrameBorderColor", "black", NULL,
571 NULL, getColor, setFrameBorderColor, NULL, NULL},
572 {"FrameFocusedBorderColor", "black", NULL,
573 NULL, getColor, setFrameFocusedBorderColor, NULL, NULL},
574 {"FrameSelectedBorderColor", "white", NULL,
575 NULL, getColor, setFrameSelectedBorderColor, NULL, NULL},
577 /* keybindings */
579 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
580 NULL, getKeybind, setKeyGrab, NULL, NULL},
581 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
582 NULL, getKeybind, setKeyGrab, NULL, NULL},
583 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
584 NULL, getKeybind, setKeyGrab, NULL, NULL},
585 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
586 NULL, getKeybind, setKeyGrab, NULL, NULL},
587 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
588 NULL, getKeybind, setKeyGrab, NULL, NULL},
589 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
590 NULL, getKeybind, setKeyGrab, NULL, NULL},
591 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
592 NULL, getKeybind, setKeyGrab, NULL, NULL },
593 {"HideKey", "None", (void *)WKBD_HIDE,
594 NULL, getKeybind, setKeyGrab, NULL, NULL},
595 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
596 NULL, getKeybind, setKeyGrab, NULL, NULL},
597 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
598 NULL, getKeybind, setKeyGrab, NULL, NULL},
599 {"CloseKey", "None", (void *)WKBD_CLOSE,
600 NULL, getKeybind, setKeyGrab, NULL, NULL},
601 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
602 NULL, getKeybind, setKeyGrab, NULL, NULL},
603 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
604 NULL, getKeybind, setKeyGrab, NULL, NULL},
605 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
606 NULL, getKeybind, setKeyGrab, NULL, NULL},
607 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
608 NULL, getKeybind, setKeyGrab, NULL, NULL},
609 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
610 NULL, getKeybind, setKeyGrab, NULL, NULL},
611 {"THMaximizeKey", "None", (void*)WKBD_THMAXIMIZE,
612 NULL, getKeybind, setKeyGrab, NULL, NULL},
613 {"BHMaximizeKey", "None", (void*)WKBD_BHMAXIMIZE,
614 NULL, getKeybind, setKeyGrab, NULL, NULL},
615 {"LTCMaximizeKey", "None", (void*)WKBD_LTCMAXIMIZE,
616 NULL, getKeybind, setKeyGrab, NULL, NULL},
617 {"RTCMaximizeKey", "None", (void*)WKBD_RTCMAXIMIZE,
618 NULL, getKeybind, setKeyGrab, NULL, NULL},
619 {"LBCMaximizeKey", "None", (void*)WKBD_LBCMAXIMIZE,
620 NULL, getKeybind, setKeyGrab, NULL, NULL},
621 {"RBCMaximizeKey", "None", (void*)WKBD_RBCMAXIMIZE,
622 NULL, getKeybind, setKeyGrab, NULL, NULL},
623 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
624 NULL, getKeybind, setKeyGrab, NULL, NULL},
625 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
626 NULL, getKeybind, setKeyGrab, NULL, NULL},
627 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
628 NULL, getKeybind, setKeyGrab, NULL, NULL},
629 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
630 NULL, getKeybind, setKeyGrab, NULL, NULL},
631 {"ShadeKey", "None", (void *)WKBD_SHADE,
632 NULL, getKeybind, setKeyGrab, NULL, NULL},
633 {"SelectKey", "None", (void *)WKBD_SELECT,
634 NULL, getKeybind, setKeyGrab, NULL, NULL},
635 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
636 NULL, getKeybind, setKeyGrab, NULL, NULL},
637 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
638 NULL, getKeybind, setKeyGrab, NULL, NULL},
639 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
640 NULL, getKeybind, setKeyGrab, NULL, NULL},
641 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
642 NULL, getKeybind, setKeyGrab, NULL, NULL},
643 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
644 NULL, getKeybind, setKeyGrab, NULL, NULL},
645 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
646 NULL, getKeybind, setKeyGrab, NULL, NULL},
647 {"LastWorkspaceKey", "None", (void *)WKBD_LASTWORKSPACE,
648 NULL, getKeybind, setKeyGrab, NULL, NULL},
649 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
650 NULL, getKeybind, setKeyGrab, NULL, NULL},
651 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
652 NULL, getKeybind, setKeyGrab, NULL, NULL},
653 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
654 NULL, getKeybind, setKeyGrab, NULL, NULL},
655 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
656 NULL, getKeybind, setKeyGrab, NULL, NULL},
657 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
658 NULL, getKeybind, setKeyGrab, NULL, NULL},
659 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
660 NULL, getKeybind, setKeyGrab, NULL, NULL},
661 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
662 NULL, getKeybind, setKeyGrab, NULL, NULL},
663 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
664 NULL, getKeybind, setKeyGrab, NULL, NULL},
665 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
666 NULL, getKeybind, setKeyGrab, NULL, NULL},
667 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
668 NULL, getKeybind, setKeyGrab, NULL, NULL},
669 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
670 NULL, getKeybind, setKeyGrab, NULL, NULL},
671 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
672 NULL, getKeybind, setKeyGrab, NULL, NULL},
673 {"MoveToWorkspace1Key", "None", (void *)WKBD_MOVE_WORKSPACE1,
674 NULL, getKeybind, setKeyGrab, NULL, NULL},
675 {"MoveToWorkspace2Key", "None", (void *)WKBD_MOVE_WORKSPACE2,
676 NULL, getKeybind, setKeyGrab, NULL, NULL},
677 {"MoveToWorkspace3Key", "None", (void *)WKBD_MOVE_WORKSPACE3,
678 NULL, getKeybind, setKeyGrab, NULL, NULL},
679 {"MoveToWorkspace4Key", "None", (void *)WKBD_MOVE_WORKSPACE4,
680 NULL, getKeybind, setKeyGrab, NULL, NULL},
681 {"MoveToWorkspace5Key", "None", (void *)WKBD_MOVE_WORKSPACE5,
682 NULL, getKeybind, setKeyGrab, NULL, NULL},
683 {"MoveToWorkspace6Key", "None", (void *)WKBD_MOVE_WORKSPACE6,
684 NULL, getKeybind, setKeyGrab, NULL, NULL},
685 {"MoveToWorkspace7Key", "None", (void *)WKBD_MOVE_WORKSPACE7,
686 NULL, getKeybind, setKeyGrab, NULL, NULL},
687 {"MoveToWorkspace8Key", "None", (void *)WKBD_MOVE_WORKSPACE8,
688 NULL, getKeybind, setKeyGrab, NULL, NULL},
689 {"MoveToWorkspace9Key", "None", (void *)WKBD_MOVE_WORKSPACE9,
690 NULL, getKeybind, setKeyGrab, NULL, NULL},
691 {"MoveToWorkspace10Key", "None", (void *)WKBD_MOVE_WORKSPACE10,
692 NULL, getKeybind, setKeyGrab, NULL, NULL},
693 {"MoveToNextWorkspaceKey", "None", (void *)WKBD_MOVE_NEXTWORKSPACE,
694 NULL, getKeybind, setKeyGrab, NULL, NULL},
695 {"MoveToPrevWorkspaceKey", "None", (void *)WKBD_MOVE_PREVWORKSPACE,
696 NULL, getKeybind, setKeyGrab, NULL, NULL},
697 {"MoveToLastWorkspaceKey", "None", (void *)WKBD_MOVE_LASTWORKSPACE,
698 NULL, getKeybind, setKeyGrab, NULL, NULL},
699 {"MoveToNextWorkspaceLayerKey", "None", (void *)WKBD_MOVE_NEXTWSLAYER,
700 NULL, getKeybind, setKeyGrab, NULL, NULL},
701 {"MoveToPrevWorkspaceLayerKey", "None", (void *)WKBD_MOVE_PREVWSLAYER,
702 NULL, getKeybind, setKeyGrab, NULL, NULL},
703 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
704 NULL, getKeybind, setKeyGrab, NULL, NULL},
705 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
706 NULL, getKeybind, setKeyGrab, NULL, NULL},
707 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
708 NULL, getKeybind, setKeyGrab, NULL, NULL},
709 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
710 NULL, getKeybind, setKeyGrab, NULL, NULL},
711 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
712 NULL, getKeybind, setKeyGrab, NULL, NULL},
713 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
714 NULL, getKeybind, setKeyGrab, NULL, NULL},
715 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
716 NULL, getKeybind, setKeyGrab, NULL, NULL},
717 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
718 NULL, getKeybind, setKeyGrab, NULL, NULL},
719 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
720 NULL, getKeybind, setKeyGrab, NULL, NULL},
721 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
722 NULL, getKeybind, setKeyGrab, NULL, NULL},
723 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
724 NULL, getKeybind, setKeyGrab, NULL, NULL},
725 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
726 NULL, getKeybind, setKeyGrab, NULL, NULL},
727 {"RunKey", "None", (void *)WKBD_RUN,
728 NULL, getKeybind, setKeyGrab, NULL, NULL},
730 #ifdef KEEP_XKB_LOCK_STATUS
731 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
732 NULL, getKeybind, setKeyGrab, NULL, NULL},
733 {"KbdModeLock", "NO", NULL,
734 &wPreferences.modelock, getBool, NULL, NULL, NULL},
735 #endif /* KEEP_XKB_LOCK_STATUS */
737 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
738 NULL, getCursor, setCursor, NULL, NULL},
739 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
740 NULL, getCursor, setCursor, NULL, NULL},
741 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
742 NULL, getCursor, setCursor, NULL, NULL},
743 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
744 NULL, getCursor, setCursor, NULL, NULL},
745 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
746 NULL, getCursor, setCursor, NULL, NULL},
747 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
748 NULL, getCursor, setCursor, NULL, NULL},
749 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
750 NULL, getCursor, setCursor, NULL, NULL},
751 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
752 NULL, getCursor, setCursor, NULL, NULL},
753 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
754 NULL, getCursor, setCursor, NULL, NULL},
755 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
756 NULL, getCursor, setCursor, NULL, NULL},
757 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
758 NULL, getCursor, setCursor, NULL, NULL},
759 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
760 NULL, getCursor, setCursor, NULL, NULL},
761 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
762 NULL, getCursor, setCursor, NULL, NULL},
763 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
764 NULL, getCursor, setCursor, NULL, NULL},
765 {"DialogHistoryLines", "500", NULL,
766 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
767 {"CycleActiveHeadOnly", "NO", NULL,
768 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL},
769 {"CycleIgnoreMinimized", "NO", NULL,
770 &wPreferences.cycle_ignore_minimized, getBool, NULL, NULL, NULL}
773 static void initDefaults(void)
775 unsigned int i;
776 WDefaultEntry *entry;
778 WMPLSetCaseSensitive(False);
780 for (i = 0; i < wlengthof(optionList); i++) {
781 entry = &optionList[i];
783 entry->plkey = WMCreatePLString(entry->key);
784 if (entry->default_value)
785 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
786 else
787 entry->plvalue = NULL;
790 for (i = 0; i < wlengthof(staticOptionList); i++) {
791 entry = &staticOptionList[i];
793 entry->plkey = WMCreatePLString(entry->key);
794 if (entry->default_value)
795 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
796 else
797 entry->plvalue = NULL;
801 static WMPropList *readGlobalDomain(const char *domainName, Bool requireDictionary)
803 WMPropList *globalDict = NULL;
804 char path[PATH_MAX];
805 struct stat stbuf;
807 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
808 if (stat(path, &stbuf) >= 0) {
809 globalDict = WMReadPropListFromFile(path);
810 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
811 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
812 WMReleasePropList(globalDict);
813 globalDict = NULL;
814 } else if (!globalDict) {
815 wwarning(_("could not load domain %s from global defaults database"), domainName);
819 return globalDict;
822 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
823 static void prependMenu(WMPropList * destarr, WMPropList * array)
825 WMPropList *item;
826 int i;
828 for (i = 0; i < WMGetPropListItemCount(array); i++) {
829 item = WMGetFromPLArray(array, i);
830 if (item)
831 WMInsertInPLArray(destarr, i + 1, item);
835 static void appendMenu(WMPropList * destarr, WMPropList * array)
837 WMPropList *item;
838 int i;
840 for (i = 0; i < WMGetPropListItemCount(array); i++) {
841 item = WMGetFromPLArray(array, i);
842 if (item)
843 WMAddToPLArray(destarr, item);
846 #endif
848 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
850 WMPropList *menu = menuDomain->dictionary;
851 WMPropList *submenu;
853 if (!menu || !WMIsPLArray(menu))
854 return;
856 #ifdef GLOBAL_PREAMBLE_MENU_FILE
857 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
859 if (submenu && !WMIsPLArray(submenu)) {
860 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
861 WMReleasePropList(submenu);
862 submenu = NULL;
864 if (submenu) {
865 prependMenu(menu, submenu);
866 WMReleasePropList(submenu);
868 #endif
870 #ifdef GLOBAL_EPILOGUE_MENU_FILE
871 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
873 if (submenu && !WMIsPLArray(submenu)) {
874 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
875 WMReleasePropList(submenu);
876 submenu = NULL;
878 if (submenu) {
879 appendMenu(menu, submenu);
880 WMReleasePropList(submenu);
882 #endif
884 menuDomain->dictionary = menu;
887 WDDomain *wDefaultsInitDomain(const char *domain, Bool requireDictionary)
889 WDDomain *db;
890 struct stat stbuf;
891 static int inited = 0;
892 const char *the_path;
893 WMPropList *shared_dict = NULL;
895 if (!inited) {
896 inited = 1;
897 initDefaults();
900 db = wmalloc(sizeof(WDDomain));
901 db->domain_name = domain;
902 db->path = wdefaultspathfordomain(domain);
903 the_path = db->path;
905 if (the_path && stat(the_path, &stbuf) >= 0) {
906 db->dictionary = WMReadPropListFromFile(the_path);
907 if (db->dictionary) {
908 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
909 WMReleasePropList(db->dictionary);
910 db->dictionary = NULL;
911 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
913 db->timestamp = stbuf.st_mtime;
914 } else {
915 wwarning(_("could not load domain %s from user defaults database"), domain);
919 /* global system dictionary */
920 shared_dict = readGlobalDomain(domain, requireDictionary);
922 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
923 WMIsPLDictionary(db->dictionary)) {
924 WMMergePLDictionaries(shared_dict, db->dictionary, True);
925 WMReleasePropList(db->dictionary);
926 db->dictionary = shared_dict;
927 if (stbuf.st_mtime > db->timestamp)
928 db->timestamp = stbuf.st_mtime;
929 } else if (!db->dictionary) {
930 db->dictionary = shared_dict;
931 if (stbuf.st_mtime > db->timestamp)
932 db->timestamp = stbuf.st_mtime;
935 return db;
938 void wReadStaticDefaults(WMPropList * dict)
940 WMPropList *plvalue;
941 WDefaultEntry *entry;
942 unsigned int i;
943 void *tdata;
945 for (i = 0; i < wlengthof(staticOptionList); i++) {
946 entry = &staticOptionList[i];
948 if (dict)
949 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
950 else
951 plvalue = NULL;
953 /* no default in the DB. Use builtin default */
954 if (!plvalue)
955 plvalue = entry->plvalue;
957 if (plvalue) {
958 /* convert data */
959 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
960 if (entry->update)
961 (*entry->update) (NULL, entry, tdata, entry->extra_data);
966 void wDefaultsCheckDomains(void* arg)
968 WScreen *scr;
969 struct stat stbuf;
970 WMPropList *shared_dict = NULL;
971 WMPropList *dict;
972 int i;
974 /* Parameter not used, but tell the compiler that it is ok */
975 (void) arg;
977 if (stat(w_global.domain.wmaker->path, &stbuf) >= 0 && w_global.domain.wmaker->timestamp < stbuf.st_mtime) {
978 w_global.domain.wmaker->timestamp = stbuf.st_mtime;
980 /* Global dictionary */
981 shared_dict = readGlobalDomain("WindowMaker", True);
983 /* User dictionary */
984 dict = WMReadPropListFromFile(w_global.domain.wmaker->path);
986 if (dict) {
987 if (!WMIsPLDictionary(dict)) {
988 WMReleasePropList(dict);
989 dict = NULL;
990 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
991 "WindowMaker", w_global.domain.wmaker->path);
992 } else {
993 if (shared_dict) {
994 WMMergePLDictionaries(shared_dict, dict, True);
995 WMReleasePropList(dict);
996 dict = shared_dict;
997 shared_dict = NULL;
1000 for (i = 0; i < w_global.screen_count; i++) {
1001 scr = wScreenWithNumber(i);
1002 if (scr)
1003 wReadDefaults(scr, dict);
1006 if (w_global.domain.wmaker->dictionary)
1007 WMReleasePropList(w_global.domain.wmaker->dictionary);
1009 w_global.domain.wmaker->dictionary = dict;
1011 } else {
1012 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1015 if (shared_dict)
1016 WMReleasePropList(shared_dict);
1020 if (stat(w_global.domain.window_attr->path, &stbuf) >= 0 && w_global.domain.window_attr->timestamp < stbuf.st_mtime) {
1021 /* global dictionary */
1022 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1023 /* user dictionary */
1024 dict = WMReadPropListFromFile(w_global.domain.window_attr->path);
1025 if (dict) {
1026 if (!WMIsPLDictionary(dict)) {
1027 WMReleasePropList(dict);
1028 dict = NULL;
1029 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1030 "WMWindowAttributes", w_global.domain.window_attr->path);
1031 } else {
1032 if (shared_dict) {
1033 WMMergePLDictionaries(shared_dict, dict, True);
1034 WMReleasePropList(dict);
1035 dict = shared_dict;
1036 shared_dict = NULL;
1039 if (w_global.domain.window_attr->dictionary)
1040 WMReleasePropList(w_global.domain.window_attr->dictionary);
1042 w_global.domain.window_attr->dictionary = dict;
1043 for (i = 0; i < w_global.screen_count; i++) {
1044 scr = wScreenWithNumber(i);
1045 if (scr) {
1046 wDefaultUpdateIcons(scr);
1048 /* Update the panel image if changed */
1049 /* Don't worry. If the image is the same these
1050 * functions will have no performance impact. */
1051 create_logo_image(scr);
1055 } else {
1056 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1059 w_global.domain.window_attr->timestamp = stbuf.st_mtime;
1060 if (shared_dict)
1061 WMReleasePropList(shared_dict);
1064 if (stat(w_global.domain.root_menu->path, &stbuf) >= 0 && w_global.domain.root_menu->timestamp < stbuf.st_mtime) {
1065 dict = WMReadPropListFromFile(w_global.domain.root_menu->path);
1066 if (dict) {
1067 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1068 WMReleasePropList(dict);
1069 dict = NULL;
1070 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1071 "WMRootMenu", w_global.domain.root_menu->path);
1072 } else {
1073 if (w_global.domain.root_menu->dictionary)
1074 WMReleasePropList(w_global.domain.root_menu->dictionary);
1076 w_global.domain.root_menu->dictionary = dict;
1077 wDefaultsMergeGlobalMenus(w_global.domain.root_menu);
1079 } else {
1080 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1082 w_global.domain.root_menu->timestamp = stbuf.st_mtime;
1084 #ifndef HAVE_INOTIFY
1085 if (!arg)
1086 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1087 #endif
1090 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1092 WMPropList *plvalue, *old_value;
1093 WDefaultEntry *entry;
1094 unsigned int i;
1095 int update_workspace_back = 0; /* kluge :/ */
1096 unsigned int needs_refresh;
1097 void *tdata;
1098 WMPropList *old_dict = (w_global.domain.wmaker->dictionary != new_dict ? w_global.domain.wmaker->dictionary : NULL);
1100 needs_refresh = 0;
1102 for (i = 0; i < wlengthof(optionList); i++) {
1103 entry = &optionList[i];
1105 if (new_dict)
1106 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1107 else
1108 plvalue = NULL;
1110 if (!old_dict)
1111 old_value = NULL;
1112 else
1113 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1115 if (!plvalue && !old_value) {
1116 /* no default in the DB. Use builtin default */
1117 plvalue = entry->plvalue;
1118 if (plvalue && new_dict)
1119 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1121 } else if (!plvalue) {
1122 /* value was deleted from DB. Keep current value */
1123 continue;
1124 } else if (!old_value) {
1125 /* set value for the 1st time */
1126 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1127 /* value has changed */
1128 } else {
1129 if (strcmp(entry->key, "WorkspaceBack") == 0
1130 && update_workspace_back && scr->flags.backimage_helper_launched) {
1131 } else {
1132 /* value was not changed since last time */
1133 continue;
1137 if (plvalue) {
1138 /* convert data */
1139 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1141 * If the WorkspaceSpecificBack data has been changed
1142 * so that the helper will be launched now, we must be
1143 * sure to send the default background texture config
1144 * to the helper.
1146 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1147 !scr->flags.backimage_helper_launched)
1148 update_workspace_back = 1;
1150 if (entry->update)
1151 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1157 if (needs_refresh != 0 && !scr->flags.startup) {
1158 int foo;
1160 foo = 0;
1161 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1162 foo |= WTextureSettings;
1163 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1164 foo |= WFontSettings;
1165 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1166 foo |= WColorSettings;
1167 if (foo)
1168 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1169 (void *)(uintptr_t) foo);
1171 foo = 0;
1172 if (needs_refresh & REFRESH_MENU_TEXTURE)
1173 foo |= WTextureSettings;
1174 if (needs_refresh & REFRESH_MENU_FONT)
1175 foo |= WFontSettings;
1176 if (needs_refresh & REFRESH_MENU_COLOR)
1177 foo |= WColorSettings;
1178 if (foo)
1179 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1181 foo = 0;
1182 if (needs_refresh & REFRESH_WINDOW_FONT)
1183 foo |= WFontSettings;
1184 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1185 foo |= WTextureSettings;
1186 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1187 foo |= WColorSettings;
1188 if (foo)
1189 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1191 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1192 foo = 0;
1193 if (needs_refresh & REFRESH_ICON_FONT)
1194 foo |= WFontSettings;
1195 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1196 foo |= WTextureSettings;
1197 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1198 foo |= WTextureSettings;
1199 if (foo)
1200 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1201 (void *)(uintptr_t) foo);
1203 if (needs_refresh & REFRESH_ICON_TILE)
1204 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1206 if (needs_refresh & REFRESH_WORKSPACE_MENU) {
1207 if (w_global.workspace.menu)
1208 wWorkspaceMenuUpdate(w_global.workspace.menu);
1209 if (w_global.clip.ws_menu)
1210 wWorkspaceMenuUpdate(w_global.clip.ws_menu);
1211 if (w_global.workspace.submenu)
1212 w_global.workspace.submenu->flags.realized = 0;
1213 if (w_global.clip.submenu)
1214 w_global.clip.submenu->flags.realized = 0;
1219 void wDefaultUpdateIcons(WScreen *scr)
1221 WAppIcon *aicon = w_global.app_icon_list;
1222 WDrawerChain *dc;
1223 WWindow *wwin = scr->focused_window;
1225 while (aicon) {
1226 /* Get the application icon, default included */
1227 wIconChangeImageFile(aicon->icon, NULL);
1228 wAppIconPaint(aicon);
1229 aicon = aicon->next;
1232 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock)
1233 wClipIconPaint();
1235 for (dc = scr->drawers; dc != NULL; dc = dc->next)
1236 wDrawerIconPaint(dc->adrawer->icon_array[0]);
1238 while (wwin) {
1239 if (wwin->icon && wwin->flags.miniaturized)
1240 wIconChangeImageFile(wwin->icon, NULL);
1241 wwin = wwin->prev;
1245 /* --------------------------- Local ----------------------- */
1247 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1248 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1249 entry->key, x); \
1250 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1251 var = entry->default_value;\
1252 } else var = WMGetFromPLString(value)\
1255 static int string2index(WMPropList *key, WMPropList *val, const char *def, WOptionEnumeration * values)
1257 char *str;
1258 WOptionEnumeration *v;
1259 char buffer[TOTAL_VALUES_LENGTH];
1261 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1262 for (v = values; v->string != NULL; v++) {
1263 if (strcasecmp(v->string, str) == 0)
1264 return v->value;
1268 buffer[0] = 0;
1269 for (v = values; v->string != NULL; v++) {
1270 if (!v->is_alias) {
1271 if (buffer[0] != 0)
1272 strcat(buffer, ", ");
1273 snprintf(buffer+strlen(buffer),
1274 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1277 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1278 WMGetFromPLString(key),
1279 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1280 buffer);
1282 if (def) {
1283 return string2index(key, val, NULL, values);
1286 return -1;
1290 * value - is the value in the defaults DB
1291 * addr - is the address to store the data
1292 * ret - is the address to store a pointer to a temporary buffer. ret
1293 * must not be freed and is used by the set functions
1295 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1297 static char data;
1298 const char *val;
1299 int second_pass = 0;
1301 /* Parameter not used, but tell the compiler that it is ok */
1302 (void) scr;
1304 GET_STRING_OR_DEFAULT("Boolean", val);
1306 again:
1307 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1308 || strcasecmp(val, "YES") == 0) {
1310 data = 1;
1311 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1312 || strcasecmp(val, "NO") == 0) {
1313 data = 0;
1314 } else {
1315 int i;
1316 if (sscanf(val, "%i", &i) == 1) {
1317 if (i != 0)
1318 data = 1;
1319 else
1320 data = 0;
1321 } else {
1322 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1323 if (second_pass == 0) {
1324 val = WMGetFromPLString(entry->plvalue);
1325 second_pass = 1;
1326 wwarning(_("using default \"%s\" instead"), val);
1327 goto again;
1329 return False;
1333 if (ret)
1334 *ret = &data;
1335 if (addr)
1336 *(char *)addr = data;
1338 return True;
1341 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1343 static int data;
1344 const char *val;
1346 /* Parameter not used, but tell the compiler that it is ok */
1347 (void) scr;
1349 GET_STRING_OR_DEFAULT("Integer", val);
1351 if (sscanf(val, "%i", &data) != 1) {
1352 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1353 val = WMGetFromPLString(entry->plvalue);
1354 wwarning(_("using default \"%s\" instead"), val);
1355 if (sscanf(val, "%i", &data) != 1) {
1356 return False;
1360 if (ret)
1361 *ret = &data;
1362 if (addr)
1363 *(int *)addr = data;
1365 return True;
1368 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1370 static WCoord data;
1371 char *val_x, *val_y;
1372 int nelem, changed = 0;
1373 WMPropList *elem_x, *elem_y;
1375 again:
1376 if (!WMIsPLArray(value)) {
1377 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1378 if (changed == 0) {
1379 value = entry->plvalue;
1380 changed = 1;
1381 wwarning(_("using default \"%s\" instead"), entry->default_value);
1382 goto again;
1384 return False;
1387 nelem = WMGetPropListItemCount(value);
1388 if (nelem != 2) {
1389 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1390 if (changed == 0) {
1391 value = entry->plvalue;
1392 changed = 1;
1393 wwarning(_("using default \"%s\" instead"), entry->default_value);
1394 goto again;
1396 return False;
1399 elem_x = WMGetFromPLArray(value, 0);
1400 elem_y = WMGetFromPLArray(value, 1);
1402 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1403 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1404 if (changed == 0) {
1405 value = entry->plvalue;
1406 changed = 1;
1407 wwarning(_("using default \"%s\" instead"), entry->default_value);
1408 goto again;
1410 return False;
1413 val_x = WMGetFromPLString(elem_x);
1414 val_y = WMGetFromPLString(elem_y);
1416 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1417 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1418 if (changed == 0) {
1419 value = entry->plvalue;
1420 changed = 1;
1421 wwarning(_("using default \"%s\" instead"), entry->default_value);
1422 goto again;
1424 return False;
1427 if (data.x < 0)
1428 data.x = 0;
1429 else if (data.x > scr->scr_width / 3)
1430 data.x = scr->scr_width / 3;
1431 if (data.y < 0)
1432 data.y = 0;
1433 else if (data.y > scr->scr_height / 3)
1434 data.y = scr->scr_height / 3;
1436 if (ret)
1437 *ret = &data;
1438 if (addr)
1439 *(WCoord *) addr = data;
1441 return True;
1444 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1446 /* Parameter not used, but tell the compiler that it is ok */
1447 (void) scr;
1448 (void) entry;
1449 (void) addr;
1451 WMRetainPropList(value);
1453 *ret = value;
1455 return True;
1458 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1460 static char *data;
1461 int i, count, len;
1462 char *ptr;
1463 WMPropList *d;
1464 int changed = 0;
1466 /* Parameter not used, but tell the compiler that it is ok */
1467 (void) scr;
1468 (void) ret;
1470 again:
1471 if (!WMIsPLArray(value)) {
1472 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1473 if (changed == 0) {
1474 value = entry->plvalue;
1475 changed = 1;
1476 wwarning(_("using default \"%s\" instead"), entry->default_value);
1477 goto again;
1479 return False;
1482 i = 0;
1483 count = WMGetPropListItemCount(value);
1484 if (count < 1) {
1485 if (changed == 0) {
1486 value = entry->plvalue;
1487 changed = 1;
1488 wwarning(_("using default \"%s\" instead"), entry->default_value);
1489 goto again;
1491 return False;
1494 len = 0;
1495 for (i = 0; i < count; i++) {
1496 d = WMGetFromPLArray(value, i);
1497 if (!d || !WMIsPLString(d)) {
1498 count = i;
1499 break;
1501 len += strlen(WMGetFromPLString(d)) + 1;
1504 ptr = data = wmalloc(len + 1);
1506 for (i = 0; i < count; i++) {
1507 d = WMGetFromPLArray(value, i);
1508 if (!d || !WMIsPLString(d)) {
1509 break;
1511 strcpy(ptr, WMGetFromPLString(d));
1512 ptr += strlen(WMGetFromPLString(d));
1513 *ptr = ':';
1514 ptr++;
1516 ptr--;
1517 *(ptr--) = 0;
1519 if (*(char **)addr != NULL) {
1520 wfree(*(char **)addr);
1522 *(char **)addr = data;
1524 return True;
1527 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1529 static signed char data;
1531 /* Parameter not used, but tell the compiler that it is ok */
1532 (void) scr;
1534 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1535 if (data < 0)
1536 return False;
1538 if (ret)
1539 *ret = &data;
1540 if (addr)
1541 *(signed char *)addr = data;
1543 return True;
1547 * (solid <color>)
1548 * (hgradient <color> <color>)
1549 * (vgradient <color> <color>)
1550 * (dgradient <color> <color>)
1551 * (mhgradient <color> <color> ...)
1552 * (mvgradient <color> <color> ...)
1553 * (mdgradient <color> <color> ...)
1554 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1555 * (tpixmap <file> <color>)
1556 * (spixmap <file> <color>)
1557 * (cpixmap <file> <color>)
1558 * (thgradient <file> <opaqueness> <color> <color>)
1559 * (tvgradient <file> <opaqueness> <color> <color>)
1560 * (tdgradient <file> <opaqueness> <color> <color>)
1561 * (function <lib> <function> ...)
1564 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1566 WMPropList *elem;
1567 char *val;
1568 int nelem;
1569 WTexture *texture = NULL;
1571 nelem = WMGetPropListItemCount(pl);
1572 if (nelem < 1)
1573 return NULL;
1575 elem = WMGetFromPLArray(pl, 0);
1576 if (!elem || !WMIsPLString(elem))
1577 return NULL;
1578 val = WMGetFromPLString(elem);
1580 if (strcasecmp(val, "solid") == 0) {
1581 XColor color;
1583 if (nelem != 2)
1584 return NULL;
1586 /* get color */
1588 elem = WMGetFromPLArray(pl, 1);
1589 if (!elem || !WMIsPLString(elem))
1590 return NULL;
1591 val = WMGetFromPLString(elem);
1593 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1594 wwarning(_("\"%s\" is not a valid color name"), val);
1595 return NULL;
1598 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1599 } else if (strcasecmp(val, "dgradient") == 0
1600 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1601 RColor color1, color2;
1602 XColor xcolor;
1603 int type;
1605 if (nelem != 3) {
1606 wwarning(_("bad number of arguments in gradient specification"));
1607 return NULL;
1610 if (val[0] == 'd' || val[0] == 'D')
1611 type = WTEX_DGRADIENT;
1612 else if (val[0] == 'h' || val[0] == 'H')
1613 type = WTEX_HGRADIENT;
1614 else
1615 type = WTEX_VGRADIENT;
1617 /* get from color */
1618 elem = WMGetFromPLArray(pl, 1);
1619 if (!elem || !WMIsPLString(elem))
1620 return NULL;
1621 val = WMGetFromPLString(elem);
1623 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1624 wwarning(_("\"%s\" is not a valid color name"), val);
1625 return NULL;
1627 color1.alpha = 255;
1628 color1.red = xcolor.red >> 8;
1629 color1.green = xcolor.green >> 8;
1630 color1.blue = xcolor.blue >> 8;
1632 /* get to color */
1633 elem = WMGetFromPLArray(pl, 2);
1634 if (!elem || !WMIsPLString(elem)) {
1635 return NULL;
1637 val = WMGetFromPLString(elem);
1639 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1640 wwarning(_("\"%s\" is not a valid color name"), val);
1641 return NULL;
1643 color2.alpha = 255;
1644 color2.red = xcolor.red >> 8;
1645 color2.green = xcolor.green >> 8;
1646 color2.blue = xcolor.blue >> 8;
1648 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1650 } else if (strcasecmp(val, "igradient") == 0) {
1651 RColor colors1[2], colors2[2];
1652 int th1, th2;
1653 XColor xcolor;
1654 int i;
1656 if (nelem != 7) {
1657 wwarning(_("bad number of arguments in gradient specification"));
1658 return NULL;
1661 /* get from color */
1662 for (i = 0; i < 2; i++) {
1663 elem = WMGetFromPLArray(pl, 1 + i);
1664 if (!elem || !WMIsPLString(elem))
1665 return NULL;
1666 val = WMGetFromPLString(elem);
1668 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1669 wwarning(_("\"%s\" is not a valid color name"), val);
1670 return NULL;
1672 colors1[i].alpha = 255;
1673 colors1[i].red = xcolor.red >> 8;
1674 colors1[i].green = xcolor.green >> 8;
1675 colors1[i].blue = xcolor.blue >> 8;
1677 elem = WMGetFromPLArray(pl, 3);
1678 if (!elem || !WMIsPLString(elem))
1679 return NULL;
1680 val = WMGetFromPLString(elem);
1681 th1 = atoi(val);
1683 /* get from color */
1684 for (i = 0; i < 2; i++) {
1685 elem = WMGetFromPLArray(pl, 4 + i);
1686 if (!elem || !WMIsPLString(elem))
1687 return NULL;
1688 val = WMGetFromPLString(elem);
1690 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1691 wwarning(_("\"%s\" is not a valid color name"), val);
1692 return NULL;
1694 colors2[i].alpha = 255;
1695 colors2[i].red = xcolor.red >> 8;
1696 colors2[i].green = xcolor.green >> 8;
1697 colors2[i].blue = xcolor.blue >> 8;
1699 elem = WMGetFromPLArray(pl, 6);
1700 if (!elem || !WMIsPLString(elem))
1701 return NULL;
1702 val = WMGetFromPLString(elem);
1703 th2 = atoi(val);
1705 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1707 } else if (strcasecmp(val, "mhgradient") == 0
1708 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1709 XColor color;
1710 RColor **colors;
1711 int i, count;
1712 int type;
1714 if (nelem < 3) {
1715 wwarning(_("too few arguments in multicolor gradient specification"));
1716 return NULL;
1719 if (val[1] == 'h' || val[1] == 'H')
1720 type = WTEX_MHGRADIENT;
1721 else if (val[1] == 'v' || val[1] == 'V')
1722 type = WTEX_MVGRADIENT;
1723 else
1724 type = WTEX_MDGRADIENT;
1726 count = nelem - 1;
1728 colors = wmalloc(sizeof(RColor *) * (count + 1));
1730 for (i = 0; i < count; i++) {
1731 elem = WMGetFromPLArray(pl, i + 1);
1732 if (!elem || !WMIsPLString(elem)) {
1733 for (--i; i >= 0; --i) {
1734 wfree(colors[i]);
1736 wfree(colors);
1737 return NULL;
1739 val = WMGetFromPLString(elem);
1741 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1742 wwarning(_("\"%s\" is not a valid color name"), val);
1743 for (--i; i >= 0; --i) {
1744 wfree(colors[i]);
1746 wfree(colors);
1747 return NULL;
1748 } else {
1749 colors[i] = wmalloc(sizeof(RColor));
1750 colors[i]->red = color.red >> 8;
1751 colors[i]->green = color.green >> 8;
1752 colors[i]->blue = color.blue >> 8;
1755 colors[i] = NULL;
1757 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1758 } else if (strcasecmp(val, "spixmap") == 0 ||
1759 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1760 XColor color;
1761 int type;
1763 if (nelem != 3)
1764 return NULL;
1766 if (val[0] == 's' || val[0] == 'S')
1767 type = WTP_SCALE;
1768 else if (val[0] == 'c' || val[0] == 'C')
1769 type = WTP_CENTER;
1770 else
1771 type = WTP_TILE;
1773 /* get color */
1774 elem = WMGetFromPLArray(pl, 2);
1775 if (!elem || !WMIsPLString(elem)) {
1776 return NULL;
1778 val = WMGetFromPLString(elem);
1780 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1781 wwarning(_("\"%s\" is not a valid color name"), val);
1782 return NULL;
1785 /* file name */
1786 elem = WMGetFromPLArray(pl, 1);
1787 if (!elem || !WMIsPLString(elem))
1788 return NULL;
1789 val = WMGetFromPLString(elem);
1791 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1792 } else if (strcasecmp(val, "thgradient") == 0
1793 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1794 RColor color1, color2;
1795 XColor xcolor;
1796 int opacity;
1797 int style;
1799 if (val[1] == 'h' || val[1] == 'H')
1800 style = WTEX_THGRADIENT;
1801 else if (val[1] == 'v' || val[1] == 'V')
1802 style = WTEX_TVGRADIENT;
1803 else
1804 style = WTEX_TDGRADIENT;
1806 if (nelem != 5) {
1807 wwarning(_("bad number of arguments in textured gradient specification"));
1808 return NULL;
1811 /* get from color */
1812 elem = WMGetFromPLArray(pl, 3);
1813 if (!elem || !WMIsPLString(elem))
1814 return NULL;
1815 val = WMGetFromPLString(elem);
1817 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1818 wwarning(_("\"%s\" is not a valid color name"), val);
1819 return NULL;
1821 color1.alpha = 255;
1822 color1.red = xcolor.red >> 8;
1823 color1.green = xcolor.green >> 8;
1824 color1.blue = xcolor.blue >> 8;
1826 /* get to color */
1827 elem = WMGetFromPLArray(pl, 4);
1828 if (!elem || !WMIsPLString(elem)) {
1829 return NULL;
1831 val = WMGetFromPLString(elem);
1833 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1834 wwarning(_("\"%s\" is not a valid color name"), val);
1835 return NULL;
1837 color2.alpha = 255;
1838 color2.red = xcolor.red >> 8;
1839 color2.green = xcolor.green >> 8;
1840 color2.blue = xcolor.blue >> 8;
1842 /* get opacity */
1843 elem = WMGetFromPLArray(pl, 2);
1844 if (!elem || !WMIsPLString(elem))
1845 opacity = 128;
1846 else
1847 val = WMGetFromPLString(elem);
1849 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1850 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1851 opacity = 128;
1854 /* get file name */
1855 elem = WMGetFromPLArray(pl, 1);
1856 if (!elem || !WMIsPLString(elem))
1857 return NULL;
1858 val = WMGetFromPLString(elem);
1860 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1861 } else if (strcasecmp(val, "function") == 0) {
1862 /* Leave this in to handle the unlikely case of
1863 * someone actually having function textures configured */
1864 wwarning("function texture support has been removed");
1865 return NULL;
1866 } else {
1867 wwarning(_("invalid texture type %s"), val);
1868 return NULL;
1870 return texture;
1873 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1875 static WTexture *texture;
1876 int changed = 0;
1878 again:
1879 if (!WMIsPLArray(value)) {
1880 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1881 if (changed == 0) {
1882 value = entry->plvalue;
1883 changed = 1;
1884 wwarning(_("using default \"%s\" instead"), entry->default_value);
1885 goto again;
1887 return False;
1890 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1891 WMPropList *pl;
1893 pl = WMGetFromPLArray(value, 0);
1894 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1895 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1896 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1897 entry->key, "Solid Texture");
1899 value = entry->plvalue;
1900 changed = 1;
1901 wwarning(_("using default \"%s\" instead"), entry->default_value);
1902 goto again;
1906 texture = parse_texture(scr, value);
1908 if (!texture) {
1909 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1910 if (changed == 0) {
1911 value = entry->plvalue;
1912 changed = 1;
1913 wwarning(_("using default \"%s\" instead"), entry->default_value);
1914 goto again;
1916 return False;
1919 if (ret)
1920 *ret = &texture;
1922 if (addr)
1923 *(WTexture **) addr = texture;
1925 return True;
1928 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1930 WMPropList *elem;
1931 int changed = 0;
1932 char *val;
1933 int nelem;
1935 /* Parameter not used, but tell the compiler that it is ok */
1936 (void) scr;
1937 (void) addr;
1939 again:
1940 if (!WMIsPLArray(value)) {
1941 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1942 "WorkspaceBack", "Texture or None");
1943 if (changed == 0) {
1944 value = entry->plvalue;
1945 changed = 1;
1946 wwarning(_("using default \"%s\" instead"), entry->default_value);
1947 goto again;
1949 return False;
1952 /* only do basic error checking and verify for None texture */
1954 nelem = WMGetPropListItemCount(value);
1955 if (nelem > 0) {
1956 elem = WMGetFromPLArray(value, 0);
1957 if (!elem || !WMIsPLString(elem)) {
1958 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1959 if (changed == 0) {
1960 value = entry->plvalue;
1961 changed = 1;
1962 wwarning(_("using default \"%s\" instead"), entry->default_value);
1963 goto again;
1965 return False;
1967 val = WMGetFromPLString(elem);
1969 if (strcasecmp(val, "None") == 0)
1970 return True;
1972 *ret = WMRetainPropList(value);
1974 return True;
1977 static int
1978 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1980 WMPropList *elem;
1981 int nelem;
1982 int changed = 0;
1984 /* Parameter not used, but tell the compiler that it is ok */
1985 (void) scr;
1986 (void) addr;
1988 again:
1989 if (!WMIsPLArray(value)) {
1990 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1991 "WorkspaceSpecificBack", "an array of textures");
1992 if (changed == 0) {
1993 value = entry->plvalue;
1994 changed = 1;
1995 wwarning(_("using default \"%s\" instead"), entry->default_value);
1996 goto again;
1998 return False;
2001 /* only do basic error checking and verify for None texture */
2003 nelem = WMGetPropListItemCount(value);
2004 if (nelem > 0) {
2005 while (nelem--) {
2006 elem = WMGetFromPLArray(value, nelem);
2007 if (!elem || !WMIsPLArray(elem)) {
2008 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2009 nelem);
2014 *ret = WMRetainPropList(value);
2016 #ifdef notworking
2018 * Kluge to force wmsetbg helper to set the default background.
2019 * If the WorkspaceSpecificBack is changed once wmaker has started,
2020 * the WorkspaceBack won't be sent to the helper, unless the user
2021 * changes it's value too. So, we must force this by removing the
2022 * value from the defaults DB.
2024 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2025 WMPropList *key = WMCreatePLString("WorkspaceBack");
2027 WMRemoveFromPLDictionary(w_global.domain.wmaker->dictionary, key);
2029 WMReleasePropList(key);
2031 #endif
2032 return True;
2035 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2037 static WMFont *font;
2038 const char *val;
2040 (void) addr;
2042 GET_STRING_OR_DEFAULT("Font", val);
2044 font = WMCreateFont(scr->wmscreen, val);
2045 if (!font)
2046 font = WMCreateFont(scr->wmscreen, "fixed");
2048 if (!font) {
2049 wfatal(_("could not load any usable font!!!"));
2050 exit(1);
2053 if (ret)
2054 *ret = font;
2056 /* can't assign font value outside update function */
2057 wassertrv(addr == NULL, True);
2059 return True;
2062 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2064 static XColor color;
2065 const char *val;
2066 int second_pass = 0;
2068 (void) addr;
2070 GET_STRING_OR_DEFAULT("Color", val);
2072 again:
2073 if (!wGetColor(scr, val, &color)) {
2074 wwarning(_("could not get color for key \"%s\""), entry->key);
2075 if (second_pass == 0) {
2076 val = WMGetFromPLString(entry->plvalue);
2077 second_pass = 1;
2078 wwarning(_("using default \"%s\" instead"), val);
2079 goto again;
2081 return False;
2084 if (ret)
2085 *ret = &color;
2087 assert(addr == NULL);
2089 if (addr)
2090 *(unsigned long*)addr = pixel;
2093 return True;
2096 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2098 static WShortKey shortcut;
2099 KeySym ksym;
2100 const char *val;
2101 char *k;
2102 char buf[MAX_SHORTCUT_LENGTH], *b;
2104 /* Parameter not used, but tell the compiler that it is ok */
2105 (void) scr;
2106 (void) addr;
2108 GET_STRING_OR_DEFAULT("Key spec", val);
2110 if (!val || strcasecmp(val, "NONE") == 0) {
2111 shortcut.keycode = 0;
2112 shortcut.modifier = 0;
2113 if (ret)
2114 *ret = &shortcut;
2115 return True;
2118 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2120 b = (char *)buf;
2122 /* get modifiers */
2123 shortcut.modifier = 0;
2124 while ((k = strchr(b, '+')) != NULL) {
2125 int mod;
2127 *k = 0;
2128 mod = wXModifierFromKey(b);
2129 if (mod < 0) {
2130 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2131 return False;
2133 shortcut.modifier |= mod;
2135 b = k + 1;
2138 /* get key */
2139 ksym = XStringToKeysym(b);
2141 if (ksym == NoSymbol) {
2142 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2143 return False;
2146 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2147 if (shortcut.keycode == 0) {
2148 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2149 return False;
2152 if (ret)
2153 *ret = &shortcut;
2155 return True;
2158 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2160 static int mask;
2161 const char *str;
2163 /* Parameter not used, but tell the compiler that it is ok */
2164 (void) scr;
2166 GET_STRING_OR_DEFAULT("Modifier Key", str);
2168 if (!str)
2169 return False;
2171 mask = wXModifierFromKey(str);
2172 if (mask < 0) {
2173 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2174 mask = 0;
2175 return False;
2178 if (addr)
2179 *(int *)addr = mask;
2181 if (ret)
2182 *ret = &mask;
2184 return True;
2187 # include <X11/cursorfont.h>
2188 typedef struct {
2189 const char *name;
2190 int id;
2191 } WCursorLookup;
2193 #define CURSOR_ID_NONE (XC_num_glyphs)
2195 static const WCursorLookup cursor_table[] = {
2196 {"X_cursor", XC_X_cursor},
2197 {"arrow", XC_arrow},
2198 {"based_arrow_down", XC_based_arrow_down},
2199 {"based_arrow_up", XC_based_arrow_up},
2200 {"boat", XC_boat},
2201 {"bogosity", XC_bogosity},
2202 {"bottom_left_corner", XC_bottom_left_corner},
2203 {"bottom_right_corner", XC_bottom_right_corner},
2204 {"bottom_side", XC_bottom_side},
2205 {"bottom_tee", XC_bottom_tee},
2206 {"box_spiral", XC_box_spiral},
2207 {"center_ptr", XC_center_ptr},
2208 {"circle", XC_circle},
2209 {"clock", XC_clock},
2210 {"coffee_mug", XC_coffee_mug},
2211 {"cross", XC_cross},
2212 {"cross_reverse", XC_cross_reverse},
2213 {"crosshair", XC_crosshair},
2214 {"diamond_cross", XC_diamond_cross},
2215 {"dot", XC_dot},
2216 {"dotbox", XC_dotbox},
2217 {"double_arrow", XC_double_arrow},
2218 {"draft_large", XC_draft_large},
2219 {"draft_small", XC_draft_small},
2220 {"draped_box", XC_draped_box},
2221 {"exchange", XC_exchange},
2222 {"fleur", XC_fleur},
2223 {"gobbler", XC_gobbler},
2224 {"gumby", XC_gumby},
2225 {"hand1", XC_hand1},
2226 {"hand2", XC_hand2},
2227 {"heart", XC_heart},
2228 {"icon", XC_icon},
2229 {"iron_cross", XC_iron_cross},
2230 {"left_ptr", XC_left_ptr},
2231 {"left_side", XC_left_side},
2232 {"left_tee", XC_left_tee},
2233 {"leftbutton", XC_leftbutton},
2234 {"ll_angle", XC_ll_angle},
2235 {"lr_angle", XC_lr_angle},
2236 {"man", XC_man},
2237 {"middlebutton", XC_middlebutton},
2238 {"mouse", XC_mouse},
2239 {"pencil", XC_pencil},
2240 {"pirate", XC_pirate},
2241 {"plus", XC_plus},
2242 {"question_arrow", XC_question_arrow},
2243 {"right_ptr", XC_right_ptr},
2244 {"right_side", XC_right_side},
2245 {"right_tee", XC_right_tee},
2246 {"rightbutton", XC_rightbutton},
2247 {"rtl_logo", XC_rtl_logo},
2248 {"sailboat", XC_sailboat},
2249 {"sb_down_arrow", XC_sb_down_arrow},
2250 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2251 {"sb_left_arrow", XC_sb_left_arrow},
2252 {"sb_right_arrow", XC_sb_right_arrow},
2253 {"sb_up_arrow", XC_sb_up_arrow},
2254 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2255 {"shuttle", XC_shuttle},
2256 {"sizing", XC_sizing},
2257 {"spider", XC_spider},
2258 {"spraycan", XC_spraycan},
2259 {"star", XC_star},
2260 {"target", XC_target},
2261 {"tcross", XC_tcross},
2262 {"top_left_arrow", XC_top_left_arrow},
2263 {"top_left_corner", XC_top_left_corner},
2264 {"top_right_corner", XC_top_right_corner},
2265 {"top_side", XC_top_side},
2266 {"top_tee", XC_top_tee},
2267 {"trek", XC_trek},
2268 {"ul_angle", XC_ul_angle},
2269 {"umbrella", XC_umbrella},
2270 {"ur_angle", XC_ur_angle},
2271 {"watch", XC_watch},
2272 {"xterm", XC_xterm},
2273 {NULL, CURSOR_ID_NONE}
2276 static void check_bitmap_status(int status, const char *filename, Pixmap bitmap)
2278 switch (status) {
2279 case BitmapOpenFailed:
2280 wwarning(_("failed to open bitmap file \"%s\""), filename);
2281 break;
2282 case BitmapFileInvalid:
2283 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2284 break;
2285 case BitmapNoMemory:
2286 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2287 break;
2288 case BitmapSuccess:
2289 XFreePixmap(dpy, bitmap);
2290 break;
2295 * (none)
2296 * (builtin, <cursor_name>)
2297 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2299 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2301 WMPropList *elem;
2302 char *val;
2303 int nelem;
2304 int status = 0;
2306 nelem = WMGetPropListItemCount(pl);
2307 if (nelem < 1) {
2308 return (status);
2310 elem = WMGetFromPLArray(pl, 0);
2311 if (!elem || !WMIsPLString(elem)) {
2312 return (status);
2314 val = WMGetFromPLString(elem);
2316 if (strcasecmp(val, "none") == 0) {
2317 status = 1;
2318 *cursor = None;
2319 } else if (strcasecmp(val, "builtin") == 0) {
2320 int i;
2321 int cursor_id = CURSOR_ID_NONE;
2323 if (nelem != 2) {
2324 wwarning(_("bad number of arguments in cursor specification"));
2325 return (status);
2327 elem = WMGetFromPLArray(pl, 1);
2328 if (!elem || !WMIsPLString(elem)) {
2329 return (status);
2331 val = WMGetFromPLString(elem);
2333 for (i = 0; cursor_table[i].name != NULL; i++) {
2334 if (strcasecmp(val, cursor_table[i].name) == 0) {
2335 cursor_id = cursor_table[i].id;
2336 break;
2339 if (CURSOR_ID_NONE == cursor_id) {
2340 wwarning(_("unknown builtin cursor name \"%s\""), val);
2341 } else {
2342 *cursor = XCreateFontCursor(dpy, cursor_id);
2343 status = 1;
2345 } else if (strcasecmp(val, "bitmap") == 0) {
2346 char *bitmap_name;
2347 char *mask_name;
2348 int bitmap_status;
2349 int mask_status;
2350 Pixmap bitmap;
2351 Pixmap mask;
2352 unsigned int w, h;
2353 int x, y;
2354 XColor fg, bg;
2356 if (nelem != 3) {
2357 wwarning(_("bad number of arguments in cursor specification"));
2358 return (status);
2360 elem = WMGetFromPLArray(pl, 1);
2361 if (!elem || !WMIsPLString(elem)) {
2362 return (status);
2364 val = WMGetFromPLString(elem);
2365 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2366 if (!bitmap_name) {
2367 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2368 return (status);
2370 elem = WMGetFromPLArray(pl, 2);
2371 if (!elem || !WMIsPLString(elem)) {
2372 wfree(bitmap_name);
2373 return (status);
2375 val = WMGetFromPLString(elem);
2376 mask_name = FindImage(wPreferences.pixmap_path, val);
2377 if (!mask_name) {
2378 wfree(bitmap_name);
2379 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2380 return (status);
2382 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2383 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2384 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2385 fg.pixel = scr->black_pixel;
2386 bg.pixel = scr->white_pixel;
2387 XQueryColor(dpy, scr->w_colormap, &fg);
2388 XQueryColor(dpy, scr->w_colormap, &bg);
2389 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2390 status = 1;
2392 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2393 check_bitmap_status(mask_status, mask_name, mask);
2394 wfree(bitmap_name);
2395 wfree(mask_name);
2397 return (status);
2400 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2402 static Cursor cursor;
2403 int status;
2404 int changed = 0;
2406 again:
2407 if (!WMIsPLArray(value)) {
2408 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2409 entry->key, "cursor specification");
2410 if (!changed) {
2411 value = entry->plvalue;
2412 changed = 1;
2413 wwarning(_("using default \"%s\" instead"), entry->default_value);
2414 goto again;
2416 return (False);
2418 status = parse_cursor(scr, value, &cursor);
2419 if (!status) {
2420 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2421 if (!changed) {
2422 value = entry->plvalue;
2423 changed = 1;
2424 wwarning(_("using default \"%s\" instead"), entry->default_value);
2425 goto again;
2427 return (False);
2429 if (ret) {
2430 *ret = &cursor;
2432 if (addr) {
2433 *(Cursor *) addr = cursor;
2435 return (True);
2438 #undef CURSOR_ID_NONE
2440 /* ---------------- value setting functions --------------- */
2441 static int setJustify(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2443 /* Parameter not used, but tell the compiler that it is ok */
2444 (void) scr;
2445 (void) entry;
2446 (void) tdata;
2447 (void) extra_data;
2449 return REFRESH_WINDOW_TITLE_COLOR;
2452 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2454 /* Parameter not used, but tell the compiler that it is ok */
2455 (void) scr;
2456 (void) entry;
2457 (void) bar;
2458 (void) foo;
2460 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2463 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2465 char *flag = tdata;
2466 long which = (long) extra_data;
2468 /* Parameter not used, but tell the compiler that it is ok */
2469 (void) scr;
2470 (void) entry;
2472 switch (which) {
2473 case WM_DOCK:
2474 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2475 // Drawers require the dock
2476 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || wPreferences.flags.nodock;
2477 break;
2478 case WM_CLIP:
2479 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2480 break;
2481 case WM_DRAWER:
2482 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || *flag;
2483 break;
2484 default:
2485 break;
2487 return 0;
2490 static int setClipMergedInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2492 char *flag = tdata;
2494 /* Parameter not used, but tell the compiler that it is ok */
2495 (void) scr;
2496 (void) entry;
2497 (void) foo;
2499 wPreferences.flags.clip_merged_in_dock = *flag;
2500 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2501 return 0;
2504 static int setWrapAppiconsInDock(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2506 char *flag = tdata;
2508 /* Parameter not used, but tell the compiler that it is ok */
2509 (void) scr;
2510 (void) entry;
2511 (void) foo;
2513 wPreferences.flags.wrap_appicons_in_dock = *flag;
2514 return 0;
2517 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2519 /* Parameter not used, but tell the compiler that it is ok */
2520 (void) entry;
2521 (void) bar;
2522 (void) foo;
2524 if (w_global.workspace.array) {
2525 wWorkspaceForceChange(scr, w_global.workspace.current);
2526 wArrangeIcons(scr, False);
2528 return 0;
2531 static int setIconTile(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2533 Pixmap pixmap;
2534 RImage *img;
2535 WTexture ** texture = tdata;
2536 int reset = 0;
2538 /* Parameter not used, but tell the compiler that it is ok */
2539 (void) foo;
2541 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2542 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2543 ? WREL_ICON : WREL_FLAT);
2544 if (!img) {
2545 wwarning(_("could not render texture for icon background"));
2546 if (!entry->addr)
2547 wTextureDestroy(scr, *texture);
2548 return 0;
2550 RConvertImage(scr->rcontext, img, &pixmap);
2552 if (scr->icon_tile) {
2553 reset = 1;
2554 RReleaseImage(scr->icon_tile);
2555 XFreePixmap(dpy, scr->icon_tile_pixmap);
2558 scr->icon_tile = img;
2560 /* put the icon in the noticeboard hint */
2561 PropSetIconTileHint(scr, img);
2563 if (!wPreferences.flags.noclip || wPreferences.flags.clip_merged_in_dock) {
2564 if (scr->clip_tile) {
2565 RReleaseImage(scr->clip_tile);
2567 scr->clip_tile = wClipMakeTile(img);
2570 if (!wPreferences.flags.nodrawer) {
2571 if (scr->drawer_tile) {
2572 RReleaseImage(scr->drawer_tile);
2574 scr->drawer_tile = wDrawerMakeTile(scr, img);
2577 scr->icon_tile_pixmap = pixmap;
2579 if (scr->def_icon_rimage) {
2580 RReleaseImage(scr->def_icon_rimage);
2581 scr->def_icon_rimage = NULL;
2584 if (scr->icon_back_texture)
2585 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2587 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2589 /* Free the texture as nobody else will use it, nor refer to it. */
2590 if (!entry->addr)
2591 wTextureDestroy(scr, *texture);
2593 return (reset ? REFRESH_ICON_TILE : 0);
2596 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2598 WMFont *font = tdata;
2600 /* Parameter not used, but tell the compiler that it is ok */
2601 (void) entry;
2602 (void) foo;
2604 if (scr->title_font) {
2605 WMReleaseFont(scr->title_font);
2607 scr->title_font = font;
2609 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2612 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2614 WMFont *font = tdata;
2616 /* Parameter not used, but tell the compiler that it is ok */
2617 (void) entry;
2618 (void) foo;
2620 if (scr->menu_title_font) {
2621 WMReleaseFont(scr->menu_title_font);
2624 scr->menu_title_font = font;
2626 return REFRESH_MENU_TITLE_FONT;
2629 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2631 WMFont *font = tdata;
2633 /* Parameter not used, but tell the compiler that it is ok */
2634 (void) entry;
2635 (void) foo;
2637 if (scr->menu_entry_font) {
2638 WMReleaseFont(scr->menu_entry_font);
2640 scr->menu_entry_font = font;
2642 return REFRESH_MENU_FONT;
2645 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2647 WMFont *font = tdata;
2649 /* Parameter not used, but tell the compiler that it is ok */
2650 (void) entry;
2651 (void) foo;
2653 if (scr->icon_title_font) {
2654 WMReleaseFont(scr->icon_title_font);
2657 scr->icon_title_font = font;
2659 return REFRESH_ICON_FONT;
2662 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2664 WMFont *font = tdata;
2666 /* Parameter not used, but tell the compiler that it is ok */
2667 (void) entry;
2668 (void) foo;
2670 if (scr->clip_title_font) {
2671 WMReleaseFont(scr->clip_title_font);
2674 scr->clip_title_font = font;
2676 return REFRESH_ICON_FONT;
2679 static int setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2681 WMFont *font = tdata;
2683 /* Parameter not used, but tell the compiler that it is ok */
2684 (void) scr;
2685 (void) entry;
2686 (void) foo;
2688 if (w_global.workspace.font_for_name)
2689 WMReleaseFont(w_global.workspace.font_for_name);
2691 w_global.workspace.font_for_name = font;
2693 return 0;
2696 static int setHightlight(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2698 XColor *color = tdata;
2700 /* Parameter not used, but tell the compiler that it is ok */
2701 (void) entry;
2702 (void) foo;
2704 if (scr->select_color)
2705 WMReleaseColor(scr->select_color);
2707 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2709 wFreeColor(scr, color->pixel);
2711 return REFRESH_MENU_COLOR;
2714 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2716 XColor *color = tdata;
2718 /* Parameter not used, but tell the compiler that it is ok */
2719 (void) entry;
2720 (void) foo;
2722 if (scr->select_text_color)
2723 WMReleaseColor(scr->select_text_color);
2725 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2727 wFreeColor(scr, color->pixel);
2729 return REFRESH_MENU_COLOR;
2732 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2734 XColor *color = tdata;
2735 long widx = (long) extra_data;
2737 /* Parameter not used, but tell the compiler that it is ok */
2738 (void) entry;
2740 if (scr->clip_title_color[widx])
2741 WMReleaseColor(scr->clip_title_color[widx]);
2743 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2744 wFreeColor(scr, color->pixel);
2746 return REFRESH_ICON_TITLE_COLOR;
2749 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2751 XColor *color = tdata;
2752 long widx = (long) extra_data;
2754 /* Parameter not used, but tell the compiler that it is ok */
2755 (void) entry;
2757 if (scr->window_title_color[widx])
2758 WMReleaseColor(scr->window_title_color[widx]);
2760 scr->window_title_color[widx] =
2761 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2763 wFreeColor(scr, color->pixel);
2765 return REFRESH_WINDOW_TITLE_COLOR;
2768 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
2770 XColor *color = tdata;
2772 /* Parameter not used, but tell the compiler that it is ok */
2773 (void) entry;
2774 (void) extra_data;
2776 if (scr->menu_title_color[0])
2777 WMReleaseColor(scr->menu_title_color[0]);
2779 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2781 wFreeColor(scr, color->pixel);
2783 return REFRESH_MENU_TITLE_COLOR;
2786 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2788 XColor *color = tdata;
2790 /* Parameter not used, but tell the compiler that it is ok */
2791 (void) entry;
2792 (void) foo;
2794 if (scr->mtext_color)
2795 WMReleaseColor(scr->mtext_color);
2797 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2799 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2800 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2801 } else {
2802 WMSetColorAlpha(scr->dtext_color, 0xffff);
2805 wFreeColor(scr, color->pixel);
2807 return REFRESH_MENU_COLOR;
2810 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2812 XColor *color = tdata;
2814 /* Parameter not used, but tell the compiler that it is ok */
2815 (void) entry;
2816 (void) foo;
2818 if (scr->dtext_color)
2819 WMReleaseColor(scr->dtext_color);
2821 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2823 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2824 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2825 } else {
2826 WMSetColorAlpha(scr->dtext_color, 0xffff);
2829 wFreeColor(scr, color->pixel);
2831 return REFRESH_MENU_COLOR;
2834 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2836 XColor *color = tdata;
2838 /* Parameter not used, but tell the compiler that it is ok */
2839 (void) entry;
2840 (void) foo;
2842 if (scr->icon_title_color)
2843 WMReleaseColor(scr->icon_title_color);
2844 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2846 wFreeColor(scr, color->pixel);
2848 return REFRESH_ICON_TITLE_COLOR;
2851 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2853 XColor *color = tdata;
2855 /* Parameter not used, but tell the compiler that it is ok */
2856 (void) entry;
2857 (void) foo;
2859 if (scr->icon_title_texture) {
2860 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2862 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2864 return REFRESH_ICON_TITLE_BACK;
2867 static int setFrameBorderWidth(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2869 int *value = tdata;
2871 /* Parameter not used, but tell the compiler that it is ok */
2872 (void) entry;
2873 (void) foo;
2875 scr->frame_border_width = *value;
2877 return REFRESH_FRAME_BORDER;
2880 static int setFrameBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2882 XColor *color = tdata;
2884 /* Parameter not used, but tell the compiler that it is ok */
2885 (void) entry;
2886 (void) foo;
2888 if (scr->frame_border_color)
2889 WMReleaseColor(scr->frame_border_color);
2890 scr->frame_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2892 wFreeColor(scr, color->pixel);
2894 return REFRESH_FRAME_BORDER;
2897 static int setFrameFocusedBorderColor(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
2899 XColor *color = tdata;
2901 /* Parameter not used, but tell the compiler that it is ok */
2902 (void) entry;
2903 (void) foo;
2905 if (scr->frame_focused_border_color)
2906 WMReleaseColor(scr->frame_focused_border_color);
2907 scr->frame_focused_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2909 wFreeColor(scr, color->pixel);
2911 return REFRESH_FRAME_BORDER;
2914 static int setFrameSelectedBorderColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
2916 XColor *color = tdata;
2918 /* Parameter not used, but tell the compiler that it is ok */
2919 (void) entry;
2920 (void) foo;
2922 if (scr->frame_selected_border_color)
2923 WMReleaseColor(scr->frame_selected_border_color);
2924 scr->frame_selected_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2926 wFreeColor(scr, color->pixel);
2928 return REFRESH_FRAME_BORDER;
2931 static void trackDeadProcess(pid_t pid, unsigned int status, void *client_data)
2933 WScreen *scr = (WScreen *) client_data;
2935 /* Parameter not used, but tell the compiler that it is ok */
2936 (void) pid;
2937 (void) status;
2939 close(scr->helper_fd);
2940 scr->helper_fd = 0;
2941 scr->helper_pid = 0;
2942 scr->flags.backimage_helper_launched = 0;
2945 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
2947 WMPropList *value = tdata;
2948 WMPropList *val;
2949 char *str;
2950 int i;
2952 /* Parameter not used, but tell the compiler that it is ok */
2953 (void) entry;
2954 (void) bar;
2956 if (scr->flags.backimage_helper_launched) {
2957 if (WMGetPropListItemCount(value) == 0) {
2958 SendHelperMessage(scr, 'C', 0, NULL);
2959 SendHelperMessage(scr, 'K', 0, NULL);
2961 WMReleasePropList(value);
2962 return 0;
2964 } else {
2965 pid_t pid;
2966 int filedes[2];
2968 if (WMGetPropListItemCount(value) == 0)
2969 return 0;
2971 if (pipe(filedes) < 0) {
2972 werror("pipe() failed:can't set workspace specific background image");
2974 WMReleasePropList(value);
2975 return 0;
2978 pid = fork();
2979 if (pid < 0) {
2980 werror("fork() failed:can't set workspace specific background image");
2981 if (close(filedes[0]) < 0)
2982 werror("could not close pipe");
2983 if (close(filedes[1]) < 0)
2984 werror("could not close pipe");
2986 } else if (pid == 0) {
2987 char *dither;
2989 SetupEnvironment(scr);
2991 if (close(0) < 0)
2992 werror("could not close pipe");
2993 if (dup(filedes[0]) < 0) {
2994 werror("dup() failed:can't set workspace specific background image");
2996 dither = wPreferences.no_dithering ? "-m" : "-d";
2997 if (wPreferences.smooth_workspace_back)
2998 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2999 else
3000 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3001 werror("could not execute wmsetbg");
3002 exit(1);
3003 } else {
3005 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3006 werror("error setting close-on-exec flag");
3008 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3009 werror("error setting close-on-exec flag");
3012 scr->helper_fd = filedes[1];
3013 scr->helper_pid = pid;
3014 scr->flags.backimage_helper_launched = 1;
3016 wAddDeathHandler(pid, trackDeadProcess, scr);
3018 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3023 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3024 val = WMGetFromPLArray(value, i);
3025 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
3026 str = WMGetPropListDescription(val, False);
3028 SendHelperMessage(scr, 'S', i + 1, str);
3030 wfree(str);
3031 } else {
3032 SendHelperMessage(scr, 'U', i + 1, NULL);
3035 sleep(1);
3037 WMReleasePropList(value);
3038 return 0;
3041 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
3043 WMPropList *value = tdata;
3045 /* Parameter not used, but tell the compiler that it is ok */
3046 (void) entry;
3047 (void) bar;
3049 if (scr->flags.backimage_helper_launched) {
3050 char *str;
3052 if (WMGetPropListItemCount(value) == 0) {
3053 SendHelperMessage(scr, 'U', 0, NULL);
3054 } else {
3055 /* set the default workspace background to this one */
3056 str = WMGetPropListDescription(value, False);
3057 if (str) {
3058 SendHelperMessage(scr, 'S', 0, str);
3059 wfree(str);
3060 SendHelperMessage(scr, 'C', w_global.workspace.current + 1, NULL);
3061 } else {
3062 SendHelperMessage(scr, 'U', 0, NULL);
3065 } else if (WMGetPropListItemCount(value) > 0) {
3066 char *command;
3067 char *text;
3068 char *dither;
3069 int len;
3071 text = WMGetPropListDescription(value, False);
3072 len = strlen(text) + 40;
3073 command = wmalloc(len);
3074 dither = wPreferences.no_dithering ? "-m" : "-d";
3075 if (wPreferences.smooth_workspace_back)
3076 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3077 else
3078 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3079 wfree(text);
3080 ExecuteShellCommand(scr, command);
3081 wfree(command);
3083 WMReleasePropList(value);
3085 return 0;
3088 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3090 WTexture **texture = tdata;
3092 /* Parameter not used, but tell the compiler that it is ok */
3093 (void) entry;
3094 (void) foo;
3096 if (scr->widget_texture) {
3097 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3099 scr->widget_texture = *(WTexSolid **) texture;
3101 return 0;
3104 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3106 WTexture **texture = tdata;
3108 /* Parameter not used, but tell the compiler that it is ok */
3109 (void) entry;
3110 (void) foo;
3112 if (scr->window_title_texture[WS_FOCUSED]) {
3113 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3115 scr->window_title_texture[WS_FOCUSED] = *texture;
3117 return REFRESH_WINDOW_TEXTURES;
3120 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3122 WTexture **texture = tdata;
3124 /* Parameter not used, but tell the compiler that it is ok */
3125 (void) entry;
3126 (void) foo;
3128 if (scr->window_title_texture[WS_PFOCUSED]) {
3129 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3131 scr->window_title_texture[WS_PFOCUSED] = *texture;
3133 return REFRESH_WINDOW_TEXTURES;
3136 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3138 WTexture **texture = tdata;
3140 /* Parameter not used, but tell the compiler that it is ok */
3141 (void) entry;
3142 (void) foo;
3144 if (scr->window_title_texture[WS_UNFOCUSED]) {
3145 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3147 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3149 return REFRESH_WINDOW_TEXTURES;
3152 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3154 WTexture **texture = tdata;
3156 /* Parameter not used, but tell the compiler that it is ok */
3157 (void) entry;
3158 (void) foo;
3160 if (scr->resizebar_texture[0]) {
3161 wTextureDestroy(scr, scr->resizebar_texture[0]);
3163 scr->resizebar_texture[0] = *texture;
3165 return REFRESH_WINDOW_TEXTURES;
3168 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3170 WTexture **texture = tdata;
3172 /* Parameter not used, but tell the compiler that it is ok */
3173 (void) entry;
3174 (void) foo;
3176 if (scr->menu_title_texture[0]) {
3177 wTextureDestroy(scr, scr->menu_title_texture[0]);
3179 scr->menu_title_texture[0] = *texture;
3181 return REFRESH_MENU_TITLE_TEXTURE;
3184 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3186 WTexture **texture = tdata;
3188 /* Parameter not used, but tell the compiler that it is ok */
3189 (void) entry;
3190 (void) foo;
3192 if (scr->menu_item_texture) {
3193 wTextureDestroy(scr, scr->menu_item_texture);
3194 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3196 scr->menu_item_texture = *texture;
3198 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3200 return REFRESH_MENU_TEXTURE;
3203 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3205 WShortKey *shortcut = tdata;
3206 WWindow *wwin;
3207 long widx = (long) extra_data;
3209 /* Parameter not used, but tell the compiler that it is ok */
3210 (void) entry;
3212 wKeyBindings[widx] = *shortcut;
3214 wwin = scr->focused_window;
3216 while (wwin != NULL) {
3217 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3219 if (!WFLAGP(wwin, no_bind_keys)) {
3220 wWindowSetKeyGrabs(wwin);
3222 wwin = wwin->prev;
3225 /* do we need to update window menus? */
3226 if (widx >= WKBD_WORKSPACE1 && widx <= WKBD_WORKSPACE10)
3227 return REFRESH_WORKSPACE_MENU;
3228 if (widx == WKBD_LASTWORKSPACE)
3229 return REFRESH_WORKSPACE_MENU;
3230 if (widx >= WKBD_MOVE_WORKSPACE1 && widx <= WKBD_MOVE_WORKSPACE10)
3231 return REFRESH_WORKSPACE_MENU;
3233 return 0;
3236 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3238 /* Parameter not used, but tell the compiler that it is ok */
3239 (void) entry;
3240 (void) bar;
3241 (void) foo;
3243 wScreenUpdateUsableArea(scr);
3244 wArrangeIcons(scr, True);
3246 return 0;
3249 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3251 /* Parameter not used, but tell the compiler that it is ok */
3252 (void) entry;
3253 (void) bar;
3254 (void) foo;
3256 wScreenUpdateUsableArea(scr);
3258 return 0;
3261 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3263 /* Parameter not used, but tell the compiler that it is ok */
3264 (void) scr;
3265 (void) entry;
3266 (void) tdata;
3267 (void) foo;
3269 return REFRESH_MENU_TEXTURE;
3272 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3274 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3276 RCopyArea(img, image, x, y, w, h, 0, 0);
3278 return img;
3281 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3283 WMPropList *array = tdata;
3284 char *path;
3285 RImage *bgimage;
3286 int cwidth, cheight;
3287 struct WPreferences *prefs = foo;
3289 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3290 if (prefs->swtileImage)
3291 RReleaseImage(prefs->swtileImage);
3292 prefs->swtileImage = NULL;
3294 WMReleasePropList(array);
3295 return 0;
3298 switch (WMGetPropListItemCount(array)) {
3299 case 4:
3300 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3301 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3302 break;
3303 } else
3304 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3306 if (!path) {
3307 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3308 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3309 } else {
3310 bgimage = RLoadImage(scr->rcontext, path, 0);
3311 if (!bgimage) {
3312 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3313 wfree(path);
3314 } else {
3315 wfree(path);
3317 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3318 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3320 if (cwidth <= 0 || cheight <= 0 ||
3321 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3322 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3323 else {
3324 int i;
3325 int swidth, theight;
3326 for (i = 0; i < 9; i++) {
3327 if (prefs->swbackImage[i])
3328 RReleaseImage(prefs->swbackImage[i]);
3329 prefs->swbackImage[i] = NULL;
3331 swidth = (bgimage->width - cwidth) / 2;
3332 theight = (bgimage->height - cheight) / 2;
3334 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3335 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3336 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3337 swidth, theight);
3339 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3340 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3341 cwidth, cheight);
3342 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3343 swidth, cheight);
3345 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3346 swidth, theight);
3347 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3348 cwidth, theight);
3349 prefs->swbackImage[8] =
3350 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3351 theight);
3353 // check if anything failed
3354 for (i = 0; i < 9; i++) {
3355 if (!prefs->swbackImage[i]) {
3356 for (; i >= 0; --i) {
3357 RReleaseImage(prefs->swbackImage[i]);
3358 prefs->swbackImage[i] = NULL;
3360 break;
3364 RReleaseImage(bgimage);
3368 case 1:
3369 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3370 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3371 break;
3372 } else
3373 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3375 if (!path) {
3376 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3377 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3378 } else {
3379 if (prefs->swtileImage)
3380 RReleaseImage(prefs->swtileImage);
3382 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3383 if (!prefs->swtileImage) {
3384 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3386 wfree(path);
3388 break;
3390 default:
3391 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3392 break;
3395 WMReleasePropList(array);
3397 return 0;
3400 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, void *tdata, void *foo)
3402 WMPropList *array = tdata;
3403 int i;
3404 struct WPreferences *prefs = foo;
3406 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3407 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3408 WMReleasePropList(array);
3409 return 0;
3412 DestroyWindowMenu(scr);
3414 for (i = 0; i < 7; i++) {
3415 if (prefs->modifier_labels[i])
3416 wfree(prefs->modifier_labels[i]);
3418 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3419 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3420 } else {
3421 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3422 prefs->modifier_labels[i] = NULL;
3426 WMReleasePropList(array);
3428 return 0;
3431 static int setDoubleClick(WScreen *scr, WDefaultEntry *entry, void *tdata, void *foo)
3433 int *value = tdata;
3435 /* Parameter not used, but tell the compiler that it is ok */
3436 (void) entry;
3437 (void) scr;
3439 if (*value <= 0)
3440 *(int *)foo = 1;
3442 W_setconf_doubleClickDelay(*value);
3444 return 0;
3447 static int setCursor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *extra_data)
3449 Cursor *cursor = tdata;
3450 long widx = (long) extra_data;
3452 /* Parameter not used, but tell the compiler that it is ok */
3453 (void) entry;
3455 if (wPreferences.cursor[widx] != None) {
3456 XFreeCursor(dpy, wPreferences.cursor[widx]);
3459 wPreferences.cursor[widx] = *cursor;
3461 if (widx == WCUR_ROOT && *cursor != None) {
3462 XDefineCursor(dpy, scr->root_win, *cursor);
3465 return 0;