Remove unused functions
[wmaker-crm.git] / src / defaults.c
blob793d1d5150ba6ecf4d840465e1726aee6c27481b
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 #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 path[PATH_MAX];
808 char *the_path;
809 WMPropList *shared_dict = NULL;
811 if (!inited) {
812 inited = 1;
813 initDefaults();
816 db = wmalloc(sizeof(WDDomain));
817 memset(db, 0, sizeof(WDDomain));
818 db->domain_name = domain;
819 db->path = wdefaultspathfordomain(domain);
820 the_path = db->path;
822 if (the_path && stat(the_path, &stbuf) >= 0) {
823 db->dictionary = WMReadPropListFromFile(the_path);
824 if (db->dictionary) {
825 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
826 WMReleasePropList(db->dictionary);
827 db->dictionary = NULL;
828 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
830 db->timestamp = stbuf.st_mtime;
831 } else {
832 wwarning(_("could not load domain %s from user defaults database"), domain);
836 /* global system dictionary */
837 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
838 if (stat(path, &stbuf) >= 0) {
839 shared_dict = WMReadPropListFromFile(path);
840 if (shared_dict) {
841 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
842 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
843 domain, path);
844 WMReleasePropList(shared_dict);
845 shared_dict = NULL;
846 } else {
847 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
848 WMIsPLDictionary(db->dictionary)) {
849 WMMergePLDictionaries(shared_dict, db->dictionary, True);
850 WMReleasePropList(db->dictionary);
851 db->dictionary = shared_dict;
852 if (stbuf.st_mtime > db->timestamp)
853 db->timestamp = stbuf.st_mtime;
854 } else if (!db->dictionary) {
855 db->dictionary = shared_dict;
856 if (stbuf.st_mtime > db->timestamp)
857 db->timestamp = stbuf.st_mtime;
860 } else {
861 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
865 return db;
868 void wReadStaticDefaults(WMPropList * dict)
870 WMPropList *plvalue;
871 WDefaultEntry *entry;
872 unsigned int i;
873 void *tdata;
875 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
876 entry = &staticOptionList[i];
878 if (dict)
879 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
880 else
881 plvalue = NULL;
883 if (!plvalue) {
884 /* no default in the DB. Use builtin default */
885 plvalue = entry->plvalue;
888 if (plvalue) {
889 /* convert data */
890 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
891 if (entry->update) {
892 (*entry->update) (NULL, entry, tdata, entry->extra_data);
898 void wDefaultsCheckDomains(void* arg)
900 WScreen *scr;
901 struct stat stbuf;
902 WMPropList *shared_dict = NULL;
903 WMPropList *dict;
904 int i;
906 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
907 WDWindowMaker->timestamp = stbuf.st_mtime;
909 /* global dictionary */
910 shared_dict = readGlobalDomain("WindowMaker", True);
911 /* user dictionary */
912 dict = WMReadPropListFromFile(WDWindowMaker->path);
913 if (dict) {
914 if (!WMIsPLDictionary(dict)) {
915 WMReleasePropList(dict);
916 dict = NULL;
917 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
918 "WindowMaker", WDWindowMaker->path);
919 } else {
920 if (shared_dict) {
921 WMMergePLDictionaries(shared_dict, dict, True);
922 WMReleasePropList(dict);
923 dict = shared_dict;
924 shared_dict = NULL;
926 for (i = 0; i < wScreenCount; i++) {
927 scr = wScreenWithNumber(i);
928 if (scr)
929 wReadDefaults(scr, dict);
931 if (WDWindowMaker->dictionary) {
932 WMReleasePropList(WDWindowMaker->dictionary);
934 WDWindowMaker->dictionary = dict;
936 } else {
937 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
939 if (shared_dict) {
940 WMReleasePropList(shared_dict);
944 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
945 /* global dictionary */
946 shared_dict = readGlobalDomain("WMWindowAttributes", True);
947 /* user dictionary */
948 dict = WMReadPropListFromFile(WDWindowAttributes->path);
949 if (dict) {
950 if (!WMIsPLDictionary(dict)) {
951 WMReleasePropList(dict);
952 dict = NULL;
953 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
954 "WMWindowAttributes", WDWindowAttributes->path);
955 } else {
956 if (shared_dict) {
957 WMMergePLDictionaries(shared_dict, dict, True);
958 WMReleasePropList(dict);
959 dict = shared_dict;
960 shared_dict = NULL;
962 if (WDWindowAttributes->dictionary) {
963 WMReleasePropList(WDWindowAttributes->dictionary);
965 WDWindowAttributes->dictionary = dict;
966 for (i = 0; i < wScreenCount; i++) {
967 scr = wScreenWithNumber(i);
968 if (scr) {
969 RImage *image;
971 wDefaultUpdateIcons(scr);
973 /* Update the panel image if changed */
974 /* Don't worry. If the image is the same these
975 * functions will have no performance impact. */
976 image = wDefaultGetImage(scr, "Logo", "WMPanel", wPreferences.icon_size);
978 if (!image) {
979 wwarning(_("could not load logo image for panels: %s"),
980 RMessageForError(RErrorCode));
981 } else {
982 WMSetApplicationIconImage(scr->wmscreen, image);
983 RReleaseImage(image);
988 } else {
989 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
991 WDWindowAttributes->timestamp = stbuf.st_mtime;
992 if (shared_dict) {
993 WMReleasePropList(shared_dict);
997 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
998 dict = WMReadPropListFromFile(WDRootMenu->path);
999 if (dict) {
1000 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1001 WMReleasePropList(dict);
1002 dict = NULL;
1003 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1004 "WMRootMenu", WDRootMenu->path);
1005 } else {
1006 if (WDRootMenu->dictionary) {
1007 WMReleasePropList(WDRootMenu->dictionary);
1009 WDRootMenu->dictionary = dict;
1010 wDefaultsMergeGlobalMenus(WDRootMenu);
1011 scr = wScreenWithNumber(0);
1012 configureMenu(scr, dict, True);
1013 rebind_key_grabs(scr);
1015 } else {
1016 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1018 WDRootMenu->timestamp = stbuf.st_mtime;
1020 #ifndef HAVE_INOTIFY
1021 if (!arg)
1022 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1023 #endif
1026 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1028 WMPropList *plvalue, *old_value;
1029 WDefaultEntry *entry;
1030 unsigned int i;
1031 int update_workspace_back = 0; /* kluge :/ */
1032 unsigned int needs_refresh;
1033 void *tdata;
1034 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1036 needs_refresh = 0;
1038 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1039 entry = &optionList[i];
1041 if (new_dict)
1042 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1043 else
1044 plvalue = NULL;
1046 if (!old_dict)
1047 old_value = NULL;
1048 else
1049 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1051 if (!plvalue && !old_value) {
1052 /* no default in the DB. Use builtin default */
1053 plvalue = entry->plvalue;
1054 if (plvalue && new_dict) {
1055 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1057 } else if (!plvalue) {
1058 /* value was deleted from DB. Keep current value */
1059 continue;
1060 } else if (!old_value) {
1061 /* set value for the 1st time */
1062 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1063 /* value has changed */
1064 } else {
1066 if (strcmp(entry->key, "WorkspaceBack") == 0
1067 && update_workspace_back && scr->flags.backimage_helper_launched) {
1068 } else {
1069 /* value was not changed since last time */
1070 continue;
1074 if (plvalue) {
1075 /* convert data */
1076 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1078 * If the WorkspaceSpecificBack data has been changed
1079 * so that the helper will be launched now, we must be
1080 * sure to send the default background texture config
1081 * to the helper.
1083 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1084 && !scr->flags.backimage_helper_launched) {
1085 update_workspace_back = 1;
1087 if (entry->update) {
1088 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1094 if (needs_refresh != 0 && !scr->flags.startup) {
1095 int foo;
1097 foo = 0;
1098 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1099 foo |= WTextureSettings;
1100 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1101 foo |= WFontSettings;
1102 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1103 foo |= WColorSettings;
1104 if (foo)
1105 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1106 (void *)(uintptr_t) foo);
1108 foo = 0;
1109 if (needs_refresh & REFRESH_MENU_TEXTURE)
1110 foo |= WTextureSettings;
1111 if (needs_refresh & REFRESH_MENU_FONT)
1112 foo |= WFontSettings;
1113 if (needs_refresh & REFRESH_MENU_COLOR)
1114 foo |= WColorSettings;
1115 if (foo)
1116 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1118 foo = 0;
1119 if (needs_refresh & REFRESH_WINDOW_FONT) {
1120 foo |= WFontSettings;
1122 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1123 foo |= WTextureSettings;
1125 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1126 foo |= WColorSettings;
1128 if (foo)
1129 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1131 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1132 foo = 0;
1133 if (needs_refresh & REFRESH_ICON_FONT) {
1134 foo |= WFontSettings;
1136 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1137 foo |= WTextureSettings;
1139 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1140 foo |= WTextureSettings;
1142 if (foo)
1143 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1144 (void *)(uintptr_t) foo);
1146 if (needs_refresh & REFRESH_ICON_TILE)
1147 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1151 void wDefaultUpdateIcons(WScreen * scr)
1153 WAppIcon *aicon = scr->app_icon_list;
1154 WWindow *wwin = scr->focused_window;
1155 char *file;
1157 while (aicon) {
1158 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1159 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1160 || (file && !aicon->icon->file)) {
1161 wIconChangeImageFile(aicon->icon, file);
1162 wAppIconPaint(aicon);
1164 aicon = aicon->next;
1167 if (!wPreferences.flags.noclip)
1168 wClipIconPaint(scr->clip_icon);
1170 while (wwin) {
1171 if (wwin->icon && wwin->flags.miniaturized) {
1172 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1173 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1174 || (file && !wwin->icon->file)) {
1175 wIconChangeImageFile(wwin->icon, file);
1178 wwin = wwin->prev;
1182 /* --------------------------- Local ----------------------- */
1184 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1185 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1186 entry->key, x); \
1187 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1188 var = entry->default_value;\
1189 } else var = WMGetFromPLString(value)\
1192 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1194 char *str;
1195 WOptionEnumeration *v;
1196 char buffer[TOTAL_VALUES_LENGTH];
1198 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1199 for (v = values; v->string != NULL; v++) {
1200 if (strcasecmp(v->string, str) == 0)
1201 return v->value;
1205 buffer[0] = 0;
1206 for (v = values; v->string != NULL; v++) {
1207 if (!v->is_alias) {
1208 if (buffer[0] != 0)
1209 strcat(buffer, ", ");
1210 snprintf(buffer+strlen(buffer),
1211 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1214 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1215 WMGetFromPLString(key),
1216 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1217 buffer);
1219 if (def) {
1220 return string2index(key, val, NULL, values);
1223 return -1;
1227 * value - is the value in the defaults DB
1228 * addr - is the address to store the data
1229 * ret - is the address to store a pointer to a temporary buffer. ret
1230 * must not be freed and is used by the set functions
1232 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1234 static char data;
1235 char *val;
1236 int second_pass = 0;
1238 GET_STRING_OR_DEFAULT("Boolean", val);
1240 again:
1241 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1242 || strcasecmp(val, "YES") == 0) {
1244 data = 1;
1245 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1246 || strcasecmp(val, "NO") == 0) {
1247 data = 0;
1248 } else {
1249 int i;
1250 if (sscanf(val, "%i", &i) == 1) {
1251 if (i != 0)
1252 data = 1;
1253 else
1254 data = 0;
1255 } else {
1256 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1257 if (second_pass == 0) {
1258 val = WMGetFromPLString(entry->plvalue);
1259 second_pass = 1;
1260 wwarning(_("using default \"%s\" instead"), val);
1261 goto again;
1263 return False;
1267 if (ret)
1268 *ret = &data;
1269 if (addr)
1270 *(char *)addr = data;
1272 return True;
1275 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1277 static int data;
1278 char *val;
1280 GET_STRING_OR_DEFAULT("Integer", val);
1282 if (sscanf(val, "%i", &data) != 1) {
1283 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1284 val = WMGetFromPLString(entry->plvalue);
1285 wwarning(_("using default \"%s\" instead"), val);
1286 if (sscanf(val, "%i", &data) != 1) {
1287 return False;
1291 if (ret)
1292 *ret = &data;
1293 if (addr)
1294 *(int *)addr = data;
1296 return True;
1299 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1301 static WCoord data;
1302 char *val_x, *val_y;
1303 int nelem, changed = 0;
1304 WMPropList *elem_x, *elem_y;
1306 again:
1307 if (!WMIsPLArray(value)) {
1308 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1309 if (changed == 0) {
1310 value = entry->plvalue;
1311 changed = 1;
1312 wwarning(_("using default \"%s\" instead"), entry->default_value);
1313 goto again;
1315 return False;
1318 nelem = WMGetPropListItemCount(value);
1319 if (nelem != 2) {
1320 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1321 if (changed == 0) {
1322 value = entry->plvalue;
1323 changed = 1;
1324 wwarning(_("using default \"%s\" instead"), entry->default_value);
1325 goto again;
1327 return False;
1330 elem_x = WMGetFromPLArray(value, 0);
1331 elem_y = WMGetFromPLArray(value, 1);
1333 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1334 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1335 if (changed == 0) {
1336 value = entry->plvalue;
1337 changed = 1;
1338 wwarning(_("using default \"%s\" instead"), entry->default_value);
1339 goto again;
1341 return False;
1344 val_x = WMGetFromPLString(elem_x);
1345 val_y = WMGetFromPLString(elem_y);
1347 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1348 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1349 if (changed == 0) {
1350 value = entry->plvalue;
1351 changed = 1;
1352 wwarning(_("using default \"%s\" instead"), entry->default_value);
1353 goto again;
1355 return False;
1358 if (data.x < 0)
1359 data.x = 0;
1360 else if (data.x > scr->scr_width / 3)
1361 data.x = scr->scr_width / 3;
1362 if (data.y < 0)
1363 data.y = 0;
1364 else if (data.y > scr->scr_height / 3)
1365 data.y = scr->scr_height / 3;
1367 if (ret)
1368 *ret = &data;
1369 if (addr)
1370 *(WCoord *) addr = data;
1372 return True;
1375 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1377 WMRetainPropList(value);
1379 *ret = value;
1381 return True;
1384 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1386 static char *data;
1387 int i, count, len;
1388 char *ptr;
1389 WMPropList *d;
1390 int changed = 0;
1392 again:
1393 if (!WMIsPLArray(value)) {
1394 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1395 if (changed == 0) {
1396 value = entry->plvalue;
1397 changed = 1;
1398 wwarning(_("using default \"%s\" instead"), entry->default_value);
1399 goto again;
1401 return False;
1404 i = 0;
1405 count = WMGetPropListItemCount(value);
1406 if (count < 1) {
1407 if (changed == 0) {
1408 value = entry->plvalue;
1409 changed = 1;
1410 wwarning(_("using default \"%s\" instead"), entry->default_value);
1411 goto again;
1413 return False;
1416 len = 0;
1417 for (i = 0; i < count; i++) {
1418 d = WMGetFromPLArray(value, i);
1419 if (!d || !WMIsPLString(d)) {
1420 count = i;
1421 break;
1423 len += strlen(WMGetFromPLString(d)) + 1;
1426 ptr = data = wmalloc(len + 1);
1428 for (i = 0; i < count; i++) {
1429 d = WMGetFromPLArray(value, i);
1430 if (!d || !WMIsPLString(d)) {
1431 break;
1433 strcpy(ptr, WMGetFromPLString(d));
1434 ptr += strlen(WMGetFromPLString(d));
1435 *ptr = ':';
1436 ptr++;
1438 ptr--;
1439 *(ptr--) = 0;
1441 if (*(char **)addr != NULL) {
1442 wfree(*(char **)addr);
1444 *(char **)addr = data;
1446 return True;
1449 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1451 static signed char data;
1453 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1454 if (data < 0)
1455 return False;
1457 if (ret)
1458 *ret = &data;
1459 if (addr)
1460 *(signed char *)addr = data;
1462 return True;
1466 * (solid <color>)
1467 * (hgradient <color> <color>)
1468 * (vgradient <color> <color>)
1469 * (dgradient <color> <color>)
1470 * (mhgradient <color> <color> ...)
1471 * (mvgradient <color> <color> ...)
1472 * (mdgradient <color> <color> ...)
1473 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1474 * (tpixmap <file> <color>)
1475 * (spixmap <file> <color>)
1476 * (cpixmap <file> <color>)
1477 * (thgradient <file> <opaqueness> <color> <color>)
1478 * (tvgradient <file> <opaqueness> <color> <color>)
1479 * (tdgradient <file> <opaqueness> <color> <color>)
1480 * (function <lib> <function> ...)
1483 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1485 WMPropList *elem;
1486 char *val;
1487 int nelem;
1488 WTexture *texture = NULL;
1490 nelem = WMGetPropListItemCount(pl);
1491 if (nelem < 1)
1492 return NULL;
1494 elem = WMGetFromPLArray(pl, 0);
1495 if (!elem || !WMIsPLString(elem))
1496 return NULL;
1497 val = WMGetFromPLString(elem);
1499 if (strcasecmp(val, "solid") == 0) {
1500 XColor color;
1502 if (nelem != 2)
1503 return NULL;
1505 /* get 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, &color)) {
1513 wwarning(_("\"%s\" is not a valid color name"), val);
1514 return NULL;
1517 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1518 } else if (strcasecmp(val, "dgradient") == 0
1519 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1520 RColor color1, color2;
1521 XColor xcolor;
1522 int type;
1524 if (nelem != 3) {
1525 wwarning(_("bad number of arguments in gradient specification"));
1526 return NULL;
1529 if (val[0] == 'd' || val[0] == 'D')
1530 type = WTEX_DGRADIENT;
1531 else if (val[0] == 'h' || val[0] == 'H')
1532 type = WTEX_HGRADIENT;
1533 else
1534 type = WTEX_VGRADIENT;
1536 /* get from color */
1537 elem = WMGetFromPLArray(pl, 1);
1538 if (!elem || !WMIsPLString(elem))
1539 return NULL;
1540 val = WMGetFromPLString(elem);
1542 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1543 wwarning(_("\"%s\" is not a valid color name"), val);
1544 return NULL;
1546 color1.alpha = 255;
1547 color1.red = xcolor.red >> 8;
1548 color1.green = xcolor.green >> 8;
1549 color1.blue = xcolor.blue >> 8;
1551 /* get to color */
1552 elem = WMGetFromPLArray(pl, 2);
1553 if (!elem || !WMIsPLString(elem)) {
1554 return NULL;
1556 val = WMGetFromPLString(elem);
1558 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1559 wwarning(_("\"%s\" is not a valid color name"), val);
1560 return NULL;
1562 color2.alpha = 255;
1563 color2.red = xcolor.red >> 8;
1564 color2.green = xcolor.green >> 8;
1565 color2.blue = xcolor.blue >> 8;
1567 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1569 } else if (strcasecmp(val, "igradient") == 0) {
1570 RColor colors1[2], colors2[2];
1571 int th1, th2;
1572 XColor xcolor;
1573 int i;
1575 if (nelem != 7) {
1576 wwarning(_("bad number of arguments in gradient specification"));
1577 return NULL;
1580 /* get from color */
1581 for (i = 0; i < 2; i++) {
1582 elem = WMGetFromPLArray(pl, 1 + i);
1583 if (!elem || !WMIsPLString(elem))
1584 return NULL;
1585 val = WMGetFromPLString(elem);
1587 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1588 wwarning(_("\"%s\" is not a valid color name"), val);
1589 return NULL;
1591 colors1[i].alpha = 255;
1592 colors1[i].red = xcolor.red >> 8;
1593 colors1[i].green = xcolor.green >> 8;
1594 colors1[i].blue = xcolor.blue >> 8;
1596 elem = WMGetFromPLArray(pl, 3);
1597 if (!elem || !WMIsPLString(elem))
1598 return NULL;
1599 val = WMGetFromPLString(elem);
1600 th1 = atoi(val);
1602 /* get from color */
1603 for (i = 0; i < 2; i++) {
1604 elem = WMGetFromPLArray(pl, 4 + i);
1605 if (!elem || !WMIsPLString(elem))
1606 return NULL;
1607 val = WMGetFromPLString(elem);
1609 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1610 wwarning(_("\"%s\" is not a valid color name"), val);
1611 return NULL;
1613 colors2[i].alpha = 255;
1614 colors2[i].red = xcolor.red >> 8;
1615 colors2[i].green = xcolor.green >> 8;
1616 colors2[i].blue = xcolor.blue >> 8;
1618 elem = WMGetFromPLArray(pl, 6);
1619 if (!elem || !WMIsPLString(elem))
1620 return NULL;
1621 val = WMGetFromPLString(elem);
1622 th2 = atoi(val);
1624 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1626 } else if (strcasecmp(val, "mhgradient") == 0
1627 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1628 XColor color;
1629 RColor **colors;
1630 int i, count;
1631 int type;
1633 if (nelem < 3) {
1634 wwarning(_("too few arguments in multicolor gradient specification"));
1635 return NULL;
1638 if (val[1] == 'h' || val[1] == 'H')
1639 type = WTEX_MHGRADIENT;
1640 else if (val[1] == 'v' || val[1] == 'V')
1641 type = WTEX_MVGRADIENT;
1642 else
1643 type = WTEX_MDGRADIENT;
1645 count = nelem - 1;
1647 colors = wmalloc(sizeof(RColor *) * (count + 1));
1649 for (i = 0; i < count; i++) {
1650 elem = WMGetFromPLArray(pl, i + 1);
1651 if (!elem || !WMIsPLString(elem)) {
1652 for (--i; i >= 0; --i) {
1653 wfree(colors[i]);
1655 wfree(colors);
1656 return NULL;
1658 val = WMGetFromPLString(elem);
1660 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1661 wwarning(_("\"%s\" is not a valid color name"), val);
1662 for (--i; i >= 0; --i) {
1663 wfree(colors[i]);
1665 wfree(colors);
1666 return NULL;
1667 } else {
1668 colors[i] = wmalloc(sizeof(RColor));
1669 colors[i]->red = color.red >> 8;
1670 colors[i]->green = color.green >> 8;
1671 colors[i]->blue = color.blue >> 8;
1674 colors[i] = NULL;
1676 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1677 } else if (strcasecmp(val, "spixmap") == 0 ||
1678 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1679 XColor color;
1680 int type;
1682 if (nelem != 3)
1683 return NULL;
1685 if (val[0] == 's' || val[0] == 'S')
1686 type = WTP_SCALE;
1687 else if (val[0] == 'c' || val[0] == 'C')
1688 type = WTP_CENTER;
1689 else
1690 type = WTP_TILE;
1692 /* get color */
1693 elem = WMGetFromPLArray(pl, 2);
1694 if (!elem || !WMIsPLString(elem)) {
1695 return NULL;
1697 val = WMGetFromPLString(elem);
1699 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1700 wwarning(_("\"%s\" is not a valid color name"), val);
1701 return NULL;
1704 /* file name */
1705 elem = WMGetFromPLArray(pl, 1);
1706 if (!elem || !WMIsPLString(elem))
1707 return NULL;
1708 val = WMGetFromPLString(elem);
1710 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1711 } else if (strcasecmp(val, "thgradient") == 0
1712 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1713 RColor color1, color2;
1714 XColor xcolor;
1715 int opacity;
1716 int style;
1718 if (val[1] == 'h' || val[1] == 'H')
1719 style = WTEX_THGRADIENT;
1720 else if (val[1] == 'v' || val[1] == 'V')
1721 style = WTEX_TVGRADIENT;
1722 else
1723 style = WTEX_TDGRADIENT;
1725 if (nelem != 5) {
1726 wwarning(_("bad number of arguments in textured gradient specification"));
1727 return NULL;
1730 /* get from color */
1731 elem = WMGetFromPLArray(pl, 3);
1732 if (!elem || !WMIsPLString(elem))
1733 return NULL;
1734 val = WMGetFromPLString(elem);
1736 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1737 wwarning(_("\"%s\" is not a valid color name"), val);
1738 return NULL;
1740 color1.alpha = 255;
1741 color1.red = xcolor.red >> 8;
1742 color1.green = xcolor.green >> 8;
1743 color1.blue = xcolor.blue >> 8;
1745 /* get to color */
1746 elem = WMGetFromPLArray(pl, 4);
1747 if (!elem || !WMIsPLString(elem)) {
1748 return NULL;
1750 val = WMGetFromPLString(elem);
1752 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1753 wwarning(_("\"%s\" is not a valid color name"), val);
1754 return NULL;
1756 color2.alpha = 255;
1757 color2.red = xcolor.red >> 8;
1758 color2.green = xcolor.green >> 8;
1759 color2.blue = xcolor.blue >> 8;
1761 /* get opacity */
1762 elem = WMGetFromPLArray(pl, 2);
1763 if (!elem || !WMIsPLString(elem))
1764 opacity = 128;
1765 else
1766 val = WMGetFromPLString(elem);
1768 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1769 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1770 opacity = 128;
1773 /* get file name */
1774 elem = WMGetFromPLArray(pl, 1);
1775 if (!elem || !WMIsPLString(elem))
1776 return NULL;
1777 val = WMGetFromPLString(elem);
1779 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1780 } else if (strcasecmp(val, "function") == 0) {
1781 /* Leave this in to handle the unlikely case of
1782 * someone actually having function textures configured */
1783 wwarning("function texture support has been removed");
1784 return NULL;
1785 } else {
1786 wwarning(_("invalid texture type %s"), val);
1787 return NULL;
1789 return texture;
1792 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1794 static WTexture *texture;
1795 int changed = 0;
1797 again:
1798 if (!WMIsPLArray(value)) {
1799 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1800 if (changed == 0) {
1801 value = entry->plvalue;
1802 changed = 1;
1803 wwarning(_("using default \"%s\" instead"), entry->default_value);
1804 goto again;
1806 return False;
1809 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1810 WMPropList *pl;
1812 pl = WMGetFromPLArray(value, 0);
1813 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1814 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1815 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1816 entry->key, "Solid Texture");
1818 value = entry->plvalue;
1819 changed = 1;
1820 wwarning(_("using default \"%s\" instead"), entry->default_value);
1821 goto again;
1825 texture = parse_texture(scr, value);
1827 if (!texture) {
1828 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1829 if (changed == 0) {
1830 value = entry->plvalue;
1831 changed = 1;
1832 wwarning(_("using default \"%s\" instead"), entry->default_value);
1833 goto again;
1835 return False;
1838 if (ret)
1839 *ret = &texture;
1841 if (addr)
1842 *(WTexture **) addr = texture;
1844 return True;
1847 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1849 WMPropList *elem;
1850 int changed = 0;
1851 char *val;
1852 int nelem;
1854 again:
1855 if (!WMIsPLArray(value)) {
1856 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1857 "WorkspaceBack", "Texture or None");
1858 if (changed == 0) {
1859 value = entry->plvalue;
1860 changed = 1;
1861 wwarning(_("using default \"%s\" instead"), entry->default_value);
1862 goto again;
1864 return False;
1867 /* only do basic error checking and verify for None texture */
1869 nelem = WMGetPropListItemCount(value);
1870 if (nelem > 0) {
1871 elem = WMGetFromPLArray(value, 0);
1872 if (!elem || !WMIsPLString(elem)) {
1873 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1874 if (changed == 0) {
1875 value = entry->plvalue;
1876 changed = 1;
1877 wwarning(_("using default \"%s\" instead"), entry->default_value);
1878 goto again;
1880 return False;
1882 val = WMGetFromPLString(elem);
1884 if (strcasecmp(val, "None") == 0)
1885 return True;
1887 *ret = WMRetainPropList(value);
1889 return True;
1892 static int
1893 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1895 WMPropList *elem;
1896 int nelem;
1897 int changed = 0;
1899 again:
1900 if (!WMIsPLArray(value)) {
1901 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1902 "WorkspaceSpecificBack", "an array of textures");
1903 if (changed == 0) {
1904 value = entry->plvalue;
1905 changed = 1;
1906 wwarning(_("using default \"%s\" instead"), entry->default_value);
1907 goto again;
1909 return False;
1912 /* only do basic error checking and verify for None texture */
1914 nelem = WMGetPropListItemCount(value);
1915 if (nelem > 0) {
1916 while (nelem--) {
1917 elem = WMGetFromPLArray(value, nelem);
1918 if (!elem || !WMIsPLArray(elem)) {
1919 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1920 nelem);
1925 *ret = WMRetainPropList(value);
1927 #ifdef notworking
1929 * Kluge to force wmsetbg helper to set the default background.
1930 * If the WorkspaceSpecificBack is changed once wmaker has started,
1931 * the WorkspaceBack won't be sent to the helper, unless the user
1932 * changes it's value too. So, we must force this by removing the
1933 * value from the defaults DB.
1935 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1936 WMPropList *key = WMCreatePLString("WorkspaceBack");
1938 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1940 WMReleasePropList(key);
1942 #endif
1943 return True;
1946 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1948 static WMFont *font;
1949 char *val;
1951 GET_STRING_OR_DEFAULT("Font", val);
1953 font = WMCreateFont(scr->wmscreen, val);
1954 if (!font)
1955 font = WMCreateFont(scr->wmscreen, "fixed");
1957 if (!font) {
1958 wfatal(_("could not load any usable font!!!"));
1959 exit(1);
1962 if (ret)
1963 *ret = font;
1965 /* can't assign font value outside update function */
1966 wassertrv(addr == NULL, True);
1968 return True;
1971 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1973 static XColor color;
1974 char *val;
1975 int second_pass = 0;
1977 GET_STRING_OR_DEFAULT("Color", val);
1979 again:
1980 if (!wGetColor(scr, val, &color)) {
1981 wwarning(_("could not get color for key \"%s\""), entry->key);
1982 if (second_pass == 0) {
1983 val = WMGetFromPLString(entry->plvalue);
1984 second_pass = 1;
1985 wwarning(_("using default \"%s\" instead"), val);
1986 goto again;
1988 return False;
1991 if (ret)
1992 *ret = &color;
1994 assert(addr == NULL);
1996 if (addr)
1997 *(unsigned long*)addr = pixel;
2000 return True;
2003 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2005 static WShortKey shortcut;
2006 KeySym ksym;
2007 char *val;
2008 char *k;
2009 char buf[MAX_SHORTCUT_LENGTH], *b;
2011 GET_STRING_OR_DEFAULT("Key spec", val);
2013 if (!val || strcasecmp(val, "NONE") == 0) {
2014 shortcut.keycode = 0;
2015 shortcut.modifier = 0;
2016 if (ret)
2017 *ret = &shortcut;
2018 return True;
2021 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2023 b = (char *)buf;
2025 /* get modifiers */
2026 shortcut.modifier = 0;
2027 while ((k = strchr(b, '+')) != NULL) {
2028 int mod;
2030 *k = 0;
2031 mod = wXModifierFromKey(b);
2032 if (mod < 0) {
2033 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2034 return False;
2036 shortcut.modifier |= mod;
2038 b = k + 1;
2041 /* get key */
2042 ksym = XStringToKeysym(b);
2044 if (ksym == NoSymbol) {
2045 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2046 return False;
2049 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2050 if (shortcut.keycode == 0) {
2051 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2052 return False;
2055 if (ret)
2056 *ret = &shortcut;
2058 return True;
2061 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2063 static int mask;
2064 char *str;
2066 GET_STRING_OR_DEFAULT("Modifier Key", str);
2068 if (!str)
2069 return False;
2071 mask = wXModifierFromKey(str);
2072 if (mask < 0) {
2073 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2074 mask = 0;
2075 return False;
2078 if (addr)
2079 *(int *)addr = mask;
2081 if (ret)
2082 *ret = &mask;
2084 return True;
2087 # include <X11/cursorfont.h>
2088 typedef struct {
2089 char *name;
2090 int id;
2091 } WCursorLookup;
2093 #define CURSOR_ID_NONE (XC_num_glyphs)
2095 static WCursorLookup cursor_table[] = {
2096 {"X_cursor", XC_X_cursor},
2097 {"arrow", XC_arrow},
2098 {"based_arrow_down", XC_based_arrow_down},
2099 {"based_arrow_up", XC_based_arrow_up},
2100 {"boat", XC_boat},
2101 {"bogosity", XC_bogosity},
2102 {"bottom_left_corner", XC_bottom_left_corner},
2103 {"bottom_right_corner", XC_bottom_right_corner},
2104 {"bottom_side", XC_bottom_side},
2105 {"bottom_tee", XC_bottom_tee},
2106 {"box_spiral", XC_box_spiral},
2107 {"center_ptr", XC_center_ptr},
2108 {"circle", XC_circle},
2109 {"clock", XC_clock},
2110 {"coffee_mug", XC_coffee_mug},
2111 {"cross", XC_cross},
2112 {"cross_reverse", XC_cross_reverse},
2113 {"crosshair", XC_crosshair},
2114 {"diamond_cross", XC_diamond_cross},
2115 {"dot", XC_dot},
2116 {"dotbox", XC_dotbox},
2117 {"double_arrow", XC_double_arrow},
2118 {"draft_large", XC_draft_large},
2119 {"draft_small", XC_draft_small},
2120 {"draped_box", XC_draped_box},
2121 {"exchange", XC_exchange},
2122 {"fleur", XC_fleur},
2123 {"gobbler", XC_gobbler},
2124 {"gumby", XC_gumby},
2125 {"hand1", XC_hand1},
2126 {"hand2", XC_hand2},
2127 {"heart", XC_heart},
2128 {"icon", XC_icon},
2129 {"iron_cross", XC_iron_cross},
2130 {"left_ptr", XC_left_ptr},
2131 {"left_side", XC_left_side},
2132 {"left_tee", XC_left_tee},
2133 {"leftbutton", XC_leftbutton},
2134 {"ll_angle", XC_ll_angle},
2135 {"lr_angle", XC_lr_angle},
2136 {"man", XC_man},
2137 {"middlebutton", XC_middlebutton},
2138 {"mouse", XC_mouse},
2139 {"pencil", XC_pencil},
2140 {"pirate", XC_pirate},
2141 {"plus", XC_plus},
2142 {"question_arrow", XC_question_arrow},
2143 {"right_ptr", XC_right_ptr},
2144 {"right_side", XC_right_side},
2145 {"right_tee", XC_right_tee},
2146 {"rightbutton", XC_rightbutton},
2147 {"rtl_logo", XC_rtl_logo},
2148 {"sailboat", XC_sailboat},
2149 {"sb_down_arrow", XC_sb_down_arrow},
2150 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2151 {"sb_left_arrow", XC_sb_left_arrow},
2152 {"sb_right_arrow", XC_sb_right_arrow},
2153 {"sb_up_arrow", XC_sb_up_arrow},
2154 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2155 {"shuttle", XC_shuttle},
2156 {"sizing", XC_sizing},
2157 {"spider", XC_spider},
2158 {"spraycan", XC_spraycan},
2159 {"star", XC_star},
2160 {"target", XC_target},
2161 {"tcross", XC_tcross},
2162 {"top_left_arrow", XC_top_left_arrow},
2163 {"top_left_corner", XC_top_left_corner},
2164 {"top_right_corner", XC_top_right_corner},
2165 {"top_side", XC_top_side},
2166 {"top_tee", XC_top_tee},
2167 {"trek", XC_trek},
2168 {"ul_angle", XC_ul_angle},
2169 {"umbrella", XC_umbrella},
2170 {"ur_angle", XC_ur_angle},
2171 {"watch", XC_watch},
2172 {"xterm", XC_xterm},
2173 {NULL, CURSOR_ID_NONE}
2176 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2178 switch (status) {
2179 case BitmapOpenFailed:
2180 wwarning(_("failed to open bitmap file \"%s\""), filename);
2181 break;
2182 case BitmapFileInvalid:
2183 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2184 break;
2185 case BitmapNoMemory:
2186 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2187 break;
2188 case BitmapSuccess:
2189 XFreePixmap(dpy, bitmap);
2190 break;
2195 * (none)
2196 * (builtin, <cursor_name>)
2197 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2199 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2201 WMPropList *elem;
2202 char *val;
2203 int nelem;
2204 int status = 0;
2206 nelem = WMGetPropListItemCount(pl);
2207 if (nelem < 1) {
2208 return (status);
2210 elem = WMGetFromPLArray(pl, 0);
2211 if (!elem || !WMIsPLString(elem)) {
2212 return (status);
2214 val = WMGetFromPLString(elem);
2216 if (strcasecmp(val, "none") == 0) {
2217 status = 1;
2218 *cursor = None;
2219 } else if (strcasecmp(val, "builtin") == 0) {
2220 int i;
2221 int cursor_id = CURSOR_ID_NONE;
2223 if (nelem != 2) {
2224 wwarning(_("bad number of arguments in cursor specification"));
2225 return (status);
2227 elem = WMGetFromPLArray(pl, 1);
2228 if (!elem || !WMIsPLString(elem)) {
2229 return (status);
2231 val = WMGetFromPLString(elem);
2233 for (i = 0; cursor_table[i].name != NULL; i++) {
2234 if (strcasecmp(val, cursor_table[i].name) == 0) {
2235 cursor_id = cursor_table[i].id;
2236 break;
2239 if (CURSOR_ID_NONE == cursor_id) {
2240 wwarning(_("unknown builtin cursor name \"%s\""), val);
2241 } else {
2242 *cursor = XCreateFontCursor(dpy, cursor_id);
2243 status = 1;
2245 } else if (strcasecmp(val, "bitmap") == 0) {
2246 char *bitmap_name;
2247 char *mask_name;
2248 int bitmap_status;
2249 int mask_status;
2250 Pixmap bitmap;
2251 Pixmap mask;
2252 unsigned int w, h;
2253 int x, y;
2254 XColor fg, bg;
2256 if (nelem != 3) {
2257 wwarning(_("bad number of arguments in cursor specification"));
2258 return (status);
2260 elem = WMGetFromPLArray(pl, 1);
2261 if (!elem || !WMIsPLString(elem)) {
2262 return (status);
2264 val = WMGetFromPLString(elem);
2265 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2266 if (!bitmap_name) {
2267 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2268 return (status);
2270 elem = WMGetFromPLArray(pl, 2);
2271 if (!elem || !WMIsPLString(elem)) {
2272 wfree(bitmap_name);
2273 return (status);
2275 val = WMGetFromPLString(elem);
2276 mask_name = FindImage(wPreferences.pixmap_path, val);
2277 if (!mask_name) {
2278 wfree(bitmap_name);
2279 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2280 return (status);
2282 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2283 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2284 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2285 fg.pixel = scr->black_pixel;
2286 bg.pixel = scr->white_pixel;
2287 XQueryColor(dpy, scr->w_colormap, &fg);
2288 XQueryColor(dpy, scr->w_colormap, &bg);
2289 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2290 status = 1;
2292 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2293 check_bitmap_status(mask_status, mask_name, mask);
2294 wfree(bitmap_name);
2295 wfree(mask_name);
2297 return (status);
2300 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2302 static Cursor cursor;
2303 int status;
2304 int changed = 0;
2306 again:
2307 if (!WMIsPLArray(value)) {
2308 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2309 entry->key, "cursor specification");
2310 if (!changed) {
2311 value = entry->plvalue;
2312 changed = 1;
2313 wwarning(_("using default \"%s\" instead"), entry->default_value);
2314 goto again;
2316 return (False);
2318 status = parse_cursor(scr, value, &cursor);
2319 if (!status) {
2320 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2321 if (!changed) {
2322 value = entry->plvalue;
2323 changed = 1;
2324 wwarning(_("using default \"%s\" instead"), entry->default_value);
2325 goto again;
2327 return (False);
2329 if (ret) {
2330 *ret = &cursor;
2332 if (addr) {
2333 *(Cursor *) addr = cursor;
2335 return (True);
2338 #undef CURSOR_ID_NONE
2340 /* ---------------- value setting functions --------------- */
2341 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2343 return REFRESH_WINDOW_TITLE_COLOR;
2346 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2348 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2351 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2353 switch (which) {
2354 case WM_DOCK:
2355 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2356 break;
2357 case WM_CLIP:
2358 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2359 break;
2360 default:
2361 break;
2363 return 0;
2366 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2368 if (scr->workspaces) {
2369 wWorkspaceForceChange(scr, scr->current_workspace);
2370 wArrangeIcons(scr, False);
2372 return 0;
2375 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2377 Pixmap pixmap;
2378 RImage *img;
2379 int reset = 0;
2381 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2382 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2383 ? WREL_ICON : WREL_FLAT);
2384 if (!img) {
2385 wwarning(_("could not render texture for icon background"));
2386 if (!entry->addr)
2387 wTextureDestroy(scr, *texture);
2388 return 0;
2390 RConvertImage(scr->rcontext, img, &pixmap);
2392 if (scr->icon_tile) {
2393 reset = 1;
2394 RReleaseImage(scr->icon_tile);
2395 XFreePixmap(dpy, scr->icon_tile_pixmap);
2398 scr->icon_tile = img;
2400 /* put the icon in the noticeboard hint */
2401 PropSetIconTileHint(scr, img);
2403 if (!wPreferences.flags.noclip) {
2404 if (scr->clip_tile) {
2405 RReleaseImage(scr->clip_tile);
2407 scr->clip_tile = wClipMakeTile(scr, img);
2410 scr->icon_tile_pixmap = pixmap;
2412 if (scr->def_icon_pixmap) {
2413 XFreePixmap(dpy, scr->def_icon_pixmap);
2414 scr->def_icon_pixmap = None;
2416 if (scr->def_ticon_pixmap) {
2417 XFreePixmap(dpy, scr->def_ticon_pixmap);
2418 scr->def_ticon_pixmap = None;
2421 if (scr->icon_back_texture) {
2422 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2424 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2426 if (scr->clip_balloon)
2427 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2430 * Free the texture as nobody else will use it, nor refer to it.
2432 if (!entry->addr)
2433 wTextureDestroy(scr, *texture);
2435 return (reset ? REFRESH_ICON_TILE : 0);
2438 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2440 if (scr->title_font) {
2441 WMReleaseFont(scr->title_font);
2443 scr->title_font = font;
2445 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2448 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2450 if (scr->menu_title_font) {
2451 WMReleaseFont(scr->menu_title_font);
2454 scr->menu_title_font = font;
2456 return REFRESH_MENU_TITLE_FONT;
2459 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2461 if (scr->menu_entry_font) {
2462 WMReleaseFont(scr->menu_entry_font);
2464 scr->menu_entry_font = font;
2466 return REFRESH_MENU_FONT;
2469 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2471 if (scr->icon_title_font) {
2472 WMReleaseFont(scr->icon_title_font);
2475 scr->icon_title_font = font;
2477 return REFRESH_ICON_FONT;
2480 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2482 if (scr->clip_title_font) {
2483 WMReleaseFont(scr->clip_title_font);
2486 scr->clip_title_font = font;
2488 return REFRESH_ICON_FONT;
2491 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2493 if (scr->workspace_name_font) {
2494 WMReleaseFont(scr->workspace_name_font);
2497 scr->workspace_name_font = font;
2499 return 0;
2502 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2504 if (scr->select_color)
2505 WMReleaseColor(scr->select_color);
2507 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2509 wFreeColor(scr, color->pixel);
2511 return REFRESH_MENU_COLOR;
2514 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2516 if (scr->select_text_color)
2517 WMReleaseColor(scr->select_text_color);
2519 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2521 wFreeColor(scr, color->pixel);
2523 return REFRESH_MENU_COLOR;
2526 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2528 if (scr->clip_title_color[widx])
2529 WMReleaseColor(scr->clip_title_color[widx]);
2531 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2532 wFreeColor(scr, color->pixel);
2534 return REFRESH_ICON_TITLE_COLOR;
2537 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2539 if (scr->window_title_color[widx])
2540 WMReleaseColor(scr->window_title_color[widx]);
2542 scr->window_title_color[widx] =
2543 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2545 wFreeColor(scr, color->pixel);
2547 return REFRESH_WINDOW_TITLE_COLOR;
2550 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2552 if (scr->menu_title_color[0])
2553 WMReleaseColor(scr->menu_title_color[0]);
2555 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2557 wFreeColor(scr, color->pixel);
2559 return REFRESH_MENU_TITLE_COLOR;
2562 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2564 if (scr->mtext_color)
2565 WMReleaseColor(scr->mtext_color);
2567 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2569 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2570 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2571 } else {
2572 WMSetColorAlpha(scr->dtext_color, 0xffff);
2575 wFreeColor(scr, color->pixel);
2577 return REFRESH_MENU_COLOR;
2580 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2582 if (scr->dtext_color)
2583 WMReleaseColor(scr->dtext_color);
2585 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2587 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2588 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2589 } else {
2590 WMSetColorAlpha(scr->dtext_color, 0xffff);
2593 wFreeColor(scr, color->pixel);
2595 return REFRESH_MENU_COLOR;
2598 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2600 if (scr->icon_title_color)
2601 WMReleaseColor(scr->icon_title_color);
2602 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2604 wFreeColor(scr, color->pixel);
2606 return REFRESH_ICON_TITLE_COLOR;
2609 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2611 if (scr->icon_title_texture) {
2612 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2614 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2616 return REFRESH_ICON_TITLE_BACK;
2619 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2621 close(scr->helper_fd);
2622 scr->helper_fd = 0;
2623 scr->helper_pid = 0;
2624 scr->flags.backimage_helper_launched = 0;
2627 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2629 WMPropList *val;
2630 char *str;
2631 int i;
2633 if (scr->flags.backimage_helper_launched) {
2634 if (WMGetPropListItemCount(value) == 0) {
2635 SendHelperMessage(scr, 'C', 0, NULL);
2636 SendHelperMessage(scr, 'K', 0, NULL);
2638 WMReleasePropList(value);
2639 return 0;
2641 } else {
2642 pid_t pid;
2643 int filedes[2];
2645 if (WMGetPropListItemCount(value) == 0)
2646 return 0;
2648 if (pipe(filedes) < 0) {
2649 werror("pipe() failed:can't set workspace specific background image");
2651 WMReleasePropList(value);
2652 return 0;
2655 pid = fork();
2656 if (pid < 0) {
2657 werror("fork() failed:can't set workspace specific background image");
2658 if (close(filedes[0]) < 0)
2659 werror("could not close pipe");
2660 if (close(filedes[1]) < 0)
2661 werror("could not close pipe");
2663 } else if (pid == 0) {
2664 char *dither;
2666 SetupEnvironment(scr);
2668 if (close(0) < 0)
2669 werror("could not close pipe");
2670 if (dup(filedes[0]) < 0) {
2671 werror("dup() failed:can't set workspace specific background image");
2673 dither = wPreferences.no_dithering ? "-m" : "-d";
2674 if (wPreferences.smooth_workspace_back)
2675 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2676 else
2677 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2678 werror("could not execute wmsetbg");
2679 exit(1);
2680 } else {
2682 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2683 werror("error setting close-on-exec flag");
2685 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2686 werror("error setting close-on-exec flag");
2689 scr->helper_fd = filedes[1];
2690 scr->helper_pid = pid;
2691 scr->flags.backimage_helper_launched = 1;
2693 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2695 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2700 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2701 val = WMGetFromPLArray(value, i);
2702 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2703 str = WMGetPropListDescription(val, False);
2705 SendHelperMessage(scr, 'S', i + 1, str);
2707 wfree(str);
2708 } else {
2709 SendHelperMessage(scr, 'U', i + 1, NULL);
2712 sleep(1);
2714 WMReleasePropList(value);
2715 return 0;
2718 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2720 if (scr->flags.backimage_helper_launched) {
2721 char *str;
2723 if (WMGetPropListItemCount(value) == 0) {
2724 SendHelperMessage(scr, 'U', 0, NULL);
2725 } else {
2726 /* set the default workspace background to this one */
2727 str = WMGetPropListDescription(value, False);
2728 if (str) {
2729 SendHelperMessage(scr, 'S', 0, str);
2730 wfree(str);
2731 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2732 } else {
2733 SendHelperMessage(scr, 'U', 0, NULL);
2736 } else if (WMGetPropListItemCount(value) > 0) {
2737 char *command;
2738 char *text;
2739 char *dither;
2740 int len;
2742 text = WMGetPropListDescription(value, False);
2743 len = strlen(text) + 40;
2744 command = wmalloc(len);
2745 dither = wPreferences.no_dithering ? "-m" : "-d";
2746 if (wPreferences.smooth_workspace_back)
2747 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2748 else
2749 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2750 wfree(text);
2751 ExecuteShellCommand(scr, command);
2752 wfree(command);
2754 WMReleasePropList(value);
2756 return 0;
2759 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2761 if (scr->widget_texture) {
2762 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2764 scr->widget_texture = *(WTexSolid **) texture;
2766 return 0;
2769 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2771 if (scr->window_title_texture[WS_FOCUSED]) {
2772 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2774 scr->window_title_texture[WS_FOCUSED] = *texture;
2776 return REFRESH_WINDOW_TEXTURES;
2779 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2781 if (scr->window_title_texture[WS_PFOCUSED]) {
2782 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2784 scr->window_title_texture[WS_PFOCUSED] = *texture;
2786 return REFRESH_WINDOW_TEXTURES;
2789 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2791 if (scr->window_title_texture[WS_UNFOCUSED]) {
2792 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2794 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2796 return REFRESH_WINDOW_TEXTURES;
2799 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2801 if (scr->resizebar_texture[0]) {
2802 wTextureDestroy(scr, scr->resizebar_texture[0]);
2804 scr->resizebar_texture[0] = *texture;
2806 return REFRESH_WINDOW_TEXTURES;
2809 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2811 if (scr->menu_title_texture[0]) {
2812 wTextureDestroy(scr, scr->menu_title_texture[0]);
2814 scr->menu_title_texture[0] = *texture;
2816 return REFRESH_MENU_TITLE_TEXTURE;
2819 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2821 if (scr->menu_item_texture) {
2822 wTextureDestroy(scr, scr->menu_item_texture);
2823 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2825 scr->menu_item_texture = *texture;
2827 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2829 return REFRESH_MENU_TEXTURE;
2832 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2834 WWindow *wwin;
2835 wKeyBindings[widx] = *shortcut;
2837 wwin = scr->focused_window;
2839 while (wwin != NULL) {
2840 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2842 if (!WFLAGP(wwin, no_bind_keys)) {
2843 wWindowSetKeyGrabs(wwin);
2845 wwin = wwin->prev;
2848 return 0;
2851 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2853 wScreenUpdateUsableArea(scr);
2854 wArrangeIcons(scr, True);
2856 return 0;
2859 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2861 wScreenUpdateUsableArea(scr);
2863 return 0;
2866 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2868 return REFRESH_MENU_TEXTURE;
2871 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2873 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2875 RCopyArea(img, image, x, y, w, h, 0, 0);
2877 return img;
2880 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2882 char *path;
2883 RImage *bgimage;
2884 int cwidth, cheight;
2885 WPreferences *prefs = (WPreferences *) foo;
2887 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2888 if (prefs->swtileImage)
2889 RReleaseImage(prefs->swtileImage);
2890 prefs->swtileImage = NULL;
2892 WMReleasePropList(array);
2893 return 0;
2896 switch (WMGetPropListItemCount(array)) {
2897 case 4:
2898 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2899 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2900 break;
2901 } else
2902 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2904 if (!path) {
2905 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2906 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2907 } else {
2908 bgimage = RLoadImage(scr->rcontext, path, 0);
2909 if (!bgimage) {
2910 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2911 wfree(path);
2912 } else {
2913 wfree(path);
2915 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2916 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2918 if (cwidth <= 0 || cheight <= 0 ||
2919 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2920 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2921 else {
2922 int i;
2923 int swidth, theight;
2924 for (i = 0; i < 9; i++) {
2925 if (prefs->swbackImage[i])
2926 RReleaseImage(prefs->swbackImage[i]);
2927 prefs->swbackImage[i] = NULL;
2929 swidth = (bgimage->width - cwidth) / 2;
2930 theight = (bgimage->height - cheight) / 2;
2932 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2933 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2934 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2935 swidth, theight);
2937 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2938 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2939 cwidth, cheight);
2940 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2941 swidth, cheight);
2943 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2944 swidth, theight);
2945 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2946 cwidth, theight);
2947 prefs->swbackImage[8] =
2948 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2949 theight);
2951 // check if anything failed
2952 for (i = 0; i < 9; i++) {
2953 if (!prefs->swbackImage[i]) {
2954 for (; i >= 0; --i) {
2955 RReleaseImage(prefs->swbackImage[i]);
2956 prefs->swbackImage[i] = NULL;
2958 break;
2962 RReleaseImage(bgimage);
2966 case 1:
2967 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
2968 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2969 break;
2970 } else
2971 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
2973 if (!path) {
2974 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2975 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
2976 } else {
2977 if (prefs->swtileImage)
2978 RReleaseImage(prefs->swtileImage);
2980 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
2981 if (!prefs->swtileImage) {
2982 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2984 wfree(path);
2986 break;
2988 default:
2989 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
2990 break;
2993 WMReleasePropList(array);
2995 return 0;
2998 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
3000 int i;
3001 WPreferences *prefs = (WPreferences *) foo;
3003 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3004 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3005 WMReleasePropList(array);
3006 return 0;
3009 DestroyWindowMenu(scr);
3011 for (i = 0; i < 7; i++) {
3012 if (prefs->modifier_labels[i])
3013 wfree(prefs->modifier_labels[i]);
3015 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3016 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3017 } else {
3018 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3019 prefs->modifier_labels[i] = NULL;
3023 WMReleasePropList(array);
3025 return 0;
3029 * Very ugly kluge.
3030 * Need access to the double click variables, so that all widgets in
3031 * wmaker panels will have the same dbl-click values.
3032 * TODO: figure a better way of dealing with it.
3034 #include <WINGs/WINGsP.h>
3036 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3038 extern _WINGsConfiguration WINGsConfiguration;
3040 if (*value <= 0)
3041 *(int *)foo = 1;
3043 WINGsConfiguration.doubleClickDelay = *value;
3045 return 0;
3048 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3050 if (wCursor[widx] != None) {
3051 XFreeCursor(dpy, wCursor[widx]);
3054 wCursor[widx] = *cursor;
3056 if (widx == WCUR_ROOT && *cursor != None) {
3057 XDefineCursor(dpy, scr->root_win, *cursor);
3060 return 0;