opaque resize
[wmaker-crm.git] / src / defaults.c
blob300a0bbd43926befb6fff98bca12f93e11bf3b83
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 WDefaultEntry optionList[] = {
333 /* dynamic options */
335 {"IconPosition", "blh", seIconPositions,
336 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
337 {"IconificationStyle", "Zoom", seIconificationStyles,
338 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
339 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
340 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
341 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
342 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
343 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
344 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
345 {"MouseWheelAction", "None", seMouseWheelActions,
346 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
347 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
348 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
349 {"IconPath", DEF_ICON_PATHS, NULL,
350 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
351 {"ColormapMode", "auto", seColormapModes,
352 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
353 {"AutoFocus", "NO", NULL,
354 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
355 {"RaiseDelay", "0", NULL,
356 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
357 {"CirculateRaise", "NO", NULL,
358 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
359 {"Superfluous", "NO", NULL,
360 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
361 {"AdvanceToNewWorkspace", "NO", NULL,
362 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
363 {"CycleWorkspaces", "NO", NULL,
364 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
365 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
366 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
367 {"WorkspaceBorder", "None", seWorkspaceBorder,
368 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
369 {"WorkspaceBorderSize", "0", NULL,
370 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
371 {"StickyIcons", "NO", NULL,
372 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
373 {"SaveSessionOnExit", "NO", NULL,
374 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
375 {"WrapMenus", "NO", NULL,
376 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
377 {"ScrollableMenus", "NO", NULL,
378 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
379 {"MenuScrollSpeed", "medium", seSpeeds,
380 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
381 {"IconSlideSpeed", "medium", seSpeeds,
382 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
383 {"ShadeSpeed", "medium", seSpeeds,
384 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
385 {"BounceAppIconsWhenUrgent", "YES", NULL,
386 &wPreferences.bounce_appicons_when_urgent, getBool, NULL, NULL, NULL},
387 {"RaiseAppIconsWhenBouncing", "NO", NULL,
388 &wPreferences.raise_appicons_when_bouncing, getBool, NULL, NULL, NULL},
389 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
390 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
391 {"AlignSubmenus", "NO", NULL,
392 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
393 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
394 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
395 {"WindowPlacement", "auto", sePlacements,
396 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
397 {"IgnoreFocusClick", "NO", NULL,
398 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
399 {"UseSaveUnders", "NO", NULL,
400 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
401 {"OpaqueMove", "NO", NULL,
402 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
403 {"OpaqueResize", "NO", NULL,
404 &wPreferences.opaque_resize, getBool, NULL, NULL, NULL},
405 {"OpaqueMoveResizeKeyboard", "NO", NULL,
406 &wPreferences.opaque_move_resize_keyboard, getBool, NULL, NULL, NULL},
407 {"DisableAnimations", "NO", NULL,
408 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
409 {"DontLinkWorkspaces", "NO", NULL,
410 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
411 {"AutoArrangeIcons", "NO", NULL,
412 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
413 {"NoWindowOverDock", "NO", NULL,
414 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
415 {"NoWindowOverIcons", "NO", NULL,
416 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
417 {"WindowPlaceOrigin", "(0, 0)", NULL,
418 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
419 {"ResizeDisplay", "corner", seGeomDisplays,
420 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
421 {"MoveDisplay", "corner", seGeomDisplays,
422 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
423 {"DontConfirmKill", "NO", NULL,
424 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
425 {"WindowTitleBalloons", "NO", NULL,
426 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
427 {"MiniwindowTitleBalloons", "NO", NULL,
428 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
429 {"AppIconBalloons", "NO", NULL,
430 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
431 {"HelpBalloons", "NO", NULL,
432 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
433 {"EdgeResistance", "30", NULL,
434 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
435 {"ResizeIncrement", "32", NULL,
436 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
437 {"Attraction", "NO", NULL,
438 &wPreferences.attract, getBool, NULL, NULL, NULL},
439 {"DisableBlinking", "NO", NULL,
440 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
441 {"SingleClickLaunch", "NO", NULL,
442 &wPreferences.single_click, getBool, NULL, NULL, NULL},
444 /* style options */
446 {"MenuStyle", "normal", seMenuStyles,
447 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
448 {"WidgetColor", "(solid, gray)", NULL,
449 NULL, getTexture, setWidgetColor, NULL, NULL},
450 {"WorkspaceSpecificBack", "()", NULL,
451 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
452 /* WorkspaceBack must come after WorkspaceSpecificBack or
453 * WorkspaceBack wont know WorkspaceSpecificBack was also
454 * specified and 2 copies of wmsetbg will be launched */
455 {"WorkspaceBack", "(solid, black)", NULL,
456 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
457 {"SmoothWorkspaceBack", "NO", NULL,
458 NULL, getBool, NULL, NULL, NULL},
459 {"IconBack", "(solid, gray)", NULL,
460 NULL, getTexture, setIconTile, NULL, NULL},
461 {"TitleJustify", "center", seJustifications,
462 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
463 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
464 NULL, getFont, setWinTitleFont, NULL, NULL},
465 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
466 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
467 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
468 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
469 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
470 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
471 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
472 NULL, getFont, setMenuTitleFont, NULL, NULL},
473 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
474 NULL, getFont, setMenuTextFont, NULL, NULL},
475 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
476 NULL, getFont, setIconTitleFont, NULL, NULL},
477 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
478 NULL, getFont, setClipTitleFont, NULL, NULL},
479 {"ShowClipTitle", "YES", NULL,
480 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
481 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
482 NULL, getFont, setLargeDisplayFont, NULL, NULL},
483 {"HighlightColor", "white", NULL,
484 NULL, getColor, setHightlight, NULL, NULL},
485 {"HighlightTextColor", "black", NULL,
486 NULL, getColor, setHightlightText, NULL, NULL},
487 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
488 NULL, getColor, setClipTitleColor, NULL, NULL},
489 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
490 NULL, getColor, setClipTitleColor, NULL, NULL},
491 {"FTitleColor", "white", (void *)WS_FOCUSED,
492 NULL, getColor, setWTitleColor, NULL, NULL},
493 {"PTitleColor", "white", (void *)WS_PFOCUSED,
494 NULL, getColor, setWTitleColor, NULL, NULL},
495 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
496 NULL, getColor, setWTitleColor, NULL, NULL},
497 {"FTitleBack", "(solid, black)", NULL,
498 NULL, getTexture, setFTitleBack, NULL, NULL},
499 {"PTitleBack", "(solid, \"#616161\")", NULL,
500 NULL, getTexture, setPTitleBack, NULL, NULL},
501 {"UTitleBack", "(solid, gray)", NULL,
502 NULL, getTexture, setUTitleBack, NULL, NULL},
503 {"ResizebarBack", "(solid, gray)", NULL,
504 NULL, getTexture, setResizebarBack, NULL, NULL},
505 {"MenuTitleColor", "white", NULL,
506 NULL, getColor, setMenuTitleColor, NULL, NULL},
507 {"MenuTextColor", "black", NULL,
508 NULL, getColor, setMenuTextColor, NULL, NULL},
509 {"MenuDisabledColor", "\"#616161\"", NULL,
510 NULL, getColor, setMenuDisabledColor, NULL, NULL},
511 {"MenuTitleBack", "(solid, black)", NULL,
512 NULL, getTexture, setMenuTitleBack, NULL, NULL},
513 {"MenuTextBack", "(solid, gray)", NULL,
514 NULL, getTexture, setMenuTextBack, NULL, NULL},
515 {"IconTitleColor", "white", NULL,
516 NULL, getColor, setIconTitleColor, NULL, NULL},
517 {"IconTitleBack", "black", NULL,
518 NULL, getColor, setIconTitleBack, NULL, NULL},
519 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
520 NULL, getPropList, setSwPOptions, NULL, NULL},
521 {"ModifierKeyLabels", "(\"Shift+\", \"Ctrl+\", \"Mod1+\", \"Mod2+\", \"Mod3+\", \"Mod4+\", \"Mod5+\")", &wPreferences,
522 NULL, getPropList, setModifierKeyLabels, NULL, NULL},
524 /* keybindings */
526 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
527 NULL, getKeybind, setKeyGrab, NULL, NULL},
528 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
529 NULL, getKeybind, setKeyGrab, NULL, NULL},
530 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
531 NULL, getKeybind, setKeyGrab, NULL, NULL},
532 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
533 NULL, getKeybind, setKeyGrab, NULL, NULL},
534 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
535 NULL, getKeybind, setKeyGrab, NULL, NULL},
536 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
537 NULL, getKeybind, setKeyGrab, NULL, NULL},
538 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
539 NULL, getKeybind, setKeyGrab, NULL, NULL },
540 {"HideKey", "None", (void *)WKBD_HIDE,
541 NULL, getKeybind, setKeyGrab, NULL, NULL},
542 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
543 NULL, getKeybind, setKeyGrab, NULL, NULL},
544 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
545 NULL, getKeybind, setKeyGrab, NULL, NULL},
546 {"CloseKey", "None", (void *)WKBD_CLOSE,
547 NULL, getKeybind, setKeyGrab, NULL, NULL},
548 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
549 NULL, getKeybind, setKeyGrab, NULL, NULL},
550 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
551 NULL, getKeybind, setKeyGrab, NULL, NULL},
552 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
553 NULL, getKeybind, setKeyGrab, NULL, NULL},
554 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
555 NULL, getKeybind, setKeyGrab, NULL, NULL},
556 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
557 NULL, getKeybind, setKeyGrab, NULL, NULL},
558 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
559 NULL, getKeybind, setKeyGrab, NULL, NULL},
560 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
561 NULL, getKeybind, setKeyGrab, NULL, NULL},
562 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
563 NULL, getKeybind, setKeyGrab, NULL, NULL},
564 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
565 NULL, getKeybind, setKeyGrab, NULL, NULL},
566 {"ShadeKey", "None", (void *)WKBD_SHADE,
567 NULL, getKeybind, setKeyGrab, NULL, NULL},
568 {"SelectKey", "None", (void *)WKBD_SELECT,
569 NULL, getKeybind, setKeyGrab, NULL, NULL},
570 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
571 NULL, getKeybind, setKeyGrab, NULL, NULL},
572 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
573 NULL, getKeybind, setKeyGrab, NULL, NULL},
574 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
575 NULL, getKeybind, setKeyGrab, NULL, NULL},
576 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
577 NULL, getKeybind, setKeyGrab, NULL, NULL},
578 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
579 NULL, getKeybind, setKeyGrab, NULL, NULL},
580 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
581 NULL, getKeybind, setKeyGrab, NULL, NULL},
582 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
583 NULL, getKeybind, setKeyGrab, NULL, NULL},
584 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
585 NULL, getKeybind, setKeyGrab, NULL, NULL},
586 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
587 NULL, getKeybind, setKeyGrab, NULL, NULL},
588 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
589 NULL, getKeybind, setKeyGrab, NULL, NULL},
590 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
591 NULL, getKeybind, setKeyGrab, NULL, NULL},
592 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
593 NULL, getKeybind, setKeyGrab, NULL, NULL},
594 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
595 NULL, getKeybind, setKeyGrab, NULL, NULL},
596 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
597 NULL, getKeybind, setKeyGrab, NULL, NULL},
598 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
599 NULL, getKeybind, setKeyGrab, NULL, NULL},
600 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
601 NULL, getKeybind, setKeyGrab, NULL, NULL},
602 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
603 NULL, getKeybind, setKeyGrab, NULL, NULL},
604 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
605 NULL, getKeybind, setKeyGrab, NULL, NULL},
606 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
607 NULL, getKeybind, setKeyGrab, NULL, NULL},
608 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
609 NULL, getKeybind, setKeyGrab, NULL, NULL},
610 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
611 NULL, getKeybind, setKeyGrab, NULL, NULL},
612 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
613 NULL, getKeybind, setKeyGrab, NULL, NULL},
614 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
615 NULL, getKeybind, setKeyGrab, NULL, NULL},
616 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
617 NULL, getKeybind, setKeyGrab, NULL, NULL},
618 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
619 NULL, getKeybind, setKeyGrab, NULL, NULL},
620 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
621 NULL, getKeybind, setKeyGrab, NULL, NULL},
622 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
623 NULL, getKeybind, setKeyGrab, NULL, NULL},
624 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
625 NULL, getKeybind, setKeyGrab, NULL, NULL},
626 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
627 NULL, getKeybind, setKeyGrab, NULL, NULL},
629 #ifdef KEEP_XKB_LOCK_STATUS
630 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
631 NULL, getKeybind, setKeyGrab, NULL, NULL},
632 {"KbdModeLock", "NO", NULL,
633 &wPreferences.modelock, getBool, NULL, NULL, NULL},
634 #endif /* KEEP_XKB_LOCK_STATUS */
636 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
637 NULL, getCursor, setCursor, NULL, NULL},
638 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
639 NULL, getCursor, setCursor, NULL, NULL},
640 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
641 NULL, getCursor, setCursor, NULL, NULL},
642 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
643 NULL, getCursor, setCursor, NULL, NULL},
644 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
645 NULL, getCursor, setCursor, NULL, NULL},
646 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
647 NULL, getCursor, setCursor, NULL, NULL},
648 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
649 NULL, getCursor, setCursor, NULL, NULL},
650 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
651 NULL, getCursor, setCursor, NULL, NULL},
652 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
653 NULL, getCursor, setCursor, NULL, NULL},
654 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
655 NULL, getCursor, setCursor, NULL, NULL},
656 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
657 NULL, getCursor, setCursor, NULL, NULL},
658 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
659 NULL, getCursor, setCursor, NULL, NULL},
660 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
661 NULL, getCursor, setCursor, NULL, NULL},
662 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
663 NULL, getCursor, setCursor, NULL, NULL},
664 {"DialogHistoryLines", "500", NULL,
665 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
666 {"CycleActiveHeadOnly", "NO", NULL,
667 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL}
670 static void initDefaults()
672 unsigned int i;
673 WDefaultEntry *entry;
675 WMPLSetCaseSensitive(False);
677 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
678 entry = &optionList[i];
680 entry->plkey = WMCreatePLString(entry->key);
681 if (entry->default_value)
682 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
683 else
684 entry->plvalue = NULL;
687 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
688 entry = &staticOptionList[i];
690 entry->plkey = WMCreatePLString(entry->key);
691 if (entry->default_value)
692 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
693 else
694 entry->plvalue = NULL;
698 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
700 WMPropList *globalDict = NULL;
701 char path[PATH_MAX];
702 struct stat stbuf;
704 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
705 if (stat(path, &stbuf) >= 0) {
706 globalDict = WMReadPropListFromFile(path);
707 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
708 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
709 WMReleasePropList(globalDict);
710 globalDict = NULL;
711 } else if (!globalDict) {
712 wwarning(_("could not load domain %s from global defaults database"), domainName);
716 return globalDict;
719 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
720 static void prependMenu(WMPropList * destarr, WMPropList * array)
722 WMPropList *item;
723 int i;
725 for (i = 0; i < WMGetPropListItemCount(array); i++) {
726 item = WMGetFromPLArray(array, i);
727 if (item)
728 WMInsertInPLArray(destarr, i + 1, item);
732 static void appendMenu(WMPropList * destarr, WMPropList * array)
734 WMPropList *item;
735 int i;
737 for (i = 0; i < WMGetPropListItemCount(array); i++) {
738 item = WMGetFromPLArray(array, i);
739 if (item)
740 WMAddToPLArray(destarr, item);
743 #endif
745 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
747 WMPropList *menu = menuDomain->dictionary;
748 WMPropList *submenu;
750 if (!menu || !WMIsPLArray(menu))
751 return;
753 #ifdef GLOBAL_PREAMBLE_MENU_FILE
754 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
756 if (submenu && !WMIsPLArray(submenu)) {
757 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
758 WMReleasePropList(submenu);
759 submenu = NULL;
761 if (submenu) {
762 prependMenu(menu, submenu);
763 WMReleasePropList(submenu);
765 #endif
767 #ifdef GLOBAL_EPILOGUE_MENU_FILE
768 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
770 if (submenu && !WMIsPLArray(submenu)) {
771 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
772 WMReleasePropList(submenu);
773 submenu = NULL;
775 if (submenu) {
776 appendMenu(menu, submenu);
777 WMReleasePropList(submenu);
779 #endif
781 menuDomain->dictionary = menu;
784 void wDefaultsDestroyDomain(WDDomain * domain)
786 if (domain->dictionary)
787 WMReleasePropList(domain->dictionary);
788 wfree(domain->path);
789 wfree(domain);
792 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
794 WDDomain *db;
795 struct stat stbuf;
796 static int inited = 0;
797 char path[PATH_MAX];
798 char *the_path;
799 WMPropList *shared_dict = NULL;
801 if (!inited) {
802 inited = 1;
803 initDefaults();
806 db = wmalloc(sizeof(WDDomain));
807 memset(db, 0, sizeof(WDDomain));
808 db->domain_name = domain;
809 db->path = wdefaultspathfordomain(domain);
810 the_path = db->path;
812 if (the_path && stat(the_path, &stbuf) >= 0) {
813 db->dictionary = WMReadPropListFromFile(the_path);
814 if (db->dictionary) {
815 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
816 WMReleasePropList(db->dictionary);
817 db->dictionary = NULL;
818 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
820 db->timestamp = stbuf.st_mtime;
821 } else {
822 wwarning(_("could not load domain %s from user defaults database"), domain);
826 /* global system dictionary */
827 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
828 if (stat(path, &stbuf) >= 0) {
829 shared_dict = WMReadPropListFromFile(path);
830 if (shared_dict) {
831 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
832 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
833 domain, path);
834 WMReleasePropList(shared_dict);
835 shared_dict = NULL;
836 } else {
837 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
838 WMIsPLDictionary(db->dictionary)) {
839 WMMergePLDictionaries(shared_dict, db->dictionary, True);
840 WMReleasePropList(db->dictionary);
841 db->dictionary = shared_dict;
842 if (stbuf.st_mtime > db->timestamp)
843 db->timestamp = stbuf.st_mtime;
844 } else if (!db->dictionary) {
845 db->dictionary = shared_dict;
846 if (stbuf.st_mtime > db->timestamp)
847 db->timestamp = stbuf.st_mtime;
850 } else {
851 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
855 return db;
858 void wReadStaticDefaults(WMPropList * dict)
860 WMPropList *plvalue;
861 WDefaultEntry *entry;
862 unsigned int i;
863 void *tdata;
865 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
866 entry = &staticOptionList[i];
868 if (dict)
869 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
870 else
871 plvalue = NULL;
873 if (!plvalue) {
874 /* no default in the DB. Use builtin default */
875 plvalue = entry->plvalue;
878 if (plvalue) {
879 /* convert data */
880 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
881 if (entry->update) {
882 (*entry->update) (NULL, entry, tdata, entry->extra_data);
888 void wDefaultsCheckDomains(void* arg)
890 WScreen *scr;
891 struct stat stbuf;
892 WMPropList *shared_dict = NULL;
893 WMPropList *dict;
894 int i;
896 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
897 WDWindowMaker->timestamp = stbuf.st_mtime;
899 /* global dictionary */
900 shared_dict = readGlobalDomain("WindowMaker", True);
901 /* user dictionary */
902 dict = WMReadPropListFromFile(WDWindowMaker->path);
903 if (dict) {
904 if (!WMIsPLDictionary(dict)) {
905 WMReleasePropList(dict);
906 dict = NULL;
907 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
908 "WindowMaker", WDWindowMaker->path);
909 } else {
910 if (shared_dict) {
911 WMMergePLDictionaries(shared_dict, dict, True);
912 WMReleasePropList(dict);
913 dict = shared_dict;
914 shared_dict = NULL;
916 for (i = 0; i < wScreenCount; i++) {
917 scr = wScreenWithNumber(i);
918 if (scr)
919 wReadDefaults(scr, dict);
921 if (WDWindowMaker->dictionary) {
922 WMReleasePropList(WDWindowMaker->dictionary);
924 WDWindowMaker->dictionary = dict;
926 } else {
927 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
929 if (shared_dict) {
930 WMReleasePropList(shared_dict);
934 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
935 /* global dictionary */
936 shared_dict = readGlobalDomain("WMWindowAttributes", True);
937 /* user dictionary */
938 dict = WMReadPropListFromFile(WDWindowAttributes->path);
939 if (dict) {
940 if (!WMIsPLDictionary(dict)) {
941 WMReleasePropList(dict);
942 dict = NULL;
943 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
944 "WMWindowAttributes", WDWindowAttributes->path);
945 } else {
946 if (shared_dict) {
947 WMMergePLDictionaries(shared_dict, dict, True);
948 WMReleasePropList(dict);
949 dict = shared_dict;
950 shared_dict = NULL;
952 if (WDWindowAttributes->dictionary) {
953 WMReleasePropList(WDWindowAttributes->dictionary);
955 WDWindowAttributes->dictionary = dict;
956 for (i = 0; i < wScreenCount; i++) {
957 scr = wScreenWithNumber(i);
958 if (scr) {
959 RImage *image;
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 image = wDefaultGetImage(scr, "Logo", "WMPanel");
968 if (!image) {
969 wwarning(_("could not load logo image for panels: %s"),
970 RMessageForError(RErrorCode));
971 } else {
972 WMSetApplicationIconImage(scr->wmscreen, image);
973 RReleaseImage(image);
978 } else {
979 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
981 WDWindowAttributes->timestamp = stbuf.st_mtime;
982 if (shared_dict) {
983 WMReleasePropList(shared_dict);
987 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
988 dict = WMReadPropListFromFile(WDRootMenu->path);
989 if (dict) {
990 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
991 WMReleasePropList(dict);
992 dict = NULL;
993 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
994 "WMRootMenu", WDRootMenu->path);
995 } else {
996 if (WDRootMenu->dictionary) {
997 WMReleasePropList(WDRootMenu->dictionary);
999 WDRootMenu->dictionary = dict;
1000 wDefaultsMergeGlobalMenus(WDRootMenu);
1002 } else {
1003 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1005 WDRootMenu->timestamp = stbuf.st_mtime;
1007 #ifndef HAVE_INOTIFY
1008 if (!arg)
1009 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1010 #endif
1013 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1015 WMPropList *plvalue, *old_value;
1016 WDefaultEntry *entry;
1017 unsigned int i;
1018 int update_workspace_back = 0; /* kluge :/ */
1019 unsigned int needs_refresh;
1020 void *tdata;
1021 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1023 needs_refresh = 0;
1025 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1026 entry = &optionList[i];
1028 if (new_dict)
1029 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1030 else
1031 plvalue = NULL;
1033 if (!old_dict)
1034 old_value = NULL;
1035 else
1036 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1038 if (!plvalue && !old_value) {
1039 /* no default in the DB. Use builtin default */
1040 plvalue = entry->plvalue;
1041 if (plvalue && new_dict) {
1042 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1044 } else if (!plvalue) {
1045 /* value was deleted from DB. Keep current value */
1046 continue;
1047 } else if (!old_value) {
1048 /* set value for the 1st time */
1049 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1050 /* value has changed */
1051 } else {
1053 if (strcmp(entry->key, "WorkspaceBack") == 0
1054 && update_workspace_back && scr->flags.backimage_helper_launched) {
1055 } else {
1056 /* value was not changed since last time */
1057 continue;
1061 if (plvalue) {
1062 /* convert data */
1063 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1065 * If the WorkspaceSpecificBack data has been changed
1066 * so that the helper will be launched now, we must be
1067 * sure to send the default background texture config
1068 * to the helper.
1070 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1071 && !scr->flags.backimage_helper_launched) {
1072 update_workspace_back = 1;
1074 if (entry->update) {
1075 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1081 if (needs_refresh != 0 && !scr->flags.startup) {
1082 int foo;
1084 foo = 0;
1085 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1086 foo |= WTextureSettings;
1087 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1088 foo |= WFontSettings;
1089 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1090 foo |= WColorSettings;
1091 if (foo)
1092 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1093 (void *)(uintptr_t) foo);
1095 foo = 0;
1096 if (needs_refresh & REFRESH_MENU_TEXTURE)
1097 foo |= WTextureSettings;
1098 if (needs_refresh & REFRESH_MENU_FONT)
1099 foo |= WFontSettings;
1100 if (needs_refresh & REFRESH_MENU_COLOR)
1101 foo |= WColorSettings;
1102 if (foo)
1103 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1105 foo = 0;
1106 if (needs_refresh & REFRESH_WINDOW_FONT) {
1107 foo |= WFontSettings;
1109 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1110 foo |= WTextureSettings;
1112 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1113 foo |= WColorSettings;
1115 if (foo)
1116 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1118 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1119 foo = 0;
1120 if (needs_refresh & REFRESH_ICON_FONT) {
1121 foo |= WFontSettings;
1123 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1124 foo |= WTextureSettings;
1126 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1127 foo |= WTextureSettings;
1129 if (foo)
1130 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1131 (void *)(uintptr_t) foo);
1133 if (needs_refresh & REFRESH_ICON_TILE)
1134 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1138 void wDefaultUpdateIcons(WScreen * scr)
1140 WAppIcon *aicon = scr->app_icon_list;
1141 WWindow *wwin = scr->focused_window;
1142 char *file;
1144 while (aicon) {
1145 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1146 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1147 || (file && !aicon->icon->file)) {
1148 wIconChangeImageFile(aicon->icon, file);
1149 wAppIconPaint(aicon);
1151 aicon = aicon->next;
1154 if (!wPreferences.flags.noclip)
1155 wClipIconPaint(scr->clip_icon);
1157 while (wwin) {
1158 if (wwin->icon && wwin->flags.miniaturized) {
1159 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1160 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1161 || (file && !wwin->icon->file)) {
1162 wIconChangeImageFile(wwin->icon, file);
1165 wwin = wwin->prev;
1169 /* --------------------------- Local ----------------------- */
1171 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1172 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1173 entry->key, x); \
1174 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1175 var = entry->default_value;\
1176 } else var = WMGetFromPLString(value)\
1179 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1181 char *str;
1182 WOptionEnumeration *v;
1183 char buffer[TOTAL_VALUES_LENGTH];
1185 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1186 for (v = values; v->string != NULL; v++) {
1187 if (strcasecmp(v->string, str) == 0)
1188 return v->value;
1192 buffer[0] = 0;
1193 for (v = values; v->string != NULL; v++) {
1194 if (!v->is_alias) {
1195 if (buffer[0] != 0)
1196 strcat(buffer, ", ");
1197 snprintf(buffer+strlen(buffer),
1198 sizeof(buffer)-strlen(buffer)-1, "\"%s\"", v->string);
1201 wwarning(_("wrong option value for key \"%s\"; got \"%s\", should be one of %s."),
1202 WMGetFromPLString(key),
1203 WMIsPLString(val) ? WMGetFromPLString(val) : "(unknown)",
1204 buffer);
1206 if (def) {
1207 return string2index(key, val, NULL, values);
1210 return -1;
1214 * value - is the value in the defaults DB
1215 * addr - is the address to store the data
1216 * ret - is the address to store a pointer to a temporary buffer. ret
1217 * must not be freed and is used by the set functions
1219 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1221 static char data;
1222 char *val;
1223 int second_pass = 0;
1225 GET_STRING_OR_DEFAULT("Boolean", val);
1227 again:
1228 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1229 || strcasecmp(val, "YES") == 0) {
1231 data = 1;
1232 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1233 || strcasecmp(val, "NO") == 0) {
1234 data = 0;
1235 } else {
1236 int i;
1237 if (sscanf(val, "%i", &i) == 1) {
1238 if (i != 0)
1239 data = 1;
1240 else
1241 data = 0;
1242 } else {
1243 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1244 if (second_pass == 0) {
1245 val = WMGetFromPLString(entry->plvalue);
1246 second_pass = 1;
1247 wwarning(_("using default \"%s\" instead"), val);
1248 goto again;
1250 return False;
1254 if (ret)
1255 *ret = &data;
1256 if (addr)
1257 *(char *)addr = data;
1259 return True;
1262 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1264 static int data;
1265 char *val;
1267 GET_STRING_OR_DEFAULT("Integer", val);
1269 if (sscanf(val, "%i", &data) != 1) {
1270 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1271 val = WMGetFromPLString(entry->plvalue);
1272 wwarning(_("using default \"%s\" instead"), val);
1273 if (sscanf(val, "%i", &data) != 1) {
1274 return False;
1278 if (ret)
1279 *ret = &data;
1280 if (addr)
1281 *(int *)addr = data;
1283 return True;
1286 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1288 static WCoord data;
1289 char *val_x, *val_y;
1290 int nelem, changed = 0;
1291 WMPropList *elem_x, *elem_y;
1293 again:
1294 if (!WMIsPLArray(value)) {
1295 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1296 if (changed == 0) {
1297 value = entry->plvalue;
1298 changed = 1;
1299 wwarning(_("using default \"%s\" instead"), entry->default_value);
1300 goto again;
1302 return False;
1305 nelem = WMGetPropListItemCount(value);
1306 if (nelem != 2) {
1307 wwarning(_("Incorrect number of elements in array for key \"%s\"."), 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 elem_x = WMGetFromPLArray(value, 0);
1318 elem_y = WMGetFromPLArray(value, 1);
1320 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1321 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), 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 val_x = WMGetFromPLString(elem_x);
1332 val_y = WMGetFromPLString(elem_y);
1334 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1335 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1336 if (changed == 0) {
1337 value = entry->plvalue;
1338 changed = 1;
1339 wwarning(_("using default \"%s\" instead"), entry->default_value);
1340 goto again;
1342 return False;
1345 if (data.x < 0)
1346 data.x = 0;
1347 else if (data.x > scr->scr_width / 3)
1348 data.x = scr->scr_width / 3;
1349 if (data.y < 0)
1350 data.y = 0;
1351 else if (data.y > scr->scr_height / 3)
1352 data.y = scr->scr_height / 3;
1354 if (ret)
1355 *ret = &data;
1356 if (addr)
1357 *(WCoord *) addr = data;
1359 return True;
1362 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1364 WMRetainPropList(value);
1366 *ret = value;
1368 return True;
1371 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1373 static char *data;
1374 int i, count, len;
1375 char *ptr;
1376 WMPropList *d;
1377 int changed = 0;
1379 again:
1380 if (!WMIsPLArray(value)) {
1381 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1382 if (changed == 0) {
1383 value = entry->plvalue;
1384 changed = 1;
1385 wwarning(_("using default \"%s\" instead"), entry->default_value);
1386 goto again;
1388 return False;
1391 i = 0;
1392 count = WMGetPropListItemCount(value);
1393 if (count < 1) {
1394 if (changed == 0) {
1395 value = entry->plvalue;
1396 changed = 1;
1397 wwarning(_("using default \"%s\" instead"), entry->default_value);
1398 goto again;
1400 return False;
1403 len = 0;
1404 for (i = 0; i < count; i++) {
1405 d = WMGetFromPLArray(value, i);
1406 if (!d || !WMIsPLString(d)) {
1407 count = i;
1408 break;
1410 len += strlen(WMGetFromPLString(d)) + 1;
1413 ptr = data = wmalloc(len + 1);
1415 for (i = 0; i < count; i++) {
1416 d = WMGetFromPLArray(value, i);
1417 if (!d || !WMIsPLString(d)) {
1418 break;
1420 strcpy(ptr, WMGetFromPLString(d));
1421 ptr += strlen(WMGetFromPLString(d));
1422 *ptr = ':';
1423 ptr++;
1425 ptr--;
1426 *(ptr--) = 0;
1428 if (*(char **)addr != NULL) {
1429 wfree(*(char **)addr);
1431 *(char **)addr = data;
1433 return True;
1436 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1438 static signed char data;
1440 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1441 if (data < 0)
1442 return False;
1444 if (ret)
1445 *ret = &data;
1446 if (addr)
1447 *(signed char *)addr = data;
1449 return True;
1453 * (solid <color>)
1454 * (hgradient <color> <color>)
1455 * (vgradient <color> <color>)
1456 * (dgradient <color> <color>)
1457 * (mhgradient <color> <color> ...)
1458 * (mvgradient <color> <color> ...)
1459 * (mdgradient <color> <color> ...)
1460 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1461 * (tpixmap <file> <color>)
1462 * (spixmap <file> <color>)
1463 * (cpixmap <file> <color>)
1464 * (thgradient <file> <opaqueness> <color> <color>)
1465 * (tvgradient <file> <opaqueness> <color> <color>)
1466 * (tdgradient <file> <opaqueness> <color> <color>)
1467 * (function <lib> <function> ...)
1470 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1472 WMPropList *elem;
1473 char *val;
1474 int nelem;
1475 WTexture *texture = NULL;
1477 nelem = WMGetPropListItemCount(pl);
1478 if (nelem < 1)
1479 return NULL;
1481 elem = WMGetFromPLArray(pl, 0);
1482 if (!elem || !WMIsPLString(elem))
1483 return NULL;
1484 val = WMGetFromPLString(elem);
1486 if (strcasecmp(val, "solid") == 0) {
1487 XColor color;
1489 if (nelem != 2)
1490 return NULL;
1492 /* get color */
1494 elem = WMGetFromPLArray(pl, 1);
1495 if (!elem || !WMIsPLString(elem))
1496 return NULL;
1497 val = WMGetFromPLString(elem);
1499 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1500 wwarning(_("\"%s\" is not a valid color name"), val);
1501 return NULL;
1504 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1505 } else if (strcasecmp(val, "dgradient") == 0
1506 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1507 RColor color1, color2;
1508 XColor xcolor;
1509 int type;
1511 if (nelem != 3) {
1512 wwarning(_("bad number of arguments in gradient specification"));
1513 return NULL;
1516 if (val[0] == 'd' || val[0] == 'D')
1517 type = WTEX_DGRADIENT;
1518 else if (val[0] == 'h' || val[0] == 'H')
1519 type = WTEX_HGRADIENT;
1520 else
1521 type = WTEX_VGRADIENT;
1523 /* get from color */
1524 elem = WMGetFromPLArray(pl, 1);
1525 if (!elem || !WMIsPLString(elem))
1526 return NULL;
1527 val = WMGetFromPLString(elem);
1529 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1530 wwarning(_("\"%s\" is not a valid color name"), val);
1531 return NULL;
1533 color1.alpha = 255;
1534 color1.red = xcolor.red >> 8;
1535 color1.green = xcolor.green >> 8;
1536 color1.blue = xcolor.blue >> 8;
1538 /* get to color */
1539 elem = WMGetFromPLArray(pl, 2);
1540 if (!elem || !WMIsPLString(elem)) {
1541 return NULL;
1543 val = WMGetFromPLString(elem);
1545 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1546 wwarning(_("\"%s\" is not a valid color name"), val);
1547 return NULL;
1549 color2.alpha = 255;
1550 color2.red = xcolor.red >> 8;
1551 color2.green = xcolor.green >> 8;
1552 color2.blue = xcolor.blue >> 8;
1554 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1556 } else if (strcasecmp(val, "igradient") == 0) {
1557 RColor colors1[2], colors2[2];
1558 int th1, th2;
1559 XColor xcolor;
1560 int i;
1562 if (nelem != 7) {
1563 wwarning(_("bad number of arguments in gradient specification"));
1564 return NULL;
1567 /* get from color */
1568 for (i = 0; i < 2; i++) {
1569 elem = WMGetFromPLArray(pl, 1 + i);
1570 if (!elem || !WMIsPLString(elem))
1571 return NULL;
1572 val = WMGetFromPLString(elem);
1574 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1575 wwarning(_("\"%s\" is not a valid color name"), val);
1576 return NULL;
1578 colors1[i].alpha = 255;
1579 colors1[i].red = xcolor.red >> 8;
1580 colors1[i].green = xcolor.green >> 8;
1581 colors1[i].blue = xcolor.blue >> 8;
1583 elem = WMGetFromPLArray(pl, 3);
1584 if (!elem || !WMIsPLString(elem))
1585 return NULL;
1586 val = WMGetFromPLString(elem);
1587 th1 = atoi(val);
1589 /* get from color */
1590 for (i = 0; i < 2; i++) {
1591 elem = WMGetFromPLArray(pl, 4 + i);
1592 if (!elem || !WMIsPLString(elem))
1593 return NULL;
1594 val = WMGetFromPLString(elem);
1596 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1597 wwarning(_("\"%s\" is not a valid color name"), val);
1598 return NULL;
1600 colors2[i].alpha = 255;
1601 colors2[i].red = xcolor.red >> 8;
1602 colors2[i].green = xcolor.green >> 8;
1603 colors2[i].blue = xcolor.blue >> 8;
1605 elem = WMGetFromPLArray(pl, 6);
1606 if (!elem || !WMIsPLString(elem))
1607 return NULL;
1608 val = WMGetFromPLString(elem);
1609 th2 = atoi(val);
1611 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1613 } else if (strcasecmp(val, "mhgradient") == 0
1614 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1615 XColor color;
1616 RColor **colors;
1617 int i, count;
1618 int type;
1620 if (nelem < 3) {
1621 wwarning(_("too few arguments in multicolor gradient specification"));
1622 return NULL;
1625 if (val[1] == 'h' || val[1] == 'H')
1626 type = WTEX_MHGRADIENT;
1627 else if (val[1] == 'v' || val[1] == 'V')
1628 type = WTEX_MVGRADIENT;
1629 else
1630 type = WTEX_MDGRADIENT;
1632 count = nelem - 1;
1634 colors = wmalloc(sizeof(RColor *) * (count + 1));
1636 for (i = 0; i < count; i++) {
1637 elem = WMGetFromPLArray(pl, i + 1);
1638 if (!elem || !WMIsPLString(elem)) {
1639 for (--i; i >= 0; --i) {
1640 wfree(colors[i]);
1642 wfree(colors);
1643 return NULL;
1645 val = WMGetFromPLString(elem);
1647 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1648 wwarning(_("\"%s\" is not a valid color name"), val);
1649 for (--i; i >= 0; --i) {
1650 wfree(colors[i]);
1652 wfree(colors);
1653 return NULL;
1654 } else {
1655 colors[i] = wmalloc(sizeof(RColor));
1656 colors[i]->red = color.red >> 8;
1657 colors[i]->green = color.green >> 8;
1658 colors[i]->blue = color.blue >> 8;
1661 colors[i] = NULL;
1663 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1664 } else if (strcasecmp(val, "spixmap") == 0 ||
1665 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1666 XColor color;
1667 int type;
1669 if (nelem != 3)
1670 return NULL;
1672 if (val[0] == 's' || val[0] == 'S')
1673 type = WTP_SCALE;
1674 else if (val[0] == 'c' || val[0] == 'C')
1675 type = WTP_CENTER;
1676 else
1677 type = WTP_TILE;
1679 /* get color */
1680 elem = WMGetFromPLArray(pl, 2);
1681 if (!elem || !WMIsPLString(elem)) {
1682 return NULL;
1684 val = WMGetFromPLString(elem);
1686 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1687 wwarning(_("\"%s\" is not a valid color name"), val);
1688 return NULL;
1691 /* file name */
1692 elem = WMGetFromPLArray(pl, 1);
1693 if (!elem || !WMIsPLString(elem))
1694 return NULL;
1695 val = WMGetFromPLString(elem);
1697 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1698 } else if (strcasecmp(val, "thgradient") == 0
1699 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1700 RColor color1, color2;
1701 XColor xcolor;
1702 int opacity;
1703 int style;
1705 if (val[1] == 'h' || val[1] == 'H')
1706 style = WTEX_THGRADIENT;
1707 else if (val[1] == 'v' || val[1] == 'V')
1708 style = WTEX_TVGRADIENT;
1709 else
1710 style = WTEX_TDGRADIENT;
1712 if (nelem != 5) {
1713 wwarning(_("bad number of arguments in textured gradient specification"));
1714 return NULL;
1717 /* get from color */
1718 elem = WMGetFromPLArray(pl, 3);
1719 if (!elem || !WMIsPLString(elem))
1720 return NULL;
1721 val = WMGetFromPLString(elem);
1723 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1724 wwarning(_("\"%s\" is not a valid color name"), val);
1725 return NULL;
1727 color1.alpha = 255;
1728 color1.red = xcolor.red >> 8;
1729 color1.green = xcolor.green >> 8;
1730 color1.blue = xcolor.blue >> 8;
1732 /* get to color */
1733 elem = WMGetFromPLArray(pl, 4);
1734 if (!elem || !WMIsPLString(elem)) {
1735 return NULL;
1737 val = WMGetFromPLString(elem);
1739 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1740 wwarning(_("\"%s\" is not a valid color name"), val);
1741 return NULL;
1743 color2.alpha = 255;
1744 color2.red = xcolor.red >> 8;
1745 color2.green = xcolor.green >> 8;
1746 color2.blue = xcolor.blue >> 8;
1748 /* get opacity */
1749 elem = WMGetFromPLArray(pl, 2);
1750 if (!elem || !WMIsPLString(elem))
1751 opacity = 128;
1752 else
1753 val = WMGetFromPLString(elem);
1755 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1756 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1757 opacity = 128;
1760 /* get file name */
1761 elem = WMGetFromPLArray(pl, 1);
1762 if (!elem || !WMIsPLString(elem))
1763 return NULL;
1764 val = WMGetFromPLString(elem);
1766 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1767 } else if (strcasecmp(val, "function") == 0) {
1768 /* Leave this in to handle the unlikely case of
1769 * someone actually having function textures configured */
1770 wwarning("function texture support has been removed");
1771 return NULL;
1772 } else {
1773 wwarning(_("invalid texture type %s"), val);
1774 return NULL;
1776 return texture;
1779 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1781 static WTexture *texture;
1782 int changed = 0;
1784 again:
1785 if (!WMIsPLArray(value)) {
1786 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1787 if (changed == 0) {
1788 value = entry->plvalue;
1789 changed = 1;
1790 wwarning(_("using default \"%s\" instead"), entry->default_value);
1791 goto again;
1793 return False;
1796 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1797 WMPropList *pl;
1799 pl = WMGetFromPLArray(value, 0);
1800 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1801 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1802 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1803 entry->key, "Solid Texture");
1805 value = entry->plvalue;
1806 changed = 1;
1807 wwarning(_("using default \"%s\" instead"), entry->default_value);
1808 goto again;
1812 texture = parse_texture(scr, value);
1814 if (!texture) {
1815 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1816 if (changed == 0) {
1817 value = entry->plvalue;
1818 changed = 1;
1819 wwarning(_("using default \"%s\" instead"), entry->default_value);
1820 goto again;
1822 return False;
1825 if (ret)
1826 *ret = &texture;
1828 if (addr)
1829 *(WTexture **) addr = texture;
1831 return True;
1834 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1836 WMPropList *elem;
1837 int changed = 0;
1838 char *val;
1839 int nelem;
1841 again:
1842 if (!WMIsPLArray(value)) {
1843 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1844 "WorkspaceBack", "Texture or None");
1845 if (changed == 0) {
1846 value = entry->plvalue;
1847 changed = 1;
1848 wwarning(_("using default \"%s\" instead"), entry->default_value);
1849 goto again;
1851 return False;
1854 /* only do basic error checking and verify for None texture */
1856 nelem = WMGetPropListItemCount(value);
1857 if (nelem > 0) {
1858 elem = WMGetFromPLArray(value, 0);
1859 if (!elem || !WMIsPLString(elem)) {
1860 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1861 if (changed == 0) {
1862 value = entry->plvalue;
1863 changed = 1;
1864 wwarning(_("using default \"%s\" instead"), entry->default_value);
1865 goto again;
1867 return False;
1869 val = WMGetFromPLString(elem);
1871 if (strcasecmp(val, "None") == 0)
1872 return True;
1874 *ret = WMRetainPropList(value);
1876 return True;
1879 static int
1880 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1882 WMPropList *elem;
1883 int nelem;
1884 int changed = 0;
1886 again:
1887 if (!WMIsPLArray(value)) {
1888 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1889 "WorkspaceSpecificBack", "an array of textures");
1890 if (changed == 0) {
1891 value = entry->plvalue;
1892 changed = 1;
1893 wwarning(_("using default \"%s\" instead"), entry->default_value);
1894 goto again;
1896 return False;
1899 /* only do basic error checking and verify for None texture */
1901 nelem = WMGetPropListItemCount(value);
1902 if (nelem > 0) {
1903 while (nelem--) {
1904 elem = WMGetFromPLArray(value, nelem);
1905 if (!elem || !WMIsPLArray(elem)) {
1906 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1907 nelem);
1912 *ret = WMRetainPropList(value);
1914 #ifdef notworking
1916 * Kluge to force wmsetbg helper to set the default background.
1917 * If the WorkspaceSpecificBack is changed once wmaker has started,
1918 * the WorkspaceBack won't be sent to the helper, unless the user
1919 * changes it's value too. So, we must force this by removing the
1920 * value from the defaults DB.
1922 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1923 WMPropList *key = WMCreatePLString("WorkspaceBack");
1925 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1927 WMReleasePropList(key);
1929 #endif
1930 return True;
1933 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1935 static WMFont *font;
1936 char *val;
1938 GET_STRING_OR_DEFAULT("Font", val);
1940 font = WMCreateFont(scr->wmscreen, val);
1941 if (!font)
1942 font = WMCreateFont(scr->wmscreen, "fixed");
1944 if (!font) {
1945 wfatal(_("could not load any usable font!!!"));
1946 exit(1);
1949 if (ret)
1950 *ret = font;
1952 /* can't assign font value outside update function */
1953 wassertrv(addr == NULL, True);
1955 return True;
1958 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1960 static XColor color;
1961 char *val;
1962 int second_pass = 0;
1964 GET_STRING_OR_DEFAULT("Color", val);
1966 again:
1967 if (!wGetColor(scr, val, &color)) {
1968 wwarning(_("could not get color for key \"%s\""), entry->key);
1969 if (second_pass == 0) {
1970 val = WMGetFromPLString(entry->plvalue);
1971 second_pass = 1;
1972 wwarning(_("using default \"%s\" instead"), val);
1973 goto again;
1975 return False;
1978 if (ret)
1979 *ret = &color;
1981 assert(addr == NULL);
1983 if (addr)
1984 *(unsigned long*)addr = pixel;
1987 return True;
1990 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1992 static WShortKey shortcut;
1993 KeySym ksym;
1994 char *val;
1995 char *k;
1996 char buf[MAX_SHORTCUT_LENGTH], *b;
1998 GET_STRING_OR_DEFAULT("Key spec", val);
2000 if (!val || strcasecmp(val, "NONE") == 0) {
2001 shortcut.keycode = 0;
2002 shortcut.modifier = 0;
2003 if (ret)
2004 *ret = &shortcut;
2005 return True;
2008 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2010 b = (char *)buf;
2012 /* get modifiers */
2013 shortcut.modifier = 0;
2014 while ((k = strchr(b, '+')) != NULL) {
2015 int mod;
2017 *k = 0;
2018 mod = wXModifierFromKey(b);
2019 if (mod < 0) {
2020 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2021 return False;
2023 shortcut.modifier |= mod;
2025 b = k + 1;
2028 /* get key */
2029 ksym = XStringToKeysym(b);
2031 if (ksym == NoSymbol) {
2032 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2033 return False;
2036 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2037 if (shortcut.keycode == 0) {
2038 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2039 return False;
2042 if (ret)
2043 *ret = &shortcut;
2045 return True;
2048 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2050 static int mask;
2051 char *str;
2053 GET_STRING_OR_DEFAULT("Modifier Key", str);
2055 if (!str)
2056 return False;
2058 mask = wXModifierFromKey(str);
2059 if (mask < 0) {
2060 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2061 mask = 0;
2062 return False;
2065 if (addr)
2066 *(int *)addr = mask;
2068 if (ret)
2069 *ret = &mask;
2071 return True;
2074 # include <X11/cursorfont.h>
2075 typedef struct {
2076 char *name;
2077 int id;
2078 } WCursorLookup;
2080 #define CURSOR_ID_NONE (XC_num_glyphs)
2082 static WCursorLookup cursor_table[] = {
2083 {"X_cursor", XC_X_cursor},
2084 {"arrow", XC_arrow},
2085 {"based_arrow_down", XC_based_arrow_down},
2086 {"based_arrow_up", XC_based_arrow_up},
2087 {"boat", XC_boat},
2088 {"bogosity", XC_bogosity},
2089 {"bottom_left_corner", XC_bottom_left_corner},
2090 {"bottom_right_corner", XC_bottom_right_corner},
2091 {"bottom_side", XC_bottom_side},
2092 {"bottom_tee", XC_bottom_tee},
2093 {"box_spiral", XC_box_spiral},
2094 {"center_ptr", XC_center_ptr},
2095 {"circle", XC_circle},
2096 {"clock", XC_clock},
2097 {"coffee_mug", XC_coffee_mug},
2098 {"cross", XC_cross},
2099 {"cross_reverse", XC_cross_reverse},
2100 {"crosshair", XC_crosshair},
2101 {"diamond_cross", XC_diamond_cross},
2102 {"dot", XC_dot},
2103 {"dotbox", XC_dotbox},
2104 {"double_arrow", XC_double_arrow},
2105 {"draft_large", XC_draft_large},
2106 {"draft_small", XC_draft_small},
2107 {"draped_box", XC_draped_box},
2108 {"exchange", XC_exchange},
2109 {"fleur", XC_fleur},
2110 {"gobbler", XC_gobbler},
2111 {"gumby", XC_gumby},
2112 {"hand1", XC_hand1},
2113 {"hand2", XC_hand2},
2114 {"heart", XC_heart},
2115 {"icon", XC_icon},
2116 {"iron_cross", XC_iron_cross},
2117 {"left_ptr", XC_left_ptr},
2118 {"left_side", XC_left_side},
2119 {"left_tee", XC_left_tee},
2120 {"leftbutton", XC_leftbutton},
2121 {"ll_angle", XC_ll_angle},
2122 {"lr_angle", XC_lr_angle},
2123 {"man", XC_man},
2124 {"middlebutton", XC_middlebutton},
2125 {"mouse", XC_mouse},
2126 {"pencil", XC_pencil},
2127 {"pirate", XC_pirate},
2128 {"plus", XC_plus},
2129 {"question_arrow", XC_question_arrow},
2130 {"right_ptr", XC_right_ptr},
2131 {"right_side", XC_right_side},
2132 {"right_tee", XC_right_tee},
2133 {"rightbutton", XC_rightbutton},
2134 {"rtl_logo", XC_rtl_logo},
2135 {"sailboat", XC_sailboat},
2136 {"sb_down_arrow", XC_sb_down_arrow},
2137 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2138 {"sb_left_arrow", XC_sb_left_arrow},
2139 {"sb_right_arrow", XC_sb_right_arrow},
2140 {"sb_up_arrow", XC_sb_up_arrow},
2141 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2142 {"shuttle", XC_shuttle},
2143 {"sizing", XC_sizing},
2144 {"spider", XC_spider},
2145 {"spraycan", XC_spraycan},
2146 {"star", XC_star},
2147 {"target", XC_target},
2148 {"tcross", XC_tcross},
2149 {"top_left_arrow", XC_top_left_arrow},
2150 {"top_left_corner", XC_top_left_corner},
2151 {"top_right_corner", XC_top_right_corner},
2152 {"top_side", XC_top_side},
2153 {"top_tee", XC_top_tee},
2154 {"trek", XC_trek},
2155 {"ul_angle", XC_ul_angle},
2156 {"umbrella", XC_umbrella},
2157 {"ur_angle", XC_ur_angle},
2158 {"watch", XC_watch},
2159 {"xterm", XC_xterm},
2160 {NULL, CURSOR_ID_NONE}
2163 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2165 switch (status) {
2166 case BitmapOpenFailed:
2167 wwarning(_("failed to open bitmap file \"%s\""), filename);
2168 break;
2169 case BitmapFileInvalid:
2170 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2171 break;
2172 case BitmapNoMemory:
2173 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2174 break;
2175 case BitmapSuccess:
2176 XFreePixmap(dpy, bitmap);
2177 break;
2182 * (none)
2183 * (builtin, <cursor_name>)
2184 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2186 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2188 WMPropList *elem;
2189 char *val;
2190 int nelem;
2191 int status = 0;
2193 nelem = WMGetPropListItemCount(pl);
2194 if (nelem < 1) {
2195 return (status);
2197 elem = WMGetFromPLArray(pl, 0);
2198 if (!elem || !WMIsPLString(elem)) {
2199 return (status);
2201 val = WMGetFromPLString(elem);
2203 if (strcasecmp(val, "none") == 0) {
2204 status = 1;
2205 *cursor = None;
2206 } else if (strcasecmp(val, "builtin") == 0) {
2207 int i;
2208 int cursor_id = CURSOR_ID_NONE;
2210 if (nelem != 2) {
2211 wwarning(_("bad number of arguments in cursor specification"));
2212 return (status);
2214 elem = WMGetFromPLArray(pl, 1);
2215 if (!elem || !WMIsPLString(elem)) {
2216 return (status);
2218 val = WMGetFromPLString(elem);
2220 for (i = 0; cursor_table[i].name != NULL; i++) {
2221 if (strcasecmp(val, cursor_table[i].name) == 0) {
2222 cursor_id = cursor_table[i].id;
2223 break;
2226 if (CURSOR_ID_NONE == cursor_id) {
2227 wwarning(_("unknown builtin cursor name \"%s\""), val);
2228 } else {
2229 *cursor = XCreateFontCursor(dpy, cursor_id);
2230 status = 1;
2232 } else if (strcasecmp(val, "bitmap") == 0) {
2233 char *bitmap_name;
2234 char *mask_name;
2235 int bitmap_status;
2236 int mask_status;
2237 Pixmap bitmap;
2238 Pixmap mask;
2239 unsigned int w, h;
2240 int x, y;
2241 XColor fg, bg;
2243 if (nelem != 3) {
2244 wwarning(_("bad number of arguments in cursor specification"));
2245 return (status);
2247 elem = WMGetFromPLArray(pl, 1);
2248 if (!elem || !WMIsPLString(elem)) {
2249 return (status);
2251 val = WMGetFromPLString(elem);
2252 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2253 if (!bitmap_name) {
2254 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2255 return (status);
2257 elem = WMGetFromPLArray(pl, 2);
2258 if (!elem || !WMIsPLString(elem)) {
2259 wfree(bitmap_name);
2260 return (status);
2262 val = WMGetFromPLString(elem);
2263 mask_name = FindImage(wPreferences.pixmap_path, val);
2264 if (!mask_name) {
2265 wfree(bitmap_name);
2266 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2267 return (status);
2269 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2270 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2271 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2272 fg.pixel = scr->black_pixel;
2273 bg.pixel = scr->white_pixel;
2274 XQueryColor(dpy, scr->w_colormap, &fg);
2275 XQueryColor(dpy, scr->w_colormap, &bg);
2276 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2277 status = 1;
2279 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2280 check_bitmap_status(mask_status, mask_name, mask);
2281 wfree(bitmap_name);
2282 wfree(mask_name);
2284 return (status);
2287 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2289 static Cursor cursor;
2290 int status;
2291 int changed = 0;
2293 again:
2294 if (!WMIsPLArray(value)) {
2295 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2296 entry->key, "cursor specification");
2297 if (!changed) {
2298 value = entry->plvalue;
2299 changed = 1;
2300 wwarning(_("using default \"%s\" instead"), entry->default_value);
2301 goto again;
2303 return (False);
2305 status = parse_cursor(scr, value, &cursor);
2306 if (!status) {
2307 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2308 if (!changed) {
2309 value = entry->plvalue;
2310 changed = 1;
2311 wwarning(_("using default \"%s\" instead"), entry->default_value);
2312 goto again;
2314 return (False);
2316 if (ret) {
2317 *ret = &cursor;
2319 if (addr) {
2320 *(Cursor *) addr = cursor;
2322 return (True);
2325 #undef CURSOR_ID_NONE
2327 /* ---------------- value setting functions --------------- */
2328 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2330 return REFRESH_WINDOW_TITLE_COLOR;
2333 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2335 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2338 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2340 switch (which) {
2341 case WM_DOCK:
2342 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2343 break;
2344 case WM_CLIP:
2345 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2346 break;
2347 default:
2348 break;
2350 return 0;
2353 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2355 if (scr->workspaces) {
2356 wWorkspaceForceChange(scr, scr->current_workspace);
2357 wArrangeIcons(scr, False);
2359 return 0;
2362 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2364 Pixmap pixmap;
2365 RImage *img;
2366 int reset = 0;
2368 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2369 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2370 ? WREL_ICON : WREL_FLAT);
2371 if (!img) {
2372 wwarning(_("could not render texture for icon background"));
2373 if (!entry->addr)
2374 wTextureDestroy(scr, *texture);
2375 return 0;
2377 RConvertImage(scr->rcontext, img, &pixmap);
2379 if (scr->icon_tile) {
2380 reset = 1;
2381 RReleaseImage(scr->icon_tile);
2382 XFreePixmap(dpy, scr->icon_tile_pixmap);
2385 scr->icon_tile = img;
2387 /* put the icon in the noticeboard hint */
2388 PropSetIconTileHint(scr, img);
2390 if (!wPreferences.flags.noclip) {
2391 if (scr->clip_tile) {
2392 RReleaseImage(scr->clip_tile);
2394 scr->clip_tile = wClipMakeTile(scr, img);
2397 scr->icon_tile_pixmap = pixmap;
2399 if (scr->def_icon_pixmap) {
2400 XFreePixmap(dpy, scr->def_icon_pixmap);
2401 scr->def_icon_pixmap = None;
2403 if (scr->def_ticon_pixmap) {
2404 XFreePixmap(dpy, scr->def_ticon_pixmap);
2405 scr->def_ticon_pixmap = None;
2408 if (scr->icon_back_texture) {
2409 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2411 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2413 if (scr->clip_balloon)
2414 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2417 * Free the texture as nobody else will use it, nor refer to it.
2419 if (!entry->addr)
2420 wTextureDestroy(scr, *texture);
2422 return (reset ? REFRESH_ICON_TILE : 0);
2425 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2427 if (scr->title_font) {
2428 WMReleaseFont(scr->title_font);
2430 scr->title_font = font;
2432 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2435 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2437 if (scr->menu_title_font) {
2438 WMReleaseFont(scr->menu_title_font);
2441 scr->menu_title_font = font;
2443 return REFRESH_MENU_TITLE_FONT;
2446 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2448 if (scr->menu_entry_font) {
2449 WMReleaseFont(scr->menu_entry_font);
2451 scr->menu_entry_font = font;
2453 return REFRESH_MENU_FONT;
2456 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2458 if (scr->icon_title_font) {
2459 WMReleaseFont(scr->icon_title_font);
2462 scr->icon_title_font = font;
2464 return REFRESH_ICON_FONT;
2467 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2469 if (scr->clip_title_font) {
2470 WMReleaseFont(scr->clip_title_font);
2473 scr->clip_title_font = font;
2475 return REFRESH_ICON_FONT;
2478 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2480 if (scr->workspace_name_font) {
2481 WMReleaseFont(scr->workspace_name_font);
2484 scr->workspace_name_font = font;
2486 return 0;
2489 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2491 if (scr->select_color)
2492 WMReleaseColor(scr->select_color);
2494 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2496 wFreeColor(scr, color->pixel);
2498 return REFRESH_MENU_COLOR;
2501 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2503 if (scr->select_text_color)
2504 WMReleaseColor(scr->select_text_color);
2506 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2508 wFreeColor(scr, color->pixel);
2510 return REFRESH_MENU_COLOR;
2513 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2515 if (scr->clip_title_color[widx])
2516 WMReleaseColor(scr->clip_title_color[widx]);
2517 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2518 #ifdef GRADIENT_CLIP_ARROW
2519 if (widx == CLIP_NORMAL) {
2520 RImage *image;
2521 RColor color1, color2;
2522 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2523 int as = pt - 15; /* 15 = 5+5+5 */
2525 FREE_PIXMAP(scr->clip_arrow_gradient);
2527 color1.red = (color->red >> 8) * 6 / 10;
2528 color1.green = (color->green >> 8) * 6 / 10;
2529 color1.blue = (color->blue >> 8) * 6 / 10;
2531 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2532 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2533 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2535 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2536 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2537 RReleaseImage(image);
2539 #endif /* GRADIENT_CLIP_ARROW */
2541 wFreeColor(scr, color->pixel);
2543 return REFRESH_ICON_TITLE_COLOR;
2546 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2548 if (scr->window_title_color[widx])
2549 WMReleaseColor(scr->window_title_color[widx]);
2551 scr->window_title_color[widx] =
2552 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2554 wFreeColor(scr, color->pixel);
2556 return REFRESH_WINDOW_TITLE_COLOR;
2559 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2561 if (scr->menu_title_color[0])
2562 WMReleaseColor(scr->menu_title_color[0]);
2564 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2566 wFreeColor(scr, color->pixel);
2568 return REFRESH_MENU_TITLE_COLOR;
2571 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2573 if (scr->mtext_color)
2574 WMReleaseColor(scr->mtext_color);
2576 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2578 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2579 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2580 } else {
2581 WMSetColorAlpha(scr->dtext_color, 0xffff);
2584 wFreeColor(scr, color->pixel);
2586 return REFRESH_MENU_COLOR;
2589 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2591 if (scr->dtext_color)
2592 WMReleaseColor(scr->dtext_color);
2594 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2596 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2597 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2598 } else {
2599 WMSetColorAlpha(scr->dtext_color, 0xffff);
2602 wFreeColor(scr, color->pixel);
2604 return REFRESH_MENU_COLOR;
2607 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2609 if (scr->icon_title_color)
2610 WMReleaseColor(scr->icon_title_color);
2611 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2613 wFreeColor(scr, color->pixel);
2615 return REFRESH_ICON_TITLE_COLOR;
2618 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2620 if (scr->icon_title_texture) {
2621 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2623 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2625 return REFRESH_ICON_TITLE_BACK;
2628 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2630 close(scr->helper_fd);
2631 scr->helper_fd = 0;
2632 scr->helper_pid = 0;
2633 scr->flags.backimage_helper_launched = 0;
2636 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2638 WMPropList *val;
2639 char *str;
2640 int i;
2642 if (scr->flags.backimage_helper_launched) {
2643 if (WMGetPropListItemCount(value) == 0) {
2644 SendHelperMessage(scr, 'C', 0, NULL);
2645 SendHelperMessage(scr, 'K', 0, NULL);
2647 WMReleasePropList(value);
2648 return 0;
2650 } else {
2651 pid_t pid;
2652 int filedes[2];
2654 if (WMGetPropListItemCount(value) == 0)
2655 return 0;
2657 if (pipe(filedes) < 0) {
2658 werror("pipe() failed:can't set workspace specific background image");
2660 WMReleasePropList(value);
2661 return 0;
2664 pid = fork();
2665 if (pid < 0) {
2666 werror("fork() failed:can't set workspace specific background image");
2667 if (close(filedes[0]) < 0)
2668 werror("could not close pipe");
2669 if (close(filedes[1]) < 0)
2670 werror("could not close pipe");
2672 } else if (pid == 0) {
2673 char *dither;
2675 SetupEnvironment(scr);
2677 if (close(0) < 0)
2678 werror("could not close pipe");
2679 if (dup(filedes[0]) < 0) {
2680 werror("dup() failed:can't set workspace specific background image");
2682 dither = wPreferences.no_dithering ? "-m" : "-d";
2683 if (wPreferences.smooth_workspace_back)
2684 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2685 else
2686 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2687 werror("could not execute wmsetbg");
2688 exit(1);
2689 } else {
2691 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2692 werror("error setting close-on-exec flag");
2694 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2695 werror("error setting close-on-exec flag");
2698 scr->helper_fd = filedes[1];
2699 scr->helper_pid = pid;
2700 scr->flags.backimage_helper_launched = 1;
2702 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2704 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2709 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2710 val = WMGetFromPLArray(value, i);
2711 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2712 str = WMGetPropListDescription(val, False);
2714 SendHelperMessage(scr, 'S', i + 1, str);
2716 wfree(str);
2717 } else {
2718 SendHelperMessage(scr, 'U', i + 1, NULL);
2721 sleep(1);
2723 WMReleasePropList(value);
2724 return 0;
2727 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2729 if (scr->flags.backimage_helper_launched) {
2730 char *str;
2732 if (WMGetPropListItemCount(value) == 0) {
2733 SendHelperMessage(scr, 'U', 0, NULL);
2734 } else {
2735 /* set the default workspace background to this one */
2736 str = WMGetPropListDescription(value, False);
2737 if (str) {
2738 SendHelperMessage(scr, 'S', 0, str);
2739 wfree(str);
2740 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2741 } else {
2742 SendHelperMessage(scr, 'U', 0, NULL);
2745 } else if (WMGetPropListItemCount(value) > 0) {
2746 char *command;
2747 char *text;
2748 char *dither;
2749 int len;
2751 text = WMGetPropListDescription(value, False);
2752 len = strlen(text) + 40;
2753 command = wmalloc(len);
2754 dither = wPreferences.no_dithering ? "-m" : "-d";
2755 if (wPreferences.smooth_workspace_back)
2756 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2757 else
2758 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2759 wfree(text);
2760 ExecuteShellCommand(scr, command);
2761 wfree(command);
2763 WMReleasePropList(value);
2765 return 0;
2768 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2770 if (scr->widget_texture) {
2771 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2773 scr->widget_texture = *(WTexSolid **) texture;
2775 return 0;
2778 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2780 if (scr->window_title_texture[WS_FOCUSED]) {
2781 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2783 scr->window_title_texture[WS_FOCUSED] = *texture;
2785 return REFRESH_WINDOW_TEXTURES;
2788 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2790 if (scr->window_title_texture[WS_PFOCUSED]) {
2791 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2793 scr->window_title_texture[WS_PFOCUSED] = *texture;
2795 return REFRESH_WINDOW_TEXTURES;
2798 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2800 if (scr->window_title_texture[WS_UNFOCUSED]) {
2801 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2803 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2805 return REFRESH_WINDOW_TEXTURES;
2808 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2810 if (scr->resizebar_texture[0]) {
2811 wTextureDestroy(scr, scr->resizebar_texture[0]);
2813 scr->resizebar_texture[0] = *texture;
2815 return REFRESH_WINDOW_TEXTURES;
2818 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2820 if (scr->menu_title_texture[0]) {
2821 wTextureDestroy(scr, scr->menu_title_texture[0]);
2823 scr->menu_title_texture[0] = *texture;
2825 return REFRESH_MENU_TITLE_TEXTURE;
2828 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2830 if (scr->menu_item_texture) {
2831 wTextureDestroy(scr, scr->menu_item_texture);
2832 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2834 scr->menu_item_texture = *texture;
2836 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2838 return REFRESH_MENU_TEXTURE;
2841 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2843 WWindow *wwin;
2844 wKeyBindings[widx] = *shortcut;
2846 wwin = scr->focused_window;
2848 while (wwin != NULL) {
2849 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2851 if (!WFLAGP(wwin, no_bind_keys)) {
2852 wWindowSetKeyGrabs(wwin);
2854 wwin = wwin->prev;
2857 return 0;
2860 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2862 wScreenUpdateUsableArea(scr);
2863 wArrangeIcons(scr, True);
2865 return 0;
2868 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2870 wScreenUpdateUsableArea(scr);
2872 return 0;
2875 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2877 return REFRESH_MENU_TEXTURE;
2880 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2882 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2884 RCopyArea(img, image, x, y, w, h, 0, 0);
2886 return img;
2889 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2891 char *path;
2892 RImage *bgimage;
2893 int cwidth, cheight;
2894 WPreferences *prefs = (WPreferences *) foo;
2896 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2897 if (prefs->swtileImage)
2898 RReleaseImage(prefs->swtileImage);
2899 prefs->swtileImage = NULL;
2901 WMReleasePropList(array);
2902 return 0;
2905 switch (WMGetPropListItemCount(array)) {
2906 case 4:
2907 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2908 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2909 break;
2910 } else
2911 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2913 if (!path) {
2914 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2915 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2916 } else {
2917 bgimage = RLoadImage(scr->rcontext, path, 0);
2918 if (!bgimage) {
2919 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2920 wfree(path);
2921 } else {
2922 wfree(path);
2924 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2925 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2927 if (cwidth <= 0 || cheight <= 0 ||
2928 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2929 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2930 else {
2931 int i;
2932 int swidth, theight;
2933 for (i = 0; i < 9; i++) {
2934 if (prefs->swbackImage[i])
2935 RReleaseImage(prefs->swbackImage[i]);
2936 prefs->swbackImage[i] = NULL;
2938 swidth = (bgimage->width - cwidth) / 2;
2939 theight = (bgimage->height - cheight) / 2;
2941 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2942 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2943 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2944 swidth, theight);
2946 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2947 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2948 cwidth, cheight);
2949 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2950 swidth, cheight);
2952 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2953 swidth, theight);
2954 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2955 cwidth, theight);
2956 prefs->swbackImage[8] =
2957 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2958 theight);
2960 // check if anything failed
2961 for (i = 0; i < 9; i++) {
2962 if (!prefs->swbackImage[i]) {
2963 for (; i >= 0; --i) {
2964 RReleaseImage(prefs->swbackImage[i]);
2965 prefs->swbackImage[i] = NULL;
2967 break;
2971 RReleaseImage(bgimage);
2975 case 1:
2976 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
2977 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2978 break;
2979 } else
2980 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
2982 if (!path) {
2983 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2984 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
2985 } else {
2986 if (prefs->swtileImage)
2987 RReleaseImage(prefs->swtileImage);
2989 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
2990 if (!prefs->swtileImage) {
2991 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2993 wfree(path);
2995 break;
2997 default:
2998 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
2999 break;
3002 WMReleasePropList(array);
3004 return 0;
3007 static int setModifierKeyLabels(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
3009 int i;
3010 WPreferences *prefs = (WPreferences *) foo;
3012 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) != 7) {
3013 wwarning(_("Value for option \"%s\" must be an array of 7 strings"), entry->key);
3014 WMReleasePropList(array);
3015 return 0;
3018 DestroyWindowMenu(scr);
3020 for (i = 0; i < 7; i++) {
3021 if (prefs->modifier_labels[i])
3022 wfree(prefs->modifier_labels[i]);
3024 if (WMIsPLString(WMGetFromPLArray(array, i))) {
3025 prefs->modifier_labels[i] = wstrdup(WMGetFromPLString(WMGetFromPLArray(array, i)));
3026 } else {
3027 wwarning(_("Invalid argument for option \"%s\" item %d"), entry->key, i);
3028 prefs->modifier_labels[i] = NULL;
3032 WMReleasePropList(array);
3034 return 0;
3038 * Very ugly kluge.
3039 * Need access to the double click variables, so that all widgets in
3040 * wmaker panels will have the same dbl-click values.
3041 * TODO: figure a better way of dealing with it.
3043 #include <WINGs/WINGsP.h>
3045 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3047 extern _WINGsConfiguration WINGsConfiguration;
3049 if (*value <= 0)
3050 *(int *)foo = 1;
3052 WINGsConfiguration.doubleClickDelay = *value;
3054 return 0;
3057 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3059 if (wCursor[widx] != None) {
3060 XFreeCursor(dpy, wCursor[widx]);
3063 wCursor[widx] = *cursor;
3065 if (widx == WCUR_ROOT && *cursor != None) {
3066 XDefineCursor(dpy, scr->root_win, *cursor);
3069 return 0;