HOWTO: The perfect Window Maker patch
[wmaker-crm.git] / src / defaults.c
blob58c823d0a679567dc0a4f8d7249499bc79fe27b6
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 #ifdef HAVE_DLFCN_H
40 # include <dlfcn.h>
41 #endif
43 #ifndef PATH_MAX
44 #define PATH_MAX DEFAULT_PATH_MAX
45 #endif
47 #include <X11/Xlib.h>
48 #include <X11/Xutil.h>
49 #include <X11/keysym.h>
51 #include <wraster.h>
53 #include "WindowMaker.h"
54 #include "wcore.h"
55 #include "framewin.h"
56 #include "window.h"
57 #include "texture.h"
58 #include "screen.h"
59 #include "resources.h"
60 #include "defaults.h"
61 #include "keybind.h"
62 #include "xmodifier.h"
63 #include "icon.h"
64 #include "funcs.h"
65 #include "actions.h"
66 #include "dock.h"
67 #include "workspace.h"
68 #include "properties.h"
70 #define MAX_SHORTCUT_LENGTH 32
72 #ifndef GLOBAL_DEFAULTS_SUBDIR
73 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
74 #endif
76 /***** Global *****/
78 extern WDDomain *WDWindowMaker;
79 extern WDDomain *WDWindowAttributes;
80 extern WDDomain *WDRootMenu;
82 extern int wScreenCount;
84 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
85 extern Atom _XA_WINDOWMAKER_ICON_TILE;
88 extern WMPropList *wDomainName;
89 extern WMPropList *wAttributeDomainName;
91 extern WPreferences wPreferences;
93 extern WShortKey wKeyBindings[WKBD_LAST];
95 typedef struct {
96 char *key;
97 char *default_value;
98 void *extra_data;
99 void *addr;
100 int (*convert) ();
101 int (*update) ();
102 WMPropList *plkey;
103 WMPropList *plvalue; /* default value */
104 } WDefaultEntry;
106 /* used to map strings to integers */
107 typedef struct {
108 char *string;
109 short value;
110 char is_alias;
111 } WOptionEnumeration;
113 /* type converters */
114 static int getBool();
115 static int getInt();
116 static int getCoord();
117 #if 0
118 /* this is not used yet */
119 static int getString();
120 #endif
121 static int getPathList();
122 static int getEnum();
123 static int getTexture();
124 static int getWSBackground();
125 static int getWSSpecificBackground();
126 static int getFont();
127 static int getColor();
128 static int getKeybind();
129 static int getModMask();
130 #ifdef NEWSTUFF
131 static int getRImage();
132 #endif
133 static int getPropList();
135 /* value setting functions */
136 static int setJustify();
137 static int setClearance();
138 static int setIfDockPresent();
139 static int setStickyIcons();
141 static int setPositive();
143 static int setWidgetColor();
144 static int setIconTile();
145 static int setWinTitleFont();
146 static int setMenuTitleFont();
147 static int setMenuTextFont();
148 static int setIconTitleFont();
149 static int setIconTitleColor();
150 static int setIconTitleBack();
151 static int setLargeDisplayFont();
152 static int setWTitleColor();
153 static int setFTitleBack();
154 static int setPTitleBack();
155 static int setUTitleBack();
156 static int setResizebarBack();
157 static int setWorkspaceBack();
158 static int setWorkspaceSpecificBack();
159 #ifdef VIRTUAL_DESKTOP
160 static int setVirtualDeskEnable();
161 #endif
162 static int setMenuTitleColor();
163 static int setMenuTextColor();
164 static int setMenuDisabledColor();
165 static int setMenuTitleBack();
166 static int setMenuTextBack();
167 static int setHightlight();
168 static int setHightlightText();
169 static int setKeyGrab();
170 static int setDoubleClick();
171 static int setIconPosition();
173 static int setClipTitleFont();
174 static int setClipTitleColor();
176 static int setMenuStyle();
177 static int setSwPOptions();
178 static int updateUsableArea();
180 extern Cursor wCursor[WCUR_LAST];
181 static int getCursor();
182 static int setCursor();
185 * Tables to convert strings to enumeration values.
186 * Values stored are char
189 /* WARNING: sum of length of all value strings must not exceed
190 * this value */
191 #define TOTAL_VALUES_LENGTH 80
193 #define REFRESH_WINDOW_TEXTURES (1<<0)
194 #define REFRESH_MENU_TEXTURE (1<<1)
195 #define REFRESH_MENU_FONT (1<<2)
196 #define REFRESH_MENU_COLOR (1<<3)
197 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
198 #define REFRESH_MENU_TITLE_FONT (1<<5)
199 #define REFRESH_MENU_TITLE_COLOR (1<<6)
200 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
201 #define REFRESH_WINDOW_FONT (1<<8)
202 #define REFRESH_ICON_TILE (1<<9)
203 #define REFRESH_ICON_FONT (1<<10)
204 #define REFRESH_WORKSPACE_BACK (1<<11)
206 #define REFRESH_BUTTON_IMAGES (1<<12)
208 #define REFRESH_ICON_TITLE_COLOR (1<<13)
209 #define REFRESH_ICON_TITLE_BACK (1<<14)
211 static WOptionEnumeration seFocusModes[] = {
212 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
213 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
214 {NULL, 0, 0}
217 static WOptionEnumeration seColormapModes[] = {
218 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
219 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
220 {NULL, 0, 0}
223 static WOptionEnumeration sePlacements[] = {
224 {"Auto", WPM_AUTO, 0},
225 {"Smart", WPM_SMART, 0},
226 {"Cascade", WPM_CASCADE, 0},
227 {"Random", WPM_RANDOM, 0},
228 {"Manual", WPM_MANUAL, 0},
229 {NULL, 0, 0}
232 static WOptionEnumeration seGeomDisplays[] = {
233 {"None", WDIS_NONE, 0},
234 {"Center", WDIS_CENTER, 0},
235 {"Corner", WDIS_TOPLEFT, 0},
236 {"Floating", WDIS_FRAME_CENTER, 0},
237 {"Line", WDIS_NEW, 0},
238 {NULL, 0, 0}
241 static WOptionEnumeration seSpeeds[] = {
242 {"UltraFast", SPEED_ULTRAFAST, 0},
243 {"Fast", SPEED_FAST, 0},
244 {"Medium", SPEED_MEDIUM, 0},
245 {"Slow", SPEED_SLOW, 0},
246 {"UltraSlow", SPEED_ULTRASLOW, 0},
247 {NULL, 0, 0}
250 static WOptionEnumeration seMouseButtonActions[] = {
251 {"None", WA_NONE, 0},
252 {"SelectWindows", WA_SELECT_WINDOWS, 0},
253 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
254 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
255 {NULL, 0, 0}
258 static WOptionEnumeration seMouseWheelActions[] = {
259 {"None", WA_NONE, 0},
260 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
261 {NULL, 0, 0}
264 static WOptionEnumeration seIconificationStyles[] = {
265 {"Zoom", WIS_ZOOM, 0},
266 {"Twist", WIS_TWIST, 0},
267 {"Flip", WIS_FLIP, 0},
268 {"None", WIS_NONE, 0},
269 {"random", WIS_RANDOM, 0},
270 {NULL, 0, 0}
273 static WOptionEnumeration seJustifications[] = {
274 {"Left", WTJ_LEFT, 0},
275 {"Center", WTJ_CENTER, 0},
276 {"Right", WTJ_RIGHT, 0},
277 {NULL, 0, 0}
280 static WOptionEnumeration seIconPositions[] = {
281 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
282 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
283 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
284 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
285 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
286 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
287 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
288 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
289 {NULL, 0, 0}
292 static WOptionEnumeration seMenuStyles[] = {
293 {"normal", MS_NORMAL, 0},
294 {"singletexture", MS_SINGLE_TEXTURE, 0},
295 {"flat", MS_FLAT, 0},
296 {NULL, 0, 0}
299 static WOptionEnumeration seDisplayPositions[] = {
300 {"none", WD_NONE, 0},
301 {"center", WD_CENTER, 0},
302 {"top", WD_TOP, 0},
303 {"bottom", WD_BOTTOM, 0},
304 {"topleft", WD_TOPLEFT, 0},
305 {"topright", WD_TOPRIGHT, 0},
306 {"bottomleft", WD_BOTTOMLEFT, 0},
307 {"bottomright", WD_BOTTOMRIGHT, 0},
308 {NULL, 0, 0}
311 static WOptionEnumeration seWorkspaceBorder[] = {
312 {"None", WB_NONE, 0},
313 {"LeftRight", WB_LEFTRIGHT, 0},
314 {"TopBottom", WB_TOPBOTTOM, 0},
315 {"AllDirections", WB_ALLDIRS, 0},
316 {NULL, 0, 0}
320 * ALL entries in the tables bellow, NEED to have a default value
321 * defined, and this value needs to be correct.
324 /* these options will only affect the window manager on startup
326 * static defaults can't access the screen data, because it is
327 * created after these defaults are read
329 WDefaultEntry staticOptionList[] = {
331 {"ColormapSize", "4", NULL,
332 &wPreferences.cmap_size, getInt, NULL},
333 {"DisableDithering", "NO", NULL,
334 &wPreferences.no_dithering, getBool, NULL},
335 /* static by laziness */
336 {"IconSize", "64", NULL,
337 &wPreferences.icon_size, getInt, NULL},
338 {"ModifierKey", "Mod1", NULL,
339 &wPreferences.modifier_mask, getModMask, NULL},
340 {"DisableWSMouseActions", "NO", NULL,
341 &wPreferences.disable_root_mouse, getBool, NULL},
342 {"FocusMode", "manual", seFocusModes,
343 &wPreferences.focus_mode, getEnum, NULL}, /* have a problem when switching from manual to sloppy without restart */
344 {"NewStyle", "NO", NULL,
345 &wPreferences.new_style, getBool, NULL},
346 {"DisableDock", "NO", (void *)WM_DOCK,
347 NULL, getBool, setIfDockPresent},
348 {"DisableClip", "NO", (void *)WM_CLIP,
349 NULL, getBool, setIfDockPresent},
350 {"DisableMiniwindows", "NO", NULL,
351 &wPreferences.disable_miniwindows, getBool, NULL}
354 WDefaultEntry optionList[] = {
355 /* dynamic options */
356 {"IconPosition", "blh", seIconPositions,
357 &wPreferences.icon_yard, getEnum, setIconPosition},
358 {"IconificationStyle", "Zoom", seIconificationStyles,
359 &wPreferences.iconification_style, getEnum, NULL},
360 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
361 &wPreferences.mouse_button1, getEnum, NULL},
362 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
363 &wPreferences.mouse_button2, getEnum, NULL},
364 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
365 &wPreferences.mouse_button3, getEnum, NULL},
366 {"MouseWheelAction", "None", seMouseWheelActions,
367 &wPreferences.mouse_wheel, getEnum, NULL},
368 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
369 &wPreferences.pixmap_path, getPathList, NULL},
370 {"IconPath", DEF_ICON_PATHS, NULL,
371 &wPreferences.icon_path, getPathList, NULL},
372 {"ColormapMode", "auto", seColormapModes,
373 &wPreferences.colormap_mode, getEnum, NULL},
374 {"AutoFocus", "NO", NULL,
375 &wPreferences.auto_focus, getBool, NULL},
376 {"RaiseDelay", "0", NULL,
377 &wPreferences.raise_delay, getInt, NULL},
378 {"CirculateRaise", "NO", NULL,
379 &wPreferences.circ_raise, getBool, NULL},
380 {"Superfluous", "NO", NULL,
381 &wPreferences.superfluous, getBool, NULL},
382 {"AdvanceToNewWorkspace", "NO", NULL,
383 &wPreferences.ws_advance, getBool, NULL},
384 {"CycleWorkspaces", "NO", NULL,
385 &wPreferences.ws_cycle, getBool, NULL},
386 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
387 &wPreferences.workspace_name_display_position, getEnum, NULL},
388 {"WorkspaceBorder", "None", seWorkspaceBorder,
389 &wPreferences.workspace_border_position, getEnum, updateUsableArea},
390 {"WorkspaceBorderSize", "0", NULL,
391 &wPreferences.workspace_border_size, getInt, updateUsableArea},
392 #ifdef VIRTUAL_DESKTOP
393 {"EnableVirtualDesktop", "NO", NULL,
394 &wPreferences.vdesk_enable, getBool, setVirtualDeskEnable},
395 {"VirtualEdgeExtendSpace", "0", NULL,
396 &wPreferences.vedge_bordersize, getInt, NULL},
397 {"VirtualEdgeHorizonScrollSpeed", "30", NULL,
398 &wPreferences.vedge_hscrollspeed, getInt, NULL},
399 {"VirtualEdgeVerticalScrollSpeed", "30", NULL,
400 &wPreferences.vedge_vscrollspeed, getInt, NULL},
401 {"VirtualEdgeResistance", "30", NULL,
402 &wPreferences.vedge_resistance, getInt, NULL},
403 {"VirtualEdgeAttraction", "30", NULL,
404 &wPreferences.vedge_attraction, getInt, NULL},
405 {"VirtualEdgeLeftKey", "None", (void *)WKBD_VDESK_LEFT,
406 NULL, getKeybind, setKeyGrab},
407 {"VirtualEdgeRightKey", "None", (void *)WKBD_VDESK_RIGHT,
408 NULL, getKeybind, setKeyGrab},
409 {"VirtualEdgeUpKey", "None", (void *)WKBD_VDESK_UP,
410 NULL, getKeybind, setKeyGrab},
411 {"VirtualEdgeDownKey", "None", (void *)WKBD_VDESK_DOWN,
412 NULL, getKeybind, setKeyGrab},
413 #endif
414 {"StickyIcons", "NO", NULL,
415 &wPreferences.sticky_icons, getBool, setStickyIcons},
416 {"SaveSessionOnExit", "NO", NULL,
417 &wPreferences.save_session_on_exit, getBool, NULL},
418 {"WrapMenus", "NO", NULL,
419 &wPreferences.wrap_menus, getBool, NULL},
420 {"ScrollableMenus", "NO", NULL,
421 &wPreferences.scrollable_menus, getBool, NULL},
422 {"MenuScrollSpeed", "medium", seSpeeds,
423 &wPreferences.menu_scroll_speed, getEnum, NULL},
424 {"IconSlideSpeed", "medium", seSpeeds,
425 &wPreferences.icon_slide_speed, getEnum, NULL},
426 {"ShadeSpeed", "medium", seSpeeds,
427 &wPreferences.shade_speed, getEnum, NULL},
428 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
429 &wPreferences.dblclick_time, getInt, setDoubleClick,
431 {"AlignSubmenus", "NO", NULL,
432 &wPreferences.align_menus, getBool, NULL},
433 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
434 &wPreferences.open_transients_with_parent, getBool, NULL},
435 {"WindowPlacement", "auto", sePlacements,
436 &wPreferences.window_placement, getEnum, NULL},
437 {"IgnoreFocusClick", "NO", NULL,
438 &wPreferences.ignore_focus_click, getBool, NULL},
439 {"UseSaveUnders", "NO", NULL,
440 &wPreferences.use_saveunders, getBool, NULL},
441 {"OpaqueMove", "NO", NULL,
442 &wPreferences.opaque_move, getBool, NULL},
443 {"DisableAnimations", "NO", NULL,
444 &wPreferences.no_animations, getBool, NULL},
445 {"DontLinkWorkspaces", "NO", NULL,
446 &wPreferences.no_autowrap, getBool, NULL},
447 {"AutoArrangeIcons", "NO", NULL,
448 &wPreferences.auto_arrange_icons, getBool, NULL},
449 {"NoWindowOverDock", "NO", NULL,
450 &wPreferences.no_window_over_dock, getBool, updateUsableArea},
451 {"NoWindowOverIcons", "NO", NULL,
452 &wPreferences.no_window_over_icons, getBool, updateUsableArea},
453 {"WindowPlaceOrigin", "(0, 0)", NULL,
454 &wPreferences.window_place_origin, getCoord, NULL},
455 {"ResizeDisplay", "corner", seGeomDisplays,
456 &wPreferences.size_display, getEnum, NULL},
457 {"MoveDisplay", "corner", seGeomDisplays,
458 &wPreferences.move_display, getEnum, NULL},
459 {"DontConfirmKill", "NO", NULL,
460 &wPreferences.dont_confirm_kill, getBool, NULL},
461 {"WindowTitleBalloons", "NO", NULL,
462 &wPreferences.window_balloon, getBool, NULL},
463 {"MiniwindowTitleBalloons", "NO", NULL,
464 &wPreferences.miniwin_balloon, getBool, NULL},
465 {"AppIconBalloons", "NO", NULL,
466 &wPreferences.appicon_balloon, getBool, NULL},
467 {"HelpBalloons", "NO", NULL,
468 &wPreferences.help_balloon, getBool, NULL},
469 {"EdgeResistance", "30", NULL,
470 &wPreferences.edge_resistance, getInt, NULL},
471 {"Attraction", "NO", NULL,
472 &wPreferences.attract, getBool, NULL},
473 {"DisableBlinking", "NO", NULL,
474 &wPreferences.dont_blink, getBool, NULL},
475 {"SingleClickLaunch", "NO", NULL,
476 &wPreferences.single_click, getBool, NULL},
477 /* style options */
478 {"MenuStyle", "normal", seMenuStyles,
479 &wPreferences.menu_style, getEnum, setMenuStyle},
480 {"WidgetColor", "(solid, gray)", NULL,
481 NULL, getTexture, setWidgetColor,
483 {"WorkspaceSpecificBack", "()", NULL,
484 NULL, getWSSpecificBackground, setWorkspaceSpecificBack},
485 /* WorkspaceBack must come after WorkspaceSpecificBack or
486 * WorkspaceBack wont know WorkspaceSpecificBack was also
487 * specified and 2 copies of wmsetbg will be launched */
488 {"WorkspaceBack", "(solid, black)", NULL,
489 NULL, getWSBackground, setWorkspaceBack},
490 {"SmoothWorkspaceBack", "NO", NULL,
491 NULL, getBool, NULL},
492 {"IconBack", "(solid, gray)", NULL,
493 NULL, getTexture, setIconTile},
494 {"TitleJustify", "center", seJustifications,
495 &wPreferences.title_justification, getEnum, setJustify},
496 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
497 NULL, getFont, setWinTitleFont,
499 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
500 &wPreferences.window_title_clearance, getInt, setClearance},
501 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
502 &wPreferences.menu_title_clearance, getInt, setClearance},
503 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
504 &wPreferences.menu_text_clearance, getInt, setClearance},
505 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
506 NULL, getFont, setMenuTitleFont},
507 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
508 NULL, getFont, setMenuTextFont},
509 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
510 NULL, getFont, setIconTitleFont},
511 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
512 NULL, getFont, setClipTitleFont},
513 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
514 NULL, getFont, setLargeDisplayFont},
515 {"HighlightColor", "white", NULL,
516 NULL, getColor, setHightlight},
517 {"HighlightTextColor", "black", NULL,
518 NULL, getColor, setHightlightText},
519 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
520 NULL, getColor, setClipTitleColor},
521 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
522 NULL, getColor, setClipTitleColor},
523 {"FTitleColor", "white", (void *)WS_FOCUSED,
524 NULL, getColor, setWTitleColor},
525 {"PTitleColor", "white", (void *)WS_PFOCUSED,
526 NULL, getColor, setWTitleColor},
527 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
528 NULL, getColor, setWTitleColor},
529 {"FTitleBack", "(solid, black)", NULL,
530 NULL, getTexture, setFTitleBack},
531 {"PTitleBack", "(solid, \"#616161\")", NULL,
532 NULL, getTexture, setPTitleBack},
533 {"UTitleBack", "(solid, gray)", NULL,
534 NULL, getTexture, setUTitleBack},
535 {"ResizebarBack", "(solid, gray)", NULL,
536 NULL, getTexture, setResizebarBack},
537 {"MenuTitleColor", "white", NULL,
538 NULL, getColor, setMenuTitleColor},
539 {"MenuTextColor", "black", NULL,
540 NULL, getColor, setMenuTextColor},
541 {"MenuDisabledColor", "\"#616161\"", NULL,
542 NULL, getColor, setMenuDisabledColor},
543 {"MenuTitleBack", "(solid, black)", NULL,
544 NULL, getTexture, setMenuTitleBack},
545 {"MenuTextBack", "(solid, gray)", NULL,
546 NULL, getTexture, setMenuTextBack},
547 {"IconTitleColor", "white", NULL,
548 NULL, getColor, setIconTitleColor},
549 {"IconTitleBack", "black", NULL,
550 NULL, getColor, setIconTitleBack},
551 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
552 NULL, getPropList, setSwPOptions},
553 /* keybindings */
554 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
555 NULL, getKeybind, setKeyGrab},
556 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
557 NULL, getKeybind, setKeyGrab},
558 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
559 NULL, getKeybind, setKeyGrab},
560 {"ClipLowerKey", "None", (void *)WKBD_CLIPLOWER,
561 NULL, getKeybind, setKeyGrab},
562 {"ClipRaiseKey", "None", (void *)WKBD_CLIPRAISE,
563 NULL, getKeybind, setKeyGrab},
564 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
565 NULL, getKeybind, setKeyGrab},
566 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
567 NULL, getKeybind, setKeyGrab},
568 {"HideKey", "None", (void *)WKBD_HIDE,
569 NULL, getKeybind, setKeyGrab},
570 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
571 NULL, getKeybind, setKeyGrab},
572 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
573 NULL, getKeybind, setKeyGrab},
574 {"CloseKey", "None", (void *)WKBD_CLOSE,
575 NULL, getKeybind, setKeyGrab},
576 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
577 NULL, getKeybind, setKeyGrab},
578 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
579 NULL, getKeybind, setKeyGrab},
580 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
581 NULL, getKeybind, setKeyGrab},
582 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
583 NULL, getKeybind, setKeyGrab},
584 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
585 NULL, getKeybind, setKeyGrab},
586 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
587 NULL, getKeybind, setKeyGrab},
588 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
589 NULL, getKeybind, setKeyGrab},
590 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
591 NULL, getKeybind, setKeyGrab},
592 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
593 NULL, getKeybind, setKeyGrab},
594 {"ShadeKey", "None", (void *)WKBD_SHADE,
595 NULL, getKeybind, setKeyGrab},
596 {"SelectKey", "None", (void *)WKBD_SELECT,
597 NULL, getKeybind, setKeyGrab},
598 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
599 NULL, getKeybind, setKeyGrab},
600 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
601 NULL, getKeybind, setKeyGrab},
602 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
603 NULL, getKeybind, setKeyGrab},
604 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
605 NULL, getKeybind, setKeyGrab},
606 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
607 NULL, getKeybind, setKeyGrab},
608 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
609 NULL, getKeybind, setKeyGrab},
610 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
611 NULL, getKeybind, setKeyGrab},
612 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
613 NULL, getKeybind, setKeyGrab},
614 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
615 NULL, getKeybind, setKeyGrab},
616 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
617 NULL, getKeybind, setKeyGrab},
618 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
619 NULL, getKeybind, setKeyGrab},
620 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
621 NULL, getKeybind, setKeyGrab},
622 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
623 NULL, getKeybind, setKeyGrab},
624 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
625 NULL, getKeybind, setKeyGrab},
626 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
627 NULL, getKeybind, setKeyGrab},
628 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
629 NULL, getKeybind, setKeyGrab},
630 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
631 NULL, getKeybind, setKeyGrab},
632 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
633 NULL, getKeybind, setKeyGrab},
634 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
635 NULL, getKeybind, setKeyGrab},
636 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
637 NULL, getKeybind, setKeyGrab},
638 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
639 NULL, getKeybind, setKeyGrab},
640 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
641 NULL, getKeybind, setKeyGrab}
642 , {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
643 NULL, getKeybind, setKeyGrab},
644 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
645 NULL, getKeybind, setKeyGrab},
646 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
647 NULL, getKeybind, setKeyGrab},
648 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
649 NULL, getKeybind, setKeyGrab},
650 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
651 NULL, getKeybind, setKeyGrab},
652 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
653 NULL, getKeybind, setKeyGrab},
654 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
655 NULL, getKeybind, setKeyGrab},
657 #ifdef KEEP_XKB_LOCK_STATUS
658 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
659 NULL, getKeybind, setKeyGrab},
660 {"KbdModeLock", "NO", NULL,
661 &wPreferences.modelock, getBool, NULL},
662 #endif /* KEEP_XKB_LOCK_STATUS */
664 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
665 NULL, getCursor, setCursor},
666 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
667 NULL, getCursor, setCursor},
668 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
669 NULL, getCursor, setCursor},
670 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
671 NULL, getCursor, setCursor},
672 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
673 (void *)WCUR_TOPLEFTRESIZE,
674 NULL, getCursor, setCursor},
675 {"TopRightResizeCursor", "(builtin, top_right_corner)",
676 (void *)WCUR_TOPRIGHTRESIZE,
677 NULL, getCursor, setCursor},
678 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
679 (void *)WCUR_BOTTOMLEFTRESIZE,
680 NULL, getCursor, setCursor},
681 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
682 (void *)WCUR_BOTTOMRIGHTRESIZE,
683 NULL, getCursor, setCursor},
684 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
685 (void *)WCUR_VERTICALRESIZE,
686 NULL, getCursor, setCursor},
687 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
688 (void *)WCUR_HORIZONRESIZE,
689 NULL, getCursor, setCursor},
690 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
691 NULL, getCursor, setCursor},
692 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
693 NULL, getCursor, setCursor},
694 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
695 NULL, getCursor, setCursor},
696 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
697 NULL, getCursor, setCursor},
698 {"DialogHistoryLines", "500", NULL,
699 &wPreferences.history_lines, getInt, NULL}
702 #if 0
703 static void rereadDefaults(void);
704 #endif
706 #if 0
707 static void rereadDefaults(void)
709 /* must defer the update because accessing X data from a
710 * signal handler can mess up Xlib */
713 #endif
715 static void initDefaults()
717 unsigned int i;
718 WDefaultEntry *entry;
720 WMPLSetCaseSensitive(False);
722 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
723 entry = &optionList[i];
725 entry->plkey = WMCreatePLString(entry->key);
726 if (entry->default_value)
727 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
728 else
729 entry->plvalue = NULL;
732 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
733 entry = &staticOptionList[i];
735 entry->plkey = WMCreatePLString(entry->key);
736 if (entry->default_value)
737 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
738 else
739 entry->plvalue = NULL;
743 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
744 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
746 PLRegister(wDomainName, rereadDefaults);
747 PLRegister(wAttributeDomainName, rereadDefaults);
751 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
753 WMPropList *globalDict = NULL;
754 char path[PATH_MAX];
755 struct stat stbuf;
757 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
758 if (stat(path, &stbuf) >= 0) {
759 globalDict = WMReadPropListFromFile(path);
760 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
761 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
762 WMReleasePropList(globalDict);
763 globalDict = NULL;
764 } else if (!globalDict) {
765 wwarning(_("could not load domain %s from global defaults database"), domainName);
769 return globalDict;
772 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
773 static void prependMenu(WMPropList * destarr, WMPropList * array)
775 WMPropList *item;
776 int i;
778 for (i = 0; i < WMGetPropListItemCount(array); i++) {
779 item = WMGetFromPLArray(array, i);
780 if (item)
781 WMInsertInPLArray(destarr, i + 1, item);
785 static void appendMenu(WMPropList * destarr, WMPropList * array)
787 WMPropList *item;
788 int i;
790 for (i = 0; i < WMGetPropListItemCount(array); i++) {
791 item = WMGetFromPLArray(array, i);
792 if (item)
793 WMAddToPLArray(destarr, item);
796 #endif
798 /* Fixup paths for cached pixmaps from .AppInfo to Library/WindowMaker/... */
799 static Bool fixupCachedPixmapsPaths(WMPropList * dict)
801 WMPropList *allApps, *app, *props, *iconkey, *icon, *newicon;
802 char *path, *fixedpath, *ptr, *search;
803 int i, len, slen;
804 Bool changed = False;
806 search = "/.AppInfo/WindowMaker/";
807 slen = strlen(search);
809 iconkey = WMCreatePLString("Icon");
810 allApps = WMGetPLDictionaryKeys(dict);
812 for (i = 0; i < WMGetPropListItemCount(allApps); i++) {
813 app = WMGetFromPLArray(allApps, i);
814 props = WMGetFromPLDictionary(dict, app);
815 if (!props)
816 continue;
817 icon = WMGetFromPLDictionary(props, iconkey);
818 if (icon && WMIsPLString(icon)) {
819 path = WMGetFromPLString(icon);
820 ptr = strstr(path, search);
821 if (ptr) {
822 changed = True;
823 len = (ptr - path);
824 fixedpath = wmalloc(strlen(path) + 32);
825 strncpy(fixedpath, path, len);
826 fixedpath[len] = 0;
827 strcat(fixedpath, "/Library/WindowMaker/CachedPixmaps/");
828 strcat(fixedpath, ptr + slen);
829 newicon = WMCreatePLString(fixedpath);
830 WMPutInPLDictionary(props, iconkey, newicon);
831 WMReleasePropList(newicon);
832 wfree(fixedpath);
837 WMReleasePropList(allApps);
838 WMReleasePropList(iconkey);
840 return changed;
843 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
845 WMPropList *menu = menuDomain->dictionary;
846 WMPropList *submenu;
848 if (!menu || !WMIsPLArray(menu))
849 return;
851 #ifdef GLOBAL_PREAMBLE_MENU_FILE
852 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
854 if (submenu && !WMIsPLArray(submenu)) {
855 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
856 WMReleasePropList(submenu);
857 submenu = NULL;
859 if (submenu) {
860 prependMenu(menu, submenu);
861 WMReleasePropList(submenu);
863 #endif
865 #ifdef GLOBAL_EPILOGUE_MENU_FILE
866 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
868 if (submenu && !WMIsPLArray(submenu)) {
869 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
870 WMReleasePropList(submenu);
871 submenu = NULL;
873 if (submenu) {
874 appendMenu(menu, submenu);
875 WMReleasePropList(submenu);
877 #endif
879 menuDomain->dictionary = menu;
882 #if 0
883 WMPropList *wDefaultsInit(int screen_number)
885 static int defaults_inited = 0;
886 WMPropList *dict;
888 if (!defaults_inited) {
889 initDefaults();
892 dict = PLGetDomain(wDomainName);
893 if (!dict) {
894 wwarning(_("could not read domain \"%s\" from defaults database"), WMGetFromPLString(wDomainName));
897 return dict;
899 #endif
901 void wDefaultsDestroyDomain(WDDomain * domain)
903 if (domain->dictionary)
904 WMReleasePropList(domain->dictionary);
905 wfree(domain->path);
906 wfree(domain);
909 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
911 WDDomain *db;
912 struct stat stbuf;
913 static int inited = 0;
914 char path[PATH_MAX];
915 char *the_path;
916 WMPropList *shared_dict = NULL;
918 if (!inited) {
919 inited = 1;
920 initDefaults();
923 db = wmalloc(sizeof(WDDomain));
924 memset(db, 0, sizeof(WDDomain));
925 db->domain_name = domain;
926 db->path = wdefaultspathfordomain(domain);
927 the_path = db->path;
929 if (the_path && stat(the_path, &stbuf) >= 0) {
930 db->dictionary = WMReadPropListFromFile(the_path);
931 if (db->dictionary) {
932 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
933 WMReleasePropList(db->dictionary);
934 db->dictionary = NULL;
935 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
937 if (strcmp(domain, "WMWindowAttributes") == 0 && db->dictionary) {
938 if (fixupCachedPixmapsPaths(db->dictionary)) {
939 WMWritePropListToFile(db->dictionary, db->path, True);
940 /* re-read the timestamp. if this fails take current time */
941 if (stat(db->path, &stbuf) < 0) {
942 stbuf.st_mtime = time(NULL);
946 db->timestamp = stbuf.st_mtime;
947 } else {
948 wwarning(_("could not load domain %s from user defaults database"), domain);
952 /* global system dictionary */
953 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
954 if (stat(path, &stbuf) >= 0) {
955 shared_dict = WMReadPropListFromFile(path);
956 if (shared_dict) {
957 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
958 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
959 domain, path);
960 WMReleasePropList(shared_dict);
961 shared_dict = NULL;
962 } else {
963 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
964 WMIsPLDictionary(db->dictionary)) {
965 WMMergePLDictionaries(shared_dict, db->dictionary, True);
966 WMReleasePropList(db->dictionary);
967 db->dictionary = shared_dict;
968 if (stbuf.st_mtime > db->timestamp)
969 db->timestamp = stbuf.st_mtime;
970 } else if (!db->dictionary) {
971 db->dictionary = shared_dict;
972 if (stbuf.st_mtime > db->timestamp)
973 db->timestamp = stbuf.st_mtime;
976 } else {
977 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
981 return db;
984 void wReadStaticDefaults(WMPropList * dict)
986 WMPropList *plvalue;
987 WDefaultEntry *entry;
988 unsigned int i;
989 void *tdata;
991 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
992 entry = &staticOptionList[i];
994 if (dict)
995 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
996 else
997 plvalue = NULL;
999 if (!plvalue) {
1000 /* no default in the DB. Use builtin default */
1001 plvalue = entry->plvalue;
1004 if (plvalue) {
1005 /* convert data */
1006 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
1007 if (entry->update) {
1008 (*entry->update) (NULL, entry, tdata, entry->extra_data);
1014 void wDefaultsCheckDomains(void)
1016 WScreen *scr;
1017 struct stat stbuf;
1018 WMPropList *shared_dict = NULL;
1019 WMPropList *dict;
1020 int i;
1022 #ifdef HEARTBEAT
1023 puts("Checking domains...");
1024 #endif
1025 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1026 #ifdef HEARTBEAT
1027 puts("Checking WindowMaker domain");
1028 #endif
1029 WDWindowMaker->timestamp = stbuf.st_mtime;
1031 /* global dictionary */
1032 shared_dict = readGlobalDomain("WindowMaker", True);
1033 /* user dictionary */
1034 dict = WMReadPropListFromFile(WDWindowMaker->path);
1035 if (dict) {
1036 if (!WMIsPLDictionary(dict)) {
1037 WMReleasePropList(dict);
1038 dict = NULL;
1039 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1040 "WindowMaker", WDWindowMaker->path);
1041 } else {
1042 if (shared_dict) {
1043 WMMergePLDictionaries(shared_dict, dict, True);
1044 WMReleasePropList(dict);
1045 dict = shared_dict;
1046 shared_dict = NULL;
1048 for (i = 0; i < wScreenCount; i++) {
1049 scr = wScreenWithNumber(i);
1050 if (scr)
1051 wReadDefaults(scr, dict);
1053 if (WDWindowMaker->dictionary) {
1054 WMReleasePropList(WDWindowMaker->dictionary);
1056 WDWindowMaker->dictionary = dict;
1058 } else {
1059 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1061 if (shared_dict) {
1062 WMReleasePropList(shared_dict);
1066 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1067 #ifdef HEARTBEAT
1068 puts("Checking WMWindowAttributes domain");
1069 #endif
1070 /* global dictionary */
1071 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1072 /* user dictionary */
1073 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1074 if (dict) {
1075 if (!WMIsPLDictionary(dict)) {
1076 WMReleasePropList(dict);
1077 dict = NULL;
1078 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1079 "WMWindowAttributes", WDWindowAttributes->path);
1080 } else {
1081 if (shared_dict) {
1082 WMMergePLDictionaries(shared_dict, dict, True);
1083 WMReleasePropList(dict);
1084 dict = shared_dict;
1085 shared_dict = NULL;
1087 if (WDWindowAttributes->dictionary) {
1088 WMReleasePropList(WDWindowAttributes->dictionary);
1090 WDWindowAttributes->dictionary = dict;
1091 for (i = 0; i < wScreenCount; i++) {
1092 scr = wScreenWithNumber(i);
1093 if (scr) {
1094 RImage *image;
1096 wDefaultUpdateIcons(scr);
1098 /* Update the panel image if changed */
1099 /* Don't worry. If the image is the same these
1100 * functions will have no performance impact. */
1101 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1103 if (!image) {
1104 wwarning(_("could not load logo image for panels: %s"),
1105 RMessageForError(RErrorCode));
1106 } else {
1107 WMSetApplicationIconImage(scr->wmscreen, image);
1108 RReleaseImage(image);
1113 } else {
1114 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1116 WDWindowAttributes->timestamp = stbuf.st_mtime;
1117 if (shared_dict) {
1118 WMReleasePropList(shared_dict);
1122 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1123 dict = WMReadPropListFromFile(WDRootMenu->path);
1124 #ifdef HEARTBEAT
1125 puts("Checking WMRootMenu domain");
1126 #endif
1127 if (dict) {
1128 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1129 WMReleasePropList(dict);
1130 dict = NULL;
1131 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1132 "WMRootMenu", WDRootMenu->path);
1133 } else {
1134 if (WDRootMenu->dictionary) {
1135 WMReleasePropList(WDRootMenu->dictionary);
1137 WDRootMenu->dictionary = dict;
1138 wDefaultsMergeGlobalMenus(WDRootMenu);
1140 } else {
1141 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1143 WDRootMenu->timestamp = stbuf.st_mtime;
1147 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1149 WMPropList *plvalue, *old_value;
1150 WDefaultEntry *entry;
1151 unsigned int i, must_update;
1152 int update_workspace_back = 0; /* kluge :/ */
1153 unsigned int needs_refresh;
1154 void *tdata;
1155 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1157 must_update = 0;
1159 needs_refresh = 0;
1161 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1162 entry = &optionList[i];
1164 if (new_dict)
1165 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1166 else
1167 plvalue = NULL;
1169 if (!old_dict)
1170 old_value = NULL;
1171 else
1172 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1174 if (!plvalue && !old_value) {
1175 /* no default in the DB. Use builtin default */
1176 plvalue = entry->plvalue;
1177 if (plvalue && new_dict) {
1178 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1179 must_update = 1;
1181 } else if (!plvalue) {
1182 /* value was deleted from DB. Keep current value */
1183 continue;
1184 } else if (!old_value) {
1185 /* set value for the 1st time */
1186 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1187 /* value has changed */
1188 } else {
1190 if (strcmp(entry->key, "WorkspaceBack") == 0
1191 && update_workspace_back && scr->flags.backimage_helper_launched) {
1192 } else {
1193 /* value was not changed since last time */
1194 continue;
1198 if (plvalue) {
1199 #ifdef DEBUG
1200 printf("Updating %s to %s\n", entry->key, WMGetPropListDescription(plvalue, False));
1201 #endif
1202 /* convert data */
1203 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1205 * If the WorkspaceSpecificBack data has been changed
1206 * so that the helper will be launched now, we must be
1207 * sure to send the default background texture config
1208 * to the helper.
1210 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1211 && !scr->flags.backimage_helper_launched) {
1212 update_workspace_back = 1;
1214 if (entry->update) {
1215 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1221 if (needs_refresh != 0 && !scr->flags.startup) {
1222 int foo;
1224 foo = 0;
1225 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1226 foo |= WTextureSettings;
1227 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1228 foo |= WFontSettings;
1229 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1230 foo |= WColorSettings;
1231 if (foo)
1232 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1233 (void *)(uintptr_t) foo);
1235 foo = 0;
1236 if (needs_refresh & REFRESH_MENU_TEXTURE)
1237 foo |= WTextureSettings;
1238 if (needs_refresh & REFRESH_MENU_FONT)
1239 foo |= WFontSettings;
1240 if (needs_refresh & REFRESH_MENU_COLOR)
1241 foo |= WColorSettings;
1242 if (foo)
1243 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1245 foo = 0;
1246 if (needs_refresh & REFRESH_WINDOW_FONT) {
1247 foo |= WFontSettings;
1249 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1250 foo |= WTextureSettings;
1252 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1253 foo |= WColorSettings;
1255 if (foo)
1256 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1258 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1259 foo = 0;
1260 if (needs_refresh & REFRESH_ICON_FONT) {
1261 foo |= WFontSettings;
1263 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1264 foo |= WTextureSettings;
1266 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1267 foo |= WTextureSettings;
1269 if (foo)
1270 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1271 (void *)(uintptr_t) foo);
1273 if (needs_refresh & REFRESH_ICON_TILE)
1274 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1278 void wDefaultUpdateIcons(WScreen * scr)
1280 WAppIcon *aicon = scr->app_icon_list;
1281 WWindow *wwin = scr->focused_window;
1282 char *file;
1284 while (aicon) {
1285 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1286 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1287 || (file && !aicon->icon->file)) {
1288 RImage *new_image;
1290 if (aicon->icon->file)
1291 wfree(aicon->icon->file);
1292 aicon->icon->file = wstrdup(file);
1294 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1295 if (new_image) {
1296 wIconChangeImage(aicon->icon, new_image);
1297 wAppIconPaint(aicon);
1300 aicon = aicon->next;
1303 if (!wPreferences.flags.noclip)
1304 wClipIconPaint(scr->clip_icon);
1306 while (wwin) {
1307 if (wwin->icon && wwin->flags.miniaturized) {
1308 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1309 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1310 || (file && !wwin->icon->file)) {
1311 RImage *new_image;
1313 if (wwin->icon->file)
1314 wfree(wwin->icon->file);
1315 wwin->icon->file = wstrdup(file);
1317 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1318 if (new_image)
1319 wIconChangeImage(wwin->icon, new_image);
1322 wwin = wwin->prev;
1326 /* --------------------------- Local ----------------------- */
1328 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1329 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1330 entry->key, x); \
1331 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1332 var = entry->default_value;\
1333 } else var = WMGetFromPLString(value)\
1336 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1338 char *str;
1339 WOptionEnumeration *v;
1340 char buffer[TOTAL_VALUES_LENGTH];
1342 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1343 for (v = values; v->string != NULL; v++) {
1344 if (strcasecmp(v->string, str) == 0)
1345 return v->value;
1349 buffer[0] = 0;
1350 for (v = values; v->string != NULL; v++) {
1351 if (!v->is_alias) {
1352 if (buffer[0] != 0)
1353 strcat(buffer, ", ");
1354 strcat(buffer, v->string);
1357 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1359 if (def) {
1360 return string2index(key, val, NULL, values);
1363 return -1;
1367 * value - is the value in the defaults DB
1368 * addr - is the address to store the data
1369 * ret - is the address to store a pointer to a temporary buffer. ret
1370 * must not be freed and is used by the set functions
1372 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1374 static char data;
1375 char *val;
1376 int second_pass = 0;
1378 GET_STRING_OR_DEFAULT("Boolean", val);
1380 again:
1381 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1382 || strcasecmp(val, "YES") == 0) {
1384 data = 1;
1385 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1386 || strcasecmp(val, "NO") == 0) {
1387 data = 0;
1388 } else {
1389 int i;
1390 if (sscanf(val, "%i", &i) == 1) {
1391 if (i != 0)
1392 data = 1;
1393 else
1394 data = 0;
1395 } else {
1396 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1397 if (second_pass == 0) {
1398 val = WMGetFromPLString(entry->plvalue);
1399 second_pass = 1;
1400 wwarning(_("using default \"%s\" instead"), val);
1401 goto again;
1403 return False;
1407 if (ret)
1408 *ret = &data;
1409 if (addr)
1410 *(char *)addr = data;
1412 return True;
1415 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1417 static int data;
1418 char *val;
1420 GET_STRING_OR_DEFAULT("Integer", val);
1422 if (sscanf(val, "%i", &data) != 1) {
1423 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1424 val = WMGetFromPLString(entry->plvalue);
1425 wwarning(_("using default \"%s\" instead"), val);
1426 if (sscanf(val, "%i", &data) != 1) {
1427 return False;
1431 if (ret)
1432 *ret = &data;
1433 if (addr)
1434 *(int *)addr = data;
1436 return True;
1439 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1441 static WCoord data;
1442 char *val_x, *val_y;
1443 int nelem, changed = 0;
1444 WMPropList *elem_x, *elem_y;
1446 again:
1447 if (!WMIsPLArray(value)) {
1448 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1449 if (changed == 0) {
1450 value = entry->plvalue;
1451 changed = 1;
1452 wwarning(_("using default \"%s\" instead"), entry->default_value);
1453 goto again;
1455 return False;
1458 nelem = WMGetPropListItemCount(value);
1459 if (nelem != 2) {
1460 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1461 if (changed == 0) {
1462 value = entry->plvalue;
1463 changed = 1;
1464 wwarning(_("using default \"%s\" instead"), entry->default_value);
1465 goto again;
1467 return False;
1470 elem_x = WMGetFromPLArray(value, 0);
1471 elem_y = WMGetFromPLArray(value, 1);
1473 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1474 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1475 if (changed == 0) {
1476 value = entry->plvalue;
1477 changed = 1;
1478 wwarning(_("using default \"%s\" instead"), entry->default_value);
1479 goto again;
1481 return False;
1484 val_x = WMGetFromPLString(elem_x);
1485 val_y = WMGetFromPLString(elem_y);
1487 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1488 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1489 if (changed == 0) {
1490 value = entry->plvalue;
1491 changed = 1;
1492 wwarning(_("using default \"%s\" instead"), entry->default_value);
1493 goto again;
1495 return False;
1498 if (data.x < 0)
1499 data.x = 0;
1500 else if (data.x > scr->scr_width / 3)
1501 data.x = scr->scr_width / 3;
1502 if (data.y < 0)
1503 data.y = 0;
1504 else if (data.y > scr->scr_height / 3)
1505 data.y = scr->scr_height / 3;
1507 if (ret)
1508 *ret = &data;
1509 if (addr)
1510 *(WCoord *) addr = data;
1512 return True;
1515 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1517 WMRetainPropList(value);
1519 *ret = value;
1521 return True;
1524 #if 0
1525 /* This function is not used at the moment. */
1526 static int getString(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1528 static char *data;
1530 GET_STRING_OR_DEFAULT("String", data);
1532 if (!data) {
1533 data = WMGetFromPLString(entry->plvalue);
1534 if (!data)
1535 return False;
1538 if (ret)
1539 *ret = &data;
1540 if (addr)
1541 *(char **)addr = wstrdup(data);
1543 return True;
1545 #endif
1547 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1549 static char *data;
1550 int i, count, len;
1551 char *ptr;
1552 WMPropList *d;
1553 int changed = 0;
1555 again:
1556 if (!WMIsPLArray(value)) {
1557 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1558 if (changed == 0) {
1559 value = entry->plvalue;
1560 changed = 1;
1561 wwarning(_("using default \"%s\" instead"), entry->default_value);
1562 goto again;
1564 return False;
1567 i = 0;
1568 count = WMGetPropListItemCount(value);
1569 if (count < 1) {
1570 if (changed == 0) {
1571 value = entry->plvalue;
1572 changed = 1;
1573 wwarning(_("using default \"%s\" instead"), entry->default_value);
1574 goto again;
1576 return False;
1579 len = 0;
1580 for (i = 0; i < count; i++) {
1581 d = WMGetFromPLArray(value, i);
1582 if (!d || !WMIsPLString(d)) {
1583 count = i;
1584 break;
1586 len += strlen(WMGetFromPLString(d)) + 1;
1589 ptr = data = wmalloc(len + 1);
1591 for (i = 0; i < count; i++) {
1592 d = WMGetFromPLArray(value, i);
1593 if (!d || !WMIsPLString(d)) {
1594 break;
1596 strcpy(ptr, WMGetFromPLString(d));
1597 ptr += strlen(WMGetFromPLString(d));
1598 *ptr = ':';
1599 ptr++;
1601 ptr--;
1602 *(ptr--) = 0;
1604 if (*(char **)addr != NULL) {
1605 wfree(*(char **)addr);
1607 *(char **)addr = data;
1609 return True;
1612 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1614 static signed char data;
1616 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1617 if (data < 0)
1618 return False;
1620 if (ret)
1621 *ret = &data;
1622 if (addr)
1623 *(signed char *)addr = data;
1625 return True;
1629 * (solid <color>)
1630 * (hgradient <color> <color>)
1631 * (vgradient <color> <color>)
1632 * (dgradient <color> <color>)
1633 * (mhgradient <color> <color> ...)
1634 * (mvgradient <color> <color> ...)
1635 * (mdgradient <color> <color> ...)
1636 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1637 * (tpixmap <file> <color>)
1638 * (spixmap <file> <color>)
1639 * (cpixmap <file> <color>)
1640 * (thgradient <file> <opaqueness> <color> <color>)
1641 * (tvgradient <file> <opaqueness> <color> <color>)
1642 * (tdgradient <file> <opaqueness> <color> <color>)
1643 * (function <lib> <function> ...)
1646 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1648 WMPropList *elem;
1649 char *val;
1650 int nelem;
1651 WTexture *texture = NULL;
1653 nelem = WMGetPropListItemCount(pl);
1654 if (nelem < 1)
1655 return NULL;
1657 elem = WMGetFromPLArray(pl, 0);
1658 if (!elem || !WMIsPLString(elem))
1659 return NULL;
1660 val = WMGetFromPLString(elem);
1662 if (strcasecmp(val, "solid") == 0) {
1663 XColor color;
1665 if (nelem != 2)
1666 return NULL;
1668 /* get color */
1670 elem = WMGetFromPLArray(pl, 1);
1671 if (!elem || !WMIsPLString(elem))
1672 return NULL;
1673 val = WMGetFromPLString(elem);
1675 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1676 wwarning(_("\"%s\" is not a valid color name"), val);
1677 return NULL;
1680 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1681 } else if (strcasecmp(val, "dgradient") == 0
1682 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1683 RColor color1, color2;
1684 XColor xcolor;
1685 int type;
1687 if (nelem != 3) {
1688 wwarning(_("bad number of arguments in gradient specification"));
1689 return NULL;
1692 if (val[0] == 'd' || val[0] == 'D')
1693 type = WTEX_DGRADIENT;
1694 else if (val[0] == 'h' || val[0] == 'H')
1695 type = WTEX_HGRADIENT;
1696 else
1697 type = WTEX_VGRADIENT;
1699 /* get from color */
1700 elem = WMGetFromPLArray(pl, 1);
1701 if (!elem || !WMIsPLString(elem))
1702 return NULL;
1703 val = WMGetFromPLString(elem);
1705 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1706 wwarning(_("\"%s\" is not a valid color name"), val);
1707 return NULL;
1709 color1.alpha = 255;
1710 color1.red = xcolor.red >> 8;
1711 color1.green = xcolor.green >> 8;
1712 color1.blue = xcolor.blue >> 8;
1714 /* get to color */
1715 elem = WMGetFromPLArray(pl, 2);
1716 if (!elem || !WMIsPLString(elem)) {
1717 return NULL;
1719 val = WMGetFromPLString(elem);
1721 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1722 wwarning(_("\"%s\" is not a valid color name"), val);
1723 return NULL;
1725 color2.alpha = 255;
1726 color2.red = xcolor.red >> 8;
1727 color2.green = xcolor.green >> 8;
1728 color2.blue = xcolor.blue >> 8;
1730 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1732 } else if (strcasecmp(val, "igradient") == 0) {
1733 RColor colors1[2], colors2[2];
1734 int th1, th2;
1735 XColor xcolor;
1736 int i;
1738 if (nelem != 7) {
1739 wwarning(_("bad number of arguments in gradient specification"));
1740 return NULL;
1743 /* get from color */
1744 for (i = 0; i < 2; i++) {
1745 elem = WMGetFromPLArray(pl, 1 + i);
1746 if (!elem || !WMIsPLString(elem))
1747 return NULL;
1748 val = WMGetFromPLString(elem);
1750 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1751 wwarning(_("\"%s\" is not a valid color name"), val);
1752 return NULL;
1754 colors1[i].alpha = 255;
1755 colors1[i].red = xcolor.red >> 8;
1756 colors1[i].green = xcolor.green >> 8;
1757 colors1[i].blue = xcolor.blue >> 8;
1759 elem = WMGetFromPLArray(pl, 3);
1760 if (!elem || !WMIsPLString(elem))
1761 return NULL;
1762 val = WMGetFromPLString(elem);
1763 th1 = atoi(val);
1765 /* get from color */
1766 for (i = 0; i < 2; i++) {
1767 elem = WMGetFromPLArray(pl, 4 + i);
1768 if (!elem || !WMIsPLString(elem))
1769 return NULL;
1770 val = WMGetFromPLString(elem);
1772 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1773 wwarning(_("\"%s\" is not a valid color name"), val);
1774 return NULL;
1776 colors2[i].alpha = 255;
1777 colors2[i].red = xcolor.red >> 8;
1778 colors2[i].green = xcolor.green >> 8;
1779 colors2[i].blue = xcolor.blue >> 8;
1781 elem = WMGetFromPLArray(pl, 6);
1782 if (!elem || !WMIsPLString(elem))
1783 return NULL;
1784 val = WMGetFromPLString(elem);
1785 th2 = atoi(val);
1787 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1789 } else if (strcasecmp(val, "mhgradient") == 0
1790 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1791 XColor color;
1792 RColor **colors;
1793 int i, count;
1794 int type;
1796 if (nelem < 3) {
1797 wwarning(_("too few arguments in multicolor gradient specification"));
1798 return NULL;
1801 if (val[1] == 'h' || val[1] == 'H')
1802 type = WTEX_MHGRADIENT;
1803 else if (val[1] == 'v' || val[1] == 'V')
1804 type = WTEX_MVGRADIENT;
1805 else
1806 type = WTEX_MDGRADIENT;
1808 count = nelem - 1;
1810 colors = wmalloc(sizeof(RColor *) * (count + 1));
1812 for (i = 0; i < count; i++) {
1813 elem = WMGetFromPLArray(pl, i + 1);
1814 if (!elem || !WMIsPLString(elem)) {
1815 for (--i; i >= 0; --i) {
1816 wfree(colors[i]);
1818 wfree(colors);
1819 return NULL;
1821 val = WMGetFromPLString(elem);
1823 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1824 wwarning(_("\"%s\" is not a valid color name"), val);
1825 for (--i; i >= 0; --i) {
1826 wfree(colors[i]);
1828 wfree(colors);
1829 return NULL;
1830 } else {
1831 colors[i] = wmalloc(sizeof(RColor));
1832 colors[i]->red = color.red >> 8;
1833 colors[i]->green = color.green >> 8;
1834 colors[i]->blue = color.blue >> 8;
1837 colors[i] = NULL;
1839 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1840 } else if (strcasecmp(val, "spixmap") == 0 ||
1841 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1842 XColor color;
1843 int type;
1845 if (nelem != 3)
1846 return NULL;
1848 if (val[0] == 's' || val[0] == 'S')
1849 type = WTP_SCALE;
1850 else if (val[0] == 'c' || val[0] == 'C')
1851 type = WTP_CENTER;
1852 else
1853 type = WTP_TILE;
1855 /* get color */
1856 elem = WMGetFromPLArray(pl, 2);
1857 if (!elem || !WMIsPLString(elem)) {
1858 return NULL;
1860 val = WMGetFromPLString(elem);
1862 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1863 wwarning(_("\"%s\" is not a valid color name"), val);
1864 return NULL;
1867 /* file name */
1868 elem = WMGetFromPLArray(pl, 1);
1869 if (!elem || !WMIsPLString(elem))
1870 return NULL;
1871 val = WMGetFromPLString(elem);
1873 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1874 } else if (strcasecmp(val, "thgradient") == 0
1875 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1876 RColor color1, color2;
1877 XColor xcolor;
1878 int opacity;
1879 int style;
1881 if (val[1] == 'h' || val[1] == 'H')
1882 style = WTEX_THGRADIENT;
1883 else if (val[1] == 'v' || val[1] == 'V')
1884 style = WTEX_TVGRADIENT;
1885 else
1886 style = WTEX_TDGRADIENT;
1888 if (nelem != 5) {
1889 wwarning(_("bad number of arguments in textured gradient specification"));
1890 return NULL;
1893 /* get from color */
1894 elem = WMGetFromPLArray(pl, 3);
1895 if (!elem || !WMIsPLString(elem))
1896 return NULL;
1897 val = WMGetFromPLString(elem);
1899 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1900 wwarning(_("\"%s\" is not a valid color name"), val);
1901 return NULL;
1903 color1.alpha = 255;
1904 color1.red = xcolor.red >> 8;
1905 color1.green = xcolor.green >> 8;
1906 color1.blue = xcolor.blue >> 8;
1908 /* get to color */
1909 elem = WMGetFromPLArray(pl, 4);
1910 if (!elem || !WMIsPLString(elem)) {
1911 return NULL;
1913 val = WMGetFromPLString(elem);
1915 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1916 wwarning(_("\"%s\" is not a valid color name"), val);
1917 return NULL;
1919 color2.alpha = 255;
1920 color2.red = xcolor.red >> 8;
1921 color2.green = xcolor.green >> 8;
1922 color2.blue = xcolor.blue >> 8;
1924 /* get opacity */
1925 elem = WMGetFromPLArray(pl, 2);
1926 if (!elem || !WMIsPLString(elem))
1927 opacity = 128;
1928 else
1929 val = WMGetFromPLString(elem);
1931 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1932 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1933 opacity = 128;
1936 /* get file name */
1937 elem = WMGetFromPLArray(pl, 1);
1938 if (!elem || !WMIsPLString(elem))
1939 return NULL;
1940 val = WMGetFromPLString(elem);
1942 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1944 #ifdef TEXTURE_PLUGIN
1945 else if (strcasecmp(val, "function") == 0) {
1946 WTexFunction *function;
1947 void (*initFunc) (Display *, Colormap);
1948 char *lib, *func, **argv;
1949 int i, argc;
1951 if (nelem < 3)
1952 return NULL;
1954 /* get the library name */
1955 elem = WMGetFromPLArray(pl, 1);
1956 if (!elem || !WMIsPLString(elem)) {
1957 return NULL;
1959 lib = WMGetFromPLString(elem);
1961 /* get the function name */
1962 elem = WMGetFromPLArray(pl, 2);
1963 if (!elem || !WMIsPLString(elem)) {
1964 return NULL;
1966 func = WMGetFromPLString(elem);
1968 argc = nelem - 2;
1969 argv = (char **)wmalloc(argc * sizeof(char *));
1971 /* get the parameters */
1972 argv[0] = wstrdup(func);
1973 for (i = 0; i < argc - 1; i++) {
1974 elem = WMGetFromPLArray(pl, 3 + i);
1975 if (!elem || !WMIsPLString(elem)) {
1976 wfree(argv);
1978 return NULL;
1980 argv[i + 1] = wstrdup(WMGetFromPLString(elem));
1983 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1985 #ifdef HAVE_DLFCN_H
1986 if (function) {
1987 initFunc = dlsym(function->handle, "initWindowMaker");
1988 if (initFunc) {
1989 initFunc(dpy, scr->w_colormap);
1990 } else {
1991 wwarning(_("could not initialize library %s"), lib);
1993 } else {
1994 wwarning(_("could not find function %s::%s"), lib, func);
1996 #endif /* HAVE_DLFCN_H */
1997 texture = (WTexture *) function;
1999 #endif /* TEXTURE_PLUGIN */
2000 else {
2001 wwarning(_("invalid texture type %s"), val);
2002 return NULL;
2004 return texture;
2007 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2009 static WTexture *texture;
2010 int changed = 0;
2012 again:
2013 if (!WMIsPLArray(value)) {
2014 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
2015 if (changed == 0) {
2016 value = entry->plvalue;
2017 changed = 1;
2018 wwarning(_("using default \"%s\" instead"), entry->default_value);
2019 goto again;
2021 return False;
2024 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
2025 WMPropList *pl;
2027 pl = WMGetFromPLArray(value, 0);
2028 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2029 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
2030 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2031 entry->key, "Solid Texture");
2033 value = entry->plvalue;
2034 changed = 1;
2035 wwarning(_("using default \"%s\" instead"), entry->default_value);
2036 goto again;
2040 texture = parse_texture(scr, value);
2042 if (!texture) {
2043 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
2044 if (changed == 0) {
2045 value = entry->plvalue;
2046 changed = 1;
2047 wwarning(_("using default \"%s\" instead"), entry->default_value);
2048 goto again;
2050 return False;
2053 if (ret)
2054 *ret = &texture;
2056 if (addr)
2057 *(WTexture **) addr = texture;
2059 return True;
2062 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2064 WMPropList *elem;
2065 int changed = 0;
2066 char *val;
2067 int nelem;
2069 again:
2070 if (!WMIsPLArray(value)) {
2071 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2072 "WorkspaceBack", "Texture or None");
2073 if (changed == 0) {
2074 value = entry->plvalue;
2075 changed = 1;
2076 wwarning(_("using default \"%s\" instead"), entry->default_value);
2077 goto again;
2079 return False;
2082 /* only do basic error checking and verify for None texture */
2084 nelem = WMGetPropListItemCount(value);
2085 if (nelem > 0) {
2086 elem = WMGetFromPLArray(value, 0);
2087 if (!elem || !WMIsPLString(elem)) {
2088 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2089 if (changed == 0) {
2090 value = entry->plvalue;
2091 changed = 1;
2092 wwarning(_("using default \"%s\" instead"), entry->default_value);
2093 goto again;
2095 return False;
2097 val = WMGetFromPLString(elem);
2099 if (strcasecmp(val, "None") == 0)
2100 return True;
2102 *ret = WMRetainPropList(value);
2104 return True;
2107 static int
2108 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2110 WMPropList *elem;
2111 int nelem;
2112 int changed = 0;
2114 again:
2115 if (!WMIsPLArray(value)) {
2116 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2117 "WorkspaceSpecificBack", "an array of textures");
2118 if (changed == 0) {
2119 value = entry->plvalue;
2120 changed = 1;
2121 wwarning(_("using default \"%s\" instead"), entry->default_value);
2122 goto again;
2124 return False;
2127 /* only do basic error checking and verify for None texture */
2129 nelem = WMGetPropListItemCount(value);
2130 if (nelem > 0) {
2131 while (nelem--) {
2132 elem = WMGetFromPLArray(value, nelem);
2133 if (!elem || !WMIsPLArray(elem)) {
2134 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2135 nelem);
2140 *ret = WMRetainPropList(value);
2142 #ifdef notworking
2144 * Kluge to force wmsetbg helper to set the default background.
2145 * If the WorkspaceSpecificBack is changed once wmaker has started,
2146 * the WorkspaceBack won't be sent to the helper, unless the user
2147 * changes it's value too. So, we must force this by removing the
2148 * value from the defaults DB.
2150 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2151 WMPropList *key = WMCreatePLString("WorkspaceBack");
2153 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2155 WMReleasePropList(key);
2157 #endif
2158 return True;
2161 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2163 static WMFont *font;
2164 char *val;
2166 GET_STRING_OR_DEFAULT("Font", val);
2168 font = WMCreateFont(scr->wmscreen, val);
2169 if (!font)
2170 font = WMCreateFont(scr->wmscreen, "fixed");
2172 if (!font) {
2173 wfatal(_("could not load any usable font!!!"));
2174 exit(1);
2177 if (ret)
2178 *ret = font;
2180 /* can't assign font value outside update function */
2181 wassertrv(addr == NULL, True);
2183 return True;
2186 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2188 static XColor color;
2189 char *val;
2190 int second_pass = 0;
2192 GET_STRING_OR_DEFAULT("Color", val);
2194 again:
2195 if (!wGetColor(scr, val, &color)) {
2196 wwarning(_("could not get color for key \"%s\""), entry->key);
2197 if (second_pass == 0) {
2198 val = WMGetFromPLString(entry->plvalue);
2199 second_pass = 1;
2200 wwarning(_("using default \"%s\" instead"), val);
2201 goto again;
2203 return False;
2206 if (ret)
2207 *ret = &color;
2209 assert(addr == NULL);
2211 if (addr)
2212 *(unsigned long*)addr = pixel;
2215 return True;
2218 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2220 static WShortKey shortcut;
2221 KeySym ksym;
2222 char *val;
2223 char *k;
2224 char buf[MAX_SHORTCUT_LENGTH], *b;
2226 GET_STRING_OR_DEFAULT("Key spec", val);
2228 if (!val || strcasecmp(val, "NONE") == 0) {
2229 shortcut.keycode = 0;
2230 shortcut.modifier = 0;
2231 if (ret)
2232 *ret = &shortcut;
2233 return True;
2236 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2238 b = (char *)buf;
2240 /* get modifiers */
2241 shortcut.modifier = 0;
2242 while ((k = strchr(b, '+')) != NULL) {
2243 int mod;
2245 *k = 0;
2246 mod = wXModifierFromKey(b);
2247 if (mod < 0) {
2248 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2249 return False;
2251 shortcut.modifier |= mod;
2253 b = k + 1;
2256 /* get key */
2257 ksym = XStringToKeysym(b);
2259 if (ksym == NoSymbol) {
2260 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2261 return False;
2264 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2265 if (shortcut.keycode == 0) {
2266 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2267 return False;
2270 if (ret)
2271 *ret = &shortcut;
2273 return True;
2276 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2278 static int mask;
2279 char *str;
2281 GET_STRING_OR_DEFAULT("Modifier Key", str);
2283 if (!str)
2284 return False;
2286 mask = wXModifierFromKey(str);
2287 if (mask < 0) {
2288 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2289 mask = 0;
2290 return False;
2293 if (addr)
2294 *(int *)addr = mask;
2296 if (ret)
2297 *ret = &mask;
2299 return True;
2302 #ifdef NEWSTUFF
2303 static int getRImages(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2305 unsigned int mask;
2306 char *str;
2307 RImage *image;
2308 int i, n;
2309 int w, h;
2311 GET_STRING_OR_DEFAULT("Image File Path", str);
2312 if (!str)
2313 return False;
2315 image = RLoadImage(scr->rcontext, str, 0);
2316 if (!image) {
2317 wwarning(_("could not load image in option %s: %s"), entry->key, RMessageForError(RErrorCode));
2318 return False;
2321 if (*(RImage **) addr) {
2322 RReleaseImage(*(RImage **) addr);
2324 if (addr)
2325 *(RImage **) addr = image;
2327 assert(ret == NULL);
2329 if (ret)
2330 *(RImage**)ret = image;
2333 return True;
2335 #endif
2337 # include <X11/cursorfont.h>
2338 typedef struct {
2339 char *name;
2340 int id;
2341 } WCursorLookup;
2343 #define CURSOR_ID_NONE (XC_num_glyphs)
2345 static WCursorLookup cursor_table[] = {
2346 {"X_cursor", XC_X_cursor},
2347 {"arrow", XC_arrow},
2348 {"based_arrow_down", XC_based_arrow_down},
2349 {"based_arrow_up", XC_based_arrow_up},
2350 {"boat", XC_boat},
2351 {"bogosity", XC_bogosity},
2352 {"bottom_left_corner", XC_bottom_left_corner},
2353 {"bottom_right_corner", XC_bottom_right_corner},
2354 {"bottom_side", XC_bottom_side},
2355 {"bottom_tee", XC_bottom_tee},
2356 {"box_spiral", XC_box_spiral},
2357 {"center_ptr", XC_center_ptr},
2358 {"circle", XC_circle},
2359 {"clock", XC_clock},
2360 {"coffee_mug", XC_coffee_mug},
2361 {"cross", XC_cross},
2362 {"cross_reverse", XC_cross_reverse},
2363 {"crosshair", XC_crosshair},
2364 {"diamond_cross", XC_diamond_cross},
2365 {"dot", XC_dot},
2366 {"dotbox", XC_dotbox},
2367 {"double_arrow", XC_double_arrow},
2368 {"draft_large", XC_draft_large},
2369 {"draft_small", XC_draft_small},
2370 {"draped_box", XC_draped_box},
2371 {"exchange", XC_exchange},
2372 {"fleur", XC_fleur},
2373 {"gobbler", XC_gobbler},
2374 {"gumby", XC_gumby},
2375 {"hand1", XC_hand1},
2376 {"hand2", XC_hand2},
2377 {"heart", XC_heart},
2378 {"icon", XC_icon},
2379 {"iron_cross", XC_iron_cross},
2380 {"left_ptr", XC_left_ptr},
2381 {"left_side", XC_left_side},
2382 {"left_tee", XC_left_tee},
2383 {"leftbutton", XC_leftbutton},
2384 {"ll_angle", XC_ll_angle},
2385 {"lr_angle", XC_lr_angle},
2386 {"man", XC_man},
2387 {"middlebutton", XC_middlebutton},
2388 {"mouse", XC_mouse},
2389 {"pencil", XC_pencil},
2390 {"pirate", XC_pirate},
2391 {"plus", XC_plus},
2392 {"question_arrow", XC_question_arrow},
2393 {"right_ptr", XC_right_ptr},
2394 {"right_side", XC_right_side},
2395 {"right_tee", XC_right_tee},
2396 {"rightbutton", XC_rightbutton},
2397 {"rtl_logo", XC_rtl_logo},
2398 {"sailboat", XC_sailboat},
2399 {"sb_down_arrow", XC_sb_down_arrow},
2400 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2401 {"sb_left_arrow", XC_sb_left_arrow},
2402 {"sb_right_arrow", XC_sb_right_arrow},
2403 {"sb_up_arrow", XC_sb_up_arrow},
2404 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2405 {"shuttle", XC_shuttle},
2406 {"sizing", XC_sizing},
2407 {"spider", XC_spider},
2408 {"spraycan", XC_spraycan},
2409 {"star", XC_star},
2410 {"target", XC_target},
2411 {"tcross", XC_tcross},
2412 {"top_left_arrow", XC_top_left_arrow},
2413 {"top_left_corner", XC_top_left_corner},
2414 {"top_right_corner", XC_top_right_corner},
2415 {"top_side", XC_top_side},
2416 {"top_tee", XC_top_tee},
2417 {"trek", XC_trek},
2418 {"ul_angle", XC_ul_angle},
2419 {"umbrella", XC_umbrella},
2420 {"ur_angle", XC_ur_angle},
2421 {"watch", XC_watch},
2422 {"xterm", XC_xterm},
2423 {NULL, CURSOR_ID_NONE}
2426 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2428 switch (status) {
2429 case BitmapOpenFailed:
2430 wwarning(_("failed to open bitmap file \"%s\""), filename);
2431 break;
2432 case BitmapFileInvalid:
2433 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2434 break;
2435 case BitmapNoMemory:
2436 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2437 break;
2438 case BitmapSuccess:
2439 XFreePixmap(dpy, bitmap);
2440 break;
2445 * (none)
2446 * (builtin, <cursor_name>)
2447 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2449 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2451 WMPropList *elem;
2452 char *val;
2453 int nelem;
2454 int status = 0;
2456 nelem = WMGetPropListItemCount(pl);
2457 if (nelem < 1) {
2458 return (status);
2460 elem = WMGetFromPLArray(pl, 0);
2461 if (!elem || !WMIsPLString(elem)) {
2462 return (status);
2464 val = WMGetFromPLString(elem);
2466 if (0 == strcasecmp(val, "none")) {
2467 status = 1;
2468 *cursor = None;
2469 } else if (0 == strcasecmp(val, "builtin")) {
2470 int i;
2471 int cursor_id = CURSOR_ID_NONE;
2473 if (2 != nelem) {
2474 wwarning(_("bad number of arguments in cursor specification"));
2475 return (status);
2477 elem = WMGetFromPLArray(pl, 1);
2478 if (!elem || !WMIsPLString(elem)) {
2479 return (status);
2481 val = WMGetFromPLString(elem);
2483 for (i = 0; NULL != cursor_table[i].name; i++) {
2484 if (0 == strcasecmp(val, cursor_table[i].name)) {
2485 cursor_id = cursor_table[i].id;
2486 break;
2489 if (CURSOR_ID_NONE == cursor_id) {
2490 wwarning(_("unknown builtin cursor name \"%s\""), val);
2491 } else {
2492 *cursor = XCreateFontCursor(dpy, cursor_id);
2493 status = 1;
2495 } else if (0 == strcasecmp(val, "bitmap")) {
2496 char *bitmap_name;
2497 char *mask_name;
2498 int bitmap_status;
2499 int mask_status;
2500 Pixmap bitmap;
2501 Pixmap mask;
2502 unsigned int w, h;
2503 int x, y;
2504 XColor fg, bg;
2506 if (3 != nelem) {
2507 wwarning(_("bad number of arguments in cursor specification"));
2508 return (status);
2510 elem = WMGetFromPLArray(pl, 1);
2511 if (!elem || !WMIsPLString(elem)) {
2512 return (status);
2514 val = WMGetFromPLString(elem);
2515 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2516 if (!bitmap_name) {
2517 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2518 return (status);
2520 elem = WMGetFromPLArray(pl, 2);
2521 if (!elem || !WMIsPLString(elem)) {
2522 wfree(bitmap_name);
2523 return (status);
2525 val = WMGetFromPLString(elem);
2526 mask_name = FindImage(wPreferences.pixmap_path, val);
2527 if (!mask_name) {
2528 wfree(bitmap_name);
2529 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2530 return (status);
2532 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2533 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2534 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2535 fg.pixel = scr->black_pixel;
2536 bg.pixel = scr->white_pixel;
2537 XQueryColor(dpy, scr->w_colormap, &fg);
2538 XQueryColor(dpy, scr->w_colormap, &bg);
2539 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2540 status = 1;
2542 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2543 check_bitmap_status(mask_status, mask_name, mask);
2544 wfree(bitmap_name);
2545 wfree(mask_name);
2547 return (status);
2550 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2552 static Cursor cursor;
2553 int status;
2554 int changed = 0;
2556 again:
2557 if (!WMIsPLArray(value)) {
2558 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2559 entry->key, "cursor specification");
2560 if (!changed) {
2561 value = entry->plvalue;
2562 changed = 1;
2563 wwarning(_("using default \"%s\" instead"), entry->default_value);
2564 goto again;
2566 return (False);
2568 status = parse_cursor(scr, value, &cursor);
2569 if (!status) {
2570 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2571 if (!changed) {
2572 value = entry->plvalue;
2573 changed = 1;
2574 wwarning(_("using default \"%s\" instead"), entry->default_value);
2575 goto again;
2577 return (False);
2579 if (ret) {
2580 *ret = &cursor;
2582 if (addr) {
2583 *(Cursor *) addr = cursor;
2585 return (True);
2588 #undef CURSOR_ID_NONE
2590 /* ---------------- value setting functions --------------- */
2591 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2593 return REFRESH_WINDOW_TITLE_COLOR;
2596 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2598 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2601 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2603 switch (which) {
2604 case WM_DOCK:
2605 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2606 break;
2607 case WM_CLIP:
2608 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2609 break;
2610 default:
2611 break;
2613 return 0;
2616 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2618 if (scr->workspaces) {
2619 wWorkspaceForceChange(scr, scr->current_workspace);
2620 wArrangeIcons(scr, False);
2622 return 0;
2625 #if not_used
2626 static int setPositive(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2628 if (*value <= 0)
2629 *(int *)foo = 1;
2631 return 0;
2633 #endif
2635 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2637 Pixmap pixmap;
2638 RImage *img;
2639 int reset = 0;
2641 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2642 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2643 ? WREL_ICON : WREL_FLAT);
2644 if (!img) {
2645 wwarning(_("could not render texture for icon background"));
2646 if (!entry->addr)
2647 wTextureDestroy(scr, *texture);
2648 return 0;
2650 RConvertImage(scr->rcontext, img, &pixmap);
2652 if (scr->icon_tile) {
2653 reset = 1;
2654 RReleaseImage(scr->icon_tile);
2655 XFreePixmap(dpy, scr->icon_tile_pixmap);
2658 scr->icon_tile = img;
2660 /* put the icon in the noticeboard hint */
2661 PropSetIconTileHint(scr, img);
2663 if (!wPreferences.flags.noclip) {
2664 if (scr->clip_tile) {
2665 RReleaseImage(scr->clip_tile);
2667 scr->clip_tile = wClipMakeTile(scr, img);
2670 scr->icon_tile_pixmap = pixmap;
2672 if (scr->def_icon_pixmap) {
2673 XFreePixmap(dpy, scr->def_icon_pixmap);
2674 scr->def_icon_pixmap = None;
2676 if (scr->def_ticon_pixmap) {
2677 XFreePixmap(dpy, scr->def_ticon_pixmap);
2678 scr->def_ticon_pixmap = None;
2681 if (scr->icon_back_texture) {
2682 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2684 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2686 if (scr->clip_balloon)
2687 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2690 * Free the texture as nobody else will use it, nor refer to it.
2692 if (!entry->addr)
2693 wTextureDestroy(scr, *texture);
2695 return (reset ? REFRESH_ICON_TILE : 0);
2698 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2700 if (scr->title_font) {
2701 WMReleaseFont(scr->title_font);
2703 scr->title_font = font;
2705 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2708 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2710 if (scr->menu_title_font) {
2711 WMReleaseFont(scr->menu_title_font);
2714 scr->menu_title_font = font;
2716 return REFRESH_MENU_TITLE_FONT;
2719 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2721 if (scr->menu_entry_font) {
2722 WMReleaseFont(scr->menu_entry_font);
2724 scr->menu_entry_font = font;
2726 return REFRESH_MENU_FONT;
2729 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2731 if (scr->icon_title_font) {
2732 WMReleaseFont(scr->icon_title_font);
2735 scr->icon_title_font = font;
2737 return REFRESH_ICON_FONT;
2740 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2742 if (scr->clip_title_font) {
2743 WMReleaseFont(scr->clip_title_font);
2746 scr->clip_title_font = font;
2748 return REFRESH_ICON_FONT;
2751 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2753 if (scr->workspace_name_font) {
2754 WMReleaseFont(scr->workspace_name_font);
2757 scr->workspace_name_font = font;
2759 return 0;
2762 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2764 if (scr->select_color)
2765 WMReleaseColor(scr->select_color);
2767 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2769 wFreeColor(scr, color->pixel);
2771 return REFRESH_MENU_COLOR;
2774 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2776 if (scr->select_text_color)
2777 WMReleaseColor(scr->select_text_color);
2779 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2781 wFreeColor(scr, color->pixel);
2783 return REFRESH_MENU_COLOR;
2786 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2788 if (scr->clip_title_color[widx])
2789 WMReleaseColor(scr->clip_title_color[widx]);
2790 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2791 #ifdef GRADIENT_CLIP_ARROW
2792 if (widx == CLIP_NORMAL) {
2793 RImage *image;
2794 RColor color1, color2;
2795 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2796 int as = pt - 15; /* 15 = 5+5+5 */
2798 FREE_PIXMAP(scr->clip_arrow_gradient);
2800 color1.red = (color->red >> 8) * 6 / 10;
2801 color1.green = (color->green >> 8) * 6 / 10;
2802 color1.blue = (color->blue >> 8) * 6 / 10;
2804 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2805 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2806 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2808 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2809 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2810 RReleaseImage(image);
2812 #endif /* GRADIENT_CLIP_ARROW */
2814 wFreeColor(scr, color->pixel);
2816 return REFRESH_ICON_TITLE_COLOR;
2819 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2821 if (scr->window_title_color[widx])
2822 WMReleaseColor(scr->window_title_color[widx]);
2824 scr->window_title_color[widx] =
2825 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2827 wFreeColor(scr, color->pixel);
2829 return REFRESH_WINDOW_TITLE_COLOR;
2832 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2834 if (scr->menu_title_color[0])
2835 WMReleaseColor(scr->menu_title_color[0]);
2837 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2839 wFreeColor(scr, color->pixel);
2841 return REFRESH_MENU_TITLE_COLOR;
2844 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2846 if (scr->mtext_color)
2847 WMReleaseColor(scr->mtext_color);
2849 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2851 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2852 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2853 } else {
2854 WMSetColorAlpha(scr->dtext_color, 0xffff);
2857 wFreeColor(scr, color->pixel);
2859 return REFRESH_MENU_COLOR;
2862 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2864 if (scr->dtext_color)
2865 WMReleaseColor(scr->dtext_color);
2867 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2869 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2870 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2871 } else {
2872 WMSetColorAlpha(scr->dtext_color, 0xffff);
2875 wFreeColor(scr, color->pixel);
2877 return REFRESH_MENU_COLOR;
2880 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2882 if (scr->icon_title_color)
2883 WMReleaseColor(scr->icon_title_color);
2884 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2886 wFreeColor(scr, color->pixel);
2888 return REFRESH_ICON_TITLE_COLOR;
2891 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2893 if (scr->icon_title_texture) {
2894 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2896 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2898 return REFRESH_ICON_TITLE_BACK;
2901 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2903 close(scr->helper_fd);
2904 scr->helper_fd = 0;
2905 scr->helper_pid = 0;
2906 scr->flags.backimage_helper_launched = 0;
2909 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2911 WMPropList *val;
2912 char *str;
2913 int i;
2915 if (scr->flags.backimage_helper_launched) {
2916 if (WMGetPropListItemCount(value) == 0) {
2917 SendHelperMessage(scr, 'C', 0, NULL);
2918 SendHelperMessage(scr, 'K', 0, NULL);
2920 WMReleasePropList(value);
2921 return 0;
2923 } else {
2924 pid_t pid;
2925 int filedes[2];
2927 if (WMGetPropListItemCount(value) == 0)
2928 return 0;
2930 if (pipe(filedes) < 0) {
2931 wsyserror("pipe() failed:can't set workspace specific background image");
2933 WMReleasePropList(value);
2934 return 0;
2937 pid = fork();
2938 if (pid < 0) {
2939 wsyserror("fork() failed:can't set workspace specific background image");
2940 if (close(filedes[0]) < 0)
2941 wsyserror("could not close pipe");
2942 if (close(filedes[1]) < 0)
2943 wsyserror("could not close pipe");
2945 } else if (pid == 0) {
2946 char *dither;
2948 SetupEnvironment(scr);
2950 if (close(0) < 0)
2951 wsyserror("could not close pipe");
2952 if (dup(filedes[0]) < 0) {
2953 wsyserror("dup() failed:can't set workspace specific background image");
2955 dither = wPreferences.no_dithering ? "-m" : "-d";
2956 if (wPreferences.smooth_workspace_back)
2957 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2958 else
2959 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2960 wsyserror("could not execute wmsetbg");
2961 exit(1);
2962 } else {
2964 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2965 wsyserror("error setting close-on-exec flag");
2967 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2968 wsyserror("error setting close-on-exec flag");
2971 scr->helper_fd = filedes[1];
2972 scr->helper_pid = pid;
2973 scr->flags.backimage_helper_launched = 1;
2975 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2977 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2982 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2983 val = WMGetFromPLArray(value, i);
2984 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2985 str = WMGetPropListDescription(val, False);
2987 SendHelperMessage(scr, 'S', i + 1, str);
2989 wfree(str);
2990 } else {
2991 SendHelperMessage(scr, 'U', i + 1, NULL);
2994 sleep(1);
2996 WMReleasePropList(value);
2997 return 0;
3000 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
3002 if (scr->flags.backimage_helper_launched) {
3003 char *str;
3005 if (WMGetPropListItemCount(value) == 0) {
3006 SendHelperMessage(scr, 'U', 0, NULL);
3007 } else {
3008 /* set the default workspace background to this one */
3009 str = WMGetPropListDescription(value, False);
3010 if (str) {
3011 SendHelperMessage(scr, 'S', 0, str);
3012 wfree(str);
3013 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
3014 } else {
3015 SendHelperMessage(scr, 'U', 0, NULL);
3018 } else if (WMGetPropListItemCount(value) > 0) {
3019 char *command;
3020 char *text;
3021 char *dither;
3022 int len;
3024 SetupEnvironment(scr);
3025 text = WMGetPropListDescription(value, False);
3026 len = strlen(text) + 40;
3027 command = wmalloc(len);
3028 dither = wPreferences.no_dithering ? "-m" : "-d";
3029 if (wPreferences.smooth_workspace_back)
3030 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3031 else
3032 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3033 wfree(text);
3034 system(command);
3035 wfree(command);
3037 WMReleasePropList(value);
3039 return 0;
3042 #ifdef VIRTUAL_DESKTOP
3043 static int setVirtualDeskEnable(WScreen * scr, WDefaultEntry * entry, void *foo, void *bar)
3045 wWorkspaceUpdateEdge(scr);
3046 return 0;
3048 #endif
3050 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3052 if (scr->widget_texture) {
3053 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3055 scr->widget_texture = *(WTexSolid **) texture;
3057 return 0;
3060 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3062 if (scr->window_title_texture[WS_FOCUSED]) {
3063 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3065 scr->window_title_texture[WS_FOCUSED] = *texture;
3067 return REFRESH_WINDOW_TEXTURES;
3070 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3072 if (scr->window_title_texture[WS_PFOCUSED]) {
3073 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3075 scr->window_title_texture[WS_PFOCUSED] = *texture;
3077 return REFRESH_WINDOW_TEXTURES;
3080 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3082 if (scr->window_title_texture[WS_UNFOCUSED]) {
3083 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3085 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3087 return REFRESH_WINDOW_TEXTURES;
3090 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3092 if (scr->resizebar_texture[0]) {
3093 wTextureDestroy(scr, scr->resizebar_texture[0]);
3095 scr->resizebar_texture[0] = *texture;
3097 return REFRESH_WINDOW_TEXTURES;
3100 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3102 if (scr->menu_title_texture[0]) {
3103 wTextureDestroy(scr, scr->menu_title_texture[0]);
3105 scr->menu_title_texture[0] = *texture;
3107 return REFRESH_MENU_TITLE_TEXTURE;
3110 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3112 if (scr->menu_item_texture) {
3113 wTextureDestroy(scr, scr->menu_item_texture);
3114 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3116 scr->menu_item_texture = *texture;
3118 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3120 return REFRESH_MENU_TEXTURE;
3123 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
3125 WWindow *wwin;
3126 wKeyBindings[widx] = *shortcut;
3128 wwin = scr->focused_window;
3130 while (wwin != NULL) {
3131 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3133 if (!WFLAGP(wwin, no_bind_keys)) {
3134 wWindowSetKeyGrabs(wwin);
3136 wwin = wwin->prev;
3139 return 0;
3142 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3144 wScreenUpdateUsableArea(scr);
3145 wArrangeIcons(scr, True);
3147 return 0;
3150 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3152 wScreenUpdateUsableArea(scr);
3154 return 0;
3157 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3159 return REFRESH_MENU_TEXTURE;
3162 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3164 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3166 RCopyArea(img, image, x, y, w, h, 0, 0);
3168 return img;
3171 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
3173 char *path;
3174 RImage *bgimage;
3175 int cwidth, cheight;
3176 WPreferences *prefs = (WPreferences *) foo;
3178 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3179 if (prefs->swtileImage)
3180 RReleaseImage(prefs->swtileImage);
3181 prefs->swtileImage = NULL;
3183 WMReleasePropList(array);
3184 return 0;
3187 switch (WMGetPropListItemCount(array)) {
3188 case 4:
3189 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3190 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3191 break;
3192 } else
3193 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3195 if (!path) {
3196 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3197 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3198 } else {
3199 bgimage = RLoadImage(scr->rcontext, path, 0);
3200 if (!bgimage) {
3201 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3202 wfree(path);
3203 } else {
3204 wfree(path);
3206 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3207 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3209 if (cwidth <= 0 || cheight <= 0 ||
3210 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3211 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3212 else {
3213 int i;
3214 int swidth, theight;
3215 for (i = 0; i < 9; i++) {
3216 if (prefs->swbackImage[i])
3217 RReleaseImage(prefs->swbackImage[i]);
3218 prefs->swbackImage[i] = NULL;
3220 swidth = (bgimage->width - cwidth) / 2;
3221 theight = (bgimage->height - cheight) / 2;
3223 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3224 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3225 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3226 swidth, theight);
3228 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3229 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3230 cwidth, cheight);
3231 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3232 swidth, cheight);
3234 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3235 swidth, theight);
3236 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3237 cwidth, theight);
3238 prefs->swbackImage[8] =
3239 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3240 theight);
3242 // check if anything failed
3243 for (i = 0; i < 9; i++) {
3244 if (!prefs->swbackImage[i]) {
3245 for (; i >= 0; --i) {
3246 RReleaseImage(prefs->swbackImage[i]);
3247 prefs->swbackImage[i] = NULL;
3249 break;
3253 RReleaseImage(bgimage);
3257 case 1:
3258 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3259 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3260 break;
3261 } else
3262 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3264 if (!path) {
3265 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3266 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3267 } else {
3268 if (prefs->swtileImage)
3269 RReleaseImage(prefs->swtileImage);
3271 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3272 if (!prefs->swtileImage) {
3273 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3275 wfree(path);
3277 break;
3279 default:
3280 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3281 break;
3284 WMReleasePropList(array);
3286 return 0;
3290 static int
3291 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3293 return REFRESH_BUTTON_IMAGES;
3298 * Very ugly kluge.
3299 * Need access to the double click variables, so that all widgets in
3300 * wmaker panels will have the same dbl-click values.
3301 * TODO: figure a better way of dealing with it.
3303 #include <WINGs/WINGsP.h>
3305 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3307 extern _WINGsConfiguration WINGsConfiguration;
3309 if (*value <= 0)
3310 *(int *)foo = 1;
3312 WINGsConfiguration.doubleClickDelay = *value;
3314 return 0;
3317 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3319 if (wCursor[widx] != None) {
3320 XFreeCursor(dpy, wCursor[widx]);
3323 wCursor[widx] = *cursor;
3325 if (widx == WCUR_ROOT && *cursor != None) {
3326 XDefineCursor(dpy, scr->root_win, *cursor);
3329 return 0;