Fix Maximize/Unmaximize in window menu
[wmaker-crm.git] / src / defaults.c
blobe8c33e05141b4e34d0fcd0ed1181c74af024805a
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <strings.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifndef PATH_MAX
40 #define PATH_MAX DEFAULT_PATH_MAX
41 #endif
43 #include <X11/Xlib.h>
44 #include <X11/Xutil.h>
45 #include <X11/keysym.h>
47 #include <wraster.h>
49 #include "WindowMaker.h"
50 #include "framewin.h"
51 #include "window.h"
52 #include "texture.h"
53 #include "screen.h"
54 #include "resources.h"
55 #include "defaults.h"
56 #include "keybind.h"
57 #include "xmodifier.h"
58 #include "icon.h"
59 #include "main.h"
60 #include "actions.h"
61 #include "dock.h"
62 #include "workspace.h"
63 #include "properties.h"
65 #define MAX_SHORTCUT_LENGTH 32
67 #ifndef GLOBAL_DEFAULTS_SUBDIR
68 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
69 #endif
71 /***** Global *****/
72 extern WDDomain *WDWindowMaker;
73 extern WDDomain *WDWindowAttributes;
74 extern WDDomain *WDRootMenu;
75 extern int wScreenCount;
76 extern WPreferences wPreferences;
77 extern WShortKey wKeyBindings[WKBD_LAST];
79 typedef struct {
80 char *key;
81 char *default_value;
82 void *extra_data;
83 void *addr;
84 int (*convert) ();
85 int (*update) ();
86 WMPropList *plkey;
87 WMPropList *plvalue; /* default value */
88 } WDefaultEntry;
90 /* used to map strings to integers */
91 typedef struct {
92 char *string;
93 short value;
94 char is_alias;
95 } WOptionEnumeration;
97 /* type converters */
98 static int getBool();
99 static int getInt();
100 static int getCoord();
101 static int getPathList();
102 static int getEnum();
103 static int getTexture();
104 static int getWSBackground();
105 static int getWSSpecificBackground();
106 static int getFont();
107 static int getColor();
108 static int getKeybind();
109 static int getModMask();
110 static int getPropList();
112 /* value setting functions */
113 static int setJustify();
114 static int setClearance();
115 static int setIfDockPresent();
116 static int setStickyIcons();
117 static int setWidgetColor();
118 static int setIconTile();
119 static int setWinTitleFont();
120 static int setMenuTitleFont();
121 static int setMenuTextFont();
122 static int setIconTitleFont();
123 static int setIconTitleColor();
124 static int setIconTitleBack();
125 static int setLargeDisplayFont();
126 static int setWTitleColor();
127 static int setFTitleBack();
128 static int setPTitleBack();
129 static int setUTitleBack();
130 static int setResizebarBack();
131 static int setWorkspaceBack();
132 static int setWorkspaceSpecificBack();
133 static int setMenuTitleColor();
134 static int setMenuTextColor();
135 static int setMenuDisabledColor();
136 static int setMenuTitleBack();
137 static int setMenuTextBack();
138 static int setHightlight();
139 static int setHightlightText();
140 static int setKeyGrab();
141 static int setDoubleClick();
142 static int setIconPosition();
144 static int setClipTitleFont();
145 static int setClipTitleColor();
147 static int setMenuStyle();
148 static int setSwPOptions();
149 static int updateUsableArea();
151 static int setModifierKeyLabels();
153 extern Cursor wCursor[WCUR_LAST];
154 static int getCursor();
155 static int setCursor();
158 * Tables to convert strings to enumeration values.
159 * Values stored are char
162 /* WARNING: sum of length of all value strings must not exceed
163 * this value */
164 #define TOTAL_VALUES_LENGTH 80
166 #define REFRESH_WINDOW_TEXTURES (1<<0)
167 #define REFRESH_MENU_TEXTURE (1<<1)
168 #define REFRESH_MENU_FONT (1<<2)
169 #define REFRESH_MENU_COLOR (1<<3)
170 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
171 #define REFRESH_MENU_TITLE_FONT (1<<5)
172 #define REFRESH_MENU_TITLE_COLOR (1<<6)
173 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
174 #define REFRESH_WINDOW_FONT (1<<8)
175 #define REFRESH_ICON_TILE (1<<9)
176 #define REFRESH_ICON_FONT (1<<10)
177 #define REFRESH_WORKSPACE_BACK (1<<11)
179 #define REFRESH_BUTTON_IMAGES (1<<12)
181 #define REFRESH_ICON_TITLE_COLOR (1<<13)
182 #define REFRESH_ICON_TITLE_BACK (1<<14)
184 static WOptionEnumeration seFocusModes[] = {
185 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
186 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
187 {NULL, 0, 0}
190 static WOptionEnumeration seTitlebarModes[] = {
191 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
192 {"next", TS_NEXT, 0}, {NULL, 0, 0}
195 static WOptionEnumeration seColormapModes[] = {
196 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
197 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
198 {NULL, 0, 0}
201 static WOptionEnumeration sePlacements[] = {
202 {"Auto", WPM_AUTO, 0},
203 {"Smart", WPM_SMART, 0},
204 {"Cascade", WPM_CASCADE, 0},
205 {"Random", WPM_RANDOM, 0},
206 {"Manual", WPM_MANUAL, 0},
207 {"Center", WPM_CENTER, 0},
208 {NULL, 0, 0}
211 static WOptionEnumeration seGeomDisplays[] = {
212 {"None", WDIS_NONE, 0},
213 {"Center", WDIS_CENTER, 0},
214 {"Corner", WDIS_TOPLEFT, 0},
215 {"Floating", WDIS_FRAME_CENTER, 0},
216 {"Line", WDIS_NEW, 0},
217 {NULL, 0, 0}
220 static WOptionEnumeration seSpeeds[] = {
221 {"UltraFast", SPEED_ULTRAFAST, 0},
222 {"Fast", SPEED_FAST, 0},
223 {"Medium", SPEED_MEDIUM, 0},
224 {"Slow", SPEED_SLOW, 0},
225 {"UltraSlow", SPEED_ULTRASLOW, 0},
226 {NULL, 0, 0}
229 static WOptionEnumeration seMouseButtonActions[] = {
230 {"None", WA_NONE, 0},
231 {"SelectWindows", WA_SELECT_WINDOWS, 0},
232 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
233 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
234 {NULL, 0, 0}
237 static WOptionEnumeration seMouseWheelActions[] = {
238 {"None", WA_NONE, 0},
239 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
240 {NULL, 0, 0}
243 static WOptionEnumeration seIconificationStyles[] = {
244 {"Zoom", WIS_ZOOM, 0},
245 {"Twist", WIS_TWIST, 0},
246 {"Flip", WIS_FLIP, 0},
247 {"None", WIS_NONE, 0},
248 {"random", WIS_RANDOM, 0},
249 {NULL, 0, 0}
252 static WOptionEnumeration seJustifications[] = {
253 {"Left", WTJ_LEFT, 0},
254 {"Center", WTJ_CENTER, 0},
255 {"Right", WTJ_RIGHT, 0},
256 {NULL, 0, 0}
259 static WOptionEnumeration seIconPositions[] = {
260 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
261 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
262 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
263 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
264 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
265 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
266 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
267 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
268 {NULL, 0, 0}
271 static WOptionEnumeration seMenuStyles[] = {
272 {"normal", MS_NORMAL, 0},
273 {"singletexture", MS_SINGLE_TEXTURE, 0},
274 {"flat", MS_FLAT, 0},
275 {NULL, 0, 0}
278 static WOptionEnumeration seDisplayPositions[] = {
279 {"none", WD_NONE, 0},
280 {"center", WD_CENTER, 0},
281 {"top", WD_TOP, 0},
282 {"bottom", WD_BOTTOM, 0},
283 {"topleft", WD_TOPLEFT, 0},
284 {"topright", WD_TOPRIGHT, 0},
285 {"bottomleft", WD_BOTTOMLEFT, 0},
286 {"bottomright", WD_BOTTOMRIGHT, 0},
287 {NULL, 0, 0}
290 static WOptionEnumeration seWorkspaceBorder[] = {
291 {"None", WB_NONE, 0},
292 {"LeftRight", WB_LEFTRIGHT, 0},
293 {"TopBottom", WB_TOPBOTTOM, 0},
294 {"AllDirections", WB_ALLDIRS, 0},
295 {NULL, 0, 0}
299 * ALL entries in the tables bellow, NEED to have a default value
300 * defined, and this value needs to be correct.
303 /* these options will only affect the window manager on startup
305 * static defaults can't access the screen data, because it is
306 * created after these defaults are read
308 WDefaultEntry staticOptionList[] = {
310 {"ColormapSize", "4", NULL,
311 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
312 {"DisableDithering", "NO", NULL,
313 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
314 {"IconSize", "64", NULL,
315 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
316 {"ModifierKey", "Mod1", NULL,
317 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
318 {"DisableWSMouseActions", "NO", NULL,
319 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
320 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
321 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
322 {"NewStyle", "new", seTitlebarModes,
323 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
324 {"DisableDock", "NO", (void *)WM_DOCK,
325 NULL, getBool, setIfDockPresent, NULL, NULL},
326 {"DisableClip", "NO", (void *)WM_CLIP,
327 NULL, getBool, setIfDockPresent, NULL, NULL},
328 {"DisableMiniwindows", "NO", NULL,
329 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
332 #define NUM2STRING_(x) #x
333 #define NUM2STRING(x) NUM2STRING_(x)
335 WDefaultEntry optionList[] = {
337 /* dynamic options */
339 {"IconPosition", "blh", seIconPositions,
340 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
341 {"IconificationStyle", "Zoom", seIconificationStyles,
342 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
343 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
344 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
345 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
346 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
347 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
348 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
349 {"MouseWheelAction", "None", seMouseWheelActions,
350 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
351 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
352 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
353 {"IconPath", DEF_ICON_PATHS, NULL,
354 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
355 {"ColormapMode", "auto", seColormapModes,
356 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
357 {"AutoFocus", "NO", NULL,
358 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
359 {"RaiseDelay", "0", NULL,
360 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
361 {"CirculateRaise", "NO", NULL,
362 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
363 {"Superfluous", "NO", NULL,
364 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
365 {"AdvanceToNewWorkspace", "NO", NULL,
366 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
367 {"CycleWorkspaces", "NO", NULL,
368 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
369 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
370 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
371 {"WorkspaceBorder", "None", seWorkspaceBorder,
372 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
373 {"WorkspaceBorderSize", "0", NULL,
374 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
375 {"StickyIcons", "NO", NULL,
376 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
377 {"SaveSessionOnExit", "NO", NULL,
378 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
379 {"WrapMenus", "NO", NULL,
380 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
381 {"ScrollableMenus", "NO", NULL,
382 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
383 {"MenuScrollSpeed", "medium", seSpeeds,
384 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
385 {"IconSlideSpeed", "medium", seSpeeds,
386 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
387 {"ShadeSpeed", "medium", seSpeeds,
388 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
389 {"BounceAppIconsWhenUrgent", "YES", NULL,
390 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
391 {"RaiseAppIconsWhenBouncing", "NO", NULL,
392 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
393 {"DoNotMakeAppIconsBounce", "NO", NULL,
394 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
395 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
396 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
397 {"AlignSubmenus", "NO", NULL,
398 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
399 {"ViKeyMenus", "NO", NULL,
400 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
401 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
402 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
403 {"WindowPlacement", "auto", sePlacements,
404 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
405 {"IgnoreFocusClick", "NO", NULL,
406 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
407 {"UseSaveUnders", "NO", NULL,
408 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
409 {"OpaqueMove", "NO", NULL,
410 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
411 {"OpaqueResize", "NO", NULL,
412 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
413 {"OpaqueMoveResizeKeyboard", "NO", NULL,
414 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
415 {"DisableAnimations", "NO", NULL,
416 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
417 {"DontLinkWorkspaces", "NO", NULL,
418 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
419 {"HighlightActiveApp", "YES", NULL,
420 &wPreferences.highlight_active_app, getBool, NULL, NULL, NULL},
421 {"AutoArrangeIcons", "NO", NULL,
422 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
423 {"NoWindowOverDock", "NO", NULL,
424 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
425 {"NoWindowOverIcons", "NO", NULL,
426 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
427 {"WindowPlaceOrigin", "(0, 0)", NULL,
428 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
429 {"ResizeDisplay", "corner", seGeomDisplays,
430 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
431 {"MoveDisplay", "corner", seGeomDisplays,
432 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
433 {"DontConfirmKill", "NO", NULL,
434 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
435 {"WindowTitleBalloons", "NO", NULL,
436 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
437 {"MiniwindowTitleBalloons", "NO", NULL,
438 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
439 {"AppIconBalloons", "NO", NULL,
440 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
441 {"HelpBalloons", "NO", NULL,
442 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
443 {"EdgeResistance", "30", NULL,
444 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
445 {"ResizeIncrement", "32", NULL,
446 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
447 {"Attraction", "NO", NULL,
448 &wPreferences.attract, getBool, NULL, NULL, NULL},
449 {"DisableBlinking", "NO", NULL,
450 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
451 {"SingleClickLaunch", "NO", NULL,
452 &wPreferences.single_click, getBool, NULL, NULL, NULL},
454 /* style options */
456 {"MenuStyle", "normal", seMenuStyles,
457 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
458 {"WidgetColor", "(solid, gray)", NULL,
459 NULL, getTexture, setWidgetColor, NULL, NULL},
460 {"WorkspaceSpecificBack", "()", NULL,
461 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
462 /* WorkspaceBack must come after WorkspaceSpecificBack or
463 * WorkspaceBack wont know WorkspaceSpecificBack was also
464 * specified and 2 copies of wmsetbg will be launched */
465 {"WorkspaceBack", "(solid, black)", NULL,
466 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
467 {"SmoothWorkspaceBack", "NO", NULL,
468 NULL, getBool, NULL, NULL, NULL},
469 {"IconBack", "(solid, gray)", NULL,
470 NULL, getTexture, setIconTile, NULL, NULL},
471 {"TitleJustify", "center", seJustifications,
472 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
473 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
474 NULL, getFont, setWinTitleFont, NULL, NULL},
475 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
476 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
477 {"WindowTitleMinHeight", "0", NULL,
478 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
479 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
480 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
481 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
482 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
483 {"MenuTitleMinHeight", "0", NULL,
484 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
485 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
486 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
487 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
488 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
489 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
490 NULL, getFont, setMenuTitleFont, NULL, NULL},
491 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
492 NULL, getFont, setMenuTextFont, NULL, NULL},
493 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
494 NULL, getFont, setIconTitleFont, NULL, NULL},
495 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
496 NULL, getFont, setClipTitleFont, NULL, NULL},
497 {"ShowClipTitle", "YES", NULL,
498 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
499 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
500 NULL, getFont, setLargeDisplayFont, NULL, NULL},
501 {"HighlightColor", "white", NULL,
502 NULL, getColor, setHightlight, NULL, NULL},
503 {"HighlightTextColor", "black", NULL,
504 NULL, getColor, setHightlightText, NULL, NULL},
505 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
506 NULL, getColor, setClipTitleColor, NULL, NULL},
507 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
508 NULL, getColor, setClipTitleColor, NULL, NULL},
509 {"FTitleColor", "white", (void *)WS_FOCUSED,
510 NULL, getColor, setWTitleColor, NULL, NULL},
511 {"PTitleColor", "white", (void *)WS_PFOCUSED,
512 NULL, getColor, setWTitleColor, NULL, NULL},
513 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
514 NULL, getColor, setWTitleColor, NULL, NULL},
515 {"FTitleBack", "(solid, black)", NULL,
516 NULL, getTexture, setFTitleBack, NULL, NULL},
517 {"PTitleBack", "(solid, \"#616161\")", NULL,
518 NULL, getTexture, setPTitleBack, NULL, NULL},
519 {"UTitleBack", "(solid, gray)", NULL,
520 NULL, getTexture, setUTitleBack, NULL, NULL},
521 {"ResizebarBack", "(solid, gray)", NULL,
522 NULL, getTexture, setResizebarBack, NULL, NULL},
523 {"MenuTitleColor", "white", NULL,
524 NULL, getColor, setMenuTitleColor, NULL, NULL},
525 {"MenuTextColor", "black", NULL,
526 NULL, getColor, setMenuTextColor, NULL, NULL},
527 {"MenuDisabledColor", "\"#616161\"", NULL,
528 NULL, getColor, setMenuDisabledColor, NULL, NULL},
529 {"MenuTitleBack", "(solid, black)", NULL,
530 NULL, getTexture, setMenuTitleBack, NULL, NULL},
531 {"MenuTextBack", "(solid, gray)", NULL,
532 NULL, getTexture, setMenuTextBack, NULL, NULL},
533 {"IconTitleColor", "white", NULL,
534 NULL, getColor, setIconTitleColor, NULL, NULL},
535 {"IconTitleBack", "black", NULL,
536 NULL, getColor, setIconTitleBack, NULL, NULL},
537 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
538 NULL, getPropList, setSwPOptions, NULL, NULL},
539 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
540 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
542 /* keybindings */
544 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
545 NULL, getKeybind, setKeyGrab, NULL, NULL},
546 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
547 NULL, getKeybind, setKeyGrab, NULL, NULL},
548 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
549 NULL, getKeybind, setKeyGrab, NULL, NULL},
550 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
551 NULL, getKeybind, setKeyGrab, NULL, NULL},
552 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
553 NULL, getKeybind, setKeyGrab, NULL, NULL},
554 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
555 NULL, getKeybind, setKeyGrab, NULL, NULL},
556 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
557 NULL, getKeybind, setKeyGrab, NULL, NULL },
558 {"HideKey", "None", (void *)WKBD_HIDE,
559 NULL, getKeybind, setKeyGrab, NULL, NULL},
560 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
561 NULL, getKeybind, setKeyGrab, NULL, NULL},
562 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
563 NULL, getKeybind, setKeyGrab, NULL, NULL},
564 {"CloseKey", "None", (void *)WKBD_CLOSE,
565 NULL, getKeybind, setKeyGrab, NULL, NULL},
566 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
567 NULL, getKeybind, setKeyGrab, NULL, NULL},
568 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
569 NULL, getKeybind, setKeyGrab, NULL, NULL},
570 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
571 NULL, getKeybind, setKeyGrab, NULL, NULL},
572 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
573 NULL, getKeybind, setKeyGrab, NULL, NULL},
574 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
575 NULL, getKeybind, setKeyGrab, NULL, NULL},
576 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
577 NULL, getKeybind, setKeyGrab, NULL, NULL},
578 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
579 NULL, getKeybind, setKeyGrab, NULL, NULL},
580 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
581 NULL, getKeybind, setKeyGrab, NULL, NULL},
582 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
583 NULL, getKeybind, setKeyGrab, NULL, NULL},
584 {"ShadeKey", "None", (void *)WKBD_SHADE,
585 NULL, getKeybind, setKeyGrab, NULL, NULL},
586 {"SelectKey", "None", (void *)WKBD_SELECT,
587 NULL, getKeybind, setKeyGrab, NULL, NULL},
588 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
589 NULL, getKeybind, setKeyGrab, NULL, NULL},
590 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
591 NULL, getKeybind, setKeyGrab, NULL, NULL},
592 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
593 NULL, getKeybind, setKeyGrab, NULL, NULL},
594 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
595 NULL, getKeybind, setKeyGrab, NULL, NULL},
596 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
597 NULL, getKeybind, setKeyGrab, NULL, NULL},
598 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
599 NULL, getKeybind, setKeyGrab, NULL, NULL},
600 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
601 NULL, getKeybind, setKeyGrab, NULL, NULL},
602 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
603 NULL, getKeybind, setKeyGrab, NULL, NULL},
604 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
605 NULL, getKeybind, setKeyGrab, NULL, NULL},
606 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
607 NULL, getKeybind, setKeyGrab, NULL, NULL},
608 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
609 NULL, getKeybind, setKeyGrab, NULL, NULL},
610 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
611 NULL, getKeybind, setKeyGrab, NULL, NULL},
612 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
613 NULL, getKeybind, setKeyGrab, NULL, NULL},
614 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
615 NULL, getKeybind, setKeyGrab, NULL, NULL},
616 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
617 NULL, getKeybind, setKeyGrab, NULL, NULL},
618 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
619 NULL, getKeybind, setKeyGrab, NULL, NULL},
620 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
621 NULL, getKeybind, setKeyGrab, NULL, NULL},
622 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
623 NULL, getKeybind, setKeyGrab, NULL, NULL},
624 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
625 NULL, getKeybind, setKeyGrab, NULL, NULL},
626 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
627 NULL, getKeybind, setKeyGrab, NULL, NULL},
628 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
629 NULL, getKeybind, setKeyGrab, NULL, NULL},
630 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
631 NULL, getKeybind, setKeyGrab, NULL, NULL},
632 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
633 NULL, getKeybind, setKeyGrab, NULL, NULL},
634 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
635 NULL, getKeybind, setKeyGrab, NULL, NULL},
636 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
637 NULL, getKeybind, setKeyGrab, NULL, NULL},
638 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
639 NULL, getKeybind, setKeyGrab, NULL, NULL},
640 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
641 NULL, getKeybind, setKeyGrab, NULL, NULL},
642 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
643 NULL, getKeybind, setKeyGrab, NULL, NULL},
644 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
645 NULL, getKeybind, setKeyGrab, NULL, NULL},
646 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
647 NULL, getKeybind, setKeyGrab, NULL, NULL},
649 #ifdef KEEP_XKB_LOCK_STATUS
650 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
651 NULL, getKeybind, setKeyGrab, NULL, NULL},
652 {"KbdModeLock", "NO", NULL,
653 &wPreferences.modelock, getBool, NULL, NULL, NULL},
654 #endif /* KEEP_XKB_LOCK_STATUS */
656 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
657 NULL, getCursor, setCursor, NULL, NULL},
658 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
659 NULL, getCursor, setCursor, NULL, NULL},
660 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
661 NULL, getCursor, setCursor, NULL, NULL},
662 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
663 NULL, getCursor, setCursor, NULL, NULL},
664 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
665 NULL, getCursor, setCursor, NULL, NULL},
666 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
667 NULL, getCursor, setCursor, NULL, NULL},
668 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
669 NULL, getCursor, setCursor, NULL, NULL},
670 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
671 NULL, getCursor, setCursor, NULL, NULL},
672 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
673 NULL, getCursor, setCursor, NULL, NULL},
674 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
675 NULL, getCursor, setCursor, NULL, NULL},
676 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
677 NULL, getCursor, setCursor, NULL, NULL},
678 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
679 NULL, getCursor, setCursor, NULL, NULL},
680 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
681 NULL, getCursor, setCursor, NULL, NULL},
682 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
683 NULL, getCursor, setCursor, NULL, NULL},
684 {"DialogHistoryLines", "500", NULL,
685 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
686 {"CycleActiveHeadOnly", "NO", NULL,
687 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL}
690 static void initDefaults()
692 unsigned int i;
693 WDefaultEntry *entry;
695 WMPLSetCaseSensitive(False);
697 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
698 entry = &optionList[i];
700 entry->plkey = WMCreatePLString(entry->key);
701 if (entry->default_value)
702 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
703 else
704 entry->plvalue = NULL;
707 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
708 entry = &staticOptionList[i];
710 entry->plkey = WMCreatePLString(entry->key);
711 if (entry->default_value)
712 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
713 else
714 entry->plvalue = NULL;
718 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
720 WMPropList *globalDict = NULL;
721 char path[PATH_MAX];
722 struct stat stbuf;
724 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
725 if (stat(path, &stbuf) >= 0) {
726 globalDict = WMReadPropListFromFile(path);
727 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
728 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
729 WMReleasePropList(globalDict);
730 globalDict = NULL;
731 } else if (!globalDict) {
732 wwarning(_("could not load domain %s from global defaults database"), domainName);
736 return globalDict;
739 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
740 static void prependMenu(WMPropList * destarr, WMPropList * array)
742 WMPropList *item;
743 int i;
745 for (i = 0; i < WMGetPropListItemCount(array); i++) {
746 item = WMGetFromPLArray(array, i);
747 if (item)
748 WMInsertInPLArray(destarr, i + 1, item);
752 static void appendMenu(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 WMAddToPLArray(destarr, item);
763 #endif
765 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
767 WMPropList *menu = menuDomain->dictionary;
768 WMPropList *submenu;
770 if (!menu || !WMIsPLArray(menu))
771 return;
773 #ifdef GLOBAL_PREAMBLE_MENU_FILE
774 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
776 if (submenu && !WMIsPLArray(submenu)) {
777 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
778 WMReleasePropList(submenu);
779 submenu = NULL;
781 if (submenu) {
782 prependMenu(menu, submenu);
783 WMReleasePropList(submenu);
785 #endif
787 #ifdef GLOBAL_EPILOGUE_MENU_FILE
788 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
790 if (submenu && !WMIsPLArray(submenu)) {
791 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
792 WMReleasePropList(submenu);
793 submenu = NULL;
795 if (submenu) {
796 appendMenu(menu, submenu);
797 WMReleasePropList(submenu);
799 #endif
801 menuDomain->dictionary = menu;
804 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
806 WDDomain *db;
807 struct stat stbuf;
808 static int inited = 0;
809 char *the_path;
810 WMPropList *shared_dict = NULL;
812 if (!inited) {
813 inited = 1;
814 initDefaults();
817 db = wmalloc(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 shared_dict = readGlobalDomain(domain, requireDictionary);
839 if (shared_dict && db->dictionary && WMIsPLDictionary(shared_dict) &&
840 WMIsPLDictionary(db->dictionary)) {
841 WMMergePLDictionaries(shared_dict, db->dictionary, True);
842 WMReleasePropList(db->dictionary);
843 db->dictionary = shared_dict;
844 if (stbuf.st_mtime > db->timestamp)
845 db->timestamp = stbuf.st_mtime;
846 } else if (!db->dictionary) {
847 db->dictionary = shared_dict;
848 if (stbuf.st_mtime > db->timestamp)
849 db->timestamp = stbuf.st_mtime;
852 return db;
855 void wReadStaticDefaults(WMPropList * dict)
857 WMPropList *plvalue;
858 WDefaultEntry *entry;
859 unsigned int i;
860 void *tdata;
862 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
863 entry = &staticOptionList[i];
865 if (dict)
866 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
867 else
868 plvalue = NULL;
870 if (!plvalue) {
871 /* no default in the DB. Use builtin default */
872 plvalue = entry->plvalue;
875 if (plvalue) {
876 /* convert data */
877 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
878 if (entry->update) {
879 (*entry->update) (NULL, entry, tdata, entry->extra_data);
885 void wDefaultsCheckDomains(void* arg)
887 WScreen *scr;
888 struct stat stbuf;
889 WMPropList *shared_dict = NULL;
890 WMPropList *dict;
891 int i;
893 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
894 WDWindowMaker->timestamp = stbuf.st_mtime;
896 /* Global dictionary */
897 shared_dict = readGlobalDomain("WindowMaker", True);
899 /* User dictionary */
900 dict = WMReadPropListFromFile(WDWindowMaker->path);
902 if (dict) {
903 if (!WMIsPLDictionary(dict)) {
904 WMReleasePropList(dict);
905 dict = NULL;
906 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
907 "WindowMaker", WDWindowMaker->path);
908 } else {
909 if (shared_dict) {
910 WMMergePLDictionaries(shared_dict, dict, True);
911 WMReleasePropList(dict);
912 dict = shared_dict;
913 shared_dict = NULL;
916 for (i = 0; i < wScreenCount; i++) {
917 scr = wScreenWithNumber(i);
918 if (scr)
919 wReadDefaults(scr, dict);
922 if (WDWindowMaker->dictionary)
923 WMReleasePropList(WDWindowMaker->dictionary);
925 WDWindowMaker->dictionary = dict;
927 } else {
928 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
931 if (shared_dict)
932 WMReleasePropList(shared_dict);
936 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
937 /* global dictionary */
938 shared_dict = readGlobalDomain("WMWindowAttributes", True);
939 /* user dictionary */
940 dict = WMReadPropListFromFile(WDWindowAttributes->path);
941 if (dict) {
942 if (!WMIsPLDictionary(dict)) {
943 WMReleasePropList(dict);
944 dict = NULL;
945 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
946 "WMWindowAttributes", WDWindowAttributes->path);
947 } else {
948 if (shared_dict) {
949 WMMergePLDictionaries(shared_dict, dict, True);
950 WMReleasePropList(dict);
951 dict = shared_dict;
952 shared_dict = NULL;
954 if (WDWindowAttributes->dictionary) {
955 WMReleasePropList(WDWindowAttributes->dictionary);
957 WDWindowAttributes->dictionary = dict;
958 for (i = 0; i < wScreenCount; i++) {
959 scr = wScreenWithNumber(i);
960 if (scr) {
961 wDefaultUpdateIcons(scr);
963 /* Update the panel image if changed */
964 /* Don't worry. If the image is the same these
965 * functions will have no performance impact. */
966 create_logo_image(scr);
970 } else {
971 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
973 WDWindowAttributes->timestamp = stbuf.st_mtime;
974 if (shared_dict) {
975 WMReleasePropList(shared_dict);
979 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
980 dict = WMReadPropListFromFile(WDRootMenu->path);
981 if (dict) {
982 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
983 WMReleasePropList(dict);
984 dict = NULL;
985 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
986 "WMRootMenu", WDRootMenu->path);
987 } else {
988 if (WDRootMenu->dictionary) {
989 WMReleasePropList(WDRootMenu->dictionary);
991 WDRootMenu->dictionary = dict;
992 wDefaultsMergeGlobalMenus(WDRootMenu);
994 } else {
995 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
997 WDRootMenu->timestamp = stbuf.st_mtime;
999 #ifndef HAVE_INOTIFY
1000 if (!arg)
1001 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1002 #endif
1005 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1007 WMPropList *plvalue, *old_value;
1008 WDefaultEntry *entry;
1009 unsigned int i;
1010 int update_workspace_back = 0; /* kluge :/ */
1011 unsigned int needs_refresh;
1012 void *tdata;
1013 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1015 needs_refresh = 0;
1017 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1018 entry = &optionList[i];
1020 if (new_dict)
1021 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1022 else
1023 plvalue = NULL;
1025 if (!old_dict)
1026 old_value = NULL;
1027 else
1028 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1030 if (!plvalue && !old_value) {
1031 /* no default in the DB. Use builtin default */
1032 plvalue = entry->plvalue;
1033 if (plvalue && new_dict)
1034 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1036 } else if (!plvalue) {
1037 /* value was deleted from DB. Keep current value */
1038 continue;
1039 } else if (!old_value) {
1040 /* set value for the 1st time */
1041 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1042 /* value has changed */
1043 } else {
1044 if (strcmp(entry->key, "WorkspaceBack") == 0
1045 && update_workspace_back && scr->flags.backimage_helper_launched) {
1046 } else {
1047 /* value was not changed since last time */
1048 continue;
1052 if (plvalue) {
1053 /* convert data */
1054 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1056 * If the WorkspaceSpecificBack data has been changed
1057 * so that the helper will be launched now, we must be
1058 * sure to send the default background texture config
1059 * to the helper.
1061 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1062 !scr->flags.backimage_helper_launched)
1063 update_workspace_back = 1;
1065 if (entry->update)
1066 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1072 if (needs_refresh != 0 && !scr->flags.startup) {
1073 int foo;
1075 foo = 0;
1076 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1077 foo |= WTextureSettings;
1078 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1079 foo |= WFontSettings;
1080 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1081 foo |= WColorSettings;
1082 if (foo)
1083 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1084 (void *)(uintptr_t) foo);
1086 foo = 0;
1087 if (needs_refresh & REFRESH_MENU_TEXTURE)
1088 foo |= WTextureSettings;
1089 if (needs_refresh & REFRESH_MENU_FONT)
1090 foo |= WFontSettings;
1091 if (needs_refresh & REFRESH_MENU_COLOR)
1092 foo |= WColorSettings;
1093 if (foo)
1094 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1096 foo = 0;
1097 if (needs_refresh & REFRESH_WINDOW_FONT)
1098 foo |= WFontSettings;
1099 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1100 foo |= WTextureSettings;
1101 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1102 foo |= WColorSettings;
1103 if (foo)
1104 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1106 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1107 foo = 0;
1108 if (needs_refresh & REFRESH_ICON_FONT)
1109 foo |= WFontSettings;
1110 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1111 foo |= WTextureSettings;
1112 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1113 foo |= WTextureSettings;
1114 if (foo)
1115 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1116 (void *)(uintptr_t) foo);
1118 if (needs_refresh & REFRESH_ICON_TILE)
1119 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1123 void wDefaultUpdateIcons(WScreen *scr)
1125 WAppIcon *aicon = scr->app_icon_list;
1126 WWindow *wwin = scr->focused_window;
1127 char *file;
1129 while (aicon) {
1130 /* Get the application icon, default included */
1131 file = wDefaultGetIconFile(aicon->wm_instance, aicon->wm_class, True);
1132 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1133 || (file && !aicon->icon->file)) {
1134 wIconChangeImageFile(aicon->icon, file);
1135 wAppIconPaint(aicon);
1137 aicon = aicon->next;
1140 if (!wPreferences.flags.noclip)
1141 wClipIconPaint(scr->clip_icon);
1143 while (wwin) {
1144 if (wwin->icon && wwin->flags.miniaturized) {
1145 /* Get the application icon, default included */
1146 file = wDefaultGetIconFile(wwin->wm_instance, wwin->wm_class, True);
1147 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1148 || (file && !wwin->icon->file))
1149 wIconChangeImageFile(wwin->icon, file);
1151 wwin = wwin->prev;
1155 /* --------------------------- Local ----------------------- */
1157 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1158 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1159 entry->key, x); \
1160 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1161 var = entry->default_value;\
1162 } else var = WMGetFromPLString(value)\
1165 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1167 char *str;
1168 WOptionEnumeration *v;
1169 char buffer[TOTAL_VALUES_LENGTH];
1171 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1172 for (v = values; v->string != NULL; v++) {
1173 if (strcasecmp(v->string, str) == 0)
1174 return v->value;
1178 buffer[0] = 0;
1179 for (v = values; v->string != NULL; v++) {
1180 if (!v->is_alias) {
1181 if (buffer[0] != 0)
1182 strcat(buffer, ", ");
1183 snprintf(buffer+strlen(buffer),
1184 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1187 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1188 WMGetFromPLString(key),
1189 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1190 buffer);
1192 if (def) {
1193 return string2index(key, val, NULL, values);
1196 return -1;
1200 * value - is the value in the defaults DB
1201 * addr - is the address to store the data
1202 * ret - is the address to store a pointer to a temporary buffer. ret
1203 * must not be freed and is used by the set functions
1205 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1207 static char data;
1208 char *val;
1209 int second_pass = 0;
1211 GET_STRING_OR_DEFAULT("Boolean", val);
1213 again:
1214 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1215 || strcasecmp(val, "YES") == 0) {
1217 data = 1;
1218 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1219 || strcasecmp(val, "NO") == 0) {
1220 data = 0;
1221 } else {
1222 int i;
1223 if (sscanf(val, "%i", &i) == 1) {
1224 if (i != 0)
1225 data = 1;
1226 else
1227 data = 0;
1228 } else {
1229 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1230 if (second_pass == 0) {
1231 val = WMGetFromPLString(entry->plvalue);
1232 second_pass = 1;
1233 wwarning(_("using default \"%s\" instead"), val);
1234 goto again;
1236 return False;
1240 if (ret)
1241 *ret = &data;
1242 if (addr)
1243 *(char *)addr = data;
1245 return True;
1248 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1250 static int data;
1251 char *val;
1253 GET_STRING_OR_DEFAULT("Integer", val);
1255 if (sscanf(val, "%i", &data) != 1) {
1256 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1257 val = WMGetFromPLString(entry->plvalue);
1258 wwarning(_("using default \"%s\" instead"), val);
1259 if (sscanf(val, "%i", &data) != 1) {
1260 return False;
1264 if (ret)
1265 *ret = &data;
1266 if (addr)
1267 *(int *)addr = data;
1269 return True;
1272 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1274 static WCoord data;
1275 char *val_x, *val_y;
1276 int nelem, changed = 0;
1277 WMPropList *elem_x, *elem_y;
1279 again:
1280 if (!WMIsPLArray(value)) {
1281 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1282 if (changed == 0) {
1283 value = entry->plvalue;
1284 changed = 1;
1285 wwarning(_("using default \"%s\" instead"), entry->default_value);
1286 goto again;
1288 return False;
1291 nelem = WMGetPropListItemCount(value);
1292 if (nelem != 2) {
1293 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1294 if (changed == 0) {
1295 value = entry->plvalue;
1296 changed = 1;
1297 wwarning(_("using default \"%s\" instead"), entry->default_value);
1298 goto again;
1300 return False;
1303 elem_x = WMGetFromPLArray(value, 0);
1304 elem_y = WMGetFromPLArray(value, 1);
1306 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1307 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1308 if (changed == 0) {
1309 value = entry->plvalue;
1310 changed = 1;
1311 wwarning(_("using default \"%s\" instead"), entry->default_value);
1312 goto again;
1314 return False;
1317 val_x = WMGetFromPLString(elem_x);
1318 val_y = WMGetFromPLString(elem_y);
1320 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1321 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1322 if (changed == 0) {
1323 value = entry->plvalue;
1324 changed = 1;
1325 wwarning(_("using default \"%s\" instead"), entry->default_value);
1326 goto again;
1328 return False;
1331 if (data.x < 0)
1332 data.x = 0;
1333 else if (data.x > scr->scr_width / 3)
1334 data.x = scr->scr_width / 3;
1335 if (data.y < 0)
1336 data.y = 0;
1337 else if (data.y > scr->scr_height / 3)
1338 data.y = scr->scr_height / 3;
1340 if (ret)
1341 *ret = &data;
1342 if (addr)
1343 *(WCoord *) addr = data;
1345 return True;
1348 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1350 WMRetainPropList(value);
1352 *ret = value;
1354 return True;
1357 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1359 static char *data;
1360 int i, count, len;
1361 char *ptr;
1362 WMPropList *d;
1363 int changed = 0;
1365 again:
1366 if (!WMIsPLArray(value)) {
1367 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1368 if (changed == 0) {
1369 value = entry->plvalue;
1370 changed = 1;
1371 wwarning(_("using default \"%s\" instead"), entry->default_value);
1372 goto again;
1374 return False;
1377 i = 0;
1378 count = WMGetPropListItemCount(value);
1379 if (count < 1) {
1380 if (changed == 0) {
1381 value = entry->plvalue;
1382 changed = 1;
1383 wwarning(_("using default \"%s\" instead"), entry->default_value);
1384 goto again;
1386 return False;
1389 len = 0;
1390 for (i = 0; i < count; i++) {
1391 d = WMGetFromPLArray(value, i);
1392 if (!d || !WMIsPLString(d)) {
1393 count = i;
1394 break;
1396 len += strlen(WMGetFromPLString(d)) + 1;
1399 ptr = data = wmalloc(len + 1);
1401 for (i = 0; i < count; i++) {
1402 d = WMGetFromPLArray(value, i);
1403 if (!d || !WMIsPLString(d)) {
1404 break;
1406 strcpy(ptr, WMGetFromPLString(d));
1407 ptr += strlen(WMGetFromPLString(d));
1408 *ptr = ':';
1409 ptr++;
1411 ptr--;
1412 *(ptr--) = 0;
1414 if (*(char **)addr != NULL) {
1415 wfree(*(char **)addr);
1417 *(char **)addr = data;
1419 return True;
1422 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1424 static signed char data;
1426 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1427 if (data < 0)
1428 return False;
1430 if (ret)
1431 *ret = &data;
1432 if (addr)
1433 *(signed char *)addr = data;
1435 return True;
1439 * (solid <color>)
1440 * (hgradient <color> <color>)
1441 * (vgradient <color> <color>)
1442 * (dgradient <color> <color>)
1443 * (mhgradient <color> <color> ...)
1444 * (mvgradient <color> <color> ...)
1445 * (mdgradient <color> <color> ...)
1446 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1447 * (tpixmap <file> <color>)
1448 * (spixmap <file> <color>)
1449 * (cpixmap <file> <color>)
1450 * (thgradient <file> <opaqueness> <color> <color>)
1451 * (tvgradient <file> <opaqueness> <color> <color>)
1452 * (tdgradient <file> <opaqueness> <color> <color>)
1453 * (function <lib> <function> ...)
1456 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1458 WMPropList *elem;
1459 char *val;
1460 int nelem;
1461 WTexture *texture = NULL;
1463 nelem = WMGetPropListItemCount(pl);
1464 if (nelem < 1)
1465 return NULL;
1467 elem = WMGetFromPLArray(pl, 0);
1468 if (!elem || !WMIsPLString(elem))
1469 return NULL;
1470 val = WMGetFromPLString(elem);
1472 if (strcasecmp(val, "solid") == 0) {
1473 XColor color;
1475 if (nelem != 2)
1476 return NULL;
1478 /* get color */
1480 elem = WMGetFromPLArray(pl, 1);
1481 if (!elem || !WMIsPLString(elem))
1482 return NULL;
1483 val = WMGetFromPLString(elem);
1485 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1486 wwarning(_("\"%s\" is not a valid color name"), val);
1487 return NULL;
1490 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1491 } else if (strcasecmp(val, "dgradient") == 0
1492 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1493 RColor color1, color2;
1494 XColor xcolor;
1495 int type;
1497 if (nelem != 3) {
1498 wwarning(_("bad number of arguments in gradient specification"));
1499 return NULL;
1502 if (val[0] == 'd' || val[0] == 'D')
1503 type = WTEX_DGRADIENT;
1504 else if (val[0] == 'h' || val[0] == 'H')
1505 type = WTEX_HGRADIENT;
1506 else
1507 type = WTEX_VGRADIENT;
1509 /* get from color */
1510 elem = WMGetFromPLArray(pl, 1);
1511 if (!elem || !WMIsPLString(elem))
1512 return NULL;
1513 val = WMGetFromPLString(elem);
1515 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1516 wwarning(_("\"%s\" is not a valid color name"), val);
1517 return NULL;
1519 color1.alpha = 255;
1520 color1.red = xcolor.red >> 8;
1521 color1.green = xcolor.green >> 8;
1522 color1.blue = xcolor.blue >> 8;
1524 /* get to color */
1525 elem = WMGetFromPLArray(pl, 2);
1526 if (!elem || !WMIsPLString(elem)) {
1527 return NULL;
1529 val = WMGetFromPLString(elem);
1531 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1532 wwarning(_("\"%s\" is not a valid color name"), val);
1533 return NULL;
1535 color2.alpha = 255;
1536 color2.red = xcolor.red >> 8;
1537 color2.green = xcolor.green >> 8;
1538 color2.blue = xcolor.blue >> 8;
1540 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1542 } else if (strcasecmp(val, "igradient") == 0) {
1543 RColor colors1[2], colors2[2];
1544 int th1, th2;
1545 XColor xcolor;
1546 int i;
1548 if (nelem != 7) {
1549 wwarning(_("bad number of arguments in gradient specification"));
1550 return NULL;
1553 /* get from color */
1554 for (i = 0; i < 2; i++) {
1555 elem = WMGetFromPLArray(pl, 1 + i);
1556 if (!elem || !WMIsPLString(elem))
1557 return NULL;
1558 val = WMGetFromPLString(elem);
1560 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1561 wwarning(_("\"%s\" is not a valid color name"), val);
1562 return NULL;
1564 colors1[i].alpha = 255;
1565 colors1[i].red = xcolor.red >> 8;
1566 colors1[i].green = xcolor.green >> 8;
1567 colors1[i].blue = xcolor.blue >> 8;
1569 elem = WMGetFromPLArray(pl, 3);
1570 if (!elem || !WMIsPLString(elem))
1571 return NULL;
1572 val = WMGetFromPLString(elem);
1573 th1 = atoi(val);
1575 /* get from color */
1576 for (i = 0; i < 2; i++) {
1577 elem = WMGetFromPLArray(pl, 4 + i);
1578 if (!elem || !WMIsPLString(elem))
1579 return NULL;
1580 val = WMGetFromPLString(elem);
1582 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1583 wwarning(_("\"%s\" is not a valid color name"), val);
1584 return NULL;
1586 colors2[i].alpha = 255;
1587 colors2[i].red = xcolor.red >> 8;
1588 colors2[i].green = xcolor.green >> 8;
1589 colors2[i].blue = xcolor.blue >> 8;
1591 elem = WMGetFromPLArray(pl, 6);
1592 if (!elem || !WMIsPLString(elem))
1593 return NULL;
1594 val = WMGetFromPLString(elem);
1595 th2 = atoi(val);
1597 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1599 } else if (strcasecmp(val, "mhgradient") == 0
1600 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1601 XColor color;
1602 RColor **colors;
1603 int i, count;
1604 int type;
1606 if (nelem < 3) {
1607 wwarning(_("too few arguments in multicolor gradient specification"));
1608 return NULL;
1611 if (val[1] == 'h' || val[1] == 'H')
1612 type = WTEX_MHGRADIENT;
1613 else if (val[1] == 'v' || val[1] == 'V')
1614 type = WTEX_MVGRADIENT;
1615 else
1616 type = WTEX_MDGRADIENT;
1618 count = nelem - 1;
1620 colors = wmalloc(sizeof(RColor *) * (count + 1));
1622 for (i = 0; i < count; i++) {
1623 elem = WMGetFromPLArray(pl, i + 1);
1624 if (!elem || !WMIsPLString(elem)) {
1625 for (--i; i >= 0; --i) {
1626 wfree(colors[i]);
1628 wfree(colors);
1629 return NULL;
1631 val = WMGetFromPLString(elem);
1633 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1634 wwarning(_("\"%s\" is not a valid color name"), val);
1635 for (--i; i >= 0; --i) {
1636 wfree(colors[i]);
1638 wfree(colors);
1639 return NULL;
1640 } else {
1641 colors[i] = wmalloc(sizeof(RColor));
1642 colors[i]->red = color.red >> 8;
1643 colors[i]->green = color.green >> 8;
1644 colors[i]->blue = color.blue >> 8;
1647 colors[i] = NULL;
1649 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1650 } else if (strcasecmp(val, "spixmap") == 0 ||
1651 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1652 XColor color;
1653 int type;
1655 if (nelem != 3)
1656 return NULL;
1658 if (val[0] == 's' || val[0] == 'S')
1659 type = WTP_SCALE;
1660 else if (val[0] == 'c' || val[0] == 'C')
1661 type = WTP_CENTER;
1662 else
1663 type = WTP_TILE;
1665 /* get color */
1666 elem = WMGetFromPLArray(pl, 2);
1667 if (!elem || !WMIsPLString(elem)) {
1668 return NULL;
1670 val = WMGetFromPLString(elem);
1672 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1673 wwarning(_("\"%s\" is not a valid color name"), val);
1674 return NULL;
1677 /* file name */
1678 elem = WMGetFromPLArray(pl, 1);
1679 if (!elem || !WMIsPLString(elem))
1680 return NULL;
1681 val = WMGetFromPLString(elem);
1683 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1684 } else if (strcasecmp(val, "thgradient") == 0
1685 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1686 RColor color1, color2;
1687 XColor xcolor;
1688 int opacity;
1689 int style;
1691 if (val[1] == 'h' || val[1] == 'H')
1692 style = WTEX_THGRADIENT;
1693 else if (val[1] == 'v' || val[1] == 'V')
1694 style = WTEX_TVGRADIENT;
1695 else
1696 style = WTEX_TDGRADIENT;
1698 if (nelem != 5) {
1699 wwarning(_("bad number of arguments in textured gradient specification"));
1700 return NULL;
1703 /* get from color */
1704 elem = WMGetFromPLArray(pl, 3);
1705 if (!elem || !WMIsPLString(elem))
1706 return NULL;
1707 val = WMGetFromPLString(elem);
1709 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1710 wwarning(_("\"%s\" is not a valid color name"), val);
1711 return NULL;
1713 color1.alpha = 255;
1714 color1.red = xcolor.red >> 8;
1715 color1.green = xcolor.green >> 8;
1716 color1.blue = xcolor.blue >> 8;
1718 /* get to color */
1719 elem = WMGetFromPLArray(pl, 4);
1720 if (!elem || !WMIsPLString(elem)) {
1721 return NULL;
1723 val = WMGetFromPLString(elem);
1725 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1726 wwarning(_("\"%s\" is not a valid color name"), val);
1727 return NULL;
1729 color2.alpha = 255;
1730 color2.red = xcolor.red >> 8;
1731 color2.green = xcolor.green >> 8;
1732 color2.blue = xcolor.blue >> 8;
1734 /* get opacity */
1735 elem = WMGetFromPLArray(pl, 2);
1736 if (!elem || !WMIsPLString(elem))
1737 opacity = 128;
1738 else
1739 val = WMGetFromPLString(elem);
1741 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1742 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1743 opacity = 128;
1746 /* get file name */
1747 elem = WMGetFromPLArray(pl, 1);
1748 if (!elem || !WMIsPLString(elem))
1749 return NULL;
1750 val = WMGetFromPLString(elem);
1752 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1753 } else if (strcasecmp(val, "function") == 0) {
1754 /* Leave this in to handle the unlikely case of
1755 * someone actually having function textures configured */
1756 wwarning("function texture support has been removed");
1757 return NULL;
1758 } else {
1759 wwarning(_("invalid texture type %s"), val);
1760 return NULL;
1762 return texture;
1765 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1767 static WTexture *texture;
1768 int changed = 0;
1770 again:
1771 if (!WMIsPLArray(value)) {
1772 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1773 if (changed == 0) {
1774 value = entry->plvalue;
1775 changed = 1;
1776 wwarning(_("using default \"%s\" instead"), entry->default_value);
1777 goto again;
1779 return False;
1782 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1783 WMPropList *pl;
1785 pl = WMGetFromPLArray(value, 0);
1786 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1787 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1788 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1789 entry->key, "Solid Texture");
1791 value = entry->plvalue;
1792 changed = 1;
1793 wwarning(_("using default \"%s\" instead"), entry->default_value);
1794 goto again;
1798 texture = parse_texture(scr, value);
1800 if (!texture) {
1801 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1802 if (changed == 0) {
1803 value = entry->plvalue;
1804 changed = 1;
1805 wwarning(_("using default \"%s\" instead"), entry->default_value);
1806 goto again;
1808 return False;
1811 if (ret)
1812 *ret = &texture;
1814 if (addr)
1815 *(WTexture **) addr = texture;
1817 return True;
1820 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1822 WMPropList *elem;
1823 int changed = 0;
1824 char *val;
1825 int nelem;
1827 again:
1828 if (!WMIsPLArray(value)) {
1829 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1830 "WorkspaceBack", "Texture or None");
1831 if (changed == 0) {
1832 value = entry->plvalue;
1833 changed = 1;
1834 wwarning(_("using default \"%s\" instead"), entry->default_value);
1835 goto again;
1837 return False;
1840 /* only do basic error checking and verify for None texture */
1842 nelem = WMGetPropListItemCount(value);
1843 if (nelem > 0) {
1844 elem = WMGetFromPLArray(value, 0);
1845 if (!elem || !WMIsPLString(elem)) {
1846 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1847 if (changed == 0) {
1848 value = entry->plvalue;
1849 changed = 1;
1850 wwarning(_("using default \"%s\" instead"), entry->default_value);
1851 goto again;
1853 return False;
1855 val = WMGetFromPLString(elem);
1857 if (strcasecmp(val, "None") == 0)
1858 return True;
1860 *ret = WMRetainPropList(value);
1862 return True;
1865 static int
1866 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1868 WMPropList *elem;
1869 int nelem;
1870 int changed = 0;
1872 again:
1873 if (!WMIsPLArray(value)) {
1874 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1875 "WorkspaceSpecificBack", "an array of textures");
1876 if (changed == 0) {
1877 value = entry->plvalue;
1878 changed = 1;
1879 wwarning(_("using default \"%s\" instead"), entry->default_value);
1880 goto again;
1882 return False;
1885 /* only do basic error checking and verify for None texture */
1887 nelem = WMGetPropListItemCount(value);
1888 if (nelem > 0) {
1889 while (nelem--) {
1890 elem = WMGetFromPLArray(value, nelem);
1891 if (!elem || !WMIsPLArray(elem)) {
1892 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1893 nelem);
1898 *ret = WMRetainPropList(value);
1900 #ifdef notworking
1902 * Kluge to force wmsetbg helper to set the default background.
1903 * If the WorkspaceSpecificBack is changed once wmaker has started,
1904 * the WorkspaceBack won't be sent to the helper, unless the user
1905 * changes it's value too. So, we must force this by removing the
1906 * value from the defaults DB.
1908 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1909 WMPropList *key = WMCreatePLString("WorkspaceBack");
1911 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1913 WMReleasePropList(key);
1915 #endif
1916 return True;
1919 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1921 static WMFont *font;
1922 char *val;
1924 GET_STRING_OR_DEFAULT("Font", val);
1926 font = WMCreateFont(scr->wmscreen, val);
1927 if (!font)
1928 font = WMCreateFont(scr->wmscreen, "fixed");
1930 if (!font) {
1931 wfatal(_("could not load any usable font!!!"));
1932 exit(1);
1935 if (ret)
1936 *ret = font;
1938 /* can't assign font value outside update function */
1939 wassertrv(addr == NULL, True);
1941 return True;
1944 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1946 static XColor color;
1947 char *val;
1948 int second_pass = 0;
1950 GET_STRING_OR_DEFAULT("Color", val);
1952 again:
1953 if (!wGetColor(scr, val, &color)) {
1954 wwarning(_("could not get color for key \"%s\""), entry->key);
1955 if (second_pass == 0) {
1956 val = WMGetFromPLString(entry->plvalue);
1957 second_pass = 1;
1958 wwarning(_("using default \"%s\" instead"), val);
1959 goto again;
1961 return False;
1964 if (ret)
1965 *ret = &color;
1967 assert(addr == NULL);
1969 if (addr)
1970 *(unsigned long*)addr = pixel;
1973 return True;
1976 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1978 static WShortKey shortcut;
1979 KeySym ksym;
1980 char *val;
1981 char *k;
1982 char buf[MAX_SHORTCUT_LENGTH], *b;
1984 GET_STRING_OR_DEFAULT("Key spec", val);
1986 if (!val || strcasecmp(val, "NONE") == 0) {
1987 shortcut.keycode = 0;
1988 shortcut.modifier = 0;
1989 if (ret)
1990 *ret = &shortcut;
1991 return True;
1994 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
1996 b = (char *)buf;
1998 /* get modifiers */
1999 shortcut.modifier = 0;
2000 while ((k = strchr(b, '+')) != NULL) {
2001 int mod;
2003 *k = 0;
2004 mod = wXModifierFromKey(b);
2005 if (mod < 0) {
2006 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2007 return False;
2009 shortcut.modifier |= mod;
2011 b = k + 1;
2014 /* get key */
2015 ksym = XStringToKeysym(b);
2017 if (ksym == NoSymbol) {
2018 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2019 return False;
2022 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2023 if (shortcut.keycode == 0) {
2024 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2025 return False;
2028 if (ret)
2029 *ret = &shortcut;
2031 return True;
2034 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2036 static int mask;
2037 char *str;
2039 GET_STRING_OR_DEFAULT("Modifier Key", str);
2041 if (!str)
2042 return False;
2044 mask = wXModifierFromKey(str);
2045 if (mask < 0) {
2046 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2047 mask = 0;
2048 return False;
2051 if (addr)
2052 *(int *)addr = mask;
2054 if (ret)
2055 *ret = &mask;
2057 return True;
2060 # include <X11/cursorfont.h>
2061 typedef struct {
2062 char *name;
2063 int id;
2064 } WCursorLookup;
2066 #define CURSOR_ID_NONE (XC_num_glyphs)
2068 static WCursorLookup cursor_table[] = {
2069 {"X_cursor", XC_X_cursor},
2070 {"arrow", XC_arrow},
2071 {"based_arrow_down", XC_based_arrow_down},
2072 {"based_arrow_up", XC_based_arrow_up},
2073 {"boat", XC_boat},
2074 {"bogosity", XC_bogosity},
2075 {"bottom_left_corner", XC_bottom_left_corner},
2076 {"bottom_right_corner", XC_bottom_right_corner},
2077 {"bottom_side", XC_bottom_side},
2078 {"bottom_tee", XC_bottom_tee},
2079 {"box_spiral", XC_box_spiral},
2080 {"center_ptr", XC_center_ptr},
2081 {"circle", XC_circle},
2082 {"clock", XC_clock},
2083 {"coffee_mug", XC_coffee_mug},
2084 {"cross", XC_cross},
2085 {"cross_reverse", XC_cross_reverse},
2086 {"crosshair", XC_crosshair},
2087 {"diamond_cross", XC_diamond_cross},
2088 {"dot", XC_dot},
2089 {"dotbox", XC_dotbox},
2090 {"double_arrow", XC_double_arrow},
2091 {"draft_large", XC_draft_large},
2092 {"draft_small", XC_draft_small},
2093 {"draped_box", XC_draped_box},
2094 {"exchange", XC_exchange},
2095 {"fleur", XC_fleur},
2096 {"gobbler", XC_gobbler},
2097 {"gumby", XC_gumby},
2098 {"hand1", XC_hand1},
2099 {"hand2", XC_hand2},
2100 {"heart", XC_heart},
2101 {"icon", XC_icon},
2102 {"iron_cross", XC_iron_cross},
2103 {"left_ptr", XC_left_ptr},
2104 {"left_side", XC_left_side},
2105 {"left_tee", XC_left_tee},
2106 {"leftbutton", XC_leftbutton},
2107 {"ll_angle", XC_ll_angle},
2108 {"lr_angle", XC_lr_angle},
2109 {"man", XC_man},
2110 {"middlebutton", XC_middlebutton},
2111 {"mouse", XC_mouse},
2112 {"pencil", XC_pencil},
2113 {"pirate", XC_pirate},
2114 {"plus", XC_plus},
2115 {"question_arrow", XC_question_arrow},
2116 {"right_ptr", XC_right_ptr},
2117 {"right_side", XC_right_side},
2118 {"right_tee", XC_right_tee},
2119 {"rightbutton", XC_rightbutton},
2120 {"rtl_logo", XC_rtl_logo},
2121 {"sailboat", XC_sailboat},
2122 {"sb_down_arrow", XC_sb_down_arrow},
2123 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2124 {"sb_left_arrow", XC_sb_left_arrow},
2125 {"sb_right_arrow", XC_sb_right_arrow},
2126 {"sb_up_arrow", XC_sb_up_arrow},
2127 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2128 {"shuttle", XC_shuttle},
2129 {"sizing", XC_sizing},
2130 {"spider", XC_spider},
2131 {"spraycan", XC_spraycan},
2132 {"star", XC_star},
2133 {"target", XC_target},
2134 {"tcross", XC_tcross},
2135 {"top_left_arrow", XC_top_left_arrow},
2136 {"top_left_corner", XC_top_left_corner},
2137 {"top_right_corner", XC_top_right_corner},
2138 {"top_side", XC_top_side},
2139 {"top_tee", XC_top_tee},
2140 {"trek", XC_trek},
2141 {"ul_angle", XC_ul_angle},
2142 {"umbrella", XC_umbrella},
2143 {"ur_angle", XC_ur_angle},
2144 {"watch", XC_watch},
2145 {"xterm", XC_xterm},
2146 {NULL, CURSOR_ID_NONE}
2149 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2151 switch (status) {
2152 case BitmapOpenFailed:
2153 wwarning(_("failed to open bitmap file \"%s\""), filename);
2154 break;
2155 case BitmapFileInvalid:
2156 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2157 break;
2158 case BitmapNoMemory:
2159 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2160 break;
2161 case BitmapSuccess:
2162 XFreePixmap(dpy, bitmap);
2163 break;
2168 * (none)
2169 * (builtin, <cursor_name>)
2170 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2172 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2174 WMPropList *elem;
2175 char *val;
2176 int nelem;
2177 int status = 0;
2179 nelem = WMGetPropListItemCount(pl);
2180 if (nelem < 1) {
2181 return (status);
2183 elem = WMGetFromPLArray(pl, 0);
2184 if (!elem || !WMIsPLString(elem)) {
2185 return (status);
2187 val = WMGetFromPLString(elem);
2189 if (strcasecmp(val, "none") == 0) {
2190 status = 1;
2191 *cursor = None;
2192 } else if (strcasecmp(val, "builtin") == 0) {
2193 int i;
2194 int cursor_id = CURSOR_ID_NONE;
2196 if (nelem != 2) {
2197 wwarning(_("bad number of arguments in cursor specification"));
2198 return (status);
2200 elem = WMGetFromPLArray(pl, 1);
2201 if (!elem || !WMIsPLString(elem)) {
2202 return (status);
2204 val = WMGetFromPLString(elem);
2206 for (i = 0; cursor_table[i].name != NULL; i++) {
2207 if (strcasecmp(val, cursor_table[i].name) == 0) {
2208 cursor_id = cursor_table[i].id;
2209 break;
2212 if (CURSOR_ID_NONE == cursor_id) {
2213 wwarning(_("unknown builtin cursor name \"%s\""), val);
2214 } else {
2215 *cursor = XCreateFontCursor(dpy, cursor_id);
2216 status = 1;
2218 } else if (strcasecmp(val, "bitmap") == 0) {
2219 char *bitmap_name;
2220 char *mask_name;
2221 int bitmap_status;
2222 int mask_status;
2223 Pixmap bitmap;
2224 Pixmap mask;
2225 unsigned int w, h;
2226 int x, y;
2227 XColor fg, bg;
2229 if (nelem != 3) {
2230 wwarning(_("bad number of arguments in cursor specification"));
2231 return (status);
2233 elem = WMGetFromPLArray(pl, 1);
2234 if (!elem || !WMIsPLString(elem)) {
2235 return (status);
2237 val = WMGetFromPLString(elem);
2238 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2239 if (!bitmap_name) {
2240 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2241 return (status);
2243 elem = WMGetFromPLArray(pl, 2);
2244 if (!elem || !WMIsPLString(elem)) {
2245 wfree(bitmap_name);
2246 return (status);
2248 val = WMGetFromPLString(elem);
2249 mask_name = FindImage(wPreferences.pixmap_path, val);
2250 if (!mask_name) {
2251 wfree(bitmap_name);
2252 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2253 return (status);
2255 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2256 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2257 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2258 fg.pixel = scr->black_pixel;
2259 bg.pixel = scr->white_pixel;
2260 XQueryColor(dpy, scr->w_colormap, &fg);
2261 XQueryColor(dpy, scr->w_colormap, &bg);
2262 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2263 status = 1;
2265 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2266 check_bitmap_status(mask_status, mask_name, mask);
2267 wfree(bitmap_name);
2268 wfree(mask_name);
2270 return (status);
2273 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2275 static Cursor cursor;
2276 int status;
2277 int changed = 0;
2279 again:
2280 if (!WMIsPLArray(value)) {
2281 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2282 entry->key, "cursor specification");
2283 if (!changed) {
2284 value = entry->plvalue;
2285 changed = 1;
2286 wwarning(_("using default \"%s\" instead"), entry->default_value);
2287 goto again;
2289 return (False);
2291 status = parse_cursor(scr, value, &cursor);
2292 if (!status) {
2293 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2294 if (!changed) {
2295 value = entry->plvalue;
2296 changed = 1;
2297 wwarning(_("using default \"%s\" instead"), entry->default_value);
2298 goto again;
2300 return (False);
2302 if (ret) {
2303 *ret = &cursor;
2305 if (addr) {
2306 *(Cursor *) addr = cursor;
2308 return (True);
2311 #undef CURSOR_ID_NONE
2313 /* ---------------- value setting functions --------------- */
2314 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2316 return REFRESH_WINDOW_TITLE_COLOR;
2319 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2321 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2324 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2326 switch (which) {
2327 case WM_DOCK:
2328 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2329 break;
2330 case WM_CLIP:
2331 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2332 break;
2333 default:
2334 break;
2336 return 0;
2339 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2341 if (scr->workspaces) {
2342 wWorkspaceForceChange(scr, scr->current_workspace);
2343 wArrangeIcons(scr, False);
2345 return 0;
2348 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2350 Pixmap pixmap;
2351 RImage *img;
2352 int reset = 0;
2354 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2355 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2356 ? WREL_ICON : WREL_FLAT);
2357 if (!img) {
2358 wwarning(_("could not render texture for icon background"));
2359 if (!entry->addr)
2360 wTextureDestroy(scr, *texture);
2361 return 0;
2363 RConvertImage(scr->rcontext, img, &pixmap);
2365 if (scr->icon_tile) {
2366 reset = 1;
2367 RReleaseImage(scr->icon_tile);
2368 XFreePixmap(dpy, scr->icon_tile_pixmap);
2371 scr->icon_tile = img;
2373 /* put the icon in the noticeboard hint */
2374 PropSetIconTileHint(scr, img);
2376 if (!wPreferences.flags.noclip) {
2377 if (scr->clip_tile) {
2378 RReleaseImage(scr->clip_tile);
2380 scr->clip_tile = wClipMakeTile(scr, img);
2383 scr->icon_tile_pixmap = pixmap;
2385 if (scr->def_icon_rimage) {
2386 RReleaseImage(scr->def_icon_rimage);
2387 scr->def_icon_rimage = NULL;
2390 if (scr->icon_back_texture)
2391 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2393 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2395 if (scr->clip_balloon)
2396 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2399 * Free the texture as nobody else will use it, nor refer to it.
2401 if (!entry->addr)
2402 wTextureDestroy(scr, *texture);
2404 return (reset ? REFRESH_ICON_TILE : 0);
2407 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2409 if (scr->title_font) {
2410 WMReleaseFont(scr->title_font);
2412 scr->title_font = font;
2414 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2417 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2419 if (scr->menu_title_font) {
2420 WMReleaseFont(scr->menu_title_font);
2423 scr->menu_title_font = font;
2425 return REFRESH_MENU_TITLE_FONT;
2428 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2430 if (scr->menu_entry_font) {
2431 WMReleaseFont(scr->menu_entry_font);
2433 scr->menu_entry_font = font;
2435 return REFRESH_MENU_FONT;
2438 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2440 if (scr->icon_title_font) {
2441 WMReleaseFont(scr->icon_title_font);
2444 scr->icon_title_font = font;
2446 return REFRESH_ICON_FONT;
2449 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2451 if (scr->clip_title_font) {
2452 WMReleaseFont(scr->clip_title_font);
2455 scr->clip_title_font = font;
2457 return REFRESH_ICON_FONT;
2460 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2462 if (scr->workspace_name_font) {
2463 WMReleaseFont(scr->workspace_name_font);
2466 scr->workspace_name_font = font;
2468 return 0;
2471 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2473 if (scr->select_color)
2474 WMReleaseColor(scr->select_color);
2476 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2478 wFreeColor(scr, color->pixel);
2480 return REFRESH_MENU_COLOR;
2483 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2485 if (scr->select_text_color)
2486 WMReleaseColor(scr->select_text_color);
2488 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2490 wFreeColor(scr, color->pixel);
2492 return REFRESH_MENU_COLOR;
2495 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2497 if (scr->clip_title_color[widx])
2498 WMReleaseColor(scr->clip_title_color[widx]);
2500 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2501 wFreeColor(scr, color->pixel);
2503 return REFRESH_ICON_TITLE_COLOR;
2506 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2508 if (scr->window_title_color[widx])
2509 WMReleaseColor(scr->window_title_color[widx]);
2511 scr->window_title_color[widx] =
2512 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2514 wFreeColor(scr, color->pixel);
2516 return REFRESH_WINDOW_TITLE_COLOR;
2519 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2521 if (scr->menu_title_color[0])
2522 WMReleaseColor(scr->menu_title_color[0]);
2524 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2526 wFreeColor(scr, color->pixel);
2528 return REFRESH_MENU_TITLE_COLOR;
2531 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2533 if (scr->mtext_color)
2534 WMReleaseColor(scr->mtext_color);
2536 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2538 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2539 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2540 } else {
2541 WMSetColorAlpha(scr->dtext_color, 0xffff);
2544 wFreeColor(scr, color->pixel);
2546 return REFRESH_MENU_COLOR;
2549 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2551 if (scr->dtext_color)
2552 WMReleaseColor(scr->dtext_color);
2554 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2556 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2557 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2558 } else {
2559 WMSetColorAlpha(scr->dtext_color, 0xffff);
2562 wFreeColor(scr, color->pixel);
2564 return REFRESH_MENU_COLOR;
2567 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2569 if (scr->icon_title_color)
2570 WMReleaseColor(scr->icon_title_color);
2571 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2573 wFreeColor(scr, color->pixel);
2575 return REFRESH_ICON_TITLE_COLOR;
2578 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2580 if (scr->icon_title_texture) {
2581 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2583 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2585 return REFRESH_ICON_TITLE_BACK;
2588 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2590 close(scr->helper_fd);
2591 scr->helper_fd = 0;
2592 scr->helper_pid = 0;
2593 scr->flags.backimage_helper_launched = 0;
2596 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2598 WMPropList *val;
2599 char *str;
2600 int i;
2602 if (scr->flags.backimage_helper_launched) {
2603 if (WMGetPropListItemCount(value) == 0) {
2604 SendHelperMessage(scr, 'C', 0, NULL);
2605 SendHelperMessage(scr, 'K', 0, NULL);
2607 WMReleasePropList(value);
2608 return 0;
2610 } else {
2611 pid_t pid;
2612 int filedes[2];
2614 if (WMGetPropListItemCount(value) == 0)
2615 return 0;
2617 if (pipe(filedes) < 0) {
2618 werror("pipe() failed:can't set workspace specific background image");
2620 WMReleasePropList(value);
2621 return 0;
2624 pid = fork();
2625 if (pid < 0) {
2626 werror("fork() failed:can't set workspace specific background image");
2627 if (close(filedes[0]) < 0)
2628 werror("could not close pipe");
2629 if (close(filedes[1]) < 0)
2630 werror("could not close pipe");
2632 } else if (pid == 0) {
2633 char *dither;
2635 SetupEnvironment(scr);
2637 if (close(0) < 0)
2638 werror("could not close pipe");
2639 if (dup(filedes[0]) < 0) {
2640 werror("dup() failed:can't set workspace specific background image");
2642 dither = wPreferences.no_dithering ? "-m" : "-d";
2643 if (wPreferences.smooth_workspace_back)
2644 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2645 else
2646 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2647 werror("could not execute wmsetbg");
2648 exit(1);
2649 } else {
2651 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2652 werror("error setting close-on-exec flag");
2654 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2655 werror("error setting close-on-exec flag");
2658 scr->helper_fd = filedes[1];
2659 scr->helper_pid = pid;
2660 scr->flags.backimage_helper_launched = 1;
2662 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2664 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2669 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2670 val = WMGetFromPLArray(value, i);
2671 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2672 str = WMGetPropListDescription(val, False);
2674 SendHelperMessage(scr, 'S', i + 1, str);
2676 wfree(str);
2677 } else {
2678 SendHelperMessage(scr, 'U', i + 1, NULL);
2681 sleep(1);
2683 WMReleasePropList(value);
2684 return 0;
2687 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2689 if (scr->flags.backimage_helper_launched) {
2690 char *str;
2692 if (WMGetPropListItemCount(value) == 0) {
2693 SendHelperMessage(scr, 'U', 0, NULL);
2694 } else {
2695 /* set the default workspace background to this one */
2696 str = WMGetPropListDescription(value, False);
2697 if (str) {
2698 SendHelperMessage(scr, 'S', 0, str);
2699 wfree(str);
2700 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2701 } else {
2702 SendHelperMessage(scr, 'U', 0, NULL);
2705 } else if (WMGetPropListItemCount(value) > 0) {
2706 char *command;
2707 char *text;
2708 char *dither;
2709 int len;
2711 text = WMGetPropListDescription(value, False);
2712 len = strlen(text) + 40;
2713 command = wmalloc(len);
2714 dither = wPreferences.no_dithering ? "-m" : "-d";
2715 if (wPreferences.smooth_workspace_back)
2716 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2717 else
2718 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2719 wfree(text);
2720 ExecuteShellCommand(scr, command);
2721 wfree(command);
2723 WMReleasePropList(value);
2725 return 0;
2728 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2730 if (scr->widget_texture) {
2731 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2733 scr->widget_texture = *(WTexSolid **) texture;
2735 return 0;
2738 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2740 if (scr->window_title_texture[WS_FOCUSED]) {
2741 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2743 scr->window_title_texture[WS_FOCUSED] = *texture;
2745 return REFRESH_WINDOW_TEXTURES;
2748 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2750 if (scr->window_title_texture[WS_PFOCUSED]) {
2751 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2753 scr->window_title_texture[WS_PFOCUSED] = *texture;
2755 return REFRESH_WINDOW_TEXTURES;
2758 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2760 if (scr->window_title_texture[WS_UNFOCUSED]) {
2761 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2763 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2765 return REFRESH_WINDOW_TEXTURES;
2768 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2770 if (scr->resizebar_texture[0]) {
2771 wTextureDestroy(scr, scr->resizebar_texture[0]);
2773 scr->resizebar_texture[0] = *texture;
2775 return REFRESH_WINDOW_TEXTURES;
2778 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2780 if (scr->menu_title_texture[0]) {
2781 wTextureDestroy(scr, scr->menu_title_texture[0]);
2783 scr->menu_title_texture[0] = *texture;
2785 return REFRESH_MENU_TITLE_TEXTURE;
2788 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2790 if (scr->menu_item_texture) {
2791 wTextureDestroy(scr, scr->menu_item_texture);
2792 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2794 scr->menu_item_texture = *texture;
2796 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2798 return REFRESH_MENU_TEXTURE;
2801 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2803 WWindow *wwin;
2804 wKeyBindings[widx] = *shortcut;
2806 wwin = scr->focused_window;
2808 while (wwin != NULL) {
2809 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2811 if (!WFLAGP(wwin, no_bind_keys)) {
2812 wWindowSetKeyGrabs(wwin);
2814 wwin = wwin->prev;
2817 return 0;
2820 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2822 wScreenUpdateUsableArea(scr);
2823 wArrangeIcons(scr, True);
2825 return 0;
2828 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2830 wScreenUpdateUsableArea(scr);
2832 return 0;
2835 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2837 return REFRESH_MENU_TEXTURE;
2840 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2842 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2844 RCopyArea(img, image, x, y, w, h, 0, 0);
2846 return img;
2849 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2851 char *path;
2852 RImage *bgimage;
2853 int cwidth, cheight;
2854 WPreferences *prefs = (WPreferences *) foo;
2856 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2857 if (prefs->swtileImage)
2858 RReleaseImage(prefs->swtileImage);
2859 prefs->swtileImage = NULL;
2861 WMReleasePropList(array);
2862 return 0;
2865 switch (WMGetPropListItemCount(array)) {
2866 case 4:
2867 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2868 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2869 break;
2870 } else
2871 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2873 if (!path) {
2874 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2875 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2876 } else {
2877 bgimage = RLoadImage(scr->rcontext, path, 0);
2878 if (!bgimage) {
2879 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2880 wfree(path);
2881 } else {
2882 wfree(path);
2884 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2885 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2887 if (cwidth <= 0 || cheight <= 0 ||
2888 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2889 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2890 else {
2891 int i;
2892 int swidth, theight;
2893 for (i = 0; i < 9; i++) {
2894 if (prefs->swbackImage[i])
2895 RReleaseImage(prefs->swbackImage[i]);
2896 prefs->swbackImage[i] = NULL;
2898 swidth = (bgimage->width - cwidth) / 2;
2899 theight = (bgimage->height - cheight) / 2;
2901 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2902 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2903 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2904 swidth, theight);
2906 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2907 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2908 cwidth, cheight);
2909 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2910 swidth, cheight);
2912 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2913 swidth, theight);
2914 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2915 cwidth, theight);
2916 prefs->swbackImage[8] =
2917 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2918 theight);
2920 // check if anything failed
2921 for (i = 0; i < 9; i++) {
2922 if (!prefs->swbackImage[i]) {
2923 for (; i >= 0; --i) {
2924 RReleaseImage(prefs->swbackImage[i]);
2925 prefs->swbackImage[i] = NULL;
2927 break;
2931 RReleaseImage(bgimage);
2935 case 1:
2936 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
2937 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2938 break;
2939 } else
2940 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
2942 if (!path) {
2943 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2944 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
2945 } else {
2946 if (prefs->swtileImage)
2947 RReleaseImage(prefs->swtileImage);
2949 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
2950 if (!prefs->swtileImage) {
2951 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2953 wfree(path);
2955 break;
2957 default:
2958 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
2959 break;
2962 WMReleasePropList(array);
2964 return 0;
2967 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2969 int i;
2970 WPreferences *prefs = (WPreferences *) foo;
2972 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
2973 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
2974 WMReleasePropList(array);
2975 return 0;
2978 DestroyWindowMenu(scr);
2980 for (i = 0; i < 7; i++) {
2981 if (prefs->modifier_labels[i])
2982 wfree(prefs->modifier_labels[i]);
2984 if (WMIsPLString(WMGetFromPLArray(array, i))) {
2985 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
2986 } else {
2987 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
2988 prefs->modifier_labels[i] = NULL;
2992 WMReleasePropList(array);
2994 return 0;
2998 * Very ugly kluge.
2999 * Need access to the double click variables, so that all widgets in
3000 * wmaker panels will have the same dbl-click values.
3001 * TODO: figure a better way of dealing with it.
3003 #include <WINGs/WINGsP.h>
3005 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3007 extern _WINGsConfiguration WINGsConfiguration;
3009 if (*value <= 0)
3010 *(int *)foo = 1;
3012 WINGsConfiguration.doubleClickDelay = *value;
3014 return 0;
3017 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3019 if (wCursor[widx] != None) {
3020 XFreeCursor(dpy, wCursor[widx]);
3023 wCursor[widx] = *cursor;
3025 if (widx == WCUR_ROOT && *cursor != None) {
3026 XDefineCursor(dpy, scr->root_win, *cursor);
3029 return 0;