Fixed wrong re-generation of 'config-paths.h' file
[wmaker-crm.git] / src / defaults.c
blobc6fc2c358a79b9d2fe76718cb4641c487daa5485
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <strings.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifndef PATH_MAX
40 #define PATH_MAX DEFAULT_PATH_MAX
41 #endif
43 #include <X11/Xlib.h>
44 #include <X11/Xutil.h>
45 #include <X11/keysym.h>
47 #include <wraster.h>
49 #include "WindowMaker.h"
50 #include "framewin.h"
51 #include "window.h"
52 #include "texture.h"
53 #include "screen.h"
54 #include "resources.h"
55 #include "defaults.h"
56 #include "keybind.h"
57 #include "xmodifier.h"
58 #include "icon.h"
59 #include "main.h"
60 #include "actions.h"
61 #include "dock.h"
62 #include "workspace.h"
63 #include "properties.h"
65 #define MAX_SHORTCUT_LENGTH 32
67 #ifndef GLOBAL_DEFAULTS_SUBDIR
68 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
69 #endif
71 /***** Global *****/
72 extern WDDomain *WDWindowMaker;
73 extern WDDomain *WDWindowAttributes;
74 extern WDDomain *WDRootMenu;
75 extern int wScreenCount;
76 extern WPreferences wPreferences;
77 extern WShortKey wKeyBindings[WKBD_LAST];
79 typedef struct {
80 char *key;
81 char *default_value;
82 void *extra_data;
83 void *addr;
84 int (*convert) ();
85 int (*update) ();
86 WMPropList *plkey;
87 WMPropList *plvalue; /* default value */
88 } WDefaultEntry;
90 /* used to map strings to integers */
91 typedef struct {
92 char *string;
93 short value;
94 char is_alias;
95 } WOptionEnumeration;
97 /* type converters */
98 static int getBool();
99 static int getInt();
100 static int getCoord();
101 static int getPathList();
102 static int getEnum();
103 static int getTexture();
104 static int getWSBackground();
105 static int getWSSpecificBackground();
106 static int getFont();
107 static int getColor();
108 static int getKeybind();
109 static int getModMask();
110 static int getPropList();
112 /* value setting functions */
113 static int setJustify();
114 static int setClearance();
115 static int setIfDockPresent();
116 static int setStickyIcons();
117 static int setWidgetColor();
118 static int setIconTile();
119 static int setWinTitleFont();
120 static int setMenuTitleFont();
121 static int setMenuTextFont();
122 static int setIconTitleFont();
123 static int setIconTitleColor();
124 static int setIconTitleBack();
125 static int setLargeDisplayFont();
126 static int setWTitleColor();
127 static int setFTitleBack();
128 static int setPTitleBack();
129 static int setUTitleBack();
130 static int setResizebarBack();
131 static int setWorkspaceBack();
132 static int setWorkspaceSpecificBack();
133 static int setMenuTitleColor();
134 static int setMenuTextColor();
135 static int setMenuDisabledColor();
136 static int setMenuTitleBack();
137 static int setMenuTextBack();
138 static int setHightlight();
139 static int setHightlightText();
140 static int setKeyGrab();
141 static int setDoubleClick();
142 static int setIconPosition();
144 static int setClipTitleFont();
145 static int setClipTitleColor();
147 static int setMenuStyle();
148 static int setSwPOptions();
149 static int updateUsableArea();
151 static int setModifierKeyLabels();
153 extern Cursor wCursor[WCUR_LAST];
154 static int getCursor();
155 static int setCursor();
158 * Tables to convert strings to enumeration values.
159 * Values stored are char
162 /* WARNING: sum of length of all value strings must not exceed
163 * this value */
164 #define TOTAL_VALUES_LENGTH 80
166 #define REFRESH_WINDOW_TEXTURES (1<<0)
167 #define REFRESH_MENU_TEXTURE (1<<1)
168 #define REFRESH_MENU_FONT (1<<2)
169 #define REFRESH_MENU_COLOR (1<<3)
170 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
171 #define REFRESH_MENU_TITLE_FONT (1<<5)
172 #define REFRESH_MENU_TITLE_COLOR (1<<6)
173 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
174 #define REFRESH_WINDOW_FONT (1<<8)
175 #define REFRESH_ICON_TILE (1<<9)
176 #define REFRESH_ICON_FONT (1<<10)
177 #define REFRESH_WORKSPACE_BACK (1<<11)
179 #define REFRESH_BUTTON_IMAGES (1<<12)
181 #define REFRESH_ICON_TITLE_COLOR (1<<13)
182 #define REFRESH_ICON_TITLE_BACK (1<<14)
184 static WOptionEnumeration seFocusModes[] = {
185 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
186 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
187 {NULL, 0, 0}
190 static WOptionEnumeration seTitlebarModes[] = {
191 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
192 {"next", TS_NEXT, 0}, {NULL, 0, 0}
195 static WOptionEnumeration seColormapModes[] = {
196 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
197 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
198 {NULL, 0, 0}
201 static WOptionEnumeration sePlacements[] = {
202 {"Auto", WPM_AUTO, 0},
203 {"Smart", WPM_SMART, 0},
204 {"Cascade", WPM_CASCADE, 0},
205 {"Random", WPM_RANDOM, 0},
206 {"Manual", WPM_MANUAL, 0},
207 {"Center", WPM_CENTER, 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 #define NUM2STRING_(x) #x
333 #define NUM2STRING(x) NUM2STRING_(x)
335 WDefaultEntry optionList[] = {
337 /* dynamic options */
339 {"IconPosition", "blh", seIconPositions,
340 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
341 {"IconificationStyle", "Zoom", seIconificationStyles,
342 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
343 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
344 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
345 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
346 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
347 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
348 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
349 {"MouseWheelAction", "None", seMouseWheelActions,
350 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
351 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
352 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
353 {"IconPath", DEF_ICON_PATHS, NULL,
354 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
355 {"ColormapMode", "auto", seColormapModes,
356 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
357 {"AutoFocus", "NO", NULL,
358 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
359 {"RaiseDelay", "0", NULL,
360 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
361 {"CirculateRaise", "NO", NULL,
362 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
363 {"Superfluous", "NO", NULL,
364 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
365 {"AdvanceToNewWorkspace", "NO", NULL,
366 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
367 {"CycleWorkspaces", "NO", NULL,
368 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
369 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
370 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
371 {"WorkspaceBorder", "None", seWorkspaceBorder,
372 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
373 {"WorkspaceBorderSize", "0", NULL,
374 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
375 {"StickyIcons", "NO", NULL,
376 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
377 {"SaveSessionOnExit", "NO", NULL,
378 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
379 {"WrapMenus", "NO", NULL,
380 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
381 {"ScrollableMenus", "NO", NULL,
382 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
383 {"MenuScrollSpeed", "medium", seSpeeds,
384 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
385 {"IconSlideSpeed", "medium", seSpeeds,
386 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
387 {"ShadeSpeed", "medium", seSpeeds,
388 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
389 {"BounceAppIconsWhenUrgent", "YES", NULL,
390 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
391 {"RaiseAppIconsWhenBouncing", "NO", NULL,
392 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
393 {"DoNotMakeAppIconsBounce", "NO", NULL,
394 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
395 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
396 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
397 {"AlignSubmenus", "NO", NULL,
398 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
399 {"ViKeyMenus", "NO", NULL,
400 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
401 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
402 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
403 {"WindowPlacement", "auto", sePlacements,
404 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
405 {"IgnoreFocusClick", "NO", NULL,
406 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
407 {"UseSaveUnders", "NO", NULL,
408 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
409 {"OpaqueMove", "NO", NULL,
410 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
411 {"OpaqueResize", "NO", NULL,
412 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
413 {"OpaqueMoveResizeKeyboard", "NO", NULL,
414 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
415 {"DisableAnimations", "NO", NULL,
416 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
417 {"DontLinkWorkspaces", "NO", NULL,
418 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
419 {"AutoArrangeIcons", "NO", NULL,
420 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
421 {"NoWindowOverDock", "NO", NULL,
422 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
423 {"NoWindowOverIcons", "NO", NULL,
424 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
425 {"WindowPlaceOrigin", "(0, 0)", NULL,
426 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
427 {"ResizeDisplay", "corner", seGeomDisplays,
428 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
429 {"MoveDisplay", "corner", seGeomDisplays,
430 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
431 {"DontConfirmKill", "NO", NULL,
432 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
433 {"WindowTitleBalloons", "NO", NULL,
434 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
435 {"MiniwindowTitleBalloons", "NO", NULL,
436 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
437 {"AppIconBalloons", "NO", NULL,
438 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
439 {"HelpBalloons", "NO", NULL,
440 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
441 {"EdgeResistance", "30", NULL,
442 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
443 {"ResizeIncrement", "32", NULL,
444 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
445 {"Attraction", "NO", NULL,
446 &wPreferences.attract, getBool, NULL, NULL, NULL},
447 {"DisableBlinking", "NO", NULL,
448 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
449 {"SingleClickLaunch", "NO", NULL,
450 &wPreferences.single_click, getBool, NULL, NULL, NULL},
452 /* style options */
454 {"MenuStyle", "normal", seMenuStyles,
455 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
456 {"WidgetColor", "(solid, gray)", NULL,
457 NULL, getTexture, setWidgetColor, NULL, NULL},
458 {"WorkspaceSpecificBack", "()", NULL,
459 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
460 /* WorkspaceBack must come after WorkspaceSpecificBack or
461 * WorkspaceBack wont know WorkspaceSpecificBack was also
462 * specified and 2 copies of wmsetbg will be launched */
463 {"WorkspaceBack", "(solid, black)", NULL,
464 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
465 {"SmoothWorkspaceBack", "NO", NULL,
466 NULL, getBool, NULL, NULL, NULL},
467 {"IconBack", "(solid, gray)", NULL,
468 NULL, getTexture, setIconTile, NULL, NULL},
469 {"TitleJustify", "center", seJustifications,
470 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
471 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
472 NULL, getFont, setWinTitleFont, NULL, NULL},
473 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
474 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
475 {"WindowTitleMinHeight", "0", NULL,
476 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
477 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
478 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
479 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
480 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
481 {"MenuTitleMinHeight", "0", NULL,
482 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
483 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
484 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
485 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
486 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
487 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
488 NULL, getFont, setMenuTitleFont, NULL, NULL},
489 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
490 NULL, getFont, setMenuTextFont, NULL, NULL},
491 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
492 NULL, getFont, setIconTitleFont, NULL, NULL},
493 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
494 NULL, getFont, setClipTitleFont, NULL, NULL},
495 {"ShowClipTitle", "YES", NULL,
496 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
497 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
498 NULL, getFont, setLargeDisplayFont, NULL, NULL},
499 {"HighlightColor", "white", NULL,
500 NULL, getColor, setHightlight, NULL, NULL},
501 {"HighlightTextColor", "black", NULL,
502 NULL, getColor, setHightlightText, NULL, NULL},
503 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
504 NULL, getColor, setClipTitleColor, NULL, NULL},
505 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
506 NULL, getColor, setClipTitleColor, NULL, NULL},
507 {"FTitleColor", "white", (void *)WS_FOCUSED,
508 NULL, getColor, setWTitleColor, NULL, NULL},
509 {"PTitleColor", "white", (void *)WS_PFOCUSED,
510 NULL, getColor, setWTitleColor, NULL, NULL},
511 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
512 NULL, getColor, setWTitleColor, NULL, NULL},
513 {"FTitleBack", "(solid, black)", NULL,
514 NULL, getTexture, setFTitleBack, NULL, NULL},
515 {"PTitleBack", "(solid, \"#616161\")", NULL,
516 NULL, getTexture, setPTitleBack, NULL, NULL},
517 {"UTitleBack", "(solid, gray)", NULL,
518 NULL, getTexture, setUTitleBack, NULL, NULL},
519 {"ResizebarBack", "(solid, gray)", NULL,
520 NULL, getTexture, setResizebarBack, NULL, NULL},
521 {"MenuTitleColor", "white", NULL,
522 NULL, getColor, setMenuTitleColor, NULL, NULL},
523 {"MenuTextColor", "black", NULL,
524 NULL, getColor, setMenuTextColor, NULL, NULL},
525 {"MenuDisabledColor", "\"#616161\"", NULL,
526 NULL, getColor, setMenuDisabledColor, NULL, NULL},
527 {"MenuTitleBack", "(solid, black)", NULL,
528 NULL, getTexture, setMenuTitleBack, NULL, NULL},
529 {"MenuTextBack", "(solid, gray)", NULL,
530 NULL, getTexture, setMenuTextBack, NULL, NULL},
531 {"IconTitleColor", "white", NULL,
532 NULL, getColor, setIconTitleColor, NULL, NULL},
533 {"IconTitleBack", "black", NULL,
534 NULL, getColor, setIconTitleBack, NULL, NULL},
535 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
536 NULL, getPropList, setSwPOptions, NULL, NULL},
537 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
538 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
540 /* keybindings */
542 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
543 NULL, getKeybind, setKeyGrab, NULL, NULL},
544 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
545 NULL, getKeybind, setKeyGrab, NULL, NULL},
546 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
547 NULL, getKeybind, setKeyGrab, NULL, NULL},
548 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
549 NULL, getKeybind, setKeyGrab, NULL, NULL},
550 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
551 NULL, getKeybind, setKeyGrab, NULL, NULL},
552 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
553 NULL, getKeybind, setKeyGrab, NULL, NULL},
554 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
555 NULL, getKeybind, setKeyGrab, NULL, NULL },
556 {"HideKey", "None", (void *)WKBD_HIDE,
557 NULL, getKeybind, setKeyGrab, NULL, NULL},
558 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
559 NULL, getKeybind, setKeyGrab, NULL, NULL},
560 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
561 NULL, getKeybind, setKeyGrab, NULL, NULL},
562 {"CloseKey", "None", (void *)WKBD_CLOSE,
563 NULL, getKeybind, setKeyGrab, NULL, NULL},
564 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
565 NULL, getKeybind, setKeyGrab, NULL, NULL},
566 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
567 NULL, getKeybind, setKeyGrab, NULL, NULL},
568 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
569 NULL, getKeybind, setKeyGrab, NULL, NULL},
570 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
571 NULL, getKeybind, setKeyGrab, NULL, NULL},
572 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
573 NULL, getKeybind, setKeyGrab, NULL, NULL},
574 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
575 NULL, getKeybind, setKeyGrab, NULL, NULL},
576 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
577 NULL, getKeybind, setKeyGrab, NULL, NULL},
578 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
579 NULL, getKeybind, setKeyGrab, NULL, NULL},
580 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
581 NULL, getKeybind, setKeyGrab, NULL, NULL},
582 {"ShadeKey", "None", (void *)WKBD_SHADE,
583 NULL, getKeybind, setKeyGrab, NULL, NULL},
584 {"SelectKey", "None", (void *)WKBD_SELECT,
585 NULL, getKeybind, setKeyGrab, NULL, NULL},
586 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
587 NULL, getKeybind, setKeyGrab, NULL, NULL},
588 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
589 NULL, getKeybind, setKeyGrab, NULL, NULL},
590 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
591 NULL, getKeybind, setKeyGrab, NULL, NULL},
592 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
593 NULL, getKeybind, setKeyGrab, NULL, NULL},
594 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
595 NULL, getKeybind, setKeyGrab, NULL, NULL},
596 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
597 NULL, getKeybind, setKeyGrab, NULL, NULL},
598 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
599 NULL, getKeybind, setKeyGrab, NULL, NULL},
600 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
601 NULL, getKeybind, setKeyGrab, NULL, NULL},
602 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
603 NULL, getKeybind, setKeyGrab, NULL, NULL},
604 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
605 NULL, getKeybind, setKeyGrab, NULL, NULL},
606 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
607 NULL, getKeybind, setKeyGrab, NULL, NULL},
608 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
609 NULL, getKeybind, setKeyGrab, NULL, NULL},
610 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
611 NULL, getKeybind, setKeyGrab, NULL, NULL},
612 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
613 NULL, getKeybind, setKeyGrab, NULL, NULL},
614 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
615 NULL, getKeybind, setKeyGrab, NULL, NULL},
616 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
617 NULL, getKeybind, setKeyGrab, NULL, NULL},
618 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
619 NULL, getKeybind, setKeyGrab, NULL, NULL},
620 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
621 NULL, getKeybind, setKeyGrab, NULL, NULL},
622 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
623 NULL, getKeybind, setKeyGrab, NULL, NULL},
624 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
625 NULL, getKeybind, setKeyGrab, NULL, NULL},
626 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
627 NULL, getKeybind, setKeyGrab, NULL, NULL},
628 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
629 NULL, getKeybind, setKeyGrab, NULL, NULL},
630 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
631 NULL, getKeybind, setKeyGrab, NULL, NULL},
632 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
633 NULL, getKeybind, setKeyGrab, NULL, NULL},
634 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
635 NULL, getKeybind, setKeyGrab, NULL, NULL},
636 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
637 NULL, getKeybind, setKeyGrab, NULL, NULL},
638 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
639 NULL, getKeybind, setKeyGrab, NULL, NULL},
640 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
641 NULL, getKeybind, setKeyGrab, NULL, NULL},
642 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
643 NULL, getKeybind, setKeyGrab, NULL, NULL},
644 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
645 NULL, getKeybind, setKeyGrab, NULL, NULL},
647 #ifdef KEEP_XKB_LOCK_STATUS
648 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
649 NULL, getKeybind, setKeyGrab, NULL, NULL},
650 {"KbdModeLock", "NO", NULL,
651 &wPreferences.modelock, getBool, NULL, NULL, NULL},
652 #endif /* KEEP_XKB_LOCK_STATUS */
654 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
655 NULL, getCursor, setCursor, NULL, NULL},
656 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
657 NULL, getCursor, setCursor, NULL, NULL},
658 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
659 NULL, getCursor, setCursor, NULL, NULL},
660 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
661 NULL, getCursor, setCursor, NULL, NULL},
662 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
663 NULL, getCursor, setCursor, NULL, NULL},
664 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
665 NULL, getCursor, setCursor, NULL, NULL},
666 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
667 NULL, getCursor, setCursor, NULL, NULL},
668 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
669 NULL, getCursor, setCursor, NULL, NULL},
670 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
671 NULL, getCursor, setCursor, NULL, NULL},
672 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
673 NULL, getCursor, setCursor, NULL, NULL},
674 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
675 NULL, getCursor, setCursor, NULL, NULL},
676 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
677 NULL, getCursor, setCursor, NULL, NULL},
678 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
679 NULL, getCursor, setCursor, NULL, NULL},
680 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
681 NULL, getCursor, setCursor, NULL, NULL},
682 {"DialogHistoryLines", "500", NULL,
683 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
684 {"CycleActiveHeadOnly", "NO", NULL,
685 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL}
688 static void initDefaults()
690 unsigned int i;
691 WDefaultEntry *entry;
693 WMPLSetCaseSensitive(False);
695 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
696 entry = &optionList[i];
698 entry->plkey = WMCreatePLString(entry->key);
699 if (entry->default_value)
700 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
701 else
702 entry->plvalue = NULL;
705 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
706 entry = &staticOptionList[i];
708 entry->plkey = WMCreatePLString(entry->key);
709 if (entry->default_value)
710 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
711 else
712 entry->plvalue = NULL;
716 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
718 WMPropList *globalDict = NULL;
719 char path[PATH_MAX];
720 struct stat stbuf;
722 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
723 if (stat(path, &stbuf) >= 0) {
724 globalDict = WMReadPropListFromFile(path);
725 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
726 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
727 WMReleasePropList(globalDict);
728 globalDict = NULL;
729 } else if (!globalDict) {
730 wwarning(_("could not load domain %s from global defaults database"), domainName);
734 return globalDict;
737 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
738 static void prependMenu(WMPropList * destarr, WMPropList * array)
740 WMPropList *item;
741 int i;
743 for (i = 0; i < WMGetPropListItemCount(array); i++) {
744 item = WMGetFromPLArray(array, i);
745 if (item)
746 WMInsertInPLArray(destarr, i + 1, item);
750 static void appendMenu(WMPropList * destarr, WMPropList * array)
752 WMPropList *item;
753 int i;
755 for (i = 0; i < WMGetPropListItemCount(array); i++) {
756 item = WMGetFromPLArray(array, i);
757 if (item)
758 WMAddToPLArray(destarr, item);
761 #endif
763 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
765 WMPropList *menu = menuDomain->dictionary;
766 WMPropList *submenu;
768 if (!menu || !WMIsPLArray(menu))
769 return;
771 #ifdef GLOBAL_PREAMBLE_MENU_FILE
772 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
774 if (submenu && !WMIsPLArray(submenu)) {
775 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
776 WMReleasePropList(submenu);
777 submenu = NULL;
779 if (submenu) {
780 prependMenu(menu, submenu);
781 WMReleasePropList(submenu);
783 #endif
785 #ifdef GLOBAL_EPILOGUE_MENU_FILE
786 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
788 if (submenu && !WMIsPLArray(submenu)) {
789 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
790 WMReleasePropList(submenu);
791 submenu = NULL;
793 if (submenu) {
794 appendMenu(menu, submenu);
795 WMReleasePropList(submenu);
797 #endif
799 menuDomain->dictionary = menu;
802 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
804 WDDomain *db;
805 struct stat stbuf;
806 static int inited = 0;
807 char *the_path;
808 WMPropList *shared_dict = NULL;
810 if (!inited) {
811 inited = 1;
812 initDefaults();
815 db = wmalloc(sizeof(WDDomain));
816 db->domain_name = domain;
817 db->path = wdefaultspathfordomain(domain);
818 the_path = db->path;
820 if (the_path && stat(the_path, &stbuf) >= 0) {
821 db->dictionary = WMReadPropListFromFile(the_path);
822 if (db->dictionary) {
823 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
824 WMReleasePropList(db->dictionary);
825 db->dictionary = NULL;
826 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
828 db->timestamp = stbuf.st_mtime;
829 } else {
830 wwarning(_("could not load domain %s from user defaults database"), domain);
834 /* global system dictionary */
835 shared_dict = readGlobalDomain(domain, requireDictionary);
837 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
838 WMIsPLDictionary(db->dictionary)) {
839 WMMergePLDictionaries(shared_dict, db->dictionary, True);
840 WMReleasePropList(db->dictionary);
841 db->dictionary = shared_dict;
842 if (stbuf.st_mtime > db->timestamp)
843 db->timestamp = stbuf.st_mtime;
844 } else if (!db->dictionary) {
845 db->dictionary = shared_dict;
846 if (stbuf.st_mtime > db->timestamp)
847 db->timestamp = stbuf.st_mtime;
850 return db;
853 void wReadStaticDefaults(WMPropList * dict)
855 WMPropList *plvalue;
856 WDefaultEntry *entry;
857 unsigned int i;
858 void *tdata;
860 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
861 entry = &staticOptionList[i];
863 if (dict)
864 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
865 else
866 plvalue = NULL;
868 if (!plvalue) {
869 /* no default in the DB. Use builtin default */
870 plvalue = entry->plvalue;
873 if (plvalue) {
874 /* convert data */
875 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
876 if (entry->update) {
877 (*entry->update) (NULL, entry, tdata, entry->extra_data);
883 void wDefaultsCheckDomains(void* arg)
885 WScreen *scr;
886 struct stat stbuf;
887 WMPropList *shared_dict = NULL;
888 WMPropList *dict;
889 int i;
891 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
892 WDWindowMaker->timestamp = stbuf.st_mtime;
894 /* Global dictionary */
895 shared_dict = readGlobalDomain("WindowMaker", True);
897 /* User dictionary */
898 dict = WMReadPropListFromFile(WDWindowMaker->path);
900 if (dict) {
901 if (!WMIsPLDictionary(dict)) {
902 WMReleasePropList(dict);
903 dict = NULL;
904 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
905 "WindowMaker", WDWindowMaker->path);
906 } else {
907 if (shared_dict) {
908 WMMergePLDictionaries(shared_dict, dict, True);
909 WMReleasePropList(dict);
910 dict = shared_dict;
911 shared_dict = NULL;
914 for (i = 0; i < wScreenCount; i++) {
915 scr = wScreenWithNumber(i);
916 if (scr)
917 wReadDefaults(scr, dict);
920 if (WDWindowMaker->dictionary)
921 WMReleasePropList(WDWindowMaker->dictionary);
923 WDWindowMaker->dictionary = dict;
925 } else {
926 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
929 if (shared_dict)
930 WMReleasePropList(shared_dict);
934 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
935 /* global dictionary */
936 shared_dict = readGlobalDomain("WMWindowAttributes", True);
937 /* user dictionary */
938 dict = WMReadPropListFromFile(WDWindowAttributes->path);
939 if (dict) {
940 if (!WMIsPLDictionary(dict)) {
941 WMReleasePropList(dict);
942 dict = NULL;
943 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
944 "WMWindowAttributes", WDWindowAttributes->path);
945 } else {
946 if (shared_dict) {
947 WMMergePLDictionaries(shared_dict, dict, True);
948 WMReleasePropList(dict);
949 dict = shared_dict;
950 shared_dict = NULL;
952 if (WDWindowAttributes->dictionary) {
953 WMReleasePropList(WDWindowAttributes->dictionary);
955 WDWindowAttributes->dictionary = dict;
956 for (i = 0; i < wScreenCount; i++) {
957 scr = wScreenWithNumber(i);
958 if (scr) {
959 wDefaultUpdateIcons(scr);
961 /* Update the panel image if changed */
962 /* Don't worry. If the image is the same these
963 * functions will have no performance impact. */
964 create_logo_image(scr);
968 } else {
969 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
971 WDWindowAttributes->timestamp = stbuf.st_mtime;
972 if (shared_dict) {
973 WMReleasePropList(shared_dict);
977 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
978 dict = WMReadPropListFromFile(WDRootMenu->path);
979 if (dict) {
980 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
981 WMReleasePropList(dict);
982 dict = NULL;
983 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
984 "WMRootMenu", WDRootMenu->path);
985 } else {
986 if (WDRootMenu->dictionary) {
987 WMReleasePropList(WDRootMenu->dictionary);
989 WDRootMenu->dictionary = dict;
990 wDefaultsMergeGlobalMenus(WDRootMenu);
992 } else {
993 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
995 WDRootMenu->timestamp = stbuf.st_mtime;
997 #ifndef HAVE_INOTIFY
998 if (!arg)
999 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1000 #endif
1003 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1005 WMPropList *plvalue, *old_value;
1006 WDefaultEntry *entry;
1007 unsigned int i;
1008 int update_workspace_back = 0; /* kluge :/ */
1009 unsigned int needs_refresh;
1010 void *tdata;
1011 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1013 needs_refresh = 0;
1015 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1016 entry = &optionList[i];
1018 if (new_dict)
1019 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1020 else
1021 plvalue = NULL;
1023 if (!old_dict)
1024 old_value = NULL;
1025 else
1026 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1028 if (!plvalue && !old_value) {
1029 /* no default in the DB. Use builtin default */
1030 plvalue = entry->plvalue;
1031 if (plvalue && new_dict)
1032 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1034 } else if (!plvalue) {
1035 /* value was deleted from DB. Keep current value */
1036 continue;
1037 } else if (!old_value) {
1038 /* set value for the 1st time */
1039 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1040 /* value has changed */
1041 } else {
1042 if (strcmp(entry->key, "WorkspaceBack") == 0
1043 && update_workspace_back && scr->flags.backimage_helper_launched) {
1044 } else {
1045 /* value was not changed since last time */
1046 continue;
1050 if (plvalue) {
1051 /* convert data */
1052 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1054 * If the WorkspaceSpecificBack data has been changed
1055 * so that the helper will be launched now, we must be
1056 * sure to send the default background texture config
1057 * to the helper.
1059 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1060 !scr->flags.backimage_helper_launched)
1061 update_workspace_back = 1;
1063 if (entry->update)
1064 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1070 if (needs_refresh != 0 && !scr->flags.startup) {
1071 int foo;
1073 foo = 0;
1074 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1075 foo |= WTextureSettings;
1076 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1077 foo |= WFontSettings;
1078 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1079 foo |= WColorSettings;
1080 if (foo)
1081 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1082 (void *)(uintptr_t) foo);
1084 foo = 0;
1085 if (needs_refresh & REFRESH_MENU_TEXTURE)
1086 foo |= WTextureSettings;
1087 if (needs_refresh & REFRESH_MENU_FONT)
1088 foo |= WFontSettings;
1089 if (needs_refresh & REFRESH_MENU_COLOR)
1090 foo |= WColorSettings;
1091 if (foo)
1092 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1094 foo = 0;
1095 if (needs_refresh & REFRESH_WINDOW_FONT)
1096 foo |= WFontSettings;
1097 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1098 foo |= WTextureSettings;
1099 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1100 foo |= WColorSettings;
1101 if (foo)
1102 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1104 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1105 foo = 0;
1106 if (needs_refresh & REFRESH_ICON_FONT)
1107 foo |= WFontSettings;
1108 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1109 foo |= WTextureSettings;
1110 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1111 foo |= WTextureSettings;
1112 if (foo)
1113 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1114 (void *)(uintptr_t) foo);
1116 if (needs_refresh & REFRESH_ICON_TILE)
1117 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1121 void wDefaultUpdateIcons(WScreen * scr)
1123 WAppIcon *aicon = scr->app_icon_list;
1124 WWindow *wwin = scr->focused_window;
1125 char *file;
1127 while (aicon) {
1128 file = wDefaultGetIconFile(aicon->wm_instance, aicon->wm_class, False);
1129 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1130 || (file && !aicon->icon->file)) {
1131 wIconChangeImageFile(aicon->icon, file);
1132 wAppIconPaint(aicon);
1134 aicon = aicon->next;
1137 if (!wPreferences.flags.noclip)
1138 wClipIconPaint(scr->clip_icon);
1140 while (wwin) {
1141 if (wwin->icon && wwin->flags.miniaturized) {
1142 file = wDefaultGetIconFile(wwin->wm_instance, wwin->wm_class, False);
1143 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1144 || (file && !wwin->icon->file)) {
1145 wIconChangeImageFile(wwin->icon, file);
1148 wwin = wwin->prev;
1152 /* --------------------------- Local ----------------------- */
1154 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1155 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1156 entry->key, x); \
1157 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1158 var = entry->default_value;\
1159 } else var = WMGetFromPLString(value)\
1162 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1164 char *str;
1165 WOptionEnumeration *v;
1166 char buffer[TOTAL_VALUES_LENGTH];
1168 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1169 for (v = values; v->string != NULL; v++) {
1170 if (strcasecmp(v->string, str) == 0)
1171 return v->value;
1175 buffer[0] = 0;
1176 for (v = values; v->string != NULL; v++) {
1177 if (!v->is_alias) {
1178 if (buffer[0] != 0)
1179 strcat(buffer, ", ");
1180 snprintf(buffer+strlen(buffer),
1181 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1184 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1185 WMGetFromPLString(key),
1186 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1187 buffer);
1189 if (def) {
1190 return string2index(key, val, NULL, values);
1193 return -1;
1197 * value - is the value in the defaults DB
1198 * addr - is the address to store the data
1199 * ret - is the address to store a pointer to a temporary buffer. ret
1200 * must not be freed and is used by the set functions
1202 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1204 static char data;
1205 char *val;
1206 int second_pass = 0;
1208 GET_STRING_OR_DEFAULT("Boolean", val);
1210 again:
1211 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1212 || strcasecmp(val, "YES") == 0) {
1214 data = 1;
1215 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1216 || strcasecmp(val, "NO") == 0) {
1217 data = 0;
1218 } else {
1219 int i;
1220 if (sscanf(val, "%i", &i) == 1) {
1221 if (i != 0)
1222 data = 1;
1223 else
1224 data = 0;
1225 } else {
1226 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1227 if (second_pass == 0) {
1228 val = WMGetFromPLString(entry->plvalue);
1229 second_pass = 1;
1230 wwarning(_("using default \"%s\" instead"), val);
1231 goto again;
1233 return False;
1237 if (ret)
1238 *ret = &data;
1239 if (addr)
1240 *(char *)addr = data;
1242 return True;
1245 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1247 static int data;
1248 char *val;
1250 GET_STRING_OR_DEFAULT("Integer", val);
1252 if (sscanf(val, "%i", &data) != 1) {
1253 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1254 val = WMGetFromPLString(entry->plvalue);
1255 wwarning(_("using default \"%s\" instead"), val);
1256 if (sscanf(val, "%i", &data) != 1) {
1257 return False;
1261 if (ret)
1262 *ret = &data;
1263 if (addr)
1264 *(int *)addr = data;
1266 return True;
1269 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1271 static WCoord data;
1272 char *val_x, *val_y;
1273 int nelem, changed = 0;
1274 WMPropList *elem_x, *elem_y;
1276 again:
1277 if (!WMIsPLArray(value)) {
1278 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1279 if (changed == 0) {
1280 value = entry->plvalue;
1281 changed = 1;
1282 wwarning(_("using default \"%s\" instead"), entry->default_value);
1283 goto again;
1285 return False;
1288 nelem = WMGetPropListItemCount(value);
1289 if (nelem != 2) {
1290 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1291 if (changed == 0) {
1292 value = entry->plvalue;
1293 changed = 1;
1294 wwarning(_("using default \"%s\" instead"), entry->default_value);
1295 goto again;
1297 return False;
1300 elem_x = WMGetFromPLArray(value, 0);
1301 elem_y = WMGetFromPLArray(value, 1);
1303 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1304 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1305 if (changed == 0) {
1306 value = entry->plvalue;
1307 changed = 1;
1308 wwarning(_("using default \"%s\" instead"), entry->default_value);
1309 goto again;
1311 return False;
1314 val_x = WMGetFromPLString(elem_x);
1315 val_y = WMGetFromPLString(elem_y);
1317 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1318 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1319 if (changed == 0) {
1320 value = entry->plvalue;
1321 changed = 1;
1322 wwarning(_("using default \"%s\" instead"), entry->default_value);
1323 goto again;
1325 return False;
1328 if (data.x < 0)
1329 data.x = 0;
1330 else if (data.x > scr->scr_width / 3)
1331 data.x = scr->scr_width / 3;
1332 if (data.y < 0)
1333 data.y = 0;
1334 else if (data.y > scr->scr_height / 3)
1335 data.y = scr->scr_height / 3;
1337 if (ret)
1338 *ret = &data;
1339 if (addr)
1340 *(WCoord *) addr = data;
1342 return True;
1345 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1347 WMRetainPropList(value);
1349 *ret = value;
1351 return True;
1354 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1356 static char *data;
1357 int i, count, len;
1358 char *ptr;
1359 WMPropList *d;
1360 int changed = 0;
1362 again:
1363 if (!WMIsPLArray(value)) {
1364 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1365 if (changed == 0) {
1366 value = entry->plvalue;
1367 changed = 1;
1368 wwarning(_("using default \"%s\" instead"), entry->default_value);
1369 goto again;
1371 return False;
1374 i = 0;
1375 count = WMGetPropListItemCount(value);
1376 if (count < 1) {
1377 if (changed == 0) {
1378 value = entry->plvalue;
1379 changed = 1;
1380 wwarning(_("using default \"%s\" instead"), entry->default_value);
1381 goto again;
1383 return False;
1386 len = 0;
1387 for (i = 0; i < count; i++) {
1388 d = WMGetFromPLArray(value, i);
1389 if (!d || !WMIsPLString(d)) {
1390 count = i;
1391 break;
1393 len += strlen(WMGetFromPLString(d)) + 1;
1396 ptr = data = wmalloc(len + 1);
1398 for (i = 0; i < count; i++) {
1399 d = WMGetFromPLArray(value, i);
1400 if (!d || !WMIsPLString(d)) {
1401 break;
1403 strcpy(ptr, WMGetFromPLString(d));
1404 ptr += strlen(WMGetFromPLString(d));
1405 *ptr = ':';
1406 ptr++;
1408 ptr--;
1409 *(ptr--) = 0;
1411 if (*(char **)addr != NULL) {
1412 wfree(*(char **)addr);
1414 *(char **)addr = data;
1416 return True;
1419 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1421 static signed char data;
1423 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1424 if (data < 0)
1425 return False;
1427 if (ret)
1428 *ret = &data;
1429 if (addr)
1430 *(signed char *)addr = data;
1432 return True;
1436 * (solid <color>)
1437 * (hgradient <color> <color>)
1438 * (vgradient <color> <color>)
1439 * (dgradient <color> <color>)
1440 * (mhgradient <color> <color> ...)
1441 * (mvgradient <color> <color> ...)
1442 * (mdgradient <color> <color> ...)
1443 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1444 * (tpixmap <file> <color>)
1445 * (spixmap <file> <color>)
1446 * (cpixmap <file> <color>)
1447 * (thgradient <file> <opaqueness> <color> <color>)
1448 * (tvgradient <file> <opaqueness> <color> <color>)
1449 * (tdgradient <file> <opaqueness> <color> <color>)
1450 * (function <lib> <function> ...)
1453 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1455 WMPropList *elem;
1456 char *val;
1457 int nelem;
1458 WTexture *texture = NULL;
1460 nelem = WMGetPropListItemCount(pl);
1461 if (nelem < 1)
1462 return NULL;
1464 elem = WMGetFromPLArray(pl, 0);
1465 if (!elem || !WMIsPLString(elem))
1466 return NULL;
1467 val = WMGetFromPLString(elem);
1469 if (strcasecmp(val, "solid") == 0) {
1470 XColor color;
1472 if (nelem != 2)
1473 return NULL;
1475 /* get color */
1477 elem = WMGetFromPLArray(pl, 1);
1478 if (!elem || !WMIsPLString(elem))
1479 return NULL;
1480 val = WMGetFromPLString(elem);
1482 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1483 wwarning(_("\"%s\" is not a valid color name"), val);
1484 return NULL;
1487 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1488 } else if (strcasecmp(val, "dgradient") == 0
1489 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1490 RColor color1, color2;
1491 XColor xcolor;
1492 int type;
1494 if (nelem != 3) {
1495 wwarning(_("bad number of arguments in gradient specification"));
1496 return NULL;
1499 if (val[0] == 'd' || val[0] == 'D')
1500 type = WTEX_DGRADIENT;
1501 else if (val[0] == 'h' || val[0] == 'H')
1502 type = WTEX_HGRADIENT;
1503 else
1504 type = WTEX_VGRADIENT;
1506 /* get from color */
1507 elem = WMGetFromPLArray(pl, 1);
1508 if (!elem || !WMIsPLString(elem))
1509 return NULL;
1510 val = WMGetFromPLString(elem);
1512 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1513 wwarning(_("\"%s\" is not a valid color name"), val);
1514 return NULL;
1516 color1.alpha = 255;
1517 color1.red = xcolor.red >> 8;
1518 color1.green = xcolor.green >> 8;
1519 color1.blue = xcolor.blue >> 8;
1521 /* get to color */
1522 elem = WMGetFromPLArray(pl, 2);
1523 if (!elem || !WMIsPLString(elem)) {
1524 return NULL;
1526 val = WMGetFromPLString(elem);
1528 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1529 wwarning(_("\"%s\" is not a valid color name"), val);
1530 return NULL;
1532 color2.alpha = 255;
1533 color2.red = xcolor.red >> 8;
1534 color2.green = xcolor.green >> 8;
1535 color2.blue = xcolor.blue >> 8;
1537 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1539 } else if (strcasecmp(val, "igradient") == 0) {
1540 RColor colors1[2], colors2[2];
1541 int th1, th2;
1542 XColor xcolor;
1543 int i;
1545 if (nelem != 7) {
1546 wwarning(_("bad number of arguments in gradient specification"));
1547 return NULL;
1550 /* get from color */
1551 for (i = 0; i < 2; i++) {
1552 elem = WMGetFromPLArray(pl, 1 + i);
1553 if (!elem || !WMIsPLString(elem))
1554 return NULL;
1555 val = WMGetFromPLString(elem);
1557 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1558 wwarning(_("\"%s\" is not a valid color name"), val);
1559 return NULL;
1561 colors1[i].alpha = 255;
1562 colors1[i].red = xcolor.red >> 8;
1563 colors1[i].green = xcolor.green >> 8;
1564 colors1[i].blue = xcolor.blue >> 8;
1566 elem = WMGetFromPLArray(pl, 3);
1567 if (!elem || !WMIsPLString(elem))
1568 return NULL;
1569 val = WMGetFromPLString(elem);
1570 th1 = atoi(val);
1572 /* get from color */
1573 for (i = 0; i < 2; i++) {
1574 elem = WMGetFromPLArray(pl, 4 + i);
1575 if (!elem || !WMIsPLString(elem))
1576 return NULL;
1577 val = WMGetFromPLString(elem);
1579 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1580 wwarning(_("\"%s\" is not a valid color name"), val);
1581 return NULL;
1583 colors2[i].alpha = 255;
1584 colors2[i].red = xcolor.red >> 8;
1585 colors2[i].green = xcolor.green >> 8;
1586 colors2[i].blue = xcolor.blue >> 8;
1588 elem = WMGetFromPLArray(pl, 6);
1589 if (!elem || !WMIsPLString(elem))
1590 return NULL;
1591 val = WMGetFromPLString(elem);
1592 th2 = atoi(val);
1594 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1596 } else if (strcasecmp(val, "mhgradient") == 0
1597 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1598 XColor color;
1599 RColor **colors;
1600 int i, count;
1601 int type;
1603 if (nelem < 3) {
1604 wwarning(_("too few arguments in multicolor gradient specification"));
1605 return NULL;
1608 if (val[1] == 'h' || val[1] == 'H')
1609 type = WTEX_MHGRADIENT;
1610 else if (val[1] == 'v' || val[1] == 'V')
1611 type = WTEX_MVGRADIENT;
1612 else
1613 type = WTEX_MDGRADIENT;
1615 count = nelem - 1;
1617 colors = wmalloc(sizeof(RColor *) * (count + 1));
1619 for (i = 0; i < count; i++) {
1620 elem = WMGetFromPLArray(pl, i + 1);
1621 if (!elem || !WMIsPLString(elem)) {
1622 for (--i; i >= 0; --i) {
1623 wfree(colors[i]);
1625 wfree(colors);
1626 return NULL;
1628 val = WMGetFromPLString(elem);
1630 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1631 wwarning(_("\"%s\" is not a valid color name"), val);
1632 for (--i; i >= 0; --i) {
1633 wfree(colors[i]);
1635 wfree(colors);
1636 return NULL;
1637 } else {
1638 colors[i] = wmalloc(sizeof(RColor));
1639 colors[i]->red = color.red >> 8;
1640 colors[i]->green = color.green >> 8;
1641 colors[i]->blue = color.blue >> 8;
1644 colors[i] = NULL;
1646 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1647 } else if (strcasecmp(val, "spixmap") == 0 ||
1648 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1649 XColor color;
1650 int type;
1652 if (nelem != 3)
1653 return NULL;
1655 if (val[0] == 's' || val[0] == 'S')
1656 type = WTP_SCALE;
1657 else if (val[0] == 'c' || val[0] == 'C')
1658 type = WTP_CENTER;
1659 else
1660 type = WTP_TILE;
1662 /* get color */
1663 elem = WMGetFromPLArray(pl, 2);
1664 if (!elem || !WMIsPLString(elem)) {
1665 return NULL;
1667 val = WMGetFromPLString(elem);
1669 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1670 wwarning(_("\"%s\" is not a valid color name"), val);
1671 return NULL;
1674 /* file name */
1675 elem = WMGetFromPLArray(pl, 1);
1676 if (!elem || !WMIsPLString(elem))
1677 return NULL;
1678 val = WMGetFromPLString(elem);
1680 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1681 } else if (strcasecmp(val, "thgradient") == 0
1682 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1683 RColor color1, color2;
1684 XColor xcolor;
1685 int opacity;
1686 int style;
1688 if (val[1] == 'h' || val[1] == 'H')
1689 style = WTEX_THGRADIENT;
1690 else if (val[1] == 'v' || val[1] == 'V')
1691 style = WTEX_TVGRADIENT;
1692 else
1693 style = WTEX_TDGRADIENT;
1695 if (nelem != 5) {
1696 wwarning(_("bad number of arguments in textured gradient specification"));
1697 return NULL;
1700 /* get from color */
1701 elem = WMGetFromPLArray(pl, 3);
1702 if (!elem || !WMIsPLString(elem))
1703 return NULL;
1704 val = WMGetFromPLString(elem);
1706 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1707 wwarning(_("\"%s\" is not a valid color name"), val);
1708 return NULL;
1710 color1.alpha = 255;
1711 color1.red = xcolor.red >> 8;
1712 color1.green = xcolor.green >> 8;
1713 color1.blue = xcolor.blue >> 8;
1715 /* get to color */
1716 elem = WMGetFromPLArray(pl, 4);
1717 if (!elem || !WMIsPLString(elem)) {
1718 return NULL;
1720 val = WMGetFromPLString(elem);
1722 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1723 wwarning(_("\"%s\" is not a valid color name"), val);
1724 return NULL;
1726 color2.alpha = 255;
1727 color2.red = xcolor.red >> 8;
1728 color2.green = xcolor.green >> 8;
1729 color2.blue = xcolor.blue >> 8;
1731 /* get opacity */
1732 elem = WMGetFromPLArray(pl, 2);
1733 if (!elem || !WMIsPLString(elem))
1734 opacity = 128;
1735 else
1736 val = WMGetFromPLString(elem);
1738 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1739 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1740 opacity = 128;
1743 /* get file name */
1744 elem = WMGetFromPLArray(pl, 1);
1745 if (!elem || !WMIsPLString(elem))
1746 return NULL;
1747 val = WMGetFromPLString(elem);
1749 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1750 } else if (strcasecmp(val, "function") == 0) {
1751 /* Leave this in to handle the unlikely case of
1752 * someone actually having function textures configured */
1753 wwarning("function texture support has been removed");
1754 return NULL;
1755 } else {
1756 wwarning(_("invalid texture type %s"), val);
1757 return NULL;
1759 return texture;
1762 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1764 static WTexture *texture;
1765 int changed = 0;
1767 again:
1768 if (!WMIsPLArray(value)) {
1769 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1770 if (changed == 0) {
1771 value = entry->plvalue;
1772 changed = 1;
1773 wwarning(_("using default \"%s\" instead"), entry->default_value);
1774 goto again;
1776 return False;
1779 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1780 WMPropList *pl;
1782 pl = WMGetFromPLArray(value, 0);
1783 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1784 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1785 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1786 entry->key, "Solid Texture");
1788 value = entry->plvalue;
1789 changed = 1;
1790 wwarning(_("using default \"%s\" instead"), entry->default_value);
1791 goto again;
1795 texture = parse_texture(scr, value);
1797 if (!texture) {
1798 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1799 if (changed == 0) {
1800 value = entry->plvalue;
1801 changed = 1;
1802 wwarning(_("using default \"%s\" instead"), entry->default_value);
1803 goto again;
1805 return False;
1808 if (ret)
1809 *ret = &texture;
1811 if (addr)
1812 *(WTexture **) addr = texture;
1814 return True;
1817 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1819 WMPropList *elem;
1820 int changed = 0;
1821 char *val;
1822 int nelem;
1824 again:
1825 if (!WMIsPLArray(value)) {
1826 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1827 "WorkspaceBack", "Texture or None");
1828 if (changed == 0) {
1829 value = entry->plvalue;
1830 changed = 1;
1831 wwarning(_("using default \"%s\" instead"), entry->default_value);
1832 goto again;
1834 return False;
1837 /* only do basic error checking and verify for None texture */
1839 nelem = WMGetPropListItemCount(value);
1840 if (nelem > 0) {
1841 elem = WMGetFromPLArray(value, 0);
1842 if (!elem || !WMIsPLString(elem)) {
1843 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1844 if (changed == 0) {
1845 value = entry->plvalue;
1846 changed = 1;
1847 wwarning(_("using default \"%s\" instead"), entry->default_value);
1848 goto again;
1850 return False;
1852 val = WMGetFromPLString(elem);
1854 if (strcasecmp(val, "None") == 0)
1855 return True;
1857 *ret = WMRetainPropList(value);
1859 return True;
1862 static int
1863 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1865 WMPropList *elem;
1866 int nelem;
1867 int changed = 0;
1869 again:
1870 if (!WMIsPLArray(value)) {
1871 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1872 "WorkspaceSpecificBack", "an array of textures");
1873 if (changed == 0) {
1874 value = entry->plvalue;
1875 changed = 1;
1876 wwarning(_("using default \"%s\" instead"), entry->default_value);
1877 goto again;
1879 return False;
1882 /* only do basic error checking and verify for None texture */
1884 nelem = WMGetPropListItemCount(value);
1885 if (nelem > 0) {
1886 while (nelem--) {
1887 elem = WMGetFromPLArray(value, nelem);
1888 if (!elem || !WMIsPLArray(elem)) {
1889 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1890 nelem);
1895 *ret = WMRetainPropList(value);
1897 #ifdef notworking
1899 * Kluge to force wmsetbg helper to set the default background.
1900 * If the WorkspaceSpecificBack is changed once wmaker has started,
1901 * the WorkspaceBack won't be sent to the helper, unless the user
1902 * changes it's value too. So, we must force this by removing the
1903 * value from the defaults DB.
1905 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1906 WMPropList *key = WMCreatePLString("WorkspaceBack");
1908 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1910 WMReleasePropList(key);
1912 #endif
1913 return True;
1916 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1918 static WMFont *font;
1919 char *val;
1921 GET_STRING_OR_DEFAULT("Font", val);
1923 font = WMCreateFont(scr->wmscreen, val);
1924 if (!font)
1925 font = WMCreateFont(scr->wmscreen, "fixed");
1927 if (!font) {
1928 wfatal(_("could not load any usable font!!!"));
1929 exit(1);
1932 if (ret)
1933 *ret = font;
1935 /* can't assign font value outside update function */
1936 wassertrv(addr == NULL, True);
1938 return True;
1941 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1943 static XColor color;
1944 char *val;
1945 int second_pass = 0;
1947 GET_STRING_OR_DEFAULT("Color", val);
1949 again:
1950 if (!wGetColor(scr, val, &color)) {
1951 wwarning(_("could not get color for key \"%s\""), entry->key);
1952 if (second_pass == 0) {
1953 val = WMGetFromPLString(entry->plvalue);
1954 second_pass = 1;
1955 wwarning(_("using default \"%s\" instead"), val);
1956 goto again;
1958 return False;
1961 if (ret)
1962 *ret = &color;
1964 assert(addr == NULL);
1966 if (addr)
1967 *(unsigned long*)addr = pixel;
1970 return True;
1973 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1975 static WShortKey shortcut;
1976 KeySym ksym;
1977 char *val;
1978 char *k;
1979 char buf[MAX_SHORTCUT_LENGTH], *b;
1981 GET_STRING_OR_DEFAULT("Key spec", val);
1983 if (!val || strcasecmp(val, "NONE") == 0) {
1984 shortcut.keycode = 0;
1985 shortcut.modifier = 0;
1986 if (ret)
1987 *ret = &shortcut;
1988 return True;
1991 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
1993 b = (char *)buf;
1995 /* get modifiers */
1996 shortcut.modifier = 0;
1997 while ((k = strchr(b, '+')) != NULL) {
1998 int mod;
2000 *k = 0;
2001 mod = wXModifierFromKey(b);
2002 if (mod < 0) {
2003 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2004 return False;
2006 shortcut.modifier |= mod;
2008 b = k + 1;
2011 /* get key */
2012 ksym = XStringToKeysym(b);
2014 if (ksym == NoSymbol) {
2015 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2016 return False;
2019 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2020 if (shortcut.keycode == 0) {
2021 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2022 return False;
2025 if (ret)
2026 *ret = &shortcut;
2028 return True;
2031 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2033 static int mask;
2034 char *str;
2036 GET_STRING_OR_DEFAULT("Modifier Key", str);
2038 if (!str)
2039 return False;
2041 mask = wXModifierFromKey(str);
2042 if (mask < 0) {
2043 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2044 mask = 0;
2045 return False;
2048 if (addr)
2049 *(int *)addr = mask;
2051 if (ret)
2052 *ret = &mask;
2054 return True;
2057 # include <X11/cursorfont.h>
2058 typedef struct {
2059 char *name;
2060 int id;
2061 } WCursorLookup;
2063 #define CURSOR_ID_NONE (XC_num_glyphs)
2065 static WCursorLookup cursor_table[] = {
2066 {"X_cursor", XC_X_cursor},
2067 {"arrow", XC_arrow},
2068 {"based_arrow_down", XC_based_arrow_down},
2069 {"based_arrow_up", XC_based_arrow_up},
2070 {"boat", XC_boat},
2071 {"bogosity", XC_bogosity},
2072 {"bottom_left_corner", XC_bottom_left_corner},
2073 {"bottom_right_corner", XC_bottom_right_corner},
2074 {"bottom_side", XC_bottom_side},
2075 {"bottom_tee", XC_bottom_tee},
2076 {"box_spiral", XC_box_spiral},
2077 {"center_ptr", XC_center_ptr},
2078 {"circle", XC_circle},
2079 {"clock", XC_clock},
2080 {"coffee_mug", XC_coffee_mug},
2081 {"cross", XC_cross},
2082 {"cross_reverse", XC_cross_reverse},
2083 {"crosshair", XC_crosshair},
2084 {"diamond_cross", XC_diamond_cross},
2085 {"dot", XC_dot},
2086 {"dotbox", XC_dotbox},
2087 {"double_arrow", XC_double_arrow},
2088 {"draft_large", XC_draft_large},
2089 {"draft_small", XC_draft_small},
2090 {"draped_box", XC_draped_box},
2091 {"exchange", XC_exchange},
2092 {"fleur", XC_fleur},
2093 {"gobbler", XC_gobbler},
2094 {"gumby", XC_gumby},
2095 {"hand1", XC_hand1},
2096 {"hand2", XC_hand2},
2097 {"heart", XC_heart},
2098 {"icon", XC_icon},
2099 {"iron_cross", XC_iron_cross},
2100 {"left_ptr", XC_left_ptr},
2101 {"left_side", XC_left_side},
2102 {"left_tee", XC_left_tee},
2103 {"leftbutton", XC_leftbutton},
2104 {"ll_angle", XC_ll_angle},
2105 {"lr_angle", XC_lr_angle},
2106 {"man", XC_man},
2107 {"middlebutton", XC_middlebutton},
2108 {"mouse", XC_mouse},
2109 {"pencil", XC_pencil},
2110 {"pirate", XC_pirate},
2111 {"plus", XC_plus},
2112 {"question_arrow", XC_question_arrow},
2113 {"right_ptr", XC_right_ptr},
2114 {"right_side", XC_right_side},
2115 {"right_tee", XC_right_tee},
2116 {"rightbutton", XC_rightbutton},
2117 {"rtl_logo", XC_rtl_logo},
2118 {"sailboat", XC_sailboat},
2119 {"sb_down_arrow", XC_sb_down_arrow},
2120 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2121 {"sb_left_arrow", XC_sb_left_arrow},
2122 {"sb_right_arrow", XC_sb_right_arrow},
2123 {"sb_up_arrow", XC_sb_up_arrow},
2124 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2125 {"shuttle", XC_shuttle},
2126 {"sizing", XC_sizing},
2127 {"spider", XC_spider},
2128 {"spraycan", XC_spraycan},
2129 {"star", XC_star},
2130 {"target", XC_target},
2131 {"tcross", XC_tcross},
2132 {"top_left_arrow", XC_top_left_arrow},
2133 {"top_left_corner", XC_top_left_corner},
2134 {"top_right_corner", XC_top_right_corner},
2135 {"top_side", XC_top_side},
2136 {"top_tee", XC_top_tee},
2137 {"trek", XC_trek},
2138 {"ul_angle", XC_ul_angle},
2139 {"umbrella", XC_umbrella},
2140 {"ur_angle", XC_ur_angle},
2141 {"watch", XC_watch},
2142 {"xterm", XC_xterm},
2143 {NULL, CURSOR_ID_NONE}
2146 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2148 switch (status) {
2149 case BitmapOpenFailed:
2150 wwarning(_("failed to open bitmap file \"%s\""), filename);
2151 break;
2152 case BitmapFileInvalid:
2153 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2154 break;
2155 case BitmapNoMemory:
2156 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2157 break;
2158 case BitmapSuccess:
2159 XFreePixmap(dpy, bitmap);
2160 break;
2165 * (none)
2166 * (builtin, <cursor_name>)
2167 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2169 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2171 WMPropList *elem;
2172 char *val;
2173 int nelem;
2174 int status = 0;
2176 nelem = WMGetPropListItemCount(pl);
2177 if (nelem < 1) {
2178 return (status);
2180 elem = WMGetFromPLArray(pl, 0);
2181 if (!elem || !WMIsPLString(elem)) {
2182 return (status);
2184 val = WMGetFromPLString(elem);
2186 if (strcasecmp(val, "none") == 0) {
2187 status = 1;
2188 *cursor = None;
2189 } else if (strcasecmp(val, "builtin") == 0) {
2190 int i;
2191 int cursor_id = CURSOR_ID_NONE;
2193 if (nelem != 2) {
2194 wwarning(_("bad number of arguments in cursor specification"));
2195 return (status);
2197 elem = WMGetFromPLArray(pl, 1);
2198 if (!elem || !WMIsPLString(elem)) {
2199 return (status);
2201 val = WMGetFromPLString(elem);
2203 for (i = 0; cursor_table[i].name != NULL; i++) {
2204 if (strcasecmp(val, cursor_table[i].name) == 0) {
2205 cursor_id = cursor_table[i].id;
2206 break;
2209 if (CURSOR_ID_NONE == cursor_id) {
2210 wwarning(_("unknown builtin cursor name \"%s\""), val);
2211 } else {
2212 *cursor = XCreateFontCursor(dpy, cursor_id);
2213 status = 1;
2215 } else if (strcasecmp(val, "bitmap") == 0) {
2216 char *bitmap_name;
2217 char *mask_name;
2218 int bitmap_status;
2219 int mask_status;
2220 Pixmap bitmap;
2221 Pixmap mask;
2222 unsigned int w, h;
2223 int x, y;
2224 XColor fg, bg;
2226 if (nelem != 3) {
2227 wwarning(_("bad number of arguments in cursor specification"));
2228 return (status);
2230 elem = WMGetFromPLArray(pl, 1);
2231 if (!elem || !WMIsPLString(elem)) {
2232 return (status);
2234 val = WMGetFromPLString(elem);
2235 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2236 if (!bitmap_name) {
2237 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2238 return (status);
2240 elem = WMGetFromPLArray(pl, 2);
2241 if (!elem || !WMIsPLString(elem)) {
2242 wfree(bitmap_name);
2243 return (status);
2245 val = WMGetFromPLString(elem);
2246 mask_name = FindImage(wPreferences.pixmap_path, val);
2247 if (!mask_name) {
2248 wfree(bitmap_name);
2249 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2250 return (status);
2252 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2253 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2254 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2255 fg.pixel = scr->black_pixel;
2256 bg.pixel = scr->white_pixel;
2257 XQueryColor(dpy, scr->w_colormap, &fg);
2258 XQueryColor(dpy, scr->w_colormap, &bg);
2259 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2260 status = 1;
2262 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2263 check_bitmap_status(mask_status, mask_name, mask);
2264 wfree(bitmap_name);
2265 wfree(mask_name);
2267 return (status);
2270 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2272 static Cursor cursor;
2273 int status;
2274 int changed = 0;
2276 again:
2277 if (!WMIsPLArray(value)) {
2278 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2279 entry->key, "cursor specification");
2280 if (!changed) {
2281 value = entry->plvalue;
2282 changed = 1;
2283 wwarning(_("using default \"%s\" instead"), entry->default_value);
2284 goto again;
2286 return (False);
2288 status = parse_cursor(scr, value, &cursor);
2289 if (!status) {
2290 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2291 if (!changed) {
2292 value = entry->plvalue;
2293 changed = 1;
2294 wwarning(_("using default \"%s\" instead"), entry->default_value);
2295 goto again;
2297 return (False);
2299 if (ret) {
2300 *ret = &cursor;
2302 if (addr) {
2303 *(Cursor *) addr = cursor;
2305 return (True);
2308 #undef CURSOR_ID_NONE
2310 /* ---------------- value setting functions --------------- */
2311 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2313 return REFRESH_WINDOW_TITLE_COLOR;
2316 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2318 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2321 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2323 switch (which) {
2324 case WM_DOCK:
2325 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2326 break;
2327 case WM_CLIP:
2328 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2329 break;
2330 default:
2331 break;
2333 return 0;
2336 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2338 if (scr->workspaces) {
2339 wWorkspaceForceChange(scr, scr->current_workspace);
2340 wArrangeIcons(scr, False);
2342 return 0;
2345 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2347 Pixmap pixmap;
2348 RImage *img;
2349 int reset = 0;
2351 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2352 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2353 ? WREL_ICON : WREL_FLAT);
2354 if (!img) {
2355 wwarning(_("could not render texture for icon background"));
2356 if (!entry->addr)
2357 wTextureDestroy(scr, *texture);
2358 return 0;
2360 RConvertImage(scr->rcontext, img, &pixmap);
2362 if (scr->icon_tile) {
2363 reset = 1;
2364 RReleaseImage(scr->icon_tile);
2365 XFreePixmap(dpy, scr->icon_tile_pixmap);
2368 scr->icon_tile = img;
2370 /* put the icon in the noticeboard hint */
2371 PropSetIconTileHint(scr, img);
2373 if (!wPreferences.flags.noclip) {
2374 if (scr->clip_tile) {
2375 RReleaseImage(scr->clip_tile);
2377 scr->clip_tile = wClipMakeTile(scr, img);
2380 scr->icon_tile_pixmap = pixmap;
2382 if (scr->def_icon_pixmap) {
2383 XFreePixmap(dpy, scr->def_icon_pixmap);
2384 scr->def_icon_pixmap = None;
2386 if (scr->def_ticon_pixmap) {
2387 XFreePixmap(dpy, scr->def_ticon_pixmap);
2388 scr->def_ticon_pixmap = None;
2391 if (scr->icon_back_texture) {
2392 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2394 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2396 if (scr->clip_balloon)
2397 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2400 * Free the texture as nobody else will use it, nor refer to it.
2402 if (!entry->addr)
2403 wTextureDestroy(scr, *texture);
2405 return (reset ? REFRESH_ICON_TILE : 0);
2408 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2410 if (scr->title_font) {
2411 WMReleaseFont(scr->title_font);
2413 scr->title_font = font;
2415 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2418 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2420 if (scr->menu_title_font) {
2421 WMReleaseFont(scr->menu_title_font);
2424 scr->menu_title_font = font;
2426 return REFRESH_MENU_TITLE_FONT;
2429 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2431 if (scr->menu_entry_font) {
2432 WMReleaseFont(scr->menu_entry_font);
2434 scr->menu_entry_font = font;
2436 return REFRESH_MENU_FONT;
2439 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2441 if (scr->icon_title_font) {
2442 WMReleaseFont(scr->icon_title_font);
2445 scr->icon_title_font = font;
2447 return REFRESH_ICON_FONT;
2450 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2452 if (scr->clip_title_font) {
2453 WMReleaseFont(scr->clip_title_font);
2456 scr->clip_title_font = font;
2458 return REFRESH_ICON_FONT;
2461 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2463 if (scr->workspace_name_font) {
2464 WMReleaseFont(scr->workspace_name_font);
2467 scr->workspace_name_font = font;
2469 return 0;
2472 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2474 if (scr->select_color)
2475 WMReleaseColor(scr->select_color);
2477 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2479 wFreeColor(scr, color->pixel);
2481 return REFRESH_MENU_COLOR;
2484 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2486 if (scr->select_text_color)
2487 WMReleaseColor(scr->select_text_color);
2489 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2491 wFreeColor(scr, color->pixel);
2493 return REFRESH_MENU_COLOR;
2496 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2498 if (scr->clip_title_color[widx])
2499 WMReleaseColor(scr->clip_title_color[widx]);
2501 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2502 wFreeColor(scr, color->pixel);
2504 return REFRESH_ICON_TITLE_COLOR;
2507 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2509 if (scr->window_title_color[widx])
2510 WMReleaseColor(scr->window_title_color[widx]);
2512 scr->window_title_color[widx] =
2513 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2515 wFreeColor(scr, color->pixel);
2517 return REFRESH_WINDOW_TITLE_COLOR;
2520 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2522 if (scr->menu_title_color[0])
2523 WMReleaseColor(scr->menu_title_color[0]);
2525 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2527 wFreeColor(scr, color->pixel);
2529 return REFRESH_MENU_TITLE_COLOR;
2532 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2534 if (scr->mtext_color)
2535 WMReleaseColor(scr->mtext_color);
2537 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2539 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2540 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2541 } else {
2542 WMSetColorAlpha(scr->dtext_color, 0xffff);
2545 wFreeColor(scr, color->pixel);
2547 return REFRESH_MENU_COLOR;
2550 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2552 if (scr->dtext_color)
2553 WMReleaseColor(scr->dtext_color);
2555 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2557 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2558 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2559 } else {
2560 WMSetColorAlpha(scr->dtext_color, 0xffff);
2563 wFreeColor(scr, color->pixel);
2565 return REFRESH_MENU_COLOR;
2568 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2570 if (scr->icon_title_color)
2571 WMReleaseColor(scr->icon_title_color);
2572 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2574 wFreeColor(scr, color->pixel);
2576 return REFRESH_ICON_TITLE_COLOR;
2579 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2581 if (scr->icon_title_texture) {
2582 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2584 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2586 return REFRESH_ICON_TITLE_BACK;
2589 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2591 close(scr->helper_fd);
2592 scr->helper_fd = 0;
2593 scr->helper_pid = 0;
2594 scr->flags.backimage_helper_launched = 0;
2597 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2599 WMPropList *val;
2600 char *str;
2601 int i;
2603 if (scr->flags.backimage_helper_launched) {
2604 if (WMGetPropListItemCount(value) == 0) {
2605 SendHelperMessage(scr, 'C', 0, NULL);
2606 SendHelperMessage(scr, 'K', 0, NULL);
2608 WMReleasePropList(value);
2609 return 0;
2611 } else {
2612 pid_t pid;
2613 int filedes[2];
2615 if (WMGetPropListItemCount(value) == 0)
2616 return 0;
2618 if (pipe(filedes) < 0) {
2619 werror("pipe() failed:can't set workspace specific background image");
2621 WMReleasePropList(value);
2622 return 0;
2625 pid = fork();
2626 if (pid < 0) {
2627 werror("fork() failed:can't set workspace specific background image");
2628 if (close(filedes[0]) < 0)
2629 werror("could not close pipe");
2630 if (close(filedes[1]) < 0)
2631 werror("could not close pipe");
2633 } else if (pid == 0) {
2634 char *dither;
2636 SetupEnvironment(scr);
2638 if (close(0) < 0)
2639 werror("could not close pipe");
2640 if (dup(filedes[0]) < 0) {
2641 werror("dup() failed:can't set workspace specific background image");
2643 dither = wPreferences.no_dithering ? "-m" : "-d";
2644 if (wPreferences.smooth_workspace_back)
2645 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2646 else
2647 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2648 werror("could not execute wmsetbg");
2649 exit(1);
2650 } else {
2652 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2653 werror("error setting close-on-exec flag");
2655 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2656 werror("error setting close-on-exec flag");
2659 scr->helper_fd = filedes[1];
2660 scr->helper_pid = pid;
2661 scr->flags.backimage_helper_launched = 1;
2663 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2665 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2670 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2671 val = WMGetFromPLArray(value, i);
2672 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2673 str = WMGetPropListDescription(val, False);
2675 SendHelperMessage(scr, 'S', i + 1, str);
2677 wfree(str);
2678 } else {
2679 SendHelperMessage(scr, 'U', i + 1, NULL);
2682 sleep(1);
2684 WMReleasePropList(value);
2685 return 0;
2688 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2690 if (scr->flags.backimage_helper_launched) {
2691 char *str;
2693 if (WMGetPropListItemCount(value) == 0) {
2694 SendHelperMessage(scr, 'U', 0, NULL);
2695 } else {
2696 /* set the default workspace background to this one */
2697 str = WMGetPropListDescription(value, False);
2698 if (str) {
2699 SendHelperMessage(scr, 'S', 0, str);
2700 wfree(str);
2701 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2702 } else {
2703 SendHelperMessage(scr, 'U', 0, NULL);
2706 } else if (WMGetPropListItemCount(value) > 0) {
2707 char *command;
2708 char *text;
2709 char *dither;
2710 int len;
2712 text = WMGetPropListDescription(value, False);
2713 len = strlen(text) + 40;
2714 command = wmalloc(len);
2715 dither = wPreferences.no_dithering ? "-m" : "-d";
2716 if (wPreferences.smooth_workspace_back)
2717 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2718 else
2719 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2720 wfree(text);
2721 ExecuteShellCommand(scr, command);
2722 wfree(command);
2724 WMReleasePropList(value);
2726 return 0;
2729 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2731 if (scr->widget_texture) {
2732 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2734 scr->widget_texture = *(WTexSolid **) texture;
2736 return 0;
2739 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2741 if (scr->window_title_texture[WS_FOCUSED]) {
2742 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2744 scr->window_title_texture[WS_FOCUSED] = *texture;
2746 return REFRESH_WINDOW_TEXTURES;
2749 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2751 if (scr->window_title_texture[WS_PFOCUSED]) {
2752 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2754 scr->window_title_texture[WS_PFOCUSED] = *texture;
2756 return REFRESH_WINDOW_TEXTURES;
2759 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2761 if (scr->window_title_texture[WS_UNFOCUSED]) {
2762 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2764 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2766 return REFRESH_WINDOW_TEXTURES;
2769 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2771 if (scr->resizebar_texture[0]) {
2772 wTextureDestroy(scr, scr->resizebar_texture[0]);
2774 scr->resizebar_texture[0] = *texture;
2776 return REFRESH_WINDOW_TEXTURES;
2779 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2781 if (scr->menu_title_texture[0]) {
2782 wTextureDestroy(scr, scr->menu_title_texture[0]);
2784 scr->menu_title_texture[0] = *texture;
2786 return REFRESH_MENU_TITLE_TEXTURE;
2789 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2791 if (scr->menu_item_texture) {
2792 wTextureDestroy(scr, scr->menu_item_texture);
2793 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2795 scr->menu_item_texture = *texture;
2797 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2799 return REFRESH_MENU_TEXTURE;
2802 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2804 WWindow *wwin;
2805 wKeyBindings[widx] = *shortcut;
2807 wwin = scr->focused_window;
2809 while (wwin != NULL) {
2810 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2812 if (!WFLAGP(wwin, no_bind_keys)) {
2813 wWindowSetKeyGrabs(wwin);
2815 wwin = wwin->prev;
2818 return 0;
2821 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2823 wScreenUpdateUsableArea(scr);
2824 wArrangeIcons(scr, True);
2826 return 0;
2829 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2831 wScreenUpdateUsableArea(scr);
2833 return 0;
2836 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2838 return REFRESH_MENU_TEXTURE;
2841 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2843 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2845 RCopyArea(img, image, x, y, w, h, 0, 0);
2847 return img;
2850 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2852 char *path;
2853 RImage *bgimage;
2854 int cwidth, cheight;
2855 WPreferences *prefs = (WPreferences *) foo;
2857 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2858 if (prefs->swtileImage)
2859 RReleaseImage(prefs->swtileImage);
2860 prefs->swtileImage = NULL;
2862 WMReleasePropList(array);
2863 return 0;
2866 switch (WMGetPropListItemCount(array)) {
2867 case 4:
2868 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2869 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2870 break;
2871 } else
2872 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2874 if (!path) {
2875 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2876 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2877 } else {
2878 bgimage = RLoadImage(scr->rcontext, path, 0);
2879 if (!bgimage) {
2880 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2881 wfree(path);
2882 } else {
2883 wfree(path);
2885 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2886 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2888 if (cwidth <= 0 || cheight <= 0 ||
2889 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2890 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2891 else {
2892 int i;
2893 int swidth, theight;
2894 for (i = 0; i < 9; i++) {
2895 if (prefs->swbackImage[i])
2896 RReleaseImage(prefs->swbackImage[i]);
2897 prefs->swbackImage[i] = NULL;
2899 swidth = (bgimage->width - cwidth) / 2;
2900 theight = (bgimage->height - cheight) / 2;
2902 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2903 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2904 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2905 swidth, theight);
2907 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2908 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2909 cwidth, cheight);
2910 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2911 swidth, cheight);
2913 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2914 swidth, theight);
2915 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2916 cwidth, theight);
2917 prefs->swbackImage[8] =
2918 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2919 theight);
2921 // check if anything failed
2922 for (i = 0; i < 9; i++) {
2923 if (!prefs->swbackImage[i]) {
2924 for (; i >= 0; --i) {
2925 RReleaseImage(prefs->swbackImage[i]);
2926 prefs->swbackImage[i] = NULL;
2928 break;
2932 RReleaseImage(bgimage);
2936 case 1:
2937 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
2938 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2939 break;
2940 } else
2941 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
2943 if (!path) {
2944 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2945 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
2946 } else {
2947 if (prefs->swtileImage)
2948 RReleaseImage(prefs->swtileImage);
2950 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
2951 if (!prefs->swtileImage) {
2952 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2954 wfree(path);
2956 break;
2958 default:
2959 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
2960 break;
2963 WMReleasePropList(array);
2965 return 0;
2968 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2970 int i;
2971 WPreferences *prefs = (WPreferences *) foo;
2973 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
2974 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
2975 WMReleasePropList(array);
2976 return 0;
2979 DestroyWindowMenu(scr);
2981 for (i = 0; i < 7; i++) {
2982 if (prefs->modifier_labels[i])
2983 wfree(prefs->modifier_labels[i]);
2985 if (WMIsPLString(WMGetFromPLArray(array, i))) {
2986 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
2987 } else {
2988 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
2989 prefs->modifier_labels[i] = NULL;
2993 WMReleasePropList(array);
2995 return 0;
2999 * Very ugly kluge.
3000 * Need access to the double click variables, so that all widgets in
3001 * wmaker panels will have the same dbl-click values.
3002 * TODO: figure a better way of dealing with it.
3004 #include <WINGs/WINGsP.h>
3006 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3008 extern _WINGsConfiguration WINGsConfiguration;
3010 if (*value <= 0)
3011 *(int *)foo = 1;
3013 WINGsConfiguration.doubleClickDelay = *value;
3015 return 0;
3018 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3020 if (wCursor[widx] != None) {
3021 XFreeCursor(dpy, wCursor[widx]);
3024 wCursor[widx] = *cursor;
3026 if (widx == WCUR_ROOT && *cursor != None) {
3027 XDefineCursor(dpy, scr->root_win, *cursor);
3030 return 0;