Left Half / Right Half Maximize
[wmaker-crm.git] / src / defaults.c
blobef1fb71598eeba72005ecf845297f66147f589cc
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 /* style options */
478 {"MenuStyle", "normal", seMenuStyles,
479 &wPreferences.menu_style, getEnum, setMenuStyle},
480 {"WidgetColor", "(solid, gray)", NULL,
481 NULL, getTexture, setWidgetColor,
483 {"WorkspaceSpecificBack", "()", NULL,
484 NULL, getWSSpecificBackground, setWorkspaceSpecificBack},
485 /* WorkspaceBack must come after WorkspaceSpecificBack or
486 * WorkspaceBack wont know WorkspaceSpecificBack was also
487 * specified and 2 copies of wmsetbg will be launched */
488 {"WorkspaceBack", "(solid, black)", NULL,
489 NULL, getWSBackground, setWorkspaceBack},
490 {"SmoothWorkspaceBack", "NO", NULL,
491 NULL, getBool, NULL},
492 {"IconBack", "(solid, gray)", NULL,
493 NULL, getTexture, setIconTile},
494 {"TitleJustify", "center", seJustifications,
495 &wPreferences.title_justification, getEnum, setJustify},
496 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
497 NULL, getFont, setWinTitleFont,
499 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
500 &wPreferences.window_title_clearance, getInt, setClearance},
501 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
502 &wPreferences.menu_title_clearance, getInt, setClearance},
503 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
504 &wPreferences.menu_text_clearance, getInt, setClearance},
505 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
506 NULL, getFont, setMenuTitleFont},
507 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
508 NULL, getFont, setMenuTextFont},
509 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
510 NULL, getFont, setIconTitleFont},
511 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
512 NULL, getFont, setClipTitleFont},
513 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
514 NULL, getFont, setLargeDisplayFont},
515 {"HighlightColor", "white", NULL,
516 NULL, getColor, setHightlight},
517 {"HighlightTextColor", "black", NULL,
518 NULL, getColor, setHightlightText},
519 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
520 NULL, getColor, setClipTitleColor},
521 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
522 NULL, getColor, setClipTitleColor},
523 {"FTitleColor", "white", (void *)WS_FOCUSED,
524 NULL, getColor, setWTitleColor},
525 {"PTitleColor", "white", (void *)WS_PFOCUSED,
526 NULL, getColor, setWTitleColor},
527 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
528 NULL, getColor, setWTitleColor},
529 {"FTitleBack", "(solid, black)", NULL,
530 NULL, getTexture, setFTitleBack},
531 {"PTitleBack", "(solid, \"#616161\")", NULL,
532 NULL, getTexture, setPTitleBack},
533 {"UTitleBack", "(solid, gray)", NULL,
534 NULL, getTexture, setUTitleBack},
535 {"ResizebarBack", "(solid, gray)", NULL,
536 NULL, getTexture, setResizebarBack},
537 {"MenuTitleColor", "white", NULL,
538 NULL, getColor, setMenuTitleColor},
539 {"MenuTextColor", "black", NULL,
540 NULL, getColor, setMenuTextColor},
541 {"MenuDisabledColor", "\"#616161\"", NULL,
542 NULL, getColor, setMenuDisabledColor},
543 {"MenuTitleBack", "(solid, black)", NULL,
544 NULL, getTexture, setMenuTitleBack},
545 {"MenuTextBack", "(solid, gray)", NULL,
546 NULL, getTexture, setMenuTextBack},
547 {"IconTitleColor", "white", NULL,
548 NULL, getColor, setIconTitleColor},
549 {"IconTitleBack", "black", NULL,
550 NULL, getColor, setIconTitleBack},
551 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
552 NULL, getPropList, setSwPOptions},
553 /* keybindings */
554 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
555 NULL, getKeybind, setKeyGrab},
556 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
557 NULL, getKeybind, setKeyGrab},
558 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
559 NULL, getKeybind, setKeyGrab},
560 {"ClipLowerKey", "None", (void *)WKBD_CLIPLOWER,
561 NULL, getKeybind, setKeyGrab},
562 {"ClipRaiseKey", "None", (void *)WKBD_CLIPRAISE,
563 NULL, getKeybind, setKeyGrab},
564 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
565 NULL, getKeybind, setKeyGrab},
566 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
567 NULL, getKeybind, setKeyGrab},
568 {"HideKey", "None", (void *)WKBD_HIDE,
569 NULL, getKeybind, setKeyGrab},
570 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
571 NULL, getKeybind, setKeyGrab},
572 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
573 NULL, getKeybind, setKeyGrab},
574 {"CloseKey", "None", (void *)WKBD_CLOSE,
575 NULL, getKeybind, setKeyGrab},
576 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
577 NULL, getKeybind, setKeyGrab},
578 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
579 NULL, getKeybind, setKeyGrab},
580 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
581 NULL, getKeybind, setKeyGrab},
582 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
583 NULL, getKeybind, setKeyGrab},
584 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
585 NULL, getKeybind, setKeyGrab},
586 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
587 NULL, getKeybind, setKeyGrab},
588 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
589 NULL, getKeybind, setKeyGrab},
590 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
591 NULL, getKeybind, setKeyGrab},
592 {"ShadeKey", "None", (void *)WKBD_SHADE,
593 NULL, getKeybind, setKeyGrab},
594 {"SelectKey", "None", (void *)WKBD_SELECT,
595 NULL, getKeybind, setKeyGrab},
596 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
597 NULL, getKeybind, setKeyGrab},
598 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
599 NULL, getKeybind, setKeyGrab},
600 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
601 NULL, getKeybind, setKeyGrab},
602 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
603 NULL, getKeybind, setKeyGrab},
604 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
605 NULL, getKeybind, setKeyGrab},
606 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
607 NULL, getKeybind, setKeyGrab},
608 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
609 NULL, getKeybind, setKeyGrab},
610 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
611 NULL, getKeybind, setKeyGrab},
612 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
613 NULL, getKeybind, setKeyGrab},
614 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
615 NULL, getKeybind, setKeyGrab},
616 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
617 NULL, getKeybind, setKeyGrab},
618 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
619 NULL, getKeybind, setKeyGrab},
620 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
621 NULL, getKeybind, setKeyGrab},
622 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
623 NULL, getKeybind, setKeyGrab},
624 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
625 NULL, getKeybind, setKeyGrab},
626 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
627 NULL, getKeybind, setKeyGrab},
628 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
629 NULL, getKeybind, setKeyGrab},
630 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
631 NULL, getKeybind, setKeyGrab},
632 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
633 NULL, getKeybind, setKeyGrab},
634 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
635 NULL, getKeybind, setKeyGrab}
636 , {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
637 NULL, getKeybind, setKeyGrab},
638 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
639 NULL, getKeybind, setKeyGrab},
640 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
641 NULL, getKeybind, setKeyGrab},
642 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
643 NULL, getKeybind, setKeyGrab},
644 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
645 NULL, getKeybind, setKeyGrab},
646 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
647 NULL, getKeybind, setKeyGrab},
648 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
649 NULL, getKeybind, setKeyGrab},
651 #ifdef KEEP_XKB_LOCK_STATUS
652 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
653 NULL, getKeybind, setKeyGrab},
654 {"KbdModeLock", "NO", NULL,
655 &wPreferences.modelock, getBool, NULL},
656 #endif /* KEEP_XKB_LOCK_STATUS */
658 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
659 NULL, getCursor, setCursor},
660 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
661 NULL, getCursor, setCursor},
662 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
663 NULL, getCursor, setCursor},
664 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
665 NULL, getCursor, setCursor},
666 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
667 (void *)WCUR_TOPLEFTRESIZE,
668 NULL, getCursor, setCursor},
669 {"TopRightResizeCursor", "(builtin, top_right_corner)",
670 (void *)WCUR_TOPRIGHTRESIZE,
671 NULL, getCursor, setCursor},
672 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
673 (void *)WCUR_BOTTOMLEFTRESIZE,
674 NULL, getCursor, setCursor},
675 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
676 (void *)WCUR_BOTTOMRIGHTRESIZE,
677 NULL, getCursor, setCursor},
678 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
679 (void *)WCUR_VERTICALRESIZE,
680 NULL, getCursor, setCursor},
681 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
682 (void *)WCUR_HORIZONRESIZE,
683 NULL, getCursor, setCursor},
684 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
685 NULL, getCursor, setCursor},
686 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
687 NULL, getCursor, setCursor},
688 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
689 NULL, getCursor, setCursor},
690 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
691 NULL, getCursor, setCursor}
694 #if 0
695 static void rereadDefaults(void);
696 #endif
698 #if 0
699 static void rereadDefaults(void)
701 /* must defer the update because accessing X data from a
702 * signal handler can mess up Xlib */
705 #endif
707 static void initDefaults()
709 unsigned int i;
710 WDefaultEntry *entry;
712 WMPLSetCaseSensitive(False);
714 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
715 entry = &optionList[i];
717 entry->plkey = WMCreatePLString(entry->key);
718 if (entry->default_value)
719 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
720 else
721 entry->plvalue = NULL;
724 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
725 entry = &staticOptionList[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;
735 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
736 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
738 PLRegister(wDomainName, rereadDefaults);
739 PLRegister(wAttributeDomainName, rereadDefaults);
743 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
745 WMPropList *globalDict = NULL;
746 char path[PATH_MAX];
747 struct stat stbuf;
749 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
750 if (stat(path, &stbuf) >= 0) {
751 globalDict = WMReadPropListFromFile(path);
752 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
753 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
754 WMReleasePropList(globalDict);
755 globalDict = NULL;
756 } else if (!globalDict) {
757 wwarning(_("could not load domain %s from global defaults database"), domainName);
761 return globalDict;
764 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
765 static void prependMenu(WMPropList * destarr, WMPropList * array)
767 WMPropList *item;
768 int i;
770 for (i = 0; i < WMGetPropListItemCount(array); i++) {
771 item = WMGetFromPLArray(array, i);
772 if (item)
773 WMInsertInPLArray(destarr, i + 1, item);
777 static void appendMenu(WMPropList * destarr, WMPropList * array)
779 WMPropList *item;
780 int i;
782 for (i = 0; i < WMGetPropListItemCount(array); i++) {
783 item = WMGetFromPLArray(array, i);
784 if (item)
785 WMAddToPLArray(destarr, item);
788 #endif
790 /* Fixup paths for cached pixmaps from .AppInfo to Library/WindowMaker/... */
791 static Bool fixupCachedPixmapsPaths(WMPropList * dict)
793 WMPropList *allApps, *app, *props, *iconkey, *icon, *newicon;
794 char *path, *fixedpath, *ptr, *search;
795 int i, len, slen;
796 Bool changed = False;
798 search = "/.AppInfo/WindowMaker/";
799 slen = strlen(search);
801 iconkey = WMCreatePLString("Icon");
802 allApps = WMGetPLDictionaryKeys(dict);
804 for (i = 0; i < WMGetPropListItemCount(allApps); i++) {
805 app = WMGetFromPLArray(allApps, i);
806 props = WMGetFromPLDictionary(dict, app);
807 if (!props)
808 continue;
809 icon = WMGetFromPLDictionary(props, iconkey);
810 if (icon && WMIsPLString(icon)) {
811 path = WMGetFromPLString(icon);
812 ptr = strstr(path, search);
813 if (ptr) {
814 changed = True;
815 len = (ptr - path);
816 fixedpath = wmalloc(strlen(path) + 32);
817 strncpy(fixedpath, path, len);
818 fixedpath[len] = 0;
819 strcat(fixedpath, "/Library/WindowMaker/CachedPixmaps/");
820 strcat(fixedpath, ptr + slen);
821 newicon = WMCreatePLString(fixedpath);
822 WMPutInPLDictionary(props, iconkey, newicon);
823 WMReleasePropList(newicon);
824 wfree(fixedpath);
829 WMReleasePropList(allApps);
830 WMReleasePropList(iconkey);
832 return changed;
835 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
837 WMPropList *menu = menuDomain->dictionary;
838 WMPropList *submenu;
840 if (!menu || !WMIsPLArray(menu))
841 return;
843 #ifdef GLOBAL_PREAMBLE_MENU_FILE
844 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
846 if (submenu && !WMIsPLArray(submenu)) {
847 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
848 WMReleasePropList(submenu);
849 submenu = NULL;
851 if (submenu) {
852 prependMenu(menu, submenu);
853 WMReleasePropList(submenu);
855 #endif
857 #ifdef GLOBAL_EPILOGUE_MENU_FILE
858 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
860 if (submenu && !WMIsPLArray(submenu)) {
861 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
862 WMReleasePropList(submenu);
863 submenu = NULL;
865 if (submenu) {
866 appendMenu(menu, submenu);
867 WMReleasePropList(submenu);
869 #endif
871 menuDomain->dictionary = menu;
874 #if 0
875 WMPropList *wDefaultsInit(int screen_number)
877 static int defaults_inited = 0;
878 WMPropList *dict;
880 if (!defaults_inited) {
881 initDefaults();
884 dict = PLGetDomain(wDomainName);
885 if (!dict) {
886 wwarning(_("could not read domain \"%s\" from defaults database"), WMGetFromPLString(wDomainName));
889 return dict;
891 #endif
893 void wDefaultsDestroyDomain(WDDomain * domain)
895 if (domain->dictionary)
896 WMReleasePropList(domain->dictionary);
897 wfree(domain->path);
898 wfree(domain);
901 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
903 WDDomain *db;
904 struct stat stbuf;
905 static int inited = 0;
906 char path[PATH_MAX];
907 char *the_path;
908 WMPropList *shared_dict = NULL;
910 if (!inited) {
911 inited = 1;
912 initDefaults();
915 db = wmalloc(sizeof(WDDomain));
916 memset(db, 0, sizeof(WDDomain));
917 db->domain_name = domain;
918 db->path = wdefaultspathfordomain(domain);
919 the_path = db->path;
921 if (the_path && stat(the_path, &stbuf) >= 0) {
922 db->dictionary = WMReadPropListFromFile(the_path);
923 if (db->dictionary) {
924 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
925 WMReleasePropList(db->dictionary);
926 db->dictionary = NULL;
927 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
929 if (strcmp(domain, "WMWindowAttributes") == 0 && db->dictionary) {
930 if (fixupCachedPixmapsPaths(db->dictionary)) {
931 WMWritePropListToFile(db->dictionary, db->path, True);
932 /* re-read the timestamp. if this fails take current time */
933 if (stat(db->path, &stbuf) < 0) {
934 stbuf.st_mtime = time(NULL);
938 db->timestamp = stbuf.st_mtime;
939 } else {
940 wwarning(_("could not load domain %s from user defaults database"), domain);
944 /* global system dictionary */
945 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
946 if (stat(path, &stbuf) >= 0) {
947 shared_dict = WMReadPropListFromFile(path);
948 if (shared_dict) {
949 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
950 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
951 domain, path);
952 WMReleasePropList(shared_dict);
953 shared_dict = NULL;
954 } else {
955 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
956 WMIsPLDictionary(db->dictionary)) {
957 WMMergePLDictionaries(shared_dict, db->dictionary, True);
958 WMReleasePropList(db->dictionary);
959 db->dictionary = shared_dict;
960 if (stbuf.st_mtime > db->timestamp)
961 db->timestamp = stbuf.st_mtime;
962 } else if (!db->dictionary) {
963 db->dictionary = shared_dict;
964 if (stbuf.st_mtime > db->timestamp)
965 db->timestamp = stbuf.st_mtime;
968 } else {
969 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
973 return db;
976 void wReadStaticDefaults(WMPropList * dict)
978 WMPropList *plvalue;
979 WDefaultEntry *entry;
980 unsigned int i;
981 void *tdata;
983 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
984 entry = &staticOptionList[i];
986 if (dict)
987 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
988 else
989 plvalue = NULL;
991 if (!plvalue) {
992 /* no default in the DB. Use builtin default */
993 plvalue = entry->plvalue;
996 if (plvalue) {
997 /* convert data */
998 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
999 if (entry->update) {
1000 (*entry->update) (NULL, entry, tdata, entry->extra_data);
1006 void wDefaultsCheckDomains(void)
1008 WScreen *scr;
1009 struct stat stbuf;
1010 WMPropList *shared_dict = NULL;
1011 WMPropList *dict;
1012 int i;
1014 #ifdef HEARTBEAT
1015 puts("Checking domains...");
1016 #endif
1017 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1018 #ifdef HEARTBEAT
1019 puts("Checking WindowMaker domain");
1020 #endif
1021 WDWindowMaker->timestamp = stbuf.st_mtime;
1023 /* global dictionary */
1024 shared_dict = readGlobalDomain("WindowMaker", True);
1025 /* user dictionary */
1026 dict = WMReadPropListFromFile(WDWindowMaker->path);
1027 if (dict) {
1028 if (!WMIsPLDictionary(dict)) {
1029 WMReleasePropList(dict);
1030 dict = NULL;
1031 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1032 "WindowMaker", WDWindowMaker->path);
1033 } else {
1034 if (shared_dict) {
1035 WMMergePLDictionaries(shared_dict, dict, True);
1036 WMReleasePropList(dict);
1037 dict = shared_dict;
1038 shared_dict = NULL;
1040 for (i = 0; i < wScreenCount; i++) {
1041 scr = wScreenWithNumber(i);
1042 if (scr)
1043 wReadDefaults(scr, dict);
1045 if (WDWindowMaker->dictionary) {
1046 WMReleasePropList(WDWindowMaker->dictionary);
1048 WDWindowMaker->dictionary = dict;
1050 } else {
1051 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1053 if (shared_dict) {
1054 WMReleasePropList(shared_dict);
1058 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1059 #ifdef HEARTBEAT
1060 puts("Checking WMWindowAttributes domain");
1061 #endif
1062 /* global dictionary */
1063 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1064 /* user dictionary */
1065 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1066 if (dict) {
1067 if (!WMIsPLDictionary(dict)) {
1068 WMReleasePropList(dict);
1069 dict = NULL;
1070 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1071 "WMWindowAttributes", WDWindowAttributes->path);
1072 } else {
1073 if (shared_dict) {
1074 WMMergePLDictionaries(shared_dict, dict, True);
1075 WMReleasePropList(dict);
1076 dict = shared_dict;
1077 shared_dict = NULL;
1079 if (WDWindowAttributes->dictionary) {
1080 WMReleasePropList(WDWindowAttributes->dictionary);
1082 WDWindowAttributes->dictionary = dict;
1083 for (i = 0; i < wScreenCount; i++) {
1084 scr = wScreenWithNumber(i);
1085 if (scr) {
1086 RImage *image;
1088 wDefaultUpdateIcons(scr);
1090 /* Update the panel image if changed */
1091 /* Don't worry. If the image is the same these
1092 * functions will have no performance impact. */
1093 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1095 if (!image) {
1096 wwarning(_("could not load logo image for panels: %s"),
1097 RMessageForError(RErrorCode));
1098 } else {
1099 WMSetApplicationIconImage(scr->wmscreen, image);
1100 RReleaseImage(image);
1105 } else {
1106 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1108 WDWindowAttributes->timestamp = stbuf.st_mtime;
1109 if (shared_dict) {
1110 WMReleasePropList(shared_dict);
1114 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1115 dict = WMReadPropListFromFile(WDRootMenu->path);
1116 #ifdef HEARTBEAT
1117 puts("Checking WMRootMenu domain");
1118 #endif
1119 if (dict) {
1120 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1121 WMReleasePropList(dict);
1122 dict = NULL;
1123 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1124 "WMRootMenu", WDRootMenu->path);
1125 } else {
1126 if (WDRootMenu->dictionary) {
1127 WMReleasePropList(WDRootMenu->dictionary);
1129 WDRootMenu->dictionary = dict;
1130 wDefaultsMergeGlobalMenus(WDRootMenu);
1132 } else {
1133 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1135 WDRootMenu->timestamp = stbuf.st_mtime;
1139 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1141 WMPropList *plvalue, *old_value;
1142 WDefaultEntry *entry;
1143 unsigned int i, must_update;
1144 int update_workspace_back = 0; /* kluge :/ */
1145 unsigned int needs_refresh;
1146 void *tdata;
1147 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1149 must_update = 0;
1151 needs_refresh = 0;
1153 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1154 entry = &optionList[i];
1156 if (new_dict)
1157 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1158 else
1159 plvalue = NULL;
1161 if (!old_dict)
1162 old_value = NULL;
1163 else
1164 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1166 if (!plvalue && !old_value) {
1167 /* no default in the DB. Use builtin default */
1168 plvalue = entry->plvalue;
1169 if (plvalue && new_dict) {
1170 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1171 must_update = 1;
1173 } else if (!plvalue) {
1174 /* value was deleted from DB. Keep current value */
1175 continue;
1176 } else if (!old_value) {
1177 /* set value for the 1st time */
1178 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1179 /* value has changed */
1180 } else {
1182 if (strcmp(entry->key, "WorkspaceBack") == 0
1183 && update_workspace_back && scr->flags.backimage_helper_launched) {
1184 } else {
1185 /* value was not changed since last time */
1186 continue;
1190 if (plvalue) {
1191 #ifdef DEBUG
1192 printf("Updating %s to %s\n", entry->key, WMGetPropListDescription(plvalue, False));
1193 #endif
1194 /* convert data */
1195 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1197 * If the WorkspaceSpecificBack data has been changed
1198 * so that the helper will be launched now, we must be
1199 * sure to send the default background texture config
1200 * to the helper.
1202 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1203 && !scr->flags.backimage_helper_launched) {
1204 update_workspace_back = 1;
1206 if (entry->update) {
1207 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1213 if (needs_refresh != 0 && !scr->flags.startup) {
1214 int foo;
1216 foo = 0;
1217 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1218 foo |= WTextureSettings;
1219 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1220 foo |= WFontSettings;
1221 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1222 foo |= WColorSettings;
1223 if (foo)
1224 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1225 (void *)(uintptr_t) foo);
1227 foo = 0;
1228 if (needs_refresh & REFRESH_MENU_TEXTURE)
1229 foo |= WTextureSettings;
1230 if (needs_refresh & REFRESH_MENU_FONT)
1231 foo |= WFontSettings;
1232 if (needs_refresh & REFRESH_MENU_COLOR)
1233 foo |= WColorSettings;
1234 if (foo)
1235 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1237 foo = 0;
1238 if (needs_refresh & REFRESH_WINDOW_FONT) {
1239 foo |= WFontSettings;
1241 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1242 foo |= WTextureSettings;
1244 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1245 foo |= WColorSettings;
1247 if (foo)
1248 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1250 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1251 foo = 0;
1252 if (needs_refresh & REFRESH_ICON_FONT) {
1253 foo |= WFontSettings;
1255 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1256 foo |= WTextureSettings;
1258 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1259 foo |= WTextureSettings;
1261 if (foo)
1262 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1263 (void *)(uintptr_t) foo);
1265 if (needs_refresh & REFRESH_ICON_TILE)
1266 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1270 void wDefaultUpdateIcons(WScreen * scr)
1272 WAppIcon *aicon = scr->app_icon_list;
1273 WWindow *wwin = scr->focused_window;
1274 char *file;
1276 while (aicon) {
1277 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1278 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1279 || (file && !aicon->icon->file)) {
1280 RImage *new_image;
1282 if (aicon->icon->file)
1283 wfree(aicon->icon->file);
1284 aicon->icon->file = wstrdup(file);
1286 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1287 if (new_image) {
1288 wIconChangeImage(aicon->icon, new_image);
1289 wAppIconPaint(aicon);
1292 aicon = aicon->next;
1295 if (!wPreferences.flags.noclip)
1296 wClipIconPaint(scr->clip_icon);
1298 while (wwin) {
1299 if (wwin->icon && wwin->flags.miniaturized) {
1300 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1301 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1302 || (file && !wwin->icon->file)) {
1303 RImage *new_image;
1305 if (wwin->icon->file)
1306 wfree(wwin->icon->file);
1307 wwin->icon->file = wstrdup(file);
1309 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1310 if (new_image)
1311 wIconChangeImage(wwin->icon, new_image);
1314 wwin = wwin->prev;
1318 /* --------------------------- Local ----------------------- */
1320 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1321 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1322 entry->key, x); \
1323 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1324 var = entry->default_value;\
1325 } else var = WMGetFromPLString(value)\
1328 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1330 char *str;
1331 WOptionEnumeration *v;
1332 char buffer[TOTAL_VALUES_LENGTH];
1334 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1335 for (v = values; v->string != NULL; v++) {
1336 if (strcasecmp(v->string, str) == 0)
1337 return v->value;
1341 buffer[0] = 0;
1342 for (v = values; v->string != NULL; v++) {
1343 if (!v->is_alias) {
1344 if (buffer[0] != 0)
1345 strcat(buffer, ", ");
1346 strcat(buffer, v->string);
1349 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1351 if (def) {
1352 return string2index(key, val, NULL, values);
1355 return -1;
1359 * value - is the value in the defaults DB
1360 * addr - is the address to store the data
1361 * ret - is the address to store a pointer to a temporary buffer. ret
1362 * must not be freed and is used by the set functions
1364 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1366 static char data;
1367 char *val;
1368 int second_pass = 0;
1370 GET_STRING_OR_DEFAULT("Boolean", val);
1372 again:
1373 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1374 || strcasecmp(val, "YES") == 0) {
1376 data = 1;
1377 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1378 || strcasecmp(val, "NO") == 0) {
1379 data = 0;
1380 } else {
1381 int i;
1382 if (sscanf(val, "%i", &i) == 1) {
1383 if (i != 0)
1384 data = 1;
1385 else
1386 data = 0;
1387 } else {
1388 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1389 if (second_pass == 0) {
1390 val = WMGetFromPLString(entry->plvalue);
1391 second_pass = 1;
1392 wwarning(_("using default \"%s\" instead"), val);
1393 goto again;
1395 return False;
1399 if (ret)
1400 *ret = &data;
1401 if (addr)
1402 *(char *)addr = data;
1404 return True;
1407 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1409 static int data;
1410 char *val;
1412 GET_STRING_OR_DEFAULT("Integer", val);
1414 if (sscanf(val, "%i", &data) != 1) {
1415 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1416 val = WMGetFromPLString(entry->plvalue);
1417 wwarning(_("using default \"%s\" instead"), val);
1418 if (sscanf(val, "%i", &data) != 1) {
1419 return False;
1423 if (ret)
1424 *ret = &data;
1425 if (addr)
1426 *(int *)addr = data;
1428 return True;
1431 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1433 static WCoord data;
1434 char *val_x, *val_y;
1435 int nelem, changed = 0;
1436 WMPropList *elem_x, *elem_y;
1438 again:
1439 if (!WMIsPLArray(value)) {
1440 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1441 if (changed == 0) {
1442 value = entry->plvalue;
1443 changed = 1;
1444 wwarning(_("using default \"%s\" instead"), entry->default_value);
1445 goto again;
1447 return False;
1450 nelem = WMGetPropListItemCount(value);
1451 if (nelem != 2) {
1452 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1453 if (changed == 0) {
1454 value = entry->plvalue;
1455 changed = 1;
1456 wwarning(_("using default \"%s\" instead"), entry->default_value);
1457 goto again;
1459 return False;
1462 elem_x = WMGetFromPLArray(value, 0);
1463 elem_y = WMGetFromPLArray(value, 1);
1465 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1466 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1467 if (changed == 0) {
1468 value = entry->plvalue;
1469 changed = 1;
1470 wwarning(_("using default \"%s\" instead"), entry->default_value);
1471 goto again;
1473 return False;
1476 val_x = WMGetFromPLString(elem_x);
1477 val_y = WMGetFromPLString(elem_y);
1479 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1480 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1481 if (changed == 0) {
1482 value = entry->plvalue;
1483 changed = 1;
1484 wwarning(_("using default \"%s\" instead"), entry->default_value);
1485 goto again;
1487 return False;
1490 if (data.x < 0)
1491 data.x = 0;
1492 else if (data.x > scr->scr_width / 3)
1493 data.x = scr->scr_width / 3;
1494 if (data.y < 0)
1495 data.y = 0;
1496 else if (data.y > scr->scr_height / 3)
1497 data.y = scr->scr_height / 3;
1499 if (ret)
1500 *ret = &data;
1501 if (addr)
1502 *(WCoord *) addr = data;
1504 return True;
1507 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1509 WMRetainPropList(value);
1511 *ret = value;
1513 return True;
1516 #if 0
1517 /* This function is not used at the moment. */
1518 static int getString(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1520 static char *data;
1522 GET_STRING_OR_DEFAULT("String", data);
1524 if (!data) {
1525 data = WMGetFromPLString(entry->plvalue);
1526 if (!data)
1527 return False;
1530 if (ret)
1531 *ret = &data;
1532 if (addr)
1533 *(char **)addr = wstrdup(data);
1535 return True;
1537 #endif
1539 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1541 static char *data;
1542 int i, count, len;
1543 char *ptr;
1544 WMPropList *d;
1545 int changed = 0;
1547 again:
1548 if (!WMIsPLArray(value)) {
1549 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1550 if (changed == 0) {
1551 value = entry->plvalue;
1552 changed = 1;
1553 wwarning(_("using default \"%s\" instead"), entry->default_value);
1554 goto again;
1556 return False;
1559 i = 0;
1560 count = WMGetPropListItemCount(value);
1561 if (count < 1) {
1562 if (changed == 0) {
1563 value = entry->plvalue;
1564 changed = 1;
1565 wwarning(_("using default \"%s\" instead"), entry->default_value);
1566 goto again;
1568 return False;
1571 len = 0;
1572 for (i = 0; i < count; i++) {
1573 d = WMGetFromPLArray(value, i);
1574 if (!d || !WMIsPLString(d)) {
1575 count = i;
1576 break;
1578 len += strlen(WMGetFromPLString(d)) + 1;
1581 ptr = data = wmalloc(len + 1);
1583 for (i = 0; i < count; i++) {
1584 d = WMGetFromPLArray(value, i);
1585 if (!d || !WMIsPLString(d)) {
1586 break;
1588 strcpy(ptr, WMGetFromPLString(d));
1589 ptr += strlen(WMGetFromPLString(d));
1590 *ptr = ':';
1591 ptr++;
1593 ptr--;
1594 *(ptr--) = 0;
1596 if (*(char **)addr != NULL) {
1597 wfree(*(char **)addr);
1599 *(char **)addr = data;
1601 return True;
1604 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1606 static signed char data;
1608 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1609 if (data < 0)
1610 return False;
1612 if (ret)
1613 *ret = &data;
1614 if (addr)
1615 *(signed char *)addr = data;
1617 return True;
1621 * (solid <color>)
1622 * (hgradient <color> <color>)
1623 * (vgradient <color> <color>)
1624 * (dgradient <color> <color>)
1625 * (mhgradient <color> <color> ...)
1626 * (mvgradient <color> <color> ...)
1627 * (mdgradient <color> <color> ...)
1628 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1629 * (tpixmap <file> <color>)
1630 * (spixmap <file> <color>)
1631 * (cpixmap <file> <color>)
1632 * (thgradient <file> <opaqueness> <color> <color>)
1633 * (tvgradient <file> <opaqueness> <color> <color>)
1634 * (tdgradient <file> <opaqueness> <color> <color>)
1635 * (function <lib> <function> ...)
1638 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1640 WMPropList *elem;
1641 char *val;
1642 int nelem;
1643 WTexture *texture = NULL;
1645 nelem = WMGetPropListItemCount(pl);
1646 if (nelem < 1)
1647 return NULL;
1649 elem = WMGetFromPLArray(pl, 0);
1650 if (!elem || !WMIsPLString(elem))
1651 return NULL;
1652 val = WMGetFromPLString(elem);
1654 if (strcasecmp(val, "solid") == 0) {
1655 XColor color;
1657 if (nelem != 2)
1658 return NULL;
1660 /* get color */
1662 elem = WMGetFromPLArray(pl, 1);
1663 if (!elem || !WMIsPLString(elem))
1664 return NULL;
1665 val = WMGetFromPLString(elem);
1667 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1668 wwarning(_("\"%s\" is not a valid color name"), val);
1669 return NULL;
1672 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1673 } else if (strcasecmp(val, "dgradient") == 0
1674 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1675 RColor color1, color2;
1676 XColor xcolor;
1677 int type;
1679 if (nelem != 3) {
1680 wwarning(_("bad number of arguments in gradient specification"));
1681 return NULL;
1684 if (val[0] == 'd' || val[0] == 'D')
1685 type = WTEX_DGRADIENT;
1686 else if (val[0] == 'h' || val[0] == 'H')
1687 type = WTEX_HGRADIENT;
1688 else
1689 type = WTEX_VGRADIENT;
1691 /* get from color */
1692 elem = WMGetFromPLArray(pl, 1);
1693 if (!elem || !WMIsPLString(elem))
1694 return NULL;
1695 val = WMGetFromPLString(elem);
1697 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1698 wwarning(_("\"%s\" is not a valid color name"), val);
1699 return NULL;
1701 color1.alpha = 255;
1702 color1.red = xcolor.red >> 8;
1703 color1.green = xcolor.green >> 8;
1704 color1.blue = xcolor.blue >> 8;
1706 /* get to color */
1707 elem = WMGetFromPLArray(pl, 2);
1708 if (!elem || !WMIsPLString(elem)) {
1709 return NULL;
1711 val = WMGetFromPLString(elem);
1713 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1714 wwarning(_("\"%s\" is not a valid color name"), val);
1715 return NULL;
1717 color2.alpha = 255;
1718 color2.red = xcolor.red >> 8;
1719 color2.green = xcolor.green >> 8;
1720 color2.blue = xcolor.blue >> 8;
1722 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1724 } else if (strcasecmp(val, "igradient") == 0) {
1725 RColor colors1[2], colors2[2];
1726 int th1, th2;
1727 XColor xcolor;
1728 int i;
1730 if (nelem != 7) {
1731 wwarning(_("bad number of arguments in gradient specification"));
1732 return NULL;
1735 /* get from color */
1736 for (i = 0; i < 2; i++) {
1737 elem = WMGetFromPLArray(pl, 1 + i);
1738 if (!elem || !WMIsPLString(elem))
1739 return NULL;
1740 val = WMGetFromPLString(elem);
1742 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1743 wwarning(_("\"%s\" is not a valid color name"), val);
1744 return NULL;
1746 colors1[i].alpha = 255;
1747 colors1[i].red = xcolor.red >> 8;
1748 colors1[i].green = xcolor.green >> 8;
1749 colors1[i].blue = xcolor.blue >> 8;
1751 elem = WMGetFromPLArray(pl, 3);
1752 if (!elem || !WMIsPLString(elem))
1753 return NULL;
1754 val = WMGetFromPLString(elem);
1755 th1 = atoi(val);
1757 /* get from color */
1758 for (i = 0; i < 2; i++) {
1759 elem = WMGetFromPLArray(pl, 4 + i);
1760 if (!elem || !WMIsPLString(elem))
1761 return NULL;
1762 val = WMGetFromPLString(elem);
1764 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1765 wwarning(_("\"%s\" is not a valid color name"), val);
1766 return NULL;
1768 colors2[i].alpha = 255;
1769 colors2[i].red = xcolor.red >> 8;
1770 colors2[i].green = xcolor.green >> 8;
1771 colors2[i].blue = xcolor.blue >> 8;
1773 elem = WMGetFromPLArray(pl, 6);
1774 if (!elem || !WMIsPLString(elem))
1775 return NULL;
1776 val = WMGetFromPLString(elem);
1777 th2 = atoi(val);
1779 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1781 } else if (strcasecmp(val, "mhgradient") == 0
1782 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1783 XColor color;
1784 RColor **colors;
1785 int i, count;
1786 int type;
1788 if (nelem < 3) {
1789 wwarning(_("too few arguments in multicolor gradient specification"));
1790 return NULL;
1793 if (val[1] == 'h' || val[1] == 'H')
1794 type = WTEX_MHGRADIENT;
1795 else if (val[1] == 'v' || val[1] == 'V')
1796 type = WTEX_MVGRADIENT;
1797 else
1798 type = WTEX_MDGRADIENT;
1800 count = nelem - 1;
1802 colors = wmalloc(sizeof(RColor *) * (count + 1));
1804 for (i = 0; i < count; i++) {
1805 elem = WMGetFromPLArray(pl, i + 1);
1806 if (!elem || !WMIsPLString(elem)) {
1807 for (--i; i >= 0; --i) {
1808 wfree(colors[i]);
1810 wfree(colors);
1811 return NULL;
1813 val = WMGetFromPLString(elem);
1815 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1816 wwarning(_("\"%s\" is not a valid color name"), val);
1817 for (--i; i >= 0; --i) {
1818 wfree(colors[i]);
1820 wfree(colors);
1821 return NULL;
1822 } else {
1823 colors[i] = wmalloc(sizeof(RColor));
1824 colors[i]->red = color.red >> 8;
1825 colors[i]->green = color.green >> 8;
1826 colors[i]->blue = color.blue >> 8;
1829 colors[i] = NULL;
1831 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1832 } else if (strcasecmp(val, "spixmap") == 0 ||
1833 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1834 XColor color;
1835 int type;
1837 if (nelem != 3)
1838 return NULL;
1840 if (val[0] == 's' || val[0] == 'S')
1841 type = WTP_SCALE;
1842 else if (val[0] == 'c' || val[0] == 'C')
1843 type = WTP_CENTER;
1844 else
1845 type = WTP_TILE;
1847 /* get color */
1848 elem = WMGetFromPLArray(pl, 2);
1849 if (!elem || !WMIsPLString(elem)) {
1850 return NULL;
1852 val = WMGetFromPLString(elem);
1854 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1855 wwarning(_("\"%s\" is not a valid color name"), val);
1856 return NULL;
1859 /* file name */
1860 elem = WMGetFromPLArray(pl, 1);
1861 if (!elem || !WMIsPLString(elem))
1862 return NULL;
1863 val = WMGetFromPLString(elem);
1865 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1866 } else if (strcasecmp(val, "thgradient") == 0
1867 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1868 RColor color1, color2;
1869 XColor xcolor;
1870 int opacity;
1871 int style;
1873 if (val[1] == 'h' || val[1] == 'H')
1874 style = WTEX_THGRADIENT;
1875 else if (val[1] == 'v' || val[1] == 'V')
1876 style = WTEX_TVGRADIENT;
1877 else
1878 style = WTEX_TDGRADIENT;
1880 if (nelem != 5) {
1881 wwarning(_("bad number of arguments in textured gradient specification"));
1882 return NULL;
1885 /* get from color */
1886 elem = WMGetFromPLArray(pl, 3);
1887 if (!elem || !WMIsPLString(elem))
1888 return NULL;
1889 val = WMGetFromPLString(elem);
1891 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1892 wwarning(_("\"%s\" is not a valid color name"), val);
1893 return NULL;
1895 color1.alpha = 255;
1896 color1.red = xcolor.red >> 8;
1897 color1.green = xcolor.green >> 8;
1898 color1.blue = xcolor.blue >> 8;
1900 /* get to color */
1901 elem = WMGetFromPLArray(pl, 4);
1902 if (!elem || !WMIsPLString(elem)) {
1903 return NULL;
1905 val = WMGetFromPLString(elem);
1907 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1908 wwarning(_("\"%s\" is not a valid color name"), val);
1909 return NULL;
1911 color2.alpha = 255;
1912 color2.red = xcolor.red >> 8;
1913 color2.green = xcolor.green >> 8;
1914 color2.blue = xcolor.blue >> 8;
1916 /* get opacity */
1917 elem = WMGetFromPLArray(pl, 2);
1918 if (!elem || !WMIsPLString(elem))
1919 opacity = 128;
1920 else
1921 val = WMGetFromPLString(elem);
1923 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1924 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1925 opacity = 128;
1928 /* get file name */
1929 elem = WMGetFromPLArray(pl, 1);
1930 if (!elem || !WMIsPLString(elem))
1931 return NULL;
1932 val = WMGetFromPLString(elem);
1934 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1936 #ifdef TEXTURE_PLUGIN
1937 else if (strcasecmp(val, "function") == 0) {
1938 WTexFunction *function;
1939 void (*initFunc) (Display *, Colormap);
1940 char *lib, *func, **argv;
1941 int i, argc;
1943 if (nelem < 3)
1944 return NULL;
1946 /* get the library name */
1947 elem = WMGetFromPLArray(pl, 1);
1948 if (!elem || !WMIsPLString(elem)) {
1949 return NULL;
1951 lib = WMGetFromPLString(elem);
1953 /* get the function name */
1954 elem = WMGetFromPLArray(pl, 2);
1955 if (!elem || !WMIsPLString(elem)) {
1956 return NULL;
1958 func = WMGetFromPLString(elem);
1960 argc = nelem - 2;
1961 argv = (char **)wmalloc(argc * sizeof(char *));
1963 /* get the parameters */
1964 argv[0] = wstrdup(func);
1965 for (i = 0; i < argc - 1; i++) {
1966 elem = WMGetFromPLArray(pl, 3 + i);
1967 if (!elem || !WMIsPLString(elem)) {
1968 wfree(argv);
1970 return NULL;
1972 argv[i + 1] = wstrdup(WMGetFromPLString(elem));
1975 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1977 #ifdef HAVE_DLFCN_H
1978 if (function) {
1979 initFunc = dlsym(function->handle, "initWindowMaker");
1980 if (initFunc) {
1981 initFunc(dpy, scr->w_colormap);
1982 } else {
1983 wwarning(_("could not initialize library %s"), lib);
1985 } else {
1986 wwarning(_("could not find function %s::%s"), lib, func);
1988 #endif /* HAVE_DLFCN_H */
1989 texture = (WTexture *) function;
1991 #endif /* TEXTURE_PLUGIN */
1992 else {
1993 wwarning(_("invalid texture type %s"), val);
1994 return NULL;
1996 return texture;
1999 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2001 static WTexture *texture;
2002 int changed = 0;
2004 again:
2005 if (!WMIsPLArray(value)) {
2006 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
2007 if (changed == 0) {
2008 value = entry->plvalue;
2009 changed = 1;
2010 wwarning(_("using default \"%s\" instead"), entry->default_value);
2011 goto again;
2013 return False;
2016 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
2017 WMPropList *pl;
2019 pl = WMGetFromPLArray(value, 0);
2020 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2021 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
2022 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2023 entry->key, "Solid Texture");
2025 value = entry->plvalue;
2026 changed = 1;
2027 wwarning(_("using default \"%s\" instead"), entry->default_value);
2028 goto again;
2032 texture = parse_texture(scr, value);
2034 if (!texture) {
2035 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
2036 if (changed == 0) {
2037 value = entry->plvalue;
2038 changed = 1;
2039 wwarning(_("using default \"%s\" instead"), entry->default_value);
2040 goto again;
2042 return False;
2045 if (ret)
2046 *ret = &texture;
2048 if (addr)
2049 *(WTexture **) addr = texture;
2051 return True;
2054 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2056 WMPropList *elem;
2057 int changed = 0;
2058 char *val;
2059 int nelem;
2061 again:
2062 if (!WMIsPLArray(value)) {
2063 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2064 "WorkspaceBack", "Texture or None");
2065 if (changed == 0) {
2066 value = entry->plvalue;
2067 changed = 1;
2068 wwarning(_("using default \"%s\" instead"), entry->default_value);
2069 goto again;
2071 return False;
2074 /* only do basic error checking and verify for None texture */
2076 nelem = WMGetPropListItemCount(value);
2077 if (nelem > 0) {
2078 elem = WMGetFromPLArray(value, 0);
2079 if (!elem || !WMIsPLString(elem)) {
2080 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2081 if (changed == 0) {
2082 value = entry->plvalue;
2083 changed = 1;
2084 wwarning(_("using default \"%s\" instead"), entry->default_value);
2085 goto again;
2087 return False;
2089 val = WMGetFromPLString(elem);
2091 if (strcasecmp(val, "None") == 0)
2092 return True;
2094 *ret = WMRetainPropList(value);
2096 return True;
2099 static int
2100 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2102 WMPropList *elem;
2103 int nelem;
2104 int changed = 0;
2106 again:
2107 if (!WMIsPLArray(value)) {
2108 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2109 "WorkspaceSpecificBack", "an array of textures");
2110 if (changed == 0) {
2111 value = entry->plvalue;
2112 changed = 1;
2113 wwarning(_("using default \"%s\" instead"), entry->default_value);
2114 goto again;
2116 return False;
2119 /* only do basic error checking and verify for None texture */
2121 nelem = WMGetPropListItemCount(value);
2122 if (nelem > 0) {
2123 while (nelem--) {
2124 elem = WMGetFromPLArray(value, nelem);
2125 if (!elem || !WMIsPLArray(elem)) {
2126 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2127 nelem);
2132 *ret = WMRetainPropList(value);
2134 #ifdef notworking
2136 * Kluge to force wmsetbg helper to set the default background.
2137 * If the WorkspaceSpecificBack is changed once wmaker has started,
2138 * the WorkspaceBack won't be sent to the helper, unless the user
2139 * changes it's value too. So, we must force this by removing the
2140 * value from the defaults DB.
2142 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2143 WMPropList *key = WMCreatePLString("WorkspaceBack");
2145 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2147 WMReleasePropList(key);
2149 #endif
2150 return True;
2153 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2155 static WMFont *font;
2156 char *val;
2158 GET_STRING_OR_DEFAULT("Font", val);
2160 font = WMCreateFont(scr->wmscreen, val);
2161 if (!font)
2162 font = WMCreateFont(scr->wmscreen, "fixed");
2164 if (!font) {
2165 wfatal(_("could not load any usable font!!!"));
2166 exit(1);
2169 if (ret)
2170 *ret = font;
2172 /* can't assign font value outside update function */
2173 wassertrv(addr == NULL, True);
2175 return True;
2178 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2180 static XColor color;
2181 char *val;
2182 int second_pass = 0;
2184 GET_STRING_OR_DEFAULT("Color", val);
2186 again:
2187 if (!wGetColor(scr, val, &color)) {
2188 wwarning(_("could not get color for key \"%s\""), entry->key);
2189 if (second_pass == 0) {
2190 val = WMGetFromPLString(entry->plvalue);
2191 second_pass = 1;
2192 wwarning(_("using default \"%s\" instead"), val);
2193 goto again;
2195 return False;
2198 if (ret)
2199 *ret = &color;
2201 assert(addr == NULL);
2203 if (addr)
2204 *(unsigned long*)addr = pixel;
2207 return True;
2210 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2212 static WShortKey shortcut;
2213 KeySym ksym;
2214 char *val;
2215 char *k;
2216 char buf[MAX_SHORTCUT_LENGTH], *b;
2218 GET_STRING_OR_DEFAULT("Key spec", val);
2220 if (!val || strcasecmp(val, "NONE") == 0) {
2221 shortcut.keycode = 0;
2222 shortcut.modifier = 0;
2223 if (ret)
2224 *ret = &shortcut;
2225 return True;
2228 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2230 b = (char *)buf;
2232 /* get modifiers */
2233 shortcut.modifier = 0;
2234 while ((k = strchr(b, '+')) != NULL) {
2235 int mod;
2237 *k = 0;
2238 mod = wXModifierFromKey(b);
2239 if (mod < 0) {
2240 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2241 return False;
2243 shortcut.modifier |= mod;
2245 b = k + 1;
2248 /* get key */
2249 ksym = XStringToKeysym(b);
2251 if (ksym == NoSymbol) {
2252 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2253 return False;
2256 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2257 if (shortcut.keycode == 0) {
2258 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2259 return False;
2262 if (ret)
2263 *ret = &shortcut;
2265 return True;
2268 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2270 static int mask;
2271 char *str;
2273 GET_STRING_OR_DEFAULT("Modifier Key", str);
2275 if (!str)
2276 return False;
2278 mask = wXModifierFromKey(str);
2279 if (mask < 0) {
2280 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2281 mask = 0;
2282 return False;
2285 if (addr)
2286 *(int *)addr = mask;
2288 if (ret)
2289 *ret = &mask;
2291 return True;
2294 #ifdef NEWSTUFF
2295 static int getRImages(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2297 unsigned int mask;
2298 char *str;
2299 RImage *image;
2300 int i, n;
2301 int w, h;
2303 GET_STRING_OR_DEFAULT("Image File Path", str);
2304 if (!str)
2305 return False;
2307 image = RLoadImage(scr->rcontext, str, 0);
2308 if (!image) {
2309 wwarning(_("could not load image in option %s: %s"), entry->key, RMessageForError(RErrorCode));
2310 return False;
2313 if (*(RImage **) addr) {
2314 RReleaseImage(*(RImage **) addr);
2316 if (addr)
2317 *(RImage **) addr = image;
2319 assert(ret == NULL);
2321 if (ret)
2322 *(RImage**)ret = image;
2325 return True;
2327 #endif
2329 # include <X11/cursorfont.h>
2330 typedef struct {
2331 char *name;
2332 int id;
2333 } WCursorLookup;
2335 #define CURSOR_ID_NONE (XC_num_glyphs)
2337 static WCursorLookup cursor_table[] = {
2338 {"X_cursor", XC_X_cursor},
2339 {"arrow", XC_arrow},
2340 {"based_arrow_down", XC_based_arrow_down},
2341 {"based_arrow_up", XC_based_arrow_up},
2342 {"boat", XC_boat},
2343 {"bogosity", XC_bogosity},
2344 {"bottom_left_corner", XC_bottom_left_corner},
2345 {"bottom_right_corner", XC_bottom_right_corner},
2346 {"bottom_side", XC_bottom_side},
2347 {"bottom_tee", XC_bottom_tee},
2348 {"box_spiral", XC_box_spiral},
2349 {"center_ptr", XC_center_ptr},
2350 {"circle", XC_circle},
2351 {"clock", XC_clock},
2352 {"coffee_mug", XC_coffee_mug},
2353 {"cross", XC_cross},
2354 {"cross_reverse", XC_cross_reverse},
2355 {"crosshair", XC_crosshair},
2356 {"diamond_cross", XC_diamond_cross},
2357 {"dot", XC_dot},
2358 {"dotbox", XC_dotbox},
2359 {"double_arrow", XC_double_arrow},
2360 {"draft_large", XC_draft_large},
2361 {"draft_small", XC_draft_small},
2362 {"draped_box", XC_draped_box},
2363 {"exchange", XC_exchange},
2364 {"fleur", XC_fleur},
2365 {"gobbler", XC_gobbler},
2366 {"gumby", XC_gumby},
2367 {"hand1", XC_hand1},
2368 {"hand2", XC_hand2},
2369 {"heart", XC_heart},
2370 {"icon", XC_icon},
2371 {"iron_cross", XC_iron_cross},
2372 {"left_ptr", XC_left_ptr},
2373 {"left_side", XC_left_side},
2374 {"left_tee", XC_left_tee},
2375 {"leftbutton", XC_leftbutton},
2376 {"ll_angle", XC_ll_angle},
2377 {"lr_angle", XC_lr_angle},
2378 {"man", XC_man},
2379 {"middlebutton", XC_middlebutton},
2380 {"mouse", XC_mouse},
2381 {"pencil", XC_pencil},
2382 {"pirate", XC_pirate},
2383 {"plus", XC_plus},
2384 {"question_arrow", XC_question_arrow},
2385 {"right_ptr", XC_right_ptr},
2386 {"right_side", XC_right_side},
2387 {"right_tee", XC_right_tee},
2388 {"rightbutton", XC_rightbutton},
2389 {"rtl_logo", XC_rtl_logo},
2390 {"sailboat", XC_sailboat},
2391 {"sb_down_arrow", XC_sb_down_arrow},
2392 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2393 {"sb_left_arrow", XC_sb_left_arrow},
2394 {"sb_right_arrow", XC_sb_right_arrow},
2395 {"sb_up_arrow", XC_sb_up_arrow},
2396 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2397 {"shuttle", XC_shuttle},
2398 {"sizing", XC_sizing},
2399 {"spider", XC_spider},
2400 {"spraycan", XC_spraycan},
2401 {"star", XC_star},
2402 {"target", XC_target},
2403 {"tcross", XC_tcross},
2404 {"top_left_arrow", XC_top_left_arrow},
2405 {"top_left_corner", XC_top_left_corner},
2406 {"top_right_corner", XC_top_right_corner},
2407 {"top_side", XC_top_side},
2408 {"top_tee", XC_top_tee},
2409 {"trek", XC_trek},
2410 {"ul_angle", XC_ul_angle},
2411 {"umbrella", XC_umbrella},
2412 {"ur_angle", XC_ur_angle},
2413 {"watch", XC_watch},
2414 {"xterm", XC_xterm},
2415 {NULL, CURSOR_ID_NONE}
2418 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2420 switch (status) {
2421 case BitmapOpenFailed:
2422 wwarning(_("failed to open bitmap file \"%s\""), filename);
2423 break;
2424 case BitmapFileInvalid:
2425 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2426 break;
2427 case BitmapNoMemory:
2428 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2429 break;
2430 case BitmapSuccess:
2431 XFreePixmap(dpy, bitmap);
2432 break;
2437 * (none)
2438 * (builtin, <cursor_name>)
2439 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2441 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2443 WMPropList *elem;
2444 char *val;
2445 int nelem;
2446 int status = 0;
2448 nelem = WMGetPropListItemCount(pl);
2449 if (nelem < 1) {
2450 return (status);
2452 elem = WMGetFromPLArray(pl, 0);
2453 if (!elem || !WMIsPLString(elem)) {
2454 return (status);
2456 val = WMGetFromPLString(elem);
2458 if (0 == strcasecmp(val, "none")) {
2459 status = 1;
2460 *cursor = None;
2461 } else if (0 == strcasecmp(val, "builtin")) {
2462 int i;
2463 int cursor_id = CURSOR_ID_NONE;
2465 if (2 != nelem) {
2466 wwarning(_("bad number of arguments in cursor specification"));
2467 return (status);
2469 elem = WMGetFromPLArray(pl, 1);
2470 if (!elem || !WMIsPLString(elem)) {
2471 return (status);
2473 val = WMGetFromPLString(elem);
2475 for (i = 0; NULL != cursor_table[i].name; i++) {
2476 if (0 == strcasecmp(val, cursor_table[i].name)) {
2477 cursor_id = cursor_table[i].id;
2478 break;
2481 if (CURSOR_ID_NONE == cursor_id) {
2482 wwarning(_("unknown builtin cursor name \"%s\""), val);
2483 } else {
2484 *cursor = XCreateFontCursor(dpy, cursor_id);
2485 status = 1;
2487 } else if (0 == strcasecmp(val, "bitmap")) {
2488 char *bitmap_name;
2489 char *mask_name;
2490 int bitmap_status;
2491 int mask_status;
2492 Pixmap bitmap;
2493 Pixmap mask;
2494 unsigned int w, h;
2495 int x, y;
2496 XColor fg, bg;
2498 if (3 != nelem) {
2499 wwarning(_("bad number of arguments in cursor specification"));
2500 return (status);
2502 elem = WMGetFromPLArray(pl, 1);
2503 if (!elem || !WMIsPLString(elem)) {
2504 return (status);
2506 val = WMGetFromPLString(elem);
2507 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2508 if (!bitmap_name) {
2509 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2510 return (status);
2512 elem = WMGetFromPLArray(pl, 2);
2513 if (!elem || !WMIsPLString(elem)) {
2514 wfree(bitmap_name);
2515 return (status);
2517 val = WMGetFromPLString(elem);
2518 mask_name = FindImage(wPreferences.pixmap_path, val);
2519 if (!mask_name) {
2520 wfree(bitmap_name);
2521 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2522 return (status);
2524 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2525 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2526 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2527 fg.pixel = scr->black_pixel;
2528 bg.pixel = scr->white_pixel;
2529 XQueryColor(dpy, scr->w_colormap, &fg);
2530 XQueryColor(dpy, scr->w_colormap, &bg);
2531 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2532 status = 1;
2534 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2535 check_bitmap_status(mask_status, mask_name, mask);
2536 wfree(bitmap_name);
2537 wfree(mask_name);
2539 return (status);
2542 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2544 static Cursor cursor;
2545 int status;
2546 int changed = 0;
2548 again:
2549 if (!WMIsPLArray(value)) {
2550 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2551 entry->key, "cursor specification");
2552 if (!changed) {
2553 value = entry->plvalue;
2554 changed = 1;
2555 wwarning(_("using default \"%s\" instead"), entry->default_value);
2556 goto again;
2558 return (False);
2560 status = parse_cursor(scr, value, &cursor);
2561 if (!status) {
2562 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2563 if (!changed) {
2564 value = entry->plvalue;
2565 changed = 1;
2566 wwarning(_("using default \"%s\" instead"), entry->default_value);
2567 goto again;
2569 return (False);
2571 if (ret) {
2572 *ret = &cursor;
2574 if (addr) {
2575 *(Cursor *) addr = cursor;
2577 return (True);
2580 #undef CURSOR_ID_NONE
2582 /* ---------------- value setting functions --------------- */
2583 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2585 return REFRESH_WINDOW_TITLE_COLOR;
2588 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2590 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2593 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2595 switch (which) {
2596 case WM_DOCK:
2597 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2598 break;
2599 case WM_CLIP:
2600 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2601 break;
2602 default:
2603 break;
2605 return 0;
2608 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2610 if (scr->workspaces) {
2611 wWorkspaceForceChange(scr, scr->current_workspace);
2612 wArrangeIcons(scr, False);
2614 return 0;
2617 #if not_used
2618 static int setPositive(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2620 if (*value <= 0)
2621 *(int *)foo = 1;
2623 return 0;
2625 #endif
2627 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2629 Pixmap pixmap;
2630 RImage *img;
2631 int reset = 0;
2633 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2634 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2635 ? WREL_ICON : WREL_FLAT);
2636 if (!img) {
2637 wwarning(_("could not render texture for icon background"));
2638 if (!entry->addr)
2639 wTextureDestroy(scr, *texture);
2640 return 0;
2642 RConvertImage(scr->rcontext, img, &pixmap);
2644 if (scr->icon_tile) {
2645 reset = 1;
2646 RReleaseImage(scr->icon_tile);
2647 XFreePixmap(dpy, scr->icon_tile_pixmap);
2650 scr->icon_tile = img;
2652 /* put the icon in the noticeboard hint */
2653 PropSetIconTileHint(scr, img);
2655 if (!wPreferences.flags.noclip) {
2656 if (scr->clip_tile) {
2657 RReleaseImage(scr->clip_tile);
2659 scr->clip_tile = wClipMakeTile(scr, img);
2662 scr->icon_tile_pixmap = pixmap;
2664 if (scr->def_icon_pixmap) {
2665 XFreePixmap(dpy, scr->def_icon_pixmap);
2666 scr->def_icon_pixmap = None;
2668 if (scr->def_ticon_pixmap) {
2669 XFreePixmap(dpy, scr->def_ticon_pixmap);
2670 scr->def_ticon_pixmap = None;
2673 if (scr->icon_back_texture) {
2674 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2676 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2678 if (scr->clip_balloon)
2679 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2682 * Free the texture as nobody else will use it, nor refer to it.
2684 if (!entry->addr)
2685 wTextureDestroy(scr, *texture);
2687 return (reset ? REFRESH_ICON_TILE : 0);
2690 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2692 if (scr->title_font) {
2693 WMReleaseFont(scr->title_font);
2695 scr->title_font = font;
2697 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2700 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2702 if (scr->menu_title_font) {
2703 WMReleaseFont(scr->menu_title_font);
2706 scr->menu_title_font = font;
2708 return REFRESH_MENU_TITLE_FONT;
2711 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2713 if (scr->menu_entry_font) {
2714 WMReleaseFont(scr->menu_entry_font);
2716 scr->menu_entry_font = font;
2718 return REFRESH_MENU_FONT;
2721 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2723 if (scr->icon_title_font) {
2724 WMReleaseFont(scr->icon_title_font);
2727 scr->icon_title_font = font;
2729 return REFRESH_ICON_FONT;
2732 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2734 if (scr->clip_title_font) {
2735 WMReleaseFont(scr->clip_title_font);
2738 scr->clip_title_font = font;
2740 return REFRESH_ICON_FONT;
2743 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2745 if (scr->workspace_name_font) {
2746 WMReleaseFont(scr->workspace_name_font);
2749 scr->workspace_name_font = font;
2751 return 0;
2754 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2756 if (scr->select_color)
2757 WMReleaseColor(scr->select_color);
2759 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2761 wFreeColor(scr, color->pixel);
2763 return REFRESH_MENU_COLOR;
2766 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2768 if (scr->select_text_color)
2769 WMReleaseColor(scr->select_text_color);
2771 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2773 wFreeColor(scr, color->pixel);
2775 return REFRESH_MENU_COLOR;
2778 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2780 if (scr->clip_title_color[widx])
2781 WMReleaseColor(scr->clip_title_color[widx]);
2782 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2783 #ifdef GRADIENT_CLIP_ARROW
2784 if (widx == CLIP_NORMAL) {
2785 RImage *image;
2786 RColor color1, color2;
2787 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2788 int as = pt - 15; /* 15 = 5+5+5 */
2790 FREE_PIXMAP(scr->clip_arrow_gradient);
2792 color1.red = (color->red >> 8) * 6 / 10;
2793 color1.green = (color->green >> 8) * 6 / 10;
2794 color1.blue = (color->blue >> 8) * 6 / 10;
2796 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2797 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2798 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2800 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2801 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2802 RReleaseImage(image);
2804 #endif /* GRADIENT_CLIP_ARROW */
2806 wFreeColor(scr, color->pixel);
2808 return REFRESH_ICON_TITLE_COLOR;
2811 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2813 if (scr->window_title_color[widx])
2814 WMReleaseColor(scr->window_title_color[widx]);
2816 scr->window_title_color[widx] =
2817 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2819 wFreeColor(scr, color->pixel);
2821 return REFRESH_WINDOW_TITLE_COLOR;
2824 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2826 if (scr->menu_title_color[0])
2827 WMReleaseColor(scr->menu_title_color[0]);
2829 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2831 wFreeColor(scr, color->pixel);
2833 return REFRESH_MENU_TITLE_COLOR;
2836 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2838 if (scr->mtext_color)
2839 WMReleaseColor(scr->mtext_color);
2841 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2843 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2844 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2845 } else {
2846 WMSetColorAlpha(scr->dtext_color, 0xffff);
2849 wFreeColor(scr, color->pixel);
2851 return REFRESH_MENU_COLOR;
2854 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2856 if (scr->dtext_color)
2857 WMReleaseColor(scr->dtext_color);
2859 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2861 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2862 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2863 } else {
2864 WMSetColorAlpha(scr->dtext_color, 0xffff);
2867 wFreeColor(scr, color->pixel);
2869 return REFRESH_MENU_COLOR;
2872 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2874 if (scr->icon_title_color)
2875 WMReleaseColor(scr->icon_title_color);
2876 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2878 wFreeColor(scr, color->pixel);
2880 return REFRESH_ICON_TITLE_COLOR;
2883 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2885 if (scr->icon_title_texture) {
2886 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2888 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2890 return REFRESH_ICON_TITLE_BACK;
2893 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2895 close(scr->helper_fd);
2896 scr->helper_fd = 0;
2897 scr->helper_pid = 0;
2898 scr->flags.backimage_helper_launched = 0;
2901 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2903 WMPropList *val;
2904 char *str;
2905 int i;
2907 if (scr->flags.backimage_helper_launched) {
2908 if (WMGetPropListItemCount(value) == 0) {
2909 SendHelperMessage(scr, 'C', 0, NULL);
2910 SendHelperMessage(scr, 'K', 0, NULL);
2912 WMReleasePropList(value);
2913 return 0;
2915 } else {
2916 pid_t pid;
2917 int filedes[2];
2919 if (WMGetPropListItemCount(value) == 0)
2920 return 0;
2922 if (pipe(filedes) < 0) {
2923 wsyserror("pipe() failed:can't set workspace specific background image");
2925 WMReleasePropList(value);
2926 return 0;
2929 pid = fork();
2930 if (pid < 0) {
2931 wsyserror("fork() failed:can't set workspace specific background image");
2932 if (close(filedes[0]) < 0)
2933 wsyserror("could not close pipe");
2934 if (close(filedes[1]) < 0)
2935 wsyserror("could not close pipe");
2937 } else if (pid == 0) {
2938 char *dither;
2940 SetupEnvironment(scr);
2942 if (close(0) < 0)
2943 wsyserror("could not close pipe");
2944 if (dup(filedes[0]) < 0) {
2945 wsyserror("dup() failed:can't set workspace specific background image");
2947 dither = wPreferences.no_dithering ? "-m" : "-d";
2948 if (wPreferences.smooth_workspace_back)
2949 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2950 else
2951 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2952 wsyserror("could not execute wmsetbg");
2953 exit(1);
2954 } else {
2956 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2957 wsyserror("error setting close-on-exec flag");
2959 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2960 wsyserror("error setting close-on-exec flag");
2963 scr->helper_fd = filedes[1];
2964 scr->helper_pid = pid;
2965 scr->flags.backimage_helper_launched = 1;
2967 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2969 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2974 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2975 val = WMGetFromPLArray(value, i);
2976 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2977 str = WMGetPropListDescription(val, False);
2979 SendHelperMessage(scr, 'S', i + 1, str);
2981 wfree(str);
2982 } else {
2983 SendHelperMessage(scr, 'U', i + 1, NULL);
2986 sleep(1);
2988 WMReleasePropList(value);
2989 return 0;
2992 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2994 if (scr->flags.backimage_helper_launched) {
2995 char *str;
2997 if (WMGetPropListItemCount(value) == 0) {
2998 SendHelperMessage(scr, 'U', 0, NULL);
2999 } else {
3000 /* set the default workspace background to this one */
3001 str = WMGetPropListDescription(value, False);
3002 if (str) {
3003 SendHelperMessage(scr, 'S', 0, str);
3004 wfree(str);
3005 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
3006 } else {
3007 SendHelperMessage(scr, 'U', 0, NULL);
3010 } else if (WMGetPropListItemCount(value) > 0) {
3011 char *command;
3012 char *text;
3013 char *dither;
3014 int len;
3016 SetupEnvironment(scr);
3017 text = WMGetPropListDescription(value, False);
3018 len = strlen(text) + 40;
3019 command = wmalloc(len);
3020 dither = wPreferences.no_dithering ? "-m" : "-d";
3021 if (wPreferences.smooth_workspace_back)
3022 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3023 else
3024 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3025 wfree(text);
3026 system(command);
3027 wfree(command);
3029 WMReleasePropList(value);
3031 return 0;
3034 #ifdef VIRTUAL_DESKTOP
3035 static int setVirtualDeskEnable(WScreen * scr, WDefaultEntry * entry, void *foo, void *bar)
3037 wWorkspaceUpdateEdge(scr);
3038 return 0;
3040 #endif
3042 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3044 if (scr->widget_texture) {
3045 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3047 scr->widget_texture = *(WTexSolid **) texture;
3049 return 0;
3052 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3054 if (scr->window_title_texture[WS_FOCUSED]) {
3055 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3057 scr->window_title_texture[WS_FOCUSED] = *texture;
3059 return REFRESH_WINDOW_TEXTURES;
3062 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3064 if (scr->window_title_texture[WS_PFOCUSED]) {
3065 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3067 scr->window_title_texture[WS_PFOCUSED] = *texture;
3069 return REFRESH_WINDOW_TEXTURES;
3072 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3074 if (scr->window_title_texture[WS_UNFOCUSED]) {
3075 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3077 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3079 return REFRESH_WINDOW_TEXTURES;
3082 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3084 if (scr->resizebar_texture[0]) {
3085 wTextureDestroy(scr, scr->resizebar_texture[0]);
3087 scr->resizebar_texture[0] = *texture;
3089 return REFRESH_WINDOW_TEXTURES;
3092 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3094 if (scr->menu_title_texture[0]) {
3095 wTextureDestroy(scr, scr->menu_title_texture[0]);
3097 scr->menu_title_texture[0] = *texture;
3099 return REFRESH_MENU_TITLE_TEXTURE;
3102 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3104 if (scr->menu_item_texture) {
3105 wTextureDestroy(scr, scr->menu_item_texture);
3106 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3108 scr->menu_item_texture = *texture;
3110 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3112 return REFRESH_MENU_TEXTURE;
3115 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
3117 WWindow *wwin;
3118 wKeyBindings[widx] = *shortcut;
3120 wwin = scr->focused_window;
3122 while (wwin != NULL) {
3123 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3125 if (!WFLAGP(wwin, no_bind_keys)) {
3126 wWindowSetKeyGrabs(wwin);
3128 wwin = wwin->prev;
3131 return 0;
3134 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3136 wScreenUpdateUsableArea(scr);
3137 wArrangeIcons(scr, True);
3139 return 0;
3142 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3144 wScreenUpdateUsableArea(scr);
3146 return 0;
3149 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3151 return REFRESH_MENU_TEXTURE;
3154 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3156 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3158 RCopyArea(img, image, x, y, w, h, 0, 0);
3160 return img;
3163 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
3165 char *path;
3166 RImage *bgimage;
3167 int cwidth, cheight;
3168 WPreferences *prefs = (WPreferences *) foo;
3170 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3171 if (prefs->swtileImage)
3172 RReleaseImage(prefs->swtileImage);
3173 prefs->swtileImage = NULL;
3175 WMReleasePropList(array);
3176 return 0;
3179 switch (WMGetPropListItemCount(array)) {
3180 case 4:
3181 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3182 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3183 break;
3184 } else
3185 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3187 if (!path) {
3188 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3189 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3190 } else {
3191 bgimage = RLoadImage(scr->rcontext, path, 0);
3192 if (!bgimage) {
3193 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3194 wfree(path);
3195 } else {
3196 wfree(path);
3198 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3199 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3201 if (cwidth <= 0 || cheight <= 0 ||
3202 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3203 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3204 else {
3205 int i;
3206 int swidth, theight;
3207 for (i = 0; i < 9; i++) {
3208 if (prefs->swbackImage[i])
3209 RReleaseImage(prefs->swbackImage[i]);
3210 prefs->swbackImage[i] = NULL;
3212 swidth = (bgimage->width - cwidth) / 2;
3213 theight = (bgimage->height - cheight) / 2;
3215 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3216 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3217 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3218 swidth, theight);
3220 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3221 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3222 cwidth, cheight);
3223 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3224 swidth, cheight);
3226 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3227 swidth, theight);
3228 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3229 cwidth, theight);
3230 prefs->swbackImage[8] =
3231 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3232 theight);
3234 // check if anything failed
3235 for (i = 0; i < 9; i++) {
3236 if (!prefs->swbackImage[i]) {
3237 for (; i >= 0; --i) {
3238 RReleaseImage(prefs->swbackImage[i]);
3239 prefs->swbackImage[i] = NULL;
3241 break;
3245 RReleaseImage(bgimage);
3249 case 1:
3250 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3251 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3252 break;
3253 } else
3254 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3256 if (!path) {
3257 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3258 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3259 } else {
3260 if (prefs->swtileImage)
3261 RReleaseImage(prefs->swtileImage);
3263 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3264 if (!prefs->swtileImage) {
3265 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3267 wfree(path);
3269 break;
3271 default:
3272 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3273 break;
3276 WMReleasePropList(array);
3278 return 0;
3282 static int
3283 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3285 return REFRESH_BUTTON_IMAGES;
3290 * Very ugly kluge.
3291 * Need access to the double click variables, so that all widgets in
3292 * wmaker panels will have the same dbl-click values.
3293 * TODO: figure a better way of dealing with it.
3295 #include <WINGs/WINGsP.h>
3297 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3299 extern _WINGsConfiguration WINGsConfiguration;
3301 if (*value <= 0)
3302 *(int *)foo = 1;
3304 WINGsConfiguration.doubleClickDelay = *value;
3306 return 0;
3309 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3311 if (wCursor[widx] != None) {
3312 XFreeCursor(dpy, wCursor[widx]);
3315 wCursor[widx] = *cursor;
3317 if (widx == WCUR_ROOT && *cursor != None) {
3318 XDefineCursor(dpy, scr->root_win, *cursor);
3321 return 0;