Escape minus sign ("-") in manpages.
[wmaker-crm.git] / src / defaults.c
blob930d47c0769fb4ed6e8445a21a09432b9d1ae9a3
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
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.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 extern Cursor wCursor[WCUR_LAST];
152 static int getCursor();
153 static int setCursor();
156 * Tables to convert strings to enumeration values.
157 * Values stored are char
160 /* WARNING: sum of length of all value strings must not exceed
161 * this value */
162 #define TOTAL_VALUES_LENGTH 80
164 #define REFRESH_WINDOW_TEXTURES (1<<0)
165 #define REFRESH_MENU_TEXTURE (1<<1)
166 #define REFRESH_MENU_FONT (1<<2)
167 #define REFRESH_MENU_COLOR (1<<3)
168 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
169 #define REFRESH_MENU_TITLE_FONT (1<<5)
170 #define REFRESH_MENU_TITLE_COLOR (1<<6)
171 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
172 #define REFRESH_WINDOW_FONT (1<<8)
173 #define REFRESH_ICON_TILE (1<<9)
174 #define REFRESH_ICON_FONT (1<<10)
175 #define REFRESH_WORKSPACE_BACK (1<<11)
177 #define REFRESH_BUTTON_IMAGES (1<<12)
179 #define REFRESH_ICON_TITLE_COLOR (1<<13)
180 #define REFRESH_ICON_TITLE_BACK (1<<14)
182 static WOptionEnumeration seFocusModes[] = {
183 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
184 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
185 {NULL, 0, 0}
188 static WOptionEnumeration seColormapModes[] = {
189 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
190 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
191 {NULL, 0, 0}
194 static WOptionEnumeration sePlacements[] = {
195 {"Auto", WPM_AUTO, 0},
196 {"Smart", WPM_SMART, 0},
197 {"Cascade", WPM_CASCADE, 0},
198 {"Random", WPM_RANDOM, 0},
199 {"Manual", WPM_MANUAL, 0},
200 {NULL, 0, 0}
203 static WOptionEnumeration seGeomDisplays[] = {
204 {"None", WDIS_NONE, 0},
205 {"Center", WDIS_CENTER, 0},
206 {"Corner", WDIS_TOPLEFT, 0},
207 {"Floating", WDIS_FRAME_CENTER, 0},
208 {"Line", WDIS_NEW, 0},
209 {NULL, 0, 0}
212 static WOptionEnumeration seSpeeds[] = {
213 {"UltraFast", SPEED_ULTRAFAST, 0},
214 {"Fast", SPEED_FAST, 0},
215 {"Medium", SPEED_MEDIUM, 0},
216 {"Slow", SPEED_SLOW, 0},
217 {"UltraSlow", SPEED_ULTRASLOW, 0},
218 {NULL, 0, 0}
221 static WOptionEnumeration seMouseButtonActions[] = {
222 {"None", WA_NONE, 0},
223 {"SelectWindows", WA_SELECT_WINDOWS, 0},
224 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
225 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
226 {NULL, 0, 0}
229 static WOptionEnumeration seMouseWheelActions[] = {
230 {"None", WA_NONE, 0},
231 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
232 {NULL, 0, 0}
235 static WOptionEnumeration seIconificationStyles[] = {
236 {"Zoom", WIS_ZOOM, 0},
237 {"Twist", WIS_TWIST, 0},
238 {"Flip", WIS_FLIP, 0},
239 {"None", WIS_NONE, 0},
240 {"random", WIS_RANDOM, 0},
241 {NULL, 0, 0}
244 static WOptionEnumeration seJustifications[] = {
245 {"Left", WTJ_LEFT, 0},
246 {"Center", WTJ_CENTER, 0},
247 {"Right", WTJ_RIGHT, 0},
248 {NULL, 0, 0}
251 static WOptionEnumeration seIconPositions[] = {
252 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
253 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
254 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
255 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
256 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
257 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
258 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
259 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
260 {NULL, 0, 0}
263 static WOptionEnumeration seMenuStyles[] = {
264 {"normal", MS_NORMAL, 0},
265 {"singletexture", MS_SINGLE_TEXTURE, 0},
266 {"flat", MS_FLAT, 0},
267 {NULL, 0, 0}
270 static WOptionEnumeration seDisplayPositions[] = {
271 {"none", WD_NONE, 0},
272 {"center", WD_CENTER, 0},
273 {"top", WD_TOP, 0},
274 {"bottom", WD_BOTTOM, 0},
275 {"topleft", WD_TOPLEFT, 0},
276 {"topright", WD_TOPRIGHT, 0},
277 {"bottomleft", WD_BOTTOMLEFT, 0},
278 {"bottomright", WD_BOTTOMRIGHT, 0},
279 {NULL, 0, 0}
282 static WOptionEnumeration seWorkspaceBorder[] = {
283 {"None", WB_NONE, 0},
284 {"LeftRight", WB_LEFTRIGHT, 0},
285 {"TopBottom", WB_TOPBOTTOM, 0},
286 {"AllDirections", WB_ALLDIRS, 0},
287 {NULL, 0, 0}
291 * ALL entries in the tables bellow, NEED to have a default value
292 * defined, and this value needs to be correct.
295 /* these options will only affect the window manager on startup
297 * static defaults can't access the screen data, because it is
298 * created after these defaults are read
300 WDefaultEntry staticOptionList[] = {
302 {"ColormapSize", "4", NULL,
303 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
304 {"DisableDithering", "NO", NULL,
305 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
306 {"IconSize", "64", NULL,
307 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
308 {"ModifierKey", "Mod1", NULL,
309 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
310 {"DisableWSMouseActions", "NO", NULL,
311 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
312 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
313 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
314 {"NewStyle", "NO", NULL,
315 &wPreferences.new_style, getBool, NULL, NULL, NULL},
316 {"DisableDock", "NO", (void *)WM_DOCK,
317 NULL, getBool, setIfDockPresent, NULL, NULL},
318 {"DisableClip", "NO", (void *)WM_CLIP,
319 NULL, getBool, setIfDockPresent, NULL, NULL},
320 {"DisableMiniwindows", "NO", NULL,
321 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
324 WDefaultEntry optionList[] = {
326 /* dynamic options */
328 {"IconPosition", "blh", seIconPositions,
329 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
330 {"IconificationStyle", "Zoom", seIconificationStyles,
331 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
332 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
333 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
334 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
335 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
336 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
337 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
338 {"MouseWheelAction", "None", seMouseWheelActions,
339 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
340 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
341 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
342 {"IconPath", DEF_ICON_PATHS, NULL,
343 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
344 {"ColormapMode", "auto", seColormapModes,
345 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
346 {"AutoFocus", "NO", NULL,
347 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
348 {"RaiseDelay", "0", NULL,
349 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
350 {"CirculateRaise", "NO", NULL,
351 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
352 {"Superfluous", "NO", NULL,
353 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
354 {"AdvanceToNewWorkspace", "NO", NULL,
355 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
356 {"CycleWorkspaces", "NO", NULL,
357 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
358 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
359 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
360 {"WorkspaceBorder", "None", seWorkspaceBorder,
361 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
362 {"WorkspaceBorderSize", "0", NULL,
363 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
364 {"StickyIcons", "NO", NULL,
365 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
366 {"SaveSessionOnExit", "NO", NULL,
367 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
368 {"WrapMenus", "NO", NULL,
369 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
370 {"ScrollableMenus", "NO", NULL,
371 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
372 {"MenuScrollSpeed", "medium", seSpeeds,
373 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
374 {"IconSlideSpeed", "medium", seSpeeds,
375 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
376 {"ShadeSpeed", "medium", seSpeeds,
377 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
378 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
379 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
380 {"AlignSubmenus", "NO", NULL,
381 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
382 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
383 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
384 {"WindowPlacement", "auto", sePlacements,
385 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
386 {"IgnoreFocusClick", "NO", NULL,
387 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
388 {"UseSaveUnders", "NO", NULL,
389 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
390 {"OpaqueMove", "NO", NULL,
391 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
392 {"DisableAnimations", "NO", NULL,
393 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
394 {"DontLinkWorkspaces", "NO", NULL,
395 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
396 {"AutoArrangeIcons", "NO", NULL,
397 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
398 {"NoWindowOverDock", "NO", NULL,
399 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
400 {"NoWindowOverIcons", "NO", NULL,
401 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
402 {"WindowPlaceOrigin", "(0, 0)", NULL,
403 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
404 {"ResizeDisplay", "corner", seGeomDisplays,
405 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
406 {"MoveDisplay", "corner", seGeomDisplays,
407 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
408 {"DontConfirmKill", "NO", NULL,
409 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
410 {"WindowTitleBalloons", "NO", NULL,
411 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
412 {"MiniwindowTitleBalloons", "NO", NULL,
413 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
414 {"AppIconBalloons", "NO", NULL,
415 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
416 {"HelpBalloons", "NO", NULL,
417 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
418 {"EdgeResistance", "30", NULL,
419 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
420 {"ResizeIncrement", "32", NULL,
421 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
422 {"Attraction", "NO", NULL,
423 &wPreferences.attract, getBool, NULL, NULL, NULL},
424 {"DisableBlinking", "NO", NULL,
425 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
426 {"SingleClickLaunch", "NO", NULL,
427 &wPreferences.single_click, getBool, NULL, NULL, NULL},
429 /* style options */
431 {"MenuStyle", "normal", seMenuStyles,
432 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
433 {"WidgetColor", "(solid, gray)", NULL,
434 NULL, getTexture, setWidgetColor, NULL, NULL},
435 {"WorkspaceSpecificBack", "()", NULL,
436 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
437 /* WorkspaceBack must come after WorkspaceSpecificBack or
438 * WorkspaceBack wont know WorkspaceSpecificBack was also
439 * specified and 2 copies of wmsetbg will be launched */
440 {"WorkspaceBack", "(solid, black)", NULL,
441 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
442 {"SmoothWorkspaceBack", "NO", NULL,
443 NULL, getBool, NULL, NULL, NULL},
444 {"IconBack", "(solid, gray)", NULL,
445 NULL, getTexture, setIconTile, NULL, NULL},
446 {"TitleJustify", "center", seJustifications,
447 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
448 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
449 NULL, getFont, setWinTitleFont, NULL, NULL},
450 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
451 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
452 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
453 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
454 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
455 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
456 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
457 NULL, getFont, setMenuTitleFont, NULL, NULL},
458 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
459 NULL, getFont, setMenuTextFont, NULL, NULL},
460 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
461 NULL, getFont, setIconTitleFont, NULL, NULL},
462 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
463 NULL, getFont, setClipTitleFont, NULL, NULL},
464 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
465 NULL, getFont, setLargeDisplayFont, NULL, NULL},
466 {"HighlightColor", "white", NULL,
467 NULL, getColor, setHightlight, NULL, NULL},
468 {"HighlightTextColor", "black", NULL,
469 NULL, getColor, setHightlightText, NULL, NULL},
470 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
471 NULL, getColor, setClipTitleColor, NULL, NULL},
472 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
473 NULL, getColor, setClipTitleColor, NULL, NULL},
474 {"FTitleColor", "white", (void *)WS_FOCUSED,
475 NULL, getColor, setWTitleColor, NULL, NULL},
476 {"PTitleColor", "white", (void *)WS_PFOCUSED,
477 NULL, getColor, setWTitleColor, NULL, NULL},
478 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
479 NULL, getColor, setWTitleColor, NULL, NULL},
480 {"FTitleBack", "(solid, black)", NULL,
481 NULL, getTexture, setFTitleBack, NULL, NULL},
482 {"PTitleBack", "(solid, \"#616161\")", NULL,
483 NULL, getTexture, setPTitleBack, NULL, NULL},
484 {"UTitleBack", "(solid, gray)", NULL,
485 NULL, getTexture, setUTitleBack, NULL, NULL},
486 {"ResizebarBack", "(solid, gray)", NULL,
487 NULL, getTexture, setResizebarBack, NULL, NULL},
488 {"MenuTitleColor", "white", NULL,
489 NULL, getColor, setMenuTitleColor, NULL, NULL},
490 {"MenuTextColor", "black", NULL,
491 NULL, getColor, setMenuTextColor, NULL, NULL},
492 {"MenuDisabledColor", "\"#616161\"", NULL,
493 NULL, getColor, setMenuDisabledColor, NULL, NULL},
494 {"MenuTitleBack", "(solid, black)", NULL,
495 NULL, getTexture, setMenuTitleBack, NULL, NULL},
496 {"MenuTextBack", "(solid, gray)", NULL,
497 NULL, getTexture, setMenuTextBack, NULL, NULL},
498 {"IconTitleColor", "white", NULL,
499 NULL, getColor, setIconTitleColor, NULL, NULL},
500 {"IconTitleBack", "black", NULL,
501 NULL, getColor, setIconTitleBack, NULL, NULL},
502 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
503 NULL, getPropList, setSwPOptions, NULL, NULL},
505 /* keybindings */
507 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
508 NULL, getKeybind, setKeyGrab, NULL, NULL},
509 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
510 NULL, getKeybind, setKeyGrab, NULL, NULL},
511 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
512 NULL, getKeybind, setKeyGrab, NULL, NULL},
513 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
514 NULL, getKeybind, setKeyGrab, NULL, NULL},
515 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
516 NULL, getKeybind, setKeyGrab, NULL, NULL},
517 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
518 NULL, getKeybind, setKeyGrab, NULL, NULL},
519 {"HideKey", "None", (void *)WKBD_HIDE,
520 NULL, getKeybind, setKeyGrab, NULL, NULL},
521 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
522 NULL, getKeybind, setKeyGrab, NULL, NULL},
523 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
524 NULL, getKeybind, setKeyGrab, NULL, NULL},
525 {"CloseKey", "None", (void *)WKBD_CLOSE,
526 NULL, getKeybind, setKeyGrab, NULL, NULL},
527 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
528 NULL, getKeybind, setKeyGrab, NULL, NULL},
529 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
530 NULL, getKeybind, setKeyGrab, NULL, NULL},
531 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
532 NULL, getKeybind, setKeyGrab, NULL, NULL},
533 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
534 NULL, getKeybind, setKeyGrab, NULL, NULL},
535 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
536 NULL, getKeybind, setKeyGrab, NULL, NULL},
537 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
538 NULL, getKeybind, setKeyGrab, NULL, NULL},
539 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
540 NULL, getKeybind, setKeyGrab, NULL, NULL},
541 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
542 NULL, getKeybind, setKeyGrab, NULL, NULL},
543 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
544 NULL, getKeybind, setKeyGrab, NULL, NULL},
545 {"ShadeKey", "None", (void *)WKBD_SHADE,
546 NULL, getKeybind, setKeyGrab, NULL, NULL},
547 {"SelectKey", "None", (void *)WKBD_SELECT,
548 NULL, getKeybind, setKeyGrab, NULL, NULL},
549 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
550 NULL, getKeybind, setKeyGrab, NULL, NULL},
551 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
552 NULL, getKeybind, setKeyGrab, NULL, NULL},
553 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
554 NULL, getKeybind, setKeyGrab, NULL, NULL},
555 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
556 NULL, getKeybind, setKeyGrab, NULL, NULL},
557 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
558 NULL, getKeybind, setKeyGrab, NULL, NULL},
559 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
560 NULL, getKeybind, setKeyGrab, NULL, NULL},
561 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
562 NULL, getKeybind, setKeyGrab, NULL, NULL},
563 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
564 NULL, getKeybind, setKeyGrab, NULL, NULL},
565 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
566 NULL, getKeybind, setKeyGrab, NULL, NULL},
567 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
568 NULL, getKeybind, setKeyGrab, NULL, NULL},
569 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
570 NULL, getKeybind, setKeyGrab, NULL, NULL},
571 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
572 NULL, getKeybind, setKeyGrab, NULL, NULL},
573 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
574 NULL, getKeybind, setKeyGrab, NULL, NULL},
575 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
576 NULL, getKeybind, setKeyGrab, NULL, NULL},
577 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
578 NULL, getKeybind, setKeyGrab, NULL, NULL},
579 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
580 NULL, getKeybind, setKeyGrab, NULL, NULL},
581 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
582 NULL, getKeybind, setKeyGrab, NULL, NULL},
583 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
584 NULL, getKeybind, setKeyGrab, NULL, NULL},
585 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
586 NULL, getKeybind, setKeyGrab, NULL, NULL},
587 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
588 NULL, getKeybind, setKeyGrab, NULL, NULL},
589 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
590 NULL, getKeybind, setKeyGrab, NULL, NULL},
591 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
592 NULL, getKeybind, setKeyGrab, NULL, NULL},
593 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
594 NULL, getKeybind, setKeyGrab, NULL, NULL},
595 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
596 NULL, getKeybind, setKeyGrab, NULL, NULL},
597 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
598 NULL, getKeybind, setKeyGrab, NULL, NULL},
599 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
600 NULL, getKeybind, setKeyGrab, NULL, NULL},
601 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
602 NULL, getKeybind, setKeyGrab, NULL, NULL},
603 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
604 NULL, getKeybind, setKeyGrab, NULL, NULL},
605 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
606 NULL, getKeybind, setKeyGrab, NULL, NULL},
608 #ifdef KEEP_XKB_LOCK_STATUS
609 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
610 NULL, getKeybind, setKeyGrab, NULL, NULL},
611 {"KbdModeLock", "NO", NULL,
612 &wPreferences.modelock, getBool, NULL, NULL, NULL},
613 #endif /* KEEP_XKB_LOCK_STATUS */
615 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
616 NULL, getCursor, setCursor, NULL, NULL},
617 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
618 NULL, getCursor, setCursor, NULL, NULL},
619 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
620 NULL, getCursor, setCursor, NULL, NULL},
621 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
622 NULL, getCursor, setCursor, NULL, NULL},
623 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
624 NULL, getCursor, setCursor, NULL, NULL},
625 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
626 NULL, getCursor, setCursor, NULL, NULL},
627 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
628 NULL, getCursor, setCursor, NULL, NULL},
629 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
630 NULL, getCursor, setCursor, NULL, NULL},
631 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
632 NULL, getCursor, setCursor, NULL, NULL},
633 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
634 NULL, getCursor, setCursor, NULL, NULL},
635 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
636 NULL, getCursor, setCursor, NULL, NULL},
637 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
638 NULL, getCursor, setCursor, NULL, NULL},
639 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
640 NULL, getCursor, setCursor, NULL, NULL},
641 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
642 NULL, getCursor, setCursor, NULL, NULL},
643 {"DialogHistoryLines", "500", NULL,
644 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
645 {"CycleActiveHeadOnly", "NO", NULL,
646 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL}
649 static void initDefaults()
651 unsigned int i;
652 WDefaultEntry *entry;
654 WMPLSetCaseSensitive(False);
656 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
657 entry = &optionList[i];
659 entry->plkey = WMCreatePLString(entry->key);
660 if (entry->default_value)
661 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
662 else
663 entry->plvalue = NULL;
666 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
667 entry = &staticOptionList[i];
669 entry->plkey = WMCreatePLString(entry->key);
670 if (entry->default_value)
671 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
672 else
673 entry->plvalue = NULL;
677 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
679 WMPropList *globalDict = NULL;
680 char path[PATH_MAX];
681 struct stat stbuf;
683 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
684 if (stat(path, &stbuf) >= 0) {
685 globalDict = WMReadPropListFromFile(path);
686 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
687 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
688 WMReleasePropList(globalDict);
689 globalDict = NULL;
690 } else if (!globalDict) {
691 wwarning(_("could not load domain %s from global defaults database"), domainName);
695 return globalDict;
698 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
699 static void prependMenu(WMPropList * destarr, WMPropList * array)
701 WMPropList *item;
702 int i;
704 for (i = 0; i < WMGetPropListItemCount(array); i++) {
705 item = WMGetFromPLArray(array, i);
706 if (item)
707 WMInsertInPLArray(destarr, i + 1, item);
711 static void appendMenu(WMPropList * destarr, WMPropList * array)
713 WMPropList *item;
714 int i;
716 for (i = 0; i < WMGetPropListItemCount(array); i++) {
717 item = WMGetFromPLArray(array, i);
718 if (item)
719 WMAddToPLArray(destarr, item);
722 #endif
724 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
726 WMPropList *menu = menuDomain->dictionary;
727 WMPropList *submenu;
729 if (!menu || !WMIsPLArray(menu))
730 return;
732 #ifdef GLOBAL_PREAMBLE_MENU_FILE
733 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
735 if (submenu && !WMIsPLArray(submenu)) {
736 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
737 WMReleasePropList(submenu);
738 submenu = NULL;
740 if (submenu) {
741 prependMenu(menu, submenu);
742 WMReleasePropList(submenu);
744 #endif
746 #ifdef GLOBAL_EPILOGUE_MENU_FILE
747 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
749 if (submenu && !WMIsPLArray(submenu)) {
750 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
751 WMReleasePropList(submenu);
752 submenu = NULL;
754 if (submenu) {
755 appendMenu(menu, submenu);
756 WMReleasePropList(submenu);
758 #endif
760 menuDomain->dictionary = menu;
763 void wDefaultsDestroyDomain(WDDomain * domain)
765 if (domain->dictionary)
766 WMReleasePropList(domain->dictionary);
767 wfree(domain->path);
768 wfree(domain);
771 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
773 WDDomain *db;
774 struct stat stbuf;
775 static int inited = 0;
776 char path[PATH_MAX];
777 char *the_path;
778 WMPropList *shared_dict = NULL;
780 if (!inited) {
781 inited = 1;
782 initDefaults();
785 db = wmalloc(sizeof(WDDomain));
786 memset(db, 0, sizeof(WDDomain));
787 db->domain_name = domain;
788 db->path = wdefaultspathfordomain(domain);
789 the_path = db->path;
791 if (the_path && stat(the_path, &stbuf) >= 0) {
792 db->dictionary = WMReadPropListFromFile(the_path);
793 if (db->dictionary) {
794 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
795 WMReleasePropList(db->dictionary);
796 db->dictionary = NULL;
797 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
799 db->timestamp = stbuf.st_mtime;
800 } else {
801 wwarning(_("could not load domain %s from user defaults database"), domain);
805 /* global system dictionary */
806 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
807 if (stat(path, &stbuf) >= 0) {
808 shared_dict = WMReadPropListFromFile(path);
809 if (shared_dict) {
810 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
811 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
812 domain, path);
813 WMReleasePropList(shared_dict);
814 shared_dict = NULL;
815 } else {
816 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
817 WMIsPLDictionary(db->dictionary)) {
818 WMMergePLDictionaries(shared_dict, db->dictionary, True);
819 WMReleasePropList(db->dictionary);
820 db->dictionary = shared_dict;
821 if (stbuf.st_mtime > db->timestamp)
822 db->timestamp = stbuf.st_mtime;
823 } else if (!db->dictionary) {
824 db->dictionary = shared_dict;
825 if (stbuf.st_mtime > db->timestamp)
826 db->timestamp = stbuf.st_mtime;
829 } else {
830 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
834 return db;
837 void wReadStaticDefaults(WMPropList * dict)
839 WMPropList *plvalue;
840 WDefaultEntry *entry;
841 unsigned int i;
842 void *tdata;
844 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
845 entry = &staticOptionList[i];
847 if (dict)
848 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
849 else
850 plvalue = NULL;
852 if (!plvalue) {
853 /* no default in the DB. Use builtin default */
854 plvalue = entry->plvalue;
857 if (plvalue) {
858 /* convert data */
859 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
860 if (entry->update) {
861 (*entry->update) (NULL, entry, tdata, entry->extra_data);
867 void wDefaultsCheckDomains(void* arg)
869 WScreen *scr;
870 struct stat stbuf;
871 WMPropList *shared_dict = NULL;
872 WMPropList *dict;
873 int i;
875 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
876 WDWindowMaker->timestamp = stbuf.st_mtime;
878 /* global dictionary */
879 shared_dict = readGlobalDomain("WindowMaker", True);
880 /* user dictionary */
881 dict = WMReadPropListFromFile(WDWindowMaker->path);
882 if (dict) {
883 if (!WMIsPLDictionary(dict)) {
884 WMReleasePropList(dict);
885 dict = NULL;
886 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
887 "WindowMaker", WDWindowMaker->path);
888 } else {
889 if (shared_dict) {
890 WMMergePLDictionaries(shared_dict, dict, True);
891 WMReleasePropList(dict);
892 dict = shared_dict;
893 shared_dict = NULL;
895 for (i = 0; i < wScreenCount; i++) {
896 scr = wScreenWithNumber(i);
897 if (scr)
898 wReadDefaults(scr, dict);
900 if (WDWindowMaker->dictionary) {
901 WMReleasePropList(WDWindowMaker->dictionary);
903 WDWindowMaker->dictionary = dict;
905 } else {
906 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
908 if (shared_dict) {
909 WMReleasePropList(shared_dict);
913 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
914 /* global dictionary */
915 shared_dict = readGlobalDomain("WMWindowAttributes", True);
916 /* user dictionary */
917 dict = WMReadPropListFromFile(WDWindowAttributes->path);
918 if (dict) {
919 if (!WMIsPLDictionary(dict)) {
920 WMReleasePropList(dict);
921 dict = NULL;
922 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
923 "WMWindowAttributes", WDWindowAttributes->path);
924 } else {
925 if (shared_dict) {
926 WMMergePLDictionaries(shared_dict, dict, True);
927 WMReleasePropList(dict);
928 dict = shared_dict;
929 shared_dict = NULL;
931 if (WDWindowAttributes->dictionary) {
932 WMReleasePropList(WDWindowAttributes->dictionary);
934 WDWindowAttributes->dictionary = dict;
935 for (i = 0; i < wScreenCount; i++) {
936 scr = wScreenWithNumber(i);
937 if (scr) {
938 RImage *image;
940 wDefaultUpdateIcons(scr);
942 /* Update the panel image if changed */
943 /* Don't worry. If the image is the same these
944 * functions will have no performance impact. */
945 image = wDefaultGetImage(scr, "Logo", "WMPanel");
947 if (!image) {
948 wwarning(_("could not load logo image for panels: %s"),
949 RMessageForError(RErrorCode));
950 } else {
951 WMSetApplicationIconImage(scr->wmscreen, image);
952 RReleaseImage(image);
957 } else {
958 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
960 WDWindowAttributes->timestamp = stbuf.st_mtime;
961 if (shared_dict) {
962 WMReleasePropList(shared_dict);
966 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
967 dict = WMReadPropListFromFile(WDRootMenu->path);
968 if (dict) {
969 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
970 WMReleasePropList(dict);
971 dict = NULL;
972 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
973 "WMRootMenu", WDRootMenu->path);
974 } else {
975 if (WDRootMenu->dictionary) {
976 WMReleasePropList(WDRootMenu->dictionary);
978 WDRootMenu->dictionary = dict;
979 wDefaultsMergeGlobalMenus(WDRootMenu);
981 } else {
982 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
984 WDRootMenu->timestamp = stbuf.st_mtime;
986 #ifndef HAVE_INOTIFY
987 if (!arg)
988 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
989 #endif
992 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
994 WMPropList *plvalue, *old_value;
995 WDefaultEntry *entry;
996 unsigned int i, must_update;
997 int update_workspace_back = 0; /* kluge :/ */
998 unsigned int needs_refresh;
999 void *tdata;
1000 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1002 must_update = 0;
1004 needs_refresh = 0;
1006 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1007 entry = &optionList[i];
1009 if (new_dict)
1010 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1011 else
1012 plvalue = NULL;
1014 if (!old_dict)
1015 old_value = NULL;
1016 else
1017 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1019 if (!plvalue && !old_value) {
1020 /* no default in the DB. Use builtin default */
1021 plvalue = entry->plvalue;
1022 if (plvalue && new_dict) {
1023 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1024 must_update = 1;
1026 } else if (!plvalue) {
1027 /* value was deleted from DB. Keep current value */
1028 continue;
1029 } else if (!old_value) {
1030 /* set value for the 1st time */
1031 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1032 /* value has changed */
1033 } else {
1035 if (strcmp(entry->key, "WorkspaceBack") == 0
1036 && update_workspace_back && scr->flags.backimage_helper_launched) {
1037 } else {
1038 /* value was not changed since last time */
1039 continue;
1043 if (plvalue) {
1044 /* convert data */
1045 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1047 * If the WorkspaceSpecificBack data has been changed
1048 * so that the helper will be launched now, we must be
1049 * sure to send the default background texture config
1050 * to the helper.
1052 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1053 && !scr->flags.backimage_helper_launched) {
1054 update_workspace_back = 1;
1056 if (entry->update) {
1057 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1063 if (needs_refresh != 0 && !scr->flags.startup) {
1064 int foo;
1066 foo = 0;
1067 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1068 foo |= WTextureSettings;
1069 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1070 foo |= WFontSettings;
1071 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1072 foo |= WColorSettings;
1073 if (foo)
1074 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1075 (void *)(uintptr_t) foo);
1077 foo = 0;
1078 if (needs_refresh & REFRESH_MENU_TEXTURE)
1079 foo |= WTextureSettings;
1080 if (needs_refresh & REFRESH_MENU_FONT)
1081 foo |= WFontSettings;
1082 if (needs_refresh & REFRESH_MENU_COLOR)
1083 foo |= WColorSettings;
1084 if (foo)
1085 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1087 foo = 0;
1088 if (needs_refresh & REFRESH_WINDOW_FONT) {
1089 foo |= WFontSettings;
1091 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1092 foo |= WTextureSettings;
1094 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1095 foo |= WColorSettings;
1097 if (foo)
1098 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1100 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1101 foo = 0;
1102 if (needs_refresh & REFRESH_ICON_FONT) {
1103 foo |= WFontSettings;
1105 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1106 foo |= WTextureSettings;
1108 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1109 foo |= WTextureSettings;
1111 if (foo)
1112 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1113 (void *)(uintptr_t) foo);
1115 if (needs_refresh & REFRESH_ICON_TILE)
1116 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1120 void wDefaultUpdateIcons(WScreen * scr)
1122 WAppIcon *aicon = scr->app_icon_list;
1123 WWindow *wwin = scr->focused_window;
1124 char *file;
1126 while (aicon) {
1127 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1128 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1129 || (file && !aicon->icon->file)) {
1130 RImage *new_image;
1132 if (aicon->icon->file)
1133 wfree(aicon->icon->file);
1134 aicon->icon->file = wstrdup(file);
1136 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1137 if (new_image) {
1138 wIconChangeImage(aicon->icon, new_image);
1139 wAppIconPaint(aicon);
1142 aicon = aicon->next;
1145 if (!wPreferences.flags.noclip)
1146 wClipIconPaint(scr->clip_icon);
1148 while (wwin) {
1149 if (wwin->icon && wwin->flags.miniaturized) {
1150 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1151 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1152 || (file && !wwin->icon->file)) {
1153 RImage *new_image;
1155 if (wwin->icon->file)
1156 wfree(wwin->icon->file);
1157 wwin->icon->file = wstrdup(file);
1159 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1160 if (new_image)
1161 wIconChangeImage(wwin->icon, new_image);
1164 wwin = wwin->prev;
1168 /* --------------------------- Local ----------------------- */
1170 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1171 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1172 entry->key, x); \
1173 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1174 var = entry->default_value;\
1175 } else var = WMGetFromPLString(value)\
1178 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1180 char *str;
1181 WOptionEnumeration *v;
1182 char buffer[TOTAL_VALUES_LENGTH];
1184 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1185 for (v = values; v->string != NULL; v++) {
1186 if (strcasecmp(v->string, str) == 0)
1187 return v->value;
1191 buffer[0] = 0;
1192 for (v = values; v->string != NULL; v++) {
1193 if (!v->is_alias) {
1194 if (buffer[0] != 0)
1195 strcat(buffer, ", ");
1196 strcat(buffer, v->string);
1199 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1201 if (def) {
1202 return string2index(key, val, NULL, values);
1205 return -1;
1209 * value - is the value in the defaults DB
1210 * addr - is the address to store the data
1211 * ret - is the address to store a pointer to a temporary buffer. ret
1212 * must not be freed and is used by the set functions
1214 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1216 static char data;
1217 char *val;
1218 int second_pass = 0;
1220 GET_STRING_OR_DEFAULT("Boolean", val);
1222 again:
1223 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1224 || strcasecmp(val, "YES") == 0) {
1226 data = 1;
1227 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1228 || strcasecmp(val, "NO") == 0) {
1229 data = 0;
1230 } else {
1231 int i;
1232 if (sscanf(val, "%i", &i) == 1) {
1233 if (i != 0)
1234 data = 1;
1235 else
1236 data = 0;
1237 } else {
1238 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1239 if (second_pass == 0) {
1240 val = WMGetFromPLString(entry->plvalue);
1241 second_pass = 1;
1242 wwarning(_("using default \"%s\" instead"), val);
1243 goto again;
1245 return False;
1249 if (ret)
1250 *ret = &data;
1251 if (addr)
1252 *(char *)addr = data;
1254 return True;
1257 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1259 static int data;
1260 char *val;
1262 GET_STRING_OR_DEFAULT("Integer", val);
1264 if (sscanf(val, "%i", &data) != 1) {
1265 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1266 val = WMGetFromPLString(entry->plvalue);
1267 wwarning(_("using default \"%s\" instead"), val);
1268 if (sscanf(val, "%i", &data) != 1) {
1269 return False;
1273 if (ret)
1274 *ret = &data;
1275 if (addr)
1276 *(int *)addr = data;
1278 return True;
1281 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1283 static WCoord data;
1284 char *val_x, *val_y;
1285 int nelem, changed = 0;
1286 WMPropList *elem_x, *elem_y;
1288 again:
1289 if (!WMIsPLArray(value)) {
1290 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1291 if (changed == 0) {
1292 value = entry->plvalue;
1293 changed = 1;
1294 wwarning(_("using default \"%s\" instead"), entry->default_value);
1295 goto again;
1297 return False;
1300 nelem = WMGetPropListItemCount(value);
1301 if (nelem != 2) {
1302 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
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 elem_x = WMGetFromPLArray(value, 0);
1313 elem_y = WMGetFromPLArray(value, 1);
1315 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1316 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1317 if (changed == 0) {
1318 value = entry->plvalue;
1319 changed = 1;
1320 wwarning(_("using default \"%s\" instead"), entry->default_value);
1321 goto again;
1323 return False;
1326 val_x = WMGetFromPLString(elem_x);
1327 val_y = WMGetFromPLString(elem_y);
1329 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1330 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1331 if (changed == 0) {
1332 value = entry->plvalue;
1333 changed = 1;
1334 wwarning(_("using default \"%s\" instead"), entry->default_value);
1335 goto again;
1337 return False;
1340 if (data.x < 0)
1341 data.x = 0;
1342 else if (data.x > scr->scr_width / 3)
1343 data.x = scr->scr_width / 3;
1344 if (data.y < 0)
1345 data.y = 0;
1346 else if (data.y > scr->scr_height / 3)
1347 data.y = scr->scr_height / 3;
1349 if (ret)
1350 *ret = &data;
1351 if (addr)
1352 *(WCoord *) addr = data;
1354 return True;
1357 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1359 WMRetainPropList(value);
1361 *ret = value;
1363 return True;
1366 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1368 static char *data;
1369 int i, count, len;
1370 char *ptr;
1371 WMPropList *d;
1372 int changed = 0;
1374 again:
1375 if (!WMIsPLArray(value)) {
1376 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1377 if (changed == 0) {
1378 value = entry->plvalue;
1379 changed = 1;
1380 wwarning(_("using default \"%s\" instead"), entry->default_value);
1381 goto again;
1383 return False;
1386 i = 0;
1387 count = WMGetPropListItemCount(value);
1388 if (count < 1) {
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 len = 0;
1399 for (i = 0; i < count; i++) {
1400 d = WMGetFromPLArray(value, i);
1401 if (!d || !WMIsPLString(d)) {
1402 count = i;
1403 break;
1405 len += strlen(WMGetFromPLString(d)) + 1;
1408 ptr = data = wmalloc(len + 1);
1410 for (i = 0; i < count; i++) {
1411 d = WMGetFromPLArray(value, i);
1412 if (!d || !WMIsPLString(d)) {
1413 break;
1415 strcpy(ptr, WMGetFromPLString(d));
1416 ptr += strlen(WMGetFromPLString(d));
1417 *ptr = ':';
1418 ptr++;
1420 ptr--;
1421 *(ptr--) = 0;
1423 if (*(char **)addr != NULL) {
1424 wfree(*(char **)addr);
1426 *(char **)addr = data;
1428 return True;
1431 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1433 static signed char data;
1435 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1436 if (data < 0)
1437 return False;
1439 if (ret)
1440 *ret = &data;
1441 if (addr)
1442 *(signed char *)addr = data;
1444 return True;
1448 * (solid <color>)
1449 * (hgradient <color> <color>)
1450 * (vgradient <color> <color>)
1451 * (dgradient <color> <color>)
1452 * (mhgradient <color> <color> ...)
1453 * (mvgradient <color> <color> ...)
1454 * (mdgradient <color> <color> ...)
1455 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1456 * (tpixmap <file> <color>)
1457 * (spixmap <file> <color>)
1458 * (cpixmap <file> <color>)
1459 * (thgradient <file> <opaqueness> <color> <color>)
1460 * (tvgradient <file> <opaqueness> <color> <color>)
1461 * (tdgradient <file> <opaqueness> <color> <color>)
1462 * (function <lib> <function> ...)
1465 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1467 WMPropList *elem;
1468 char *val;
1469 int nelem;
1470 WTexture *texture = NULL;
1472 nelem = WMGetPropListItemCount(pl);
1473 if (nelem < 1)
1474 return NULL;
1476 elem = WMGetFromPLArray(pl, 0);
1477 if (!elem || !WMIsPLString(elem))
1478 return NULL;
1479 val = WMGetFromPLString(elem);
1481 if (strcasecmp(val, "solid") == 0) {
1482 XColor color;
1484 if (nelem != 2)
1485 return NULL;
1487 /* get color */
1489 elem = WMGetFromPLArray(pl, 1);
1490 if (!elem || !WMIsPLString(elem))
1491 return NULL;
1492 val = WMGetFromPLString(elem);
1494 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1495 wwarning(_("\"%s\" is not a valid color name"), val);
1496 return NULL;
1499 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1500 } else if (strcasecmp(val, "dgradient") == 0
1501 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1502 RColor color1, color2;
1503 XColor xcolor;
1504 int type;
1506 if (nelem != 3) {
1507 wwarning(_("bad number of arguments in gradient specification"));
1508 return NULL;
1511 if (val[0] == 'd' || val[0] == 'D')
1512 type = WTEX_DGRADIENT;
1513 else if (val[0] == 'h' || val[0] == 'H')
1514 type = WTEX_HGRADIENT;
1515 else
1516 type = WTEX_VGRADIENT;
1518 /* get from color */
1519 elem = WMGetFromPLArray(pl, 1);
1520 if (!elem || !WMIsPLString(elem))
1521 return NULL;
1522 val = WMGetFromPLString(elem);
1524 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1525 wwarning(_("\"%s\" is not a valid color name"), val);
1526 return NULL;
1528 color1.alpha = 255;
1529 color1.red = xcolor.red >> 8;
1530 color1.green = xcolor.green >> 8;
1531 color1.blue = xcolor.blue >> 8;
1533 /* get to color */
1534 elem = WMGetFromPLArray(pl, 2);
1535 if (!elem || !WMIsPLString(elem)) {
1536 return NULL;
1538 val = WMGetFromPLString(elem);
1540 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1541 wwarning(_("\"%s\" is not a valid color name"), val);
1542 return NULL;
1544 color2.alpha = 255;
1545 color2.red = xcolor.red >> 8;
1546 color2.green = xcolor.green >> 8;
1547 color2.blue = xcolor.blue >> 8;
1549 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1551 } else if (strcasecmp(val, "igradient") == 0) {
1552 RColor colors1[2], colors2[2];
1553 int th1, th2;
1554 XColor xcolor;
1555 int i;
1557 if (nelem != 7) {
1558 wwarning(_("bad number of arguments in gradient specification"));
1559 return NULL;
1562 /* get from color */
1563 for (i = 0; i < 2; i++) {
1564 elem = WMGetFromPLArray(pl, 1 + i);
1565 if (!elem || !WMIsPLString(elem))
1566 return NULL;
1567 val = WMGetFromPLString(elem);
1569 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1570 wwarning(_("\"%s\" is not a valid color name"), val);
1571 return NULL;
1573 colors1[i].alpha = 255;
1574 colors1[i].red = xcolor.red >> 8;
1575 colors1[i].green = xcolor.green >> 8;
1576 colors1[i].blue = xcolor.blue >> 8;
1578 elem = WMGetFromPLArray(pl, 3);
1579 if (!elem || !WMIsPLString(elem))
1580 return NULL;
1581 val = WMGetFromPLString(elem);
1582 th1 = atoi(val);
1584 /* get from color */
1585 for (i = 0; i < 2; i++) {
1586 elem = WMGetFromPLArray(pl, 4 + i);
1587 if (!elem || !WMIsPLString(elem))
1588 return NULL;
1589 val = WMGetFromPLString(elem);
1591 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1592 wwarning(_("\"%s\" is not a valid color name"), val);
1593 return NULL;
1595 colors2[i].alpha = 255;
1596 colors2[i].red = xcolor.red >> 8;
1597 colors2[i].green = xcolor.green >> 8;
1598 colors2[i].blue = xcolor.blue >> 8;
1600 elem = WMGetFromPLArray(pl, 6);
1601 if (!elem || !WMIsPLString(elem))
1602 return NULL;
1603 val = WMGetFromPLString(elem);
1604 th2 = atoi(val);
1606 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1608 } else if (strcasecmp(val, "mhgradient") == 0
1609 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1610 XColor color;
1611 RColor **colors;
1612 int i, count;
1613 int type;
1615 if (nelem < 3) {
1616 wwarning(_("too few arguments in multicolor gradient specification"));
1617 return NULL;
1620 if (val[1] == 'h' || val[1] == 'H')
1621 type = WTEX_MHGRADIENT;
1622 else if (val[1] == 'v' || val[1] == 'V')
1623 type = WTEX_MVGRADIENT;
1624 else
1625 type = WTEX_MDGRADIENT;
1627 count = nelem - 1;
1629 colors = wmalloc(sizeof(RColor *) * (count + 1));
1631 for (i = 0; i < count; i++) {
1632 elem = WMGetFromPLArray(pl, i + 1);
1633 if (!elem || !WMIsPLString(elem)) {
1634 for (--i; i >= 0; --i) {
1635 wfree(colors[i]);
1637 wfree(colors);
1638 return NULL;
1640 val = WMGetFromPLString(elem);
1642 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1643 wwarning(_("\"%s\" is not a valid color name"), val);
1644 for (--i; i >= 0; --i) {
1645 wfree(colors[i]);
1647 wfree(colors);
1648 return NULL;
1649 } else {
1650 colors[i] = wmalloc(sizeof(RColor));
1651 colors[i]->red = color.red >> 8;
1652 colors[i]->green = color.green >> 8;
1653 colors[i]->blue = color.blue >> 8;
1656 colors[i] = NULL;
1658 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1659 } else if (strcasecmp(val, "spixmap") == 0 ||
1660 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1661 XColor color;
1662 int type;
1664 if (nelem != 3)
1665 return NULL;
1667 if (val[0] == 's' || val[0] == 'S')
1668 type = WTP_SCALE;
1669 else if (val[0] == 'c' || val[0] == 'C')
1670 type = WTP_CENTER;
1671 else
1672 type = WTP_TILE;
1674 /* get color */
1675 elem = WMGetFromPLArray(pl, 2);
1676 if (!elem || !WMIsPLString(elem)) {
1677 return NULL;
1679 val = WMGetFromPLString(elem);
1681 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1682 wwarning(_("\"%s\" is not a valid color name"), val);
1683 return NULL;
1686 /* file name */
1687 elem = WMGetFromPLArray(pl, 1);
1688 if (!elem || !WMIsPLString(elem))
1689 return NULL;
1690 val = WMGetFromPLString(elem);
1692 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1693 } else if (strcasecmp(val, "thgradient") == 0
1694 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1695 RColor color1, color2;
1696 XColor xcolor;
1697 int opacity;
1698 int style;
1700 if (val[1] == 'h' || val[1] == 'H')
1701 style = WTEX_THGRADIENT;
1702 else if (val[1] == 'v' || val[1] == 'V')
1703 style = WTEX_TVGRADIENT;
1704 else
1705 style = WTEX_TDGRADIENT;
1707 if (nelem != 5) {
1708 wwarning(_("bad number of arguments in textured gradient specification"));
1709 return NULL;
1712 /* get from color */
1713 elem = WMGetFromPLArray(pl, 3);
1714 if (!elem || !WMIsPLString(elem))
1715 return NULL;
1716 val = WMGetFromPLString(elem);
1718 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1719 wwarning(_("\"%s\" is not a valid color name"), val);
1720 return NULL;
1722 color1.alpha = 255;
1723 color1.red = xcolor.red >> 8;
1724 color1.green = xcolor.green >> 8;
1725 color1.blue = xcolor.blue >> 8;
1727 /* get to color */
1728 elem = WMGetFromPLArray(pl, 4);
1729 if (!elem || !WMIsPLString(elem)) {
1730 return NULL;
1732 val = WMGetFromPLString(elem);
1734 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1735 wwarning(_("\"%s\" is not a valid color name"), val);
1736 return NULL;
1738 color2.alpha = 255;
1739 color2.red = xcolor.red >> 8;
1740 color2.green = xcolor.green >> 8;
1741 color2.blue = xcolor.blue >> 8;
1743 /* get opacity */
1744 elem = WMGetFromPLArray(pl, 2);
1745 if (!elem || !WMIsPLString(elem))
1746 opacity = 128;
1747 else
1748 val = WMGetFromPLString(elem);
1750 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1751 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1752 opacity = 128;
1755 /* get file name */
1756 elem = WMGetFromPLArray(pl, 1);
1757 if (!elem || !WMIsPLString(elem))
1758 return NULL;
1759 val = WMGetFromPLString(elem);
1761 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1762 } else if (strcasecmp(val, "function") == 0) {
1763 /* Leave this in to handle the unlikely case of
1764 * someone actually having function textures configured */
1765 wwarning("function texture support has been removed");
1766 return NULL;
1767 } else {
1768 wwarning(_("invalid texture type %s"), val);
1769 return NULL;
1771 return texture;
1774 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1776 static WTexture *texture;
1777 int changed = 0;
1779 again:
1780 if (!WMIsPLArray(value)) {
1781 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1782 if (changed == 0) {
1783 value = entry->plvalue;
1784 changed = 1;
1785 wwarning(_("using default \"%s\" instead"), entry->default_value);
1786 goto again;
1788 return False;
1791 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1792 WMPropList *pl;
1794 pl = WMGetFromPLArray(value, 0);
1795 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1796 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1797 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1798 entry->key, "Solid Texture");
1800 value = entry->plvalue;
1801 changed = 1;
1802 wwarning(_("using default \"%s\" instead"), entry->default_value);
1803 goto again;
1807 texture = parse_texture(scr, value);
1809 if (!texture) {
1810 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1811 if (changed == 0) {
1812 value = entry->plvalue;
1813 changed = 1;
1814 wwarning(_("using default \"%s\" instead"), entry->default_value);
1815 goto again;
1817 return False;
1820 if (ret)
1821 *ret = &texture;
1823 if (addr)
1824 *(WTexture **) addr = texture;
1826 return True;
1829 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1831 WMPropList *elem;
1832 int changed = 0;
1833 char *val;
1834 int nelem;
1836 again:
1837 if (!WMIsPLArray(value)) {
1838 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1839 "WorkspaceBack", "Texture or None");
1840 if (changed == 0) {
1841 value = entry->plvalue;
1842 changed = 1;
1843 wwarning(_("using default \"%s\" instead"), entry->default_value);
1844 goto again;
1846 return False;
1849 /* only do basic error checking and verify for None texture */
1851 nelem = WMGetPropListItemCount(value);
1852 if (nelem > 0) {
1853 elem = WMGetFromPLArray(value, 0);
1854 if (!elem || !WMIsPLString(elem)) {
1855 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1856 if (changed == 0) {
1857 value = entry->plvalue;
1858 changed = 1;
1859 wwarning(_("using default \"%s\" instead"), entry->default_value);
1860 goto again;
1862 return False;
1864 val = WMGetFromPLString(elem);
1866 if (strcasecmp(val, "None") == 0)
1867 return True;
1869 *ret = WMRetainPropList(value);
1871 return True;
1874 static int
1875 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1877 WMPropList *elem;
1878 int nelem;
1879 int changed = 0;
1881 again:
1882 if (!WMIsPLArray(value)) {
1883 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1884 "WorkspaceSpecificBack", "an array of textures");
1885 if (changed == 0) {
1886 value = entry->plvalue;
1887 changed = 1;
1888 wwarning(_("using default \"%s\" instead"), entry->default_value);
1889 goto again;
1891 return False;
1894 /* only do basic error checking and verify for None texture */
1896 nelem = WMGetPropListItemCount(value);
1897 if (nelem > 0) {
1898 while (nelem--) {
1899 elem = WMGetFromPLArray(value, nelem);
1900 if (!elem || !WMIsPLArray(elem)) {
1901 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1902 nelem);
1907 *ret = WMRetainPropList(value);
1909 #ifdef notworking
1911 * Kluge to force wmsetbg helper to set the default background.
1912 * If the WorkspaceSpecificBack is changed once wmaker has started,
1913 * the WorkspaceBack won't be sent to the helper, unless the user
1914 * changes it's value too. So, we must force this by removing the
1915 * value from the defaults DB.
1917 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1918 WMPropList *key = WMCreatePLString("WorkspaceBack");
1920 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1922 WMReleasePropList(key);
1924 #endif
1925 return True;
1928 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1930 static WMFont *font;
1931 char *val;
1933 GET_STRING_OR_DEFAULT("Font", val);
1935 font = WMCreateFont(scr->wmscreen, val);
1936 if (!font)
1937 font = WMCreateFont(scr->wmscreen, "fixed");
1939 if (!font) {
1940 wfatal(_("could not load any usable font!!!"));
1941 exit(1);
1944 if (ret)
1945 *ret = font;
1947 /* can't assign font value outside update function */
1948 wassertrv(addr == NULL, True);
1950 return True;
1953 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1955 static XColor color;
1956 char *val;
1957 int second_pass = 0;
1959 GET_STRING_OR_DEFAULT("Color", val);
1961 again:
1962 if (!wGetColor(scr, val, &color)) {
1963 wwarning(_("could not get color for key \"%s\""), entry->key);
1964 if (second_pass == 0) {
1965 val = WMGetFromPLString(entry->plvalue);
1966 second_pass = 1;
1967 wwarning(_("using default \"%s\" instead"), val);
1968 goto again;
1970 return False;
1973 if (ret)
1974 *ret = &color;
1976 assert(addr == NULL);
1978 if (addr)
1979 *(unsigned long*)addr = pixel;
1982 return True;
1985 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1987 static WShortKey shortcut;
1988 KeySym ksym;
1989 char *val;
1990 char *k;
1991 char buf[MAX_SHORTCUT_LENGTH], *b;
1993 GET_STRING_OR_DEFAULT("Key spec", val);
1995 if (!val || strcasecmp(val, "NONE") == 0) {
1996 shortcut.keycode = 0;
1997 shortcut.modifier = 0;
1998 if (ret)
1999 *ret = &shortcut;
2000 return True;
2003 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2005 b = (char *)buf;
2007 /* get modifiers */
2008 shortcut.modifier = 0;
2009 while ((k = strchr(b, '+')) != NULL) {
2010 int mod;
2012 *k = 0;
2013 mod = wXModifierFromKey(b);
2014 if (mod < 0) {
2015 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2016 return False;
2018 shortcut.modifier |= mod;
2020 b = k + 1;
2023 /* get key */
2024 ksym = XStringToKeysym(b);
2026 if (ksym == NoSymbol) {
2027 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2028 return False;
2031 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2032 if (shortcut.keycode == 0) {
2033 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2034 return False;
2037 if (ret)
2038 *ret = &shortcut;
2040 return True;
2043 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2045 static int mask;
2046 char *str;
2048 GET_STRING_OR_DEFAULT("Modifier Key", str);
2050 if (!str)
2051 return False;
2053 mask = wXModifierFromKey(str);
2054 if (mask < 0) {
2055 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2056 mask = 0;
2057 return False;
2060 if (addr)
2061 *(int *)addr = mask;
2063 if (ret)
2064 *ret = &mask;
2066 return True;
2069 # include <X11/cursorfont.h>
2070 typedef struct {
2071 char *name;
2072 int id;
2073 } WCursorLookup;
2075 #define CURSOR_ID_NONE (XC_num_glyphs)
2077 static WCursorLookup cursor_table[] = {
2078 {"X_cursor", XC_X_cursor},
2079 {"arrow", XC_arrow},
2080 {"based_arrow_down", XC_based_arrow_down},
2081 {"based_arrow_up", XC_based_arrow_up},
2082 {"boat", XC_boat},
2083 {"bogosity", XC_bogosity},
2084 {"bottom_left_corner", XC_bottom_left_corner},
2085 {"bottom_right_corner", XC_bottom_right_corner},
2086 {"bottom_side", XC_bottom_side},
2087 {"bottom_tee", XC_bottom_tee},
2088 {"box_spiral", XC_box_spiral},
2089 {"center_ptr", XC_center_ptr},
2090 {"circle", XC_circle},
2091 {"clock", XC_clock},
2092 {"coffee_mug", XC_coffee_mug},
2093 {"cross", XC_cross},
2094 {"cross_reverse", XC_cross_reverse},
2095 {"crosshair", XC_crosshair},
2096 {"diamond_cross", XC_diamond_cross},
2097 {"dot", XC_dot},
2098 {"dotbox", XC_dotbox},
2099 {"double_arrow", XC_double_arrow},
2100 {"draft_large", XC_draft_large},
2101 {"draft_small", XC_draft_small},
2102 {"draped_box", XC_draped_box},
2103 {"exchange", XC_exchange},
2104 {"fleur", XC_fleur},
2105 {"gobbler", XC_gobbler},
2106 {"gumby", XC_gumby},
2107 {"hand1", XC_hand1},
2108 {"hand2", XC_hand2},
2109 {"heart", XC_heart},
2110 {"icon", XC_icon},
2111 {"iron_cross", XC_iron_cross},
2112 {"left_ptr", XC_left_ptr},
2113 {"left_side", XC_left_side},
2114 {"left_tee", XC_left_tee},
2115 {"leftbutton", XC_leftbutton},
2116 {"ll_angle", XC_ll_angle},
2117 {"lr_angle", XC_lr_angle},
2118 {"man", XC_man},
2119 {"middlebutton", XC_middlebutton},
2120 {"mouse", XC_mouse},
2121 {"pencil", XC_pencil},
2122 {"pirate", XC_pirate},
2123 {"plus", XC_plus},
2124 {"question_arrow", XC_question_arrow},
2125 {"right_ptr", XC_right_ptr},
2126 {"right_side", XC_right_side},
2127 {"right_tee", XC_right_tee},
2128 {"rightbutton", XC_rightbutton},
2129 {"rtl_logo", XC_rtl_logo},
2130 {"sailboat", XC_sailboat},
2131 {"sb_down_arrow", XC_sb_down_arrow},
2132 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2133 {"sb_left_arrow", XC_sb_left_arrow},
2134 {"sb_right_arrow", XC_sb_right_arrow},
2135 {"sb_up_arrow", XC_sb_up_arrow},
2136 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2137 {"shuttle", XC_shuttle},
2138 {"sizing", XC_sizing},
2139 {"spider", XC_spider},
2140 {"spraycan", XC_spraycan},
2141 {"star", XC_star},
2142 {"target", XC_target},
2143 {"tcross", XC_tcross},
2144 {"top_left_arrow", XC_top_left_arrow},
2145 {"top_left_corner", XC_top_left_corner},
2146 {"top_right_corner", XC_top_right_corner},
2147 {"top_side", XC_top_side},
2148 {"top_tee", XC_top_tee},
2149 {"trek", XC_trek},
2150 {"ul_angle", XC_ul_angle},
2151 {"umbrella", XC_umbrella},
2152 {"ur_angle", XC_ur_angle},
2153 {"watch", XC_watch},
2154 {"xterm", XC_xterm},
2155 {NULL, CURSOR_ID_NONE}
2158 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2160 switch (status) {
2161 case BitmapOpenFailed:
2162 wwarning(_("failed to open bitmap file \"%s\""), filename);
2163 break;
2164 case BitmapFileInvalid:
2165 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2166 break;
2167 case BitmapNoMemory:
2168 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2169 break;
2170 case BitmapSuccess:
2171 XFreePixmap(dpy, bitmap);
2172 break;
2177 * (none)
2178 * (builtin, <cursor_name>)
2179 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2181 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2183 WMPropList *elem;
2184 char *val;
2185 int nelem;
2186 int status = 0;
2188 nelem = WMGetPropListItemCount(pl);
2189 if (nelem < 1) {
2190 return (status);
2192 elem = WMGetFromPLArray(pl, 0);
2193 if (!elem || !WMIsPLString(elem)) {
2194 return (status);
2196 val = WMGetFromPLString(elem);
2198 if (strcasecmp(val, "none") == 0) {
2199 status = 1;
2200 *cursor = None;
2201 } else if (strcasecmp(val, "builtin") == 0) {
2202 int i;
2203 int cursor_id = CURSOR_ID_NONE;
2205 if (nelem != 2) {
2206 wwarning(_("bad number of arguments in cursor specification"));
2207 return (status);
2209 elem = WMGetFromPLArray(pl, 1);
2210 if (!elem || !WMIsPLString(elem)) {
2211 return (status);
2213 val = WMGetFromPLString(elem);
2215 for (i = 0; cursor_table[i].name != NULL; i++) {
2216 if (strcasecmp(val, cursor_table[i].name) == 0) {
2217 cursor_id = cursor_table[i].id;
2218 break;
2221 if (CURSOR_ID_NONE == cursor_id) {
2222 wwarning(_("unknown builtin cursor name \"%s\""), val);
2223 } else {
2224 *cursor = XCreateFontCursor(dpy, cursor_id);
2225 status = 1;
2227 } else if (strcasecmp(val, "bitmap") == 0) {
2228 char *bitmap_name;
2229 char *mask_name;
2230 int bitmap_status;
2231 int mask_status;
2232 Pixmap bitmap;
2233 Pixmap mask;
2234 unsigned int w, h;
2235 int x, y;
2236 XColor fg, bg;
2238 if (nelem != 3) {
2239 wwarning(_("bad number of arguments in cursor specification"));
2240 return (status);
2242 elem = WMGetFromPLArray(pl, 1);
2243 if (!elem || !WMIsPLString(elem)) {
2244 return (status);
2246 val = WMGetFromPLString(elem);
2247 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2248 if (!bitmap_name) {
2249 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2250 return (status);
2252 elem = WMGetFromPLArray(pl, 2);
2253 if (!elem || !WMIsPLString(elem)) {
2254 wfree(bitmap_name);
2255 return (status);
2257 val = WMGetFromPLString(elem);
2258 mask_name = FindImage(wPreferences.pixmap_path, val);
2259 if (!mask_name) {
2260 wfree(bitmap_name);
2261 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2262 return (status);
2264 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2265 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2266 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2267 fg.pixel = scr->black_pixel;
2268 bg.pixel = scr->white_pixel;
2269 XQueryColor(dpy, scr->w_colormap, &fg);
2270 XQueryColor(dpy, scr->w_colormap, &bg);
2271 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2272 status = 1;
2274 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2275 check_bitmap_status(mask_status, mask_name, mask);
2276 wfree(bitmap_name);
2277 wfree(mask_name);
2279 return (status);
2282 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2284 static Cursor cursor;
2285 int status;
2286 int changed = 0;
2288 again:
2289 if (!WMIsPLArray(value)) {
2290 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2291 entry->key, "cursor specification");
2292 if (!changed) {
2293 value = entry->plvalue;
2294 changed = 1;
2295 wwarning(_("using default \"%s\" instead"), entry->default_value);
2296 goto again;
2298 return (False);
2300 status = parse_cursor(scr, value, &cursor);
2301 if (!status) {
2302 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2303 if (!changed) {
2304 value = entry->plvalue;
2305 changed = 1;
2306 wwarning(_("using default \"%s\" instead"), entry->default_value);
2307 goto again;
2309 return (False);
2311 if (ret) {
2312 *ret = &cursor;
2314 if (addr) {
2315 *(Cursor *) addr = cursor;
2317 return (True);
2320 #undef CURSOR_ID_NONE
2322 /* ---------------- value setting functions --------------- */
2323 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2325 return REFRESH_WINDOW_TITLE_COLOR;
2328 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2330 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2333 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2335 switch (which) {
2336 case WM_DOCK:
2337 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2338 break;
2339 case WM_CLIP:
2340 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2341 break;
2342 default:
2343 break;
2345 return 0;
2348 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2350 if (scr->workspaces) {
2351 wWorkspaceForceChange(scr, scr->current_workspace);
2352 wArrangeIcons(scr, False);
2354 return 0;
2357 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2359 Pixmap pixmap;
2360 RImage *img;
2361 int reset = 0;
2363 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2364 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2365 ? WREL_ICON : WREL_FLAT);
2366 if (!img) {
2367 wwarning(_("could not render texture for icon background"));
2368 if (!entry->addr)
2369 wTextureDestroy(scr, *texture);
2370 return 0;
2372 RConvertImage(scr->rcontext, img, &pixmap);
2374 if (scr->icon_tile) {
2375 reset = 1;
2376 RReleaseImage(scr->icon_tile);
2377 XFreePixmap(dpy, scr->icon_tile_pixmap);
2380 scr->icon_tile = img;
2382 /* put the icon in the noticeboard hint */
2383 PropSetIconTileHint(scr, img);
2385 if (!wPreferences.flags.noclip) {
2386 if (scr->clip_tile) {
2387 RReleaseImage(scr->clip_tile);
2389 scr->clip_tile = wClipMakeTile(scr, img);
2392 scr->icon_tile_pixmap = pixmap;
2394 if (scr->def_icon_pixmap) {
2395 XFreePixmap(dpy, scr->def_icon_pixmap);
2396 scr->def_icon_pixmap = None;
2398 if (scr->def_ticon_pixmap) {
2399 XFreePixmap(dpy, scr->def_ticon_pixmap);
2400 scr->def_ticon_pixmap = None;
2403 if (scr->icon_back_texture) {
2404 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2406 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2408 if (scr->clip_balloon)
2409 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2412 * Free the texture as nobody else will use it, nor refer to it.
2414 if (!entry->addr)
2415 wTextureDestroy(scr, *texture);
2417 return (reset ? REFRESH_ICON_TILE : 0);
2420 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2422 if (scr->title_font) {
2423 WMReleaseFont(scr->title_font);
2425 scr->title_font = font;
2427 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2430 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2432 if (scr->menu_title_font) {
2433 WMReleaseFont(scr->menu_title_font);
2436 scr->menu_title_font = font;
2438 return REFRESH_MENU_TITLE_FONT;
2441 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2443 if (scr->menu_entry_font) {
2444 WMReleaseFont(scr->menu_entry_font);
2446 scr->menu_entry_font = font;
2448 return REFRESH_MENU_FONT;
2451 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2453 if (scr->icon_title_font) {
2454 WMReleaseFont(scr->icon_title_font);
2457 scr->icon_title_font = font;
2459 return REFRESH_ICON_FONT;
2462 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2464 if (scr->clip_title_font) {
2465 WMReleaseFont(scr->clip_title_font);
2468 scr->clip_title_font = font;
2470 return REFRESH_ICON_FONT;
2473 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2475 if (scr->workspace_name_font) {
2476 WMReleaseFont(scr->workspace_name_font);
2479 scr->workspace_name_font = font;
2481 return 0;
2484 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2486 if (scr->select_color)
2487 WMReleaseColor(scr->select_color);
2489 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2491 wFreeColor(scr, color->pixel);
2493 return REFRESH_MENU_COLOR;
2496 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2498 if (scr->select_text_color)
2499 WMReleaseColor(scr->select_text_color);
2501 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2503 wFreeColor(scr, color->pixel);
2505 return REFRESH_MENU_COLOR;
2508 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2510 if (scr->clip_title_color[widx])
2511 WMReleaseColor(scr->clip_title_color[widx]);
2512 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2513 #ifdef GRADIENT_CLIP_ARROW
2514 if (widx == CLIP_NORMAL) {
2515 RImage *image;
2516 RColor color1, color2;
2517 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2518 int as = pt - 15; /* 15 = 5+5+5 */
2520 FREE_PIXMAP(scr->clip_arrow_gradient);
2522 color1.red = (color->red >> 8) * 6 / 10;
2523 color1.green = (color->green >> 8) * 6 / 10;
2524 color1.blue = (color->blue >> 8) * 6 / 10;
2526 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2527 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2528 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2530 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2531 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2532 RReleaseImage(image);
2534 #endif /* GRADIENT_CLIP_ARROW */
2536 wFreeColor(scr, color->pixel);
2538 return REFRESH_ICON_TITLE_COLOR;
2541 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2543 if (scr->window_title_color[widx])
2544 WMReleaseColor(scr->window_title_color[widx]);
2546 scr->window_title_color[widx] =
2547 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2549 wFreeColor(scr, color->pixel);
2551 return REFRESH_WINDOW_TITLE_COLOR;
2554 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2556 if (scr->menu_title_color[0])
2557 WMReleaseColor(scr->menu_title_color[0]);
2559 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2561 wFreeColor(scr, color->pixel);
2563 return REFRESH_MENU_TITLE_COLOR;
2566 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2568 if (scr->mtext_color)
2569 WMReleaseColor(scr->mtext_color);
2571 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2573 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2574 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2575 } else {
2576 WMSetColorAlpha(scr->dtext_color, 0xffff);
2579 wFreeColor(scr, color->pixel);
2581 return REFRESH_MENU_COLOR;
2584 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2586 if (scr->dtext_color)
2587 WMReleaseColor(scr->dtext_color);
2589 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2591 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2592 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2593 } else {
2594 WMSetColorAlpha(scr->dtext_color, 0xffff);
2597 wFreeColor(scr, color->pixel);
2599 return REFRESH_MENU_COLOR;
2602 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2604 if (scr->icon_title_color)
2605 WMReleaseColor(scr->icon_title_color);
2606 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2608 wFreeColor(scr, color->pixel);
2610 return REFRESH_ICON_TITLE_COLOR;
2613 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2615 if (scr->icon_title_texture) {
2616 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2618 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2620 return REFRESH_ICON_TITLE_BACK;
2623 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2625 close(scr->helper_fd);
2626 scr->helper_fd = 0;
2627 scr->helper_pid = 0;
2628 scr->flags.backimage_helper_launched = 0;
2631 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2633 WMPropList *val;
2634 char *str;
2635 int i;
2637 if (scr->flags.backimage_helper_launched) {
2638 if (WMGetPropListItemCount(value) == 0) {
2639 SendHelperMessage(scr, 'C', 0, NULL);
2640 SendHelperMessage(scr, 'K', 0, NULL);
2642 WMReleasePropList(value);
2643 return 0;
2645 } else {
2646 pid_t pid;
2647 int filedes[2];
2649 if (WMGetPropListItemCount(value) == 0)
2650 return 0;
2652 if (pipe(filedes) < 0) {
2653 wsyserror("pipe() failed:can't set workspace specific background image");
2655 WMReleasePropList(value);
2656 return 0;
2659 pid = fork();
2660 if (pid < 0) {
2661 wsyserror("fork() failed:can't set workspace specific background image");
2662 if (close(filedes[0]) < 0)
2663 wsyserror("could not close pipe");
2664 if (close(filedes[1]) < 0)
2665 wsyserror("could not close pipe");
2667 } else if (pid == 0) {
2668 char *dither;
2670 SetupEnvironment(scr);
2672 if (close(0) < 0)
2673 wsyserror("could not close pipe");
2674 if (dup(filedes[0]) < 0) {
2675 wsyserror("dup() failed:can't set workspace specific background image");
2677 dither = wPreferences.no_dithering ? "-m" : "-d";
2678 if (wPreferences.smooth_workspace_back)
2679 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2680 else
2681 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2682 wsyserror("could not execute wmsetbg");
2683 exit(1);
2684 } else {
2686 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2687 wsyserror("error setting close-on-exec flag");
2689 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2690 wsyserror("error setting close-on-exec flag");
2693 scr->helper_fd = filedes[1];
2694 scr->helper_pid = pid;
2695 scr->flags.backimage_helper_launched = 1;
2697 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2699 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2704 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2705 val = WMGetFromPLArray(value, i);
2706 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2707 str = WMGetPropListDescription(val, False);
2709 SendHelperMessage(scr, 'S', i + 1, str);
2711 wfree(str);
2712 } else {
2713 SendHelperMessage(scr, 'U', i + 1, NULL);
2716 sleep(1);
2718 WMReleasePropList(value);
2719 return 0;
2722 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2724 if (scr->flags.backimage_helper_launched) {
2725 char *str;
2727 if (WMGetPropListItemCount(value) == 0) {
2728 SendHelperMessage(scr, 'U', 0, NULL);
2729 } else {
2730 /* set the default workspace background to this one */
2731 str = WMGetPropListDescription(value, False);
2732 if (str) {
2733 SendHelperMessage(scr, 'S', 0, str);
2734 wfree(str);
2735 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2736 } else {
2737 SendHelperMessage(scr, 'U', 0, NULL);
2740 } else if (WMGetPropListItemCount(value) > 0) {
2741 char *command;
2742 char *text;
2743 char *dither;
2744 int len;
2746 text = WMGetPropListDescription(value, False);
2747 len = strlen(text) + 40;
2748 command = wmalloc(len);
2749 dither = wPreferences.no_dithering ? "-m" : "-d";
2750 if (wPreferences.smooth_workspace_back)
2751 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2752 else
2753 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2754 wfree(text);
2755 ExecuteShellCommand(scr, command);
2756 wfree(command);
2758 WMReleasePropList(value);
2760 return 0;
2763 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2765 if (scr->widget_texture) {
2766 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2768 scr->widget_texture = *(WTexSolid **) texture;
2770 return 0;
2773 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2775 if (scr->window_title_texture[WS_FOCUSED]) {
2776 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2778 scr->window_title_texture[WS_FOCUSED] = *texture;
2780 return REFRESH_WINDOW_TEXTURES;
2783 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2785 if (scr->window_title_texture[WS_PFOCUSED]) {
2786 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2788 scr->window_title_texture[WS_PFOCUSED] = *texture;
2790 return REFRESH_WINDOW_TEXTURES;
2793 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2795 if (scr->window_title_texture[WS_UNFOCUSED]) {
2796 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2798 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2800 return REFRESH_WINDOW_TEXTURES;
2803 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2805 if (scr->resizebar_texture[0]) {
2806 wTextureDestroy(scr, scr->resizebar_texture[0]);
2808 scr->resizebar_texture[0] = *texture;
2810 return REFRESH_WINDOW_TEXTURES;
2813 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2815 if (scr->menu_title_texture[0]) {
2816 wTextureDestroy(scr, scr->menu_title_texture[0]);
2818 scr->menu_title_texture[0] = *texture;
2820 return REFRESH_MENU_TITLE_TEXTURE;
2823 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2825 if (scr->menu_item_texture) {
2826 wTextureDestroy(scr, scr->menu_item_texture);
2827 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2829 scr->menu_item_texture = *texture;
2831 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2833 return REFRESH_MENU_TEXTURE;
2836 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2838 WWindow *wwin;
2839 wKeyBindings[widx] = *shortcut;
2841 wwin = scr->focused_window;
2843 while (wwin != NULL) {
2844 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2846 if (!WFLAGP(wwin, no_bind_keys)) {
2847 wWindowSetKeyGrabs(wwin);
2849 wwin = wwin->prev;
2852 return 0;
2855 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2857 wScreenUpdateUsableArea(scr);
2858 wArrangeIcons(scr, True);
2860 return 0;
2863 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2865 wScreenUpdateUsableArea(scr);
2867 return 0;
2870 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2872 return REFRESH_MENU_TEXTURE;
2875 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2877 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2879 RCopyArea(img, image, x, y, w, h, 0, 0);
2881 return img;
2884 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2886 char *path;
2887 RImage *bgimage;
2888 int cwidth, cheight;
2889 WPreferences *prefs = (WPreferences *) foo;
2891 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2892 if (prefs->swtileImage)
2893 RReleaseImage(prefs->swtileImage);
2894 prefs->swtileImage = NULL;
2896 WMReleasePropList(array);
2897 return 0;
2900 switch (WMGetPropListItemCount(array)) {
2901 case 4:
2902 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2903 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2904 break;
2905 } else
2906 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2908 if (!path) {
2909 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2910 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2911 } else {
2912 bgimage = RLoadImage(scr->rcontext, path, 0);
2913 if (!bgimage) {
2914 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2915 wfree(path);
2916 } else {
2917 wfree(path);
2919 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2920 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2922 if (cwidth <= 0 || cheight <= 0 ||
2923 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2924 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2925 else {
2926 int i;
2927 int swidth, theight;
2928 for (i = 0; i < 9; i++) {
2929 if (prefs->swbackImage[i])
2930 RReleaseImage(prefs->swbackImage[i]);
2931 prefs->swbackImage[i] = NULL;
2933 swidth = (bgimage->width - cwidth) / 2;
2934 theight = (bgimage->height - cheight) / 2;
2936 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2937 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2938 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2939 swidth, theight);
2941 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2942 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2943 cwidth, cheight);
2944 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2945 swidth, cheight);
2947 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2948 swidth, theight);
2949 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2950 cwidth, theight);
2951 prefs->swbackImage[8] =
2952 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2953 theight);
2955 // check if anything failed
2956 for (i = 0; i < 9; i++) {
2957 if (!prefs->swbackImage[i]) {
2958 for (; i >= 0; --i) {
2959 RReleaseImage(prefs->swbackImage[i]);
2960 prefs->swbackImage[i] = NULL;
2962 break;
2966 RReleaseImage(bgimage);
2970 case 1:
2971 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
2972 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2973 break;
2974 } else
2975 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
2977 if (!path) {
2978 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2979 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
2980 } else {
2981 if (prefs->swtileImage)
2982 RReleaseImage(prefs->swtileImage);
2984 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
2985 if (!prefs->swtileImage) {
2986 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2988 wfree(path);
2990 break;
2992 default:
2993 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
2994 break;
2997 WMReleasePropList(array);
2999 return 0;
3003 * Very ugly kluge.
3004 * Need access to the double click variables, so that all widgets in
3005 * wmaker panels will have the same dbl-click values.
3006 * TODO: figure a better way of dealing with it.
3008 #include <WINGs/WINGsP.h>
3010 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3012 extern _WINGsConfiguration WINGsConfiguration;
3014 if (*value <= 0)
3015 *(int *)foo = 1;
3017 WINGsConfiguration.doubleClickDelay = *value;
3019 return 0;
3022 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3024 if (wCursor[widx] != None) {
3025 XFreeCursor(dpy, wCursor[widx]);
3028 wCursor[widx] = *cursor;
3030 if (widx == WCUR_ROOT && *cursor != None) {
3031 XDefineCursor(dpy, scr->root_win, *cursor);
3034 return 0;