Mac OS X-style window cycling.
[wmaker-crm.git] / src / defaults.c
blob555bdac1ebb8e6bf1012010351902165875741fb
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 {"DisableSound", "NO", NULL,
444 &wPreferences.no_sound, getBool, NULL},
445 {"DisableAnimations", "NO", NULL,
446 &wPreferences.no_animations, getBool, NULL},
447 {"DontLinkWorkspaces", "NO", NULL,
448 &wPreferences.no_autowrap, getBool, NULL},
449 {"AutoArrangeIcons", "NO", NULL,
450 &wPreferences.auto_arrange_icons, getBool, NULL},
451 {"NoWindowOverDock", "NO", NULL,
452 &wPreferences.no_window_over_dock, getBool, updateUsableArea},
453 {"NoWindowOverIcons", "NO", NULL,
454 &wPreferences.no_window_over_icons, getBool, updateUsableArea},
455 {"WindowPlaceOrigin", "(0, 0)", NULL,
456 &wPreferences.window_place_origin, getCoord, NULL},
457 {"ResizeDisplay", "corner", seGeomDisplays,
458 &wPreferences.size_display, getEnum, NULL},
459 {"MoveDisplay", "corner", seGeomDisplays,
460 &wPreferences.move_display, getEnum, NULL},
461 {"DontConfirmKill", "NO", NULL,
462 &wPreferences.dont_confirm_kill, getBool, NULL},
463 {"WindowTitleBalloons", "NO", NULL,
464 &wPreferences.window_balloon, getBool, NULL},
465 {"MiniwindowTitleBalloons", "NO", NULL,
466 &wPreferences.miniwin_balloon, getBool, NULL},
467 {"AppIconBalloons", "NO", NULL,
468 &wPreferences.appicon_balloon, getBool, NULL},
469 {"HelpBalloons", "NO", NULL,
470 &wPreferences.help_balloon, getBool, NULL},
471 {"EdgeResistance", "30", NULL,
472 &wPreferences.edge_resistance, getInt, NULL},
473 {"Attraction", "NO", NULL,
474 &wPreferences.attract, getBool, NULL},
475 {"DisableBlinking", "NO", NULL,
476 &wPreferences.dont_blink, getBool, NULL},
477 {"SingleClickLaunch", "NO", NULL,
478 &wPreferences.single_click, getBool, NULL},
479 /* style options */
480 {"MenuStyle", "normal", seMenuStyles,
481 &wPreferences.menu_style, getEnum, setMenuStyle},
482 {"WidgetColor", "(solid, gray)", NULL,
483 NULL, getTexture, setWidgetColor,
485 {"WorkspaceSpecificBack", "()", NULL,
486 NULL, getWSSpecificBackground, setWorkspaceSpecificBack},
487 /* WorkspaceBack must come after WorkspaceSpecificBack or
488 * WorkspaceBack wont know WorkspaceSpecificBack was also
489 * specified and 2 copies of wmsetbg will be launched */
490 {"WorkspaceBack", "(solid, black)", NULL,
491 NULL, getWSBackground, setWorkspaceBack},
492 {"SmoothWorkspaceBack", "NO", NULL,
493 NULL, getBool, NULL},
494 {"IconBack", "(solid, gray)", NULL,
495 NULL, getTexture, setIconTile},
496 {"TitleJustify", "center", seJustifications,
497 &wPreferences.title_justification, getEnum, setJustify},
498 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
499 NULL, getFont, setWinTitleFont,
501 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
502 &wPreferences.window_title_clearance, getInt, setClearance},
503 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
504 &wPreferences.menu_title_clearance, getInt, setClearance},
505 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
506 &wPreferences.menu_text_clearance, getInt, setClearance},
507 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
508 NULL, getFont, setMenuTitleFont},
509 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
510 NULL, getFont, setMenuTextFont},
511 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
512 NULL, getFont, setIconTitleFont},
513 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
514 NULL, getFont, setClipTitleFont},
515 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
516 NULL, getFont, setLargeDisplayFont},
517 {"HighlightColor", "white", NULL,
518 NULL, getColor, setHightlight},
519 {"HighlightTextColor", "black", NULL,
520 NULL, getColor, setHightlightText},
521 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
522 NULL, getColor, setClipTitleColor},
523 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
524 NULL, getColor, setClipTitleColor},
525 {"FTitleColor", "white", (void *)WS_FOCUSED,
526 NULL, getColor, setWTitleColor},
527 {"PTitleColor", "white", (void *)WS_PFOCUSED,
528 NULL, getColor, setWTitleColor},
529 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
530 NULL, getColor, setWTitleColor},
531 {"FTitleBack", "(solid, black)", NULL,
532 NULL, getTexture, setFTitleBack},
533 {"PTitleBack", "(solid, \"#616161\")", NULL,
534 NULL, getTexture, setPTitleBack},
535 {"UTitleBack", "(solid, gray)", NULL,
536 NULL, getTexture, setUTitleBack},
537 {"ResizebarBack", "(solid, gray)", NULL,
538 NULL, getTexture, setResizebarBack},
539 {"MenuTitleColor", "white", NULL,
540 NULL, getColor, setMenuTitleColor},
541 {"MenuTextColor", "black", NULL,
542 NULL, getColor, setMenuTextColor},
543 {"MenuDisabledColor", "\"#616161\"", NULL,
544 NULL, getColor, setMenuDisabledColor},
545 {"MenuTitleBack", "(solid, black)", NULL,
546 NULL, getTexture, setMenuTitleBack},
547 {"MenuTextBack", "(solid, gray)", NULL,
548 NULL, getTexture, setMenuTextBack},
549 {"IconTitleColor", "white", NULL,
550 NULL, getColor, setIconTitleColor},
551 {"IconTitleBack", "black", NULL,
552 NULL, getColor, setIconTitleBack},
553 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
554 NULL, getPropList, setSwPOptions},
555 /* keybindings */
556 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
557 NULL, getKeybind, setKeyGrab},
558 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
559 NULL, getKeybind, setKeyGrab},
560 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
561 NULL, getKeybind, setKeyGrab},
562 {"ClipLowerKey", "None", (void *)WKBD_CLIPLOWER,
563 NULL, getKeybind, setKeyGrab},
564 {"ClipRaiseKey", "None", (void *)WKBD_CLIPRAISE,
565 NULL, getKeybind, setKeyGrab},
566 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
567 NULL, getKeybind, setKeyGrab},
568 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
569 NULL, getKeybind, setKeyGrab},
570 {"HideKey", "None", (void *)WKBD_HIDE,
571 NULL, getKeybind, setKeyGrab},
572 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
573 NULL, getKeybind, setKeyGrab},
574 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
575 NULL, getKeybind, setKeyGrab},
576 {"CloseKey", "None", (void *)WKBD_CLOSE,
577 NULL, getKeybind, setKeyGrab},
578 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
579 NULL, getKeybind, setKeyGrab},
580 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
581 NULL, getKeybind, setKeyGrab},
582 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
583 NULL, getKeybind, setKeyGrab},
584 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
585 NULL, getKeybind, setKeyGrab},
586 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
587 NULL, getKeybind, setKeyGrab},
588 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
589 NULL, getKeybind, setKeyGrab},
590 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
591 NULL, getKeybind, setKeyGrab},
592 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
593 NULL, getKeybind, setKeyGrab},
594 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
595 NULL, getKeybind, setKeyGrab},
596 {"ShadeKey", "None", (void *)WKBD_SHADE,
597 NULL, getKeybind, setKeyGrab},
598 {"SelectKey", "None", (void *)WKBD_SELECT,
599 NULL, getKeybind, setKeyGrab},
600 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
601 NULL, getKeybind, setKeyGrab},
602 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
603 NULL, getKeybind, setKeyGrab},
604 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
605 NULL, getKeybind, setKeyGrab},
606 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
607 NULL, getKeybind, setKeyGrab},
608 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
609 NULL, getKeybind, setKeyGrab},
610 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
611 NULL, getKeybind, setKeyGrab},
612 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
613 NULL, getKeybind, setKeyGrab},
614 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
615 NULL, getKeybind, setKeyGrab},
616 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
617 NULL, getKeybind, setKeyGrab},
618 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
619 NULL, getKeybind, setKeyGrab},
620 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
621 NULL, getKeybind, setKeyGrab},
622 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
623 NULL, getKeybind, setKeyGrab},
624 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
625 NULL, getKeybind, setKeyGrab},
626 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
627 NULL, getKeybind, setKeyGrab},
628 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
629 NULL, getKeybind, setKeyGrab},
630 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
631 NULL, getKeybind, setKeyGrab},
632 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
633 NULL, getKeybind, setKeyGrab},
634 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
635 NULL, getKeybind, setKeyGrab},
636 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
637 NULL, getKeybind, setKeyGrab},
638 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
639 NULL, getKeybind, setKeyGrab},
640 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
641 NULL, getKeybind, setKeyGrab},
642 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
643 NULL, getKeybind, setKeyGrab}
644 , {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
645 NULL, getKeybind, setKeyGrab},
646 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
647 NULL, getKeybind, setKeyGrab},
648 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
649 NULL, getKeybind, setKeyGrab},
650 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
651 NULL, getKeybind, setKeyGrab},
652 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
653 NULL, getKeybind, setKeyGrab},
654 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
655 NULL, getKeybind, setKeyGrab},
656 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
657 NULL, getKeybind, setKeyGrab},
659 #ifdef KEEP_XKB_LOCK_STATUS
660 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
661 NULL, getKeybind, setKeyGrab},
662 {"KbdModeLock", "NO", NULL,
663 &wPreferences.modelock, getBool, NULL},
664 #endif /* KEEP_XKB_LOCK_STATUS */
666 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
667 NULL, getCursor, setCursor},
668 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
669 NULL, getCursor, setCursor},
670 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
671 NULL, getCursor, setCursor},
672 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
673 NULL, getCursor, setCursor},
674 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
675 (void *)WCUR_TOPLEFTRESIZE,
676 NULL, getCursor, setCursor},
677 {"TopRightResizeCursor", "(builtin, top_right_corner)",
678 (void *)WCUR_TOPRIGHTRESIZE,
679 NULL, getCursor, setCursor},
680 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
681 (void *)WCUR_BOTTOMLEFTRESIZE,
682 NULL, getCursor, setCursor},
683 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
684 (void *)WCUR_BOTTOMRIGHTRESIZE,
685 NULL, getCursor, setCursor},
686 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
687 (void *)WCUR_VERTICALRESIZE,
688 NULL, getCursor, setCursor},
689 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
690 (void *)WCUR_HORIZONRESIZE,
691 NULL, getCursor, setCursor},
692 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
693 NULL, getCursor, setCursor},
694 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
695 NULL, getCursor, setCursor},
696 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
697 NULL, getCursor, setCursor},
698 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
699 NULL, getCursor, setCursor},
700 {"DialogHistoryLines", "500", NULL,
701 &wPreferences.history_lines, getInt, NULL}
704 #if 0
705 static void rereadDefaults(void);
706 #endif
708 #if 0
709 static void rereadDefaults(void)
711 /* must defer the update because accessing X data from a
712 * signal handler can mess up Xlib */
715 #endif
717 static void initDefaults()
719 unsigned int i;
720 WDefaultEntry *entry;
722 WMPLSetCaseSensitive(False);
724 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
725 entry = &optionList[i];
727 entry->plkey = WMCreatePLString(entry->key);
728 if (entry->default_value)
729 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
730 else
731 entry->plvalue = NULL;
734 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
735 entry = &staticOptionList[i];
737 entry->plkey = WMCreatePLString(entry->key);
738 if (entry->default_value)
739 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
740 else
741 entry->plvalue = NULL;
745 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
746 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
748 PLRegister(wDomainName, rereadDefaults);
749 PLRegister(wAttributeDomainName, rereadDefaults);
753 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
755 WMPropList *globalDict = NULL;
756 char path[PATH_MAX];
757 struct stat stbuf;
759 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
760 if (stat(path, &stbuf) >= 0) {
761 globalDict = WMReadPropListFromFile(path);
762 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
763 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
764 WMReleasePropList(globalDict);
765 globalDict = NULL;
766 } else if (!globalDict) {
767 wwarning(_("could not load domain %s from global defaults database"), domainName);
771 return globalDict;
774 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
775 static void prependMenu(WMPropList * destarr, WMPropList * array)
777 WMPropList *item;
778 int i;
780 for (i = 0; i < WMGetPropListItemCount(array); i++) {
781 item = WMGetFromPLArray(array, i);
782 if (item)
783 WMInsertInPLArray(destarr, i + 1, item);
787 static void appendMenu(WMPropList * destarr, WMPropList * array)
789 WMPropList *item;
790 int i;
792 for (i = 0; i < WMGetPropListItemCount(array); i++) {
793 item = WMGetFromPLArray(array, i);
794 if (item)
795 WMAddToPLArray(destarr, item);
798 #endif
800 /* Fixup paths for cached pixmaps from .AppInfo to Library/WindowMaker/... */
801 static Bool fixupCachedPixmapsPaths(WMPropList * dict)
803 WMPropList *allApps, *app, *props, *iconkey, *icon, *newicon;
804 char *path, *fixedpath, *ptr, *search;
805 int i, len, slen;
806 Bool changed = False;
808 search = "/.AppInfo/WindowMaker/";
809 slen = strlen(search);
811 iconkey = WMCreatePLString("Icon");
812 allApps = WMGetPLDictionaryKeys(dict);
814 for (i = 0; i < WMGetPropListItemCount(allApps); i++) {
815 app = WMGetFromPLArray(allApps, i);
816 props = WMGetFromPLDictionary(dict, app);
817 if (!props)
818 continue;
819 icon = WMGetFromPLDictionary(props, iconkey);
820 if (icon && WMIsPLString(icon)) {
821 path = WMGetFromPLString(icon);
822 ptr = strstr(path, search);
823 if (ptr) {
824 changed = True;
825 len = (ptr - path);
826 fixedpath = wmalloc(strlen(path) + 32);
827 strncpy(fixedpath, path, len);
828 fixedpath[len] = 0;
829 strcat(fixedpath, "/Library/WindowMaker/CachedPixmaps/");
830 strcat(fixedpath, ptr + slen);
831 newicon = WMCreatePLString(fixedpath);
832 WMPutInPLDictionary(props, iconkey, newicon);
833 WMReleasePropList(newicon);
834 wfree(fixedpath);
839 WMReleasePropList(allApps);
840 WMReleasePropList(iconkey);
842 return changed;
845 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
847 WMPropList *menu = menuDomain->dictionary;
848 WMPropList *submenu;
850 if (!menu || !WMIsPLArray(menu))
851 return;
853 #ifdef GLOBAL_PREAMBLE_MENU_FILE
854 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
856 if (submenu && !WMIsPLArray(submenu)) {
857 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
858 WMReleasePropList(submenu);
859 submenu = NULL;
861 if (submenu) {
862 prependMenu(menu, submenu);
863 WMReleasePropList(submenu);
865 #endif
867 #ifdef GLOBAL_EPILOGUE_MENU_FILE
868 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
870 if (submenu && !WMIsPLArray(submenu)) {
871 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
872 WMReleasePropList(submenu);
873 submenu = NULL;
875 if (submenu) {
876 appendMenu(menu, submenu);
877 WMReleasePropList(submenu);
879 #endif
881 menuDomain->dictionary = menu;
884 #if 0
885 WMPropList *wDefaultsInit(int screen_number)
887 static int defaults_inited = 0;
888 WMPropList *dict;
890 if (!defaults_inited) {
891 initDefaults();
894 dict = PLGetDomain(wDomainName);
895 if (!dict) {
896 wwarning(_("could not read domain \"%s\" from defaults database"), WMGetFromPLString(wDomainName));
899 return dict;
901 #endif
903 void wDefaultsDestroyDomain(WDDomain * domain)
905 if (domain->dictionary)
906 WMReleasePropList(domain->dictionary);
907 wfree(domain->path);
908 wfree(domain);
911 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
913 WDDomain *db;
914 struct stat stbuf;
915 static int inited = 0;
916 char path[PATH_MAX];
917 char *the_path;
918 WMPropList *shared_dict = NULL;
920 if (!inited) {
921 inited = 1;
922 initDefaults();
925 db = wmalloc(sizeof(WDDomain));
926 memset(db, 0, sizeof(WDDomain));
927 db->domain_name = domain;
928 db->path = wdefaultspathfordomain(domain);
929 the_path = db->path;
931 if (the_path && stat(the_path, &stbuf) >= 0) {
932 db->dictionary = WMReadPropListFromFile(the_path);
933 if (db->dictionary) {
934 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
935 WMReleasePropList(db->dictionary);
936 db->dictionary = NULL;
937 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
939 if (strcmp(domain, "WMWindowAttributes") == 0 && db->dictionary) {
940 if (fixupCachedPixmapsPaths(db->dictionary)) {
941 WMWritePropListToFile(db->dictionary, db->path, True);
942 /* re-read the timestamp. if this fails take current time */
943 if (stat(db->path, &stbuf) < 0) {
944 stbuf.st_mtime = time(NULL);
948 db->timestamp = stbuf.st_mtime;
949 } else {
950 wwarning(_("could not load domain %s from user defaults database"), domain);
954 /* global system dictionary */
955 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
956 if (stat(path, &stbuf) >= 0) {
957 shared_dict = WMReadPropListFromFile(path);
958 if (shared_dict) {
959 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
960 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
961 domain, path);
962 WMReleasePropList(shared_dict);
963 shared_dict = NULL;
964 } else {
965 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
966 WMIsPLDictionary(db->dictionary)) {
967 WMMergePLDictionaries(shared_dict, db->dictionary, True);
968 WMReleasePropList(db->dictionary);
969 db->dictionary = shared_dict;
970 if (stbuf.st_mtime > db->timestamp)
971 db->timestamp = stbuf.st_mtime;
972 } else if (!db->dictionary) {
973 db->dictionary = shared_dict;
974 if (stbuf.st_mtime > db->timestamp)
975 db->timestamp = stbuf.st_mtime;
978 } else {
979 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
983 return db;
986 void wReadStaticDefaults(WMPropList * dict)
988 WMPropList *plvalue;
989 WDefaultEntry *entry;
990 unsigned int i;
991 void *tdata;
993 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
994 entry = &staticOptionList[i];
996 if (dict)
997 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
998 else
999 plvalue = NULL;
1001 if (!plvalue) {
1002 /* no default in the DB. Use builtin default */
1003 plvalue = entry->plvalue;
1006 if (plvalue) {
1007 /* convert data */
1008 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
1009 if (entry->update) {
1010 (*entry->update) (NULL, entry, tdata, entry->extra_data);
1016 void wDefaultsCheckDomains(void)
1018 WScreen *scr;
1019 struct stat stbuf;
1020 WMPropList *shared_dict = NULL;
1021 WMPropList *dict;
1022 int i;
1024 #ifdef HEARTBEAT
1025 puts("Checking domains...");
1026 #endif
1027 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1028 #ifdef HEARTBEAT
1029 puts("Checking WindowMaker domain");
1030 #endif
1031 WDWindowMaker->timestamp = stbuf.st_mtime;
1033 /* global dictionary */
1034 shared_dict = readGlobalDomain("WindowMaker", True);
1035 /* user dictionary */
1036 dict = WMReadPropListFromFile(WDWindowMaker->path);
1037 if (dict) {
1038 if (!WMIsPLDictionary(dict)) {
1039 WMReleasePropList(dict);
1040 dict = NULL;
1041 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1042 "WindowMaker", WDWindowMaker->path);
1043 } else {
1044 if (shared_dict) {
1045 WMMergePLDictionaries(shared_dict, dict, True);
1046 WMReleasePropList(dict);
1047 dict = shared_dict;
1048 shared_dict = NULL;
1050 for (i = 0; i < wScreenCount; i++) {
1051 scr = wScreenWithNumber(i);
1052 if (scr)
1053 wReadDefaults(scr, dict);
1055 if (WDWindowMaker->dictionary) {
1056 WMReleasePropList(WDWindowMaker->dictionary);
1058 WDWindowMaker->dictionary = dict;
1060 } else {
1061 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1063 if (shared_dict) {
1064 WMReleasePropList(shared_dict);
1068 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1069 #ifdef HEARTBEAT
1070 puts("Checking WMWindowAttributes domain");
1071 #endif
1072 /* global dictionary */
1073 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1074 /* user dictionary */
1075 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1076 if (dict) {
1077 if (!WMIsPLDictionary(dict)) {
1078 WMReleasePropList(dict);
1079 dict = NULL;
1080 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1081 "WMWindowAttributes", WDWindowAttributes->path);
1082 } else {
1083 if (shared_dict) {
1084 WMMergePLDictionaries(shared_dict, dict, True);
1085 WMReleasePropList(dict);
1086 dict = shared_dict;
1087 shared_dict = NULL;
1089 if (WDWindowAttributes->dictionary) {
1090 WMReleasePropList(WDWindowAttributes->dictionary);
1092 WDWindowAttributes->dictionary = dict;
1093 for (i = 0; i < wScreenCount; i++) {
1094 scr = wScreenWithNumber(i);
1095 if (scr) {
1096 RImage *image;
1098 wDefaultUpdateIcons(scr);
1100 /* Update the panel image if changed */
1101 /* Don't worry. If the image is the same these
1102 * functions will have no performance impact. */
1103 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1105 if (!image) {
1106 wwarning(_("could not load logo image for panels: %s"),
1107 RMessageForError(RErrorCode));
1108 } else {
1109 WMSetApplicationIconImage(scr->wmscreen, image);
1110 RReleaseImage(image);
1115 } else {
1116 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1118 WDWindowAttributes->timestamp = stbuf.st_mtime;
1119 if (shared_dict) {
1120 WMReleasePropList(shared_dict);
1124 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1125 dict = WMReadPropListFromFile(WDRootMenu->path);
1126 #ifdef HEARTBEAT
1127 puts("Checking WMRootMenu domain");
1128 #endif
1129 if (dict) {
1130 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1131 WMReleasePropList(dict);
1132 dict = NULL;
1133 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1134 "WMRootMenu", WDRootMenu->path);
1135 } else {
1136 if (WDRootMenu->dictionary) {
1137 WMReleasePropList(WDRootMenu->dictionary);
1139 WDRootMenu->dictionary = dict;
1140 wDefaultsMergeGlobalMenus(WDRootMenu);
1142 } else {
1143 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1145 WDRootMenu->timestamp = stbuf.st_mtime;
1149 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1151 WMPropList *plvalue, *old_value;
1152 WDefaultEntry *entry;
1153 unsigned int i, must_update;
1154 int update_workspace_back = 0; /* kluge :/ */
1155 unsigned int needs_refresh;
1156 void *tdata;
1157 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1159 must_update = 0;
1161 needs_refresh = 0;
1163 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1164 entry = &optionList[i];
1166 if (new_dict)
1167 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1168 else
1169 plvalue = NULL;
1171 if (!old_dict)
1172 old_value = NULL;
1173 else
1174 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1176 if (!plvalue && !old_value) {
1177 /* no default in the DB. Use builtin default */
1178 plvalue = entry->plvalue;
1179 if (plvalue && new_dict) {
1180 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1181 must_update = 1;
1183 } else if (!plvalue) {
1184 /* value was deleted from DB. Keep current value */
1185 continue;
1186 } else if (!old_value) {
1187 /* set value for the 1st time */
1188 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1189 /* value has changed */
1190 } else {
1192 if (strcmp(entry->key, "WorkspaceBack") == 0
1193 && update_workspace_back && scr->flags.backimage_helper_launched) {
1194 } else {
1195 /* value was not changed since last time */
1196 continue;
1200 if (plvalue) {
1201 #ifdef DEBUG
1202 printf("Updating %s to %s\n", entry->key, WMGetPropListDescription(plvalue, False));
1203 #endif
1204 /* convert data */
1205 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1207 * If the WorkspaceSpecificBack data has been changed
1208 * so that the helper will be launched now, we must be
1209 * sure to send the default background texture config
1210 * to the helper.
1212 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1213 && !scr->flags.backimage_helper_launched) {
1214 update_workspace_back = 1;
1216 if (entry->update) {
1217 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1223 if (needs_refresh != 0 && !scr->flags.startup) {
1224 int foo;
1226 foo = 0;
1227 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1228 foo |= WTextureSettings;
1229 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1230 foo |= WFontSettings;
1231 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1232 foo |= WColorSettings;
1233 if (foo)
1234 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1235 (void *)(uintptr_t) foo);
1237 foo = 0;
1238 if (needs_refresh & REFRESH_MENU_TEXTURE)
1239 foo |= WTextureSettings;
1240 if (needs_refresh & REFRESH_MENU_FONT)
1241 foo |= WFontSettings;
1242 if (needs_refresh & REFRESH_MENU_COLOR)
1243 foo |= WColorSettings;
1244 if (foo)
1245 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1247 foo = 0;
1248 if (needs_refresh & REFRESH_WINDOW_FONT) {
1249 foo |= WFontSettings;
1251 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1252 foo |= WTextureSettings;
1254 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1255 foo |= WColorSettings;
1257 if (foo)
1258 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1260 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1261 foo = 0;
1262 if (needs_refresh & REFRESH_ICON_FONT) {
1263 foo |= WFontSettings;
1265 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1266 foo |= WTextureSettings;
1268 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1269 foo |= WTextureSettings;
1271 if (foo)
1272 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1273 (void *)(uintptr_t) foo);
1275 if (needs_refresh & REFRESH_ICON_TILE)
1276 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1280 void wDefaultUpdateIcons(WScreen * scr)
1282 WAppIcon *aicon = scr->app_icon_list;
1283 WWindow *wwin = scr->focused_window;
1284 char *file;
1286 while (aicon) {
1287 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1288 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1289 || (file && !aicon->icon->file)) {
1290 RImage *new_image;
1292 if (aicon->icon->file)
1293 wfree(aicon->icon->file);
1294 aicon->icon->file = wstrdup(file);
1296 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1297 if (new_image) {
1298 wIconChangeImage(aicon->icon, new_image);
1299 wAppIconPaint(aicon);
1302 aicon = aicon->next;
1305 if (!wPreferences.flags.noclip)
1306 wClipIconPaint(scr->clip_icon);
1308 while (wwin) {
1309 if (wwin->icon && wwin->flags.miniaturized) {
1310 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1311 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1312 || (file && !wwin->icon->file)) {
1313 RImage *new_image;
1315 if (wwin->icon->file)
1316 wfree(wwin->icon->file);
1317 wwin->icon->file = wstrdup(file);
1319 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1320 if (new_image)
1321 wIconChangeImage(wwin->icon, new_image);
1324 wwin = wwin->prev;
1328 /* --------------------------- Local ----------------------- */
1330 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1331 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1332 entry->key, x); \
1333 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1334 var = entry->default_value;\
1335 } else var = WMGetFromPLString(value)\
1338 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1340 char *str;
1341 WOptionEnumeration *v;
1342 char buffer[TOTAL_VALUES_LENGTH];
1344 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1345 for (v = values; v->string != NULL; v++) {
1346 if (strcasecmp(v->string, str) == 0)
1347 return v->value;
1351 buffer[0] = 0;
1352 for (v = values; v->string != NULL; v++) {
1353 if (!v->is_alias) {
1354 if (buffer[0] != 0)
1355 strcat(buffer, ", ");
1356 strcat(buffer, v->string);
1359 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1361 if (def) {
1362 return string2index(key, val, NULL, values);
1365 return -1;
1369 * value - is the value in the defaults DB
1370 * addr - is the address to store the data
1371 * ret - is the address to store a pointer to a temporary buffer. ret
1372 * must not be freed and is used by the set functions
1374 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1376 static char data;
1377 char *val;
1378 int second_pass = 0;
1380 GET_STRING_OR_DEFAULT("Boolean", val);
1382 again:
1383 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1384 || strcasecmp(val, "YES") == 0) {
1386 data = 1;
1387 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1388 || strcasecmp(val, "NO") == 0) {
1389 data = 0;
1390 } else {
1391 int i;
1392 if (sscanf(val, "%i", &i) == 1) {
1393 if (i != 0)
1394 data = 1;
1395 else
1396 data = 0;
1397 } else {
1398 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1399 if (second_pass == 0) {
1400 val = WMGetFromPLString(entry->plvalue);
1401 second_pass = 1;
1402 wwarning(_("using default \"%s\" instead"), val);
1403 goto again;
1405 return False;
1409 if (ret)
1410 *ret = &data;
1411 if (addr)
1412 *(char *)addr = data;
1414 return True;
1417 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1419 static int data;
1420 char *val;
1422 GET_STRING_OR_DEFAULT("Integer", val);
1424 if (sscanf(val, "%i", &data) != 1) {
1425 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1426 val = WMGetFromPLString(entry->plvalue);
1427 wwarning(_("using default \"%s\" instead"), val);
1428 if (sscanf(val, "%i", &data) != 1) {
1429 return False;
1433 if (ret)
1434 *ret = &data;
1435 if (addr)
1436 *(int *)addr = data;
1438 return True;
1441 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1443 static WCoord data;
1444 char *val_x, *val_y;
1445 int nelem, changed = 0;
1446 WMPropList *elem_x, *elem_y;
1448 again:
1449 if (!WMIsPLArray(value)) {
1450 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1451 if (changed == 0) {
1452 value = entry->plvalue;
1453 changed = 1;
1454 wwarning(_("using default \"%s\" instead"), entry->default_value);
1455 goto again;
1457 return False;
1460 nelem = WMGetPropListItemCount(value);
1461 if (nelem != 2) {
1462 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1463 if (changed == 0) {
1464 value = entry->plvalue;
1465 changed = 1;
1466 wwarning(_("using default \"%s\" instead"), entry->default_value);
1467 goto again;
1469 return False;
1472 elem_x = WMGetFromPLArray(value, 0);
1473 elem_y = WMGetFromPLArray(value, 1);
1475 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1476 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1477 if (changed == 0) {
1478 value = entry->plvalue;
1479 changed = 1;
1480 wwarning(_("using default \"%s\" instead"), entry->default_value);
1481 goto again;
1483 return False;
1486 val_x = WMGetFromPLString(elem_x);
1487 val_y = WMGetFromPLString(elem_y);
1489 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1490 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1491 if (changed == 0) {
1492 value = entry->plvalue;
1493 changed = 1;
1494 wwarning(_("using default \"%s\" instead"), entry->default_value);
1495 goto again;
1497 return False;
1500 if (data.x < 0)
1501 data.x = 0;
1502 else if (data.x > scr->scr_width / 3)
1503 data.x = scr->scr_width / 3;
1504 if (data.y < 0)
1505 data.y = 0;
1506 else if (data.y > scr->scr_height / 3)
1507 data.y = scr->scr_height / 3;
1509 if (ret)
1510 *ret = &data;
1511 if (addr)
1512 *(WCoord *) addr = data;
1514 return True;
1517 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1519 WMRetainPropList(value);
1521 *ret = value;
1523 return True;
1526 #if 0
1527 /* This function is not used at the moment. */
1528 static int getString(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1530 static char *data;
1532 GET_STRING_OR_DEFAULT("String", data);
1534 if (!data) {
1535 data = WMGetFromPLString(entry->plvalue);
1536 if (!data)
1537 return False;
1540 if (ret)
1541 *ret = &data;
1542 if (addr)
1543 *(char **)addr = wstrdup(data);
1545 return True;
1547 #endif
1549 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1551 static char *data;
1552 int i, count, len;
1553 char *ptr;
1554 WMPropList *d;
1555 int changed = 0;
1557 again:
1558 if (!WMIsPLArray(value)) {
1559 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1560 if (changed == 0) {
1561 value = entry->plvalue;
1562 changed = 1;
1563 wwarning(_("using default \"%s\" instead"), entry->default_value);
1564 goto again;
1566 return False;
1569 i = 0;
1570 count = WMGetPropListItemCount(value);
1571 if (count < 1) {
1572 if (changed == 0) {
1573 value = entry->plvalue;
1574 changed = 1;
1575 wwarning(_("using default \"%s\" instead"), entry->default_value);
1576 goto again;
1578 return False;
1581 len = 0;
1582 for (i = 0; i < count; i++) {
1583 d = WMGetFromPLArray(value, i);
1584 if (!d || !WMIsPLString(d)) {
1585 count = i;
1586 break;
1588 len += strlen(WMGetFromPLString(d)) + 1;
1591 ptr = data = wmalloc(len + 1);
1593 for (i = 0; i < count; i++) {
1594 d = WMGetFromPLArray(value, i);
1595 if (!d || !WMIsPLString(d)) {
1596 break;
1598 strcpy(ptr, WMGetFromPLString(d));
1599 ptr += strlen(WMGetFromPLString(d));
1600 *ptr = ':';
1601 ptr++;
1603 ptr--;
1604 *(ptr--) = 0;
1606 if (*(char **)addr != NULL) {
1607 wfree(*(char **)addr);
1609 *(char **)addr = data;
1611 return True;
1614 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1616 static signed char data;
1618 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1619 if (data < 0)
1620 return False;
1622 if (ret)
1623 *ret = &data;
1624 if (addr)
1625 *(signed char *)addr = data;
1627 return True;
1631 * (solid <color>)
1632 * (hgradient <color> <color>)
1633 * (vgradient <color> <color>)
1634 * (dgradient <color> <color>)
1635 * (mhgradient <color> <color> ...)
1636 * (mvgradient <color> <color> ...)
1637 * (mdgradient <color> <color> ...)
1638 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1639 * (tpixmap <file> <color>)
1640 * (spixmap <file> <color>)
1641 * (cpixmap <file> <color>)
1642 * (thgradient <file> <opaqueness> <color> <color>)
1643 * (tvgradient <file> <opaqueness> <color> <color>)
1644 * (tdgradient <file> <opaqueness> <color> <color>)
1645 * (function <lib> <function> ...)
1648 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1650 WMPropList *elem;
1651 char *val;
1652 int nelem;
1653 WTexture *texture = NULL;
1655 nelem = WMGetPropListItemCount(pl);
1656 if (nelem < 1)
1657 return NULL;
1659 elem = WMGetFromPLArray(pl, 0);
1660 if (!elem || !WMIsPLString(elem))
1661 return NULL;
1662 val = WMGetFromPLString(elem);
1664 if (strcasecmp(val, "solid") == 0) {
1665 XColor color;
1667 if (nelem != 2)
1668 return NULL;
1670 /* get color */
1672 elem = WMGetFromPLArray(pl, 1);
1673 if (!elem || !WMIsPLString(elem))
1674 return NULL;
1675 val = WMGetFromPLString(elem);
1677 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1678 wwarning(_("\"%s\" is not a valid color name"), val);
1679 return NULL;
1682 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1683 } else if (strcasecmp(val, "dgradient") == 0
1684 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1685 RColor color1, color2;
1686 XColor xcolor;
1687 int type;
1689 if (nelem != 3) {
1690 wwarning(_("bad number of arguments in gradient specification"));
1691 return NULL;
1694 if (val[0] == 'd' || val[0] == 'D')
1695 type = WTEX_DGRADIENT;
1696 else if (val[0] == 'h' || val[0] == 'H')
1697 type = WTEX_HGRADIENT;
1698 else
1699 type = WTEX_VGRADIENT;
1701 /* get from color */
1702 elem = WMGetFromPLArray(pl, 1);
1703 if (!elem || !WMIsPLString(elem))
1704 return NULL;
1705 val = WMGetFromPLString(elem);
1707 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1708 wwarning(_("\"%s\" is not a valid color name"), val);
1709 return NULL;
1711 color1.alpha = 255;
1712 color1.red = xcolor.red >> 8;
1713 color1.green = xcolor.green >> 8;
1714 color1.blue = xcolor.blue >> 8;
1716 /* get to color */
1717 elem = WMGetFromPLArray(pl, 2);
1718 if (!elem || !WMIsPLString(elem)) {
1719 return NULL;
1721 val = WMGetFromPLString(elem);
1723 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1724 wwarning(_("\"%s\" is not a valid color name"), val);
1725 return NULL;
1727 color2.alpha = 255;
1728 color2.red = xcolor.red >> 8;
1729 color2.green = xcolor.green >> 8;
1730 color2.blue = xcolor.blue >> 8;
1732 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1734 } else if (strcasecmp(val, "igradient") == 0) {
1735 RColor colors1[2], colors2[2];
1736 int th1, th2;
1737 XColor xcolor;
1738 int i;
1740 if (nelem != 7) {
1741 wwarning(_("bad number of arguments in gradient specification"));
1742 return NULL;
1745 /* get from color */
1746 for (i = 0; i < 2; i++) {
1747 elem = WMGetFromPLArray(pl, 1 + i);
1748 if (!elem || !WMIsPLString(elem))
1749 return NULL;
1750 val = WMGetFromPLString(elem);
1752 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1753 wwarning(_("\"%s\" is not a valid color name"), val);
1754 return NULL;
1756 colors1[i].alpha = 255;
1757 colors1[i].red = xcolor.red >> 8;
1758 colors1[i].green = xcolor.green >> 8;
1759 colors1[i].blue = xcolor.blue >> 8;
1761 elem = WMGetFromPLArray(pl, 3);
1762 if (!elem || !WMIsPLString(elem))
1763 return NULL;
1764 val = WMGetFromPLString(elem);
1765 th1 = atoi(val);
1767 /* get from color */
1768 for (i = 0; i < 2; i++) {
1769 elem = WMGetFromPLArray(pl, 4 + i);
1770 if (!elem || !WMIsPLString(elem))
1771 return NULL;
1772 val = WMGetFromPLString(elem);
1774 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1775 wwarning(_("\"%s\" is not a valid color name"), val);
1776 return NULL;
1778 colors2[i].alpha = 255;
1779 colors2[i].red = xcolor.red >> 8;
1780 colors2[i].green = xcolor.green >> 8;
1781 colors2[i].blue = xcolor.blue >> 8;
1783 elem = WMGetFromPLArray(pl, 6);
1784 if (!elem || !WMIsPLString(elem))
1785 return NULL;
1786 val = WMGetFromPLString(elem);
1787 th2 = atoi(val);
1789 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1791 } else if (strcasecmp(val, "mhgradient") == 0
1792 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1793 XColor color;
1794 RColor **colors;
1795 int i, count;
1796 int type;
1798 if (nelem < 3) {
1799 wwarning(_("too few arguments in multicolor gradient specification"));
1800 return NULL;
1803 if (val[1] == 'h' || val[1] == 'H')
1804 type = WTEX_MHGRADIENT;
1805 else if (val[1] == 'v' || val[1] == 'V')
1806 type = WTEX_MVGRADIENT;
1807 else
1808 type = WTEX_MDGRADIENT;
1810 count = nelem - 1;
1812 colors = wmalloc(sizeof(RColor *) * (count + 1));
1814 for (i = 0; i < count; i++) {
1815 elem = WMGetFromPLArray(pl, i + 1);
1816 if (!elem || !WMIsPLString(elem)) {
1817 for (--i; i >= 0; --i) {
1818 wfree(colors[i]);
1820 wfree(colors);
1821 return NULL;
1823 val = WMGetFromPLString(elem);
1825 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1826 wwarning(_("\"%s\" is not a valid color name"), val);
1827 for (--i; i >= 0; --i) {
1828 wfree(colors[i]);
1830 wfree(colors);
1831 return NULL;
1832 } else {
1833 colors[i] = wmalloc(sizeof(RColor));
1834 colors[i]->red = color.red >> 8;
1835 colors[i]->green = color.green >> 8;
1836 colors[i]->blue = color.blue >> 8;
1839 colors[i] = NULL;
1841 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1842 } else if (strcasecmp(val, "spixmap") == 0 ||
1843 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1844 XColor color;
1845 int type;
1847 if (nelem != 3)
1848 return NULL;
1850 if (val[0] == 's' || val[0] == 'S')
1851 type = WTP_SCALE;
1852 else if (val[0] == 'c' || val[0] == 'C')
1853 type = WTP_CENTER;
1854 else
1855 type = WTP_TILE;
1857 /* get color */
1858 elem = WMGetFromPLArray(pl, 2);
1859 if (!elem || !WMIsPLString(elem)) {
1860 return NULL;
1862 val = WMGetFromPLString(elem);
1864 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1865 wwarning(_("\"%s\" is not a valid color name"), val);
1866 return NULL;
1869 /* file name */
1870 elem = WMGetFromPLArray(pl, 1);
1871 if (!elem || !WMIsPLString(elem))
1872 return NULL;
1873 val = WMGetFromPLString(elem);
1875 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1876 } else if (strcasecmp(val, "thgradient") == 0
1877 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1878 RColor color1, color2;
1879 XColor xcolor;
1880 int opacity;
1881 int style;
1883 if (val[1] == 'h' || val[1] == 'H')
1884 style = WTEX_THGRADIENT;
1885 else if (val[1] == 'v' || val[1] == 'V')
1886 style = WTEX_TVGRADIENT;
1887 else
1888 style = WTEX_TDGRADIENT;
1890 if (nelem != 5) {
1891 wwarning(_("bad number of arguments in textured gradient specification"));
1892 return NULL;
1895 /* get from color */
1896 elem = WMGetFromPLArray(pl, 3);
1897 if (!elem || !WMIsPLString(elem))
1898 return NULL;
1899 val = WMGetFromPLString(elem);
1901 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1902 wwarning(_("\"%s\" is not a valid color name"), val);
1903 return NULL;
1905 color1.alpha = 255;
1906 color1.red = xcolor.red >> 8;
1907 color1.green = xcolor.green >> 8;
1908 color1.blue = xcolor.blue >> 8;
1910 /* get to color */
1911 elem = WMGetFromPLArray(pl, 4);
1912 if (!elem || !WMIsPLString(elem)) {
1913 return NULL;
1915 val = WMGetFromPLString(elem);
1917 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1918 wwarning(_("\"%s\" is not a valid color name"), val);
1919 return NULL;
1921 color2.alpha = 255;
1922 color2.red = xcolor.red >> 8;
1923 color2.green = xcolor.green >> 8;
1924 color2.blue = xcolor.blue >> 8;
1926 /* get opacity */
1927 elem = WMGetFromPLArray(pl, 2);
1928 if (!elem || !WMIsPLString(elem))
1929 opacity = 128;
1930 else
1931 val = WMGetFromPLString(elem);
1933 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1934 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1935 opacity = 128;
1938 /* get file name */
1939 elem = WMGetFromPLArray(pl, 1);
1940 if (!elem || !WMIsPLString(elem))
1941 return NULL;
1942 val = WMGetFromPLString(elem);
1944 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1946 #ifdef TEXTURE_PLUGIN
1947 else if (strcasecmp(val, "function") == 0) {
1948 WTexFunction *function;
1949 void (*initFunc) (Display *, Colormap);
1950 char *lib, *func, **argv;
1951 int i, argc;
1953 if (nelem < 3)
1954 return NULL;
1956 /* get the library name */
1957 elem = WMGetFromPLArray(pl, 1);
1958 if (!elem || !WMIsPLString(elem)) {
1959 return NULL;
1961 lib = WMGetFromPLString(elem);
1963 /* get the function name */
1964 elem = WMGetFromPLArray(pl, 2);
1965 if (!elem || !WMIsPLString(elem)) {
1966 return NULL;
1968 func = WMGetFromPLString(elem);
1970 argc = nelem - 2;
1971 argv = (char **)wmalloc(argc * sizeof(char *));
1973 /* get the parameters */
1974 argv[0] = wstrdup(func);
1975 for (i = 0; i < argc - 1; i++) {
1976 elem = WMGetFromPLArray(pl, 3 + i);
1977 if (!elem || !WMIsPLString(elem)) {
1978 wfree(argv);
1980 return NULL;
1982 argv[i + 1] = wstrdup(WMGetFromPLString(elem));
1985 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1987 #ifdef HAVE_DLFCN_H
1988 if (function) {
1989 initFunc = dlsym(function->handle, "initWindowMaker");
1990 if (initFunc) {
1991 initFunc(dpy, scr->w_colormap);
1992 } else {
1993 wwarning(_("could not initialize library %s"), lib);
1995 } else {
1996 wwarning(_("could not find function %s::%s"), lib, func);
1998 #endif /* HAVE_DLFCN_H */
1999 texture = (WTexture *) function;
2001 #endif /* TEXTURE_PLUGIN */
2002 else {
2003 wwarning(_("invalid texture type %s"), val);
2004 return NULL;
2006 return texture;
2009 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2011 static WTexture *texture;
2012 int changed = 0;
2014 again:
2015 if (!WMIsPLArray(value)) {
2016 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
2017 if (changed == 0) {
2018 value = entry->plvalue;
2019 changed = 1;
2020 wwarning(_("using default \"%s\" instead"), entry->default_value);
2021 goto again;
2023 return False;
2026 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
2027 WMPropList *pl;
2029 pl = WMGetFromPLArray(value, 0);
2030 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2031 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
2032 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2033 entry->key, "Solid Texture");
2035 value = entry->plvalue;
2036 changed = 1;
2037 wwarning(_("using default \"%s\" instead"), entry->default_value);
2038 goto again;
2042 texture = parse_texture(scr, value);
2044 if (!texture) {
2045 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
2046 if (changed == 0) {
2047 value = entry->plvalue;
2048 changed = 1;
2049 wwarning(_("using default \"%s\" instead"), entry->default_value);
2050 goto again;
2052 return False;
2055 if (ret)
2056 *ret = &texture;
2058 if (addr)
2059 *(WTexture **) addr = texture;
2061 return True;
2064 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2066 WMPropList *elem;
2067 int changed = 0;
2068 char *val;
2069 int nelem;
2071 again:
2072 if (!WMIsPLArray(value)) {
2073 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2074 "WorkspaceBack", "Texture or None");
2075 if (changed == 0) {
2076 value = entry->plvalue;
2077 changed = 1;
2078 wwarning(_("using default \"%s\" instead"), entry->default_value);
2079 goto again;
2081 return False;
2084 /* only do basic error checking and verify for None texture */
2086 nelem = WMGetPropListItemCount(value);
2087 if (nelem > 0) {
2088 elem = WMGetFromPLArray(value, 0);
2089 if (!elem || !WMIsPLString(elem)) {
2090 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2091 if (changed == 0) {
2092 value = entry->plvalue;
2093 changed = 1;
2094 wwarning(_("using default \"%s\" instead"), entry->default_value);
2095 goto again;
2097 return False;
2099 val = WMGetFromPLString(elem);
2101 if (strcasecmp(val, "None") == 0)
2102 return True;
2104 *ret = WMRetainPropList(value);
2106 return True;
2109 static int
2110 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2112 WMPropList *elem;
2113 int nelem;
2114 int changed = 0;
2116 again:
2117 if (!WMIsPLArray(value)) {
2118 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2119 "WorkspaceSpecificBack", "an array of textures");
2120 if (changed == 0) {
2121 value = entry->plvalue;
2122 changed = 1;
2123 wwarning(_("using default \"%s\" instead"), entry->default_value);
2124 goto again;
2126 return False;
2129 /* only do basic error checking and verify for None texture */
2131 nelem = WMGetPropListItemCount(value);
2132 if (nelem > 0) {
2133 while (nelem--) {
2134 elem = WMGetFromPLArray(value, nelem);
2135 if (!elem || !WMIsPLArray(elem)) {
2136 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2137 nelem);
2142 *ret = WMRetainPropList(value);
2144 #ifdef notworking
2146 * Kluge to force wmsetbg helper to set the default background.
2147 * If the WorkspaceSpecificBack is changed once wmaker has started,
2148 * the WorkspaceBack won't be sent to the helper, unless the user
2149 * changes it's value too. So, we must force this by removing the
2150 * value from the defaults DB.
2152 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2153 WMPropList *key = WMCreatePLString("WorkspaceBack");
2155 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2157 WMReleasePropList(key);
2159 #endif
2160 return True;
2163 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2165 static WMFont *font;
2166 char *val;
2168 GET_STRING_OR_DEFAULT("Font", val);
2170 font = WMCreateFont(scr->wmscreen, val);
2171 if (!font)
2172 font = WMCreateFont(scr->wmscreen, "fixed");
2174 if (!font) {
2175 wfatal(_("could not load any usable font!!!"));
2176 exit(1);
2179 if (ret)
2180 *ret = font;
2182 /* can't assign font value outside update function */
2183 wassertrv(addr == NULL, True);
2185 return True;
2188 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2190 static XColor color;
2191 char *val;
2192 int second_pass = 0;
2194 GET_STRING_OR_DEFAULT("Color", val);
2196 again:
2197 if (!wGetColor(scr, val, &color)) {
2198 wwarning(_("could not get color for key \"%s\""), entry->key);
2199 if (second_pass == 0) {
2200 val = WMGetFromPLString(entry->plvalue);
2201 second_pass = 1;
2202 wwarning(_("using default \"%s\" instead"), val);
2203 goto again;
2205 return False;
2208 if (ret)
2209 *ret = &color;
2211 assert(addr == NULL);
2213 if (addr)
2214 *(unsigned long*)addr = pixel;
2217 return True;
2220 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2222 static WShortKey shortcut;
2223 KeySym ksym;
2224 char *val;
2225 char *k;
2226 char buf[MAX_SHORTCUT_LENGTH], *b;
2228 GET_STRING_OR_DEFAULT("Key spec", val);
2230 if (!val || strcasecmp(val, "NONE") == 0) {
2231 shortcut.keycode = 0;
2232 shortcut.modifier = 0;
2233 if (ret)
2234 *ret = &shortcut;
2235 return True;
2238 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2240 b = (char *)buf;
2242 /* get modifiers */
2243 shortcut.modifier = 0;
2244 while ((k = strchr(b, '+')) != NULL) {
2245 int mod;
2247 *k = 0;
2248 mod = wXModifierFromKey(b);
2249 if (mod < 0) {
2250 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2251 return False;
2253 shortcut.modifier |= mod;
2255 b = k + 1;
2258 /* get key */
2259 ksym = XStringToKeysym(b);
2261 if (ksym == NoSymbol) {
2262 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2263 return False;
2266 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2267 if (shortcut.keycode == 0) {
2268 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2269 return False;
2272 if (ret)
2273 *ret = &shortcut;
2275 return True;
2278 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2280 static int mask;
2281 char *str;
2283 GET_STRING_OR_DEFAULT("Modifier Key", str);
2285 if (!str)
2286 return False;
2288 mask = wXModifierFromKey(str);
2289 if (mask < 0) {
2290 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2291 mask = 0;
2292 return False;
2295 if (addr)
2296 *(int *)addr = mask;
2298 if (ret)
2299 *ret = &mask;
2301 return True;
2304 #ifdef NEWSTUFF
2305 static int getRImages(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2307 unsigned int mask;
2308 char *str;
2309 RImage *image;
2310 int i, n;
2311 int w, h;
2313 GET_STRING_OR_DEFAULT("Image File Path", str);
2314 if (!str)
2315 return False;
2317 image = RLoadImage(scr->rcontext, str, 0);
2318 if (!image) {
2319 wwarning(_("could not load image in option %s: %s"), entry->key, RMessageForError(RErrorCode));
2320 return False;
2323 if (*(RImage **) addr) {
2324 RReleaseImage(*(RImage **) addr);
2326 if (addr)
2327 *(RImage **) addr = image;
2329 assert(ret == NULL);
2331 if (ret)
2332 *(RImage**)ret = image;
2335 return True;
2337 #endif
2339 # include <X11/cursorfont.h>
2340 typedef struct {
2341 char *name;
2342 int id;
2343 } WCursorLookup;
2345 #define CURSOR_ID_NONE (XC_num_glyphs)
2347 static WCursorLookup cursor_table[] = {
2348 {"X_cursor", XC_X_cursor},
2349 {"arrow", XC_arrow},
2350 {"based_arrow_down", XC_based_arrow_down},
2351 {"based_arrow_up", XC_based_arrow_up},
2352 {"boat", XC_boat},
2353 {"bogosity", XC_bogosity},
2354 {"bottom_left_corner", XC_bottom_left_corner},
2355 {"bottom_right_corner", XC_bottom_right_corner},
2356 {"bottom_side", XC_bottom_side},
2357 {"bottom_tee", XC_bottom_tee},
2358 {"box_spiral", XC_box_spiral},
2359 {"center_ptr", XC_center_ptr},
2360 {"circle", XC_circle},
2361 {"clock", XC_clock},
2362 {"coffee_mug", XC_coffee_mug},
2363 {"cross", XC_cross},
2364 {"cross_reverse", XC_cross_reverse},
2365 {"crosshair", XC_crosshair},
2366 {"diamond_cross", XC_diamond_cross},
2367 {"dot", XC_dot},
2368 {"dotbox", XC_dotbox},
2369 {"double_arrow", XC_double_arrow},
2370 {"draft_large", XC_draft_large},
2371 {"draft_small", XC_draft_small},
2372 {"draped_box", XC_draped_box},
2373 {"exchange", XC_exchange},
2374 {"fleur", XC_fleur},
2375 {"gobbler", XC_gobbler},
2376 {"gumby", XC_gumby},
2377 {"hand1", XC_hand1},
2378 {"hand2", XC_hand2},
2379 {"heart", XC_heart},
2380 {"icon", XC_icon},
2381 {"iron_cross", XC_iron_cross},
2382 {"left_ptr", XC_left_ptr},
2383 {"left_side", XC_left_side},
2384 {"left_tee", XC_left_tee},
2385 {"leftbutton", XC_leftbutton},
2386 {"ll_angle", XC_ll_angle},
2387 {"lr_angle", XC_lr_angle},
2388 {"man", XC_man},
2389 {"middlebutton", XC_middlebutton},
2390 {"mouse", XC_mouse},
2391 {"pencil", XC_pencil},
2392 {"pirate", XC_pirate},
2393 {"plus", XC_plus},
2394 {"question_arrow", XC_question_arrow},
2395 {"right_ptr", XC_right_ptr},
2396 {"right_side", XC_right_side},
2397 {"right_tee", XC_right_tee},
2398 {"rightbutton", XC_rightbutton},
2399 {"rtl_logo", XC_rtl_logo},
2400 {"sailboat", XC_sailboat},
2401 {"sb_down_arrow", XC_sb_down_arrow},
2402 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2403 {"sb_left_arrow", XC_sb_left_arrow},
2404 {"sb_right_arrow", XC_sb_right_arrow},
2405 {"sb_up_arrow", XC_sb_up_arrow},
2406 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2407 {"shuttle", XC_shuttle},
2408 {"sizing", XC_sizing},
2409 {"spider", XC_spider},
2410 {"spraycan", XC_spraycan},
2411 {"star", XC_star},
2412 {"target", XC_target},
2413 {"tcross", XC_tcross},
2414 {"top_left_arrow", XC_top_left_arrow},
2415 {"top_left_corner", XC_top_left_corner},
2416 {"top_right_corner", XC_top_right_corner},
2417 {"top_side", XC_top_side},
2418 {"top_tee", XC_top_tee},
2419 {"trek", XC_trek},
2420 {"ul_angle", XC_ul_angle},
2421 {"umbrella", XC_umbrella},
2422 {"ur_angle", XC_ur_angle},
2423 {"watch", XC_watch},
2424 {"xterm", XC_xterm},
2425 {NULL, CURSOR_ID_NONE}
2428 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2430 switch (status) {
2431 case BitmapOpenFailed:
2432 wwarning(_("failed to open bitmap file \"%s\""), filename);
2433 break;
2434 case BitmapFileInvalid:
2435 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2436 break;
2437 case BitmapNoMemory:
2438 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2439 break;
2440 case BitmapSuccess:
2441 XFreePixmap(dpy, bitmap);
2442 break;
2447 * (none)
2448 * (builtin, <cursor_name>)
2449 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2451 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2453 WMPropList *elem;
2454 char *val;
2455 int nelem;
2456 int status = 0;
2458 nelem = WMGetPropListItemCount(pl);
2459 if (nelem < 1) {
2460 return (status);
2462 elem = WMGetFromPLArray(pl, 0);
2463 if (!elem || !WMIsPLString(elem)) {
2464 return (status);
2466 val = WMGetFromPLString(elem);
2468 if (0 == strcasecmp(val, "none")) {
2469 status = 1;
2470 *cursor = None;
2471 } else if (0 == strcasecmp(val, "builtin")) {
2472 int i;
2473 int cursor_id = CURSOR_ID_NONE;
2475 if (2 != nelem) {
2476 wwarning(_("bad number of arguments in cursor specification"));
2477 return (status);
2479 elem = WMGetFromPLArray(pl, 1);
2480 if (!elem || !WMIsPLString(elem)) {
2481 return (status);
2483 val = WMGetFromPLString(elem);
2485 for (i = 0; NULL != cursor_table[i].name; i++) {
2486 if (0 == strcasecmp(val, cursor_table[i].name)) {
2487 cursor_id = cursor_table[i].id;
2488 break;
2491 if (CURSOR_ID_NONE == cursor_id) {
2492 wwarning(_("unknown builtin cursor name \"%s\""), val);
2493 } else {
2494 *cursor = XCreateFontCursor(dpy, cursor_id);
2495 status = 1;
2497 } else if (0 == strcasecmp(val, "bitmap")) {
2498 char *bitmap_name;
2499 char *mask_name;
2500 int bitmap_status;
2501 int mask_status;
2502 Pixmap bitmap;
2503 Pixmap mask;
2504 unsigned int w, h;
2505 int x, y;
2506 XColor fg, bg;
2508 if (3 != nelem) {
2509 wwarning(_("bad number of arguments in cursor specification"));
2510 return (status);
2512 elem = WMGetFromPLArray(pl, 1);
2513 if (!elem || !WMIsPLString(elem)) {
2514 return (status);
2516 val = WMGetFromPLString(elem);
2517 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2518 if (!bitmap_name) {
2519 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2520 return (status);
2522 elem = WMGetFromPLArray(pl, 2);
2523 if (!elem || !WMIsPLString(elem)) {
2524 wfree(bitmap_name);
2525 return (status);
2527 val = WMGetFromPLString(elem);
2528 mask_name = FindImage(wPreferences.pixmap_path, val);
2529 if (!mask_name) {
2530 wfree(bitmap_name);
2531 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2532 return (status);
2534 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2535 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2536 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2537 fg.pixel = scr->black_pixel;
2538 bg.pixel = scr->white_pixel;
2539 XQueryColor(dpy, scr->w_colormap, &fg);
2540 XQueryColor(dpy, scr->w_colormap, &bg);
2541 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2542 status = 1;
2544 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2545 check_bitmap_status(mask_status, mask_name, mask);
2546 wfree(bitmap_name);
2547 wfree(mask_name);
2549 return (status);
2552 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2554 static Cursor cursor;
2555 int status;
2556 int changed = 0;
2558 again:
2559 if (!WMIsPLArray(value)) {
2560 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2561 entry->key, "cursor specification");
2562 if (!changed) {
2563 value = entry->plvalue;
2564 changed = 1;
2565 wwarning(_("using default \"%s\" instead"), entry->default_value);
2566 goto again;
2568 return (False);
2570 status = parse_cursor(scr, value, &cursor);
2571 if (!status) {
2572 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2573 if (!changed) {
2574 value = entry->plvalue;
2575 changed = 1;
2576 wwarning(_("using default \"%s\" instead"), entry->default_value);
2577 goto again;
2579 return (False);
2581 if (ret) {
2582 *ret = &cursor;
2584 if (addr) {
2585 *(Cursor *) addr = cursor;
2587 return (True);
2590 #undef CURSOR_ID_NONE
2592 /* ---------------- value setting functions --------------- */
2593 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2595 return REFRESH_WINDOW_TITLE_COLOR;
2598 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2600 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2603 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2605 switch (which) {
2606 case WM_DOCK:
2607 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2608 break;
2609 case WM_CLIP:
2610 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2611 break;
2612 default:
2613 break;
2615 return 0;
2618 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2620 if (scr->workspaces) {
2621 wWorkspaceForceChange(scr, scr->current_workspace);
2622 wArrangeIcons(scr, False);
2624 return 0;
2627 #if not_used
2628 static int setPositive(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2630 if (*value <= 0)
2631 *(int *)foo = 1;
2633 return 0;
2635 #endif
2637 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2639 Pixmap pixmap;
2640 RImage *img;
2641 int reset = 0;
2643 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2644 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2645 ? WREL_ICON : WREL_FLAT);
2646 if (!img) {
2647 wwarning(_("could not render texture for icon background"));
2648 if (!entry->addr)
2649 wTextureDestroy(scr, *texture);
2650 return 0;
2652 RConvertImage(scr->rcontext, img, &pixmap);
2654 if (scr->icon_tile) {
2655 reset = 1;
2656 RReleaseImage(scr->icon_tile);
2657 XFreePixmap(dpy, scr->icon_tile_pixmap);
2660 scr->icon_tile = img;
2662 /* put the icon in the noticeboard hint */
2663 PropSetIconTileHint(scr, img);
2665 if (!wPreferences.flags.noclip) {
2666 if (scr->clip_tile) {
2667 RReleaseImage(scr->clip_tile);
2669 scr->clip_tile = wClipMakeTile(scr, img);
2672 scr->icon_tile_pixmap = pixmap;
2674 if (scr->def_icon_pixmap) {
2675 XFreePixmap(dpy, scr->def_icon_pixmap);
2676 scr->def_icon_pixmap = None;
2678 if (scr->def_ticon_pixmap) {
2679 XFreePixmap(dpy, scr->def_ticon_pixmap);
2680 scr->def_ticon_pixmap = None;
2683 if (scr->icon_back_texture) {
2684 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2686 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2688 if (scr->clip_balloon)
2689 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2692 * Free the texture as nobody else will use it, nor refer to it.
2694 if (!entry->addr)
2695 wTextureDestroy(scr, *texture);
2697 return (reset ? REFRESH_ICON_TILE : 0);
2700 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2702 if (scr->title_font) {
2703 WMReleaseFont(scr->title_font);
2705 scr->title_font = font;
2707 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2710 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2712 if (scr->menu_title_font) {
2713 WMReleaseFont(scr->menu_title_font);
2716 scr->menu_title_font = font;
2718 return REFRESH_MENU_TITLE_FONT;
2721 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2723 if (scr->menu_entry_font) {
2724 WMReleaseFont(scr->menu_entry_font);
2726 scr->menu_entry_font = font;
2728 return REFRESH_MENU_FONT;
2731 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2733 if (scr->icon_title_font) {
2734 WMReleaseFont(scr->icon_title_font);
2737 scr->icon_title_font = font;
2739 return REFRESH_ICON_FONT;
2742 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2744 if (scr->clip_title_font) {
2745 WMReleaseFont(scr->clip_title_font);
2748 scr->clip_title_font = font;
2750 return REFRESH_ICON_FONT;
2753 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2755 if (scr->workspace_name_font) {
2756 WMReleaseFont(scr->workspace_name_font);
2759 scr->workspace_name_font = font;
2761 return 0;
2764 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2766 if (scr->select_color)
2767 WMReleaseColor(scr->select_color);
2769 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2771 wFreeColor(scr, color->pixel);
2773 return REFRESH_MENU_COLOR;
2776 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2778 if (scr->select_text_color)
2779 WMReleaseColor(scr->select_text_color);
2781 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2783 wFreeColor(scr, color->pixel);
2785 return REFRESH_MENU_COLOR;
2788 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2790 if (scr->clip_title_color[widx])
2791 WMReleaseColor(scr->clip_title_color[widx]);
2792 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2793 #ifdef GRADIENT_CLIP_ARROW
2794 if (widx == CLIP_NORMAL) {
2795 RImage *image;
2796 RColor color1, color2;
2797 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2798 int as = pt - 15; /* 15 = 5+5+5 */
2800 FREE_PIXMAP(scr->clip_arrow_gradient);
2802 color1.red = (color->red >> 8) * 6 / 10;
2803 color1.green = (color->green >> 8) * 6 / 10;
2804 color1.blue = (color->blue >> 8) * 6 / 10;
2806 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2807 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2808 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2810 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2811 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2812 RReleaseImage(image);
2814 #endif /* GRADIENT_CLIP_ARROW */
2816 wFreeColor(scr, color->pixel);
2818 return REFRESH_ICON_TITLE_COLOR;
2821 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2823 if (scr->window_title_color[widx])
2824 WMReleaseColor(scr->window_title_color[widx]);
2826 scr->window_title_color[widx] =
2827 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2829 wFreeColor(scr, color->pixel);
2831 return REFRESH_WINDOW_TITLE_COLOR;
2834 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2836 if (scr->menu_title_color[0])
2837 WMReleaseColor(scr->menu_title_color[0]);
2839 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2841 wFreeColor(scr, color->pixel);
2843 return REFRESH_MENU_TITLE_COLOR;
2846 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2848 if (scr->mtext_color)
2849 WMReleaseColor(scr->mtext_color);
2851 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2853 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2854 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2855 } else {
2856 WMSetColorAlpha(scr->dtext_color, 0xffff);
2859 wFreeColor(scr, color->pixel);
2861 return REFRESH_MENU_COLOR;
2864 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2866 if (scr->dtext_color)
2867 WMReleaseColor(scr->dtext_color);
2869 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2871 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2872 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2873 } else {
2874 WMSetColorAlpha(scr->dtext_color, 0xffff);
2877 wFreeColor(scr, color->pixel);
2879 return REFRESH_MENU_COLOR;
2882 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2884 if (scr->icon_title_color)
2885 WMReleaseColor(scr->icon_title_color);
2886 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2888 wFreeColor(scr, color->pixel);
2890 return REFRESH_ICON_TITLE_COLOR;
2893 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2895 if (scr->icon_title_texture) {
2896 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2898 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2900 return REFRESH_ICON_TITLE_BACK;
2903 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2905 close(scr->helper_fd);
2906 scr->helper_fd = 0;
2907 scr->helper_pid = 0;
2908 scr->flags.backimage_helper_launched = 0;
2911 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2913 WMPropList *val;
2914 char *str;
2915 int i;
2917 if (scr->flags.backimage_helper_launched) {
2918 if (WMGetPropListItemCount(value) == 0) {
2919 SendHelperMessage(scr, 'C', 0, NULL);
2920 SendHelperMessage(scr, 'K', 0, NULL);
2922 WMReleasePropList(value);
2923 return 0;
2925 } else {
2926 pid_t pid;
2927 int filedes[2];
2929 if (WMGetPropListItemCount(value) == 0)
2930 return 0;
2932 if (pipe(filedes) < 0) {
2933 wsyserror("pipe() failed:can't set workspace specific background image");
2935 WMReleasePropList(value);
2936 return 0;
2939 pid = fork();
2940 if (pid < 0) {
2941 wsyserror("fork() failed:can't set workspace specific background image");
2942 if (close(filedes[0]) < 0)
2943 wsyserror("could not close pipe");
2944 if (close(filedes[1]) < 0)
2945 wsyserror("could not close pipe");
2947 } else if (pid == 0) {
2948 char *dither;
2950 SetupEnvironment(scr);
2952 if (close(0) < 0)
2953 wsyserror("could not close pipe");
2954 if (dup(filedes[0]) < 0) {
2955 wsyserror("dup() failed:can't set workspace specific background image");
2957 dither = wPreferences.no_dithering ? "-m" : "-d";
2958 if (wPreferences.smooth_workspace_back)
2959 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2960 else
2961 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2962 wsyserror("could not execute wmsetbg");
2963 exit(1);
2964 } else {
2966 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2967 wsyserror("error setting close-on-exec flag");
2969 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2970 wsyserror("error setting close-on-exec flag");
2973 scr->helper_fd = filedes[1];
2974 scr->helper_pid = pid;
2975 scr->flags.backimage_helper_launched = 1;
2977 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2979 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2984 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2985 val = WMGetFromPLArray(value, i);
2986 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2987 str = WMGetPropListDescription(val, False);
2989 SendHelperMessage(scr, 'S', i + 1, str);
2991 wfree(str);
2992 } else {
2993 SendHelperMessage(scr, 'U', i + 1, NULL);
2996 sleep(1);
2998 WMReleasePropList(value);
2999 return 0;
3002 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
3004 if (scr->flags.backimage_helper_launched) {
3005 char *str;
3007 if (WMGetPropListItemCount(value) == 0) {
3008 SendHelperMessage(scr, 'U', 0, NULL);
3009 } else {
3010 /* set the default workspace background to this one */
3011 str = WMGetPropListDescription(value, False);
3012 if (str) {
3013 SendHelperMessage(scr, 'S', 0, str);
3014 wfree(str);
3015 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
3016 } else {
3017 SendHelperMessage(scr, 'U', 0, NULL);
3020 } else if (WMGetPropListItemCount(value) > 0) {
3021 char *command;
3022 char *text;
3023 char *dither;
3024 int len;
3026 SetupEnvironment(scr);
3027 text = WMGetPropListDescription(value, False);
3028 len = strlen(text) + 40;
3029 command = wmalloc(len);
3030 dither = wPreferences.no_dithering ? "-m" : "-d";
3031 if (wPreferences.smooth_workspace_back)
3032 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3033 else
3034 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3035 wfree(text);
3036 system(command);
3037 wfree(command);
3039 WMReleasePropList(value);
3041 return 0;
3044 #ifdef VIRTUAL_DESKTOP
3045 static int setVirtualDeskEnable(WScreen * scr, WDefaultEntry * entry, void *foo, void *bar)
3047 wWorkspaceUpdateEdge(scr);
3048 return 0;
3050 #endif
3052 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3054 if (scr->widget_texture) {
3055 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3057 scr->widget_texture = *(WTexSolid **) texture;
3059 return 0;
3062 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3064 if (scr->window_title_texture[WS_FOCUSED]) {
3065 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3067 scr->window_title_texture[WS_FOCUSED] = *texture;
3069 return REFRESH_WINDOW_TEXTURES;
3072 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3074 if (scr->window_title_texture[WS_PFOCUSED]) {
3075 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3077 scr->window_title_texture[WS_PFOCUSED] = *texture;
3079 return REFRESH_WINDOW_TEXTURES;
3082 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3084 if (scr->window_title_texture[WS_UNFOCUSED]) {
3085 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3087 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3089 return REFRESH_WINDOW_TEXTURES;
3092 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3094 if (scr->resizebar_texture[0]) {
3095 wTextureDestroy(scr, scr->resizebar_texture[0]);
3097 scr->resizebar_texture[0] = *texture;
3099 return REFRESH_WINDOW_TEXTURES;
3102 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3104 if (scr->menu_title_texture[0]) {
3105 wTextureDestroy(scr, scr->menu_title_texture[0]);
3107 scr->menu_title_texture[0] = *texture;
3109 return REFRESH_MENU_TITLE_TEXTURE;
3112 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3114 if (scr->menu_item_texture) {
3115 wTextureDestroy(scr, scr->menu_item_texture);
3116 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3118 scr->menu_item_texture = *texture;
3120 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3122 return REFRESH_MENU_TEXTURE;
3125 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
3127 WWindow *wwin;
3128 wKeyBindings[widx] = *shortcut;
3130 wwin = scr->focused_window;
3132 while (wwin != NULL) {
3133 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3135 if (!WFLAGP(wwin, no_bind_keys)) {
3136 wWindowSetKeyGrabs(wwin);
3138 wwin = wwin->prev;
3141 return 0;
3144 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3146 wScreenUpdateUsableArea(scr);
3147 wArrangeIcons(scr, True);
3149 return 0;
3152 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3154 wScreenUpdateUsableArea(scr);
3156 return 0;
3159 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3161 return REFRESH_MENU_TEXTURE;
3164 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3166 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3168 RCopyArea(img, image, x, y, w, h, 0, 0);
3170 return img;
3173 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
3175 char *path;
3176 RImage *bgimage;
3177 int cwidth, cheight;
3178 WPreferences *prefs = (WPreferences *) foo;
3180 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3181 if (prefs->swtileImage)
3182 RReleaseImage(prefs->swtileImage);
3183 prefs->swtileImage = NULL;
3185 WMReleasePropList(array);
3186 return 0;
3189 switch (WMGetPropListItemCount(array)) {
3190 case 4:
3191 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3192 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3193 break;
3194 } else
3195 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3197 if (!path) {
3198 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3199 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3200 } else {
3201 bgimage = RLoadImage(scr->rcontext, path, 0);
3202 if (!bgimage) {
3203 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3204 wfree(path);
3205 } else {
3206 wfree(path);
3208 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3209 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3211 if (cwidth <= 0 || cheight <= 0 ||
3212 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3213 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3214 else {
3215 int i;
3216 int swidth, theight;
3217 for (i = 0; i < 9; i++) {
3218 if (prefs->swbackImage[i])
3219 RReleaseImage(prefs->swbackImage[i]);
3220 prefs->swbackImage[i] = NULL;
3222 swidth = (bgimage->width - cwidth) / 2;
3223 theight = (bgimage->height - cheight) / 2;
3225 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3226 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3227 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3228 swidth, theight);
3230 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3231 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3232 cwidth, cheight);
3233 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3234 swidth, cheight);
3236 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3237 swidth, theight);
3238 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3239 cwidth, theight);
3240 prefs->swbackImage[8] =
3241 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3242 theight);
3244 // check if anything failed
3245 for (i = 0; i < 9; i++) {
3246 if (!prefs->swbackImage[i]) {
3247 for (; i >= 0; --i) {
3248 RReleaseImage(prefs->swbackImage[i]);
3249 prefs->swbackImage[i] = NULL;
3251 break;
3255 RReleaseImage(bgimage);
3259 case 1:
3260 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3261 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3262 break;
3263 } else
3264 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3266 if (!path) {
3267 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3268 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3269 } else {
3270 if (prefs->swtileImage)
3271 RReleaseImage(prefs->swtileImage);
3273 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3274 if (!prefs->swtileImage) {
3275 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3277 wfree(path);
3279 break;
3281 default:
3282 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3283 break;
3286 WMReleasePropList(array);
3288 return 0;
3292 static int
3293 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3295 return REFRESH_BUTTON_IMAGES;
3300 * Very ugly kluge.
3301 * Need access to the double click variables, so that all widgets in
3302 * wmaker panels will have the same dbl-click values.
3303 * TODO: figure a better way of dealing with it.
3305 #include <WINGs/WINGsP.h>
3307 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3309 extern _WINGsConfiguration WINGsConfiguration;
3311 if (*value <= 0)
3312 *(int *)foo = 1;
3314 WINGsConfiguration.doubleClickDelay = *value;
3316 return 0;
3319 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3321 if (wCursor[widx] != None) {
3322 XFreeCursor(dpy, wCursor[widx]);
3325 wCursor[widx] = *cursor;
3327 if (widx == WCUR_ROOT && *cursor != None) {
3328 XDefineCursor(dpy, scr->root_win, *cursor);
3331 return 0;