Shortcuts for moving windows between workspaces.
[wmaker-crm.git] / src / defaults.c
blob6c23064d8c161545d1b4f36fee9a48ce62e12971
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"
65 #define MAX_SHORTCUT_LENGTH 32
67 #ifndef GLOBAL_DEFAULTS_SUBDIR
68 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
69 #endif
71 /***** Global *****/
72 extern WDDomain *WDWindowMaker;
73 extern WDDomain *WDWindowAttributes;
74 extern WDDomain *WDRootMenu;
75 extern int wScreenCount;
76 extern WPreferences wPreferences;
77 extern WShortKey wKeyBindings[WKBD_LAST];
79 typedef struct {
80 char *key;
81 char *default_value;
82 void *extra_data;
83 void *addr;
84 int (*convert) ();
85 int (*update) ();
86 WMPropList *plkey;
87 WMPropList *plvalue; /* default value */
88 } WDefaultEntry;
90 /* used to map strings to integers */
91 typedef struct {
92 char *string;
93 short value;
94 char is_alias;
95 } WOptionEnumeration;
97 /* type converters */
98 static int getBool();
99 static int getInt();
100 static int getCoord();
101 static int getPathList();
102 static int getEnum();
103 static int getTexture();
104 static int getWSBackground();
105 static int getWSSpecificBackground();
106 static int getFont();
107 static int getColor();
108 static int getKeybind();
109 static int getModMask();
110 static int getPropList();
112 /* value setting functions */
113 static int setJustify();
114 static int setClearance();
115 static int setIfDockPresent();
116 static int setStickyIcons();
117 static int setWidgetColor();
118 static int setIconTile();
119 static int setWinTitleFont();
120 static int setMenuTitleFont();
121 static int setMenuTextFont();
122 static int setIconTitleFont();
123 static int setIconTitleColor();
124 static int setIconTitleBack();
125 static int setFrameBorderWidth();
126 static int setFrameBorderColor();
127 static int setFrameSelectedBorderColor();
128 static int setLargeDisplayFont();
129 static int setWTitleColor();
130 static int setFTitleBack();
131 static int setPTitleBack();
132 static int setUTitleBack();
133 static int setResizebarBack();
134 static int setWorkspaceBack();
135 static int setWorkspaceSpecificBack();
136 static int setMenuTitleColor();
137 static int setMenuTextColor();
138 static int setMenuDisabledColor();
139 static int setMenuTitleBack();
140 static int setMenuTextBack();
141 static int setHightlight();
142 static int setHightlightText();
143 static int setKeyGrab();
144 static int setDoubleClick();
145 static int setIconPosition();
147 static int setClipTitleFont();
148 static int setClipTitleColor();
150 static int setMenuStyle();
151 static int setSwPOptions();
152 static int updateUsableArea();
154 static int setModifierKeyLabels();
156 extern Cursor wCursor[WCUR_LAST];
157 static int getCursor();
158 static int setCursor();
161 * Tables to convert strings to enumeration values.
162 * Values stored are char
165 /* WARNING: sum of length of all value strings must not exceed
166 * this value */
167 #define TOTAL_VALUES_LENGTH 80
169 #define REFRESH_WINDOW_TEXTURES (1<<0)
170 #define REFRESH_MENU_TEXTURE (1<<1)
171 #define REFRESH_MENU_FONT (1<<2)
172 #define REFRESH_MENU_COLOR (1<<3)
173 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
174 #define REFRESH_MENU_TITLE_FONT (1<<5)
175 #define REFRESH_MENU_TITLE_COLOR (1<<6)
176 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
177 #define REFRESH_WINDOW_FONT (1<<8)
178 #define REFRESH_ICON_TILE (1<<9)
179 #define REFRESH_ICON_FONT (1<<10)
180 #define REFRESH_WORKSPACE_BACK (1<<11)
182 #define REFRESH_BUTTON_IMAGES (1<<12)
184 #define REFRESH_ICON_TITLE_COLOR (1<<13)
185 #define REFRESH_ICON_TITLE_BACK (1<<14)
187 #define REFRESH_WORKSPACE_MENU (1<<15)
189 #define REFRESH_FRAME_BORDER REFRESH_MENU_FONT|REFRESH_WINDOW_FONT
191 static WOptionEnumeration seFocusModes[] = {
192 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
193 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
194 {NULL, 0, 0}
197 static WOptionEnumeration seTitlebarModes[] = {
198 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
199 {"next", TS_NEXT, 0}, {NULL, 0, 0}
202 static WOptionEnumeration seColormapModes[] = {
203 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
204 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
205 {NULL, 0, 0}
208 static WOptionEnumeration sePlacements[] = {
209 {"Auto", WPM_AUTO, 0},
210 {"Smart", WPM_SMART, 0},
211 {"Cascade", WPM_CASCADE, 0},
212 {"Random", WPM_RANDOM, 0},
213 {"Manual", WPM_MANUAL, 0},
214 {"Center", WPM_CENTER, 0},
215 {NULL, 0, 0}
218 static WOptionEnumeration seGeomDisplays[] = {
219 {"None", WDIS_NONE, 0},
220 {"Center", WDIS_CENTER, 0},
221 {"Corner", WDIS_TOPLEFT, 0},
222 {"Floating", WDIS_FRAME_CENTER, 0},
223 {"Line", WDIS_NEW, 0},
224 {NULL, 0, 0}
227 static WOptionEnumeration seSpeeds[] = {
228 {"UltraFast", SPEED_ULTRAFAST, 0},
229 {"Fast", SPEED_FAST, 0},
230 {"Medium", SPEED_MEDIUM, 0},
231 {"Slow", SPEED_SLOW, 0},
232 {"UltraSlow", SPEED_ULTRASLOW, 0},
233 {NULL, 0, 0}
236 static WOptionEnumeration seMouseButtonActions[] = {
237 {"None", WA_NONE, 0},
238 {"SelectWindows", WA_SELECT_WINDOWS, 0},
239 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
240 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
241 {NULL, 0, 0}
244 static WOptionEnumeration seMouseWheelActions[] = {
245 {"None", WA_NONE, 0},
246 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
247 {NULL, 0, 0}
250 static WOptionEnumeration seIconificationStyles[] = {
251 {"Zoom", WIS_ZOOM, 0},
252 {"Twist", WIS_TWIST, 0},
253 {"Flip", WIS_FLIP, 0},
254 {"None", WIS_NONE, 0},
255 {"random", WIS_RANDOM, 0},
256 {NULL, 0, 0}
259 static WOptionEnumeration seJustifications[] = {
260 {"Left", WTJ_LEFT, 0},
261 {"Center", WTJ_CENTER, 0},
262 {"Right", WTJ_RIGHT, 0},
263 {NULL, 0, 0}
266 static WOptionEnumeration seIconPositions[] = {
267 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
268 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
269 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
270 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
271 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
272 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
273 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
274 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
275 {NULL, 0, 0}
278 static WOptionEnumeration seMenuStyles[] = {
279 {"normal", MS_NORMAL, 0},
280 {"singletexture", MS_SINGLE_TEXTURE, 0},
281 {"flat", MS_FLAT, 0},
282 {NULL, 0, 0}
285 static WOptionEnumeration seDisplayPositions[] = {
286 {"none", WD_NONE, 0},
287 {"center", WD_CENTER, 0},
288 {"top", WD_TOP, 0},
289 {"bottom", WD_BOTTOM, 0},
290 {"topleft", WD_TOPLEFT, 0},
291 {"topright", WD_TOPRIGHT, 0},
292 {"bottomleft", WD_BOTTOMLEFT, 0},
293 {"bottomright", WD_BOTTOMRIGHT, 0},
294 {NULL, 0, 0}
297 static WOptionEnumeration seWorkspaceBorder[] = {
298 {"None", WB_NONE, 0},
299 {"LeftRight", WB_LEFTRIGHT, 0},
300 {"TopBottom", WB_TOPBOTTOM, 0},
301 {"AllDirections", WB_ALLDIRS, 0},
302 {NULL, 0, 0}
306 * ALL entries in the tables bellow, NEED to have a default value
307 * defined, and this value needs to be correct.
310 /* these options will only affect the window manager on startup
312 * static defaults can't access the screen data, because it is
313 * created after these defaults are read
315 WDefaultEntry staticOptionList[] = {
317 {"ColormapSize", "4", NULL,
318 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
319 {"DisableDithering", "NO", NULL,
320 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
321 {"IconSize", "64", NULL,
322 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
323 {"ModifierKey", "Mod1", NULL,
324 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
325 {"DisableWSMouseActions", "NO", NULL,
326 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
327 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
328 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
329 {"NewStyle", "new", seTitlebarModes,
330 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
331 {"DisableDock", "NO", (void *)WM_DOCK,
332 NULL, getBool, setIfDockPresent, NULL, NULL},
333 {"DisableClip", "NO", (void *)WM_CLIP,
334 NULL, getBool, setIfDockPresent, NULL, NULL},
335 {"DisableMiniwindows", "NO", NULL,
336 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
339 #define NUM2STRING_(x) #x
340 #define NUM2STRING(x) NUM2STRING_(x)
342 WDefaultEntry optionList[] = {
344 /* dynamic options */
346 {"IconPosition", "blh", seIconPositions,
347 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
348 {"IconificationStyle", "Zoom", seIconificationStyles,
349 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
350 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
351 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
352 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
353 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
354 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
355 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
356 {"MouseWheelAction", "None", seMouseWheelActions,
357 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
358 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
359 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
360 {"IconPath", DEF_ICON_PATHS, NULL,
361 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
362 {"ColormapMode", "auto", seColormapModes,
363 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
364 {"AutoFocus", "NO", NULL,
365 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
366 {"RaiseDelay", "0", NULL,
367 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
368 {"CirculateRaise", "NO", NULL,
369 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
370 {"Superfluous", "NO", NULL,
371 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
372 {"AdvanceToNewWorkspace", "NO", NULL,
373 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
374 {"CycleWorkspaces", "NO", NULL,
375 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
376 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
377 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
378 {"WorkspaceBorder", "None", seWorkspaceBorder,
379 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
380 {"WorkspaceBorderSize", "0", NULL,
381 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
382 {"StickyIcons", "NO", NULL,
383 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
384 {"SaveSessionOnExit", "NO", NULL,
385 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
386 {"WrapMenus", "NO", NULL,
387 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
388 {"ScrollableMenus", "NO", NULL,
389 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
390 {"MenuScrollSpeed", "medium", seSpeeds,
391 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
392 {"IconSlideSpeed", "medium", seSpeeds,
393 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
394 {"ShadeSpeed", "medium", seSpeeds,
395 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
396 {"BounceAppIconsWhenUrgent", "YES", NULL,
397 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
398 {"RaiseAppIconsWhenBouncing", "NO", NULL,
399 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
400 {"DoNotMakeAppIconsBounce", "NO", NULL,
401 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
402 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
403 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
404 {"AlignSubmenus", "NO", NULL,
405 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
406 {"ViKeyMenus", "NO", NULL,
407 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
408 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
409 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
410 {"WindowPlacement", "auto", sePlacements,
411 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
412 {"IgnoreFocusClick", "NO", NULL,
413 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
414 {"UseSaveUnders", "NO", NULL,
415 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
416 {"OpaqueMove", "NO", NULL,
417 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
418 {"OpaqueResize", "NO", NULL,
419 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
420 {"OpaqueMoveResizeKeyboard", "NO", NULL,
421 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
422 {"DisableAnimations", "NO", NULL,
423 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
424 {"DontLinkWorkspaces", "NO", NULL,
425 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
426 {"HighlightActiveApp", "YES", NULL,
427 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
428 {"AutoArrangeIcons", "NO", NULL,
429 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
430 {"NoWindowOverDock", "NO", NULL,
431 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
432 {"NoWindowOverIcons", "NO", NULL,
433 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
434 {"WindowPlaceOrigin", "(0, 0)", NULL,
435 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
436 {"ResizeDisplay", "corner", seGeomDisplays,
437 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
438 {"MoveDisplay", "corner", seGeomDisplays,
439 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
440 {"DontConfirmKill", "NO", NULL,
441 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
442 {"WindowTitleBalloons", "NO", NULL,
443 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
444 {"MiniwindowTitleBalloons", "NO", NULL,
445 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
446 {"AppIconBalloons", "NO", NULL,
447 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
448 {"HelpBalloons", "NO", NULL,
449 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
450 {"EdgeResistance", "30", NULL,
451 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
452 {"ResizeIncrement", "0", NULL,
453 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
454 {"Attraction", "NO", NULL,
455 &wPreferences.attract, getBool, NULL, NULL, NULL},
456 {"DisableBlinking", "NO", NULL,
457 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
458 {"SingleClickLaunch", "NO", NULL,
459 &wPreferences.single_click, getBool, NULL, NULL, NULL},
461 /* style options */
463 {"MenuStyle", "normal", seMenuStyles,
464 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
465 {"WidgetColor", "(solid, gray)", NULL,
466 NULL, getTexture, setWidgetColor, NULL, NULL},
467 {"WorkspaceSpecificBack", "()", NULL,
468 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
469 /* WorkspaceBack must come after WorkspaceSpecificBack or
470 * WorkspaceBack wont know WorkspaceSpecificBack was also
471 * specified and 2 copies of wmsetbg will be launched */
472 {"WorkspaceBack", "(solid, black)", NULL,
473 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
474 {"SmoothWorkspaceBack", "NO", NULL,
475 NULL, getBool, NULL, NULL, NULL},
476 {"IconBack", "(solid, gray)", NULL,
477 NULL, getTexture, setIconTile, NULL, NULL},
478 {"TitleJustify", "center", seJustifications,
479 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
480 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
481 NULL, getFont, setWinTitleFont, NULL, NULL},
482 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
483 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
484 {"WindowTitleMinHeight", "0", NULL,
485 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
486 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
487 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
488 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
489 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
490 {"MenuTitleMinHeight", "0", NULL,
491 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
492 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
493 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
494 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
495 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
496 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
497 NULL, getFont, setMenuTitleFont, NULL, NULL},
498 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
499 NULL, getFont, setMenuTextFont, NULL, NULL},
500 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
501 NULL, getFont, setIconTitleFont, NULL, NULL},
502 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
503 NULL, getFont, setClipTitleFont, NULL, NULL},
504 {"ShowClipTitle", "YES", NULL,
505 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
506 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
507 NULL, getFont, setLargeDisplayFont, NULL, NULL},
508 {"HighlightColor", "white", NULL,
509 NULL, getColor, setHightlight, NULL, NULL},
510 {"HighlightTextColor", "black", NULL,
511 NULL, getColor, setHightlightText, NULL, NULL},
512 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
513 NULL, getColor, setClipTitleColor, NULL, NULL},
514 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
515 NULL, getColor, setClipTitleColor, NULL, NULL},
516 {"FTitleColor", "white", (void *)WS_FOCUSED,
517 NULL, getColor, setWTitleColor, NULL, NULL},
518 {"PTitleColor", "white", (void *)WS_PFOCUSED,
519 NULL, getColor, setWTitleColor, NULL, NULL},
520 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
521 NULL, getColor, setWTitleColor, NULL, NULL},
522 {"FTitleBack", "(solid, black)", NULL,
523 NULL, getTexture, setFTitleBack, NULL, NULL},
524 {"PTitleBack", "(solid, \"#616161\")", NULL,
525 NULL, getTexture, setPTitleBack, NULL, NULL},
526 {"UTitleBack", "(solid, gray)", NULL,
527 NULL, getTexture, setUTitleBack, NULL, NULL},
528 {"ResizebarBack", "(solid, gray)", NULL,
529 NULL, getTexture, setResizebarBack, NULL, NULL},
530 {"MenuTitleColor", "white", NULL,
531 NULL, getColor, setMenuTitleColor, NULL, NULL},
532 {"MenuTextColor", "black", NULL,
533 NULL, getColor, setMenuTextColor, NULL, NULL},
534 {"MenuDisabledColor", "\"#616161\"", NULL,
535 NULL, getColor, setMenuDisabledColor, NULL, NULL},
536 {"MenuTitleBack", "(solid, black)", NULL,
537 NULL, getTexture, setMenuTitleBack, NULL, NULL},
538 {"MenuTextBack", "(solid, gray)", NULL,
539 NULL, getTexture, setMenuTextBack, NULL, NULL},
540 {"IconTitleColor", "white", NULL,
541 NULL, getColor, setIconTitleColor, NULL, NULL},
542 {"IconTitleBack", "black", NULL,
543 NULL, getColor, setIconTitleBack, NULL, NULL},
544 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
545 NULL, getPropList, setSwPOptions, NULL, NULL},
546 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
547 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
548 {"FrameBorderWidth", "1", NULL,
549 NULL, getInt, setFrameBorderWidth, NULL, NULL},
550 {"FrameBorderColor", "black", NULL,
551 NULL, getColor, setFrameBorderColor, NULL, NULL},
552 {"FrameSelectedBorderColor", "white", NULL,
553 NULL, getColor, setFrameSelectedBorderColor, NULL, NULL},
555 /* keybindings */
557 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
558 NULL, getKeybind, setKeyGrab, NULL, NULL},
559 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
560 NULL, getKeybind, setKeyGrab, NULL, NULL},
561 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
562 NULL, getKeybind, setKeyGrab, NULL, NULL},
563 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
564 NULL, getKeybind, setKeyGrab, NULL, NULL},
565 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
566 NULL, getKeybind, setKeyGrab, NULL, NULL},
567 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
568 NULL, getKeybind, setKeyGrab, NULL, NULL},
569 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
570 NULL, getKeybind, setKeyGrab, NULL, NULL },
571 {"HideKey", "None", (void *)WKBD_HIDE,
572 NULL, getKeybind, setKeyGrab, NULL, NULL},
573 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
574 NULL, getKeybind, setKeyGrab, NULL, NULL},
575 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
576 NULL, getKeybind, setKeyGrab, NULL, NULL},
577 {"CloseKey", "None", (void *)WKBD_CLOSE,
578 NULL, getKeybind, setKeyGrab, NULL, NULL},
579 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
580 NULL, getKeybind, setKeyGrab, NULL, NULL},
581 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
582 NULL, getKeybind, setKeyGrab, NULL, NULL},
583 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
584 NULL, getKeybind, setKeyGrab, NULL, NULL},
585 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
586 NULL, getKeybind, setKeyGrab, NULL, NULL},
587 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
588 NULL, getKeybind, setKeyGrab, NULL, NULL},
589 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
590 NULL, getKeybind, setKeyGrab, NULL, NULL},
591 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
592 NULL, getKeybind, setKeyGrab, NULL, NULL},
593 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
594 NULL, getKeybind, setKeyGrab, NULL, NULL},
595 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
596 NULL, getKeybind, setKeyGrab, NULL, NULL},
597 {"ShadeKey", "None", (void *)WKBD_SHADE,
598 NULL, getKeybind, setKeyGrab, NULL, NULL},
599 {"SelectKey", "None", (void *)WKBD_SELECT,
600 NULL, getKeybind, setKeyGrab, NULL, NULL},
601 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
602 NULL, getKeybind, setKeyGrab, NULL, NULL},
603 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
604 NULL, getKeybind, setKeyGrab, NULL, NULL},
605 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
606 NULL, getKeybind, setKeyGrab, NULL, NULL},
607 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
608 NULL, getKeybind, setKeyGrab, NULL, NULL},
609 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
610 NULL, getKeybind, setKeyGrab, NULL, NULL},
611 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
612 NULL, getKeybind, setKeyGrab, NULL, NULL},
613 {"LastWorkspaceKey", "None", (void *)WKBD_LASTWORKSPACE,
614 NULL, getKeybind, setKeyGrab, NULL, NULL},
615 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
616 NULL, getKeybind, setKeyGrab, NULL, NULL},
617 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
618 NULL, getKeybind, setKeyGrab, NULL, NULL},
619 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
620 NULL, getKeybind, setKeyGrab, NULL, NULL},
621 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
622 NULL, getKeybind, setKeyGrab, NULL, NULL},
623 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
624 NULL, getKeybind, setKeyGrab, NULL, NULL},
625 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
626 NULL, getKeybind, setKeyGrab, NULL, NULL},
627 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
628 NULL, getKeybind, setKeyGrab, NULL, NULL},
629 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
630 NULL, getKeybind, setKeyGrab, NULL, NULL},
631 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
632 NULL, getKeybind, setKeyGrab, NULL, NULL},
633 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
634 NULL, getKeybind, setKeyGrab, NULL, NULL},
635 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
636 NULL, getKeybind, setKeyGrab, NULL, NULL},
637 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
638 NULL, getKeybind, setKeyGrab, NULL, NULL},
639 {"MoveToWorkspace1Key", "None", (void *)WKBD_MOVE_WORKSPACE1,
640 NULL, getKeybind, setKeyGrab, NULL, NULL},
641 {"MoveToWorkspace2Key", "None", (void *)WKBD_MOVE_WORKSPACE2,
642 NULL, getKeybind, setKeyGrab, NULL, NULL},
643 {"MoveToWorkspace3Key", "None", (void *)WKBD_MOVE_WORKSPACE3,
644 NULL, getKeybind, setKeyGrab, NULL, NULL},
645 {"MoveToWorkspace4Key", "None", (void *)WKBD_MOVE_WORKSPACE4,
646 NULL, getKeybind, setKeyGrab, NULL, NULL},
647 {"MoveToWorkspace5Key", "None", (void *)WKBD_MOVE_WORKSPACE5,
648 NULL, getKeybind, setKeyGrab, NULL, NULL},
649 {"MoveToWorkspace6Key", "None", (void *)WKBD_MOVE_WORKSPACE6,
650 NULL, getKeybind, setKeyGrab, NULL, NULL},
651 {"MoveToWorkspace7Key", "None", (void *)WKBD_MOVE_WORKSPACE7,
652 NULL, getKeybind, setKeyGrab, NULL, NULL},
653 {"MoveToWorkspace8Key", "None", (void *)WKBD_MOVE_WORKSPACE8,
654 NULL, getKeybind, setKeyGrab, NULL, NULL},
655 {"MoveToWorkspace9Key", "None", (void *)WKBD_MOVE_WORKSPACE9,
656 NULL, getKeybind, setKeyGrab, NULL, NULL},
657 {"MoveToWorkspace10Key", "None", (void *)WKBD_MOVE_WORKSPACE10,
658 NULL, getKeybind, setKeyGrab, NULL, NULL},
659 {"MoveToNextWorkspaceKey", "None", (void *)WKBD_MOVE_NEXTWORKSPACE,
660 NULL, getKeybind, setKeyGrab, NULL, NULL},
661 {"MoveToPrevWorkspaceKey", "None", (void *)WKBD_MOVE_PREVWORKSPACE,
662 NULL, getKeybind, setKeyGrab, NULL, NULL},
663 {"MoveToLastWorkspaceKey", "None", (void *)WKBD_MOVE_LASTWORKSPACE,
664 NULL, getKeybind, setKeyGrab, NULL, NULL},
665 {"MoveToNextWorkspaceLayerKey", "None", (void *)WKBD_MOVE_NEXTWSLAYER,
666 NULL, getKeybind, setKeyGrab, NULL, NULL},
667 {"MoveToPrevWorkspaceLayerKey", "None", (void *)WKBD_MOVE_PREVWSLAYER,
668 NULL, getKeybind, setKeyGrab, NULL, NULL},
669 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
670 NULL, getKeybind, setKeyGrab, NULL, NULL},
671 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
672 NULL, getKeybind, setKeyGrab, NULL, NULL},
673 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
674 NULL, getKeybind, setKeyGrab, NULL, NULL},
675 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
676 NULL, getKeybind, setKeyGrab, NULL, NULL},
677 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
678 NULL, getKeybind, setKeyGrab, NULL, NULL},
679 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
680 NULL, getKeybind, setKeyGrab, NULL, NULL},
681 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
682 NULL, getKeybind, setKeyGrab, NULL, NULL},
683 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
684 NULL, getKeybind, setKeyGrab, NULL, NULL},
685 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
686 NULL, getKeybind, setKeyGrab, NULL, NULL},
687 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
688 NULL, getKeybind, setKeyGrab, NULL, NULL},
689 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
690 NULL, getKeybind, setKeyGrab, NULL, NULL},
691 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
692 NULL, getKeybind, setKeyGrab, NULL, NULL},
694 #ifdef KEEP_XKB_LOCK_STATUS
695 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
696 NULL, getKeybind, setKeyGrab, NULL, NULL},
697 {"KbdModeLock", "NO", NULL,
698 &wPreferences.modelock, getBool, NULL, NULL, NULL},
699 #endif /* KEEP_XKB_LOCK_STATUS */
701 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
702 NULL, getCursor, setCursor, NULL, NULL},
703 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
704 NULL, getCursor, setCursor, NULL, NULL},
705 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
706 NULL, getCursor, setCursor, NULL, NULL},
707 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
708 NULL, getCursor, setCursor, NULL, NULL},
709 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
710 NULL, getCursor, setCursor, NULL, NULL},
711 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
712 NULL, getCursor, setCursor, NULL, NULL},
713 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
714 NULL, getCursor, setCursor, NULL, NULL},
715 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
716 NULL, getCursor, setCursor, NULL, NULL},
717 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
718 NULL, getCursor, setCursor, NULL, NULL},
719 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
720 NULL, getCursor, setCursor, NULL, NULL},
721 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
722 NULL, getCursor, setCursor, NULL, NULL},
723 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
724 NULL, getCursor, setCursor, NULL, NULL},
725 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
726 NULL, getCursor, setCursor, NULL, NULL},
727 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
728 NULL, getCursor, setCursor, NULL, NULL},
729 {"DialogHistoryLines", "500", NULL,
730 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
731 {"CycleActiveHeadOnly", "NO", NULL,
732 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL},
733 {"CycleIgnoreMinimized", "NO", NULL,
734 &wPreferences.cycle_ignore_minimized, getBool, NULL, NULL, NULL}
737 static void initDefaults()
739 unsigned int i;
740 WDefaultEntry *entry;
742 WMPLSetCaseSensitive(False);
744 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
745 entry = &optionList[i];
747 entry->plkey = WMCreatePLString(entry->key);
748 if (entry->default_value)
749 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
750 else
751 entry->plvalue = NULL;
754 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
755 entry = &staticOptionList[i];
757 entry->plkey = WMCreatePLString(entry->key);
758 if (entry->default_value)
759 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
760 else
761 entry->plvalue = NULL;
765 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
767 WMPropList *globalDict = NULL;
768 char path[PATH_MAX];
769 struct stat stbuf;
771 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
772 if (stat(path, &stbuf) >= 0) {
773 globalDict = WMReadPropListFromFile(path);
774 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
775 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
776 WMReleasePropList(globalDict);
777 globalDict = NULL;
778 } else if (!globalDict) {
779 wwarning(_("could not load domain %s from global defaults database"), domainName);
783 return globalDict;
786 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
787 static void prependMenu(WMPropList * destarr, WMPropList * array)
789 WMPropList *item;
790 int i;
792 for (i = 0; i < WMGetPropListItemCount(array); i++) {
793 item = WMGetFromPLArray(array, i);
794 if (item)
795 WMInsertInPLArray(destarr, i + 1, item);
799 static void appendMenu(WMPropList * destarr, WMPropList * array)
801 WMPropList *item;
802 int i;
804 for (i = 0; i < WMGetPropListItemCount(array); i++) {
805 item = WMGetFromPLArray(array, i);
806 if (item)
807 WMAddToPLArray(destarr, item);
810 #endif
812 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
814 WMPropList *menu = menuDomain->dictionary;
815 WMPropList *submenu;
817 if (!menu || !WMIsPLArray(menu))
818 return;
820 #ifdef GLOBAL_PREAMBLE_MENU_FILE
821 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
823 if (submenu && !WMIsPLArray(submenu)) {
824 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
825 WMReleasePropList(submenu);
826 submenu = NULL;
828 if (submenu) {
829 prependMenu(menu, submenu);
830 WMReleasePropList(submenu);
832 #endif
834 #ifdef GLOBAL_EPILOGUE_MENU_FILE
835 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
837 if (submenu && !WMIsPLArray(submenu)) {
838 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
839 WMReleasePropList(submenu);
840 submenu = NULL;
842 if (submenu) {
843 appendMenu(menu, submenu);
844 WMReleasePropList(submenu);
846 #endif
848 menuDomain->dictionary = menu;
851 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
853 WDDomain *db;
854 struct stat stbuf;
855 static int inited = 0;
856 char *the_path;
857 WMPropList *shared_dict = NULL;
859 if (!inited) {
860 inited = 1;
861 initDefaults();
864 db = wmalloc(sizeof(WDDomain));
865 db->domain_name = domain;
866 db->path = wdefaultspathfordomain(domain);
867 the_path = db->path;
869 if (the_path && stat(the_path, &stbuf) >= 0) {
870 db->dictionary = WMReadPropListFromFile(the_path);
871 if (db->dictionary) {
872 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
873 WMReleasePropList(db->dictionary);
874 db->dictionary = NULL;
875 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
877 db->timestamp = stbuf.st_mtime;
878 } else {
879 wwarning(_("could not load domain %s from user defaults database"), domain);
883 /* global system dictionary */
884 shared_dict = readGlobalDomain(domain, requireDictionary);
886 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
887 WMIsPLDictionary(db->dictionary)) {
888 WMMergePLDictionaries(shared_dict, db->dictionary, True);
889 WMReleasePropList(db->dictionary);
890 db->dictionary = shared_dict;
891 if (stbuf.st_mtime > db->timestamp)
892 db->timestamp = stbuf.st_mtime;
893 } else if (!db->dictionary) {
894 db->dictionary = shared_dict;
895 if (stbuf.st_mtime > db->timestamp)
896 db->timestamp = stbuf.st_mtime;
899 return db;
902 void wReadStaticDefaults(WMPropList * dict)
904 WMPropList *plvalue;
905 WDefaultEntry *entry;
906 unsigned int i;
907 void *tdata;
909 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
910 entry = &staticOptionList[i];
912 if (dict)
913 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
914 else
915 plvalue = NULL;
917 /* no default in the DB. Use builtin default */
918 if (!plvalue)
919 plvalue = entry->plvalue;
921 if (plvalue) {
922 /* convert data */
923 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
924 if (entry->update)
925 (*entry->update) (NULL, entry, tdata, entry->extra_data);
930 void wDefaultsCheckDomains(void* arg)
932 WScreen *scr;
933 struct stat stbuf;
934 WMPropList *shared_dict = NULL;
935 WMPropList *dict;
936 int i;
938 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
939 WDWindowMaker->timestamp = stbuf.st_mtime;
941 /* Global dictionary */
942 shared_dict = readGlobalDomain("WindowMaker", True);
944 /* User dictionary */
945 dict = WMReadPropListFromFile(WDWindowMaker->path);
947 if (dict) {
948 if (!WMIsPLDictionary(dict)) {
949 WMReleasePropList(dict);
950 dict = NULL;
951 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
952 "WindowMaker", WDWindowMaker->path);
953 } else {
954 if (shared_dict) {
955 WMMergePLDictionaries(shared_dict, dict, True);
956 WMReleasePropList(dict);
957 dict = shared_dict;
958 shared_dict = NULL;
961 for (i = 0; i < wScreenCount; i++) {
962 scr = wScreenWithNumber(i);
963 if (scr)
964 wReadDefaults(scr, dict);
967 if (WDWindowMaker->dictionary)
968 WMReleasePropList(WDWindowMaker->dictionary);
970 WDWindowMaker->dictionary = dict;
972 } else {
973 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
976 if (shared_dict)
977 WMReleasePropList(shared_dict);
981 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
982 /* global dictionary */
983 shared_dict = readGlobalDomain("WMWindowAttributes", True);
984 /* user dictionary */
985 dict = WMReadPropListFromFile(WDWindowAttributes->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 "WMWindowAttributes", WDWindowAttributes->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 if (WDWindowAttributes->dictionary)
1001 WMReleasePropList(WDWindowAttributes->dictionary);
1003 WDWindowAttributes->dictionary = dict;
1004 for (i = 0; i < wScreenCount; i++) {
1005 scr = wScreenWithNumber(i);
1006 if (scr) {
1007 wDefaultUpdateIcons(scr);
1009 /* Update the panel image if changed */
1010 /* Don't worry. If the image is the same these
1011 * functions will have no performance impact. */
1012 create_logo_image(scr);
1016 } else {
1017 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1020 WDWindowAttributes->timestamp = stbuf.st_mtime;
1021 if (shared_dict)
1022 WMReleasePropList(shared_dict);
1025 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1026 dict = WMReadPropListFromFile(WDRootMenu->path);
1027 if (dict) {
1028 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1029 WMReleasePropList(dict);
1030 dict = NULL;
1031 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1032 "WMRootMenu", WDRootMenu->path);
1033 } else {
1034 if (WDRootMenu->dictionary)
1035 WMReleasePropList(WDRootMenu->dictionary);
1037 WDRootMenu->dictionary = dict;
1038 wDefaultsMergeGlobalMenus(WDRootMenu);
1040 } else {
1041 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1043 WDRootMenu->timestamp = stbuf.st_mtime;
1045 #ifndef HAVE_INOTIFY
1046 if (!arg)
1047 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1048 #endif
1051 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1053 WMPropList *plvalue, *old_value;
1054 WDefaultEntry *entry;
1055 unsigned int i;
1056 int update_workspace_back = 0; /* kluge :/ */
1057 unsigned int needs_refresh;
1058 void *tdata;
1059 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1061 needs_refresh = 0;
1063 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1064 entry = &optionList[i];
1066 if (new_dict)
1067 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1068 else
1069 plvalue = NULL;
1071 if (!old_dict)
1072 old_value = NULL;
1073 else
1074 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1076 if (!plvalue && !old_value) {
1077 /* no default in the DB. Use builtin default */
1078 plvalue = entry->plvalue;
1079 if (plvalue && new_dict)
1080 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1082 } else if (!plvalue) {
1083 /* value was deleted from DB. Keep current value */
1084 continue;
1085 } else if (!old_value) {
1086 /* set value for the 1st time */
1087 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1088 /* value has changed */
1089 } else {
1090 if (strcmp(entry->key, "WorkspaceBack") == 0
1091 && update_workspace_back && scr->flags.backimage_helper_launched) {
1092 } else {
1093 /* value was not changed since last time */
1094 continue;
1098 if (plvalue) {
1099 /* convert data */
1100 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1102 * If the WorkspaceSpecificBack data has been changed
1103 * so that the helper will be launched now, we must be
1104 * sure to send the default background texture config
1105 * to the helper.
1107 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1108 !scr->flags.backimage_helper_launched)
1109 update_workspace_back = 1;
1111 if (entry->update)
1112 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1118 if (needs_refresh != 0 && !scr->flags.startup) {
1119 int foo;
1121 foo = 0;
1122 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1123 foo |= WTextureSettings;
1124 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1125 foo |= WFontSettings;
1126 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1127 foo |= WColorSettings;
1128 if (foo)
1129 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1130 (void *)(uintptr_t) foo);
1132 foo = 0;
1133 if (needs_refresh & REFRESH_MENU_TEXTURE)
1134 foo |= WTextureSettings;
1135 if (needs_refresh & REFRESH_MENU_FONT)
1136 foo |= WFontSettings;
1137 if (needs_refresh & REFRESH_MENU_COLOR)
1138 foo |= WColorSettings;
1139 if (foo)
1140 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1142 foo = 0;
1143 if (needs_refresh & REFRESH_WINDOW_FONT)
1144 foo |= WFontSettings;
1145 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1146 foo |= WTextureSettings;
1147 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1148 foo |= WColorSettings;
1149 if (foo)
1150 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1152 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1153 foo = 0;
1154 if (needs_refresh & REFRESH_ICON_FONT)
1155 foo |= WFontSettings;
1156 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1157 foo |= WTextureSettings;
1158 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1159 foo |= WTextureSettings;
1160 if (foo)
1161 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1162 (void *)(uintptr_t) foo);
1164 if (needs_refresh & REFRESH_ICON_TILE)
1165 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1167 if (needs_refresh & REFRESH_WORKSPACE_MENU) {
1168 if (scr->workspace_menu)
1169 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
1170 if (scr->clip_ws_menu)
1171 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
1172 if (scr->workspace_submenu)
1173 scr->workspace_submenu->flags.realized = 0;
1174 if (scr->clip_submenu)
1175 scr->clip_submenu->flags.realized = 0;
1180 void wDefaultUpdateIcons(WScreen *scr)
1182 WAppIcon *aicon = scr->app_icon_list;
1183 WWindow *wwin = scr->focused_window;
1185 while (aicon) {
1186 /* Get the application icon, default included */
1187 wIconChangeImageFile(aicon->icon, NULL);
1188 wAppIconPaint(aicon);
1189 aicon = aicon->next;
1192 if (!wPreferences.flags.noclip)
1193 wClipIconPaint(scr->clip_icon);
1195 while (wwin) {
1196 if (wwin->icon && wwin->flags.miniaturized)
1197 wIconChangeImageFile(wwin->icon, NULL);
1198 wwin = wwin->prev;
1202 /* --------------------------- Local ----------------------- */
1204 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1205 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1206 entry->key, x); \
1207 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1208 var = entry->default_value;\
1209 } else var = WMGetFromPLString(value)\
1212 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1214 char *str;
1215 WOptionEnumeration *v;
1216 char buffer[TOTAL_VALUES_LENGTH];
1218 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1219 for (v = values; v->string != NULL; v++) {
1220 if (strcasecmp(v->string, str) == 0)
1221 return v->value;
1225 buffer[0] = 0;
1226 for (v = values; v->string != NULL; v++) {
1227 if (!v->is_alias) {
1228 if (buffer[0] != 0)
1229 strcat(buffer, ", ");
1230 snprintf(buffer+strlen(buffer),
1231 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1234 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1235 WMGetFromPLString(key),
1236 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1237 buffer);
1239 if (def) {
1240 return string2index(key, val, NULL, values);
1243 return -1;
1247 * value - is the value in the defaults DB
1248 * addr - is the address to store the data
1249 * ret - is the address to store a pointer to a temporary buffer. ret
1250 * must not be freed and is used by the set functions
1252 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1254 static char data;
1255 char *val;
1256 int second_pass = 0;
1258 GET_STRING_OR_DEFAULT("Boolean", val);
1260 again:
1261 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1262 || strcasecmp(val, "YES") == 0) {
1264 data = 1;
1265 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1266 || strcasecmp(val, "NO") == 0) {
1267 data = 0;
1268 } else {
1269 int i;
1270 if (sscanf(val, "%i", &i) == 1) {
1271 if (i != 0)
1272 data = 1;
1273 else
1274 data = 0;
1275 } else {
1276 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1277 if (second_pass == 0) {
1278 val = WMGetFromPLString(entry->plvalue);
1279 second_pass = 1;
1280 wwarning(_("using default \"%s\" instead"), val);
1281 goto again;
1283 return False;
1287 if (ret)
1288 *ret = &data;
1289 if (addr)
1290 *(char *)addr = data;
1292 return True;
1295 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1297 static int data;
1298 char *val;
1300 GET_STRING_OR_DEFAULT("Integer", val);
1302 if (sscanf(val, "%i", &data) != 1) {
1303 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1304 val = WMGetFromPLString(entry->plvalue);
1305 wwarning(_("using default \"%s\" instead"), val);
1306 if (sscanf(val, "%i", &data) != 1) {
1307 return False;
1311 if (ret)
1312 *ret = &data;
1313 if (addr)
1314 *(int *)addr = data;
1316 return True;
1319 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1321 static WCoord data;
1322 char *val_x, *val_y;
1323 int nelem, changed = 0;
1324 WMPropList *elem_x, *elem_y;
1326 again:
1327 if (!WMIsPLArray(value)) {
1328 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1329 if (changed == 0) {
1330 value = entry->plvalue;
1331 changed = 1;
1332 wwarning(_("using default \"%s\" instead"), entry->default_value);
1333 goto again;
1335 return False;
1338 nelem = WMGetPropListItemCount(value);
1339 if (nelem != 2) {
1340 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1341 if (changed == 0) {
1342 value = entry->plvalue;
1343 changed = 1;
1344 wwarning(_("using default \"%s\" instead"), entry->default_value);
1345 goto again;
1347 return False;
1350 elem_x = WMGetFromPLArray(value, 0);
1351 elem_y = WMGetFromPLArray(value, 1);
1353 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1354 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1355 if (changed == 0) {
1356 value = entry->plvalue;
1357 changed = 1;
1358 wwarning(_("using default \"%s\" instead"), entry->default_value);
1359 goto again;
1361 return False;
1364 val_x = WMGetFromPLString(elem_x);
1365 val_y = WMGetFromPLString(elem_y);
1367 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1368 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1369 if (changed == 0) {
1370 value = entry->plvalue;
1371 changed = 1;
1372 wwarning(_("using default \"%s\" instead"), entry->default_value);
1373 goto again;
1375 return False;
1378 if (data.x < 0)
1379 data.x = 0;
1380 else if (data.x > scr->scr_width / 3)
1381 data.x = scr->scr_width / 3;
1382 if (data.y < 0)
1383 data.y = 0;
1384 else if (data.y > scr->scr_height / 3)
1385 data.y = scr->scr_height / 3;
1387 if (ret)
1388 *ret = &data;
1389 if (addr)
1390 *(WCoord *) addr = data;
1392 return True;
1395 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1397 WMRetainPropList(value);
1399 *ret = value;
1401 return True;
1404 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1406 static char *data;
1407 int i, count, len;
1408 char *ptr;
1409 WMPropList *d;
1410 int changed = 0;
1412 again:
1413 if (!WMIsPLArray(value)) {
1414 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1415 if (changed == 0) {
1416 value = entry->plvalue;
1417 changed = 1;
1418 wwarning(_("using default \"%s\" instead"), entry->default_value);
1419 goto again;
1421 return False;
1424 i = 0;
1425 count = WMGetPropListItemCount(value);
1426 if (count < 1) {
1427 if (changed == 0) {
1428 value = entry->plvalue;
1429 changed = 1;
1430 wwarning(_("using default \"%s\" instead"), entry->default_value);
1431 goto again;
1433 return False;
1436 len = 0;
1437 for (i = 0; i < count; i++) {
1438 d = WMGetFromPLArray(value, i);
1439 if (!d || !WMIsPLString(d)) {
1440 count = i;
1441 break;
1443 len += strlen(WMGetFromPLString(d)) + 1;
1446 ptr = data = wmalloc(len + 1);
1448 for (i = 0; i < count; i++) {
1449 d = WMGetFromPLArray(value, i);
1450 if (!d || !WMIsPLString(d)) {
1451 break;
1453 strcpy(ptr, WMGetFromPLString(d));
1454 ptr += strlen(WMGetFromPLString(d));
1455 *ptr = ':';
1456 ptr++;
1458 ptr--;
1459 *(ptr--) = 0;
1461 if (*(char **)addr != NULL) {
1462 wfree(*(char **)addr);
1464 *(char **)addr = data;
1466 return True;
1469 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1471 static signed char data;
1473 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1474 if (data < 0)
1475 return False;
1477 if (ret)
1478 *ret = &data;
1479 if (addr)
1480 *(signed char *)addr = data;
1482 return True;
1486 * (solid <color>)
1487 * (hgradient <color> <color>)
1488 * (vgradient <color> <color>)
1489 * (dgradient <color> <color>)
1490 * (mhgradient <color> <color> ...)
1491 * (mvgradient <color> <color> ...)
1492 * (mdgradient <color> <color> ...)
1493 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1494 * (tpixmap <file> <color>)
1495 * (spixmap <file> <color>)
1496 * (cpixmap <file> <color>)
1497 * (thgradient <file> <opaqueness> <color> <color>)
1498 * (tvgradient <file> <opaqueness> <color> <color>)
1499 * (tdgradient <file> <opaqueness> <color> <color>)
1500 * (function <lib> <function> ...)
1503 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1505 WMPropList *elem;
1506 char *val;
1507 int nelem;
1508 WTexture *texture = NULL;
1510 nelem = WMGetPropListItemCount(pl);
1511 if (nelem < 1)
1512 return NULL;
1514 elem = WMGetFromPLArray(pl, 0);
1515 if (!elem || !WMIsPLString(elem))
1516 return NULL;
1517 val = WMGetFromPLString(elem);
1519 if (strcasecmp(val, "solid") == 0) {
1520 XColor color;
1522 if (nelem != 2)
1523 return NULL;
1525 /* get color */
1527 elem = WMGetFromPLArray(pl, 1);
1528 if (!elem || !WMIsPLString(elem))
1529 return NULL;
1530 val = WMGetFromPLString(elem);
1532 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1533 wwarning(_("\"%s\" is not a valid color name"), val);
1534 return NULL;
1537 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1538 } else if (strcasecmp(val, "dgradient") == 0
1539 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1540 RColor color1, color2;
1541 XColor xcolor;
1542 int type;
1544 if (nelem != 3) {
1545 wwarning(_("bad number of arguments in gradient specification"));
1546 return NULL;
1549 if (val[0] == 'd' || val[0] == 'D')
1550 type = WTEX_DGRADIENT;
1551 else if (val[0] == 'h' || val[0] == 'H')
1552 type = WTEX_HGRADIENT;
1553 else
1554 type = WTEX_VGRADIENT;
1556 /* get from color */
1557 elem = WMGetFromPLArray(pl, 1);
1558 if (!elem || !WMIsPLString(elem))
1559 return NULL;
1560 val = WMGetFromPLString(elem);
1562 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1563 wwarning(_("\"%s\" is not a valid color name"), val);
1564 return NULL;
1566 color1.alpha = 255;
1567 color1.red = xcolor.red >> 8;
1568 color1.green = xcolor.green >> 8;
1569 color1.blue = xcolor.blue >> 8;
1571 /* get to color */
1572 elem = WMGetFromPLArray(pl, 2);
1573 if (!elem || !WMIsPLString(elem)) {
1574 return NULL;
1576 val = WMGetFromPLString(elem);
1578 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1579 wwarning(_("\"%s\" is not a valid color name"), val);
1580 return NULL;
1582 color2.alpha = 255;
1583 color2.red = xcolor.red >> 8;
1584 color2.green = xcolor.green >> 8;
1585 color2.blue = xcolor.blue >> 8;
1587 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1589 } else if (strcasecmp(val, "igradient") == 0) {
1590 RColor colors1[2], colors2[2];
1591 int th1, th2;
1592 XColor xcolor;
1593 int i;
1595 if (nelem != 7) {
1596 wwarning(_("bad number of arguments in gradient specification"));
1597 return NULL;
1600 /* get from color */
1601 for (i = 0; i < 2; i++) {
1602 elem = WMGetFromPLArray(pl, 1 + i);
1603 if (!elem || !WMIsPLString(elem))
1604 return NULL;
1605 val = WMGetFromPLString(elem);
1607 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1608 wwarning(_("\"%s\" is not a valid color name"), val);
1609 return NULL;
1611 colors1[i].alpha = 255;
1612 colors1[i].red = xcolor.red >> 8;
1613 colors1[i].green = xcolor.green >> 8;
1614 colors1[i].blue = xcolor.blue >> 8;
1616 elem = WMGetFromPLArray(pl, 3);
1617 if (!elem || !WMIsPLString(elem))
1618 return NULL;
1619 val = WMGetFromPLString(elem);
1620 th1 = atoi(val);
1622 /* get from color */
1623 for (i = 0; i < 2; i++) {
1624 elem = WMGetFromPLArray(pl, 4 + i);
1625 if (!elem || !WMIsPLString(elem))
1626 return NULL;
1627 val = WMGetFromPLString(elem);
1629 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1630 wwarning(_("\"%s\" is not a valid color name"), val);
1631 return NULL;
1633 colors2[i].alpha = 255;
1634 colors2[i].red = xcolor.red >> 8;
1635 colors2[i].green = xcolor.green >> 8;
1636 colors2[i].blue = xcolor.blue >> 8;
1638 elem = WMGetFromPLArray(pl, 6);
1639 if (!elem || !WMIsPLString(elem))
1640 return NULL;
1641 val = WMGetFromPLString(elem);
1642 th2 = atoi(val);
1644 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1646 } else if (strcasecmp(val, "mhgradient") == 0
1647 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1648 XColor color;
1649 RColor **colors;
1650 int i, count;
1651 int type;
1653 if (nelem < 3) {
1654 wwarning(_("too few arguments in multicolor gradient specification"));
1655 return NULL;
1658 if (val[1] == 'h' || val[1] == 'H')
1659 type = WTEX_MHGRADIENT;
1660 else if (val[1] == 'v' || val[1] == 'V')
1661 type = WTEX_MVGRADIENT;
1662 else
1663 type = WTEX_MDGRADIENT;
1665 count = nelem - 1;
1667 colors = wmalloc(sizeof(RColor *) * (count + 1));
1669 for (i = 0; i < count; i++) {
1670 elem = WMGetFromPLArray(pl, i + 1);
1671 if (!elem || !WMIsPLString(elem)) {
1672 for (--i; i >= 0; --i) {
1673 wfree(colors[i]);
1675 wfree(colors);
1676 return NULL;
1678 val = WMGetFromPLString(elem);
1680 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1681 wwarning(_("\"%s\" is not a valid color name"), val);
1682 for (--i; i >= 0; --i) {
1683 wfree(colors[i]);
1685 wfree(colors);
1686 return NULL;
1687 } else {
1688 colors[i] = wmalloc(sizeof(RColor));
1689 colors[i]->red = color.red >> 8;
1690 colors[i]->green = color.green >> 8;
1691 colors[i]->blue = color.blue >> 8;
1694 colors[i] = NULL;
1696 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1697 } else if (strcasecmp(val, "spixmap") == 0 ||
1698 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1699 XColor color;
1700 int type;
1702 if (nelem != 3)
1703 return NULL;
1705 if (val[0] == 's' || val[0] == 'S')
1706 type = WTP_SCALE;
1707 else if (val[0] == 'c' || val[0] == 'C')
1708 type = WTP_CENTER;
1709 else
1710 type = WTP_TILE;
1712 /* get color */
1713 elem = WMGetFromPLArray(pl, 2);
1714 if (!elem || !WMIsPLString(elem)) {
1715 return NULL;
1717 val = WMGetFromPLString(elem);
1719 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1720 wwarning(_("\"%s\" is not a valid color name"), val);
1721 return NULL;
1724 /* file name */
1725 elem = WMGetFromPLArray(pl, 1);
1726 if (!elem || !WMIsPLString(elem))
1727 return NULL;
1728 val = WMGetFromPLString(elem);
1730 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1731 } else if (strcasecmp(val, "thgradient") == 0
1732 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1733 RColor color1, color2;
1734 XColor xcolor;
1735 int opacity;
1736 int style;
1738 if (val[1] == 'h' || val[1] == 'H')
1739 style = WTEX_THGRADIENT;
1740 else if (val[1] == 'v' || val[1] == 'V')
1741 style = WTEX_TVGRADIENT;
1742 else
1743 style = WTEX_TDGRADIENT;
1745 if (nelem != 5) {
1746 wwarning(_("bad number of arguments in textured gradient specification"));
1747 return NULL;
1750 /* get from color */
1751 elem = WMGetFromPLArray(pl, 3);
1752 if (!elem || !WMIsPLString(elem))
1753 return NULL;
1754 val = WMGetFromPLString(elem);
1756 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1757 wwarning(_("\"%s\" is not a valid color name"), val);
1758 return NULL;
1760 color1.alpha = 255;
1761 color1.red = xcolor.red >> 8;
1762 color1.green = xcolor.green >> 8;
1763 color1.blue = xcolor.blue >> 8;
1765 /* get to color */
1766 elem = WMGetFromPLArray(pl, 4);
1767 if (!elem || !WMIsPLString(elem)) {
1768 return NULL;
1770 val = WMGetFromPLString(elem);
1772 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1773 wwarning(_("\"%s\" is not a valid color name"), val);
1774 return NULL;
1776 color2.alpha = 255;
1777 color2.red = xcolor.red >> 8;
1778 color2.green = xcolor.green >> 8;
1779 color2.blue = xcolor.blue >> 8;
1781 /* get opacity */
1782 elem = WMGetFromPLArray(pl, 2);
1783 if (!elem || !WMIsPLString(elem))
1784 opacity = 128;
1785 else
1786 val = WMGetFromPLString(elem);
1788 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1789 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1790 opacity = 128;
1793 /* get file name */
1794 elem = WMGetFromPLArray(pl, 1);
1795 if (!elem || !WMIsPLString(elem))
1796 return NULL;
1797 val = WMGetFromPLString(elem);
1799 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1800 } else if (strcasecmp(val, "function") == 0) {
1801 /* Leave this in to handle the unlikely case of
1802 * someone actually having function textures configured */
1803 wwarning("function texture support has been removed");
1804 return NULL;
1805 } else {
1806 wwarning(_("invalid texture type %s"), val);
1807 return NULL;
1809 return texture;
1812 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1814 static WTexture *texture;
1815 int changed = 0;
1817 again:
1818 if (!WMIsPLArray(value)) {
1819 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1820 if (changed == 0) {
1821 value = entry->plvalue;
1822 changed = 1;
1823 wwarning(_("using default \"%s\" instead"), entry->default_value);
1824 goto again;
1826 return False;
1829 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1830 WMPropList *pl;
1832 pl = WMGetFromPLArray(value, 0);
1833 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1834 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1835 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1836 entry->key, "Solid Texture");
1838 value = entry->plvalue;
1839 changed = 1;
1840 wwarning(_("using default \"%s\" instead"), entry->default_value);
1841 goto again;
1845 texture = parse_texture(scr, value);
1847 if (!texture) {
1848 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1849 if (changed == 0) {
1850 value = entry->plvalue;
1851 changed = 1;
1852 wwarning(_("using default \"%s\" instead"), entry->default_value);
1853 goto again;
1855 return False;
1858 if (ret)
1859 *ret = &texture;
1861 if (addr)
1862 *(WTexture **) addr = texture;
1864 return True;
1867 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1869 WMPropList *elem;
1870 int changed = 0;
1871 char *val;
1872 int nelem;
1874 again:
1875 if (!WMIsPLArray(value)) {
1876 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1877 "WorkspaceBack", "Texture or None");
1878 if (changed == 0) {
1879 value = entry->plvalue;
1880 changed = 1;
1881 wwarning(_("using default \"%s\" instead"), entry->default_value);
1882 goto again;
1884 return False;
1887 /* only do basic error checking and verify for None texture */
1889 nelem = WMGetPropListItemCount(value);
1890 if (nelem > 0) {
1891 elem = WMGetFromPLArray(value, 0);
1892 if (!elem || !WMIsPLString(elem)) {
1893 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1894 if (changed == 0) {
1895 value = entry->plvalue;
1896 changed = 1;
1897 wwarning(_("using default \"%s\" instead"), entry->default_value);
1898 goto again;
1900 return False;
1902 val = WMGetFromPLString(elem);
1904 if (strcasecmp(val, "None") == 0)
1905 return True;
1907 *ret = WMRetainPropList(value);
1909 return True;
1912 static int
1913 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1915 WMPropList *elem;
1916 int nelem;
1917 int changed = 0;
1919 again:
1920 if (!WMIsPLArray(value)) {
1921 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1922 "WorkspaceSpecificBack", "an array of textures");
1923 if (changed == 0) {
1924 value = entry->plvalue;
1925 changed = 1;
1926 wwarning(_("using default \"%s\" instead"), entry->default_value);
1927 goto again;
1929 return False;
1932 /* only do basic error checking and verify for None texture */
1934 nelem = WMGetPropListItemCount(value);
1935 if (nelem > 0) {
1936 while (nelem--) {
1937 elem = WMGetFromPLArray(value, nelem);
1938 if (!elem || !WMIsPLArray(elem)) {
1939 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1940 nelem);
1945 *ret = WMRetainPropList(value);
1947 #ifdef notworking
1949 * Kluge to force wmsetbg helper to set the default background.
1950 * If the WorkspaceSpecificBack is changed once wmaker has started,
1951 * the WorkspaceBack won't be sent to the helper, unless the user
1952 * changes it's value too. So, we must force this by removing the
1953 * value from the defaults DB.
1955 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1956 WMPropList *key = WMCreatePLString("WorkspaceBack");
1958 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1960 WMReleasePropList(key);
1962 #endif
1963 return True;
1966 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1968 static WMFont *font;
1969 char *val;
1971 GET_STRING_OR_DEFAULT("Font", val);
1973 font = WMCreateFont(scr->wmscreen, val);
1974 if (!font)
1975 font = WMCreateFont(scr->wmscreen, "fixed");
1977 if (!font) {
1978 wfatal(_("could not load any usable font!!!"));
1979 exit(1);
1982 if (ret)
1983 *ret = font;
1985 /* can't assign font value outside update function */
1986 wassertrv(addr == NULL, True);
1988 return True;
1991 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1993 static XColor color;
1994 char *val;
1995 int second_pass = 0;
1997 GET_STRING_OR_DEFAULT("Color", val);
1999 again:
2000 if (!wGetColor(scr, val, &color)) {
2001 wwarning(_("could not get color for key \"%s\""), entry->key);
2002 if (second_pass == 0) {
2003 val = WMGetFromPLString(entry->plvalue);
2004 second_pass = 1;
2005 wwarning(_("using default \"%s\" instead"), val);
2006 goto again;
2008 return False;
2011 if (ret)
2012 *ret = &color;
2014 assert(addr == NULL);
2016 if (addr)
2017 *(unsigned long*)addr = pixel;
2020 return True;
2023 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2025 static WShortKey shortcut;
2026 KeySym ksym;
2027 char *val;
2028 char *k;
2029 char buf[MAX_SHORTCUT_LENGTH], *b;
2031 GET_STRING_OR_DEFAULT("Key spec", val);
2033 if (!val || strcasecmp(val, "NONE") == 0) {
2034 shortcut.keycode = 0;
2035 shortcut.modifier = 0;
2036 if (ret)
2037 *ret = &shortcut;
2038 return True;
2041 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2043 b = (char *)buf;
2045 /* get modifiers */
2046 shortcut.modifier = 0;
2047 while ((k = strchr(b, '+')) != NULL) {
2048 int mod;
2050 *k = 0;
2051 mod = wXModifierFromKey(b);
2052 if (mod < 0) {
2053 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2054 return False;
2056 shortcut.modifier |= mod;
2058 b = k + 1;
2061 /* get key */
2062 ksym = XStringToKeysym(b);
2064 if (ksym == NoSymbol) {
2065 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2066 return False;
2069 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2070 if (shortcut.keycode == 0) {
2071 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2072 return False;
2075 if (ret)
2076 *ret = &shortcut;
2078 return True;
2081 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2083 static int mask;
2084 char *str;
2086 GET_STRING_OR_DEFAULT("Modifier Key", str);
2088 if (!str)
2089 return False;
2091 mask = wXModifierFromKey(str);
2092 if (mask < 0) {
2093 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2094 mask = 0;
2095 return False;
2098 if (addr)
2099 *(int *)addr = mask;
2101 if (ret)
2102 *ret = &mask;
2104 return True;
2107 # include <X11/cursorfont.h>
2108 typedef struct {
2109 char *name;
2110 int id;
2111 } WCursorLookup;
2113 #define CURSOR_ID_NONE (XC_num_glyphs)
2115 static WCursorLookup cursor_table[] = {
2116 {"X_cursor", XC_X_cursor},
2117 {"arrow", XC_arrow},
2118 {"based_arrow_down", XC_based_arrow_down},
2119 {"based_arrow_up", XC_based_arrow_up},
2120 {"boat", XC_boat},
2121 {"bogosity", XC_bogosity},
2122 {"bottom_left_corner", XC_bottom_left_corner},
2123 {"bottom_right_corner", XC_bottom_right_corner},
2124 {"bottom_side", XC_bottom_side},
2125 {"bottom_tee", XC_bottom_tee},
2126 {"box_spiral", XC_box_spiral},
2127 {"center_ptr", XC_center_ptr},
2128 {"circle", XC_circle},
2129 {"clock", XC_clock},
2130 {"coffee_mug", XC_coffee_mug},
2131 {"cross", XC_cross},
2132 {"cross_reverse", XC_cross_reverse},
2133 {"crosshair", XC_crosshair},
2134 {"diamond_cross", XC_diamond_cross},
2135 {"dot", XC_dot},
2136 {"dotbox", XC_dotbox},
2137 {"double_arrow", XC_double_arrow},
2138 {"draft_large", XC_draft_large},
2139 {"draft_small", XC_draft_small},
2140 {"draped_box", XC_draped_box},
2141 {"exchange", XC_exchange},
2142 {"fleur", XC_fleur},
2143 {"gobbler", XC_gobbler},
2144 {"gumby", XC_gumby},
2145 {"hand1", XC_hand1},
2146 {"hand2", XC_hand2},
2147 {"heart", XC_heart},
2148 {"icon", XC_icon},
2149 {"iron_cross", XC_iron_cross},
2150 {"left_ptr", XC_left_ptr},
2151 {"left_side", XC_left_side},
2152 {"left_tee", XC_left_tee},
2153 {"leftbutton", XC_leftbutton},
2154 {"ll_angle", XC_ll_angle},
2155 {"lr_angle", XC_lr_angle},
2156 {"man", XC_man},
2157 {"middlebutton", XC_middlebutton},
2158 {"mouse", XC_mouse},
2159 {"pencil", XC_pencil},
2160 {"pirate", XC_pirate},
2161 {"plus", XC_plus},
2162 {"question_arrow", XC_question_arrow},
2163 {"right_ptr", XC_right_ptr},
2164 {"right_side", XC_right_side},
2165 {"right_tee", XC_right_tee},
2166 {"rightbutton", XC_rightbutton},
2167 {"rtl_logo", XC_rtl_logo},
2168 {"sailboat", XC_sailboat},
2169 {"sb_down_arrow", XC_sb_down_arrow},
2170 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2171 {"sb_left_arrow", XC_sb_left_arrow},
2172 {"sb_right_arrow", XC_sb_right_arrow},
2173 {"sb_up_arrow", XC_sb_up_arrow},
2174 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2175 {"shuttle", XC_shuttle},
2176 {"sizing", XC_sizing},
2177 {"spider", XC_spider},
2178 {"spraycan", XC_spraycan},
2179 {"star", XC_star},
2180 {"target", XC_target},
2181 {"tcross", XC_tcross},
2182 {"top_left_arrow", XC_top_left_arrow},
2183 {"top_left_corner", XC_top_left_corner},
2184 {"top_right_corner", XC_top_right_corner},
2185 {"top_side", XC_top_side},
2186 {"top_tee", XC_top_tee},
2187 {"trek", XC_trek},
2188 {"ul_angle", XC_ul_angle},
2189 {"umbrella", XC_umbrella},
2190 {"ur_angle", XC_ur_angle},
2191 {"watch", XC_watch},
2192 {"xterm", XC_xterm},
2193 {NULL, CURSOR_ID_NONE}
2196 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2198 switch (status) {
2199 case BitmapOpenFailed:
2200 wwarning(_("failed to open bitmap file \"%s\""), filename);
2201 break;
2202 case BitmapFileInvalid:
2203 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2204 break;
2205 case BitmapNoMemory:
2206 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2207 break;
2208 case BitmapSuccess:
2209 XFreePixmap(dpy, bitmap);
2210 break;
2215 * (none)
2216 * (builtin, <cursor_name>)
2217 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2219 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2221 WMPropList *elem;
2222 char *val;
2223 int nelem;
2224 int status = 0;
2226 nelem = WMGetPropListItemCount(pl);
2227 if (nelem < 1) {
2228 return (status);
2230 elem = WMGetFromPLArray(pl, 0);
2231 if (!elem || !WMIsPLString(elem)) {
2232 return (status);
2234 val = WMGetFromPLString(elem);
2236 if (strcasecmp(val, "none") == 0) {
2237 status = 1;
2238 *cursor = None;
2239 } else if (strcasecmp(val, "builtin") == 0) {
2240 int i;
2241 int cursor_id = CURSOR_ID_NONE;
2243 if (nelem != 2) {
2244 wwarning(_("bad number of arguments in cursor specification"));
2245 return (status);
2247 elem = WMGetFromPLArray(pl, 1);
2248 if (!elem || !WMIsPLString(elem)) {
2249 return (status);
2251 val = WMGetFromPLString(elem);
2253 for (i = 0; cursor_table[i].name != NULL; i++) {
2254 if (strcasecmp(val, cursor_table[i].name) == 0) {
2255 cursor_id = cursor_table[i].id;
2256 break;
2259 if (CURSOR_ID_NONE == cursor_id) {
2260 wwarning(_("unknown builtin cursor name \"%s\""), val);
2261 } else {
2262 *cursor = XCreateFontCursor(dpy, cursor_id);
2263 status = 1;
2265 } else if (strcasecmp(val, "bitmap") == 0) {
2266 char *bitmap_name;
2267 char *mask_name;
2268 int bitmap_status;
2269 int mask_status;
2270 Pixmap bitmap;
2271 Pixmap mask;
2272 unsigned int w, h;
2273 int x, y;
2274 XColor fg, bg;
2276 if (nelem != 3) {
2277 wwarning(_("bad number of arguments in cursor specification"));
2278 return (status);
2280 elem = WMGetFromPLArray(pl, 1);
2281 if (!elem || !WMIsPLString(elem)) {
2282 return (status);
2284 val = WMGetFromPLString(elem);
2285 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2286 if (!bitmap_name) {
2287 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2288 return (status);
2290 elem = WMGetFromPLArray(pl, 2);
2291 if (!elem || !WMIsPLString(elem)) {
2292 wfree(bitmap_name);
2293 return (status);
2295 val = WMGetFromPLString(elem);
2296 mask_name = FindImage(wPreferences.pixmap_path, val);
2297 if (!mask_name) {
2298 wfree(bitmap_name);
2299 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2300 return (status);
2302 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2303 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2304 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2305 fg.pixel = scr->black_pixel;
2306 bg.pixel = scr->white_pixel;
2307 XQueryColor(dpy, scr->w_colormap, &fg);
2308 XQueryColor(dpy, scr->w_colormap, &bg);
2309 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2310 status = 1;
2312 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2313 check_bitmap_status(mask_status, mask_name, mask);
2314 wfree(bitmap_name);
2315 wfree(mask_name);
2317 return (status);
2320 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2322 static Cursor cursor;
2323 int status;
2324 int changed = 0;
2326 again:
2327 if (!WMIsPLArray(value)) {
2328 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2329 entry->key, "cursor specification");
2330 if (!changed) {
2331 value = entry->plvalue;
2332 changed = 1;
2333 wwarning(_("using default \"%s\" instead"), entry->default_value);
2334 goto again;
2336 return (False);
2338 status = parse_cursor(scr, value, &cursor);
2339 if (!status) {
2340 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2341 if (!changed) {
2342 value = entry->plvalue;
2343 changed = 1;
2344 wwarning(_("using default \"%s\" instead"), entry->default_value);
2345 goto again;
2347 return (False);
2349 if (ret) {
2350 *ret = &cursor;
2352 if (addr) {
2353 *(Cursor *) addr = cursor;
2355 return (True);
2358 #undef CURSOR_ID_NONE
2360 /* ---------------- value setting functions --------------- */
2361 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2363 return REFRESH_WINDOW_TITLE_COLOR;
2366 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2368 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2371 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2373 switch (which) {
2374 case WM_DOCK:
2375 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2376 break;
2377 case WM_CLIP:
2378 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2379 break;
2380 default:
2381 break;
2383 return 0;
2386 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2388 if (scr->workspaces) {
2389 wWorkspaceForceChange(scr, scr->current_workspace);
2390 wArrangeIcons(scr, False);
2392 return 0;
2395 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2397 Pixmap pixmap;
2398 RImage *img;
2399 int reset = 0;
2401 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2402 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2403 ? WREL_ICON : WREL_FLAT);
2404 if (!img) {
2405 wwarning(_("could not render texture for icon background"));
2406 if (!entry->addr)
2407 wTextureDestroy(scr, *texture);
2408 return 0;
2410 RConvertImage(scr->rcontext, img, &pixmap);
2412 if (scr->icon_tile) {
2413 reset = 1;
2414 RReleaseImage(scr->icon_tile);
2415 XFreePixmap(dpy, scr->icon_tile_pixmap);
2418 scr->icon_tile = img;
2420 /* put the icon in the noticeboard hint */
2421 PropSetIconTileHint(scr, img);
2423 if (!wPreferences.flags.noclip) {
2424 if (scr->clip_tile) {
2425 RReleaseImage(scr->clip_tile);
2427 scr->clip_tile = wClipMakeTile(scr, img);
2430 scr->icon_tile_pixmap = pixmap;
2432 if (scr->def_icon_rimage) {
2433 RReleaseImage(scr->def_icon_rimage);
2434 scr->def_icon_rimage = NULL;
2437 if (scr->icon_back_texture)
2438 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2440 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2442 /* Free the texture as nobody else will use it, nor refer to it. */
2443 if (!entry->addr)
2444 wTextureDestroy(scr, *texture);
2446 return (reset ? REFRESH_ICON_TILE : 0);
2449 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2451 if (scr->title_font) {
2452 WMReleaseFont(scr->title_font);
2454 scr->title_font = font;
2456 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2459 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2461 if (scr->menu_title_font) {
2462 WMReleaseFont(scr->menu_title_font);
2465 scr->menu_title_font = font;
2467 return REFRESH_MENU_TITLE_FONT;
2470 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2472 if (scr->menu_entry_font) {
2473 WMReleaseFont(scr->menu_entry_font);
2475 scr->menu_entry_font = font;
2477 return REFRESH_MENU_FONT;
2480 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2482 if (scr->icon_title_font) {
2483 WMReleaseFont(scr->icon_title_font);
2486 scr->icon_title_font = font;
2488 return REFRESH_ICON_FONT;
2491 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2493 if (scr->clip_title_font) {
2494 WMReleaseFont(scr->clip_title_font);
2497 scr->clip_title_font = font;
2499 return REFRESH_ICON_FONT;
2502 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2504 if (scr->workspace_name_font) {
2505 WMReleaseFont(scr->workspace_name_font);
2508 scr->workspace_name_font = font;
2510 return 0;
2513 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2515 if (scr->select_color)
2516 WMReleaseColor(scr->select_color);
2518 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2520 wFreeColor(scr, color->pixel);
2522 return REFRESH_MENU_COLOR;
2525 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2527 if (scr->select_text_color)
2528 WMReleaseColor(scr->select_text_color);
2530 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2532 wFreeColor(scr, color->pixel);
2534 return REFRESH_MENU_COLOR;
2537 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2539 if (scr->clip_title_color[widx])
2540 WMReleaseColor(scr->clip_title_color[widx]);
2542 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2543 wFreeColor(scr, color->pixel);
2545 return REFRESH_ICON_TITLE_COLOR;
2548 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2550 if (scr->window_title_color[widx])
2551 WMReleaseColor(scr->window_title_color[widx]);
2553 scr->window_title_color[widx] =
2554 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2556 wFreeColor(scr, color->pixel);
2558 return REFRESH_WINDOW_TITLE_COLOR;
2561 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2563 if (scr->menu_title_color[0])
2564 WMReleaseColor(scr->menu_title_color[0]);
2566 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2568 wFreeColor(scr, color->pixel);
2570 return REFRESH_MENU_TITLE_COLOR;
2573 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2575 if (scr->mtext_color)
2576 WMReleaseColor(scr->mtext_color);
2578 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2580 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2581 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2582 } else {
2583 WMSetColorAlpha(scr->dtext_color, 0xffff);
2586 wFreeColor(scr, color->pixel);
2588 return REFRESH_MENU_COLOR;
2591 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2593 if (scr->dtext_color)
2594 WMReleaseColor(scr->dtext_color);
2596 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2598 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2599 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2600 } else {
2601 WMSetColorAlpha(scr->dtext_color, 0xffff);
2604 wFreeColor(scr, color->pixel);
2606 return REFRESH_MENU_COLOR;
2609 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2611 if (scr->icon_title_color)
2612 WMReleaseColor(scr->icon_title_color);
2613 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2615 wFreeColor(scr, color->pixel);
2617 return REFRESH_ICON_TITLE_COLOR;
2620 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2622 if (scr->icon_title_texture) {
2623 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2625 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2627 return REFRESH_ICON_TITLE_BACK;
2630 static int setFrameBorderWidth(WScreen * scr, WDefaultEntry * entry, int * value, void *foo)
2632 scr->frame_border_width = *value;
2634 return REFRESH_FRAME_BORDER;
2637 static int setFrameBorderColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2639 if (scr->frame_border_color)
2640 WMReleaseColor(scr->frame_border_color);
2641 scr->frame_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2643 wFreeColor(scr, color->pixel);
2645 return REFRESH_FRAME_BORDER;
2648 static int setFrameSelectedBorderColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2650 if (scr->frame_selected_border_color)
2651 WMReleaseColor(scr->frame_selected_border_color);
2652 scr->frame_selected_border_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2654 wFreeColor(scr, color->pixel);
2656 return REFRESH_FRAME_BORDER;
2659 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2661 close(scr->helper_fd);
2662 scr->helper_fd = 0;
2663 scr->helper_pid = 0;
2664 scr->flags.backimage_helper_launched = 0;
2667 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2669 WMPropList *val;
2670 char *str;
2671 int i;
2673 if (scr->flags.backimage_helper_launched) {
2674 if (WMGetPropListItemCount(value) == 0) {
2675 SendHelperMessage(scr, 'C', 0, NULL);
2676 SendHelperMessage(scr, 'K', 0, NULL);
2678 WMReleasePropList(value);
2679 return 0;
2681 } else {
2682 pid_t pid;
2683 int filedes[2];
2685 if (WMGetPropListItemCount(value) == 0)
2686 return 0;
2688 if (pipe(filedes) < 0) {
2689 werror("pipe() failed:can't set workspace specific background image");
2691 WMReleasePropList(value);
2692 return 0;
2695 pid = fork();
2696 if (pid < 0) {
2697 werror("fork() failed:can't set workspace specific background image");
2698 if (close(filedes[0]) < 0)
2699 werror("could not close pipe");
2700 if (close(filedes[1]) < 0)
2701 werror("could not close pipe");
2703 } else if (pid == 0) {
2704 char *dither;
2706 SetupEnvironment(scr);
2708 if (close(0) < 0)
2709 werror("could not close pipe");
2710 if (dup(filedes[0]) < 0) {
2711 werror("dup() failed:can't set workspace specific background image");
2713 dither = wPreferences.no_dithering ? "-m" : "-d";
2714 if (wPreferences.smooth_workspace_back)
2715 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2716 else
2717 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2718 werror("could not execute wmsetbg");
2719 exit(1);
2720 } else {
2722 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2723 werror("error setting close-on-exec flag");
2725 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2726 werror("error setting close-on-exec flag");
2729 scr->helper_fd = filedes[1];
2730 scr->helper_pid = pid;
2731 scr->flags.backimage_helper_launched = 1;
2733 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2735 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2740 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2741 val = WMGetFromPLArray(value, i);
2742 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2743 str = WMGetPropListDescription(val, False);
2745 SendHelperMessage(scr, 'S', i + 1, str);
2747 wfree(str);
2748 } else {
2749 SendHelperMessage(scr, 'U', i + 1, NULL);
2752 sleep(1);
2754 WMReleasePropList(value);
2755 return 0;
2758 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2760 if (scr->flags.backimage_helper_launched) {
2761 char *str;
2763 if (WMGetPropListItemCount(value) == 0) {
2764 SendHelperMessage(scr, 'U', 0, NULL);
2765 } else {
2766 /* set the default workspace background to this one */
2767 str = WMGetPropListDescription(value, False);
2768 if (str) {
2769 SendHelperMessage(scr, 'S', 0, str);
2770 wfree(str);
2771 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2772 } else {
2773 SendHelperMessage(scr, 'U', 0, NULL);
2776 } else if (WMGetPropListItemCount(value) > 0) {
2777 char *command;
2778 char *text;
2779 char *dither;
2780 int len;
2782 text = WMGetPropListDescription(value, False);
2783 len = strlen(text) + 40;
2784 command = wmalloc(len);
2785 dither = wPreferences.no_dithering ? "-m" : "-d";
2786 if (wPreferences.smooth_workspace_back)
2787 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2788 else
2789 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2790 wfree(text);
2791 ExecuteShellCommand(scr, command);
2792 wfree(command);
2794 WMReleasePropList(value);
2796 return 0;
2799 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2801 if (scr->widget_texture) {
2802 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2804 scr->widget_texture = *(WTexSolid **) texture;
2806 return 0;
2809 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2811 if (scr->window_title_texture[WS_FOCUSED]) {
2812 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2814 scr->window_title_texture[WS_FOCUSED] = *texture;
2816 return REFRESH_WINDOW_TEXTURES;
2819 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2821 if (scr->window_title_texture[WS_PFOCUSED]) {
2822 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2824 scr->window_title_texture[WS_PFOCUSED] = *texture;
2826 return REFRESH_WINDOW_TEXTURES;
2829 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2831 if (scr->window_title_texture[WS_UNFOCUSED]) {
2832 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2834 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2836 return REFRESH_WINDOW_TEXTURES;
2839 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2841 if (scr->resizebar_texture[0]) {
2842 wTextureDestroy(scr, scr->resizebar_texture[0]);
2844 scr->resizebar_texture[0] = *texture;
2846 return REFRESH_WINDOW_TEXTURES;
2849 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2851 if (scr->menu_title_texture[0]) {
2852 wTextureDestroy(scr, scr->menu_title_texture[0]);
2854 scr->menu_title_texture[0] = *texture;
2856 return REFRESH_MENU_TITLE_TEXTURE;
2859 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2861 if (scr->menu_item_texture) {
2862 wTextureDestroy(scr, scr->menu_item_texture);
2863 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2865 scr->menu_item_texture = *texture;
2867 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2869 return REFRESH_MENU_TEXTURE;
2872 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2874 WWindow *wwin;
2875 wKeyBindings[widx] = *shortcut;
2877 wwin = scr->focused_window;
2879 while (wwin != NULL) {
2880 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2882 if (!WFLAGP(wwin, no_bind_keys)) {
2883 wWindowSetKeyGrabs(wwin);
2885 wwin = wwin->prev;
2888 /* do we need to update window menus? */
2889 if (widx >= WKBD_WORKSPACE1 && widx <= WKBD_WORKSPACE10)
2890 return REFRESH_WORKSPACE_MENU;
2891 if (widx == WKBD_LASTWORKSPACE)
2892 return REFRESH_WORKSPACE_MENU;
2893 if (widx >= WKBD_MOVE_WORKSPACE1 && widx <= WKBD_MOVE_WORKSPACE10)
2894 return REFRESH_WORKSPACE_MENU;
2896 return 0;
2899 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2901 wScreenUpdateUsableArea(scr);
2902 wArrangeIcons(scr, True);
2904 return 0;
2907 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2909 wScreenUpdateUsableArea(scr);
2911 return 0;
2914 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2916 return REFRESH_MENU_TEXTURE;
2919 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2921 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2923 RCopyArea(img, image, x, y, w, h, 0, 0);
2925 return img;
2928 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2930 char *path;
2931 RImage *bgimage;
2932 int cwidth, cheight;
2933 WPreferences *prefs = (WPreferences *) foo;
2935 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2936 if (prefs->swtileImage)
2937 RReleaseImage(prefs->swtileImage);
2938 prefs->swtileImage = NULL;
2940 WMReleasePropList(array);
2941 return 0;
2944 switch (WMGetPropListItemCount(array)) {
2945 case 4:
2946 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2947 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2948 break;
2949 } else
2950 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2952 if (!path) {
2953 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2954 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2955 } else {
2956 bgimage = RLoadImage(scr->rcontext, path, 0);
2957 if (!bgimage) {
2958 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2959 wfree(path);
2960 } else {
2961 wfree(path);
2963 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2964 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2966 if (cwidth <= 0 || cheight <= 0 ||
2967 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2968 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2969 else {
2970 int i;
2971 int swidth, theight;
2972 for (i = 0; i < 9; i++) {
2973 if (prefs->swbackImage[i])
2974 RReleaseImage(prefs->swbackImage[i]);
2975 prefs->swbackImage[i] = NULL;
2977 swidth = (bgimage->width - cwidth) / 2;
2978 theight = (bgimage->height - cheight) / 2;
2980 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2981 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2982 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2983 swidth, theight);
2985 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2986 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2987 cwidth, cheight);
2988 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2989 swidth, cheight);
2991 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2992 swidth, theight);
2993 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2994 cwidth, theight);
2995 prefs->swbackImage[8] =
2996 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2997 theight);
2999 // check if anything failed
3000 for (i = 0; i < 9; i++) {
3001 if (!prefs->swbackImage[i]) {
3002 for (; i >= 0; --i) {
3003 RReleaseImage(prefs->swbackImage[i]);
3004 prefs->swbackImage[i] = NULL;
3006 break;
3010 RReleaseImage(bgimage);
3014 case 1:
3015 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3016 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3017 break;
3018 } else
3019 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3021 if (!path) {
3022 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3023 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3024 } else {
3025 if (prefs->swtileImage)
3026 RReleaseImage(prefs->swtileImage);
3028 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3029 if (!prefs->swtileImage) {
3030 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3032 wfree(path);
3034 break;
3036 default:
3037 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3038 break;
3041 WMReleasePropList(array);
3043 return 0;
3046 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
3048 int i;
3049 WPreferences *prefs = (WPreferences *) foo;
3051 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3052 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3053 WMReleasePropList(array);
3054 return 0;
3057 DestroyWindowMenu(scr);
3059 for (i = 0; i < 7; i++) {
3060 if (prefs->modifier_labels[i])
3061 wfree(prefs->modifier_labels[i]);
3063 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3064 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3065 } else {
3066 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3067 prefs->modifier_labels[i] = NULL;
3071 WMReleasePropList(array);
3073 return 0;
3076 static int setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3078 if (*value <= 0)
3079 *(int *)foo = 1;
3081 W_setconf_doubleClickDelay(*value);
3083 return 0;
3086 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3088 if (wCursor[widx] != None) {
3089 XFreeCursor(dpy, wCursor[widx]);
3092 wCursor[widx] = *cursor;
3094 if (widx == WCUR_ROOT && *cursor != None) {
3095 XDefineCursor(dpy, scr->root_win, *cursor);
3098 return 0;