debian: New debian version 0.95.2
[wmaker-crm.git] / src / defaults.c
blobb5ea8e2f4baed698ceb29142a12e9d6b7a067d3f
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 "funcs.h"
60 #include "actions.h"
61 #include "dock.h"
62 #include "workspace.h"
63 #include "properties.h"
64 #include "rootmenu.h"
66 #define MAX_SHORTCUT_LENGTH 32
68 #ifndef GLOBAL_DEFAULTS_SUBDIR
69 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
70 #endif
72 /***** Global *****/
73 extern WDDomain *WDWindowMaker;
74 extern WDDomain *WDWindowAttributes;
75 extern WDDomain *WDRootMenu;
76 extern int wScreenCount;
77 extern WPreferences wPreferences;
78 extern WShortKey wKeyBindings[WKBD_LAST];
80 typedef struct {
81 char *key;
82 char *default_value;
83 void *extra_data;
84 void *addr;
85 int (*convert) ();
86 int (*update) ();
87 WMPropList *plkey;
88 WMPropList *plvalue; /* default value */
89 } WDefaultEntry;
91 /* used to map strings to integers */
92 typedef struct {
93 char *string;
94 short value;
95 char is_alias;
96 } WOptionEnumeration;
98 /* type converters */
99 static int getBool();
100 static int getInt();
101 static int getCoord();
102 static int getPathList();
103 static int getEnum();
104 static int getTexture();
105 static int getWSBackground();
106 static int getWSSpecificBackground();
107 static int getFont();
108 static int getColor();
109 static int getKeybind();
110 static int getModMask();
111 static int getPropList();
113 /* value setting functions */
114 static int setJustify();
115 static int setClearance();
116 static int setIfDockPresent();
117 static int setStickyIcons();
118 static int setWidgetColor();
119 static int setIconTile();
120 static int setWinTitleFont();
121 static int setMenuTitleFont();
122 static int setMenuTextFont();
123 static int setIconTitleFont();
124 static int setIconTitleColor();
125 static int setIconTitleBack();
126 static int setLargeDisplayFont();
127 static int setWTitleColor();
128 static int setFTitleBack();
129 static int setPTitleBack();
130 static int setUTitleBack();
131 static int setResizebarBack();
132 static int setWorkspaceBack();
133 static int setWorkspaceSpecificBack();
134 static int setMenuTitleColor();
135 static int setMenuTextColor();
136 static int setMenuDisabledColor();
137 static int setMenuTitleBack();
138 static int setMenuTextBack();
139 static int setHightlight();
140 static int setHightlightText();
141 static int setKeyGrab();
142 static int setDoubleClick();
143 static int setIconPosition();
145 static int setClipTitleFont();
146 static int setClipTitleColor();
148 static int setMenuStyle();
149 static int setSwPOptions();
150 static int updateUsableArea();
152 static int setModifierKeyLabels();
154 extern Cursor wCursor[WCUR_LAST];
155 static int getCursor();
156 static int setCursor();
159 * Tables to convert strings to enumeration values.
160 * Values stored are char
163 /* WARNING: sum of length of all value strings must not exceed
164 * this value */
165 #define TOTAL_VALUES_LENGTH 80
167 #define REFRESH_WINDOW_TEXTURES (1<<0)
168 #define REFRESH_MENU_TEXTURE (1<<1)
169 #define REFRESH_MENU_FONT (1<<2)
170 #define REFRESH_MENU_COLOR (1<<3)
171 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
172 #define REFRESH_MENU_TITLE_FONT (1<<5)
173 #define REFRESH_MENU_TITLE_COLOR (1<<6)
174 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
175 #define REFRESH_WINDOW_FONT (1<<8)
176 #define REFRESH_ICON_TILE (1<<9)
177 #define REFRESH_ICON_FONT (1<<10)
178 #define REFRESH_WORKSPACE_BACK (1<<11)
180 #define REFRESH_BUTTON_IMAGES (1<<12)
182 #define REFRESH_ICON_TITLE_COLOR (1<<13)
183 #define REFRESH_ICON_TITLE_BACK (1<<14)
185 static WOptionEnumeration seFocusModes[] = {
186 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
187 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
188 {NULL, 0, 0}
191 static WOptionEnumeration seTitlebarModes[] = {
192 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
193 {"next", TS_NEXT, 0}, {NULL, 0, 0}
196 static WOptionEnumeration seColormapModes[] = {
197 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
198 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
199 {NULL, 0, 0}
202 static WOptionEnumeration sePlacements[] = {
203 {"Auto", WPM_AUTO, 0},
204 {"Smart", WPM_SMART, 0},
205 {"Cascade", WPM_CASCADE, 0},
206 {"Random", WPM_RANDOM, 0},
207 {"Manual", WPM_MANUAL, 0},
208 {NULL, 0, 0}
211 static WOptionEnumeration seGeomDisplays[] = {
212 {"None", WDIS_NONE, 0},
213 {"Center", WDIS_CENTER, 0},
214 {"Corner", WDIS_TOPLEFT, 0},
215 {"Floating", WDIS_FRAME_CENTER, 0},
216 {"Line", WDIS_NEW, 0},
217 {NULL, 0, 0}
220 static WOptionEnumeration seSpeeds[] = {
221 {"UltraFast", SPEED_ULTRAFAST, 0},
222 {"Fast", SPEED_FAST, 0},
223 {"Medium", SPEED_MEDIUM, 0},
224 {"Slow", SPEED_SLOW, 0},
225 {"UltraSlow", SPEED_ULTRASLOW, 0},
226 {NULL, 0, 0}
229 static WOptionEnumeration seMouseButtonActions[] = {
230 {"None", WA_NONE, 0},
231 {"SelectWindows", WA_SELECT_WINDOWS, 0},
232 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
233 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
234 {NULL, 0, 0}
237 static WOptionEnumeration seMouseWheelActions[] = {
238 {"None", WA_NONE, 0},
239 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
240 {NULL, 0, 0}
243 static WOptionEnumeration seIconificationStyles[] = {
244 {"Zoom", WIS_ZOOM, 0},
245 {"Twist", WIS_TWIST, 0},
246 {"Flip", WIS_FLIP, 0},
247 {"None", WIS_NONE, 0},
248 {"random", WIS_RANDOM, 0},
249 {NULL, 0, 0}
252 static WOptionEnumeration seJustifications[] = {
253 {"Left", WTJ_LEFT, 0},
254 {"Center", WTJ_CENTER, 0},
255 {"Right", WTJ_RIGHT, 0},
256 {NULL, 0, 0}
259 static WOptionEnumeration seIconPositions[] = {
260 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
261 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
262 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
263 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
264 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
265 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
266 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
267 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
268 {NULL, 0, 0}
271 static WOptionEnumeration seMenuStyles[] = {
272 {"normal", MS_NORMAL, 0},
273 {"singletexture", MS_SINGLE_TEXTURE, 0},
274 {"flat", MS_FLAT, 0},
275 {NULL, 0, 0}
278 static WOptionEnumeration seDisplayPositions[] = {
279 {"none", WD_NONE, 0},
280 {"center", WD_CENTER, 0},
281 {"top", WD_TOP, 0},
282 {"bottom", WD_BOTTOM, 0},
283 {"topleft", WD_TOPLEFT, 0},
284 {"topright", WD_TOPRIGHT, 0},
285 {"bottomleft", WD_BOTTOMLEFT, 0},
286 {"bottomright", WD_BOTTOMRIGHT, 0},
287 {NULL, 0, 0}
290 static WOptionEnumeration seWorkspaceBorder[] = {
291 {"None", WB_NONE, 0},
292 {"LeftRight", WB_LEFTRIGHT, 0},
293 {"TopBottom", WB_TOPBOTTOM, 0},
294 {"AllDirections", WB_ALLDIRS, 0},
295 {NULL, 0, 0}
299 * ALL entries in the tables bellow, NEED to have a default value
300 * defined, and this value needs to be correct.
303 /* these options will only affect the window manager on startup
305 * static defaults can't access the screen data, because it is
306 * created after these defaults are read
308 WDefaultEntry staticOptionList[] = {
310 {"ColormapSize", "4", NULL,
311 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
312 {"DisableDithering", "NO", NULL,
313 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
314 {"IconSize", "64", NULL,
315 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
316 {"ModifierKey", "Mod1", NULL,
317 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
318 {"DisableWSMouseActions", "NO", NULL,
319 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
320 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
321 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
322 {"NewStyle", "new", seTitlebarModes,
323 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
324 {"DisableDock", "NO", (void *)WM_DOCK,
325 NULL, getBool, setIfDockPresent, NULL, NULL},
326 {"DisableClip", "NO", (void *)WM_CLIP,
327 NULL, getBool, setIfDockPresent, NULL, NULL},
328 {"DisableMiniwindows", "NO", NULL,
329 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
332 WDefaultEntry optionList[] = {
334 /* dynamic options */
336 {"IconPosition", "blh", seIconPositions,
337 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
338 {"IconificationStyle", "Zoom", seIconificationStyles,
339 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
340 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
341 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
342 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
343 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
344 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
345 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
346 {"MouseWheelAction", "None", seMouseWheelActions,
347 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
348 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
349 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
350 {"IconPath", DEF_ICON_PATHS, NULL,
351 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
352 {"ColormapMode", "auto", seColormapModes,
353 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
354 {"AutoFocus", "NO", NULL,
355 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
356 {"RaiseDelay", "0", NULL,
357 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
358 {"CirculateRaise", "NO", NULL,
359 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
360 {"Superfluous", "NO", NULL,
361 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
362 {"AdvanceToNewWorkspace", "NO", NULL,
363 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
364 {"CycleWorkspaces", "NO", NULL,
365 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
366 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
367 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
368 {"WorkspaceBorder", "None", seWorkspaceBorder,
369 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
370 {"WorkspaceBorderSize", "0", NULL,
371 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
372 {"StickyIcons", "NO", NULL,
373 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
374 {"SaveSessionOnExit", "NO", NULL,
375 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
376 {"WrapMenus", "NO", NULL,
377 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
378 {"ScrollableMenus", "NO", NULL,
379 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
380 {"MenuScrollSpeed", "medium", seSpeeds,
381 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
382 {"IconSlideSpeed", "medium", seSpeeds,
383 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
384 {"ShadeSpeed", "medium", seSpeeds,
385 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
386 {"BounceAppIconsWhenUrgent", "YES", NULL,
387 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
388 {"RaiseAppIconsWhenBouncing", "NO", NULL,
389 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
390 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
391 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
392 {"AlignSubmenus", "NO", NULL,
393 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
394 {"ViKeyMenus", "NO", NULL,
395 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
396 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
397 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
398 {"WindowPlacement", "auto", sePlacements,
399 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
400 {"IgnoreFocusClick", "NO", NULL,
401 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
402 {"UseSaveUnders", "NO", NULL,
403 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
404 {"OpaqueMove", "NO", NULL,
405 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
406 {"OpaqueResize", "NO", NULL,
407 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
408 {"OpaqueMoveResizeKeyboard", "NO", NULL,
409 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
410 {"DisableAnimations", "NO", NULL,
411 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
412 {"DontLinkWorkspaces", "NO", NULL,
413 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
414 {"AutoArrangeIcons", "NO", NULL,
415 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
416 {"NoWindowOverDock", "NO", NULL,
417 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
418 {"NoWindowOverIcons", "NO", NULL,
419 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
420 {"WindowPlaceOrigin", "(0, 0)", NULL,
421 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
422 {"ResizeDisplay", "corner", seGeomDisplays,
423 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
424 {"MoveDisplay", "corner", seGeomDisplays,
425 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
426 {"DontConfirmKill", "NO", NULL,
427 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
428 {"WindowTitleBalloons", "NO", NULL,
429 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
430 {"MiniwindowTitleBalloons", "NO", NULL,
431 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
432 {"AppIconBalloons", "NO", NULL,
433 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
434 {"HelpBalloons", "NO", NULL,
435 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
436 {"EdgeResistance", "30", NULL,
437 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
438 {"ResizeIncrement", "32", NULL,
439 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
440 {"Attraction", "NO", NULL,
441 &wPreferences.attract, getBool, NULL, NULL, NULL},
442 {"DisableBlinking", "NO", NULL,
443 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
444 {"SingleClickLaunch", "NO", NULL,
445 &wPreferences.single_click, getBool, NULL, NULL, NULL},
447 /* style options */
449 {"MenuStyle", "normal", seMenuStyles,
450 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
451 {"WidgetColor", "(solid, gray)", NULL,
452 NULL, getTexture, setWidgetColor, NULL, NULL},
453 {"WorkspaceSpecificBack", "()", NULL,
454 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
455 /* WorkspaceBack must come after WorkspaceSpecificBack or
456 * WorkspaceBack wont know WorkspaceSpecificBack was also
457 * specified and 2 copies of wmsetbg will be launched */
458 {"WorkspaceBack", "(solid, black)", NULL,
459 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
460 {"SmoothWorkspaceBack", "NO", NULL,
461 NULL, getBool, NULL, NULL, NULL},
462 {"IconBack", "(solid, gray)", NULL,
463 NULL, getTexture, setIconTile, NULL, NULL},
464 {"TitleJustify", "center", seJustifications,
465 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
466 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
467 NULL, getFont, setWinTitleFont, NULL, NULL},
468 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
469 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
470 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
471 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
472 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
473 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
474 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
475 NULL, getFont, setMenuTitleFont, NULL, NULL},
476 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
477 NULL, getFont, setMenuTextFont, NULL, NULL},
478 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
479 NULL, getFont, setIconTitleFont, NULL, NULL},
480 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
481 NULL, getFont, setClipTitleFont, NULL, NULL},
482 {"ShowClipTitle", "YES", NULL,
483 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
484 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
485 NULL, getFont, setLargeDisplayFont, NULL, NULL},
486 {"HighlightColor", "white", NULL,
487 NULL, getColor, setHightlight, NULL, NULL},
488 {"HighlightTextColor", "black", NULL,
489 NULL, getColor, setHightlightText, NULL, NULL},
490 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
491 NULL, getColor, setClipTitleColor, NULL, NULL},
492 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
493 NULL, getColor, setClipTitleColor, NULL, NULL},
494 {"FTitleColor", "white", (void *)WS_FOCUSED,
495 NULL, getColor, setWTitleColor, NULL, NULL},
496 {"PTitleColor", "white", (void *)WS_PFOCUSED,
497 NULL, getColor, setWTitleColor, NULL, NULL},
498 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
499 NULL, getColor, setWTitleColor, NULL, NULL},
500 {"FTitleBack", "(solid, black)", NULL,
501 NULL, getTexture, setFTitleBack, NULL, NULL},
502 {"PTitleBack", "(solid, \"#616161\")", NULL,
503 NULL, getTexture, setPTitleBack, NULL, NULL},
504 {"UTitleBack", "(solid, gray)", NULL,
505 NULL, getTexture, setUTitleBack, NULL, NULL},
506 {"ResizebarBack", "(solid, gray)", NULL,
507 NULL, getTexture, setResizebarBack, NULL, NULL},
508 {"MenuTitleColor", "white", NULL,
509 NULL, getColor, setMenuTitleColor, NULL, NULL},
510 {"MenuTextColor", "black", NULL,
511 NULL, getColor, setMenuTextColor, NULL, NULL},
512 {"MenuDisabledColor", "\"#616161\"", NULL,
513 NULL, getColor, setMenuDisabledColor, NULL, NULL},
514 {"MenuTitleBack", "(solid, black)", NULL,
515 NULL, getTexture, setMenuTitleBack, NULL, NULL},
516 {"MenuTextBack", "(solid, gray)", NULL,
517 NULL, getTexture, setMenuTextBack, NULL, NULL},
518 {"IconTitleColor", "white", NULL,
519 NULL, getColor, setIconTitleColor, NULL, NULL},
520 {"IconTitleBack", "black", NULL,
521 NULL, getColor, setIconTitleBack, NULL, NULL},
522 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
523 NULL, getPropList, setSwPOptions, NULL, NULL},
524 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
525 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
527 /* keybindings */
529 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
530 NULL, getKeybind, setKeyGrab, NULL, NULL},
531 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
532 NULL, getKeybind, setKeyGrab, NULL, NULL},
533 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
534 NULL, getKeybind, setKeyGrab, NULL, NULL},
535 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
536 NULL, getKeybind, setKeyGrab, NULL, NULL},
537 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
538 NULL, getKeybind, setKeyGrab, NULL, NULL},
539 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
540 NULL, getKeybind, setKeyGrab, NULL, NULL},
541 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
542 NULL, getKeybind, setKeyGrab, NULL, NULL },
543 {"HideKey", "None", (void *)WKBD_HIDE,
544 NULL, getKeybind, setKeyGrab, NULL, NULL},
545 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
546 NULL, getKeybind, setKeyGrab, NULL, NULL},
547 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
548 NULL, getKeybind, setKeyGrab, NULL, NULL},
549 {"CloseKey", "None", (void *)WKBD_CLOSE,
550 NULL, getKeybind, setKeyGrab, NULL, NULL},
551 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
552 NULL, getKeybind, setKeyGrab, NULL, NULL},
553 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
554 NULL, getKeybind, setKeyGrab, NULL, NULL},
555 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
556 NULL, getKeybind, setKeyGrab, NULL, NULL},
557 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
558 NULL, getKeybind, setKeyGrab, NULL, NULL},
559 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
560 NULL, getKeybind, setKeyGrab, NULL, NULL},
561 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
562 NULL, getKeybind, setKeyGrab, NULL, NULL},
563 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
564 NULL, getKeybind, setKeyGrab, NULL, NULL},
565 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
566 NULL, getKeybind, setKeyGrab, NULL, NULL},
567 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
568 NULL, getKeybind, setKeyGrab, NULL, NULL},
569 {"ShadeKey", "None", (void *)WKBD_SHADE,
570 NULL, getKeybind, setKeyGrab, NULL, NULL},
571 {"SelectKey", "None", (void *)WKBD_SELECT,
572 NULL, getKeybind, setKeyGrab, NULL, NULL},
573 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
574 NULL, getKeybind, setKeyGrab, NULL, NULL},
575 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
576 NULL, getKeybind, setKeyGrab, NULL, NULL},
577 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
578 NULL, getKeybind, setKeyGrab, NULL, NULL},
579 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
580 NULL, getKeybind, setKeyGrab, NULL, NULL},
581 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
582 NULL, getKeybind, setKeyGrab, NULL, NULL},
583 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
584 NULL, getKeybind, setKeyGrab, NULL, NULL},
585 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
586 NULL, getKeybind, setKeyGrab, NULL, NULL},
587 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
588 NULL, getKeybind, setKeyGrab, NULL, NULL},
589 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
590 NULL, getKeybind, setKeyGrab, NULL, NULL},
591 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
592 NULL, getKeybind, setKeyGrab, NULL, NULL},
593 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
594 NULL, getKeybind, setKeyGrab, NULL, NULL},
595 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
596 NULL, getKeybind, setKeyGrab, NULL, NULL},
597 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
598 NULL, getKeybind, setKeyGrab, NULL, NULL},
599 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
600 NULL, getKeybind, setKeyGrab, NULL, NULL},
601 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
602 NULL, getKeybind, setKeyGrab, NULL, NULL},
603 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
604 NULL, getKeybind, setKeyGrab, NULL, NULL},
605 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
606 NULL, getKeybind, setKeyGrab, NULL, NULL},
607 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
608 NULL, getKeybind, setKeyGrab, NULL, NULL},
609 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
610 NULL, getKeybind, setKeyGrab, NULL, NULL},
611 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
612 NULL, getKeybind, setKeyGrab, NULL, NULL},
613 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
614 NULL, getKeybind, setKeyGrab, NULL, NULL},
615 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
616 NULL, getKeybind, setKeyGrab, NULL, NULL},
617 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
618 NULL, getKeybind, setKeyGrab, NULL, NULL},
619 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
620 NULL, getKeybind, setKeyGrab, NULL, NULL},
621 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
622 NULL, getKeybind, setKeyGrab, NULL, NULL},
623 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
624 NULL, getKeybind, setKeyGrab, NULL, NULL},
625 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
626 NULL, getKeybind, setKeyGrab, NULL, NULL},
627 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
628 NULL, getKeybind, setKeyGrab, NULL, NULL},
629 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
630 NULL, getKeybind, setKeyGrab, NULL, NULL},
632 #ifdef KEEP_XKB_LOCK_STATUS
633 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
634 NULL, getKeybind, setKeyGrab, NULL, NULL},
635 {"KbdModeLock", "NO", NULL,
636 &wPreferences.modelock, getBool, NULL, NULL, NULL},
637 #endif /* KEEP_XKB_LOCK_STATUS */
639 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
640 NULL, getCursor, setCursor, NULL, NULL},
641 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
642 NULL, getCursor, setCursor, NULL, NULL},
643 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
644 NULL, getCursor, setCursor, NULL, NULL},
645 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
646 NULL, getCursor, setCursor, NULL, NULL},
647 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
648 NULL, getCursor, setCursor, NULL, NULL},
649 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
650 NULL, getCursor, setCursor, NULL, NULL},
651 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
652 NULL, getCursor, setCursor, NULL, NULL},
653 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
654 NULL, getCursor, setCursor, NULL, NULL},
655 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
656 NULL, getCursor, setCursor, NULL, NULL},
657 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
658 NULL, getCursor, setCursor, NULL, NULL},
659 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
660 NULL, getCursor, setCursor, NULL, NULL},
661 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
662 NULL, getCursor, setCursor, NULL, NULL},
663 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
664 NULL, getCursor, setCursor, NULL, NULL},
665 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
666 NULL, getCursor, setCursor, NULL, NULL},
667 {"DialogHistoryLines", "500", NULL,
668 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
669 {"CycleActiveHeadOnly", "NO", NULL,
670 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL}
673 static void initDefaults()
675 unsigned int i;
676 WDefaultEntry *entry;
678 WMPLSetCaseSensitive(False);
680 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
681 entry = &optionList[i];
683 entry->plkey = WMCreatePLString(entry->key);
684 if (entry->default_value)
685 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
686 else
687 entry->plvalue = NULL;
690 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
691 entry = &staticOptionList[i];
693 entry->plkey = WMCreatePLString(entry->key);
694 if (entry->default_value)
695 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
696 else
697 entry->plvalue = NULL;
701 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
703 WMPropList *globalDict = NULL;
704 char path[PATH_MAX];
705 struct stat stbuf;
707 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
708 if (stat(path, &stbuf) >= 0) {
709 globalDict = WMReadPropListFromFile(path);
710 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
711 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
712 WMReleasePropList(globalDict);
713 globalDict = NULL;
714 } else if (!globalDict) {
715 wwarning(_("could not load domain %s from global defaults database"), domainName);
719 return globalDict;
722 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
723 static void prependMenu(WMPropList * destarr, WMPropList * array)
725 WMPropList *item;
726 int i;
728 for (i = 0; i < WMGetPropListItemCount(array); i++) {
729 item = WMGetFromPLArray(array, i);
730 if (item)
731 WMInsertInPLArray(destarr, i + 1, item);
735 static void appendMenu(WMPropList * destarr, WMPropList * array)
737 WMPropList *item;
738 int i;
740 for (i = 0; i < WMGetPropListItemCount(array); i++) {
741 item = WMGetFromPLArray(array, i);
742 if (item)
743 WMAddToPLArray(destarr, item);
746 #endif
748 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
750 WMPropList *menu = menuDomain->dictionary;
751 WMPropList *submenu;
753 if (!menu || !WMIsPLArray(menu))
754 return;
756 #ifdef GLOBAL_PREAMBLE_MENU_FILE
757 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
759 if (submenu && !WMIsPLArray(submenu)) {
760 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
761 WMReleasePropList(submenu);
762 submenu = NULL;
764 if (submenu) {
765 prependMenu(menu, submenu);
766 WMReleasePropList(submenu);
768 #endif
770 #ifdef GLOBAL_EPILOGUE_MENU_FILE
771 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
773 if (submenu && !WMIsPLArray(submenu)) {
774 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
775 WMReleasePropList(submenu);
776 submenu = NULL;
778 if (submenu) {
779 appendMenu(menu, submenu);
780 WMReleasePropList(submenu);
782 #endif
784 menuDomain->dictionary = menu;
787 void wDefaultsDestroyDomain(WDDomain * domain)
789 if (domain->dictionary)
790 WMReleasePropList(domain->dictionary);
791 wfree(domain->path);
792 wfree(domain);
795 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
797 WDDomain *db;
798 struct stat stbuf;
799 static int inited = 0;
800 char path[PATH_MAX];
801 char *the_path;
802 WMPropList *shared_dict = NULL;
804 if (!inited) {
805 inited = 1;
806 initDefaults();
809 db = wmalloc(sizeof(WDDomain));
810 memset(db, 0, sizeof(WDDomain));
811 db->domain_name = domain;
812 db->path = wdefaultspathfordomain(domain);
813 the_path = db->path;
815 if (the_path && stat(the_path, &stbuf) >= 0) {
816 db->dictionary = WMReadPropListFromFile(the_path);
817 if (db->dictionary) {
818 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
819 WMReleasePropList(db->dictionary);
820 db->dictionary = NULL;
821 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
823 db->timestamp = stbuf.st_mtime;
824 } else {
825 wwarning(_("could not load domain %s from user defaults database"), domain);
829 /* global system dictionary */
830 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
831 if (stat(path, &stbuf) >= 0) {
832 shared_dict = WMReadPropListFromFile(path);
833 if (shared_dict) {
834 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
835 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
836 domain, path);
837 WMReleasePropList(shared_dict);
838 shared_dict = NULL;
839 } else {
840 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
841 WMIsPLDictionary(db->dictionary)) {
842 WMMergePLDictionaries(shared_dict, db->dictionary, True);
843 WMReleasePropList(db->dictionary);
844 db->dictionary = shared_dict;
845 if (stbuf.st_mtime > db->timestamp)
846 db->timestamp = stbuf.st_mtime;
847 } else if (!db->dictionary) {
848 db->dictionary = shared_dict;
849 if (stbuf.st_mtime > db->timestamp)
850 db->timestamp = stbuf.st_mtime;
853 } else {
854 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
858 return db;
861 void wReadStaticDefaults(WMPropList * dict)
863 WMPropList *plvalue;
864 WDefaultEntry *entry;
865 unsigned int i;
866 void *tdata;
868 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
869 entry = &staticOptionList[i];
871 if (dict)
872 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
873 else
874 plvalue = NULL;
876 if (!plvalue) {
877 /* no default in the DB. Use builtin default */
878 plvalue = entry->plvalue;
881 if (plvalue) {
882 /* convert data */
883 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
884 if (entry->update) {
885 (*entry->update) (NULL, entry, tdata, entry->extra_data);
891 void wDefaultsCheckDomains(void* arg)
893 WScreen *scr;
894 struct stat stbuf;
895 WMPropList *shared_dict = NULL;
896 WMPropList *dict;
897 int i;
899 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
900 WDWindowMaker->timestamp = stbuf.st_mtime;
902 /* global dictionary */
903 shared_dict = readGlobalDomain("WindowMaker", True);
904 /* user dictionary */
905 dict = WMReadPropListFromFile(WDWindowMaker->path);
906 if (dict) {
907 if (!WMIsPLDictionary(dict)) {
908 WMReleasePropList(dict);
909 dict = NULL;
910 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
911 "WindowMaker", WDWindowMaker->path);
912 } else {
913 if (shared_dict) {
914 WMMergePLDictionaries(shared_dict, dict, True);
915 WMReleasePropList(dict);
916 dict = shared_dict;
917 shared_dict = NULL;
919 for (i = 0; i < wScreenCount; i++) {
920 scr = wScreenWithNumber(i);
921 if (scr)
922 wReadDefaults(scr, dict);
924 if (WDWindowMaker->dictionary) {
925 WMReleasePropList(WDWindowMaker->dictionary);
927 WDWindowMaker->dictionary = dict;
929 } else {
930 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
932 if (shared_dict) {
933 WMReleasePropList(shared_dict);
937 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
938 /* global dictionary */
939 shared_dict = readGlobalDomain("WMWindowAttributes", True);
940 /* user dictionary */
941 dict = WMReadPropListFromFile(WDWindowAttributes->path);
942 if (dict) {
943 if (!WMIsPLDictionary(dict)) {
944 WMReleasePropList(dict);
945 dict = NULL;
946 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
947 "WMWindowAttributes", WDWindowAttributes->path);
948 } else {
949 if (shared_dict) {
950 WMMergePLDictionaries(shared_dict, dict, True);
951 WMReleasePropList(dict);
952 dict = shared_dict;
953 shared_dict = NULL;
955 if (WDWindowAttributes->dictionary) {
956 WMReleasePropList(WDWindowAttributes->dictionary);
958 WDWindowAttributes->dictionary = dict;
959 for (i = 0; i < wScreenCount; i++) {
960 scr = wScreenWithNumber(i);
961 if (scr) {
962 RImage *image;
964 wDefaultUpdateIcons(scr);
966 /* Update the panel image if changed */
967 /* Don't worry. If the image is the same these
968 * functions will have no performance impact. */
969 image = wDefaultGetImage(scr, "Logo", "WMPanel");
971 if (!image) {
972 wwarning(_("could not load logo image for panels: %s"),
973 RMessageForError(RErrorCode));
974 } else {
975 WMSetApplicationIconImage(scr->wmscreen, image);
976 RReleaseImage(image);
981 } else {
982 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
984 WDWindowAttributes->timestamp = stbuf.st_mtime;
985 if (shared_dict) {
986 WMReleasePropList(shared_dict);
990 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
991 dict = WMReadPropListFromFile(WDRootMenu->path);
992 if (dict) {
993 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
994 WMReleasePropList(dict);
995 dict = NULL;
996 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
997 "WMRootMenu", WDRootMenu->path);
998 } else {
999 if (WDRootMenu->dictionary) {
1000 WMReleasePropList(WDRootMenu->dictionary);
1002 WDRootMenu->dictionary = dict;
1003 wDefaultsMergeGlobalMenus(WDRootMenu);
1004 scr = wScreenWithNumber(0);
1005 configureMenu(scr, dict, True);
1006 rebind_key_grabs(scr);
1008 } else {
1009 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1011 WDRootMenu->timestamp = stbuf.st_mtime;
1013 #ifndef HAVE_INOTIFY
1014 if (!arg)
1015 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1016 #endif
1019 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1021 WMPropList *plvalue, *old_value;
1022 WDefaultEntry *entry;
1023 unsigned int i;
1024 int update_workspace_back = 0; /* kluge :/ */
1025 unsigned int needs_refresh;
1026 void *tdata;
1027 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1029 needs_refresh = 0;
1031 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1032 entry = &optionList[i];
1034 if (new_dict)
1035 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1036 else
1037 plvalue = NULL;
1039 if (!old_dict)
1040 old_value = NULL;
1041 else
1042 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1044 if (!plvalue && !old_value) {
1045 /* no default in the DB. Use builtin default */
1046 plvalue = entry->plvalue;
1047 if (plvalue && new_dict) {
1048 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1050 } else if (!plvalue) {
1051 /* value was deleted from DB. Keep current value */
1052 continue;
1053 } else if (!old_value) {
1054 /* set value for the 1st time */
1055 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1056 /* value has changed */
1057 } else {
1059 if (strcmp(entry->key, "WorkspaceBack") == 0
1060 && update_workspace_back && scr->flags.backimage_helper_launched) {
1061 } else {
1062 /* value was not changed since last time */
1063 continue;
1067 if (plvalue) {
1068 /* convert data */
1069 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1071 * If the WorkspaceSpecificBack data has been changed
1072 * so that the helper will be launched now, we must be
1073 * sure to send the default background texture config
1074 * to the helper.
1076 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1077 && !scr->flags.backimage_helper_launched) {
1078 update_workspace_back = 1;
1080 if (entry->update) {
1081 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1087 if (needs_refresh != 0 && !scr->flags.startup) {
1088 int foo;
1090 foo = 0;
1091 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1092 foo |= WTextureSettings;
1093 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1094 foo |= WFontSettings;
1095 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1096 foo |= WColorSettings;
1097 if (foo)
1098 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1099 (void *)(uintptr_t) foo);
1101 foo = 0;
1102 if (needs_refresh & REFRESH_MENU_TEXTURE)
1103 foo |= WTextureSettings;
1104 if (needs_refresh & REFRESH_MENU_FONT)
1105 foo |= WFontSettings;
1106 if (needs_refresh & REFRESH_MENU_COLOR)
1107 foo |= WColorSettings;
1108 if (foo)
1109 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1111 foo = 0;
1112 if (needs_refresh & REFRESH_WINDOW_FONT) {
1113 foo |= WFontSettings;
1115 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1116 foo |= WTextureSettings;
1118 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1119 foo |= WColorSettings;
1121 if (foo)
1122 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1124 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1125 foo = 0;
1126 if (needs_refresh & REFRESH_ICON_FONT) {
1127 foo |= WFontSettings;
1129 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1130 foo |= WTextureSettings;
1132 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1133 foo |= WTextureSettings;
1135 if (foo)
1136 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1137 (void *)(uintptr_t) foo);
1139 if (needs_refresh & REFRESH_ICON_TILE)
1140 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1144 void wDefaultUpdateIcons(WScreen * scr)
1146 WAppIcon *aicon = scr->app_icon_list;
1147 WWindow *wwin = scr->focused_window;
1148 char *file;
1150 while (aicon) {
1151 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1152 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1153 || (file && !aicon->icon->file)) {
1154 wIconChangeImageFile(aicon->icon, file);
1155 wAppIconPaint(aicon);
1157 aicon = aicon->next;
1160 if (!wPreferences.flags.noclip)
1161 wClipIconPaint(scr->clip_icon);
1163 while (wwin) {
1164 if (wwin->icon && wwin->flags.miniaturized) {
1165 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1166 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1167 || (file && !wwin->icon->file)) {
1168 wIconChangeImageFile(wwin->icon, file);
1171 wwin = wwin->prev;
1175 /* --------------------------- Local ----------------------- */
1177 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1178 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1179 entry->key, x); \
1180 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1181 var = entry->default_value;\
1182 } else var = WMGetFromPLString(value)\
1185 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1187 char *str;
1188 WOptionEnumeration *v;
1189 char buffer[TOTAL_VALUES_LENGTH];
1191 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1192 for (v = values; v->string != NULL; v++) {
1193 if (strcasecmp(v->string, str) == 0)
1194 return v->value;
1198 buffer[0] = 0;
1199 for (v = values; v->string != NULL; v++) {
1200 if (!v->is_alias) {
1201 if (buffer[0] != 0)
1202 strcat(buffer, ", ");
1203 snprintf(buffer+strlen(buffer),
1204 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1207 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1208 WMGetFromPLString(key),
1209 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1210 buffer);
1212 if (def) {
1213 return string2index(key, val, NULL, values);
1216 return -1;
1220 * value - is the value in the defaults DB
1221 * addr - is the address to store the data
1222 * ret - is the address to store a pointer to a temporary buffer. ret
1223 * must not be freed and is used by the set functions
1225 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1227 static char data;
1228 char *val;
1229 int second_pass = 0;
1231 GET_STRING_OR_DEFAULT("Boolean", val);
1233 again:
1234 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1235 || strcasecmp(val, "YES") == 0) {
1237 data = 1;
1238 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1239 || strcasecmp(val, "NO") == 0) {
1240 data = 0;
1241 } else {
1242 int i;
1243 if (sscanf(val, "%i", &i) == 1) {
1244 if (i != 0)
1245 data = 1;
1246 else
1247 data = 0;
1248 } else {
1249 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1250 if (second_pass == 0) {
1251 val = WMGetFromPLString(entry->plvalue);
1252 second_pass = 1;
1253 wwarning(_("using default \"%s\" instead"), val);
1254 goto again;
1256 return False;
1260 if (ret)
1261 *ret = &data;
1262 if (addr)
1263 *(char *)addr = data;
1265 return True;
1268 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1270 static int data;
1271 char *val;
1273 GET_STRING_OR_DEFAULT("Integer", val);
1275 if (sscanf(val, "%i", &data) != 1) {
1276 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1277 val = WMGetFromPLString(entry->plvalue);
1278 wwarning(_("using default \"%s\" instead"), val);
1279 if (sscanf(val, "%i", &data) != 1) {
1280 return False;
1284 if (ret)
1285 *ret = &data;
1286 if (addr)
1287 *(int *)addr = data;
1289 return True;
1292 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1294 static WCoord data;
1295 char *val_x, *val_y;
1296 int nelem, changed = 0;
1297 WMPropList *elem_x, *elem_y;
1299 again:
1300 if (!WMIsPLArray(value)) {
1301 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1302 if (changed == 0) {
1303 value = entry->plvalue;
1304 changed = 1;
1305 wwarning(_("using default \"%s\" instead"), entry->default_value);
1306 goto again;
1308 return False;
1311 nelem = WMGetPropListItemCount(value);
1312 if (nelem != 2) {
1313 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1314 if (changed == 0) {
1315 value = entry->plvalue;
1316 changed = 1;
1317 wwarning(_("using default \"%s\" instead"), entry->default_value);
1318 goto again;
1320 return False;
1323 elem_x = WMGetFromPLArray(value, 0);
1324 elem_y = WMGetFromPLArray(value, 1);
1326 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1327 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1328 if (changed == 0) {
1329 value = entry->plvalue;
1330 changed = 1;
1331 wwarning(_("using default \"%s\" instead"), entry->default_value);
1332 goto again;
1334 return False;
1337 val_x = WMGetFromPLString(elem_x);
1338 val_y = WMGetFromPLString(elem_y);
1340 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1341 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1342 if (changed == 0) {
1343 value = entry->plvalue;
1344 changed = 1;
1345 wwarning(_("using default \"%s\" instead"), entry->default_value);
1346 goto again;
1348 return False;
1351 if (data.x < 0)
1352 data.x = 0;
1353 else if (data.x > scr->scr_width / 3)
1354 data.x = scr->scr_width / 3;
1355 if (data.y < 0)
1356 data.y = 0;
1357 else if (data.y > scr->scr_height / 3)
1358 data.y = scr->scr_height / 3;
1360 if (ret)
1361 *ret = &data;
1362 if (addr)
1363 *(WCoord *) addr = data;
1365 return True;
1368 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1370 WMRetainPropList(value);
1372 *ret = value;
1374 return True;
1377 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1379 static char *data;
1380 int i, count, len;
1381 char *ptr;
1382 WMPropList *d;
1383 int changed = 0;
1385 again:
1386 if (!WMIsPLArray(value)) {
1387 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1388 if (changed == 0) {
1389 value = entry->plvalue;
1390 changed = 1;
1391 wwarning(_("using default \"%s\" instead"), entry->default_value);
1392 goto again;
1394 return False;
1397 i = 0;
1398 count = WMGetPropListItemCount(value);
1399 if (count < 1) {
1400 if (changed == 0) {
1401 value = entry->plvalue;
1402 changed = 1;
1403 wwarning(_("using default \"%s\" instead"), entry->default_value);
1404 goto again;
1406 return False;
1409 len = 0;
1410 for (i = 0; i < count; i++) {
1411 d = WMGetFromPLArray(value, i);
1412 if (!d || !WMIsPLString(d)) {
1413 count = i;
1414 break;
1416 len += strlen(WMGetFromPLString(d)) + 1;
1419 ptr = data = wmalloc(len + 1);
1421 for (i = 0; i < count; i++) {
1422 d = WMGetFromPLArray(value, i);
1423 if (!d || !WMIsPLString(d)) {
1424 break;
1426 strcpy(ptr, WMGetFromPLString(d));
1427 ptr += strlen(WMGetFromPLString(d));
1428 *ptr = ':';
1429 ptr++;
1431 ptr--;
1432 *(ptr--) = 0;
1434 if (*(char **)addr != NULL) {
1435 wfree(*(char **)addr);
1437 *(char **)addr = data;
1439 return True;
1442 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1444 static signed char data;
1446 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1447 if (data < 0)
1448 return False;
1450 if (ret)
1451 *ret = &data;
1452 if (addr)
1453 *(signed char *)addr = data;
1455 return True;
1459 * (solid <color>)
1460 * (hgradient <color> <color>)
1461 * (vgradient <color> <color>)
1462 * (dgradient <color> <color>)
1463 * (mhgradient <color> <color> ...)
1464 * (mvgradient <color> <color> ...)
1465 * (mdgradient <color> <color> ...)
1466 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1467 * (tpixmap <file> <color>)
1468 * (spixmap <file> <color>)
1469 * (cpixmap <file> <color>)
1470 * (thgradient <file> <opaqueness> <color> <color>)
1471 * (tvgradient <file> <opaqueness> <color> <color>)
1472 * (tdgradient <file> <opaqueness> <color> <color>)
1473 * (function <lib> <function> ...)
1476 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1478 WMPropList *elem;
1479 char *val;
1480 int nelem;
1481 WTexture *texture = NULL;
1483 nelem = WMGetPropListItemCount(pl);
1484 if (nelem < 1)
1485 return NULL;
1487 elem = WMGetFromPLArray(pl, 0);
1488 if (!elem || !WMIsPLString(elem))
1489 return NULL;
1490 val = WMGetFromPLString(elem);
1492 if (strcasecmp(val, "solid") == 0) {
1493 XColor color;
1495 if (nelem != 2)
1496 return NULL;
1498 /* get color */
1500 elem = WMGetFromPLArray(pl, 1);
1501 if (!elem || !WMIsPLString(elem))
1502 return NULL;
1503 val = WMGetFromPLString(elem);
1505 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1506 wwarning(_("\"%s\" is not a valid color name"), val);
1507 return NULL;
1510 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1511 } else if (strcasecmp(val, "dgradient") == 0
1512 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1513 RColor color1, color2;
1514 XColor xcolor;
1515 int type;
1517 if (nelem != 3) {
1518 wwarning(_("bad number of arguments in gradient specification"));
1519 return NULL;
1522 if (val[0] == 'd' || val[0] == 'D')
1523 type = WTEX_DGRADIENT;
1524 else if (val[0] == 'h' || val[0] == 'H')
1525 type = WTEX_HGRADIENT;
1526 else
1527 type = WTEX_VGRADIENT;
1529 /* get from color */
1530 elem = WMGetFromPLArray(pl, 1);
1531 if (!elem || !WMIsPLString(elem))
1532 return NULL;
1533 val = WMGetFromPLString(elem);
1535 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1536 wwarning(_("\"%s\" is not a valid color name"), val);
1537 return NULL;
1539 color1.alpha = 255;
1540 color1.red = xcolor.red >> 8;
1541 color1.green = xcolor.green >> 8;
1542 color1.blue = xcolor.blue >> 8;
1544 /* get to color */
1545 elem = WMGetFromPLArray(pl, 2);
1546 if (!elem || !WMIsPLString(elem)) {
1547 return NULL;
1549 val = WMGetFromPLString(elem);
1551 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1552 wwarning(_("\"%s\" is not a valid color name"), val);
1553 return NULL;
1555 color2.alpha = 255;
1556 color2.red = xcolor.red >> 8;
1557 color2.green = xcolor.green >> 8;
1558 color2.blue = xcolor.blue >> 8;
1560 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1562 } else if (strcasecmp(val, "igradient") == 0) {
1563 RColor colors1[2], colors2[2];
1564 int th1, th2;
1565 XColor xcolor;
1566 int i;
1568 if (nelem != 7) {
1569 wwarning(_("bad number of arguments in gradient specification"));
1570 return NULL;
1573 /* get from color */
1574 for (i = 0; i < 2; i++) {
1575 elem = WMGetFromPLArray(pl, 1 + i);
1576 if (!elem || !WMIsPLString(elem))
1577 return NULL;
1578 val = WMGetFromPLString(elem);
1580 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1581 wwarning(_("\"%s\" is not a valid color name"), val);
1582 return NULL;
1584 colors1[i].alpha = 255;
1585 colors1[i].red = xcolor.red >> 8;
1586 colors1[i].green = xcolor.green >> 8;
1587 colors1[i].blue = xcolor.blue >> 8;
1589 elem = WMGetFromPLArray(pl, 3);
1590 if (!elem || !WMIsPLString(elem))
1591 return NULL;
1592 val = WMGetFromPLString(elem);
1593 th1 = atoi(val);
1595 /* get from color */
1596 for (i = 0; i < 2; i++) {
1597 elem = WMGetFromPLArray(pl, 4 + i);
1598 if (!elem || !WMIsPLString(elem))
1599 return NULL;
1600 val = WMGetFromPLString(elem);
1602 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1603 wwarning(_("\"%s\" is not a valid color name"), val);
1604 return NULL;
1606 colors2[i].alpha = 255;
1607 colors2[i].red = xcolor.red >> 8;
1608 colors2[i].green = xcolor.green >> 8;
1609 colors2[i].blue = xcolor.blue >> 8;
1611 elem = WMGetFromPLArray(pl, 6);
1612 if (!elem || !WMIsPLString(elem))
1613 return NULL;
1614 val = WMGetFromPLString(elem);
1615 th2 = atoi(val);
1617 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1619 } else if (strcasecmp(val, "mhgradient") == 0
1620 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1621 XColor color;
1622 RColor **colors;
1623 int i, count;
1624 int type;
1626 if (nelem < 3) {
1627 wwarning(_("too few arguments in multicolor gradient specification"));
1628 return NULL;
1631 if (val[1] == 'h' || val[1] == 'H')
1632 type = WTEX_MHGRADIENT;
1633 else if (val[1] == 'v' || val[1] == 'V')
1634 type = WTEX_MVGRADIENT;
1635 else
1636 type = WTEX_MDGRADIENT;
1638 count = nelem - 1;
1640 colors = wmalloc(sizeof(RColor *) * (count + 1));
1642 for (i = 0; i < count; i++) {
1643 elem = WMGetFromPLArray(pl, i + 1);
1644 if (!elem || !WMIsPLString(elem)) {
1645 for (--i; i >= 0; --i) {
1646 wfree(colors[i]);
1648 wfree(colors);
1649 return NULL;
1651 val = WMGetFromPLString(elem);
1653 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1654 wwarning(_("\"%s\" is not a valid color name"), val);
1655 for (--i; i >= 0; --i) {
1656 wfree(colors[i]);
1658 wfree(colors);
1659 return NULL;
1660 } else {
1661 colors[i] = wmalloc(sizeof(RColor));
1662 colors[i]->red = color.red >> 8;
1663 colors[i]->green = color.green >> 8;
1664 colors[i]->blue = color.blue >> 8;
1667 colors[i] = NULL;
1669 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1670 } else if (strcasecmp(val, "spixmap") == 0 ||
1671 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1672 XColor color;
1673 int type;
1675 if (nelem != 3)
1676 return NULL;
1678 if (val[0] == 's' || val[0] == 'S')
1679 type = WTP_SCALE;
1680 else if (val[0] == 'c' || val[0] == 'C')
1681 type = WTP_CENTER;
1682 else
1683 type = WTP_TILE;
1685 /* get color */
1686 elem = WMGetFromPLArray(pl, 2);
1687 if (!elem || !WMIsPLString(elem)) {
1688 return NULL;
1690 val = WMGetFromPLString(elem);
1692 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1693 wwarning(_("\"%s\" is not a valid color name"), val);
1694 return NULL;
1697 /* file name */
1698 elem = WMGetFromPLArray(pl, 1);
1699 if (!elem || !WMIsPLString(elem))
1700 return NULL;
1701 val = WMGetFromPLString(elem);
1703 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1704 } else if (strcasecmp(val, "thgradient") == 0
1705 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1706 RColor color1, color2;
1707 XColor xcolor;
1708 int opacity;
1709 int style;
1711 if (val[1] == 'h' || val[1] == 'H')
1712 style = WTEX_THGRADIENT;
1713 else if (val[1] == 'v' || val[1] == 'V')
1714 style = WTEX_TVGRADIENT;
1715 else
1716 style = WTEX_TDGRADIENT;
1718 if (nelem != 5) {
1719 wwarning(_("bad number of arguments in textured gradient specification"));
1720 return NULL;
1723 /* get from color */
1724 elem = WMGetFromPLArray(pl, 3);
1725 if (!elem || !WMIsPLString(elem))
1726 return NULL;
1727 val = WMGetFromPLString(elem);
1729 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1730 wwarning(_("\"%s\" is not a valid color name"), val);
1731 return NULL;
1733 color1.alpha = 255;
1734 color1.red = xcolor.red >> 8;
1735 color1.green = xcolor.green >> 8;
1736 color1.blue = xcolor.blue >> 8;
1738 /* get to color */
1739 elem = WMGetFromPLArray(pl, 4);
1740 if (!elem || !WMIsPLString(elem)) {
1741 return NULL;
1743 val = WMGetFromPLString(elem);
1745 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1746 wwarning(_("\"%s\" is not a valid color name"), val);
1747 return NULL;
1749 color2.alpha = 255;
1750 color2.red = xcolor.red >> 8;
1751 color2.green = xcolor.green >> 8;
1752 color2.blue = xcolor.blue >> 8;
1754 /* get opacity */
1755 elem = WMGetFromPLArray(pl, 2);
1756 if (!elem || !WMIsPLString(elem))
1757 opacity = 128;
1758 else
1759 val = WMGetFromPLString(elem);
1761 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1762 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1763 opacity = 128;
1766 /* get file name */
1767 elem = WMGetFromPLArray(pl, 1);
1768 if (!elem || !WMIsPLString(elem))
1769 return NULL;
1770 val = WMGetFromPLString(elem);
1772 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1773 } else if (strcasecmp(val, "function") == 0) {
1774 /* Leave this in to handle the unlikely case of
1775 * someone actually having function textures configured */
1776 wwarning("function texture support has been removed");
1777 return NULL;
1778 } else {
1779 wwarning(_("invalid texture type %s"), val);
1780 return NULL;
1782 return texture;
1785 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1787 static WTexture *texture;
1788 int changed = 0;
1790 again:
1791 if (!WMIsPLArray(value)) {
1792 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1793 if (changed == 0) {
1794 value = entry->plvalue;
1795 changed = 1;
1796 wwarning(_("using default \"%s\" instead"), entry->default_value);
1797 goto again;
1799 return False;
1802 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1803 WMPropList *pl;
1805 pl = WMGetFromPLArray(value, 0);
1806 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1807 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1808 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1809 entry->key, "Solid Texture");
1811 value = entry->plvalue;
1812 changed = 1;
1813 wwarning(_("using default \"%s\" instead"), entry->default_value);
1814 goto again;
1818 texture = parse_texture(scr, value);
1820 if (!texture) {
1821 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1822 if (changed == 0) {
1823 value = entry->plvalue;
1824 changed = 1;
1825 wwarning(_("using default \"%s\" instead"), entry->default_value);
1826 goto again;
1828 return False;
1831 if (ret)
1832 *ret = &texture;
1834 if (addr)
1835 *(WTexture **) addr = texture;
1837 return True;
1840 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1842 WMPropList *elem;
1843 int changed = 0;
1844 char *val;
1845 int nelem;
1847 again:
1848 if (!WMIsPLArray(value)) {
1849 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1850 "WorkspaceBack", "Texture or None");
1851 if (changed == 0) {
1852 value = entry->plvalue;
1853 changed = 1;
1854 wwarning(_("using default \"%s\" instead"), entry->default_value);
1855 goto again;
1857 return False;
1860 /* only do basic error checking and verify for None texture */
1862 nelem = WMGetPropListItemCount(value);
1863 if (nelem > 0) {
1864 elem = WMGetFromPLArray(value, 0);
1865 if (!elem || !WMIsPLString(elem)) {
1866 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1867 if (changed == 0) {
1868 value = entry->plvalue;
1869 changed = 1;
1870 wwarning(_("using default \"%s\" instead"), entry->default_value);
1871 goto again;
1873 return False;
1875 val = WMGetFromPLString(elem);
1877 if (strcasecmp(val, "None") == 0)
1878 return True;
1880 *ret = WMRetainPropList(value);
1882 return True;
1885 static int
1886 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1888 WMPropList *elem;
1889 int nelem;
1890 int changed = 0;
1892 again:
1893 if (!WMIsPLArray(value)) {
1894 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1895 "WorkspaceSpecificBack", "an array of textures");
1896 if (changed == 0) {
1897 value = entry->plvalue;
1898 changed = 1;
1899 wwarning(_("using default \"%s\" instead"), entry->default_value);
1900 goto again;
1902 return False;
1905 /* only do basic error checking and verify for None texture */
1907 nelem = WMGetPropListItemCount(value);
1908 if (nelem > 0) {
1909 while (nelem--) {
1910 elem = WMGetFromPLArray(value, nelem);
1911 if (!elem || !WMIsPLArray(elem)) {
1912 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1913 nelem);
1918 *ret = WMRetainPropList(value);
1920 #ifdef notworking
1922 * Kluge to force wmsetbg helper to set the default background.
1923 * If the WorkspaceSpecificBack is changed once wmaker has started,
1924 * the WorkspaceBack won't be sent to the helper, unless the user
1925 * changes it's value too. So, we must force this by removing the
1926 * value from the defaults DB.
1928 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1929 WMPropList *key = WMCreatePLString("WorkspaceBack");
1931 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1933 WMReleasePropList(key);
1935 #endif
1936 return True;
1939 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1941 static WMFont *font;
1942 char *val;
1944 GET_STRING_OR_DEFAULT("Font", val);
1946 font = WMCreateFont(scr->wmscreen, val);
1947 if (!font)
1948 font = WMCreateFont(scr->wmscreen, "fixed");
1950 if (!font) {
1951 wfatal(_("could not load any usable font!!!"));
1952 exit(1);
1955 if (ret)
1956 *ret = font;
1958 /* can't assign font value outside update function */
1959 wassertrv(addr == NULL, True);
1961 return True;
1964 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1966 static XColor color;
1967 char *val;
1968 int second_pass = 0;
1970 GET_STRING_OR_DEFAULT("Color", val);
1972 again:
1973 if (!wGetColor(scr, val, &color)) {
1974 wwarning(_("could not get color for key \"%s\""), entry->key);
1975 if (second_pass == 0) {
1976 val = WMGetFromPLString(entry->plvalue);
1977 second_pass = 1;
1978 wwarning(_("using default \"%s\" instead"), val);
1979 goto again;
1981 return False;
1984 if (ret)
1985 *ret = &color;
1987 assert(addr == NULL);
1989 if (addr)
1990 *(unsigned long*)addr = pixel;
1993 return True;
1996 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1998 static WShortKey shortcut;
1999 KeySym ksym;
2000 char *val;
2001 char *k;
2002 char buf[MAX_SHORTCUT_LENGTH], *b;
2004 GET_STRING_OR_DEFAULT("Key spec", val);
2006 if (!val || strcasecmp(val, "NONE") == 0) {
2007 shortcut.keycode = 0;
2008 shortcut.modifier = 0;
2009 if (ret)
2010 *ret = &shortcut;
2011 return True;
2014 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2016 b = (char *)buf;
2018 /* get modifiers */
2019 shortcut.modifier = 0;
2020 while ((k = strchr(b, '+')) != NULL) {
2021 int mod;
2023 *k = 0;
2024 mod = wXModifierFromKey(b);
2025 if (mod < 0) {
2026 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2027 return False;
2029 shortcut.modifier |= mod;
2031 b = k + 1;
2034 /* get key */
2035 ksym = XStringToKeysym(b);
2037 if (ksym == NoSymbol) {
2038 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2039 return False;
2042 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2043 if (shortcut.keycode == 0) {
2044 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2045 return False;
2048 if (ret)
2049 *ret = &shortcut;
2051 return True;
2054 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2056 static int mask;
2057 char *str;
2059 GET_STRING_OR_DEFAULT("Modifier Key", str);
2061 if (!str)
2062 return False;
2064 mask = wXModifierFromKey(str);
2065 if (mask < 0) {
2066 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2067 mask = 0;
2068 return False;
2071 if (addr)
2072 *(int *)addr = mask;
2074 if (ret)
2075 *ret = &mask;
2077 return True;
2080 # include <X11/cursorfont.h>
2081 typedef struct {
2082 char *name;
2083 int id;
2084 } WCursorLookup;
2086 #define CURSOR_ID_NONE (XC_num_glyphs)
2088 static WCursorLookup cursor_table[] = {
2089 {"X_cursor", XC_X_cursor},
2090 {"arrow", XC_arrow},
2091 {"based_arrow_down", XC_based_arrow_down},
2092 {"based_arrow_up", XC_based_arrow_up},
2093 {"boat", XC_boat},
2094 {"bogosity", XC_bogosity},
2095 {"bottom_left_corner", XC_bottom_left_corner},
2096 {"bottom_right_corner", XC_bottom_right_corner},
2097 {"bottom_side", XC_bottom_side},
2098 {"bottom_tee", XC_bottom_tee},
2099 {"box_spiral", XC_box_spiral},
2100 {"center_ptr", XC_center_ptr},
2101 {"circle", XC_circle},
2102 {"clock", XC_clock},
2103 {"coffee_mug", XC_coffee_mug},
2104 {"cross", XC_cross},
2105 {"cross_reverse", XC_cross_reverse},
2106 {"crosshair", XC_crosshair},
2107 {"diamond_cross", XC_diamond_cross},
2108 {"dot", XC_dot},
2109 {"dotbox", XC_dotbox},
2110 {"double_arrow", XC_double_arrow},
2111 {"draft_large", XC_draft_large},
2112 {"draft_small", XC_draft_small},
2113 {"draped_box", XC_draped_box},
2114 {"exchange", XC_exchange},
2115 {"fleur", XC_fleur},
2116 {"gobbler", XC_gobbler},
2117 {"gumby", XC_gumby},
2118 {"hand1", XC_hand1},
2119 {"hand2", XC_hand2},
2120 {"heart", XC_heart},
2121 {"icon", XC_icon},
2122 {"iron_cross", XC_iron_cross},
2123 {"left_ptr", XC_left_ptr},
2124 {"left_side", XC_left_side},
2125 {"left_tee", XC_left_tee},
2126 {"leftbutton", XC_leftbutton},
2127 {"ll_angle", XC_ll_angle},
2128 {"lr_angle", XC_lr_angle},
2129 {"man", XC_man},
2130 {"middlebutton", XC_middlebutton},
2131 {"mouse", XC_mouse},
2132 {"pencil", XC_pencil},
2133 {"pirate", XC_pirate},
2134 {"plus", XC_plus},
2135 {"question_arrow", XC_question_arrow},
2136 {"right_ptr", XC_right_ptr},
2137 {"right_side", XC_right_side},
2138 {"right_tee", XC_right_tee},
2139 {"rightbutton", XC_rightbutton},
2140 {"rtl_logo", XC_rtl_logo},
2141 {"sailboat", XC_sailboat},
2142 {"sb_down_arrow", XC_sb_down_arrow},
2143 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2144 {"sb_left_arrow", XC_sb_left_arrow},
2145 {"sb_right_arrow", XC_sb_right_arrow},
2146 {"sb_up_arrow", XC_sb_up_arrow},
2147 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2148 {"shuttle", XC_shuttle},
2149 {"sizing", XC_sizing},
2150 {"spider", XC_spider},
2151 {"spraycan", XC_spraycan},
2152 {"star", XC_star},
2153 {"target", XC_target},
2154 {"tcross", XC_tcross},
2155 {"top_left_arrow", XC_top_left_arrow},
2156 {"top_left_corner", XC_top_left_corner},
2157 {"top_right_corner", XC_top_right_corner},
2158 {"top_side", XC_top_side},
2159 {"top_tee", XC_top_tee},
2160 {"trek", XC_trek},
2161 {"ul_angle", XC_ul_angle},
2162 {"umbrella", XC_umbrella},
2163 {"ur_angle", XC_ur_angle},
2164 {"watch", XC_watch},
2165 {"xterm", XC_xterm},
2166 {NULL, CURSOR_ID_NONE}
2169 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2171 switch (status) {
2172 case BitmapOpenFailed:
2173 wwarning(_("failed to open bitmap file \"%s\""), filename);
2174 break;
2175 case BitmapFileInvalid:
2176 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2177 break;
2178 case BitmapNoMemory:
2179 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2180 break;
2181 case BitmapSuccess:
2182 XFreePixmap(dpy, bitmap);
2183 break;
2188 * (none)
2189 * (builtin, <cursor_name>)
2190 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2192 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2194 WMPropList *elem;
2195 char *val;
2196 int nelem;
2197 int status = 0;
2199 nelem = WMGetPropListItemCount(pl);
2200 if (nelem < 1) {
2201 return (status);
2203 elem = WMGetFromPLArray(pl, 0);
2204 if (!elem || !WMIsPLString(elem)) {
2205 return (status);
2207 val = WMGetFromPLString(elem);
2209 if (strcasecmp(val, "none") == 0) {
2210 status = 1;
2211 *cursor = None;
2212 } else if (strcasecmp(val, "builtin") == 0) {
2213 int i;
2214 int cursor_id = CURSOR_ID_NONE;
2216 if (nelem != 2) {
2217 wwarning(_("bad number of arguments in cursor specification"));
2218 return (status);
2220 elem = WMGetFromPLArray(pl, 1);
2221 if (!elem || !WMIsPLString(elem)) {
2222 return (status);
2224 val = WMGetFromPLString(elem);
2226 for (i = 0; cursor_table[i].name != NULL; i++) {
2227 if (strcasecmp(val, cursor_table[i].name) == 0) {
2228 cursor_id = cursor_table[i].id;
2229 break;
2232 if (CURSOR_ID_NONE == cursor_id) {
2233 wwarning(_("unknown builtin cursor name \"%s\""), val);
2234 } else {
2235 *cursor = XCreateFontCursor(dpy, cursor_id);
2236 status = 1;
2238 } else if (strcasecmp(val, "bitmap") == 0) {
2239 char *bitmap_name;
2240 char *mask_name;
2241 int bitmap_status;
2242 int mask_status;
2243 Pixmap bitmap;
2244 Pixmap mask;
2245 unsigned int w, h;
2246 int x, y;
2247 XColor fg, bg;
2249 if (nelem != 3) {
2250 wwarning(_("bad number of arguments in cursor specification"));
2251 return (status);
2253 elem = WMGetFromPLArray(pl, 1);
2254 if (!elem || !WMIsPLString(elem)) {
2255 return (status);
2257 val = WMGetFromPLString(elem);
2258 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2259 if (!bitmap_name) {
2260 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2261 return (status);
2263 elem = WMGetFromPLArray(pl, 2);
2264 if (!elem || !WMIsPLString(elem)) {
2265 wfree(bitmap_name);
2266 return (status);
2268 val = WMGetFromPLString(elem);
2269 mask_name = FindImage(wPreferences.pixmap_path, val);
2270 if (!mask_name) {
2271 wfree(bitmap_name);
2272 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2273 return (status);
2275 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2276 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2277 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2278 fg.pixel = scr->black_pixel;
2279 bg.pixel = scr->white_pixel;
2280 XQueryColor(dpy, scr->w_colormap, &fg);
2281 XQueryColor(dpy, scr->w_colormap, &bg);
2282 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2283 status = 1;
2285 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2286 check_bitmap_status(mask_status, mask_name, mask);
2287 wfree(bitmap_name);
2288 wfree(mask_name);
2290 return (status);
2293 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2295 static Cursor cursor;
2296 int status;
2297 int changed = 0;
2299 again:
2300 if (!WMIsPLArray(value)) {
2301 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2302 entry->key, "cursor specification");
2303 if (!changed) {
2304 value = entry->plvalue;
2305 changed = 1;
2306 wwarning(_("using default \"%s\" instead"), entry->default_value);
2307 goto again;
2309 return (False);
2311 status = parse_cursor(scr, value, &cursor);
2312 if (!status) {
2313 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2314 if (!changed) {
2315 value = entry->plvalue;
2316 changed = 1;
2317 wwarning(_("using default \"%s\" instead"), entry->default_value);
2318 goto again;
2320 return (False);
2322 if (ret) {
2323 *ret = &cursor;
2325 if (addr) {
2326 *(Cursor *) addr = cursor;
2328 return (True);
2331 #undef CURSOR_ID_NONE
2333 /* ---------------- value setting functions --------------- */
2334 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2336 return REFRESH_WINDOW_TITLE_COLOR;
2339 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2341 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2344 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2346 switch (which) {
2347 case WM_DOCK:
2348 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2349 break;
2350 case WM_CLIP:
2351 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2352 break;
2353 default:
2354 break;
2356 return 0;
2359 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2361 if (scr->workspaces) {
2362 wWorkspaceForceChange(scr, scr->current_workspace);
2363 wArrangeIcons(scr, False);
2365 return 0;
2368 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2370 Pixmap pixmap;
2371 RImage *img;
2372 int reset = 0;
2374 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2375 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2376 ? WREL_ICON : WREL_FLAT);
2377 if (!img) {
2378 wwarning(_("could not render texture for icon background"));
2379 if (!entry->addr)
2380 wTextureDestroy(scr, *texture);
2381 return 0;
2383 RConvertImage(scr->rcontext, img, &pixmap);
2385 if (scr->icon_tile) {
2386 reset = 1;
2387 RReleaseImage(scr->icon_tile);
2388 XFreePixmap(dpy, scr->icon_tile_pixmap);
2391 scr->icon_tile = img;
2393 /* put the icon in the noticeboard hint */
2394 PropSetIconTileHint(scr, img);
2396 if (!wPreferences.flags.noclip) {
2397 if (scr->clip_tile) {
2398 RReleaseImage(scr->clip_tile);
2400 scr->clip_tile = wClipMakeTile(scr, img);
2403 scr->icon_tile_pixmap = pixmap;
2405 if (scr->def_icon_pixmap) {
2406 XFreePixmap(dpy, scr->def_icon_pixmap);
2407 scr->def_icon_pixmap = None;
2409 if (scr->def_ticon_pixmap) {
2410 XFreePixmap(dpy, scr->def_ticon_pixmap);
2411 scr->def_ticon_pixmap = None;
2414 if (scr->icon_back_texture) {
2415 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2417 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2419 if (scr->clip_balloon)
2420 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2423 * Free the texture as nobody else will use it, nor refer to it.
2425 if (!entry->addr)
2426 wTextureDestroy(scr, *texture);
2428 return (reset ? REFRESH_ICON_TILE : 0);
2431 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2433 if (scr->title_font) {
2434 WMReleaseFont(scr->title_font);
2436 scr->title_font = font;
2438 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2441 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2443 if (scr->menu_title_font) {
2444 WMReleaseFont(scr->menu_title_font);
2447 scr->menu_title_font = font;
2449 return REFRESH_MENU_TITLE_FONT;
2452 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2454 if (scr->menu_entry_font) {
2455 WMReleaseFont(scr->menu_entry_font);
2457 scr->menu_entry_font = font;
2459 return REFRESH_MENU_FONT;
2462 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2464 if (scr->icon_title_font) {
2465 WMReleaseFont(scr->icon_title_font);
2468 scr->icon_title_font = font;
2470 return REFRESH_ICON_FONT;
2473 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2475 if (scr->clip_title_font) {
2476 WMReleaseFont(scr->clip_title_font);
2479 scr->clip_title_font = font;
2481 return REFRESH_ICON_FONT;
2484 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2486 if (scr->workspace_name_font) {
2487 WMReleaseFont(scr->workspace_name_font);
2490 scr->workspace_name_font = font;
2492 return 0;
2495 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2497 if (scr->select_color)
2498 WMReleaseColor(scr->select_color);
2500 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2502 wFreeColor(scr, color->pixel);
2504 return REFRESH_MENU_COLOR;
2507 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2509 if (scr->select_text_color)
2510 WMReleaseColor(scr->select_text_color);
2512 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2514 wFreeColor(scr, color->pixel);
2516 return REFRESH_MENU_COLOR;
2519 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2521 if (scr->clip_title_color[widx])
2522 WMReleaseColor(scr->clip_title_color[widx]);
2524 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2525 wFreeColor(scr, color->pixel);
2527 return REFRESH_ICON_TITLE_COLOR;
2530 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2532 if (scr->window_title_color[widx])
2533 WMReleaseColor(scr->window_title_color[widx]);
2535 scr->window_title_color[widx] =
2536 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2538 wFreeColor(scr, color->pixel);
2540 return REFRESH_WINDOW_TITLE_COLOR;
2543 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2545 if (scr->menu_title_color[0])
2546 WMReleaseColor(scr->menu_title_color[0]);
2548 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2550 wFreeColor(scr, color->pixel);
2552 return REFRESH_MENU_TITLE_COLOR;
2555 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2557 if (scr->mtext_color)
2558 WMReleaseColor(scr->mtext_color);
2560 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2562 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2563 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2564 } else {
2565 WMSetColorAlpha(scr->dtext_color, 0xffff);
2568 wFreeColor(scr, color->pixel);
2570 return REFRESH_MENU_COLOR;
2573 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2575 if (scr->dtext_color)
2576 WMReleaseColor(scr->dtext_color);
2578 scr->dtext_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 setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2593 if (scr->icon_title_color)
2594 WMReleaseColor(scr->icon_title_color);
2595 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2597 wFreeColor(scr, color->pixel);
2599 return REFRESH_ICON_TITLE_COLOR;
2602 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2604 if (scr->icon_title_texture) {
2605 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2607 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2609 return REFRESH_ICON_TITLE_BACK;
2612 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2614 close(scr->helper_fd);
2615 scr->helper_fd = 0;
2616 scr->helper_pid = 0;
2617 scr->flags.backimage_helper_launched = 0;
2620 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2622 WMPropList *val;
2623 char *str;
2624 int i;
2626 if (scr->flags.backimage_helper_launched) {
2627 if (WMGetPropListItemCount(value) == 0) {
2628 SendHelperMessage(scr, 'C', 0, NULL);
2629 SendHelperMessage(scr, 'K', 0, NULL);
2631 WMReleasePropList(value);
2632 return 0;
2634 } else {
2635 pid_t pid;
2636 int filedes[2];
2638 if (WMGetPropListItemCount(value) == 0)
2639 return 0;
2641 if (pipe(filedes) < 0) {
2642 werror("pipe() failed:can't set workspace specific background image");
2644 WMReleasePropList(value);
2645 return 0;
2648 pid = fork();
2649 if (pid < 0) {
2650 werror("fork() failed:can't set workspace specific background image");
2651 if (close(filedes[0]) < 0)
2652 werror("could not close pipe");
2653 if (close(filedes[1]) < 0)
2654 werror("could not close pipe");
2656 } else if (pid == 0) {
2657 char *dither;
2659 SetupEnvironment(scr);
2661 if (close(0) < 0)
2662 werror("could not close pipe");
2663 if (dup(filedes[0]) < 0) {
2664 werror("dup() failed:can't set workspace specific background image");
2666 dither = wPreferences.no_dithering ? "-m" : "-d";
2667 if (wPreferences.smooth_workspace_back)
2668 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2669 else
2670 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2671 werror("could not execute wmsetbg");
2672 exit(1);
2673 } else {
2675 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2676 werror("error setting close-on-exec flag");
2678 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2679 werror("error setting close-on-exec flag");
2682 scr->helper_fd = filedes[1];
2683 scr->helper_pid = pid;
2684 scr->flags.backimage_helper_launched = 1;
2686 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2688 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2693 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2694 val = WMGetFromPLArray(value, i);
2695 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2696 str = WMGetPropListDescription(val, False);
2698 SendHelperMessage(scr, 'S', i + 1, str);
2700 wfree(str);
2701 } else {
2702 SendHelperMessage(scr, 'U', i + 1, NULL);
2705 sleep(1);
2707 WMReleasePropList(value);
2708 return 0;
2711 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2713 if (scr->flags.backimage_helper_launched) {
2714 char *str;
2716 if (WMGetPropListItemCount(value) == 0) {
2717 SendHelperMessage(scr, 'U', 0, NULL);
2718 } else {
2719 /* set the default workspace background to this one */
2720 str = WMGetPropListDescription(value, False);
2721 if (str) {
2722 SendHelperMessage(scr, 'S', 0, str);
2723 wfree(str);
2724 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2725 } else {
2726 SendHelperMessage(scr, 'U', 0, NULL);
2729 } else if (WMGetPropListItemCount(value) > 0) {
2730 char *command;
2731 char *text;
2732 char *dither;
2733 int len;
2735 text = WMGetPropListDescription(value, False);
2736 len = strlen(text) + 40;
2737 command = wmalloc(len);
2738 dither = wPreferences.no_dithering ? "-m" : "-d";
2739 if (wPreferences.smooth_workspace_back)
2740 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2741 else
2742 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2743 wfree(text);
2744 ExecuteShellCommand(scr, command);
2745 wfree(command);
2747 WMReleasePropList(value);
2749 return 0;
2752 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2754 if (scr->widget_texture) {
2755 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2757 scr->widget_texture = *(WTexSolid **) texture;
2759 return 0;
2762 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2764 if (scr->window_title_texture[WS_FOCUSED]) {
2765 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2767 scr->window_title_texture[WS_FOCUSED] = *texture;
2769 return REFRESH_WINDOW_TEXTURES;
2772 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2774 if (scr->window_title_texture[WS_PFOCUSED]) {
2775 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2777 scr->window_title_texture[WS_PFOCUSED] = *texture;
2779 return REFRESH_WINDOW_TEXTURES;
2782 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2784 if (scr->window_title_texture[WS_UNFOCUSED]) {
2785 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2787 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2789 return REFRESH_WINDOW_TEXTURES;
2792 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2794 if (scr->resizebar_texture[0]) {
2795 wTextureDestroy(scr, scr->resizebar_texture[0]);
2797 scr->resizebar_texture[0] = *texture;
2799 return REFRESH_WINDOW_TEXTURES;
2802 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2804 if (scr->menu_title_texture[0]) {
2805 wTextureDestroy(scr, scr->menu_title_texture[0]);
2807 scr->menu_title_texture[0] = *texture;
2809 return REFRESH_MENU_TITLE_TEXTURE;
2812 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2814 if (scr->menu_item_texture) {
2815 wTextureDestroy(scr, scr->menu_item_texture);
2816 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2818 scr->menu_item_texture = *texture;
2820 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2822 return REFRESH_MENU_TEXTURE;
2825 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2827 WWindow *wwin;
2828 wKeyBindings[widx] = *shortcut;
2830 wwin = scr->focused_window;
2832 while (wwin != NULL) {
2833 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2835 if (!WFLAGP(wwin, no_bind_keys)) {
2836 wWindowSetKeyGrabs(wwin);
2838 wwin = wwin->prev;
2841 return 0;
2844 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2846 wScreenUpdateUsableArea(scr);
2847 wArrangeIcons(scr, True);
2849 return 0;
2852 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2854 wScreenUpdateUsableArea(scr);
2856 return 0;
2859 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2861 return REFRESH_MENU_TEXTURE;
2864 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2866 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2868 RCopyArea(img, image, x, y, w, h, 0, 0);
2870 return img;
2873 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2875 char *path;
2876 RImage *bgimage;
2877 int cwidth, cheight;
2878 WPreferences *prefs = (WPreferences *) foo;
2880 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2881 if (prefs->swtileImage)
2882 RReleaseImage(prefs->swtileImage);
2883 prefs->swtileImage = NULL;
2885 WMReleasePropList(array);
2886 return 0;
2889 switch (WMGetPropListItemCount(array)) {
2890 case 4:
2891 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2892 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2893 break;
2894 } else
2895 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2897 if (!path) {
2898 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2899 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2900 } else {
2901 bgimage = RLoadImage(scr->rcontext, path, 0);
2902 if (!bgimage) {
2903 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2904 wfree(path);
2905 } else {
2906 wfree(path);
2908 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2909 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2911 if (cwidth <= 0 || cheight <= 0 ||
2912 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2913 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2914 else {
2915 int i;
2916 int swidth, theight;
2917 for (i = 0; i < 9; i++) {
2918 if (prefs->swbackImage[i])
2919 RReleaseImage(prefs->swbackImage[i]);
2920 prefs->swbackImage[i] = NULL;
2922 swidth = (bgimage->width - cwidth) / 2;
2923 theight = (bgimage->height - cheight) / 2;
2925 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2926 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2927 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2928 swidth, theight);
2930 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2931 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2932 cwidth, cheight);
2933 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2934 swidth, cheight);
2936 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2937 swidth, theight);
2938 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2939 cwidth, theight);
2940 prefs->swbackImage[8] =
2941 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2942 theight);
2944 // check if anything failed
2945 for (i = 0; i < 9; i++) {
2946 if (!prefs->swbackImage[i]) {
2947 for (; i >= 0; --i) {
2948 RReleaseImage(prefs->swbackImage[i]);
2949 prefs->swbackImage[i] = NULL;
2951 break;
2955 RReleaseImage(bgimage);
2959 case 1:
2960 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
2961 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2962 break;
2963 } else
2964 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
2966 if (!path) {
2967 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2968 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
2969 } else {
2970 if (prefs->swtileImage)
2971 RReleaseImage(prefs->swtileImage);
2973 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
2974 if (!prefs->swtileImage) {
2975 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2977 wfree(path);
2979 break;
2981 default:
2982 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
2983 break;
2986 WMReleasePropList(array);
2988 return 0;
2991 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2993 int i;
2994 WPreferences *prefs = (WPreferences *) foo;
2996 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
2997 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
2998 WMReleasePropList(array);
2999 return 0;
3002 DestroyWindowMenu(scr);
3004 for (i = 0; i < 7; i++) {
3005 if (prefs->modifier_labels[i])
3006 wfree(prefs->modifier_labels[i]);
3008 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3009 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3010 } else {
3011 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3012 prefs->modifier_labels[i] = NULL;
3016 WMReleasePropList(array);
3018 return 0;
3022 * Very ugly kluge.
3023 * Need access to the double click variables, so that all widgets in
3024 * wmaker panels will have the same dbl-click values.
3025 * TODO: figure a better way of dealing with it.
3027 #include <WINGs/WINGsP.h>
3029 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3031 extern _WINGsConfiguration WINGsConfiguration;
3033 if (*value <= 0)
3034 *(int *)foo = 1;
3036 WINGsConfiguration.doubleClickDelay = *value;
3038 return 0;
3041 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3043 if (wCursor[widx] != None) {
3044 XFreeCursor(dpy, wCursor[widx]);
3047 wCursor[widx] = *cursor;
3049 if (widx == WCUR_ROOT && *cursor != None) {
3050 XDefineCursor(dpy, scr->root_win, *cursor);
3053 return 0;