Revert "Inotify: Reload keyboard shortcut definitions when configuration changes"
[wmaker-crm.git] / src / defaults.c
blob1f6b6eb6777fcbb9bb141ff263ee622414458449
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <strings.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifndef PATH_MAX
40 #define PATH_MAX DEFAULT_PATH_MAX
41 #endif
43 #include <X11/Xlib.h>
44 #include <X11/Xutil.h>
45 #include <X11/keysym.h>
47 #include <wraster.h>
49 #include "WindowMaker.h"
50 #include "framewin.h"
51 #include "window.h"
52 #include "texture.h"
53 #include "screen.h"
54 #include "resources.h"
55 #include "defaults.h"
56 #include "keybind.h"
57 #include "xmodifier.h"
58 #include "icon.h"
59 #include "funcs.h"
60 #include "actions.h"
61 #include "dock.h"
62 #include "workspace.h"
63 #include "properties.h"
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 {NULL, 0, 0}
210 static WOptionEnumeration seGeomDisplays[] = {
211 {"None", WDIS_NONE, 0},
212 {"Center", WDIS_CENTER, 0},
213 {"Corner", WDIS_TOPLEFT, 0},
214 {"Floating", WDIS_FRAME_CENTER, 0},
215 {"Line", WDIS_NEW, 0},
216 {NULL, 0, 0}
219 static WOptionEnumeration seSpeeds[] = {
220 {"UltraFast", SPEED_ULTRAFAST, 0},
221 {"Fast", SPEED_FAST, 0},
222 {"Medium", SPEED_MEDIUM, 0},
223 {"Slow", SPEED_SLOW, 0},
224 {"UltraSlow", SPEED_ULTRASLOW, 0},
225 {NULL, 0, 0}
228 static WOptionEnumeration seMouseButtonActions[] = {
229 {"None", WA_NONE, 0},
230 {"SelectWindows", WA_SELECT_WINDOWS, 0},
231 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
232 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
233 {NULL, 0, 0}
236 static WOptionEnumeration seMouseWheelActions[] = {
237 {"None", WA_NONE, 0},
238 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
239 {NULL, 0, 0}
242 static WOptionEnumeration seIconificationStyles[] = {
243 {"Zoom", WIS_ZOOM, 0},
244 {"Twist", WIS_TWIST, 0},
245 {"Flip", WIS_FLIP, 0},
246 {"None", WIS_NONE, 0},
247 {"random", WIS_RANDOM, 0},
248 {NULL, 0, 0}
251 static WOptionEnumeration seJustifications[] = {
252 {"Left", WTJ_LEFT, 0},
253 {"Center", WTJ_CENTER, 0},
254 {"Right", WTJ_RIGHT, 0},
255 {NULL, 0, 0}
258 static WOptionEnumeration seIconPositions[] = {
259 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
260 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
261 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
262 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
263 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
264 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
265 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
266 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
267 {NULL, 0, 0}
270 static WOptionEnumeration seMenuStyles[] = {
271 {"normal", MS_NORMAL, 0},
272 {"singletexture", MS_SINGLE_TEXTURE, 0},
273 {"flat", MS_FLAT, 0},
274 {NULL, 0, 0}
277 static WOptionEnumeration seDisplayPositions[] = {
278 {"none", WD_NONE, 0},
279 {"center", WD_CENTER, 0},
280 {"top", WD_TOP, 0},
281 {"bottom", WD_BOTTOM, 0},
282 {"topleft", WD_TOPLEFT, 0},
283 {"topright", WD_TOPRIGHT, 0},
284 {"bottomleft", WD_BOTTOMLEFT, 0},
285 {"bottomright", WD_BOTTOMRIGHT, 0},
286 {NULL, 0, 0}
289 static WOptionEnumeration seWorkspaceBorder[] = {
290 {"None", WB_NONE, 0},
291 {"LeftRight", WB_LEFTRIGHT, 0},
292 {"TopBottom", WB_TOPBOTTOM, 0},
293 {"AllDirections", WB_ALLDIRS, 0},
294 {NULL, 0, 0}
298 * ALL entries in the tables bellow, NEED to have a default value
299 * defined, and this value needs to be correct.
302 /* these options will only affect the window manager on startup
304 * static defaults can't access the screen data, because it is
305 * created after these defaults are read
307 WDefaultEntry staticOptionList[] = {
309 {"ColormapSize", "4", NULL,
310 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
311 {"DisableDithering", "NO", NULL,
312 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
313 {"IconSize", "64", NULL,
314 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
315 {"ModifierKey", "Mod1", NULL,
316 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
317 {"DisableWSMouseActions", "NO", NULL,
318 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
319 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
320 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
321 {"NewStyle", "new", seTitlebarModes,
322 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
323 {"DisableDock", "NO", (void *)WM_DOCK,
324 NULL, getBool, setIfDockPresent, NULL, NULL},
325 {"DisableClip", "NO", (void *)WM_CLIP,
326 NULL, getBool, setIfDockPresent, NULL, NULL},
327 {"DisableMiniwindows", "NO", NULL,
328 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
331 #define NUM2STRING_(x) #x
332 #define NUM2STRING(x) NUM2STRING_(x)
334 WDefaultEntry optionList[] = {
336 /* dynamic options */
338 {"IconPosition", "blh", seIconPositions,
339 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
340 {"IconificationStyle", "Zoom", seIconificationStyles,
341 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
342 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
343 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
344 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
345 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
346 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
347 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
348 {"MouseWheelAction", "None", seMouseWheelActions,
349 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
350 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
351 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
352 {"IconPath", DEF_ICON_PATHS, NULL,
353 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
354 {"ColormapMode", "auto", seColormapModes,
355 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
356 {"AutoFocus", "NO", NULL,
357 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
358 {"RaiseDelay", "0", NULL,
359 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
360 {"CirculateRaise", "NO", NULL,
361 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
362 {"Superfluous", "NO", NULL,
363 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
364 {"AdvanceToNewWorkspace", "NO", NULL,
365 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
366 {"CycleWorkspaces", "NO", NULL,
367 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
368 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
369 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
370 {"WorkspaceBorder", "None", seWorkspaceBorder,
371 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
372 {"WorkspaceBorderSize", "0", NULL,
373 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
374 {"StickyIcons", "NO", NULL,
375 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
376 {"SaveSessionOnExit", "NO", NULL,
377 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
378 {"WrapMenus", "NO", NULL,
379 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
380 {"ScrollableMenus", "NO", NULL,
381 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
382 {"MenuScrollSpeed", "medium", seSpeeds,
383 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
384 {"IconSlideSpeed", "medium", seSpeeds,
385 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
386 {"ShadeSpeed", "medium", seSpeeds,
387 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
388 {"BounceAppIconsWhenUrgent", "YES", NULL,
389 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
390 {"RaiseAppIconsWhenBouncing", "NO", NULL,
391 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
392 {"DoNotMakeAppIconsBounce", "NO", NULL,
393 &wPreferences.do_not_make_appicons_bounce, getBool, NULL, NULL, NULL},
394 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
395 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
396 {"AlignSubmenus", "NO", NULL,
397 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
398 {"ViKeyMenus", "NO", NULL,
399 &wPreferences.vi_key_menus, getBool, NULL, NULL, NULL},
400 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
401 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
402 {"WindowPlacement", "auto", sePlacements,
403 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
404 {"IgnoreFocusClick", "NO", NULL,
405 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
406 {"UseSaveUnders", "NO", NULL,
407 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
408 {"OpaqueMove", "NO", NULL,
409 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
410 {"OpaqueResize", "NO", NULL,
411 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
412 {"OpaqueMoveResizeKeyboard", "NO", NULL,
413 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
414 {"DisableAnimations", "NO", NULL,
415 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
416 {"DontLinkWorkspaces", "NO", NULL,
417 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
418 {"AutoArrangeIcons", "NO", NULL,
419 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
420 {"NoWindowOverDock", "NO", NULL,
421 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
422 {"NoWindowOverIcons", "NO", NULL,
423 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
424 {"WindowPlaceOrigin", "(0, 0)", NULL,
425 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
426 {"ResizeDisplay", "corner", seGeomDisplays,
427 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
428 {"MoveDisplay", "corner", seGeomDisplays,
429 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
430 {"DontConfirmKill", "NO", NULL,
431 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
432 {"WindowTitleBalloons", "NO", NULL,
433 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
434 {"MiniwindowTitleBalloons", "NO", NULL,
435 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
436 {"AppIconBalloons", "NO", NULL,
437 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
438 {"HelpBalloons", "NO", NULL,
439 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
440 {"EdgeResistance", "30", NULL,
441 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
442 {"ResizeIncrement", "32", NULL,
443 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
444 {"Attraction", "NO", NULL,
445 &wPreferences.attract, getBool, NULL, NULL, NULL},
446 {"DisableBlinking", "NO", NULL,
447 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
448 {"SingleClickLaunch", "NO", NULL,
449 &wPreferences.single_click, getBool, NULL, NULL, NULL},
451 /* style options */
453 {"MenuStyle", "normal", seMenuStyles,
454 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
455 {"WidgetColor", "(solid, gray)", NULL,
456 NULL, getTexture, setWidgetColor, NULL, NULL},
457 {"WorkspaceSpecificBack", "()", NULL,
458 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
459 /* WorkspaceBack must come after WorkspaceSpecificBack or
460 * WorkspaceBack wont know WorkspaceSpecificBack was also
461 * specified and 2 copies of wmsetbg will be launched */
462 {"WorkspaceBack", "(solid, black)", NULL,
463 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
464 {"SmoothWorkspaceBack", "NO", NULL,
465 NULL, getBool, NULL, NULL, NULL},
466 {"IconBack", "(solid, gray)", NULL,
467 NULL, getTexture, setIconTile, NULL, NULL},
468 {"TitleJustify", "center", seJustifications,
469 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
470 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
471 NULL, getFont, setWinTitleFont, NULL, NULL},
472 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
473 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
474 {"WindowTitleMinHeight", "0", NULL,
475 &wPreferences.window_title_min_height, getInt, setClearance, NULL, NULL},
476 {"WindowTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
477 &wPreferences.window_title_max_height, getInt, setClearance, NULL, NULL},
478 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
479 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
480 {"MenuTitleMinHeight", "0", NULL,
481 &wPreferences.menu_title_min_height, getInt, setClearance, NULL, NULL},
482 {"MenuTitleMaxHeight", NUM2STRING(INT_MAX), NULL,
483 &wPreferences.menu_title_max_height, getInt, setClearance, NULL, NULL},
484 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
485 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
486 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
487 NULL, getFont, setMenuTitleFont, NULL, NULL},
488 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
489 NULL, getFont, setMenuTextFont, NULL, NULL},
490 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
491 NULL, getFont, setIconTitleFont, NULL, NULL},
492 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
493 NULL, getFont, setClipTitleFont, NULL, NULL},
494 {"ShowClipTitle", "YES", NULL,
495 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
496 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
497 NULL, getFont, setLargeDisplayFont, NULL, NULL},
498 {"HighlightColor", "white", NULL,
499 NULL, getColor, setHightlight, NULL, NULL},
500 {"HighlightTextColor", "black", NULL,
501 NULL, getColor, setHightlightText, NULL, NULL},
502 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
503 NULL, getColor, setClipTitleColor, NULL, NULL},
504 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
505 NULL, getColor, setClipTitleColor, NULL, NULL},
506 {"FTitleColor", "white", (void *)WS_FOCUSED,
507 NULL, getColor, setWTitleColor, NULL, NULL},
508 {"PTitleColor", "white", (void *)WS_PFOCUSED,
509 NULL, getColor, setWTitleColor, NULL, NULL},
510 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
511 NULL, getColor, setWTitleColor, NULL, NULL},
512 {"FTitleBack", "(solid, black)", NULL,
513 NULL, getTexture, setFTitleBack, NULL, NULL},
514 {"PTitleBack", "(solid, \"#616161\")", NULL,
515 NULL, getTexture, setPTitleBack, NULL, NULL},
516 {"UTitleBack", "(solid, gray)", NULL,
517 NULL, getTexture, setUTitleBack, NULL, NULL},
518 {"ResizebarBack", "(solid, gray)", NULL,
519 NULL, getTexture, setResizebarBack, NULL, NULL},
520 {"MenuTitleColor", "white", NULL,
521 NULL, getColor, setMenuTitleColor, NULL, NULL},
522 {"MenuTextColor", "black", NULL,
523 NULL, getColor, setMenuTextColor, NULL, NULL},
524 {"MenuDisabledColor", "\"#616161\"", NULL,
525 NULL, getColor, setMenuDisabledColor, NULL, NULL},
526 {"MenuTitleBack", "(solid, black)", NULL,
527 NULL, getTexture, setMenuTitleBack, NULL, NULL},
528 {"MenuTextBack", "(solid, gray)", NULL,
529 NULL, getTexture, setMenuTextBack, NULL, NULL},
530 {"IconTitleColor", "white", NULL,
531 NULL, getColor, setIconTitleColor, NULL, NULL},
532 {"IconTitleBack", "black", NULL,
533 NULL, getColor, setIconTitleBack, NULL, NULL},
534 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
535 NULL, getPropList, setSwPOptions, NULL, NULL},
536 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
537 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
539 /* keybindings */
541 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
542 NULL, getKeybind, setKeyGrab, NULL, NULL},
543 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
544 NULL, getKeybind, setKeyGrab, NULL, NULL},
545 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
546 NULL, getKeybind, setKeyGrab, NULL, NULL},
547 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
548 NULL, getKeybind, setKeyGrab, NULL, NULL},
549 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
550 NULL, getKeybind, setKeyGrab, NULL, NULL},
551 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
552 NULL, getKeybind, setKeyGrab, NULL, NULL},
553 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
554 NULL, getKeybind, setKeyGrab, NULL, NULL },
555 {"HideKey", "None", (void *)WKBD_HIDE,
556 NULL, getKeybind, setKeyGrab, NULL, NULL},
557 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
558 NULL, getKeybind, setKeyGrab, NULL, NULL},
559 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
560 NULL, getKeybind, setKeyGrab, NULL, NULL},
561 {"CloseKey", "None", (void *)WKBD_CLOSE,
562 NULL, getKeybind, setKeyGrab, NULL, NULL},
563 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
564 NULL, getKeybind, setKeyGrab, NULL, NULL},
565 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
566 NULL, getKeybind, setKeyGrab, NULL, NULL},
567 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
568 NULL, getKeybind, setKeyGrab, NULL, NULL},
569 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
570 NULL, getKeybind, setKeyGrab, NULL, NULL},
571 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
572 NULL, getKeybind, setKeyGrab, NULL, NULL},
573 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
574 NULL, getKeybind, setKeyGrab, NULL, NULL},
575 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
576 NULL, getKeybind, setKeyGrab, NULL, NULL},
577 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
578 NULL, getKeybind, setKeyGrab, NULL, NULL},
579 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
580 NULL, getKeybind, setKeyGrab, NULL, NULL},
581 {"ShadeKey", "None", (void *)WKBD_SHADE,
582 NULL, getKeybind, setKeyGrab, NULL, NULL},
583 {"SelectKey", "None", (void *)WKBD_SELECT,
584 NULL, getKeybind, setKeyGrab, NULL, NULL},
585 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
586 NULL, getKeybind, setKeyGrab, NULL, NULL},
587 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
588 NULL, getKeybind, setKeyGrab, NULL, NULL},
589 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
590 NULL, getKeybind, setKeyGrab, NULL, NULL},
591 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
592 NULL, getKeybind, setKeyGrab, NULL, NULL},
593 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
594 NULL, getKeybind, setKeyGrab, NULL, NULL},
595 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
596 NULL, getKeybind, setKeyGrab, NULL, NULL},
597 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
598 NULL, getKeybind, setKeyGrab, NULL, NULL},
599 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
600 NULL, getKeybind, setKeyGrab, NULL, NULL},
601 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
602 NULL, getKeybind, setKeyGrab, NULL, NULL},
603 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
604 NULL, getKeybind, setKeyGrab, NULL, NULL},
605 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
606 NULL, getKeybind, setKeyGrab, NULL, NULL},
607 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
608 NULL, getKeybind, setKeyGrab, NULL, NULL},
609 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
610 NULL, getKeybind, setKeyGrab, NULL, NULL},
611 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
612 NULL, getKeybind, setKeyGrab, NULL, NULL},
613 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
614 NULL, getKeybind, setKeyGrab, NULL, NULL},
615 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
616 NULL, getKeybind, setKeyGrab, NULL, NULL},
617 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
618 NULL, getKeybind, setKeyGrab, NULL, NULL},
619 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
620 NULL, getKeybind, setKeyGrab, NULL, NULL},
621 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
622 NULL, getKeybind, setKeyGrab, NULL, NULL},
623 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
624 NULL, getKeybind, setKeyGrab, NULL, NULL},
625 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
626 NULL, getKeybind, setKeyGrab, NULL, NULL},
627 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
628 NULL, getKeybind, setKeyGrab, NULL, NULL},
629 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
630 NULL, getKeybind, setKeyGrab, NULL, NULL},
631 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
632 NULL, getKeybind, setKeyGrab, NULL, NULL},
633 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
634 NULL, getKeybind, setKeyGrab, NULL, NULL},
635 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
636 NULL, getKeybind, setKeyGrab, NULL, NULL},
637 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
638 NULL, getKeybind, setKeyGrab, NULL, NULL},
639 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
640 NULL, getKeybind, setKeyGrab, NULL, NULL},
641 {"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
642 NULL, getKeybind, setKeyGrab, NULL, NULL},
643 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
644 NULL, getKeybind, setKeyGrab, NULL, NULL},
646 #ifdef KEEP_XKB_LOCK_STATUS
647 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
648 NULL, getKeybind, setKeyGrab, NULL, NULL},
649 {"KbdModeLock", "NO", NULL,
650 &wPreferences.modelock, getBool, NULL, NULL, NULL},
651 #endif /* KEEP_XKB_LOCK_STATUS */
653 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
654 NULL, getCursor, setCursor, NULL, NULL},
655 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
656 NULL, getCursor, setCursor, NULL, NULL},
657 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
658 NULL, getCursor, setCursor, NULL, NULL},
659 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
660 NULL, getCursor, setCursor, NULL, NULL},
661 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
662 NULL, getCursor, setCursor, NULL, NULL},
663 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
664 NULL, getCursor, setCursor, NULL, NULL},
665 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
666 NULL, getCursor, setCursor, NULL, NULL},
667 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
668 NULL, getCursor, setCursor, NULL, NULL},
669 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
670 NULL, getCursor, setCursor, NULL, NULL},
671 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
672 NULL, getCursor, setCursor, NULL, NULL},
673 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
674 NULL, getCursor, setCursor, NULL, NULL},
675 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
676 NULL, getCursor, setCursor, NULL, NULL},
677 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
678 NULL, getCursor, setCursor, NULL, NULL},
679 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
680 NULL, getCursor, setCursor, NULL, NULL},
681 {"DialogHistoryLines", "500", NULL,
682 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
683 {"CycleActiveHeadOnly", "NO", NULL,
684 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL}
687 static void initDefaults()
689 unsigned int i;
690 WDefaultEntry *entry;
692 WMPLSetCaseSensitive(False);
694 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
695 entry = &optionList[i];
697 entry->plkey = WMCreatePLString(entry->key);
698 if (entry->default_value)
699 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
700 else
701 entry->plvalue = NULL;
704 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
705 entry = &staticOptionList[i];
707 entry->plkey = WMCreatePLString(entry->key);
708 if (entry->default_value)
709 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
710 else
711 entry->plvalue = NULL;
715 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
717 WMPropList *globalDict = NULL;
718 char path[PATH_MAX];
719 struct stat stbuf;
721 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
722 if (stat(path, &stbuf) >= 0) {
723 globalDict = WMReadPropListFromFile(path);
724 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
725 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
726 WMReleasePropList(globalDict);
727 globalDict = NULL;
728 } else if (!globalDict) {
729 wwarning(_("could not load domain %s from global defaults database"), domainName);
733 return globalDict;
736 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
737 static void prependMenu(WMPropList * destarr, WMPropList * array)
739 WMPropList *item;
740 int i;
742 for (i = 0; i < WMGetPropListItemCount(array); i++) {
743 item = WMGetFromPLArray(array, i);
744 if (item)
745 WMInsertInPLArray(destarr, i + 1, item);
749 static void appendMenu(WMPropList * destarr, WMPropList * array)
751 WMPropList *item;
752 int i;
754 for (i = 0; i < WMGetPropListItemCount(array); i++) {
755 item = WMGetFromPLArray(array, i);
756 if (item)
757 WMAddToPLArray(destarr, item);
760 #endif
762 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
764 WMPropList *menu = menuDomain->dictionary;
765 WMPropList *submenu;
767 if (!menu || !WMIsPLArray(menu))
768 return;
770 #ifdef GLOBAL_PREAMBLE_MENU_FILE
771 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
773 if (submenu && !WMIsPLArray(submenu)) {
774 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
775 WMReleasePropList(submenu);
776 submenu = NULL;
778 if (submenu) {
779 prependMenu(menu, submenu);
780 WMReleasePropList(submenu);
782 #endif
784 #ifdef GLOBAL_EPILOGUE_MENU_FILE
785 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
787 if (submenu && !WMIsPLArray(submenu)) {
788 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
789 WMReleasePropList(submenu);
790 submenu = NULL;
792 if (submenu) {
793 appendMenu(menu, submenu);
794 WMReleasePropList(submenu);
796 #endif
798 menuDomain->dictionary = menu;
801 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
803 WDDomain *db;
804 struct stat stbuf;
805 static int inited = 0;
806 char path[PATH_MAX];
807 char *the_path;
808 WMPropList *shared_dict = NULL;
810 if (!inited) {
811 inited = 1;
812 initDefaults();
815 db = wmalloc(sizeof(WDDomain));
816 memset(db, 0, sizeof(WDDomain));
817 db->domain_name = domain;
818 db->path = wdefaultspathfordomain(domain);
819 the_path = db->path;
821 if (the_path && stat(the_path, &stbuf) >= 0) {
822 db->dictionary = WMReadPropListFromFile(the_path);
823 if (db->dictionary) {
824 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
825 WMReleasePropList(db->dictionary);
826 db->dictionary = NULL;
827 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
829 db->timestamp = stbuf.st_mtime;
830 } else {
831 wwarning(_("could not load domain %s from user defaults database"), domain);
835 /* global system dictionary */
836 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
837 if (stat(path, &stbuf) >= 0) {
838 shared_dict = WMReadPropListFromFile(path);
839 if (shared_dict) {
840 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
841 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
842 domain, path);
843 WMReleasePropList(shared_dict);
844 shared_dict = NULL;
845 } else {
846 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
847 WMIsPLDictionary(db->dictionary)) {
848 WMMergePLDictionaries(shared_dict, db->dictionary, True);
849 WMReleasePropList(db->dictionary);
850 db->dictionary = shared_dict;
851 if (stbuf.st_mtime > db->timestamp)
852 db->timestamp = stbuf.st_mtime;
853 } else if (!db->dictionary) {
854 db->dictionary = shared_dict;
855 if (stbuf.st_mtime > db->timestamp)
856 db->timestamp = stbuf.st_mtime;
859 } else {
860 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
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 if (!plvalue) {
883 /* no default in the DB. Use builtin default */
884 plvalue = entry->plvalue;
887 if (plvalue) {
888 /* convert data */
889 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
890 if (entry->update) {
891 (*entry->update) (NULL, entry, tdata, entry->extra_data);
897 void wDefaultsCheckDomains(void* arg)
899 WScreen *scr;
900 struct stat stbuf;
901 WMPropList *shared_dict = NULL;
902 WMPropList *dict;
903 int i;
905 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
906 WDWindowMaker->timestamp = stbuf.st_mtime;
908 /* Global dictionary */
909 shared_dict = readGlobalDomain("WindowMaker", True);
911 /* User dictionary */
912 dict = WMReadPropListFromFile(WDWindowMaker->path);
914 if (dict) {
915 if (!WMIsPLDictionary(dict)) {
916 WMReleasePropList(dict);
917 dict = NULL;
918 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
919 "WindowMaker", WDWindowMaker->path);
920 } else {
921 if (shared_dict) {
922 WMMergePLDictionaries(shared_dict, dict, True);
923 WMReleasePropList(dict);
924 dict = shared_dict;
925 shared_dict = NULL;
928 for (i = 0; i < wScreenCount; i++) {
929 scr = wScreenWithNumber(i);
930 if (scr)
931 wReadDefaults(scr, dict);
934 if (WDWindowMaker->dictionary)
935 WMReleasePropList(WDWindowMaker->dictionary);
937 WDWindowMaker->dictionary = dict;
939 } else {
940 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
943 if (shared_dict)
944 WMReleasePropList(shared_dict);
948 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
949 /* global dictionary */
950 shared_dict = readGlobalDomain("WMWindowAttributes", True);
951 /* user dictionary */
952 dict = WMReadPropListFromFile(WDWindowAttributes->path);
953 if (dict) {
954 if (!WMIsPLDictionary(dict)) {
955 WMReleasePropList(dict);
956 dict = NULL;
957 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
958 "WMWindowAttributes", WDWindowAttributes->path);
959 } else {
960 if (shared_dict) {
961 WMMergePLDictionaries(shared_dict, dict, True);
962 WMReleasePropList(dict);
963 dict = shared_dict;
964 shared_dict = NULL;
966 if (WDWindowAttributes->dictionary) {
967 WMReleasePropList(WDWindowAttributes->dictionary);
969 WDWindowAttributes->dictionary = dict;
970 for (i = 0; i < wScreenCount; i++) {
971 scr = wScreenWithNumber(i);
972 if (scr) {
973 RImage *image;
975 wDefaultUpdateIcons(scr);
977 /* Update the panel image if changed */
978 /* Don't worry. If the image is the same these
979 * functions will have no performance impact. */
980 image = wDefaultGetImage(scr, "Logo", "WMPanel", wPreferences.icon_size);
982 if (!image) {
983 wwarning(_("could not load logo image for panels: %s"),
984 RMessageForError(RErrorCode));
985 } else {
986 WMSetApplicationIconImage(scr->wmscreen, image);
987 RReleaseImage(image);
992 } else {
993 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
995 WDWindowAttributes->timestamp = stbuf.st_mtime;
996 if (shared_dict) {
997 WMReleasePropList(shared_dict);
1001 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1002 dict = WMReadPropListFromFile(WDRootMenu->path);
1003 if (dict) {
1004 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1005 WMReleasePropList(dict);
1006 dict = NULL;
1007 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1008 "WMRootMenu", WDRootMenu->path);
1009 } else {
1010 if (WDRootMenu->dictionary) {
1011 WMReleasePropList(WDRootMenu->dictionary);
1013 WDRootMenu->dictionary = dict;
1014 wDefaultsMergeGlobalMenus(WDRootMenu);
1016 } else {
1017 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1019 WDRootMenu->timestamp = stbuf.st_mtime;
1021 #ifndef HAVE_INOTIFY
1022 if (!arg)
1023 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1024 #endif
1027 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1029 WMPropList *plvalue, *old_value;
1030 WDefaultEntry *entry;
1031 unsigned int i;
1032 int update_workspace_back = 0; /* kluge :/ */
1033 unsigned int needs_refresh;
1034 void *tdata;
1035 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1037 needs_refresh = 0;
1039 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1040 entry = &optionList[i];
1042 if (new_dict)
1043 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1044 else
1045 plvalue = NULL;
1047 if (!old_dict)
1048 old_value = NULL;
1049 else
1050 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1052 if (!plvalue && !old_value) {
1053 /* no default in the DB. Use builtin default */
1054 plvalue = entry->plvalue;
1055 if (plvalue && new_dict)
1056 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1058 } else if (!plvalue) {
1059 /* value was deleted from DB. Keep current value */
1060 continue;
1061 } else if (!old_value) {
1062 /* set value for the 1st time */
1063 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1064 /* value has changed */
1065 } else {
1066 if (strcmp(entry->key, "WorkspaceBack") == 0
1067 && update_workspace_back && scr->flags.backimage_helper_launched) {
1068 } else {
1069 /* value was not changed since last time */
1070 continue;
1074 if (plvalue) {
1075 /* convert data */
1076 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1078 * If the WorkspaceSpecificBack data has been changed
1079 * so that the helper will be launched now, we must be
1080 * sure to send the default background texture config
1081 * to the helper.
1083 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0 &&
1084 !scr->flags.backimage_helper_launched)
1085 update_workspace_back = 1;
1087 if (entry->update)
1088 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1094 if (needs_refresh != 0 && !scr->flags.startup) {
1095 int foo;
1097 foo = 0;
1098 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1099 foo |= WTextureSettings;
1100 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1101 foo |= WFontSettings;
1102 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1103 foo |= WColorSettings;
1104 if (foo)
1105 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1106 (void *)(uintptr_t) foo);
1108 foo = 0;
1109 if (needs_refresh & REFRESH_MENU_TEXTURE)
1110 foo |= WTextureSettings;
1111 if (needs_refresh & REFRESH_MENU_FONT)
1112 foo |= WFontSettings;
1113 if (needs_refresh & REFRESH_MENU_COLOR)
1114 foo |= WColorSettings;
1115 if (foo)
1116 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1118 foo = 0;
1119 if (needs_refresh & REFRESH_WINDOW_FONT)
1120 foo |= WFontSettings;
1121 if (needs_refresh & REFRESH_WINDOW_TEXTURES)
1122 foo |= WTextureSettings;
1123 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR)
1124 foo |= WColorSettings;
1125 if (foo)
1126 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1128 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1129 foo = 0;
1130 if (needs_refresh & REFRESH_ICON_FONT)
1131 foo |= WFontSettings;
1132 if (needs_refresh & REFRESH_ICON_TITLE_COLOR)
1133 foo |= WTextureSettings;
1134 if (needs_refresh & REFRESH_ICON_TITLE_BACK)
1135 foo |= WTextureSettings;
1136 if (foo)
1137 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1138 (void *)(uintptr_t) foo);
1140 if (needs_refresh & REFRESH_ICON_TILE)
1141 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1145 void wDefaultUpdateIcons(WScreen * scr)
1147 WAppIcon *aicon = scr->app_icon_list;
1148 WWindow *wwin = scr->focused_window;
1149 char *file;
1151 while (aicon) {
1152 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1153 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1154 || (file && !aicon->icon->file)) {
1155 wIconChangeImageFile(aicon->icon, file);
1156 wAppIconPaint(aicon);
1158 aicon = aicon->next;
1161 if (!wPreferences.flags.noclip)
1162 wClipIconPaint(scr->clip_icon);
1164 while (wwin) {
1165 if (wwin->icon && wwin->flags.miniaturized) {
1166 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1167 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1168 || (file && !wwin->icon->file)) {
1169 wIconChangeImageFile(wwin->icon, file);
1172 wwin = wwin->prev;
1176 /* --------------------------- Local ----------------------- */
1178 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1179 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1180 entry->key, x); \
1181 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1182 var = entry->default_value;\
1183 } else var = WMGetFromPLString(value)\
1186 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1188 char *str;
1189 WOptionEnumeration *v;
1190 char buffer[TOTAL_VALUES_LENGTH];
1192 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1193 for (v = values; v->string != NULL; v++) {
1194 if (strcasecmp(v->string, str) == 0)
1195 return v->value;
1199 buffer[0] = 0;
1200 for (v = values; v->string != NULL; v++) {
1201 if (!v->is_alias) {
1202 if (buffer[0] != 0)
1203 strcat(buffer, ", ");
1204 snprintf(buffer+strlen(buffer),
1205 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1208 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1209 WMGetFromPLString(key),
1210 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1211 buffer);
1213 if (def) {
1214 return string2index(key, val, NULL, values);
1217 return -1;
1221 * value - is the value in the defaults DB
1222 * addr - is the address to store the data
1223 * ret - is the address to store a pointer to a temporary buffer. ret
1224 * must not be freed and is used by the set functions
1226 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1228 static char data;
1229 char *val;
1230 int second_pass = 0;
1232 GET_STRING_OR_DEFAULT("Boolean", val);
1234 again:
1235 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1236 || strcasecmp(val, "YES") == 0) {
1238 data = 1;
1239 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1240 || strcasecmp(val, "NO") == 0) {
1241 data = 0;
1242 } else {
1243 int i;
1244 if (sscanf(val, "%i", &i) == 1) {
1245 if (i != 0)
1246 data = 1;
1247 else
1248 data = 0;
1249 } else {
1250 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1251 if (second_pass == 0) {
1252 val = WMGetFromPLString(entry->plvalue);
1253 second_pass = 1;
1254 wwarning(_("using default \"%s\" instead"), val);
1255 goto again;
1257 return False;
1261 if (ret)
1262 *ret = &data;
1263 if (addr)
1264 *(char *)addr = data;
1266 return True;
1269 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1271 static int data;
1272 char *val;
1274 GET_STRING_OR_DEFAULT("Integer", val);
1276 if (sscanf(val, "%i", &data) != 1) {
1277 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1278 val = WMGetFromPLString(entry->plvalue);
1279 wwarning(_("using default \"%s\" instead"), val);
1280 if (sscanf(val, "%i", &data) != 1) {
1281 return False;
1285 if (ret)
1286 *ret = &data;
1287 if (addr)
1288 *(int *)addr = data;
1290 return True;
1293 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1295 static WCoord data;
1296 char *val_x, *val_y;
1297 int nelem, changed = 0;
1298 WMPropList *elem_x, *elem_y;
1300 again:
1301 if (!WMIsPLArray(value)) {
1302 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1303 if (changed == 0) {
1304 value = entry->plvalue;
1305 changed = 1;
1306 wwarning(_("using default \"%s\" instead"), entry->default_value);
1307 goto again;
1309 return False;
1312 nelem = WMGetPropListItemCount(value);
1313 if (nelem != 2) {
1314 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1315 if (changed == 0) {
1316 value = entry->plvalue;
1317 changed = 1;
1318 wwarning(_("using default \"%s\" instead"), entry->default_value);
1319 goto again;
1321 return False;
1324 elem_x = WMGetFromPLArray(value, 0);
1325 elem_y = WMGetFromPLArray(value, 1);
1327 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1328 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1329 if (changed == 0) {
1330 value = entry->plvalue;
1331 changed = 1;
1332 wwarning(_("using default \"%s\" instead"), entry->default_value);
1333 goto again;
1335 return False;
1338 val_x = WMGetFromPLString(elem_x);
1339 val_y = WMGetFromPLString(elem_y);
1341 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1342 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1343 if (changed == 0) {
1344 value = entry->plvalue;
1345 changed = 1;
1346 wwarning(_("using default \"%s\" instead"), entry->default_value);
1347 goto again;
1349 return False;
1352 if (data.x < 0)
1353 data.x = 0;
1354 else if (data.x > scr->scr_width / 3)
1355 data.x = scr->scr_width / 3;
1356 if (data.y < 0)
1357 data.y = 0;
1358 else if (data.y > scr->scr_height / 3)
1359 data.y = scr->scr_height / 3;
1361 if (ret)
1362 *ret = &data;
1363 if (addr)
1364 *(WCoord *) addr = data;
1366 return True;
1369 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1371 WMRetainPropList(value);
1373 *ret = value;
1375 return True;
1378 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1380 static char *data;
1381 int i, count, len;
1382 char *ptr;
1383 WMPropList *d;
1384 int changed = 0;
1386 again:
1387 if (!WMIsPLArray(value)) {
1388 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1389 if (changed == 0) {
1390 value = entry->plvalue;
1391 changed = 1;
1392 wwarning(_("using default \"%s\" instead"), entry->default_value);
1393 goto again;
1395 return False;
1398 i = 0;
1399 count = WMGetPropListItemCount(value);
1400 if (count < 1) {
1401 if (changed == 0) {
1402 value = entry->plvalue;
1403 changed = 1;
1404 wwarning(_("using default \"%s\" instead"), entry->default_value);
1405 goto again;
1407 return False;
1410 len = 0;
1411 for (i = 0; i < count; i++) {
1412 d = WMGetFromPLArray(value, i);
1413 if (!d || !WMIsPLString(d)) {
1414 count = i;
1415 break;
1417 len += strlen(WMGetFromPLString(d)) + 1;
1420 ptr = data = wmalloc(len + 1);
1422 for (i = 0; i < count; i++) {
1423 d = WMGetFromPLArray(value, i);
1424 if (!d || !WMIsPLString(d)) {
1425 break;
1427 strcpy(ptr, WMGetFromPLString(d));
1428 ptr += strlen(WMGetFromPLString(d));
1429 *ptr = ':';
1430 ptr++;
1432 ptr--;
1433 *(ptr--) = 0;
1435 if (*(char **)addr != NULL) {
1436 wfree(*(char **)addr);
1438 *(char **)addr = data;
1440 return True;
1443 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1445 static signed char data;
1447 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1448 if (data < 0)
1449 return False;
1451 if (ret)
1452 *ret = &data;
1453 if (addr)
1454 *(signed char *)addr = data;
1456 return True;
1460 * (solid <color>)
1461 * (hgradient <color> <color>)
1462 * (vgradient <color> <color>)
1463 * (dgradient <color> <color>)
1464 * (mhgradient <color> <color> ...)
1465 * (mvgradient <color> <color> ...)
1466 * (mdgradient <color> <color> ...)
1467 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1468 * (tpixmap <file> <color>)
1469 * (spixmap <file> <color>)
1470 * (cpixmap <file> <color>)
1471 * (thgradient <file> <opaqueness> <color> <color>)
1472 * (tvgradient <file> <opaqueness> <color> <color>)
1473 * (tdgradient <file> <opaqueness> <color> <color>)
1474 * (function <lib> <function> ...)
1477 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1479 WMPropList *elem;
1480 char *val;
1481 int nelem;
1482 WTexture *texture = NULL;
1484 nelem = WMGetPropListItemCount(pl);
1485 if (nelem < 1)
1486 return NULL;
1488 elem = WMGetFromPLArray(pl, 0);
1489 if (!elem || !WMIsPLString(elem))
1490 return NULL;
1491 val = WMGetFromPLString(elem);
1493 if (strcasecmp(val, "solid") == 0) {
1494 XColor color;
1496 if (nelem != 2)
1497 return NULL;
1499 /* get color */
1501 elem = WMGetFromPLArray(pl, 1);
1502 if (!elem || !WMIsPLString(elem))
1503 return NULL;
1504 val = WMGetFromPLString(elem);
1506 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1507 wwarning(_("\"%s\" is not a valid color name"), val);
1508 return NULL;
1511 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1512 } else if (strcasecmp(val, "dgradient") == 0
1513 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1514 RColor color1, color2;
1515 XColor xcolor;
1516 int type;
1518 if (nelem != 3) {
1519 wwarning(_("bad number of arguments in gradient specification"));
1520 return NULL;
1523 if (val[0] == 'd' || val[0] == 'D')
1524 type = WTEX_DGRADIENT;
1525 else if (val[0] == 'h' || val[0] == 'H')
1526 type = WTEX_HGRADIENT;
1527 else
1528 type = WTEX_VGRADIENT;
1530 /* get from color */
1531 elem = WMGetFromPLArray(pl, 1);
1532 if (!elem || !WMIsPLString(elem))
1533 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 color1.alpha = 255;
1541 color1.red = xcolor.red >> 8;
1542 color1.green = xcolor.green >> 8;
1543 color1.blue = xcolor.blue >> 8;
1545 /* get to color */
1546 elem = WMGetFromPLArray(pl, 2);
1547 if (!elem || !WMIsPLString(elem)) {
1548 return NULL;
1550 val = WMGetFromPLString(elem);
1552 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1553 wwarning(_("\"%s\" is not a valid color name"), val);
1554 return NULL;
1556 color2.alpha = 255;
1557 color2.red = xcolor.red >> 8;
1558 color2.green = xcolor.green >> 8;
1559 color2.blue = xcolor.blue >> 8;
1561 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1563 } else if (strcasecmp(val, "igradient") == 0) {
1564 RColor colors1[2], colors2[2];
1565 int th1, th2;
1566 XColor xcolor;
1567 int i;
1569 if (nelem != 7) {
1570 wwarning(_("bad number of arguments in gradient specification"));
1571 return NULL;
1574 /* get from color */
1575 for (i = 0; i < 2; i++) {
1576 elem = WMGetFromPLArray(pl, 1 + i);
1577 if (!elem || !WMIsPLString(elem))
1578 return NULL;
1579 val = WMGetFromPLString(elem);
1581 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1582 wwarning(_("\"%s\" is not a valid color name"), val);
1583 return NULL;
1585 colors1[i].alpha = 255;
1586 colors1[i].red = xcolor.red >> 8;
1587 colors1[i].green = xcolor.green >> 8;
1588 colors1[i].blue = xcolor.blue >> 8;
1590 elem = WMGetFromPLArray(pl, 3);
1591 if (!elem || !WMIsPLString(elem))
1592 return NULL;
1593 val = WMGetFromPLString(elem);
1594 th1 = atoi(val);
1596 /* get from color */
1597 for (i = 0; i < 2; i++) {
1598 elem = WMGetFromPLArray(pl, 4 + i);
1599 if (!elem || !WMIsPLString(elem))
1600 return NULL;
1601 val = WMGetFromPLString(elem);
1603 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1604 wwarning(_("\"%s\" is not a valid color name"), val);
1605 return NULL;
1607 colors2[i].alpha = 255;
1608 colors2[i].red = xcolor.red >> 8;
1609 colors2[i].green = xcolor.green >> 8;
1610 colors2[i].blue = xcolor.blue >> 8;
1612 elem = WMGetFromPLArray(pl, 6);
1613 if (!elem || !WMIsPLString(elem))
1614 return NULL;
1615 val = WMGetFromPLString(elem);
1616 th2 = atoi(val);
1618 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1620 } else if (strcasecmp(val, "mhgradient") == 0
1621 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1622 XColor color;
1623 RColor **colors;
1624 int i, count;
1625 int type;
1627 if (nelem < 3) {
1628 wwarning(_("too few arguments in multicolor gradient specification"));
1629 return NULL;
1632 if (val[1] == 'h' || val[1] == 'H')
1633 type = WTEX_MHGRADIENT;
1634 else if (val[1] == 'v' || val[1] == 'V')
1635 type = WTEX_MVGRADIENT;
1636 else
1637 type = WTEX_MDGRADIENT;
1639 count = nelem - 1;
1641 colors = wmalloc(sizeof(RColor *) * (count + 1));
1643 for (i = 0; i < count; i++) {
1644 elem = WMGetFromPLArray(pl, i + 1);
1645 if (!elem || !WMIsPLString(elem)) {
1646 for (--i; i >= 0; --i) {
1647 wfree(colors[i]);
1649 wfree(colors);
1650 return NULL;
1652 val = WMGetFromPLString(elem);
1654 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1655 wwarning(_("\"%s\" is not a valid color name"), val);
1656 for (--i; i >= 0; --i) {
1657 wfree(colors[i]);
1659 wfree(colors);
1660 return NULL;
1661 } else {
1662 colors[i] = wmalloc(sizeof(RColor));
1663 colors[i]->red = color.red >> 8;
1664 colors[i]->green = color.green >> 8;
1665 colors[i]->blue = color.blue >> 8;
1668 colors[i] = NULL;
1670 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1671 } else if (strcasecmp(val, "spixmap") == 0 ||
1672 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1673 XColor color;
1674 int type;
1676 if (nelem != 3)
1677 return NULL;
1679 if (val[0] == 's' || val[0] == 'S')
1680 type = WTP_SCALE;
1681 else if (val[0] == 'c' || val[0] == 'C')
1682 type = WTP_CENTER;
1683 else
1684 type = WTP_TILE;
1686 /* get color */
1687 elem = WMGetFromPLArray(pl, 2);
1688 if (!elem || !WMIsPLString(elem)) {
1689 return NULL;
1691 val = WMGetFromPLString(elem);
1693 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1694 wwarning(_("\"%s\" is not a valid color name"), val);
1695 return NULL;
1698 /* file name */
1699 elem = WMGetFromPLArray(pl, 1);
1700 if (!elem || !WMIsPLString(elem))
1701 return NULL;
1702 val = WMGetFromPLString(elem);
1704 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1705 } else if (strcasecmp(val, "thgradient") == 0
1706 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1707 RColor color1, color2;
1708 XColor xcolor;
1709 int opacity;
1710 int style;
1712 if (val[1] == 'h' || val[1] == 'H')
1713 style = WTEX_THGRADIENT;
1714 else if (val[1] == 'v' || val[1] == 'V')
1715 style = WTEX_TVGRADIENT;
1716 else
1717 style = WTEX_TDGRADIENT;
1719 if (nelem != 5) {
1720 wwarning(_("bad number of arguments in textured gradient specification"));
1721 return NULL;
1724 /* get from color */
1725 elem = WMGetFromPLArray(pl, 3);
1726 if (!elem || !WMIsPLString(elem))
1727 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 color1.alpha = 255;
1735 color1.red = xcolor.red >> 8;
1736 color1.green = xcolor.green >> 8;
1737 color1.blue = xcolor.blue >> 8;
1739 /* get to color */
1740 elem = WMGetFromPLArray(pl, 4);
1741 if (!elem || !WMIsPLString(elem)) {
1742 return NULL;
1744 val = WMGetFromPLString(elem);
1746 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1747 wwarning(_("\"%s\" is not a valid color name"), val);
1748 return NULL;
1750 color2.alpha = 255;
1751 color2.red = xcolor.red >> 8;
1752 color2.green = xcolor.green >> 8;
1753 color2.blue = xcolor.blue >> 8;
1755 /* get opacity */
1756 elem = WMGetFromPLArray(pl, 2);
1757 if (!elem || !WMIsPLString(elem))
1758 opacity = 128;
1759 else
1760 val = WMGetFromPLString(elem);
1762 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1763 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1764 opacity = 128;
1767 /* get file name */
1768 elem = WMGetFromPLArray(pl, 1);
1769 if (!elem || !WMIsPLString(elem))
1770 return NULL;
1771 val = WMGetFromPLString(elem);
1773 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1774 } else if (strcasecmp(val, "function") == 0) {
1775 /* Leave this in to handle the unlikely case of
1776 * someone actually having function textures configured */
1777 wwarning("function texture support has been removed");
1778 return NULL;
1779 } else {
1780 wwarning(_("invalid texture type %s"), val);
1781 return NULL;
1783 return texture;
1786 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1788 static WTexture *texture;
1789 int changed = 0;
1791 again:
1792 if (!WMIsPLArray(value)) {
1793 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1794 if (changed == 0) {
1795 value = entry->plvalue;
1796 changed = 1;
1797 wwarning(_("using default \"%s\" instead"), entry->default_value);
1798 goto again;
1800 return False;
1803 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1804 WMPropList *pl;
1806 pl = WMGetFromPLArray(value, 0);
1807 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1808 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1809 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1810 entry->key, "Solid Texture");
1812 value = entry->plvalue;
1813 changed = 1;
1814 wwarning(_("using default \"%s\" instead"), entry->default_value);
1815 goto again;
1819 texture = parse_texture(scr, value);
1821 if (!texture) {
1822 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1823 if (changed == 0) {
1824 value = entry->plvalue;
1825 changed = 1;
1826 wwarning(_("using default \"%s\" instead"), entry->default_value);
1827 goto again;
1829 return False;
1832 if (ret)
1833 *ret = &texture;
1835 if (addr)
1836 *(WTexture **) addr = texture;
1838 return True;
1841 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1843 WMPropList *elem;
1844 int changed = 0;
1845 char *val;
1846 int nelem;
1848 again:
1849 if (!WMIsPLArray(value)) {
1850 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1851 "WorkspaceBack", "Texture or None");
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;
1861 /* only do basic error checking and verify for None texture */
1863 nelem = WMGetPropListItemCount(value);
1864 if (nelem > 0) {
1865 elem = WMGetFromPLArray(value, 0);
1866 if (!elem || !WMIsPLString(elem)) {
1867 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1868 if (changed == 0) {
1869 value = entry->plvalue;
1870 changed = 1;
1871 wwarning(_("using default \"%s\" instead"), entry->default_value);
1872 goto again;
1874 return False;
1876 val = WMGetFromPLString(elem);
1878 if (strcasecmp(val, "None") == 0)
1879 return True;
1881 *ret = WMRetainPropList(value);
1883 return True;
1886 static int
1887 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1889 WMPropList *elem;
1890 int nelem;
1891 int changed = 0;
1893 again:
1894 if (!WMIsPLArray(value)) {
1895 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1896 "WorkspaceSpecificBack", "an array of textures");
1897 if (changed == 0) {
1898 value = entry->plvalue;
1899 changed = 1;
1900 wwarning(_("using default \"%s\" instead"), entry->default_value);
1901 goto again;
1903 return False;
1906 /* only do basic error checking and verify for None texture */
1908 nelem = WMGetPropListItemCount(value);
1909 if (nelem > 0) {
1910 while (nelem--) {
1911 elem = WMGetFromPLArray(value, nelem);
1912 if (!elem || !WMIsPLArray(elem)) {
1913 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1914 nelem);
1919 *ret = WMRetainPropList(value);
1921 #ifdef notworking
1923 * Kluge to force wmsetbg helper to set the default background.
1924 * If the WorkspaceSpecificBack is changed once wmaker has started,
1925 * the WorkspaceBack won't be sent to the helper, unless the user
1926 * changes it's value too. So, we must force this by removing the
1927 * value from the defaults DB.
1929 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1930 WMPropList *key = WMCreatePLString("WorkspaceBack");
1932 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1934 WMReleasePropList(key);
1936 #endif
1937 return True;
1940 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1942 static WMFont *font;
1943 char *val;
1945 GET_STRING_OR_DEFAULT("Font", val);
1947 font = WMCreateFont(scr->wmscreen, val);
1948 if (!font)
1949 font = WMCreateFont(scr->wmscreen, "fixed");
1951 if (!font) {
1952 wfatal(_("could not load any usable font!!!"));
1953 exit(1);
1956 if (ret)
1957 *ret = font;
1959 /* can't assign font value outside update function */
1960 wassertrv(addr == NULL, True);
1962 return True;
1965 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1967 static XColor color;
1968 char *val;
1969 int second_pass = 0;
1971 GET_STRING_OR_DEFAULT("Color", val);
1973 again:
1974 if (!wGetColor(scr, val, &color)) {
1975 wwarning(_("could not get color for key \"%s\""), entry->key);
1976 if (second_pass == 0) {
1977 val = WMGetFromPLString(entry->plvalue);
1978 second_pass = 1;
1979 wwarning(_("using default \"%s\" instead"), val);
1980 goto again;
1982 return False;
1985 if (ret)
1986 *ret = &color;
1988 assert(addr == NULL);
1990 if (addr)
1991 *(unsigned long*)addr = pixel;
1994 return True;
1997 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1999 static WShortKey shortcut;
2000 KeySym ksym;
2001 char *val;
2002 char *k;
2003 char buf[MAX_SHORTCUT_LENGTH], *b;
2005 GET_STRING_OR_DEFAULT("Key spec", val);
2007 if (!val || strcasecmp(val, "NONE") == 0) {
2008 shortcut.keycode = 0;
2009 shortcut.modifier = 0;
2010 if (ret)
2011 *ret = &shortcut;
2012 return True;
2015 wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
2017 b = (char *)buf;
2019 /* get modifiers */
2020 shortcut.modifier = 0;
2021 while ((k = strchr(b, '+')) != NULL) {
2022 int mod;
2024 *k = 0;
2025 mod = wXModifierFromKey(b);
2026 if (mod < 0) {
2027 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2028 return False;
2030 shortcut.modifier |= mod;
2032 b = k + 1;
2035 /* get key */
2036 ksym = XStringToKeysym(b);
2038 if (ksym == NoSymbol) {
2039 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2040 return False;
2043 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2044 if (shortcut.keycode == 0) {
2045 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2046 return False;
2049 if (ret)
2050 *ret = &shortcut;
2052 return True;
2055 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2057 static int mask;
2058 char *str;
2060 GET_STRING_OR_DEFAULT("Modifier Key", str);
2062 if (!str)
2063 return False;
2065 mask = wXModifierFromKey(str);
2066 if (mask < 0) {
2067 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2068 mask = 0;
2069 return False;
2072 if (addr)
2073 *(int *)addr = mask;
2075 if (ret)
2076 *ret = &mask;
2078 return True;
2081 # include <X11/cursorfont.h>
2082 typedef struct {
2083 char *name;
2084 int id;
2085 } WCursorLookup;
2087 #define CURSOR_ID_NONE (XC_num_glyphs)
2089 static WCursorLookup cursor_table[] = {
2090 {"X_cursor", XC_X_cursor},
2091 {"arrow", XC_arrow},
2092 {"based_arrow_down", XC_based_arrow_down},
2093 {"based_arrow_up", XC_based_arrow_up},
2094 {"boat", XC_boat},
2095 {"bogosity", XC_bogosity},
2096 {"bottom_left_corner", XC_bottom_left_corner},
2097 {"bottom_right_corner", XC_bottom_right_corner},
2098 {"bottom_side", XC_bottom_side},
2099 {"bottom_tee", XC_bottom_tee},
2100 {"box_spiral", XC_box_spiral},
2101 {"center_ptr", XC_center_ptr},
2102 {"circle", XC_circle},
2103 {"clock", XC_clock},
2104 {"coffee_mug", XC_coffee_mug},
2105 {"cross", XC_cross},
2106 {"cross_reverse", XC_cross_reverse},
2107 {"crosshair", XC_crosshair},
2108 {"diamond_cross", XC_diamond_cross},
2109 {"dot", XC_dot},
2110 {"dotbox", XC_dotbox},
2111 {"double_arrow", XC_double_arrow},
2112 {"draft_large", XC_draft_large},
2113 {"draft_small", XC_draft_small},
2114 {"draped_box", XC_draped_box},
2115 {"exchange", XC_exchange},
2116 {"fleur", XC_fleur},
2117 {"gobbler", XC_gobbler},
2118 {"gumby", XC_gumby},
2119 {"hand1", XC_hand1},
2120 {"hand2", XC_hand2},
2121 {"heart", XC_heart},
2122 {"icon", XC_icon},
2123 {"iron_cross", XC_iron_cross},
2124 {"left_ptr", XC_left_ptr},
2125 {"left_side", XC_left_side},
2126 {"left_tee", XC_left_tee},
2127 {"leftbutton", XC_leftbutton},
2128 {"ll_angle", XC_ll_angle},
2129 {"lr_angle", XC_lr_angle},
2130 {"man", XC_man},
2131 {"middlebutton", XC_middlebutton},
2132 {"mouse", XC_mouse},
2133 {"pencil", XC_pencil},
2134 {"pirate", XC_pirate},
2135 {"plus", XC_plus},
2136 {"question_arrow", XC_question_arrow},
2137 {"right_ptr", XC_right_ptr},
2138 {"right_side", XC_right_side},
2139 {"right_tee", XC_right_tee},
2140 {"rightbutton", XC_rightbutton},
2141 {"rtl_logo", XC_rtl_logo},
2142 {"sailboat", XC_sailboat},
2143 {"sb_down_arrow", XC_sb_down_arrow},
2144 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2145 {"sb_left_arrow", XC_sb_left_arrow},
2146 {"sb_right_arrow", XC_sb_right_arrow},
2147 {"sb_up_arrow", XC_sb_up_arrow},
2148 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2149 {"shuttle", XC_shuttle},
2150 {"sizing", XC_sizing},
2151 {"spider", XC_spider},
2152 {"spraycan", XC_spraycan},
2153 {"star", XC_star},
2154 {"target", XC_target},
2155 {"tcross", XC_tcross},
2156 {"top_left_arrow", XC_top_left_arrow},
2157 {"top_left_corner", XC_top_left_corner},
2158 {"top_right_corner", XC_top_right_corner},
2159 {"top_side", XC_top_side},
2160 {"top_tee", XC_top_tee},
2161 {"trek", XC_trek},
2162 {"ul_angle", XC_ul_angle},
2163 {"umbrella", XC_umbrella},
2164 {"ur_angle", XC_ur_angle},
2165 {"watch", XC_watch},
2166 {"xterm", XC_xterm},
2167 {NULL, CURSOR_ID_NONE}
2170 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2172 switch (status) {
2173 case BitmapOpenFailed:
2174 wwarning(_("failed to open bitmap file \"%s\""), filename);
2175 break;
2176 case BitmapFileInvalid:
2177 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2178 break;
2179 case BitmapNoMemory:
2180 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2181 break;
2182 case BitmapSuccess:
2183 XFreePixmap(dpy, bitmap);
2184 break;
2189 * (none)
2190 * (builtin, <cursor_name>)
2191 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2193 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2195 WMPropList *elem;
2196 char *val;
2197 int nelem;
2198 int status = 0;
2200 nelem = WMGetPropListItemCount(pl);
2201 if (nelem < 1) {
2202 return (status);
2204 elem = WMGetFromPLArray(pl, 0);
2205 if (!elem || !WMIsPLString(elem)) {
2206 return (status);
2208 val = WMGetFromPLString(elem);
2210 if (strcasecmp(val, "none") == 0) {
2211 status = 1;
2212 *cursor = None;
2213 } else if (strcasecmp(val, "builtin") == 0) {
2214 int i;
2215 int cursor_id = CURSOR_ID_NONE;
2217 if (nelem != 2) {
2218 wwarning(_("bad number of arguments in cursor specification"));
2219 return (status);
2221 elem = WMGetFromPLArray(pl, 1);
2222 if (!elem || !WMIsPLString(elem)) {
2223 return (status);
2225 val = WMGetFromPLString(elem);
2227 for (i = 0; cursor_table[i].name != NULL; i++) {
2228 if (strcasecmp(val, cursor_table[i].name) == 0) {
2229 cursor_id = cursor_table[i].id;
2230 break;
2233 if (CURSOR_ID_NONE == cursor_id) {
2234 wwarning(_("unknown builtin cursor name \"%s\""), val);
2235 } else {
2236 *cursor = XCreateFontCursor(dpy, cursor_id);
2237 status = 1;
2239 } else if (strcasecmp(val, "bitmap") == 0) {
2240 char *bitmap_name;
2241 char *mask_name;
2242 int bitmap_status;
2243 int mask_status;
2244 Pixmap bitmap;
2245 Pixmap mask;
2246 unsigned int w, h;
2247 int x, y;
2248 XColor fg, bg;
2250 if (nelem != 3) {
2251 wwarning(_("bad number of arguments in cursor specification"));
2252 return (status);
2254 elem = WMGetFromPLArray(pl, 1);
2255 if (!elem || !WMIsPLString(elem)) {
2256 return (status);
2258 val = WMGetFromPLString(elem);
2259 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2260 if (!bitmap_name) {
2261 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2262 return (status);
2264 elem = WMGetFromPLArray(pl, 2);
2265 if (!elem || !WMIsPLString(elem)) {
2266 wfree(bitmap_name);
2267 return (status);
2269 val = WMGetFromPLString(elem);
2270 mask_name = FindImage(wPreferences.pixmap_path, val);
2271 if (!mask_name) {
2272 wfree(bitmap_name);
2273 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2274 return (status);
2276 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2277 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2278 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2279 fg.pixel = scr->black_pixel;
2280 bg.pixel = scr->white_pixel;
2281 XQueryColor(dpy, scr->w_colormap, &fg);
2282 XQueryColor(dpy, scr->w_colormap, &bg);
2283 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2284 status = 1;
2286 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2287 check_bitmap_status(mask_status, mask_name, mask);
2288 wfree(bitmap_name);
2289 wfree(mask_name);
2291 return (status);
2294 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2296 static Cursor cursor;
2297 int status;
2298 int changed = 0;
2300 again:
2301 if (!WMIsPLArray(value)) {
2302 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2303 entry->key, "cursor specification");
2304 if (!changed) {
2305 value = entry->plvalue;
2306 changed = 1;
2307 wwarning(_("using default \"%s\" instead"), entry->default_value);
2308 goto again;
2310 return (False);
2312 status = parse_cursor(scr, value, &cursor);
2313 if (!status) {
2314 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2315 if (!changed) {
2316 value = entry->plvalue;
2317 changed = 1;
2318 wwarning(_("using default \"%s\" instead"), entry->default_value);
2319 goto again;
2321 return (False);
2323 if (ret) {
2324 *ret = &cursor;
2326 if (addr) {
2327 *(Cursor *) addr = cursor;
2329 return (True);
2332 #undef CURSOR_ID_NONE
2334 /* ---------------- value setting functions --------------- */
2335 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2337 return REFRESH_WINDOW_TITLE_COLOR;
2340 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2342 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2345 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2347 switch (which) {
2348 case WM_DOCK:
2349 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2350 break;
2351 case WM_CLIP:
2352 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2353 break;
2354 default:
2355 break;
2357 return 0;
2360 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2362 if (scr->workspaces) {
2363 wWorkspaceForceChange(scr, scr->current_workspace);
2364 wArrangeIcons(scr, False);
2366 return 0;
2369 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2371 Pixmap pixmap;
2372 RImage *img;
2373 int reset = 0;
2375 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2376 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2377 ? WREL_ICON : WREL_FLAT);
2378 if (!img) {
2379 wwarning(_("could not render texture for icon background"));
2380 if (!entry->addr)
2381 wTextureDestroy(scr, *texture);
2382 return 0;
2384 RConvertImage(scr->rcontext, img, &pixmap);
2386 if (scr->icon_tile) {
2387 reset = 1;
2388 RReleaseImage(scr->icon_tile);
2389 XFreePixmap(dpy, scr->icon_tile_pixmap);
2392 scr->icon_tile = img;
2394 /* put the icon in the noticeboard hint */
2395 PropSetIconTileHint(scr, img);
2397 if (!wPreferences.flags.noclip) {
2398 if (scr->clip_tile) {
2399 RReleaseImage(scr->clip_tile);
2401 scr->clip_tile = wClipMakeTile(scr, img);
2404 scr->icon_tile_pixmap = pixmap;
2406 if (scr->def_icon_pixmap) {
2407 XFreePixmap(dpy, scr->def_icon_pixmap);
2408 scr->def_icon_pixmap = None;
2410 if (scr->def_ticon_pixmap) {
2411 XFreePixmap(dpy, scr->def_ticon_pixmap);
2412 scr->def_ticon_pixmap = None;
2415 if (scr->icon_back_texture) {
2416 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2418 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2420 if (scr->clip_balloon)
2421 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2424 * Free the texture as nobody else will use it, nor refer to it.
2426 if (!entry->addr)
2427 wTextureDestroy(scr, *texture);
2429 return (reset ? REFRESH_ICON_TILE : 0);
2432 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2434 if (scr->title_font) {
2435 WMReleaseFont(scr->title_font);
2437 scr->title_font = font;
2439 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2442 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2444 if (scr->menu_title_font) {
2445 WMReleaseFont(scr->menu_title_font);
2448 scr->menu_title_font = font;
2450 return REFRESH_MENU_TITLE_FONT;
2453 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2455 if (scr->menu_entry_font) {
2456 WMReleaseFont(scr->menu_entry_font);
2458 scr->menu_entry_font = font;
2460 return REFRESH_MENU_FONT;
2463 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2465 if (scr->icon_title_font) {
2466 WMReleaseFont(scr->icon_title_font);
2469 scr->icon_title_font = font;
2471 return REFRESH_ICON_FONT;
2474 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2476 if (scr->clip_title_font) {
2477 WMReleaseFont(scr->clip_title_font);
2480 scr->clip_title_font = font;
2482 return REFRESH_ICON_FONT;
2485 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2487 if (scr->workspace_name_font) {
2488 WMReleaseFont(scr->workspace_name_font);
2491 scr->workspace_name_font = font;
2493 return 0;
2496 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2498 if (scr->select_color)
2499 WMReleaseColor(scr->select_color);
2501 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2503 wFreeColor(scr, color->pixel);
2505 return REFRESH_MENU_COLOR;
2508 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2510 if (scr->select_text_color)
2511 WMReleaseColor(scr->select_text_color);
2513 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2515 wFreeColor(scr, color->pixel);
2517 return REFRESH_MENU_COLOR;
2520 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2522 if (scr->clip_title_color[widx])
2523 WMReleaseColor(scr->clip_title_color[widx]);
2525 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2526 wFreeColor(scr, color->pixel);
2528 return REFRESH_ICON_TITLE_COLOR;
2531 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2533 if (scr->window_title_color[widx])
2534 WMReleaseColor(scr->window_title_color[widx]);
2536 scr->window_title_color[widx] =
2537 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2539 wFreeColor(scr, color->pixel);
2541 return REFRESH_WINDOW_TITLE_COLOR;
2544 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2546 if (scr->menu_title_color[0])
2547 WMReleaseColor(scr->menu_title_color[0]);
2549 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2551 wFreeColor(scr, color->pixel);
2553 return REFRESH_MENU_TITLE_COLOR;
2556 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2558 if (scr->mtext_color)
2559 WMReleaseColor(scr->mtext_color);
2561 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2563 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2564 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2565 } else {
2566 WMSetColorAlpha(scr->dtext_color, 0xffff);
2569 wFreeColor(scr, color->pixel);
2571 return REFRESH_MENU_COLOR;
2574 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2576 if (scr->dtext_color)
2577 WMReleaseColor(scr->dtext_color);
2579 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2581 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2582 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2583 } else {
2584 WMSetColorAlpha(scr->dtext_color, 0xffff);
2587 wFreeColor(scr, color->pixel);
2589 return REFRESH_MENU_COLOR;
2592 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2594 if (scr->icon_title_color)
2595 WMReleaseColor(scr->icon_title_color);
2596 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2598 wFreeColor(scr, color->pixel);
2600 return REFRESH_ICON_TITLE_COLOR;
2603 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2605 if (scr->icon_title_texture) {
2606 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2608 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2610 return REFRESH_ICON_TITLE_BACK;
2613 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2615 close(scr->helper_fd);
2616 scr->helper_fd = 0;
2617 scr->helper_pid = 0;
2618 scr->flags.backimage_helper_launched = 0;
2621 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2623 WMPropList *val;
2624 char *str;
2625 int i;
2627 if (scr->flags.backimage_helper_launched) {
2628 if (WMGetPropListItemCount(value) == 0) {
2629 SendHelperMessage(scr, 'C', 0, NULL);
2630 SendHelperMessage(scr, 'K', 0, NULL);
2632 WMReleasePropList(value);
2633 return 0;
2635 } else {
2636 pid_t pid;
2637 int filedes[2];
2639 if (WMGetPropListItemCount(value) == 0)
2640 return 0;
2642 if (pipe(filedes) < 0) {
2643 werror("pipe() failed:can't set workspace specific background image");
2645 WMReleasePropList(value);
2646 return 0;
2649 pid = fork();
2650 if (pid < 0) {
2651 werror("fork() failed:can't set workspace specific background image");
2652 if (close(filedes[0]) < 0)
2653 werror("could not close pipe");
2654 if (close(filedes[1]) < 0)
2655 werror("could not close pipe");
2657 } else if (pid == 0) {
2658 char *dither;
2660 SetupEnvironment(scr);
2662 if (close(0) < 0)
2663 werror("could not close pipe");
2664 if (dup(filedes[0]) < 0) {
2665 werror("dup() failed:can't set workspace specific background image");
2667 dither = wPreferences.no_dithering ? "-m" : "-d";
2668 if (wPreferences.smooth_workspace_back)
2669 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2670 else
2671 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2672 werror("could not execute wmsetbg");
2673 exit(1);
2674 } else {
2676 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2677 werror("error setting close-on-exec flag");
2679 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2680 werror("error setting close-on-exec flag");
2683 scr->helper_fd = filedes[1];
2684 scr->helper_pid = pid;
2685 scr->flags.backimage_helper_launched = 1;
2687 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2689 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2694 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2695 val = WMGetFromPLArray(value, i);
2696 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2697 str = WMGetPropListDescription(val, False);
2699 SendHelperMessage(scr, 'S', i + 1, str);
2701 wfree(str);
2702 } else {
2703 SendHelperMessage(scr, 'U', i + 1, NULL);
2706 sleep(1);
2708 WMReleasePropList(value);
2709 return 0;
2712 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2714 if (scr->flags.backimage_helper_launched) {
2715 char *str;
2717 if (WMGetPropListItemCount(value) == 0) {
2718 SendHelperMessage(scr, 'U', 0, NULL);
2719 } else {
2720 /* set the default workspace background to this one */
2721 str = WMGetPropListDescription(value, False);
2722 if (str) {
2723 SendHelperMessage(scr, 'S', 0, str);
2724 wfree(str);
2725 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2726 } else {
2727 SendHelperMessage(scr, 'U', 0, NULL);
2730 } else if (WMGetPropListItemCount(value) > 0) {
2731 char *command;
2732 char *text;
2733 char *dither;
2734 int len;
2736 text = WMGetPropListDescription(value, False);
2737 len = strlen(text) + 40;
2738 command = wmalloc(len);
2739 dither = wPreferences.no_dithering ? "-m" : "-d";
2740 if (wPreferences.smooth_workspace_back)
2741 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2742 else
2743 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2744 wfree(text);
2745 ExecuteShellCommand(scr, command);
2746 wfree(command);
2748 WMReleasePropList(value);
2750 return 0;
2753 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2755 if (scr->widget_texture) {
2756 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2758 scr->widget_texture = *(WTexSolid **) texture;
2760 return 0;
2763 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2765 if (scr->window_title_texture[WS_FOCUSED]) {
2766 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2768 scr->window_title_texture[WS_FOCUSED] = *texture;
2770 return REFRESH_WINDOW_TEXTURES;
2773 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2775 if (scr->window_title_texture[WS_PFOCUSED]) {
2776 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2778 scr->window_title_texture[WS_PFOCUSED] = *texture;
2780 return REFRESH_WINDOW_TEXTURES;
2783 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2785 if (scr->window_title_texture[WS_UNFOCUSED]) {
2786 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2788 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2790 return REFRESH_WINDOW_TEXTURES;
2793 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2795 if (scr->resizebar_texture[0]) {
2796 wTextureDestroy(scr, scr->resizebar_texture[0]);
2798 scr->resizebar_texture[0] = *texture;
2800 return REFRESH_WINDOW_TEXTURES;
2803 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2805 if (scr->menu_title_texture[0]) {
2806 wTextureDestroy(scr, scr->menu_title_texture[0]);
2808 scr->menu_title_texture[0] = *texture;
2810 return REFRESH_MENU_TITLE_TEXTURE;
2813 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2815 if (scr->menu_item_texture) {
2816 wTextureDestroy(scr, scr->menu_item_texture);
2817 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2819 scr->menu_item_texture = *texture;
2821 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2823 return REFRESH_MENU_TEXTURE;
2826 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2828 WWindow *wwin;
2829 wKeyBindings[widx] = *shortcut;
2831 wwin = scr->focused_window;
2833 while (wwin != NULL) {
2834 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2836 if (!WFLAGP(wwin, no_bind_keys)) {
2837 wWindowSetKeyGrabs(wwin);
2839 wwin = wwin->prev;
2842 return 0;
2845 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2847 wScreenUpdateUsableArea(scr);
2848 wArrangeIcons(scr, True);
2850 return 0;
2853 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2855 wScreenUpdateUsableArea(scr);
2857 return 0;
2860 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2862 return REFRESH_MENU_TEXTURE;
2865 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2867 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2869 RCopyArea(img, image, x, y, w, h, 0, 0);
2871 return img;
2874 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2876 char *path;
2877 RImage *bgimage;
2878 int cwidth, cheight;
2879 WPreferences *prefs = (WPreferences *) foo;
2881 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2882 if (prefs->swtileImage)
2883 RReleaseImage(prefs->swtileImage);
2884 prefs->swtileImage = NULL;
2886 WMReleasePropList(array);
2887 return 0;
2890 switch (WMGetPropListItemCount(array)) {
2891 case 4:
2892 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2893 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2894 break;
2895 } else
2896 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2898 if (!path) {
2899 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2900 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2901 } else {
2902 bgimage = RLoadImage(scr->rcontext, path, 0);
2903 if (!bgimage) {
2904 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2905 wfree(path);
2906 } else {
2907 wfree(path);
2909 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2910 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2912 if (cwidth <= 0 || cheight <= 0 ||
2913 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2914 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2915 else {
2916 int i;
2917 int swidth, theight;
2918 for (i = 0; i < 9; i++) {
2919 if (prefs->swbackImage[i])
2920 RReleaseImage(prefs->swbackImage[i]);
2921 prefs->swbackImage[i] = NULL;
2923 swidth = (bgimage->width - cwidth) / 2;
2924 theight = (bgimage->height - cheight) / 2;
2926 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2927 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2928 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2929 swidth, theight);
2931 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2932 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2933 cwidth, cheight);
2934 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2935 swidth, cheight);
2937 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2938 swidth, theight);
2939 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2940 cwidth, theight);
2941 prefs->swbackImage[8] =
2942 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2943 theight);
2945 // check if anything failed
2946 for (i = 0; i < 9; i++) {
2947 if (!prefs->swbackImage[i]) {
2948 for (; i >= 0; --i) {
2949 RReleaseImage(prefs->swbackImage[i]);
2950 prefs->swbackImage[i] = NULL;
2952 break;
2956 RReleaseImage(bgimage);
2960 case 1:
2961 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
2962 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2963 break;
2964 } else
2965 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
2967 if (!path) {
2968 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2969 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
2970 } else {
2971 if (prefs->swtileImage)
2972 RReleaseImage(prefs->swtileImage);
2974 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
2975 if (!prefs->swtileImage) {
2976 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2978 wfree(path);
2980 break;
2982 default:
2983 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
2984 break;
2987 WMReleasePropList(array);
2989 return 0;
2992 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2994 int i;
2995 WPreferences *prefs = (WPreferences *) foo;
2997 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
2998 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
2999 WMReleasePropList(array);
3000 return 0;
3003 DestroyWindowMenu(scr);
3005 for (i = 0; i < 7; i++) {
3006 if (prefs->modifier_labels[i])
3007 wfree(prefs->modifier_labels[i]);
3009 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3010 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3011 } else {
3012 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3013 prefs->modifier_labels[i] = NULL;
3017 WMReleasePropList(array);
3019 return 0;
3023 * Very ugly kluge.
3024 * Need access to the double click variables, so that all widgets in
3025 * wmaker panels will have the same dbl-click values.
3026 * TODO: figure a better way of dealing with it.
3028 #include <WINGs/WINGsP.h>
3030 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3032 extern _WINGsConfiguration WINGsConfiguration;
3034 if (*value <= 0)
3035 *(int *)foo = 1;
3037 WINGsConfiguration.doubleClickDelay = *value;
3039 return 0;
3042 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3044 if (wCursor[widx] != None) {
3045 XFreeCursor(dpy, wCursor[widx]);
3048 wCursor[widx] = *cursor;
3050 if (widx == WCUR_ROOT && *cursor != None) {
3051 XDefineCursor(dpy, scr->root_win, *cursor);
3054 return 0;