Add drawers to wmaker!
[wmaker-crm.git] / src / defaults.c
blob053551d1da9f71b53eea314baa792afa204919ff
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 {"DisableDrawers", "NO", (void *)WM_DRAWER,
329 NULL, getBool, setIfDockPresent, NULL, NULL},
330 {"DisableMiniwindows", "NO", NULL,
331 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
334 #define NUM2STRING_(x) #x
335 #define NUM2STRING(x) NUM2STRING_(x)
337 WDefaultEntry optionList[] = {
339 /* dynamic options */
341 {"IconPosition", "blh", seIconPositions,
342 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
343 {"IconificationStyle", "Zoom", seIconificationStyles,
344 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
345 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
346 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
347 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
348 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
349 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
350 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
351 {"MouseWheelAction", "None", seMouseWheelActions,
352 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
353 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
354 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
355 {"IconPath", DEF_ICON_PATHS, NULL,
356 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
357 {"ColormapMode", "auto", seColormapModes,
358 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
359 {"AutoFocus", "NO", NULL,
360 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
361 {"RaiseDelay", "0", NULL,
362 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
363 {"CirculateRaise", "NO", NULL,
364 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
365 {"Superfluous", "NO", NULL,
366 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
367 {"AdvanceToNewWorkspace", "NO", NULL,
368 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
369 {"CycleWorkspaces", "NO", NULL,
370 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
371 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
372 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
373 {"WorkspaceBorder", "None", seWorkspaceBorder,
374 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
375 {"WorkspaceBorderSize", "0", NULL,
376 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
377 {"StickyIcons", "NO", NULL,
378 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
379 {"SaveSessionOnExit", "NO", NULL,
380 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
381 {"WrapMenus", "NO", NULL,
382 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
383 {"ScrollableMenus", "NO", NULL,
384 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
385 {"MenuScrollSpeed", "medium", seSpeeds,
386 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
387 {"IconSlideSpeed", "medium", seSpeeds,
388 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
389 {"ShadeSpeed", "medium", seSpeeds,
390 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
391 {"BounceAppIconsWhenUrgent", "YES", NULL,
392 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
393 {"RaiseAppIconsWhenBouncing", "NO", NULL,
394 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
395 {"DoNotMakeAppIconsBounce", "NO", NULL,
396 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
397 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
398 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
399 {"ClipAutoraiseDelay", "600", NULL,
400 &wPreferences.clip_auto_raise_delay, getInt, NULL, NULL, NULL},
401 {"ClipAutolowerDelay", "1000", NULL,
402 &wPreferences.clip_auto_lower_delay, getInt, NULL, NULL, NULL},
403 {"ClipAutoexpandDelay", "600", NULL,
404 &wPreferences.clip_auto_expand_delay, getInt, NULL, NULL, NULL},
405 {"ClipAutocollapseDelay", "1000", NULL,
406 &wPreferences.clip_auto_collapse_delay, getInt, NULL, NULL, NULL},
407 {"AlignSubmenus", "NO", NULL,
408 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
409 {"ViKeyMenus", "NO", NULL,
410 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
411 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
412 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
413 {"WindowPlacement", "auto", sePlacements,
414 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
415 {"IgnoreFocusClick", "NO", NULL,
416 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
417 {"UseSaveUnders", "NO", NULL,
418 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
419 {"OpaqueMove", "NO", NULL,
420 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
421 {"OpaqueResize", "NO", NULL,
422 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
423 {"OpaqueMoveResizeKeyboard", "NO", NULL,
424 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
425 {"DisableAnimations", "NO", NULL,
426 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
427 {"DontLinkWorkspaces", "NO", NULL,
428 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
429 {"HighlightActiveApp", "YES", NULL,
430 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
431 {"AutoArrangeIcons", "NO", NULL,
432 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
433 {"NoWindowOverDock", "NO", NULL,
434 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
435 {"NoWindowOverIcons", "NO", NULL,
436 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
437 {"WindowPlaceOrigin", "(0, 0)", NULL,
438 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
439 {"ResizeDisplay", "corner", seGeomDisplays,
440 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
441 {"MoveDisplay", "corner", seGeomDisplays,
442 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
443 {"DontConfirmKill", "NO", NULL,
444 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
445 {"WindowTitleBalloons", "NO", NULL,
446 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
447 {"MiniwindowTitleBalloons", "NO", NULL,
448 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
449 {"AppIconBalloons", "NO", NULL,
450 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
451 {"HelpBalloons", "NO", NULL,
452 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
453 {"EdgeResistance", "30", NULL,
454 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
455 {"ResizeIncrement", "0", NULL,
456 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
457 {"Attraction", "NO", NULL,
458 &wPreferences.attract, getBool, NULL, NULL, NULL},
459 {"DisableBlinking", "NO", NULL,
460 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
461 {"SingleClickLaunch", "NO", NULL,
462 &wPreferences.single_click, getBool, NULL, NULL, NULL},
464 /* style options */
466 {"MenuStyle", "normal", seMenuStyles,
467 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
468 {"WidgetColor", "(solid, gray)", NULL,
469 NULL, getTexture, setWidgetColor, NULL, NULL},
470 {"WorkspaceSpecificBack", "()", NULL,
471 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
472 /* WorkspaceBack must come after WorkspaceSpecificBack or
473 * WorkspaceBack wont know WorkspaceSpecificBack was also
474 * specified and 2 copies of wmsetbg will be launched */
475 {"WorkspaceBack", "(solid, black)", NULL,
476 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
477 {"SmoothWorkspaceBack", "NO", NULL,
478 NULL, getBool, NULL, NULL, NULL},
479 {"IconBack", "(solid, gray)", NULL,
480 NULL, getTexture, setIconTile, NULL, NULL},
481 {"TitleJustify", "center", seJustifications,
482 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
483 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
484 NULL, getFont, setWinTitleFont, NULL, NULL},
485 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
486 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
487 {"WindowTitleMinHeight", "0", NULL,
488 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
489 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
490 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
491 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
492 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
493 {"MenuTitleMinHeight", "0", NULL,
494 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
495 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
496 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
497 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
498 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
499 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
500 NULL, getFont, setMenuTitleFont, NULL, NULL},
501 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
502 NULL, getFont, setMenuTextFont, NULL, NULL},
503 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
504 NULL, getFont, setIconTitleFont, NULL, NULL},
505 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
506 NULL, getFont, setClipTitleFont, NULL, NULL},
507 {"ShowClipTitle", "YES", NULL,
508 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
509 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
510 NULL, getFont, setLargeDisplayFont, NULL, NULL},
511 {"HighlightColor", "white", NULL,
512 NULL, getColor, setHightlight, NULL, NULL},
513 {"HighlightTextColor", "black", NULL,
514 NULL, getColor, setHightlightText, NULL, NULL},
515 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
516 NULL, getColor, setClipTitleColor, NULL, NULL},
517 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
518 NULL, getColor, setClipTitleColor, NULL, NULL},
519 {"FTitleColor", "white", (void *)WS_FOCUSED,
520 NULL, getColor, setWTitleColor, NULL, NULL},
521 {"PTitleColor", "white", (void *)WS_PFOCUSED,
522 NULL, getColor, setWTitleColor, NULL, NULL},
523 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
524 NULL, getColor, setWTitleColor, NULL, NULL},
525 {"FTitleBack", "(solid, black)", NULL,
526 NULL, getTexture, setFTitleBack, NULL, NULL},
527 {"PTitleBack", "(solid, \"#616161\")", NULL,
528 NULL, getTexture, setPTitleBack, NULL, NULL},
529 {"UTitleBack", "(solid, gray)", NULL,
530 NULL, getTexture, setUTitleBack, NULL, NULL},
531 {"ResizebarBack", "(solid, gray)", NULL,
532 NULL, getTexture, setResizebarBack, NULL, NULL},
533 {"MenuTitleColor", "white", NULL,
534 NULL, getColor, setMenuTitleColor, NULL, NULL},
535 {"MenuTextColor", "black", NULL,
536 NULL, getColor, setMenuTextColor, NULL, NULL},
537 {"MenuDisabledColor", "\"#616161\"", NULL,
538 NULL, getColor, setMenuDisabledColor, NULL, NULL},
539 {"MenuTitleBack", "(solid, black)", NULL,
540 NULL, getTexture, setMenuTitleBack, NULL, NULL},
541 {"MenuTextBack", "(solid, gray)", NULL,
542 NULL, getTexture, setMenuTextBack, NULL, NULL},
543 {"IconTitleColor", "white", NULL,
544 NULL, getColor, setIconTitleColor, NULL, NULL},
545 {"IconTitleBack", "black", NULL,
546 NULL, getColor, setIconTitleBack, NULL, NULL},
547 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
548 NULL, getPropList, setSwPOptions, NULL, NULL},
549 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
550 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
552 /* keybindings */
554 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
555 NULL, getKeybind, setKeyGrab, NULL, NULL},
556 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
557 NULL, getKeybind, setKeyGrab, NULL, NULL},
558 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
559 NULL, getKeybind, setKeyGrab, NULL, NULL},
560 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
561 NULL, getKeybind, setKeyGrab, NULL, NULL},
562 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
563 NULL, getKeybind, setKeyGrab, NULL, NULL},
564 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
565 NULL, getKeybind, setKeyGrab, NULL, NULL},
566 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
567 NULL, getKeybind, setKeyGrab, NULL, NULL },
568 {"HideKey", "None", (void *)WKBD_HIDE,
569 NULL, getKeybind, setKeyGrab, NULL, NULL},
570 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
571 NULL, getKeybind, setKeyGrab, NULL, NULL},
572 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
573 NULL, getKeybind, setKeyGrab, NULL, NULL},
574 {"CloseKey", "None", (void *)WKBD_CLOSE,
575 NULL, getKeybind, setKeyGrab, NULL, NULL},
576 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
577 NULL, getKeybind, setKeyGrab, NULL, NULL},
578 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
579 NULL, getKeybind, setKeyGrab, NULL, NULL},
580 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
581 NULL, getKeybind, setKeyGrab, NULL, NULL},
582 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
583 NULL, getKeybind, setKeyGrab, NULL, NULL},
584 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
585 NULL, getKeybind, setKeyGrab, NULL, NULL},
586 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
587 NULL, getKeybind, setKeyGrab, NULL, NULL},
588 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
589 NULL, getKeybind, setKeyGrab, NULL, NULL},
590 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
591 NULL, getKeybind, setKeyGrab, NULL, NULL},
592 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
593 NULL, getKeybind, setKeyGrab, NULL, NULL},
594 {"ShadeKey", "None", (void *)WKBD_SHADE,
595 NULL, getKeybind, setKeyGrab, NULL, NULL},
596 {"SelectKey", "None", (void *)WKBD_SELECT,
597 NULL, getKeybind, setKeyGrab, NULL, NULL},
598 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
599 NULL, getKeybind, setKeyGrab, NULL, NULL},
600 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
601 NULL, getKeybind, setKeyGrab, NULL, NULL},
602 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
603 NULL, getKeybind, setKeyGrab, NULL, NULL},
604 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
605 NULL, getKeybind, setKeyGrab, NULL, NULL},
606 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
607 NULL, getKeybind, setKeyGrab, NULL, NULL},
608 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
609 NULL, getKeybind, setKeyGrab, NULL, NULL},
610 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
611 NULL, getKeybind, setKeyGrab, NULL, NULL},
612 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
613 NULL, getKeybind, setKeyGrab, NULL, NULL},
614 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
615 NULL, getKeybind, setKeyGrab, NULL, NULL},
616 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
617 NULL, getKeybind, setKeyGrab, NULL, NULL},
618 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
619 NULL, getKeybind, setKeyGrab, NULL, NULL},
620 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
621 NULL, getKeybind, setKeyGrab, NULL, NULL},
622 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
623 NULL, getKeybind, setKeyGrab, NULL, NULL},
624 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
625 NULL, getKeybind, setKeyGrab, NULL, NULL},
626 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
627 NULL, getKeybind, setKeyGrab, NULL, NULL},
628 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
629 NULL, getKeybind, setKeyGrab, NULL, NULL},
630 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
631 NULL, getKeybind, setKeyGrab, NULL, NULL},
632 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
633 NULL, getKeybind, setKeyGrab, NULL, NULL},
634 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
635 NULL, getKeybind, setKeyGrab, NULL, NULL},
636 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
637 NULL, getKeybind, setKeyGrab, NULL, NULL},
638 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
639 NULL, getKeybind, setKeyGrab, NULL, NULL},
640 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
641 NULL, getKeybind, setKeyGrab, NULL, NULL},
642 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
643 NULL, getKeybind, setKeyGrab, NULL, NULL},
644 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
645 NULL, getKeybind, setKeyGrab, NULL, NULL},
646 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
647 NULL, getKeybind, setKeyGrab, NULL, NULL},
648 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
649 NULL, getKeybind, setKeyGrab, NULL, NULL},
650 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
651 NULL, getKeybind, setKeyGrab, NULL, NULL},
652 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
653 NULL, getKeybind, setKeyGrab, NULL, NULL},
654 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
655 NULL, getKeybind, setKeyGrab, NULL, NULL},
656 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
657 NULL, getKeybind, setKeyGrab, NULL, NULL},
659 #ifdef KEEP_XKB_LOCK_STATUS
660 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
661 NULL, getKeybind, setKeyGrab, NULL, NULL},
662 {"KbdModeLock", "NO", NULL,
663 &wPreferences.modelock, getBool, NULL, NULL, NULL},
664 #endif /* KEEP_XKB_LOCK_STATUS */
666 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
667 NULL, getCursor, setCursor, NULL, NULL},
668 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
669 NULL, getCursor, setCursor, NULL, NULL},
670 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
671 NULL, getCursor, setCursor, NULL, NULL},
672 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
673 NULL, getCursor, setCursor, NULL, NULL},
674 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
675 NULL, getCursor, setCursor, NULL, NULL},
676 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
677 NULL, getCursor, setCursor, NULL, NULL},
678 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
679 NULL, getCursor, setCursor, NULL, NULL},
680 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
681 NULL, getCursor, setCursor, NULL, NULL},
682 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
683 NULL, getCursor, setCursor, NULL, NULL},
684 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
685 NULL, getCursor, setCursor, NULL, NULL},
686 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
687 NULL, getCursor, setCursor, NULL, NULL},
688 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
689 NULL, getCursor, setCursor, NULL, NULL},
690 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
691 NULL, getCursor, setCursor, NULL, NULL},
692 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
693 NULL, getCursor, setCursor, NULL, NULL},
694 {"DialogHistoryLines", "500", NULL,
695 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
696 {"CycleActiveHeadOnly", "NO", NULL,
697 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL},
698 {"CycleIgnoreMinimized", "NO", NULL,
699 &wPreferences.cycle_ignore_minimized, getBool, NULL, NULL, NULL}
702 static void initDefaults()
704 unsigned int i;
705 WDefaultEntry *entry;
707 WMPLSetCaseSensitive(False);
709 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
710 entry = &optionList[i];
712 entry->plkey = WMCreatePLString(entry->key);
713 if (entry->default_value)
714 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
715 else
716 entry->plvalue = NULL;
719 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
720 entry = &staticOptionList[i];
722 entry->plkey = WMCreatePLString(entry->key);
723 if (entry->default_value)
724 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
725 else
726 entry->plvalue = NULL;
730 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
732 WMPropList *globalDict = NULL;
733 char path[PATH_MAX];
734 struct stat stbuf;
736 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
737 if (stat(path, &stbuf) >= 0) {
738 globalDict = WMReadPropListFromFile(path);
739 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
740 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
741 WMReleasePropList(globalDict);
742 globalDict = NULL;
743 } else if (!globalDict) {
744 wwarning(_("could not load domain %s from global defaults database"), domainName);
748 return globalDict;
751 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
752 static void prependMenu(WMPropList * destarr, WMPropList * array)
754 WMPropList *item;
755 int i;
757 for (i = 0; i < WMGetPropListItemCount(array); i++) {
758 item = WMGetFromPLArray(array, i);
759 if (item)
760 WMInsertInPLArray(destarr, i + 1, item);
764 static void appendMenu(WMPropList * destarr, WMPropList * array)
766 WMPropList *item;
767 int i;
769 for (i = 0; i < WMGetPropListItemCount(array); i++) {
770 item = WMGetFromPLArray(array, i);
771 if (item)
772 WMAddToPLArray(destarr, item);
775 #endif
777 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
779 WMPropList *menu = menuDomain->dictionary;
780 WMPropList *submenu;
782 if (!menu || !WMIsPLArray(menu))
783 return;
785 #ifdef GLOBAL_PREAMBLE_MENU_FILE
786 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
788 if (submenu && !WMIsPLArray(submenu)) {
789 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
790 WMReleasePropList(submenu);
791 submenu = NULL;
793 if (submenu) {
794 prependMenu(menu, submenu);
795 WMReleasePropList(submenu);
797 #endif
799 #ifdef GLOBAL_EPILOGUE_MENU_FILE
800 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
802 if (submenu && !WMIsPLArray(submenu)) {
803 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
804 WMReleasePropList(submenu);
805 submenu = NULL;
807 if (submenu) {
808 appendMenu(menu, submenu);
809 WMReleasePropList(submenu);
811 #endif
813 menuDomain->dictionary = menu;
816 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
818 WDDomain *db;
819 struct stat stbuf;
820 static int inited = 0;
821 char *the_path;
822 WMPropList *shared_dict = NULL;
824 if (!inited) {
825 inited = 1;
826 initDefaults();
829 db = wmalloc(sizeof(WDDomain));
830 db->domain_name = domain;
831 db->path = wdefaultspathfordomain(domain);
832 the_path = db->path;
834 if (the_path && stat(the_path, &stbuf) >= 0) {
835 db->dictionary = WMReadPropListFromFile(the_path);
836 if (db->dictionary) {
837 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
838 WMReleasePropList(db->dictionary);
839 db->dictionary = NULL;
840 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
842 db->timestamp = stbuf.st_mtime;
843 } else {
844 wwarning(_("could not load domain %s from user defaults database"), domain);
848 /* global system dictionary */
849 shared_dict = readGlobalDomain(domain, requireDictionary);
851 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
852 WMIsPLDictionary(db->dictionary)) {
853 WMMergePLDictionaries(shared_dict, db->dictionary, True);
854 WMReleasePropList(db->dictionary);
855 db->dictionary = shared_dict;
856 if (stbuf.st_mtime > db->timestamp)
857 db->timestamp = stbuf.st_mtime;
858 } else if (!db->dictionary) {
859 db->dictionary = shared_dict;
860 if (stbuf.st_mtime > db->timestamp)
861 db->timestamp = stbuf.st_mtime;
864 return db;
867 void wReadStaticDefaults(WMPropList * dict)
869 WMPropList *plvalue;
870 WDefaultEntry *entry;
871 unsigned int i;
872 void *tdata;
874 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
875 entry = &staticOptionList[i];
877 if (dict)
878 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
879 else
880 plvalue = NULL;
882 /* no default in the DB. Use builtin default */
883 if (!plvalue)
884 plvalue = entry->plvalue;
886 if (plvalue) {
887 /* convert data */
888 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
889 if (entry->update)
890 (*entry->update) (NULL, entry, tdata, entry->extra_data);
895 void wDefaultsCheckDomains(void* arg)
897 WScreen *scr;
898 struct stat stbuf;
899 WMPropList *shared_dict = NULL;
900 WMPropList *dict;
901 int i;
903 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
904 WDWindowMaker->timestamp = stbuf.st_mtime;
906 /* Global dictionary */
907 shared_dict = readGlobalDomain("WindowMaker", True);
909 /* User dictionary */
910 dict = WMReadPropListFromFile(WDWindowMaker->path);
912 if (dict) {
913 if (!WMIsPLDictionary(dict)) {
914 WMReleasePropList(dict);
915 dict = NULL;
916 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
917 "WindowMaker", WDWindowMaker->path);
918 } else {
919 if (shared_dict) {
920 WMMergePLDictionaries(shared_dict, dict, True);
921 WMReleasePropList(dict);
922 dict = shared_dict;
923 shared_dict = NULL;
926 for (i = 0; i < wScreenCount; i++) {
927 scr = wScreenWithNumber(i);
928 if (scr)
929 wReadDefaults(scr, dict);
932 if (WDWindowMaker->dictionary)
933 WMReleasePropList(WDWindowMaker->dictionary);
935 WDWindowMaker->dictionary = dict;
937 } else {
938 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
941 if (shared_dict)
942 WMReleasePropList(shared_dict);
946 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
947 /* global dictionary */
948 shared_dict = readGlobalDomain("WMWindowAttributes", True);
949 /* user dictionary */
950 dict = WMReadPropListFromFile(WDWindowAttributes->path);
951 if (dict) {
952 if (!WMIsPLDictionary(dict)) {
953 WMReleasePropList(dict);
954 dict = NULL;
955 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
956 "WMWindowAttributes", WDWindowAttributes->path);
957 } else {
958 if (shared_dict) {
959 WMMergePLDictionaries(shared_dict, dict, True);
960 WMReleasePropList(dict);
961 dict = shared_dict;
962 shared_dict = NULL;
965 if (WDWindowAttributes->dictionary)
966 WMReleasePropList(WDWindowAttributes->dictionary);
968 WDWindowAttributes->dictionary = dict;
969 for (i = 0; i < wScreenCount; i++) {
970 scr = wScreenWithNumber(i);
971 if (scr) {
972 wDefaultUpdateIcons(scr);
974 /* Update the panel image if changed */
975 /* Don't worry. If the image is the same these
976 * functions will have no performance impact. */
977 create_logo_image(scr);
981 } else {
982 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
985 WDWindowAttributes->timestamp = stbuf.st_mtime;
986 if (shared_dict)
987 WMReleasePropList(shared_dict);
990 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
991 dict = WMReadPropListFromFile(WDRootMenu->path);
992 if (dict) {
993 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
994 WMReleasePropList(dict);
995 dict = NULL;
996 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
997 "WMRootMenu", WDRootMenu->path);
998 } else {
999 if (WDRootMenu->dictionary)
1000 WMReleasePropList(WDRootMenu->dictionary);
1002 WDRootMenu->dictionary = dict;
1003 wDefaultsMergeGlobalMenus(WDRootMenu);
1005 } else {
1006 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1008 WDRootMenu->timestamp = stbuf.st_mtime;
1010 #ifndef HAVE_INOTIFY
1011 if (!arg)
1012 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1013 #endif
1016 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1018 WMPropList *plvalue, *old_value;
1019 WDefaultEntry *entry;
1020 unsigned int i;
1021 int update_workspace_back = 0; /* kluge :/ */
1022 unsigned int needs_refresh;
1023 void *tdata;
1024 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1026 needs_refresh = 0;
1028 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1029 entry = &optionList[i];
1031 if (new_dict)
1032 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1033 else
1034 plvalue = NULL;
1036 if (!old_dict)
1037 old_value = NULL;
1038 else
1039 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1041 if (!plvalue && !old_value) {
1042 /* no default in the DB. Use builtin default */
1043 plvalue = entry->plvalue;
1044 if (plvalue && new_dict)
1045 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1047 } else if (!plvalue) {
1048 /* value was deleted from DB. Keep current value */
1049 continue;
1050 } else if (!old_value) {
1051 /* set value for the 1st time */
1052 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1053 /* value has changed */
1054 } else {
1055 if (strcmp(entry->key, "WorkspaceBack") == 0
1056 && update_workspace_back && scr->flags.backimage_helper_launched) {
1057 } else {
1058 /* value was not changed since last time */
1059 continue;
1063 if (plvalue) {
1064 /* convert data */
1065 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1067 * If the WorkspaceSpecificBack data has been changed
1068 * so that the helper will be launched now, we must be
1069 * sure to send the default background texture config
1070 * to the helper.
1072 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1073 !scr->flags.backimage_helper_launched)
1074 update_workspace_back = 1;
1076 if (entry->update)
1077 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1083 if (needs_refresh != 0 && !scr->flags.startup) {
1084 int foo;
1086 foo = 0;
1087 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1088 foo |= WTextureSettings;
1089 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1090 foo |= WFontSettings;
1091 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1092 foo |= WColorSettings;
1093 if (foo)
1094 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1095 (void *)(uintptr_t) foo);
1097 foo = 0;
1098 if (needs_refresh & REFRESH_MENU_TEXTURE)
1099 foo |= WTextureSettings;
1100 if (needs_refresh & REFRESH_MENU_FONT)
1101 foo |= WFontSettings;
1102 if (needs_refresh & REFRESH_MENU_COLOR)
1103 foo |= WColorSettings;
1104 if (foo)
1105 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1107 foo = 0;
1108 if (needs_refresh & REFRESH_WINDOW_FONT)
1109 foo |= WFontSettings;
1110 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1111 foo |= WTextureSettings;
1112 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1113 foo |= WColorSettings;
1114 if (foo)
1115 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1117 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1118 foo = 0;
1119 if (needs_refresh & REFRESH_ICON_FONT)
1120 foo |= WFontSettings;
1121 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1122 foo |= WTextureSettings;
1123 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1124 foo |= WTextureSettings;
1125 if (foo)
1126 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1127 (void *)(uintptr_t) foo);
1129 if (needs_refresh & REFRESH_ICON_TILE)
1130 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1134 void wDefaultUpdateIcons(WScreen *scr)
1136 WAppIcon *aicon = scr->app_icon_list;
1137 WDrawerChain *dc;
1138 WWindow *wwin = scr->focused_window;
1140 while (aicon) {
1141 /* Get the application icon, default included */
1142 wIconChangeImageFile(aicon->icon, NULL);
1143 wAppIconPaint(aicon);
1144 aicon = aicon->next;
1147 if (!wPreferences.flags.noclip)
1148 wClipIconPaint(scr->clip_icon);
1150 for (dc = scr->drawers; dc != NULL; dc = dc->next)
1151 wDrawerIconPaint(dc->adrawer->icon_array[0]);
1153 while (wwin) {
1154 if (wwin->icon && wwin->flags.miniaturized)
1155 wIconChangeImageFile(wwin->icon, NULL);
1156 wwin = wwin->prev;
1160 /* --------------------------- Local ----------------------- */
1162 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1163 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1164 entry->key, x); \
1165 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1166 var = entry->default_value;\
1167 } else var = WMGetFromPLString(value)\
1170 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1172 char *str;
1173 WOptionEnumeration *v;
1174 char buffer[TOTAL_VALUES_LENGTH];
1176 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1177 for (v = values; v->string != NULL; v++) {
1178 if (strcasecmp(v->string, str) == 0)
1179 return v->value;
1183 buffer[0] = 0;
1184 for (v = values; v->string != NULL; v++) {
1185 if (!v->is_alias) {
1186 if (buffer[0] != 0)
1187 strcat(buffer, ", ");
1188 snprintf(buffer+strlen(buffer),
1189 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1192 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1193 WMGetFromPLString(key),
1194 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1195 buffer);
1197 if (def) {
1198 return string2index(key, val, NULL, values);
1201 return -1;
1205 * value - is the value in the defaults DB
1206 * addr - is the address to store the data
1207 * ret - is the address to store a pointer to a temporary buffer. ret
1208 * must not be freed and is used by the set functions
1210 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1212 static char data;
1213 char *val;
1214 int second_pass = 0;
1216 GET_STRING_OR_DEFAULT("Boolean", val);
1218 again:
1219 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1220 || strcasecmp(val, "YES") == 0) {
1222 data = 1;
1223 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1224 || strcasecmp(val, "NO") == 0) {
1225 data = 0;
1226 } else {
1227 int i;
1228 if (sscanf(val, "%i", &i) == 1) {
1229 if (i != 0)
1230 data = 1;
1231 else
1232 data = 0;
1233 } else {
1234 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1235 if (second_pass == 0) {
1236 val = WMGetFromPLString(entry->plvalue);
1237 second_pass = 1;
1238 wwarning(_("using default \"%s\" instead"), val);
1239 goto again;
1241 return False;
1245 if (ret)
1246 *ret = &data;
1247 if (addr)
1248 *(char *)addr = data;
1250 return True;
1253 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1255 static int data;
1256 char *val;
1258 GET_STRING_OR_DEFAULT("Integer", val);
1260 if (sscanf(val, "%i", &data) != 1) {
1261 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1262 val = WMGetFromPLString(entry->plvalue);
1263 wwarning(_("using default \"%s\" instead"), val);
1264 if (sscanf(val, "%i", &data) != 1) {
1265 return False;
1269 if (ret)
1270 *ret = &data;
1271 if (addr)
1272 *(int *)addr = data;
1274 return True;
1277 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1279 static WCoord data;
1280 char *val_x, *val_y;
1281 int nelem, changed = 0;
1282 WMPropList *elem_x, *elem_y;
1284 again:
1285 if (!WMIsPLArray(value)) {
1286 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1287 if (changed == 0) {
1288 value = entry->plvalue;
1289 changed = 1;
1290 wwarning(_("using default \"%s\" instead"), entry->default_value);
1291 goto again;
1293 return False;
1296 nelem = WMGetPropListItemCount(value);
1297 if (nelem != 2) {
1298 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1299 if (changed == 0) {
1300 value = entry->plvalue;
1301 changed = 1;
1302 wwarning(_("using default \"%s\" instead"), entry->default_value);
1303 goto again;
1305 return False;
1308 elem_x = WMGetFromPLArray(value, 0);
1309 elem_y = WMGetFromPLArray(value, 1);
1311 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1312 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1313 if (changed == 0) {
1314 value = entry->plvalue;
1315 changed = 1;
1316 wwarning(_("using default \"%s\" instead"), entry->default_value);
1317 goto again;
1319 return False;
1322 val_x = WMGetFromPLString(elem_x);
1323 val_y = WMGetFromPLString(elem_y);
1325 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1326 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1327 if (changed == 0) {
1328 value = entry->plvalue;
1329 changed = 1;
1330 wwarning(_("using default \"%s\" instead"), entry->default_value);
1331 goto again;
1333 return False;
1336 if (data.x < 0)
1337 data.x = 0;
1338 else if (data.x > scr->scr_width / 3)
1339 data.x = scr->scr_width / 3;
1340 if (data.y < 0)
1341 data.y = 0;
1342 else if (data.y > scr->scr_height / 3)
1343 data.y = scr->scr_height / 3;
1345 if (ret)
1346 *ret = &data;
1347 if (addr)
1348 *(WCoord *) addr = data;
1350 return True;
1353 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1355 WMRetainPropList(value);
1357 *ret = value;
1359 return True;
1362 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1364 static char *data;
1365 int i, count, len;
1366 char *ptr;
1367 WMPropList *d;
1368 int changed = 0;
1370 again:
1371 if (!WMIsPLArray(value)) {
1372 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1373 if (changed == 0) {
1374 value = entry->plvalue;
1375 changed = 1;
1376 wwarning(_("using default \"%s\" instead"), entry->default_value);
1377 goto again;
1379 return False;
1382 i = 0;
1383 count = WMGetPropListItemCount(value);
1384 if (count < 1) {
1385 if (changed == 0) {
1386 value = entry->plvalue;
1387 changed = 1;
1388 wwarning(_("using default \"%s\" instead"), entry->default_value);
1389 goto again;
1391 return False;
1394 len = 0;
1395 for (i = 0; i < count; i++) {
1396 d = WMGetFromPLArray(value, i);
1397 if (!d || !WMIsPLString(d)) {
1398 count = i;
1399 break;
1401 len += strlen(WMGetFromPLString(d)) + 1;
1404 ptr = data = wmalloc(len + 1);
1406 for (i = 0; i < count; i++) {
1407 d = WMGetFromPLArray(value, i);
1408 if (!d || !WMIsPLString(d)) {
1409 break;
1411 strcpy(ptr, WMGetFromPLString(d));
1412 ptr += strlen(WMGetFromPLString(d));
1413 *ptr = ':';
1414 ptr++;
1416 ptr--;
1417 *(ptr--) = 0;
1419 if (*(char **)addr != NULL) {
1420 wfree(*(char **)addr);
1422 *(char **)addr = data;
1424 return True;
1427 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1429 static signed char data;
1431 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1432 if (data < 0)
1433 return False;
1435 if (ret)
1436 *ret = &data;
1437 if (addr)
1438 *(signed char *)addr = data;
1440 return True;
1444 * (solid <color>)
1445 * (hgradient <color> <color>)
1446 * (vgradient <color> <color>)
1447 * (dgradient <color> <color>)
1448 * (mhgradient <color> <color> ...)
1449 * (mvgradient <color> <color> ...)
1450 * (mdgradient <color> <color> ...)
1451 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1452 * (tpixmap <file> <color>)
1453 * (spixmap <file> <color>)
1454 * (cpixmap <file> <color>)
1455 * (thgradient <file> <opaqueness> <color> <color>)
1456 * (tvgradient <file> <opaqueness> <color> <color>)
1457 * (tdgradient <file> <opaqueness> <color> <color>)
1458 * (function <lib> <function> ...)
1461 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1463 WMPropList *elem;
1464 char *val;
1465 int nelem;
1466 WTexture *texture = NULL;
1468 nelem = WMGetPropListItemCount(pl);
1469 if (nelem < 1)
1470 return NULL;
1472 elem = WMGetFromPLArray(pl, 0);
1473 if (!elem || !WMIsPLString(elem))
1474 return NULL;
1475 val = WMGetFromPLString(elem);
1477 if (strcasecmp(val, "solid") == 0) {
1478 XColor color;
1480 if (nelem != 2)
1481 return NULL;
1483 /* get color */
1485 elem = WMGetFromPLArray(pl, 1);
1486 if (!elem || !WMIsPLString(elem))
1487 return NULL;
1488 val = WMGetFromPLString(elem);
1490 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1491 wwarning(_("\"%s\" is not a valid color name"), val);
1492 return NULL;
1495 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1496 } else if (strcasecmp(val, "dgradient") == 0
1497 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1498 RColor color1, color2;
1499 XColor xcolor;
1500 int type;
1502 if (nelem != 3) {
1503 wwarning(_("bad number of arguments in gradient specification"));
1504 return NULL;
1507 if (val[0] == 'd' || val[0] == 'D')
1508 type = WTEX_DGRADIENT;
1509 else if (val[0] == 'h' || val[0] == 'H')
1510 type = WTEX_HGRADIENT;
1511 else
1512 type = WTEX_VGRADIENT;
1514 /* get from color */
1515 elem = WMGetFromPLArray(pl, 1);
1516 if (!elem || !WMIsPLString(elem))
1517 return NULL;
1518 val = WMGetFromPLString(elem);
1520 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1521 wwarning(_("\"%s\" is not a valid color name"), val);
1522 return NULL;
1524 color1.alpha = 255;
1525 color1.red = xcolor.red >> 8;
1526 color1.green = xcolor.green >> 8;
1527 color1.blue = xcolor.blue >> 8;
1529 /* get to color */
1530 elem = WMGetFromPLArray(pl, 2);
1531 if (!elem || !WMIsPLString(elem)) {
1532 return NULL;
1534 val = WMGetFromPLString(elem);
1536 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1537 wwarning(_("\"%s\" is not a valid color name"), val);
1538 return NULL;
1540 color2.alpha = 255;
1541 color2.red = xcolor.red >> 8;
1542 color2.green = xcolor.green >> 8;
1543 color2.blue = xcolor.blue >> 8;
1545 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1547 } else if (strcasecmp(val, "igradient") == 0) {
1548 RColor colors1[2], colors2[2];
1549 int th1, th2;
1550 XColor xcolor;
1551 int i;
1553 if (nelem != 7) {
1554 wwarning(_("bad number of arguments in gradient specification"));
1555 return NULL;
1558 /* get from color */
1559 for (i = 0; i < 2; i++) {
1560 elem = WMGetFromPLArray(pl, 1 + i);
1561 if (!elem || !WMIsPLString(elem))
1562 return NULL;
1563 val = WMGetFromPLString(elem);
1565 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1566 wwarning(_("\"%s\" is not a valid color name"), val);
1567 return NULL;
1569 colors1[i].alpha = 255;
1570 colors1[i].red = xcolor.red >> 8;
1571 colors1[i].green = xcolor.green >> 8;
1572 colors1[i].blue = xcolor.blue >> 8;
1574 elem = WMGetFromPLArray(pl, 3);
1575 if (!elem || !WMIsPLString(elem))
1576 return NULL;
1577 val = WMGetFromPLString(elem);
1578 th1 = atoi(val);
1580 /* get from color */
1581 for (i = 0; i < 2; i++) {
1582 elem = WMGetFromPLArray(pl, 4 + 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 colors2[i].alpha = 255;
1592 colors2[i].red = xcolor.red >> 8;
1593 colors2[i].green = xcolor.green >> 8;
1594 colors2[i].blue = xcolor.blue >> 8;
1596 elem = WMGetFromPLArray(pl, 6);
1597 if (!elem || !WMIsPLString(elem))
1598 return NULL;
1599 val = WMGetFromPLString(elem);
1600 th2 = atoi(val);
1602 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1604 } else if (strcasecmp(val, "mhgradient") == 0
1605 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1606 XColor color;
1607 RColor **colors;
1608 int i, count;
1609 int type;
1611 if (nelem < 3) {
1612 wwarning(_("too few arguments in multicolor gradient specification"));
1613 return NULL;
1616 if (val[1] == 'h' || val[1] == 'H')
1617 type = WTEX_MHGRADIENT;
1618 else if (val[1] == 'v' || val[1] == 'V')
1619 type = WTEX_MVGRADIENT;
1620 else
1621 type = WTEX_MDGRADIENT;
1623 count = nelem - 1;
1625 colors = wmalloc(sizeof(RColor *) * (count + 1));
1627 for (i = 0; i < count; i++) {
1628 elem = WMGetFromPLArray(pl, i + 1);
1629 if (!elem || !WMIsPLString(elem)) {
1630 for (--i; i >= 0; --i) {
1631 wfree(colors[i]);
1633 wfree(colors);
1634 return NULL;
1636 val = WMGetFromPLString(elem);
1638 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1639 wwarning(_("\"%s\" is not a valid color name"), val);
1640 for (--i; i >= 0; --i) {
1641 wfree(colors[i]);
1643 wfree(colors);
1644 return NULL;
1645 } else {
1646 colors[i] = wmalloc(sizeof(RColor));
1647 colors[i]->red = color.red >> 8;
1648 colors[i]->green = color.green >> 8;
1649 colors[i]->blue = color.blue >> 8;
1652 colors[i] = NULL;
1654 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1655 } else if (strcasecmp(val, "spixmap") == 0 ||
1656 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1657 XColor color;
1658 int type;
1660 if (nelem != 3)
1661 return NULL;
1663 if (val[0] == 's' || val[0] == 'S')
1664 type = WTP_SCALE;
1665 else if (val[0] == 'c' || val[0] == 'C')
1666 type = WTP_CENTER;
1667 else
1668 type = WTP_TILE;
1670 /* get color */
1671 elem = WMGetFromPLArray(pl, 2);
1672 if (!elem || !WMIsPLString(elem)) {
1673 return NULL;
1675 val = WMGetFromPLString(elem);
1677 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1678 wwarning(_("\"%s\" is not a valid color name"), val);
1679 return NULL;
1682 /* file name */
1683 elem = WMGetFromPLArray(pl, 1);
1684 if (!elem || !WMIsPLString(elem))
1685 return NULL;
1686 val = WMGetFromPLString(elem);
1688 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1689 } else if (strcasecmp(val, "thgradient") == 0
1690 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1691 RColor color1, color2;
1692 XColor xcolor;
1693 int opacity;
1694 int style;
1696 if (val[1] == 'h' || val[1] == 'H')
1697 style = WTEX_THGRADIENT;
1698 else if (val[1] == 'v' || val[1] == 'V')
1699 style = WTEX_TVGRADIENT;
1700 else
1701 style = WTEX_TDGRADIENT;
1703 if (nelem != 5) {
1704 wwarning(_("bad number of arguments in textured gradient specification"));
1705 return NULL;
1708 /* get from color */
1709 elem = WMGetFromPLArray(pl, 3);
1710 if (!elem || !WMIsPLString(elem))
1711 return NULL;
1712 val = WMGetFromPLString(elem);
1714 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1715 wwarning(_("\"%s\" is not a valid color name"), val);
1716 return NULL;
1718 color1.alpha = 255;
1719 color1.red = xcolor.red >> 8;
1720 color1.green = xcolor.green >> 8;
1721 color1.blue = xcolor.blue >> 8;
1723 /* get to color */
1724 elem = WMGetFromPLArray(pl, 4);
1725 if (!elem || !WMIsPLString(elem)) {
1726 return NULL;
1728 val = WMGetFromPLString(elem);
1730 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1731 wwarning(_("\"%s\" is not a valid color name"), val);
1732 return NULL;
1734 color2.alpha = 255;
1735 color2.red = xcolor.red >> 8;
1736 color2.green = xcolor.green >> 8;
1737 color2.blue = xcolor.blue >> 8;
1739 /* get opacity */
1740 elem = WMGetFromPLArray(pl, 2);
1741 if (!elem || !WMIsPLString(elem))
1742 opacity = 128;
1743 else
1744 val = WMGetFromPLString(elem);
1746 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1747 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1748 opacity = 128;
1751 /* get file name */
1752 elem = WMGetFromPLArray(pl, 1);
1753 if (!elem || !WMIsPLString(elem))
1754 return NULL;
1755 val = WMGetFromPLString(elem);
1757 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1758 } else if (strcasecmp(val, "function") == 0) {
1759 /* Leave this in to handle the unlikely case of
1760 * someone actually having function textures configured */
1761 wwarning("function texture support has been removed");
1762 return NULL;
1763 } else {
1764 wwarning(_("invalid texture type %s"), val);
1765 return NULL;
1767 return texture;
1770 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1772 static WTexture *texture;
1773 int changed = 0;
1775 again:
1776 if (!WMIsPLArray(value)) {
1777 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1778 if (changed == 0) {
1779 value = entry->plvalue;
1780 changed = 1;
1781 wwarning(_("using default \"%s\" instead"), entry->default_value);
1782 goto again;
1784 return False;
1787 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1788 WMPropList *pl;
1790 pl = WMGetFromPLArray(value, 0);
1791 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1792 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1793 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1794 entry->key, "Solid Texture");
1796 value = entry->plvalue;
1797 changed = 1;
1798 wwarning(_("using default \"%s\" instead"), entry->default_value);
1799 goto again;
1803 texture = parse_texture(scr, value);
1805 if (!texture) {
1806 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1807 if (changed == 0) {
1808 value = entry->plvalue;
1809 changed = 1;
1810 wwarning(_("using default \"%s\" instead"), entry->default_value);
1811 goto again;
1813 return False;
1816 if (ret)
1817 *ret = &texture;
1819 if (addr)
1820 *(WTexture **) addr = texture;
1822 return True;
1825 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1827 WMPropList *elem;
1828 int changed = 0;
1829 char *val;
1830 int nelem;
1832 again:
1833 if (!WMIsPLArray(value)) {
1834 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1835 "WorkspaceBack", "Texture or None");
1836 if (changed == 0) {
1837 value = entry->plvalue;
1838 changed = 1;
1839 wwarning(_("using default \"%s\" instead"), entry->default_value);
1840 goto again;
1842 return False;
1845 /* only do basic error checking and verify for None texture */
1847 nelem = WMGetPropListItemCount(value);
1848 if (nelem > 0) {
1849 elem = WMGetFromPLArray(value, 0);
1850 if (!elem || !WMIsPLString(elem)) {
1851 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1852 if (changed == 0) {
1853 value = entry->plvalue;
1854 changed = 1;
1855 wwarning(_("using default \"%s\" instead"), entry->default_value);
1856 goto again;
1858 return False;
1860 val = WMGetFromPLString(elem);
1862 if (strcasecmp(val, "None") == 0)
1863 return True;
1865 *ret = WMRetainPropList(value);
1867 return True;
1870 static int
1871 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1873 WMPropList *elem;
1874 int nelem;
1875 int changed = 0;
1877 again:
1878 if (!WMIsPLArray(value)) {
1879 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1880 "WorkspaceSpecificBack", "an array of textures");
1881 if (changed == 0) {
1882 value = entry->plvalue;
1883 changed = 1;
1884 wwarning(_("using default \"%s\" instead"), entry->default_value);
1885 goto again;
1887 return False;
1890 /* only do basic error checking and verify for None texture */
1892 nelem = WMGetPropListItemCount(value);
1893 if (nelem > 0) {
1894 while (nelem--) {
1895 elem = WMGetFromPLArray(value, nelem);
1896 if (!elem || !WMIsPLArray(elem)) {
1897 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1898 nelem);
1903 *ret = WMRetainPropList(value);
1905 #ifdef notworking
1907 * Kluge to force wmsetbg helper to set the default background.
1908 * If the WorkspaceSpecificBack is changed once wmaker has started,
1909 * the WorkspaceBack won't be sent to the helper, unless the user
1910 * changes it's value too. So, we must force this by removing the
1911 * value from the defaults DB.
1913 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1914 WMPropList *key = WMCreatePLString("WorkspaceBack");
1916 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1918 WMReleasePropList(key);
1920 #endif
1921 return True;
1924 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1926 static WMFont *font;
1927 char *val;
1929 GET_STRING_OR_DEFAULT("Font", val);
1931 font = WMCreateFont(scr->wmscreen, val);
1932 if (!font)
1933 font = WMCreateFont(scr->wmscreen, "fixed");
1935 if (!font) {
1936 wfatal(_("could not load any usable font!!!"));
1937 exit(1);
1940 if (ret)
1941 *ret = font;
1943 /* can't assign font value outside update function */
1944 wassertrv(addr == NULL, True);
1946 return True;
1949 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1951 static XColor color;
1952 char *val;
1953 int second_pass = 0;
1955 GET_STRING_OR_DEFAULT("Color", val);
1957 again:
1958 if (!wGetColor(scr, val, &color)) {
1959 wwarning(_("could not get color for key \"%s\""), entry->key);
1960 if (second_pass == 0) {
1961 val = WMGetFromPLString(entry->plvalue);
1962 second_pass = 1;
1963 wwarning(_("using default \"%s\" instead"), val);
1964 goto again;
1966 return False;
1969 if (ret)
1970 *ret = &color;
1972 assert(addr == NULL);
1974 if (addr)
1975 *(unsigned long*)addr = pixel;
1978 return True;
1981 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1983 static WShortKey shortcut;
1984 KeySym ksym;
1985 char *val;
1986 char *k;
1987 char buf[MAX_SHORTCUT_LENGTH], *b;
1989 GET_STRING_OR_DEFAULT("Key spec", val);
1991 if (!val || strcasecmp(val, "NONE") == 0) {
1992 shortcut.keycode = 0;
1993 shortcut.modifier = 0;
1994 if (ret)
1995 *ret = &shortcut;
1996 return True;
1999 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2001 b = (char *)buf;
2003 /* get modifiers */
2004 shortcut.modifier = 0;
2005 while ((k = strchr(b, '+')) != NULL) {
2006 int mod;
2008 *k = 0;
2009 mod = wXModifierFromKey(b);
2010 if (mod < 0) {
2011 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2012 return False;
2014 shortcut.modifier |= mod;
2016 b = k + 1;
2019 /* get key */
2020 ksym = XStringToKeysym(b);
2022 if (ksym == NoSymbol) {
2023 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2024 return False;
2027 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2028 if (shortcut.keycode == 0) {
2029 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2030 return False;
2033 if (ret)
2034 *ret = &shortcut;
2036 return True;
2039 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2041 static int mask;
2042 char *str;
2044 GET_STRING_OR_DEFAULT("Modifier Key", str);
2046 if (!str)
2047 return False;
2049 mask = wXModifierFromKey(str);
2050 if (mask < 0) {
2051 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2052 mask = 0;
2053 return False;
2056 if (addr)
2057 *(int *)addr = mask;
2059 if (ret)
2060 *ret = &mask;
2062 return True;
2065 # include <X11/cursorfont.h>
2066 typedef struct {
2067 char *name;
2068 int id;
2069 } WCursorLookup;
2071 #define CURSOR_ID_NONE (XC_num_glyphs)
2073 static WCursorLookup cursor_table[] = {
2074 {"X_cursor", XC_X_cursor},
2075 {"arrow", XC_arrow},
2076 {"based_arrow_down", XC_based_arrow_down},
2077 {"based_arrow_up", XC_based_arrow_up},
2078 {"boat", XC_boat},
2079 {"bogosity", XC_bogosity},
2080 {"bottom_left_corner", XC_bottom_left_corner},
2081 {"bottom_right_corner", XC_bottom_right_corner},
2082 {"bottom_side", XC_bottom_side},
2083 {"bottom_tee", XC_bottom_tee},
2084 {"box_spiral", XC_box_spiral},
2085 {"center_ptr", XC_center_ptr},
2086 {"circle", XC_circle},
2087 {"clock", XC_clock},
2088 {"coffee_mug", XC_coffee_mug},
2089 {"cross", XC_cross},
2090 {"cross_reverse", XC_cross_reverse},
2091 {"crosshair", XC_crosshair},
2092 {"diamond_cross", XC_diamond_cross},
2093 {"dot", XC_dot},
2094 {"dotbox", XC_dotbox},
2095 {"double_arrow", XC_double_arrow},
2096 {"draft_large", XC_draft_large},
2097 {"draft_small", XC_draft_small},
2098 {"draped_box", XC_draped_box},
2099 {"exchange", XC_exchange},
2100 {"fleur", XC_fleur},
2101 {"gobbler", XC_gobbler},
2102 {"gumby", XC_gumby},
2103 {"hand1", XC_hand1},
2104 {"hand2", XC_hand2},
2105 {"heart", XC_heart},
2106 {"icon", XC_icon},
2107 {"iron_cross", XC_iron_cross},
2108 {"left_ptr", XC_left_ptr},
2109 {"left_side", XC_left_side},
2110 {"left_tee", XC_left_tee},
2111 {"leftbutton", XC_leftbutton},
2112 {"ll_angle", XC_ll_angle},
2113 {"lr_angle", XC_lr_angle},
2114 {"man", XC_man},
2115 {"middlebutton", XC_middlebutton},
2116 {"mouse", XC_mouse},
2117 {"pencil", XC_pencil},
2118 {"pirate", XC_pirate},
2119 {"plus", XC_plus},
2120 {"question_arrow", XC_question_arrow},
2121 {"right_ptr", XC_right_ptr},
2122 {"right_side", XC_right_side},
2123 {"right_tee", XC_right_tee},
2124 {"rightbutton", XC_rightbutton},
2125 {"rtl_logo", XC_rtl_logo},
2126 {"sailboat", XC_sailboat},
2127 {"sb_down_arrow", XC_sb_down_arrow},
2128 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2129 {"sb_left_arrow", XC_sb_left_arrow},
2130 {"sb_right_arrow", XC_sb_right_arrow},
2131 {"sb_up_arrow", XC_sb_up_arrow},
2132 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2133 {"shuttle", XC_shuttle},
2134 {"sizing", XC_sizing},
2135 {"spider", XC_spider},
2136 {"spraycan", XC_spraycan},
2137 {"star", XC_star},
2138 {"target", XC_target},
2139 {"tcross", XC_tcross},
2140 {"top_left_arrow", XC_top_left_arrow},
2141 {"top_left_corner", XC_top_left_corner},
2142 {"top_right_corner", XC_top_right_corner},
2143 {"top_side", XC_top_side},
2144 {"top_tee", XC_top_tee},
2145 {"trek", XC_trek},
2146 {"ul_angle", XC_ul_angle},
2147 {"umbrella", XC_umbrella},
2148 {"ur_angle", XC_ur_angle},
2149 {"watch", XC_watch},
2150 {"xterm", XC_xterm},
2151 {NULL, CURSOR_ID_NONE}
2154 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2156 switch (status) {
2157 case BitmapOpenFailed:
2158 wwarning(_("failed to open bitmap file \"%s\""), filename);
2159 break;
2160 case BitmapFileInvalid:
2161 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2162 break;
2163 case BitmapNoMemory:
2164 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2165 break;
2166 case BitmapSuccess:
2167 XFreePixmap(dpy, bitmap);
2168 break;
2173 * (none)
2174 * (builtin, <cursor_name>)
2175 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2177 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2179 WMPropList *elem;
2180 char *val;
2181 int nelem;
2182 int status = 0;
2184 nelem = WMGetPropListItemCount(pl);
2185 if (nelem < 1) {
2186 return (status);
2188 elem = WMGetFromPLArray(pl, 0);
2189 if (!elem || !WMIsPLString(elem)) {
2190 return (status);
2192 val = WMGetFromPLString(elem);
2194 if (strcasecmp(val, "none") == 0) {
2195 status = 1;
2196 *cursor = None;
2197 } else if (strcasecmp(val, "builtin") == 0) {
2198 int i;
2199 int cursor_id = CURSOR_ID_NONE;
2201 if (nelem != 2) {
2202 wwarning(_("bad number of arguments in cursor specification"));
2203 return (status);
2205 elem = WMGetFromPLArray(pl, 1);
2206 if (!elem || !WMIsPLString(elem)) {
2207 return (status);
2209 val = WMGetFromPLString(elem);
2211 for (i = 0; cursor_table[i].name != NULL; i++) {
2212 if (strcasecmp(val, cursor_table[i].name) == 0) {
2213 cursor_id = cursor_table[i].id;
2214 break;
2217 if (CURSOR_ID_NONE == cursor_id) {
2218 wwarning(_("unknown builtin cursor name \"%s\""), val);
2219 } else {
2220 *cursor = XCreateFontCursor(dpy, cursor_id);
2221 status = 1;
2223 } else if (strcasecmp(val, "bitmap") == 0) {
2224 char *bitmap_name;
2225 char *mask_name;
2226 int bitmap_status;
2227 int mask_status;
2228 Pixmap bitmap;
2229 Pixmap mask;
2230 unsigned int w, h;
2231 int x, y;
2232 XColor fg, bg;
2234 if (nelem != 3) {
2235 wwarning(_("bad number of arguments in cursor specification"));
2236 return (status);
2238 elem = WMGetFromPLArray(pl, 1);
2239 if (!elem || !WMIsPLString(elem)) {
2240 return (status);
2242 val = WMGetFromPLString(elem);
2243 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2244 if (!bitmap_name) {
2245 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2246 return (status);
2248 elem = WMGetFromPLArray(pl, 2);
2249 if (!elem || !WMIsPLString(elem)) {
2250 wfree(bitmap_name);
2251 return (status);
2253 val = WMGetFromPLString(elem);
2254 mask_name = FindImage(wPreferences.pixmap_path, val);
2255 if (!mask_name) {
2256 wfree(bitmap_name);
2257 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2258 return (status);
2260 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2261 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2262 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2263 fg.pixel = scr->black_pixel;
2264 bg.pixel = scr->white_pixel;
2265 XQueryColor(dpy, scr->w_colormap, &fg);
2266 XQueryColor(dpy, scr->w_colormap, &bg);
2267 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2268 status = 1;
2270 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2271 check_bitmap_status(mask_status, mask_name, mask);
2272 wfree(bitmap_name);
2273 wfree(mask_name);
2275 return (status);
2278 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2280 static Cursor cursor;
2281 int status;
2282 int changed = 0;
2284 again:
2285 if (!WMIsPLArray(value)) {
2286 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2287 entry->key, "cursor specification");
2288 if (!changed) {
2289 value = entry->plvalue;
2290 changed = 1;
2291 wwarning(_("using default \"%s\" instead"), entry->default_value);
2292 goto again;
2294 return (False);
2296 status = parse_cursor(scr, value, &cursor);
2297 if (!status) {
2298 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2299 if (!changed) {
2300 value = entry->plvalue;
2301 changed = 1;
2302 wwarning(_("using default \"%s\" instead"), entry->default_value);
2303 goto again;
2305 return (False);
2307 if (ret) {
2308 *ret = &cursor;
2310 if (addr) {
2311 *(Cursor *) addr = cursor;
2313 return (True);
2316 #undef CURSOR_ID_NONE
2318 /* ---------------- value setting functions --------------- */
2319 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2321 return REFRESH_WINDOW_TITLE_COLOR;
2324 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2326 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2329 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2331 switch (which) {
2332 case WM_DOCK:
2333 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2334 // Drawers require the dock
2335 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || wPreferences.flags.nodock;
2336 break;
2337 case WM_CLIP:
2338 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2339 break;
2340 case WM_DRAWER:
2341 wPreferences.flags.nodrawer = wPreferences.flags.nodrawer || *flag;
2342 break;
2343 default:
2344 break;
2346 return 0;
2349 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2351 if (scr->workspaces) {
2352 wWorkspaceForceChange(scr, scr->current_workspace);
2353 wArrangeIcons(scr, False);
2355 return 0;
2358 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2360 Pixmap pixmap;
2361 RImage *img;
2362 int reset = 0;
2364 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2365 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2366 ? WREL_ICON : WREL_FLAT);
2367 if (!img) {
2368 wwarning(_("could not render texture for icon background"));
2369 if (!entry->addr)
2370 wTextureDestroy(scr, *texture);
2371 return 0;
2373 RConvertImage(scr->rcontext, img, &pixmap);
2375 if (scr->icon_tile) {
2376 reset = 1;
2377 RReleaseImage(scr->icon_tile);
2378 XFreePixmap(dpy, scr->icon_tile_pixmap);
2381 scr->icon_tile = img;
2383 /* put the icon in the noticeboard hint */
2384 PropSetIconTileHint(scr, img);
2386 if (!wPreferences.flags.noclip) {
2387 if (scr->clip_tile) {
2388 RReleaseImage(scr->clip_tile);
2390 scr->clip_tile = wClipMakeTile(scr, img);
2393 if (!wPreferences.flags.nodrawer) {
2394 if (scr->drawer_tile) {
2395 RReleaseImage(scr->drawer_tile);
2397 scr->drawer_tile = wDrawerMakeTile(scr, img);
2400 scr->icon_tile_pixmap = pixmap;
2402 if (scr->def_icon_rimage) {
2403 RReleaseImage(scr->def_icon_rimage);
2404 scr->def_icon_rimage = NULL;
2407 if (scr->icon_back_texture)
2408 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2410 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2412 if (scr->clip_balloon)
2413 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2416 * Free the texture as nobody else will use it, nor refer to it.
2418 if (!entry->addr)
2419 wTextureDestroy(scr, *texture);
2421 return (reset ? REFRESH_ICON_TILE : 0);
2424 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2426 if (scr->title_font) {
2427 WMReleaseFont(scr->title_font);
2429 scr->title_font = font;
2431 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2434 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2436 if (scr->menu_title_font) {
2437 WMReleaseFont(scr->menu_title_font);
2440 scr->menu_title_font = font;
2442 return REFRESH_MENU_TITLE_FONT;
2445 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2447 if (scr->menu_entry_font) {
2448 WMReleaseFont(scr->menu_entry_font);
2450 scr->menu_entry_font = font;
2452 return REFRESH_MENU_FONT;
2455 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2457 if (scr->icon_title_font) {
2458 WMReleaseFont(scr->icon_title_font);
2461 scr->icon_title_font = font;
2463 return REFRESH_ICON_FONT;
2466 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2468 if (scr->clip_title_font) {
2469 WMReleaseFont(scr->clip_title_font);
2472 scr->clip_title_font = font;
2474 return REFRESH_ICON_FONT;
2477 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2479 if (scr->workspace_name_font) {
2480 WMReleaseFont(scr->workspace_name_font);
2483 scr->workspace_name_font = font;
2485 return 0;
2488 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2490 if (scr->select_color)
2491 WMReleaseColor(scr->select_color);
2493 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2495 wFreeColor(scr, color->pixel);
2497 return REFRESH_MENU_COLOR;
2500 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2502 if (scr->select_text_color)
2503 WMReleaseColor(scr->select_text_color);
2505 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2507 wFreeColor(scr, color->pixel);
2509 return REFRESH_MENU_COLOR;
2512 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2514 if (scr->clip_title_color[widx])
2515 WMReleaseColor(scr->clip_title_color[widx]);
2517 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2518 wFreeColor(scr, color->pixel);
2520 return REFRESH_ICON_TITLE_COLOR;
2523 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2525 if (scr->window_title_color[widx])
2526 WMReleaseColor(scr->window_title_color[widx]);
2528 scr->window_title_color[widx] =
2529 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2531 wFreeColor(scr, color->pixel);
2533 return REFRESH_WINDOW_TITLE_COLOR;
2536 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2538 if (scr->menu_title_color[0])
2539 WMReleaseColor(scr->menu_title_color[0]);
2541 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2543 wFreeColor(scr, color->pixel);
2545 return REFRESH_MENU_TITLE_COLOR;
2548 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2550 if (scr->mtext_color)
2551 WMReleaseColor(scr->mtext_color);
2553 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2555 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2556 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2557 } else {
2558 WMSetColorAlpha(scr->dtext_color, 0xffff);
2561 wFreeColor(scr, color->pixel);
2563 return REFRESH_MENU_COLOR;
2566 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2568 if (scr->dtext_color)
2569 WMReleaseColor(scr->dtext_color);
2571 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2573 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2574 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2575 } else {
2576 WMSetColorAlpha(scr->dtext_color, 0xffff);
2579 wFreeColor(scr, color->pixel);
2581 return REFRESH_MENU_COLOR;
2584 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2586 if (scr->icon_title_color)
2587 WMReleaseColor(scr->icon_title_color);
2588 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2590 wFreeColor(scr, color->pixel);
2592 return REFRESH_ICON_TITLE_COLOR;
2595 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2597 if (scr->icon_title_texture) {
2598 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2600 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2602 return REFRESH_ICON_TITLE_BACK;
2605 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2607 close(scr->helper_fd);
2608 scr->helper_fd = 0;
2609 scr->helper_pid = 0;
2610 scr->flags.backimage_helper_launched = 0;
2613 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2615 WMPropList *val;
2616 char *str;
2617 int i;
2619 if (scr->flags.backimage_helper_launched) {
2620 if (WMGetPropListItemCount(value) == 0) {
2621 SendHelperMessage(scr, 'C', 0, NULL);
2622 SendHelperMessage(scr, 'K', 0, NULL);
2624 WMReleasePropList(value);
2625 return 0;
2627 } else {
2628 pid_t pid;
2629 int filedes[2];
2631 if (WMGetPropListItemCount(value) == 0)
2632 return 0;
2634 if (pipe(filedes) < 0) {
2635 werror("pipe() failed:can't set workspace specific background image");
2637 WMReleasePropList(value);
2638 return 0;
2641 pid = fork();
2642 if (pid < 0) {
2643 werror("fork() failed:can't set workspace specific background image");
2644 if (close(filedes[0]) < 0)
2645 werror("could not close pipe");
2646 if (close(filedes[1]) < 0)
2647 werror("could not close pipe");
2649 } else if (pid == 0) {
2650 char *dither;
2652 SetupEnvironment(scr);
2654 if (close(0) < 0)
2655 werror("could not close pipe");
2656 if (dup(filedes[0]) < 0) {
2657 werror("dup() failed:can't set workspace specific background image");
2659 dither = wPreferences.no_dithering ? "-m" : "-d";
2660 if (wPreferences.smooth_workspace_back)
2661 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2662 else
2663 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2664 werror("could not execute wmsetbg");
2665 exit(1);
2666 } else {
2668 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2669 werror("error setting close-on-exec flag");
2671 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2672 werror("error setting close-on-exec flag");
2675 scr->helper_fd = filedes[1];
2676 scr->helper_pid = pid;
2677 scr->flags.backimage_helper_launched = 1;
2679 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2681 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2686 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2687 val = WMGetFromPLArray(value, i);
2688 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2689 str = WMGetPropListDescription(val, False);
2691 SendHelperMessage(scr, 'S', i + 1, str);
2693 wfree(str);
2694 } else {
2695 SendHelperMessage(scr, 'U', i + 1, NULL);
2698 sleep(1);
2700 WMReleasePropList(value);
2701 return 0;
2704 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2706 if (scr->flags.backimage_helper_launched) {
2707 char *str;
2709 if (WMGetPropListItemCount(value) == 0) {
2710 SendHelperMessage(scr, 'U', 0, NULL);
2711 } else {
2712 /* set the default workspace background to this one */
2713 str = WMGetPropListDescription(value, False);
2714 if (str) {
2715 SendHelperMessage(scr, 'S', 0, str);
2716 wfree(str);
2717 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2718 } else {
2719 SendHelperMessage(scr, 'U', 0, NULL);
2722 } else if (WMGetPropListItemCount(value) > 0) {
2723 char *command;
2724 char *text;
2725 char *dither;
2726 int len;
2728 text = WMGetPropListDescription(value, False);
2729 len = strlen(text) + 40;
2730 command = wmalloc(len);
2731 dither = wPreferences.no_dithering ? "-m" : "-d";
2732 if (wPreferences.smooth_workspace_back)
2733 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2734 else
2735 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2736 wfree(text);
2737 ExecuteShellCommand(scr, command);
2738 wfree(command);
2740 WMReleasePropList(value);
2742 return 0;
2745 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2747 if (scr->widget_texture) {
2748 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2750 scr->widget_texture = *(WTexSolid **) texture;
2752 return 0;
2755 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2757 if (scr->window_title_texture[WS_FOCUSED]) {
2758 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2760 scr->window_title_texture[WS_FOCUSED] = *texture;
2762 return REFRESH_WINDOW_TEXTURES;
2765 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2767 if (scr->window_title_texture[WS_PFOCUSED]) {
2768 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2770 scr->window_title_texture[WS_PFOCUSED] = *texture;
2772 return REFRESH_WINDOW_TEXTURES;
2775 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2777 if (scr->window_title_texture[WS_UNFOCUSED]) {
2778 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2780 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2782 return REFRESH_WINDOW_TEXTURES;
2785 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2787 if (scr->resizebar_texture[0]) {
2788 wTextureDestroy(scr, scr->resizebar_texture[0]);
2790 scr->resizebar_texture[0] = *texture;
2792 return REFRESH_WINDOW_TEXTURES;
2795 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2797 if (scr->menu_title_texture[0]) {
2798 wTextureDestroy(scr, scr->menu_title_texture[0]);
2800 scr->menu_title_texture[0] = *texture;
2802 return REFRESH_MENU_TITLE_TEXTURE;
2805 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2807 if (scr->menu_item_texture) {
2808 wTextureDestroy(scr, scr->menu_item_texture);
2809 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2811 scr->menu_item_texture = *texture;
2813 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2815 return REFRESH_MENU_TEXTURE;
2818 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2820 WWindow *wwin;
2821 wKeyBindings[widx] = *shortcut;
2823 wwin = scr->focused_window;
2825 while (wwin != NULL) {
2826 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2828 if (!WFLAGP(wwin, no_bind_keys)) {
2829 wWindowSetKeyGrabs(wwin);
2831 wwin = wwin->prev;
2834 return 0;
2837 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2839 wScreenUpdateUsableArea(scr);
2840 wArrangeIcons(scr, True);
2842 return 0;
2845 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2847 wScreenUpdateUsableArea(scr);
2849 return 0;
2852 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2854 return REFRESH_MENU_TEXTURE;
2857 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2859 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2861 RCopyArea(img, image, x, y, w, h, 0, 0);
2863 return img;
2866 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2868 char *path;
2869 RImage *bgimage;
2870 int cwidth, cheight;
2871 WPreferences *prefs = (WPreferences *) foo;
2873 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2874 if (prefs->swtileImage)
2875 RReleaseImage(prefs->swtileImage);
2876 prefs->swtileImage = NULL;
2878 WMReleasePropList(array);
2879 return 0;
2882 switch (WMGetPropListItemCount(array)) {
2883 case 4:
2884 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2885 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2886 break;
2887 } else
2888 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2890 if (!path) {
2891 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2892 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2893 } else {
2894 bgimage = RLoadImage(scr->rcontext, path, 0);
2895 if (!bgimage) {
2896 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2897 wfree(path);
2898 } else {
2899 wfree(path);
2901 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2902 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2904 if (cwidth <= 0 || cheight <= 0 ||
2905 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2906 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2907 else {
2908 int i;
2909 int swidth, theight;
2910 for (i = 0; i < 9; i++) {
2911 if (prefs->swbackImage[i])
2912 RReleaseImage(prefs->swbackImage[i]);
2913 prefs->swbackImage[i] = NULL;
2915 swidth = (bgimage->width - cwidth) / 2;
2916 theight = (bgimage->height - cheight) / 2;
2918 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2919 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2920 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2921 swidth, theight);
2923 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2924 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2925 cwidth, cheight);
2926 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2927 swidth, cheight);
2929 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2930 swidth, theight);
2931 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2932 cwidth, theight);
2933 prefs->swbackImage[8] =
2934 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2935 theight);
2937 // check if anything failed
2938 for (i = 0; i < 9; i++) {
2939 if (!prefs->swbackImage[i]) {
2940 for (; i >= 0; --i) {
2941 RReleaseImage(prefs->swbackImage[i]);
2942 prefs->swbackImage[i] = NULL;
2944 break;
2948 RReleaseImage(bgimage);
2952 case 1:
2953 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
2954 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2955 break;
2956 } else
2957 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
2959 if (!path) {
2960 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2961 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
2962 } else {
2963 if (prefs->swtileImage)
2964 RReleaseImage(prefs->swtileImage);
2966 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
2967 if (!prefs->swtileImage) {
2968 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2970 wfree(path);
2972 break;
2974 default:
2975 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
2976 break;
2979 WMReleasePropList(array);
2981 return 0;
2984 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2986 int i;
2987 WPreferences *prefs = (WPreferences *) foo;
2989 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
2990 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
2991 WMReleasePropList(array);
2992 return 0;
2995 DestroyWindowMenu(scr);
2997 for (i = 0; i < 7; i++) {
2998 if (prefs->modifier_labels[i])
2999 wfree(prefs->modifier_labels[i]);
3001 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3002 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3003 } else {
3004 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3005 prefs->modifier_labels[i] = NULL;
3009 WMReleasePropList(array);
3011 return 0;
3014 static int setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3016 if (*value <= 0)
3017 *(int *)foo = 1;
3019 W_setconf_doubleClickDelay(*value);
3021 return 0;
3024 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3026 if (wCursor[widx] != None) {
3027 XFreeCursor(dpy, wCursor[widx]);
3030 wCursor[widx] = *cursor;
3032 if (widx == WCUR_ROOT && *cursor != None) {
3033 XDefineCursor(dpy, scr->root_win, *cursor);
3036 return 0;