Enable toggling of AppIcons bouncing
[wmaker-crm.git] / src / defaults.c
blobcb3501bf8fcb8ab46724f6c8031a6c78eb0921c5
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 {"DoNotMakeAppIconsBounce", "NO", NULL,
391 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
392 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
393 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
394 {"AlignSubmenus", "NO", NULL,
395 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
396 {"ViKeyMenus", "NO", NULL,
397 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
398 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
399 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
400 {"WindowPlacement", "auto", sePlacements,
401 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
402 {"IgnoreFocusClick", "NO", NULL,
403 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
404 {"UseSaveUnders", "NO", NULL,
405 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
406 {"OpaqueMove", "NO", NULL,
407 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
408 {"OpaqueResize", "NO", NULL,
409 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
410 {"OpaqueMoveResizeKeyboard", "NO", NULL,
411 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
412 {"DisableAnimations", "NO", NULL,
413 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
414 {"DontLinkWorkspaces", "NO", NULL,
415 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
416 {"AutoArrangeIcons", "NO", NULL,
417 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
418 {"NoWindowOverDock", "NO", NULL,
419 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
420 {"NoWindowOverIcons", "NO", NULL,
421 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
422 {"WindowPlaceOrigin", "(0, 0)", NULL,
423 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
424 {"ResizeDisplay", "corner", seGeomDisplays,
425 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
426 {"MoveDisplay", "corner", seGeomDisplays,
427 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
428 {"DontConfirmKill", "NO", NULL,
429 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
430 {"WindowTitleBalloons", "NO", NULL,
431 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
432 {"MiniwindowTitleBalloons", "NO", NULL,
433 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
434 {"AppIconBalloons", "NO", NULL,
435 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
436 {"HelpBalloons", "NO", NULL,
437 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
438 {"EdgeResistance", "30", NULL,
439 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
440 {"ResizeIncrement", "32", NULL,
441 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
442 {"Attraction", "NO", NULL,
443 &wPreferences.attract, getBool, NULL, NULL, NULL},
444 {"DisableBlinking", "NO", NULL,
445 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
446 {"SingleClickLaunch", "NO", NULL,
447 &wPreferences.single_click, getBool, NULL, NULL, NULL},
449 /* style options */
451 {"MenuStyle", "normal", seMenuStyles,
452 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
453 {"WidgetColor", "(solid, gray)", NULL,
454 NULL, getTexture, setWidgetColor, NULL, NULL},
455 {"WorkspaceSpecificBack", "()", NULL,
456 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
457 /* WorkspaceBack must come after WorkspaceSpecificBack or
458 * WorkspaceBack wont know WorkspaceSpecificBack was also
459 * specified and 2 copies of wmsetbg will be launched */
460 {"WorkspaceBack", "(solid, black)", NULL,
461 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
462 {"SmoothWorkspaceBack", "NO", NULL,
463 NULL, getBool, NULL, NULL, NULL},
464 {"IconBack", "(solid, gray)", NULL,
465 NULL, getTexture, setIconTile, NULL, NULL},
466 {"TitleJustify", "center", seJustifications,
467 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
468 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
469 NULL, getFont, setWinTitleFont, NULL, NULL},
470 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
471 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
472 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
473 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
474 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
475 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
476 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
477 NULL, getFont, setMenuTitleFont, NULL, NULL},
478 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
479 NULL, getFont, setMenuTextFont, NULL, NULL},
480 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
481 NULL, getFont, setIconTitleFont, NULL, NULL},
482 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
483 NULL, getFont, setClipTitleFont, NULL, NULL},
484 {"ShowClipTitle", "YES", NULL,
485 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
486 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
487 NULL, getFont, setLargeDisplayFont, NULL, NULL},
488 {"HighlightColor", "white", NULL,
489 NULL, getColor, setHightlight, NULL, NULL},
490 {"HighlightTextColor", "black", NULL,
491 NULL, getColor, setHightlightText, NULL, NULL},
492 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
493 NULL, getColor, setClipTitleColor, NULL, NULL},
494 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
495 NULL, getColor, setClipTitleColor, NULL, NULL},
496 {"FTitleColor", "white", (void *)WS_FOCUSED,
497 NULL, getColor, setWTitleColor, NULL, NULL},
498 {"PTitleColor", "white", (void *)WS_PFOCUSED,
499 NULL, getColor, setWTitleColor, NULL, NULL},
500 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
501 NULL, getColor, setWTitleColor, NULL, NULL},
502 {"FTitleBack", "(solid, black)", NULL,
503 NULL, getTexture, setFTitleBack, NULL, NULL},
504 {"PTitleBack", "(solid, \"#616161\")", NULL,
505 NULL, getTexture, setPTitleBack, NULL, NULL},
506 {"UTitleBack", "(solid, gray)", NULL,
507 NULL, getTexture, setUTitleBack, NULL, NULL},
508 {"ResizebarBack", "(solid, gray)", NULL,
509 NULL, getTexture, setResizebarBack, NULL, NULL},
510 {"MenuTitleColor", "white", NULL,
511 NULL, getColor, setMenuTitleColor, NULL, NULL},
512 {"MenuTextColor", "black", NULL,
513 NULL, getColor, setMenuTextColor, NULL, NULL},
514 {"MenuDisabledColor", "\"#616161\"", NULL,
515 NULL, getColor, setMenuDisabledColor, NULL, NULL},
516 {"MenuTitleBack", "(solid, black)", NULL,
517 NULL, getTexture, setMenuTitleBack, NULL, NULL},
518 {"MenuTextBack", "(solid, gray)", NULL,
519 NULL, getTexture, setMenuTextBack, NULL, NULL},
520 {"IconTitleColor", "white", NULL,
521 NULL, getColor, setIconTitleColor, NULL, NULL},
522 {"IconTitleBack", "black", NULL,
523 NULL, getColor, setIconTitleBack, NULL, NULL},
524 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
525 NULL, getPropList, setSwPOptions, NULL, NULL},
526 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
527 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
529 /* keybindings */
531 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
532 NULL, getKeybind, setKeyGrab, NULL, NULL},
533 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
534 NULL, getKeybind, setKeyGrab, NULL, NULL},
535 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
536 NULL, getKeybind, setKeyGrab, NULL, NULL},
537 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
538 NULL, getKeybind, setKeyGrab, NULL, NULL},
539 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
540 NULL, getKeybind, setKeyGrab, NULL, NULL},
541 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
542 NULL, getKeybind, setKeyGrab, NULL, NULL},
543 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
544 NULL, getKeybind, setKeyGrab, NULL, NULL },
545 {"HideKey", "None", (void *)WKBD_HIDE,
546 NULL, getKeybind, setKeyGrab, NULL, NULL},
547 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
548 NULL, getKeybind, setKeyGrab, NULL, NULL},
549 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
550 NULL, getKeybind, setKeyGrab, NULL, NULL},
551 {"CloseKey", "None", (void *)WKBD_CLOSE,
552 NULL, getKeybind, setKeyGrab, NULL, NULL},
553 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
554 NULL, getKeybind, setKeyGrab, NULL, NULL},
555 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
556 NULL, getKeybind, setKeyGrab, NULL, NULL},
557 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
558 NULL, getKeybind, setKeyGrab, NULL, NULL},
559 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
560 NULL, getKeybind, setKeyGrab, NULL, NULL},
561 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
562 NULL, getKeybind, setKeyGrab, NULL, NULL},
563 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
564 NULL, getKeybind, setKeyGrab, NULL, NULL},
565 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
566 NULL, getKeybind, setKeyGrab, NULL, NULL},
567 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
568 NULL, getKeybind, setKeyGrab, NULL, NULL},
569 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
570 NULL, getKeybind, setKeyGrab, NULL, NULL},
571 {"ShadeKey", "None", (void *)WKBD_SHADE,
572 NULL, getKeybind, setKeyGrab, NULL, NULL},
573 {"SelectKey", "None", (void *)WKBD_SELECT,
574 NULL, getKeybind, setKeyGrab, NULL, NULL},
575 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
576 NULL, getKeybind, setKeyGrab, NULL, NULL},
577 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
578 NULL, getKeybind, setKeyGrab, NULL, NULL},
579 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
580 NULL, getKeybind, setKeyGrab, NULL, NULL},
581 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
582 NULL, getKeybind, setKeyGrab, NULL, NULL},
583 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
584 NULL, getKeybind, setKeyGrab, NULL, NULL},
585 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
586 NULL, getKeybind, setKeyGrab, NULL, NULL},
587 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
588 NULL, getKeybind, setKeyGrab, NULL, NULL},
589 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
590 NULL, getKeybind, setKeyGrab, NULL, NULL},
591 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
592 NULL, getKeybind, setKeyGrab, NULL, NULL},
593 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
594 NULL, getKeybind, setKeyGrab, NULL, NULL},
595 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
596 NULL, getKeybind, setKeyGrab, NULL, NULL},
597 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
598 NULL, getKeybind, setKeyGrab, NULL, NULL},
599 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
600 NULL, getKeybind, setKeyGrab, NULL, NULL},
601 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
602 NULL, getKeybind, setKeyGrab, NULL, NULL},
603 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
604 NULL, getKeybind, setKeyGrab, NULL, NULL},
605 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
606 NULL, getKeybind, setKeyGrab, NULL, NULL},
607 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
608 NULL, getKeybind, setKeyGrab, NULL, NULL},
609 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
610 NULL, getKeybind, setKeyGrab, NULL, NULL},
611 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
612 NULL, getKeybind, setKeyGrab, NULL, NULL},
613 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
614 NULL, getKeybind, setKeyGrab, NULL, NULL},
615 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
616 NULL, getKeybind, setKeyGrab, NULL, NULL},
617 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
618 NULL, getKeybind, setKeyGrab, NULL, NULL},
619 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
620 NULL, getKeybind, setKeyGrab, NULL, NULL},
621 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
622 NULL, getKeybind, setKeyGrab, NULL, NULL},
623 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
624 NULL, getKeybind, setKeyGrab, NULL, NULL},
625 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
626 NULL, getKeybind, setKeyGrab, NULL, NULL},
627 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
628 NULL, getKeybind, setKeyGrab, NULL, NULL},
629 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
630 NULL, getKeybind, setKeyGrab, NULL, NULL},
631 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
632 NULL, getKeybind, setKeyGrab, NULL, NULL},
634 #ifdef KEEP_XKB_LOCK_STATUS
635 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
636 NULL, getKeybind, setKeyGrab, NULL, NULL},
637 {"KbdModeLock", "NO", NULL,
638 &wPreferences.modelock, getBool, NULL, NULL, NULL},
639 #endif /* KEEP_XKB_LOCK_STATUS */
641 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
642 NULL, getCursor, setCursor, NULL, NULL},
643 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
644 NULL, getCursor, setCursor, NULL, NULL},
645 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
646 NULL, getCursor, setCursor, NULL, NULL},
647 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
648 NULL, getCursor, setCursor, NULL, NULL},
649 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
650 NULL, getCursor, setCursor, NULL, NULL},
651 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
652 NULL, getCursor, setCursor, NULL, NULL},
653 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
654 NULL, getCursor, setCursor, NULL, NULL},
655 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
656 NULL, getCursor, setCursor, NULL, NULL},
657 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
658 NULL, getCursor, setCursor, NULL, NULL},
659 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
660 NULL, getCursor, setCursor, NULL, NULL},
661 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
662 NULL, getCursor, setCursor, NULL, NULL},
663 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
664 NULL, getCursor, setCursor, NULL, NULL},
665 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
666 NULL, getCursor, setCursor, NULL, NULL},
667 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
668 NULL, getCursor, setCursor, NULL, NULL},
669 {"DialogHistoryLines", "500", NULL,
670 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
671 {"CycleActiveHeadOnly", "NO", NULL,
672 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL}
675 static void initDefaults()
677 unsigned int i;
678 WDefaultEntry *entry;
680 WMPLSetCaseSensitive(False);
682 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
683 entry = &optionList[i];
685 entry->plkey = WMCreatePLString(entry->key);
686 if (entry->default_value)
687 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
688 else
689 entry->plvalue = NULL;
692 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
693 entry = &staticOptionList[i];
695 entry->plkey = WMCreatePLString(entry->key);
696 if (entry->default_value)
697 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
698 else
699 entry->plvalue = NULL;
703 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
705 WMPropList *globalDict = NULL;
706 char path[PATH_MAX];
707 struct stat stbuf;
709 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
710 if (stat(path, &stbuf) >= 0) {
711 globalDict = WMReadPropListFromFile(path);
712 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
713 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
714 WMReleasePropList(globalDict);
715 globalDict = NULL;
716 } else if (!globalDict) {
717 wwarning(_("could not load domain %s from global defaults database"), domainName);
721 return globalDict;
724 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
725 static void prependMenu(WMPropList * destarr, WMPropList * array)
727 WMPropList *item;
728 int i;
730 for (i = 0; i < WMGetPropListItemCount(array); i++) {
731 item = WMGetFromPLArray(array, i);
732 if (item)
733 WMInsertInPLArray(destarr, i + 1, item);
737 static void appendMenu(WMPropList * destarr, WMPropList * array)
739 WMPropList *item;
740 int i;
742 for (i = 0; i < WMGetPropListItemCount(array); i++) {
743 item = WMGetFromPLArray(array, i);
744 if (item)
745 WMAddToPLArray(destarr, item);
748 #endif
750 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
752 WMPropList *menu = menuDomain->dictionary;
753 WMPropList *submenu;
755 if (!menu || !WMIsPLArray(menu))
756 return;
758 #ifdef GLOBAL_PREAMBLE_MENU_FILE
759 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
761 if (submenu && !WMIsPLArray(submenu)) {
762 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
763 WMReleasePropList(submenu);
764 submenu = NULL;
766 if (submenu) {
767 prependMenu(menu, submenu);
768 WMReleasePropList(submenu);
770 #endif
772 #ifdef GLOBAL_EPILOGUE_MENU_FILE
773 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
775 if (submenu && !WMIsPLArray(submenu)) {
776 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
777 WMReleasePropList(submenu);
778 submenu = NULL;
780 if (submenu) {
781 appendMenu(menu, submenu);
782 WMReleasePropList(submenu);
784 #endif
786 menuDomain->dictionary = menu;
789 void wDefaultsDestroyDomain(WDDomain * domain)
791 if (domain->dictionary)
792 WMReleasePropList(domain->dictionary);
793 wfree(domain->path);
794 wfree(domain);
797 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
799 WDDomain *db;
800 struct stat stbuf;
801 static int inited = 0;
802 char path[PATH_MAX];
803 char *the_path;
804 WMPropList *shared_dict = NULL;
806 if (!inited) {
807 inited = 1;
808 initDefaults();
811 db = wmalloc(sizeof(WDDomain));
812 memset(db, 0, sizeof(WDDomain));
813 db->domain_name = domain;
814 db->path = wdefaultspathfordomain(domain);
815 the_path = db->path;
817 if (the_path && stat(the_path, &stbuf) >= 0) {
818 db->dictionary = WMReadPropListFromFile(the_path);
819 if (db->dictionary) {
820 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
821 WMReleasePropList(db->dictionary);
822 db->dictionary = NULL;
823 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
825 db->timestamp = stbuf.st_mtime;
826 } else {
827 wwarning(_("could not load domain %s from user defaults database"), domain);
831 /* global system dictionary */
832 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
833 if (stat(path, &stbuf) >= 0) {
834 shared_dict = WMReadPropListFromFile(path);
835 if (shared_dict) {
836 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
837 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
838 domain, path);
839 WMReleasePropList(shared_dict);
840 shared_dict = NULL;
841 } else {
842 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
843 WMIsPLDictionary(db->dictionary)) {
844 WMMergePLDictionaries(shared_dict, db->dictionary, True);
845 WMReleasePropList(db->dictionary);
846 db->dictionary = shared_dict;
847 if (stbuf.st_mtime > db->timestamp)
848 db->timestamp = stbuf.st_mtime;
849 } else if (!db->dictionary) {
850 db->dictionary = shared_dict;
851 if (stbuf.st_mtime > db->timestamp)
852 db->timestamp = stbuf.st_mtime;
855 } else {
856 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
860 return db;
863 void wReadStaticDefaults(WMPropList * dict)
865 WMPropList *plvalue;
866 WDefaultEntry *entry;
867 unsigned int i;
868 void *tdata;
870 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
871 entry = &staticOptionList[i];
873 if (dict)
874 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
875 else
876 plvalue = NULL;
878 if (!plvalue) {
879 /* no default in the DB. Use builtin default */
880 plvalue = entry->plvalue;
883 if (plvalue) {
884 /* convert data */
885 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
886 if (entry->update) {
887 (*entry->update) (NULL, entry, tdata, entry->extra_data);
893 void wDefaultsCheckDomains(void* arg)
895 WScreen *scr;
896 struct stat stbuf;
897 WMPropList *shared_dict = NULL;
898 WMPropList *dict;
899 int i;
901 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
902 WDWindowMaker->timestamp = stbuf.st_mtime;
904 /* global dictionary */
905 shared_dict = readGlobalDomain("WindowMaker", True);
906 /* user dictionary */
907 dict = WMReadPropListFromFile(WDWindowMaker->path);
908 if (dict) {
909 if (!WMIsPLDictionary(dict)) {
910 WMReleasePropList(dict);
911 dict = NULL;
912 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
913 "WindowMaker", WDWindowMaker->path);
914 } else {
915 if (shared_dict) {
916 WMMergePLDictionaries(shared_dict, dict, True);
917 WMReleasePropList(dict);
918 dict = shared_dict;
919 shared_dict = NULL;
921 for (i = 0; i < wScreenCount; i++) {
922 scr = wScreenWithNumber(i);
923 if (scr)
924 wReadDefaults(scr, dict);
926 if (WDWindowMaker->dictionary) {
927 WMReleasePropList(WDWindowMaker->dictionary);
929 WDWindowMaker->dictionary = dict;
931 } else {
932 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
934 if (shared_dict) {
935 WMReleasePropList(shared_dict);
939 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
940 /* global dictionary */
941 shared_dict = readGlobalDomain("WMWindowAttributes", True);
942 /* user dictionary */
943 dict = WMReadPropListFromFile(WDWindowAttributes->path);
944 if (dict) {
945 if (!WMIsPLDictionary(dict)) {
946 WMReleasePropList(dict);
947 dict = NULL;
948 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
949 "WMWindowAttributes", WDWindowAttributes->path);
950 } else {
951 if (shared_dict) {
952 WMMergePLDictionaries(shared_dict, dict, True);
953 WMReleasePropList(dict);
954 dict = shared_dict;
955 shared_dict = NULL;
957 if (WDWindowAttributes->dictionary) {
958 WMReleasePropList(WDWindowAttributes->dictionary);
960 WDWindowAttributes->dictionary = dict;
961 for (i = 0; i < wScreenCount; i++) {
962 scr = wScreenWithNumber(i);
963 if (scr) {
964 RImage *image;
966 wDefaultUpdateIcons(scr);
968 /* Update the panel image if changed */
969 /* Don't worry. If the image is the same these
970 * functions will have no performance impact. */
971 image = wDefaultGetImage(scr, "Logo", "WMPanel", wPreferences.icon_size);
973 if (!image) {
974 wwarning(_("could not load logo image for panels: %s"),
975 RMessageForError(RErrorCode));
976 } else {
977 WMSetApplicationIconImage(scr->wmscreen, image);
978 RReleaseImage(image);
983 } else {
984 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
986 WDWindowAttributes->timestamp = stbuf.st_mtime;
987 if (shared_dict) {
988 WMReleasePropList(shared_dict);
992 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
993 dict = WMReadPropListFromFile(WDRootMenu->path);
994 if (dict) {
995 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
996 WMReleasePropList(dict);
997 dict = NULL;
998 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
999 "WMRootMenu", WDRootMenu->path);
1000 } else {
1001 if (WDRootMenu->dictionary) {
1002 WMReleasePropList(WDRootMenu->dictionary);
1004 WDRootMenu->dictionary = dict;
1005 wDefaultsMergeGlobalMenus(WDRootMenu);
1006 scr = wScreenWithNumber(0);
1007 configureMenu(scr, dict, True);
1008 rebind_key_grabs(scr);
1010 } else {
1011 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1013 WDRootMenu->timestamp = stbuf.st_mtime;
1015 #ifndef HAVE_INOTIFY
1016 if (!arg)
1017 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1018 #endif
1021 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1023 WMPropList *plvalue, *old_value;
1024 WDefaultEntry *entry;
1025 unsigned int i;
1026 int update_workspace_back = 0; /* kluge :/ */
1027 unsigned int needs_refresh;
1028 void *tdata;
1029 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1031 needs_refresh = 0;
1033 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1034 entry = &optionList[i];
1036 if (new_dict)
1037 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1038 else
1039 plvalue = NULL;
1041 if (!old_dict)
1042 old_value = NULL;
1043 else
1044 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1046 if (!plvalue && !old_value) {
1047 /* no default in the DB. Use builtin default */
1048 plvalue = entry->plvalue;
1049 if (plvalue && new_dict) {
1050 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1052 } else if (!plvalue) {
1053 /* value was deleted from DB. Keep current value */
1054 continue;
1055 } else if (!old_value) {
1056 /* set value for the 1st time */
1057 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1058 /* value has changed */
1059 } else {
1061 if (strcmp(entry->key, "WorkspaceBack") == 0
1062 && update_workspace_back && scr->flags.backimage_helper_launched) {
1063 } else {
1064 /* value was not changed since last time */
1065 continue;
1069 if (plvalue) {
1070 /* convert data */
1071 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1073 * If the WorkspaceSpecificBack data has been changed
1074 * so that the helper will be launched now, we must be
1075 * sure to send the default background texture config
1076 * to the helper.
1078 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1079 && !scr->flags.backimage_helper_launched) {
1080 update_workspace_back = 1;
1082 if (entry->update) {
1083 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1089 if (needs_refresh != 0 && !scr->flags.startup) {
1090 int foo;
1092 foo = 0;
1093 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1094 foo |= WTextureSettings;
1095 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1096 foo |= WFontSettings;
1097 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1098 foo |= WColorSettings;
1099 if (foo)
1100 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1101 (void *)(uintptr_t) foo);
1103 foo = 0;
1104 if (needs_refresh & REFRESH_MENU_TEXTURE)
1105 foo |= WTextureSettings;
1106 if (needs_refresh & REFRESH_MENU_FONT)
1107 foo |= WFontSettings;
1108 if (needs_refresh & REFRESH_MENU_COLOR)
1109 foo |= WColorSettings;
1110 if (foo)
1111 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1113 foo = 0;
1114 if (needs_refresh & REFRESH_WINDOW_FONT) {
1115 foo |= WFontSettings;
1117 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1118 foo |= WTextureSettings;
1120 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1121 foo |= WColorSettings;
1123 if (foo)
1124 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1126 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1127 foo = 0;
1128 if (needs_refresh & REFRESH_ICON_FONT) {
1129 foo |= WFontSettings;
1131 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1132 foo |= WTextureSettings;
1134 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1135 foo |= WTextureSettings;
1137 if (foo)
1138 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1139 (void *)(uintptr_t) foo);
1141 if (needs_refresh & REFRESH_ICON_TILE)
1142 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1146 void wDefaultUpdateIcons(WScreen * scr)
1148 WAppIcon *aicon = scr->app_icon_list;
1149 WWindow *wwin = scr->focused_window;
1150 char *file;
1152 while (aicon) {
1153 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1154 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1155 || (file && !aicon->icon->file)) {
1156 wIconChangeImageFile(aicon->icon, file);
1157 wAppIconPaint(aicon);
1159 aicon = aicon->next;
1162 if (!wPreferences.flags.noclip)
1163 wClipIconPaint(scr->clip_icon);
1165 while (wwin) {
1166 if (wwin->icon && wwin->flags.miniaturized) {
1167 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1168 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1169 || (file && !wwin->icon->file)) {
1170 wIconChangeImageFile(wwin->icon, file);
1173 wwin = wwin->prev;
1177 /* --------------------------- Local ----------------------- */
1179 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1180 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1181 entry->key, x); \
1182 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1183 var = entry->default_value;\
1184 } else var = WMGetFromPLString(value)\
1187 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1189 char *str;
1190 WOptionEnumeration *v;
1191 char buffer[TOTAL_VALUES_LENGTH];
1193 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1194 for (v = values; v->string != NULL; v++) {
1195 if (strcasecmp(v->string, str) == 0)
1196 return v->value;
1200 buffer[0] = 0;
1201 for (v = values; v->string != NULL; v++) {
1202 if (!v->is_alias) {
1203 if (buffer[0] != 0)
1204 strcat(buffer, ", ");
1205 snprintf(buffer+strlen(buffer),
1206 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1209 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1210 WMGetFromPLString(key),
1211 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1212 buffer);
1214 if (def) {
1215 return string2index(key, val, NULL, values);
1218 return -1;
1222 * value - is the value in the defaults DB
1223 * addr - is the address to store the data
1224 * ret - is the address to store a pointer to a temporary buffer. ret
1225 * must not be freed and is used by the set functions
1227 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1229 static char data;
1230 char *val;
1231 int second_pass = 0;
1233 GET_STRING_OR_DEFAULT("Boolean", val);
1235 again:
1236 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1237 || strcasecmp(val, "YES") == 0) {
1239 data = 1;
1240 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1241 || strcasecmp(val, "NO") == 0) {
1242 data = 0;
1243 } else {
1244 int i;
1245 if (sscanf(val, "%i", &i) == 1) {
1246 if (i != 0)
1247 data = 1;
1248 else
1249 data = 0;
1250 } else {
1251 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1252 if (second_pass == 0) {
1253 val = WMGetFromPLString(entry->plvalue);
1254 second_pass = 1;
1255 wwarning(_("using default \"%s\" instead"), val);
1256 goto again;
1258 return False;
1262 if (ret)
1263 *ret = &data;
1264 if (addr)
1265 *(char *)addr = data;
1267 return True;
1270 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1272 static int data;
1273 char *val;
1275 GET_STRING_OR_DEFAULT("Integer", val);
1277 if (sscanf(val, "%i", &data) != 1) {
1278 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1279 val = WMGetFromPLString(entry->plvalue);
1280 wwarning(_("using default \"%s\" instead"), val);
1281 if (sscanf(val, "%i", &data) != 1) {
1282 return False;
1286 if (ret)
1287 *ret = &data;
1288 if (addr)
1289 *(int *)addr = data;
1291 return True;
1294 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1296 static WCoord data;
1297 char *val_x, *val_y;
1298 int nelem, changed = 0;
1299 WMPropList *elem_x, *elem_y;
1301 again:
1302 if (!WMIsPLArray(value)) {
1303 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1304 if (changed == 0) {
1305 value = entry->plvalue;
1306 changed = 1;
1307 wwarning(_("using default \"%s\" instead"), entry->default_value);
1308 goto again;
1310 return False;
1313 nelem = WMGetPropListItemCount(value);
1314 if (nelem != 2) {
1315 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1316 if (changed == 0) {
1317 value = entry->plvalue;
1318 changed = 1;
1319 wwarning(_("using default \"%s\" instead"), entry->default_value);
1320 goto again;
1322 return False;
1325 elem_x = WMGetFromPLArray(value, 0);
1326 elem_y = WMGetFromPLArray(value, 1);
1328 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1329 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1330 if (changed == 0) {
1331 value = entry->plvalue;
1332 changed = 1;
1333 wwarning(_("using default \"%s\" instead"), entry->default_value);
1334 goto again;
1336 return False;
1339 val_x = WMGetFromPLString(elem_x);
1340 val_y = WMGetFromPLString(elem_y);
1342 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1343 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1344 if (changed == 0) {
1345 value = entry->plvalue;
1346 changed = 1;
1347 wwarning(_("using default \"%s\" instead"), entry->default_value);
1348 goto again;
1350 return False;
1353 if (data.x < 0)
1354 data.x = 0;
1355 else if (data.x > scr->scr_width / 3)
1356 data.x = scr->scr_width / 3;
1357 if (data.y < 0)
1358 data.y = 0;
1359 else if (data.y > scr->scr_height / 3)
1360 data.y = scr->scr_height / 3;
1362 if (ret)
1363 *ret = &data;
1364 if (addr)
1365 *(WCoord *) addr = data;
1367 return True;
1370 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1372 WMRetainPropList(value);
1374 *ret = value;
1376 return True;
1379 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1381 static char *data;
1382 int i, count, len;
1383 char *ptr;
1384 WMPropList *d;
1385 int changed = 0;
1387 again:
1388 if (!WMIsPLArray(value)) {
1389 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1390 if (changed == 0) {
1391 value = entry->plvalue;
1392 changed = 1;
1393 wwarning(_("using default \"%s\" instead"), entry->default_value);
1394 goto again;
1396 return False;
1399 i = 0;
1400 count = WMGetPropListItemCount(value);
1401 if (count < 1) {
1402 if (changed == 0) {
1403 value = entry->plvalue;
1404 changed = 1;
1405 wwarning(_("using default \"%s\" instead"), entry->default_value);
1406 goto again;
1408 return False;
1411 len = 0;
1412 for (i = 0; i < count; i++) {
1413 d = WMGetFromPLArray(value, i);
1414 if (!d || !WMIsPLString(d)) {
1415 count = i;
1416 break;
1418 len += strlen(WMGetFromPLString(d)) + 1;
1421 ptr = data = wmalloc(len + 1);
1423 for (i = 0; i < count; i++) {
1424 d = WMGetFromPLArray(value, i);
1425 if (!d || !WMIsPLString(d)) {
1426 break;
1428 strcpy(ptr, WMGetFromPLString(d));
1429 ptr += strlen(WMGetFromPLString(d));
1430 *ptr = ':';
1431 ptr++;
1433 ptr--;
1434 *(ptr--) = 0;
1436 if (*(char **)addr != NULL) {
1437 wfree(*(char **)addr);
1439 *(char **)addr = data;
1441 return True;
1444 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1446 static signed char data;
1448 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1449 if (data < 0)
1450 return False;
1452 if (ret)
1453 *ret = &data;
1454 if (addr)
1455 *(signed char *)addr = data;
1457 return True;
1461 * (solid <color>)
1462 * (hgradient <color> <color>)
1463 * (vgradient <color> <color>)
1464 * (dgradient <color> <color>)
1465 * (mhgradient <color> <color> ...)
1466 * (mvgradient <color> <color> ...)
1467 * (mdgradient <color> <color> ...)
1468 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1469 * (tpixmap <file> <color>)
1470 * (spixmap <file> <color>)
1471 * (cpixmap <file> <color>)
1472 * (thgradient <file> <opaqueness> <color> <color>)
1473 * (tvgradient <file> <opaqueness> <color> <color>)
1474 * (tdgradient <file> <opaqueness> <color> <color>)
1475 * (function <lib> <function> ...)
1478 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1480 WMPropList *elem;
1481 char *val;
1482 int nelem;
1483 WTexture *texture = NULL;
1485 nelem = WMGetPropListItemCount(pl);
1486 if (nelem < 1)
1487 return NULL;
1489 elem = WMGetFromPLArray(pl, 0);
1490 if (!elem || !WMIsPLString(elem))
1491 return NULL;
1492 val = WMGetFromPLString(elem);
1494 if (strcasecmp(val, "solid") == 0) {
1495 XColor color;
1497 if (nelem != 2)
1498 return NULL;
1500 /* get color */
1502 elem = WMGetFromPLArray(pl, 1);
1503 if (!elem || !WMIsPLString(elem))
1504 return NULL;
1505 val = WMGetFromPLString(elem);
1507 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1508 wwarning(_("\"%s\" is not a valid color name"), val);
1509 return NULL;
1512 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1513 } else if (strcasecmp(val, "dgradient") == 0
1514 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1515 RColor color1, color2;
1516 XColor xcolor;
1517 int type;
1519 if (nelem != 3) {
1520 wwarning(_("bad number of arguments in gradient specification"));
1521 return NULL;
1524 if (val[0] == 'd' || val[0] == 'D')
1525 type = WTEX_DGRADIENT;
1526 else if (val[0] == 'h' || val[0] == 'H')
1527 type = WTEX_HGRADIENT;
1528 else
1529 type = WTEX_VGRADIENT;
1531 /* get from color */
1532 elem = WMGetFromPLArray(pl, 1);
1533 if (!elem || !WMIsPLString(elem))
1534 return NULL;
1535 val = WMGetFromPLString(elem);
1537 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1538 wwarning(_("\"%s\" is not a valid color name"), val);
1539 return NULL;
1541 color1.alpha = 255;
1542 color1.red = xcolor.red >> 8;
1543 color1.green = xcolor.green >> 8;
1544 color1.blue = xcolor.blue >> 8;
1546 /* get to color */
1547 elem = WMGetFromPLArray(pl, 2);
1548 if (!elem || !WMIsPLString(elem)) {
1549 return NULL;
1551 val = WMGetFromPLString(elem);
1553 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1554 wwarning(_("\"%s\" is not a valid color name"), val);
1555 return NULL;
1557 color2.alpha = 255;
1558 color2.red = xcolor.red >> 8;
1559 color2.green = xcolor.green >> 8;
1560 color2.blue = xcolor.blue >> 8;
1562 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1564 } else if (strcasecmp(val, "igradient") == 0) {
1565 RColor colors1[2], colors2[2];
1566 int th1, th2;
1567 XColor xcolor;
1568 int i;
1570 if (nelem != 7) {
1571 wwarning(_("bad number of arguments in gradient specification"));
1572 return NULL;
1575 /* get from color */
1576 for (i = 0; i < 2; i++) {
1577 elem = WMGetFromPLArray(pl, 1 + i);
1578 if (!elem || !WMIsPLString(elem))
1579 return NULL;
1580 val = WMGetFromPLString(elem);
1582 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1583 wwarning(_("\"%s\" is not a valid color name"), val);
1584 return NULL;
1586 colors1[i].alpha = 255;
1587 colors1[i].red = xcolor.red >> 8;
1588 colors1[i].green = xcolor.green >> 8;
1589 colors1[i].blue = xcolor.blue >> 8;
1591 elem = WMGetFromPLArray(pl, 3);
1592 if (!elem || !WMIsPLString(elem))
1593 return NULL;
1594 val = WMGetFromPLString(elem);
1595 th1 = atoi(val);
1597 /* get from color */
1598 for (i = 0; i < 2; i++) {
1599 elem = WMGetFromPLArray(pl, 4 + i);
1600 if (!elem || !WMIsPLString(elem))
1601 return NULL;
1602 val = WMGetFromPLString(elem);
1604 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1605 wwarning(_("\"%s\" is not a valid color name"), val);
1606 return NULL;
1608 colors2[i].alpha = 255;
1609 colors2[i].red = xcolor.red >> 8;
1610 colors2[i].green = xcolor.green >> 8;
1611 colors2[i].blue = xcolor.blue >> 8;
1613 elem = WMGetFromPLArray(pl, 6);
1614 if (!elem || !WMIsPLString(elem))
1615 return NULL;
1616 val = WMGetFromPLString(elem);
1617 th2 = atoi(val);
1619 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1621 } else if (strcasecmp(val, "mhgradient") == 0
1622 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1623 XColor color;
1624 RColor **colors;
1625 int i, count;
1626 int type;
1628 if (nelem < 3) {
1629 wwarning(_("too few arguments in multicolor gradient specification"));
1630 return NULL;
1633 if (val[1] == 'h' || val[1] == 'H')
1634 type = WTEX_MHGRADIENT;
1635 else if (val[1] == 'v' || val[1] == 'V')
1636 type = WTEX_MVGRADIENT;
1637 else
1638 type = WTEX_MDGRADIENT;
1640 count = nelem - 1;
1642 colors = wmalloc(sizeof(RColor *) * (count + 1));
1644 for (i = 0; i < count; i++) {
1645 elem = WMGetFromPLArray(pl, i + 1);
1646 if (!elem || !WMIsPLString(elem)) {
1647 for (--i; i >= 0; --i) {
1648 wfree(colors[i]);
1650 wfree(colors);
1651 return NULL;
1653 val = WMGetFromPLString(elem);
1655 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1656 wwarning(_("\"%s\" is not a valid color name"), val);
1657 for (--i; i >= 0; --i) {
1658 wfree(colors[i]);
1660 wfree(colors);
1661 return NULL;
1662 } else {
1663 colors[i] = wmalloc(sizeof(RColor));
1664 colors[i]->red = color.red >> 8;
1665 colors[i]->green = color.green >> 8;
1666 colors[i]->blue = color.blue >> 8;
1669 colors[i] = NULL;
1671 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1672 } else if (strcasecmp(val, "spixmap") == 0 ||
1673 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1674 XColor color;
1675 int type;
1677 if (nelem != 3)
1678 return NULL;
1680 if (val[0] == 's' || val[0] == 'S')
1681 type = WTP_SCALE;
1682 else if (val[0] == 'c' || val[0] == 'C')
1683 type = WTP_CENTER;
1684 else
1685 type = WTP_TILE;
1687 /* get color */
1688 elem = WMGetFromPLArray(pl, 2);
1689 if (!elem || !WMIsPLString(elem)) {
1690 return NULL;
1692 val = WMGetFromPLString(elem);
1694 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1695 wwarning(_("\"%s\" is not a valid color name"), val);
1696 return NULL;
1699 /* file name */
1700 elem = WMGetFromPLArray(pl, 1);
1701 if (!elem || !WMIsPLString(elem))
1702 return NULL;
1703 val = WMGetFromPLString(elem);
1705 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1706 } else if (strcasecmp(val, "thgradient") == 0
1707 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1708 RColor color1, color2;
1709 XColor xcolor;
1710 int opacity;
1711 int style;
1713 if (val[1] == 'h' || val[1] == 'H')
1714 style = WTEX_THGRADIENT;
1715 else if (val[1] == 'v' || val[1] == 'V')
1716 style = WTEX_TVGRADIENT;
1717 else
1718 style = WTEX_TDGRADIENT;
1720 if (nelem != 5) {
1721 wwarning(_("bad number of arguments in textured gradient specification"));
1722 return NULL;
1725 /* get from color */
1726 elem = WMGetFromPLArray(pl, 3);
1727 if (!elem || !WMIsPLString(elem))
1728 return NULL;
1729 val = WMGetFromPLString(elem);
1731 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1732 wwarning(_("\"%s\" is not a valid color name"), val);
1733 return NULL;
1735 color1.alpha = 255;
1736 color1.red = xcolor.red >> 8;
1737 color1.green = xcolor.green >> 8;
1738 color1.blue = xcolor.blue >> 8;
1740 /* get to color */
1741 elem = WMGetFromPLArray(pl, 4);
1742 if (!elem || !WMIsPLString(elem)) {
1743 return NULL;
1745 val = WMGetFromPLString(elem);
1747 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1748 wwarning(_("\"%s\" is not a valid color name"), val);
1749 return NULL;
1751 color2.alpha = 255;
1752 color2.red = xcolor.red >> 8;
1753 color2.green = xcolor.green >> 8;
1754 color2.blue = xcolor.blue >> 8;
1756 /* get opacity */
1757 elem = WMGetFromPLArray(pl, 2);
1758 if (!elem || !WMIsPLString(elem))
1759 opacity = 128;
1760 else
1761 val = WMGetFromPLString(elem);
1763 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1764 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1765 opacity = 128;
1768 /* get file name */
1769 elem = WMGetFromPLArray(pl, 1);
1770 if (!elem || !WMIsPLString(elem))
1771 return NULL;
1772 val = WMGetFromPLString(elem);
1774 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1775 } else if (strcasecmp(val, "function") == 0) {
1776 /* Leave this in to handle the unlikely case of
1777 * someone actually having function textures configured */
1778 wwarning("function texture support has been removed");
1779 return NULL;
1780 } else {
1781 wwarning(_("invalid texture type %s"), val);
1782 return NULL;
1784 return texture;
1787 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1789 static WTexture *texture;
1790 int changed = 0;
1792 again:
1793 if (!WMIsPLArray(value)) {
1794 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1795 if (changed == 0) {
1796 value = entry->plvalue;
1797 changed = 1;
1798 wwarning(_("using default \"%s\" instead"), entry->default_value);
1799 goto again;
1801 return False;
1804 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1805 WMPropList *pl;
1807 pl = WMGetFromPLArray(value, 0);
1808 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1809 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1810 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1811 entry->key, "Solid Texture");
1813 value = entry->plvalue;
1814 changed = 1;
1815 wwarning(_("using default \"%s\" instead"), entry->default_value);
1816 goto again;
1820 texture = parse_texture(scr, value);
1822 if (!texture) {
1823 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1824 if (changed == 0) {
1825 value = entry->plvalue;
1826 changed = 1;
1827 wwarning(_("using default \"%s\" instead"), entry->default_value);
1828 goto again;
1830 return False;
1833 if (ret)
1834 *ret = &texture;
1836 if (addr)
1837 *(WTexture **) addr = texture;
1839 return True;
1842 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1844 WMPropList *elem;
1845 int changed = 0;
1846 char *val;
1847 int nelem;
1849 again:
1850 if (!WMIsPLArray(value)) {
1851 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1852 "WorkspaceBack", "Texture or None");
1853 if (changed == 0) {
1854 value = entry->plvalue;
1855 changed = 1;
1856 wwarning(_("using default \"%s\" instead"), entry->default_value);
1857 goto again;
1859 return False;
1862 /* only do basic error checking and verify for None texture */
1864 nelem = WMGetPropListItemCount(value);
1865 if (nelem > 0) {
1866 elem = WMGetFromPLArray(value, 0);
1867 if (!elem || !WMIsPLString(elem)) {
1868 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1869 if (changed == 0) {
1870 value = entry->plvalue;
1871 changed = 1;
1872 wwarning(_("using default \"%s\" instead"), entry->default_value);
1873 goto again;
1875 return False;
1877 val = WMGetFromPLString(elem);
1879 if (strcasecmp(val, "None") == 0)
1880 return True;
1882 *ret = WMRetainPropList(value);
1884 return True;
1887 static int
1888 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1890 WMPropList *elem;
1891 int nelem;
1892 int changed = 0;
1894 again:
1895 if (!WMIsPLArray(value)) {
1896 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1897 "WorkspaceSpecificBack", "an array of textures");
1898 if (changed == 0) {
1899 value = entry->plvalue;
1900 changed = 1;
1901 wwarning(_("using default \"%s\" instead"), entry->default_value);
1902 goto again;
1904 return False;
1907 /* only do basic error checking and verify for None texture */
1909 nelem = WMGetPropListItemCount(value);
1910 if (nelem > 0) {
1911 while (nelem--) {
1912 elem = WMGetFromPLArray(value, nelem);
1913 if (!elem || !WMIsPLArray(elem)) {
1914 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1915 nelem);
1920 *ret = WMRetainPropList(value);
1922 #ifdef notworking
1924 * Kluge to force wmsetbg helper to set the default background.
1925 * If the WorkspaceSpecificBack is changed once wmaker has started,
1926 * the WorkspaceBack won't be sent to the helper, unless the user
1927 * changes it's value too. So, we must force this by removing the
1928 * value from the defaults DB.
1930 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1931 WMPropList *key = WMCreatePLString("WorkspaceBack");
1933 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1935 WMReleasePropList(key);
1937 #endif
1938 return True;
1941 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1943 static WMFont *font;
1944 char *val;
1946 GET_STRING_OR_DEFAULT("Font", val);
1948 font = WMCreateFont(scr->wmscreen, val);
1949 if (!font)
1950 font = WMCreateFont(scr->wmscreen, "fixed");
1952 if (!font) {
1953 wfatal(_("could not load any usable font!!!"));
1954 exit(1);
1957 if (ret)
1958 *ret = font;
1960 /* can't assign font value outside update function */
1961 wassertrv(addr == NULL, True);
1963 return True;
1966 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1968 static XColor color;
1969 char *val;
1970 int second_pass = 0;
1972 GET_STRING_OR_DEFAULT("Color", val);
1974 again:
1975 if (!wGetColor(scr, val, &color)) {
1976 wwarning(_("could not get color for key \"%s\""), entry->key);
1977 if (second_pass == 0) {
1978 val = WMGetFromPLString(entry->plvalue);
1979 second_pass = 1;
1980 wwarning(_("using default \"%s\" instead"), val);
1981 goto again;
1983 return False;
1986 if (ret)
1987 *ret = &color;
1989 assert(addr == NULL);
1991 if (addr)
1992 *(unsigned long*)addr = pixel;
1995 return True;
1998 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2000 static WShortKey shortcut;
2001 KeySym ksym;
2002 char *val;
2003 char *k;
2004 char buf[MAX_SHORTCUT_LENGTH], *b;
2006 GET_STRING_OR_DEFAULT("Key spec", val);
2008 if (!val || strcasecmp(val, "NONE") == 0) {
2009 shortcut.keycode = 0;
2010 shortcut.modifier = 0;
2011 if (ret)
2012 *ret = &shortcut;
2013 return True;
2016 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2018 b = (char *)buf;
2020 /* get modifiers */
2021 shortcut.modifier = 0;
2022 while ((k = strchr(b, '+')) != NULL) {
2023 int mod;
2025 *k = 0;
2026 mod = wXModifierFromKey(b);
2027 if (mod < 0) {
2028 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2029 return False;
2031 shortcut.modifier |= mod;
2033 b = k + 1;
2036 /* get key */
2037 ksym = XStringToKeysym(b);
2039 if (ksym == NoSymbol) {
2040 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2041 return False;
2044 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2045 if (shortcut.keycode == 0) {
2046 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2047 return False;
2050 if (ret)
2051 *ret = &shortcut;
2053 return True;
2056 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2058 static int mask;
2059 char *str;
2061 GET_STRING_OR_DEFAULT("Modifier Key", str);
2063 if (!str)
2064 return False;
2066 mask = wXModifierFromKey(str);
2067 if (mask < 0) {
2068 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2069 mask = 0;
2070 return False;
2073 if (addr)
2074 *(int *)addr = mask;
2076 if (ret)
2077 *ret = &mask;
2079 return True;
2082 # include <X11/cursorfont.h>
2083 typedef struct {
2084 char *name;
2085 int id;
2086 } WCursorLookup;
2088 #define CURSOR_ID_NONE (XC_num_glyphs)
2090 static WCursorLookup cursor_table[] = {
2091 {"X_cursor", XC_X_cursor},
2092 {"arrow", XC_arrow},
2093 {"based_arrow_down", XC_based_arrow_down},
2094 {"based_arrow_up", XC_based_arrow_up},
2095 {"boat", XC_boat},
2096 {"bogosity", XC_bogosity},
2097 {"bottom_left_corner", XC_bottom_left_corner},
2098 {"bottom_right_corner", XC_bottom_right_corner},
2099 {"bottom_side", XC_bottom_side},
2100 {"bottom_tee", XC_bottom_tee},
2101 {"box_spiral", XC_box_spiral},
2102 {"center_ptr", XC_center_ptr},
2103 {"circle", XC_circle},
2104 {"clock", XC_clock},
2105 {"coffee_mug", XC_coffee_mug},
2106 {"cross", XC_cross},
2107 {"cross_reverse", XC_cross_reverse},
2108 {"crosshair", XC_crosshair},
2109 {"diamond_cross", XC_diamond_cross},
2110 {"dot", XC_dot},
2111 {"dotbox", XC_dotbox},
2112 {"double_arrow", XC_double_arrow},
2113 {"draft_large", XC_draft_large},
2114 {"draft_small", XC_draft_small},
2115 {"draped_box", XC_draped_box},
2116 {"exchange", XC_exchange},
2117 {"fleur", XC_fleur},
2118 {"gobbler", XC_gobbler},
2119 {"gumby", XC_gumby},
2120 {"hand1", XC_hand1},
2121 {"hand2", XC_hand2},
2122 {"heart", XC_heart},
2123 {"icon", XC_icon},
2124 {"iron_cross", XC_iron_cross},
2125 {"left_ptr", XC_left_ptr},
2126 {"left_side", XC_left_side},
2127 {"left_tee", XC_left_tee},
2128 {"leftbutton", XC_leftbutton},
2129 {"ll_angle", XC_ll_angle},
2130 {"lr_angle", XC_lr_angle},
2131 {"man", XC_man},
2132 {"middlebutton", XC_middlebutton},
2133 {"mouse", XC_mouse},
2134 {"pencil", XC_pencil},
2135 {"pirate", XC_pirate},
2136 {"plus", XC_plus},
2137 {"question_arrow", XC_question_arrow},
2138 {"right_ptr", XC_right_ptr},
2139 {"right_side", XC_right_side},
2140 {"right_tee", XC_right_tee},
2141 {"rightbutton", XC_rightbutton},
2142 {"rtl_logo", XC_rtl_logo},
2143 {"sailboat", XC_sailboat},
2144 {"sb_down_arrow", XC_sb_down_arrow},
2145 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2146 {"sb_left_arrow", XC_sb_left_arrow},
2147 {"sb_right_arrow", XC_sb_right_arrow},
2148 {"sb_up_arrow", XC_sb_up_arrow},
2149 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2150 {"shuttle", XC_shuttle},
2151 {"sizing", XC_sizing},
2152 {"spider", XC_spider},
2153 {"spraycan", XC_spraycan},
2154 {"star", XC_star},
2155 {"target", XC_target},
2156 {"tcross", XC_tcross},
2157 {"top_left_arrow", XC_top_left_arrow},
2158 {"top_left_corner", XC_top_left_corner},
2159 {"top_right_corner", XC_top_right_corner},
2160 {"top_side", XC_top_side},
2161 {"top_tee", XC_top_tee},
2162 {"trek", XC_trek},
2163 {"ul_angle", XC_ul_angle},
2164 {"umbrella", XC_umbrella},
2165 {"ur_angle", XC_ur_angle},
2166 {"watch", XC_watch},
2167 {"xterm", XC_xterm},
2168 {NULL, CURSOR_ID_NONE}
2171 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2173 switch (status) {
2174 case BitmapOpenFailed:
2175 wwarning(_("failed to open bitmap file \"%s\""), filename);
2176 break;
2177 case BitmapFileInvalid:
2178 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2179 break;
2180 case BitmapNoMemory:
2181 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2182 break;
2183 case BitmapSuccess:
2184 XFreePixmap(dpy, bitmap);
2185 break;
2190 * (none)
2191 * (builtin, <cursor_name>)
2192 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2194 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2196 WMPropList *elem;
2197 char *val;
2198 int nelem;
2199 int status = 0;
2201 nelem = WMGetPropListItemCount(pl);
2202 if (nelem < 1) {
2203 return (status);
2205 elem = WMGetFromPLArray(pl, 0);
2206 if (!elem || !WMIsPLString(elem)) {
2207 return (status);
2209 val = WMGetFromPLString(elem);
2211 if (strcasecmp(val, "none") == 0) {
2212 status = 1;
2213 *cursor = None;
2214 } else if (strcasecmp(val, "builtin") == 0) {
2215 int i;
2216 int cursor_id = CURSOR_ID_NONE;
2218 if (nelem != 2) {
2219 wwarning(_("bad number of arguments in cursor specification"));
2220 return (status);
2222 elem = WMGetFromPLArray(pl, 1);
2223 if (!elem || !WMIsPLString(elem)) {
2224 return (status);
2226 val = WMGetFromPLString(elem);
2228 for (i = 0; cursor_table[i].name != NULL; i++) {
2229 if (strcasecmp(val, cursor_table[i].name) == 0) {
2230 cursor_id = cursor_table[i].id;
2231 break;
2234 if (CURSOR_ID_NONE == cursor_id) {
2235 wwarning(_("unknown builtin cursor name \"%s\""), val);
2236 } else {
2237 *cursor = XCreateFontCursor(dpy, cursor_id);
2238 status = 1;
2240 } else if (strcasecmp(val, "bitmap") == 0) {
2241 char *bitmap_name;
2242 char *mask_name;
2243 int bitmap_status;
2244 int mask_status;
2245 Pixmap bitmap;
2246 Pixmap mask;
2247 unsigned int w, h;
2248 int x, y;
2249 XColor fg, bg;
2251 if (nelem != 3) {
2252 wwarning(_("bad number of arguments in cursor specification"));
2253 return (status);
2255 elem = WMGetFromPLArray(pl, 1);
2256 if (!elem || !WMIsPLString(elem)) {
2257 return (status);
2259 val = WMGetFromPLString(elem);
2260 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2261 if (!bitmap_name) {
2262 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2263 return (status);
2265 elem = WMGetFromPLArray(pl, 2);
2266 if (!elem || !WMIsPLString(elem)) {
2267 wfree(bitmap_name);
2268 return (status);
2270 val = WMGetFromPLString(elem);
2271 mask_name = FindImage(wPreferences.pixmap_path, val);
2272 if (!mask_name) {
2273 wfree(bitmap_name);
2274 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2275 return (status);
2277 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2278 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2279 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2280 fg.pixel = scr->black_pixel;
2281 bg.pixel = scr->white_pixel;
2282 XQueryColor(dpy, scr->w_colormap, &fg);
2283 XQueryColor(dpy, scr->w_colormap, &bg);
2284 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2285 status = 1;
2287 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2288 check_bitmap_status(mask_status, mask_name, mask);
2289 wfree(bitmap_name);
2290 wfree(mask_name);
2292 return (status);
2295 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2297 static Cursor cursor;
2298 int status;
2299 int changed = 0;
2301 again:
2302 if (!WMIsPLArray(value)) {
2303 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2304 entry->key, "cursor specification");
2305 if (!changed) {
2306 value = entry->plvalue;
2307 changed = 1;
2308 wwarning(_("using default \"%s\" instead"), entry->default_value);
2309 goto again;
2311 return (False);
2313 status = parse_cursor(scr, value, &cursor);
2314 if (!status) {
2315 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2316 if (!changed) {
2317 value = entry->plvalue;
2318 changed = 1;
2319 wwarning(_("using default \"%s\" instead"), entry->default_value);
2320 goto again;
2322 return (False);
2324 if (ret) {
2325 *ret = &cursor;
2327 if (addr) {
2328 *(Cursor *) addr = cursor;
2330 return (True);
2333 #undef CURSOR_ID_NONE
2335 /* ---------------- value setting functions --------------- */
2336 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2338 return REFRESH_WINDOW_TITLE_COLOR;
2341 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2343 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2346 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2348 switch (which) {
2349 case WM_DOCK:
2350 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2351 break;
2352 case WM_CLIP:
2353 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2354 break;
2355 default:
2356 break;
2358 return 0;
2361 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2363 if (scr->workspaces) {
2364 wWorkspaceForceChange(scr, scr->current_workspace);
2365 wArrangeIcons(scr, False);
2367 return 0;
2370 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2372 Pixmap pixmap;
2373 RImage *img;
2374 int reset = 0;
2376 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2377 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2378 ? WREL_ICON : WREL_FLAT);
2379 if (!img) {
2380 wwarning(_("could not render texture for icon background"));
2381 if (!entry->addr)
2382 wTextureDestroy(scr, *texture);
2383 return 0;
2385 RConvertImage(scr->rcontext, img, &pixmap);
2387 if (scr->icon_tile) {
2388 reset = 1;
2389 RReleaseImage(scr->icon_tile);
2390 XFreePixmap(dpy, scr->icon_tile_pixmap);
2393 scr->icon_tile = img;
2395 /* put the icon in the noticeboard hint */
2396 PropSetIconTileHint(scr, img);
2398 if (!wPreferences.flags.noclip) {
2399 if (scr->clip_tile) {
2400 RReleaseImage(scr->clip_tile);
2402 scr->clip_tile = wClipMakeTile(scr, img);
2405 scr->icon_tile_pixmap = pixmap;
2407 if (scr->def_icon_pixmap) {
2408 XFreePixmap(dpy, scr->def_icon_pixmap);
2409 scr->def_icon_pixmap = None;
2411 if (scr->def_ticon_pixmap) {
2412 XFreePixmap(dpy, scr->def_ticon_pixmap);
2413 scr->def_ticon_pixmap = None;
2416 if (scr->icon_back_texture) {
2417 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2419 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2421 if (scr->clip_balloon)
2422 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2425 * Free the texture as nobody else will use it, nor refer to it.
2427 if (!entry->addr)
2428 wTextureDestroy(scr, *texture);
2430 return (reset ? REFRESH_ICON_TILE : 0);
2433 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2435 if (scr->title_font) {
2436 WMReleaseFont(scr->title_font);
2438 scr->title_font = font;
2440 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2443 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2445 if (scr->menu_title_font) {
2446 WMReleaseFont(scr->menu_title_font);
2449 scr->menu_title_font = font;
2451 return REFRESH_MENU_TITLE_FONT;
2454 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2456 if (scr->menu_entry_font) {
2457 WMReleaseFont(scr->menu_entry_font);
2459 scr->menu_entry_font = font;
2461 return REFRESH_MENU_FONT;
2464 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2466 if (scr->icon_title_font) {
2467 WMReleaseFont(scr->icon_title_font);
2470 scr->icon_title_font = font;
2472 return REFRESH_ICON_FONT;
2475 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2477 if (scr->clip_title_font) {
2478 WMReleaseFont(scr->clip_title_font);
2481 scr->clip_title_font = font;
2483 return REFRESH_ICON_FONT;
2486 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2488 if (scr->workspace_name_font) {
2489 WMReleaseFont(scr->workspace_name_font);
2492 scr->workspace_name_font = font;
2494 return 0;
2497 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2499 if (scr->select_color)
2500 WMReleaseColor(scr->select_color);
2502 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2504 wFreeColor(scr, color->pixel);
2506 return REFRESH_MENU_COLOR;
2509 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2511 if (scr->select_text_color)
2512 WMReleaseColor(scr->select_text_color);
2514 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2516 wFreeColor(scr, color->pixel);
2518 return REFRESH_MENU_COLOR;
2521 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2523 if (scr->clip_title_color[widx])
2524 WMReleaseColor(scr->clip_title_color[widx]);
2526 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2527 wFreeColor(scr, color->pixel);
2529 return REFRESH_ICON_TITLE_COLOR;
2532 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2534 if (scr->window_title_color[widx])
2535 WMReleaseColor(scr->window_title_color[widx]);
2537 scr->window_title_color[widx] =
2538 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2540 wFreeColor(scr, color->pixel);
2542 return REFRESH_WINDOW_TITLE_COLOR;
2545 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2547 if (scr->menu_title_color[0])
2548 WMReleaseColor(scr->menu_title_color[0]);
2550 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2552 wFreeColor(scr, color->pixel);
2554 return REFRESH_MENU_TITLE_COLOR;
2557 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2559 if (scr->mtext_color)
2560 WMReleaseColor(scr->mtext_color);
2562 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2564 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2565 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2566 } else {
2567 WMSetColorAlpha(scr->dtext_color, 0xffff);
2570 wFreeColor(scr, color->pixel);
2572 return REFRESH_MENU_COLOR;
2575 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2577 if (scr->dtext_color)
2578 WMReleaseColor(scr->dtext_color);
2580 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2582 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2583 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2584 } else {
2585 WMSetColorAlpha(scr->dtext_color, 0xffff);
2588 wFreeColor(scr, color->pixel);
2590 return REFRESH_MENU_COLOR;
2593 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2595 if (scr->icon_title_color)
2596 WMReleaseColor(scr->icon_title_color);
2597 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2599 wFreeColor(scr, color->pixel);
2601 return REFRESH_ICON_TITLE_COLOR;
2604 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2606 if (scr->icon_title_texture) {
2607 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2609 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2611 return REFRESH_ICON_TITLE_BACK;
2614 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2616 close(scr->helper_fd);
2617 scr->helper_fd = 0;
2618 scr->helper_pid = 0;
2619 scr->flags.backimage_helper_launched = 0;
2622 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2624 WMPropList *val;
2625 char *str;
2626 int i;
2628 if (scr->flags.backimage_helper_launched) {
2629 if (WMGetPropListItemCount(value) == 0) {
2630 SendHelperMessage(scr, 'C', 0, NULL);
2631 SendHelperMessage(scr, 'K', 0, NULL);
2633 WMReleasePropList(value);
2634 return 0;
2636 } else {
2637 pid_t pid;
2638 int filedes[2];
2640 if (WMGetPropListItemCount(value) == 0)
2641 return 0;
2643 if (pipe(filedes) < 0) {
2644 werror("pipe() failed:can't set workspace specific background image");
2646 WMReleasePropList(value);
2647 return 0;
2650 pid = fork();
2651 if (pid < 0) {
2652 werror("fork() failed:can't set workspace specific background image");
2653 if (close(filedes[0]) < 0)
2654 werror("could not close pipe");
2655 if (close(filedes[1]) < 0)
2656 werror("could not close pipe");
2658 } else if (pid == 0) {
2659 char *dither;
2661 SetupEnvironment(scr);
2663 if (close(0) < 0)
2664 werror("could not close pipe");
2665 if (dup(filedes[0]) < 0) {
2666 werror("dup() failed:can't set workspace specific background image");
2668 dither = wPreferences.no_dithering ? "-m" : "-d";
2669 if (wPreferences.smooth_workspace_back)
2670 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2671 else
2672 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2673 werror("could not execute wmsetbg");
2674 exit(1);
2675 } else {
2677 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2678 werror("error setting close-on-exec flag");
2680 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2681 werror("error setting close-on-exec flag");
2684 scr->helper_fd = filedes[1];
2685 scr->helper_pid = pid;
2686 scr->flags.backimage_helper_launched = 1;
2688 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2690 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2695 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2696 val = WMGetFromPLArray(value, i);
2697 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2698 str = WMGetPropListDescription(val, False);
2700 SendHelperMessage(scr, 'S', i + 1, str);
2702 wfree(str);
2703 } else {
2704 SendHelperMessage(scr, 'U', i + 1, NULL);
2707 sleep(1);
2709 WMReleasePropList(value);
2710 return 0;
2713 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2715 if (scr->flags.backimage_helper_launched) {
2716 char *str;
2718 if (WMGetPropListItemCount(value) == 0) {
2719 SendHelperMessage(scr, 'U', 0, NULL);
2720 } else {
2721 /* set the default workspace background to this one */
2722 str = WMGetPropListDescription(value, False);
2723 if (str) {
2724 SendHelperMessage(scr, 'S', 0, str);
2725 wfree(str);
2726 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2727 } else {
2728 SendHelperMessage(scr, 'U', 0, NULL);
2731 } else if (WMGetPropListItemCount(value) > 0) {
2732 char *command;
2733 char *text;
2734 char *dither;
2735 int len;
2737 text = WMGetPropListDescription(value, False);
2738 len = strlen(text) + 40;
2739 command = wmalloc(len);
2740 dither = wPreferences.no_dithering ? "-m" : "-d";
2741 if (wPreferences.smooth_workspace_back)
2742 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2743 else
2744 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2745 wfree(text);
2746 ExecuteShellCommand(scr, command);
2747 wfree(command);
2749 WMReleasePropList(value);
2751 return 0;
2754 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2756 if (scr->widget_texture) {
2757 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2759 scr->widget_texture = *(WTexSolid **) texture;
2761 return 0;
2764 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2766 if (scr->window_title_texture[WS_FOCUSED]) {
2767 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2769 scr->window_title_texture[WS_FOCUSED] = *texture;
2771 return REFRESH_WINDOW_TEXTURES;
2774 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2776 if (scr->window_title_texture[WS_PFOCUSED]) {
2777 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2779 scr->window_title_texture[WS_PFOCUSED] = *texture;
2781 return REFRESH_WINDOW_TEXTURES;
2784 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2786 if (scr->window_title_texture[WS_UNFOCUSED]) {
2787 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2789 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2791 return REFRESH_WINDOW_TEXTURES;
2794 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2796 if (scr->resizebar_texture[0]) {
2797 wTextureDestroy(scr, scr->resizebar_texture[0]);
2799 scr->resizebar_texture[0] = *texture;
2801 return REFRESH_WINDOW_TEXTURES;
2804 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2806 if (scr->menu_title_texture[0]) {
2807 wTextureDestroy(scr, scr->menu_title_texture[0]);
2809 scr->menu_title_texture[0] = *texture;
2811 return REFRESH_MENU_TITLE_TEXTURE;
2814 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2816 if (scr->menu_item_texture) {
2817 wTextureDestroy(scr, scr->menu_item_texture);
2818 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2820 scr->menu_item_texture = *texture;
2822 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2824 return REFRESH_MENU_TEXTURE;
2827 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2829 WWindow *wwin;
2830 wKeyBindings[widx] = *shortcut;
2832 wwin = scr->focused_window;
2834 while (wwin != NULL) {
2835 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2837 if (!WFLAGP(wwin, no_bind_keys)) {
2838 wWindowSetKeyGrabs(wwin);
2840 wwin = wwin->prev;
2843 return 0;
2846 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2848 wScreenUpdateUsableArea(scr);
2849 wArrangeIcons(scr, True);
2851 return 0;
2854 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2856 wScreenUpdateUsableArea(scr);
2858 return 0;
2861 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2863 return REFRESH_MENU_TEXTURE;
2866 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2868 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2870 RCopyArea(img, image, x, y, w, h, 0, 0);
2872 return img;
2875 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2877 char *path;
2878 RImage *bgimage;
2879 int cwidth, cheight;
2880 WPreferences *prefs = (WPreferences *) foo;
2882 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2883 if (prefs->swtileImage)
2884 RReleaseImage(prefs->swtileImage);
2885 prefs->swtileImage = NULL;
2887 WMReleasePropList(array);
2888 return 0;
2891 switch (WMGetPropListItemCount(array)) {
2892 case 4:
2893 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2894 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2895 break;
2896 } else
2897 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2899 if (!path) {
2900 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2901 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2902 } else {
2903 bgimage = RLoadImage(scr->rcontext, path, 0);
2904 if (!bgimage) {
2905 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2906 wfree(path);
2907 } else {
2908 wfree(path);
2910 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2911 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2913 if (cwidth <= 0 || cheight <= 0 ||
2914 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2915 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2916 else {
2917 int i;
2918 int swidth, theight;
2919 for (i = 0; i < 9; i++) {
2920 if (prefs->swbackImage[i])
2921 RReleaseImage(prefs->swbackImage[i]);
2922 prefs->swbackImage[i] = NULL;
2924 swidth = (bgimage->width - cwidth) / 2;
2925 theight = (bgimage->height - cheight) / 2;
2927 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2928 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2929 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2930 swidth, theight);
2932 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2933 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2934 cwidth, cheight);
2935 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2936 swidth, cheight);
2938 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2939 swidth, theight);
2940 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2941 cwidth, theight);
2942 prefs->swbackImage[8] =
2943 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2944 theight);
2946 // check if anything failed
2947 for (i = 0; i < 9; i++) {
2948 if (!prefs->swbackImage[i]) {
2949 for (; i >= 0; --i) {
2950 RReleaseImage(prefs->swbackImage[i]);
2951 prefs->swbackImage[i] = NULL;
2953 break;
2957 RReleaseImage(bgimage);
2961 case 1:
2962 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
2963 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2964 break;
2965 } else
2966 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
2968 if (!path) {
2969 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2970 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
2971 } else {
2972 if (prefs->swtileImage)
2973 RReleaseImage(prefs->swtileImage);
2975 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
2976 if (!prefs->swtileImage) {
2977 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2979 wfree(path);
2981 break;
2983 default:
2984 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
2985 break;
2988 WMReleasePropList(array);
2990 return 0;
2993 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2995 int i;
2996 WPreferences *prefs = (WPreferences *) foo;
2998 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
2999 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3000 WMReleasePropList(array);
3001 return 0;
3004 DestroyWindowMenu(scr);
3006 for (i = 0; i < 7; i++) {
3007 if (prefs->modifier_labels[i])
3008 wfree(prefs->modifier_labels[i]);
3010 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3011 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3012 } else {
3013 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3014 prefs->modifier_labels[i] = NULL;
3018 WMReleasePropList(array);
3020 return 0;
3024 * Very ugly kluge.
3025 * Need access to the double click variables, so that all widgets in
3026 * wmaker panels will have the same dbl-click values.
3027 * TODO: figure a better way of dealing with it.
3029 #include <WINGs/WINGsP.h>
3031 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3033 extern _WINGsConfiguration WINGsConfiguration;
3035 if (*value <= 0)
3036 *(int *)foo = 1;
3038 WINGsConfiguration.doubleClickDelay = *value;
3040 return 0;
3043 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3045 if (wCursor[widx] != None) {
3046 XFreeCursor(dpy, wCursor[widx]);
3049 wCursor[widx] = *cursor;
3051 if (widx == WCUR_ROOT && *cursor != None) {
3052 XDefineCursor(dpy, scr->root_win, *cursor);
3055 return 0;