Add history to some dialog boxes
[wmaker-crm.git] / src / defaults.c
1 /* defaults.c - manage configuration through defaults db
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
7 *
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.
12 *
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.
17 *
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.
22 */
23
24 #include "wconfig.h"
25
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>
38
39 #ifdef HAVE_DLFCN_H
40 # include <dlfcn.h>
41 #endif
42
43 #ifndef PATH_MAX
44 #define PATH_MAX DEFAULT_PATH_MAX
45 #endif
46
47 #include <X11/Xlib.h>
48 #include <X11/Xutil.h>
49 #include <X11/keysym.h>
50
51 #include <wraster.h>
52
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"
69
70 #define MAX_SHORTCUT_LENGTH 32
71
72 #ifndef GLOBAL_DEFAULTS_SUBDIR
73 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
74 #endif
75
76 /***** Global *****/
77
78 extern WDDomain *WDWindowMaker;
79 extern WDDomain *WDWindowAttributes;
80 extern WDDomain *WDRootMenu;
81
82 extern int wScreenCount;
83
84 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
85 extern Atom _XA_WINDOWMAKER_ICON_TILE;
86
87 /*
88 extern WMPropList *wDomainName;
89 extern WMPropList *wAttributeDomainName;
90 */
91 extern WPreferences wPreferences;
92
93 extern WShortKey wKeyBindings[WKBD_LAST];
94
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;
105
106 /* used to map strings to integers */
107 typedef struct {
108 char *string;
109 short value;
110 char is_alias;
111 } WOptionEnumeration;
112
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();
134
135 /* value setting functions */
136 static int setJustify();
137 static int setClearance();
138 static int setIfDockPresent();
139 static int setStickyIcons();
140 /*
141 static int setPositive();
142 */
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();
172
173 static int setClipTitleFont();
174 static int setClipTitleColor();
175
176 static int setMenuStyle();
177 static int setSwPOptions();
178 static int updateUsableArea();
179
180 extern Cursor wCursor[WCUR_LAST];
181 static int getCursor();
182 static int setCursor();
183
184 /*
185 * Tables to convert strings to enumeration values.
186 * Values stored are char
187 */
188
189 /* WARNING: sum of length of all value strings must not exceed
190 * this value */
191 #define TOTAL_VALUES_LENGTH 80
192
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)
205
206 #define REFRESH_BUTTON_IMAGES (1<<12)
207
208 #define REFRESH_ICON_TITLE_COLOR (1<<13)
209 #define REFRESH_ICON_TITLE_BACK (1<<14)
210
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}
215 };
216
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}
221 };
222
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}
230 };
231
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}
239 };
240
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}
248 };
249
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}
256 };
257
258 static WOptionEnumeration seMouseWheelActions[] = {
259 {"None", WA_NONE, 0},
260 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
261 {NULL, 0, 0}
262 };
263
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}
271 };
272
273 static WOptionEnumeration seJustifications[] = {
274 {"Left", WTJ_LEFT, 0},
275 {"Center", WTJ_CENTER, 0},
276 {"Right", WTJ_RIGHT, 0},
277 {NULL, 0, 0}
278 };
279
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}
290 };
291
292 static WOptionEnumeration seMenuStyles[] = {
293 {"normal", MS_NORMAL, 0},
294 {"singletexture", MS_SINGLE_TEXTURE, 0},
295 {"flat", MS_FLAT, 0},
296 {NULL, 0, 0}
297 };
298
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}
309 };
310
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}
317 };
318
319 /*
320 * ALL entries in the tables bellow, NEED to have a default value
321 * defined, and this value needs to be correct.
322 */
323
324 /* these options will only affect the window manager on startup
325 *
326 * static defaults can't access the screen data, because it is
327 * created after these defaults are read
328 */
329 WDefaultEntry staticOptionList[] = {
330
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}
352 };
353
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,
430 },
431 {"AlignSubmenus", "NO", NULL,
432 &wPreferences.align_menus, getBool, NULL},
433 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
434 &wPreferences.open_transients_with_parent, getBool, NULL},
435 {"WindowPlacement", "auto", sePlacements,
436 &wPreferences.window_placement, getEnum, NULL},
437 {"IgnoreFocusClick", "NO", NULL,
438 &wPreferences.ignore_focus_click, getBool, NULL},
439 {"UseSaveUnders", "NO", NULL,
440 &wPreferences.use_saveunders, getBool, NULL},
441 {"OpaqueMove", "NO", NULL,
442 &wPreferences.opaque_move, getBool, NULL},
443 {"DisableSound", "NO", NULL,
444 &wPreferences.no_sound, getBool, NULL},
445 {"DisableAnimations", "NO", NULL,
446 &wPreferences.no_animations, getBool, NULL},
447 {"DontLinkWorkspaces", "NO", NULL,
448 &wPreferences.no_autowrap, getBool, NULL},
449 {"AutoArrangeIcons", "NO", NULL,
450 &wPreferences.auto_arrange_icons, getBool, NULL},
451 {"NoWindowOverDock", "NO", NULL,
452 &wPreferences.no_window_over_dock, getBool, updateUsableArea},
453 {"NoWindowOverIcons", "NO", NULL,
454 &wPreferences.no_window_over_icons, getBool, updateUsableArea},
455 {"WindowPlaceOrigin", "(0, 0)", NULL,
456 &wPreferences.window_place_origin, getCoord, NULL},
457 {"ResizeDisplay", "corner", seGeomDisplays,
458 &wPreferences.size_display, getEnum, NULL},
459 {"MoveDisplay", "corner", seGeomDisplays,
460 &wPreferences.move_display, getEnum, NULL},
461 {"DontConfirmKill", "NO", NULL,
462 &wPreferences.dont_confirm_kill, getBool, NULL},
463 {"WindowTitleBalloons", "NO", NULL,
464 &wPreferences.window_balloon, getBool, NULL},
465 {"MiniwindowTitleBalloons", "NO", NULL,
466 &wPreferences.miniwin_balloon, getBool, NULL},
467 {"AppIconBalloons", "NO", NULL,
468 &wPreferences.appicon_balloon, getBool, NULL},
469 {"HelpBalloons", "NO", NULL,
470 &wPreferences.help_balloon, getBool, NULL},
471 {"EdgeResistance", "30", NULL,
472 &wPreferences.edge_resistance, getInt, NULL},
473 {"Attraction", "NO", NULL,
474 &wPreferences.attract, getBool, NULL},
475 {"DisableBlinking", "NO", NULL,
476 &wPreferences.dont_blink, getBool, NULL},
477 {"SingleClickLaunch", "NO", NULL,
478 &wPreferences.single_click, getBool, NULL},
479 /* style options */
480 {"MenuStyle", "normal", seMenuStyles,
481 &wPreferences.menu_style, getEnum, setMenuStyle},
482 {"WidgetColor", "(solid, gray)", NULL,
483 NULL, getTexture, setWidgetColor,
484 },
485 {"WorkspaceSpecificBack", "()", NULL,
486 NULL, getWSSpecificBackground, setWorkspaceSpecificBack},
487 /* WorkspaceBack must come after WorkspaceSpecificBack or
488 * WorkspaceBack wont know WorkspaceSpecificBack was also
489 * specified and 2 copies of wmsetbg will be launched */
490 {"WorkspaceBack", "(solid, black)", NULL,
491 NULL, getWSBackground, setWorkspaceBack},
492 {"SmoothWorkspaceBack", "NO", NULL,
493 NULL, getBool, NULL},
494 {"IconBack", "(solid, gray)", NULL,
495 NULL, getTexture, setIconTile},
496 {"TitleJustify", "center", seJustifications,
497 &wPreferences.title_justification, getEnum, setJustify},
498 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
499 NULL, getFont, setWinTitleFont,
500 },
501 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
502 &wPreferences.window_title_clearance, getInt, setClearance},
503 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
504 &wPreferences.menu_title_clearance, getInt, setClearance},
505 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
506 &wPreferences.menu_text_clearance, getInt, setClearance},
507 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
508 NULL, getFont, setMenuTitleFont},
509 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
510 NULL, getFont, setMenuTextFont},
511 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
512 NULL, getFont, setIconTitleFont},
513 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
514 NULL, getFont, setClipTitleFont},
515 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
516 NULL, getFont, setLargeDisplayFont},
517 {"HighlightColor", "white", NULL,
518 NULL, getColor, setHightlight},
519 {"HighlightTextColor", "black", NULL,
520 NULL, getColor, setHightlightText},
521 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
522 NULL, getColor, setClipTitleColor},
523 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
524 NULL, getColor, setClipTitleColor},
525 {"FTitleColor", "white", (void *)WS_FOCUSED,
526 NULL, getColor, setWTitleColor},
527 {"PTitleColor", "white", (void *)WS_PFOCUSED,
528 NULL, getColor, setWTitleColor},
529 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
530 NULL, getColor, setWTitleColor},
531 {"FTitleBack", "(solid, black)", NULL,
532 NULL, getTexture, setFTitleBack},
533 {"PTitleBack", "(solid, \"#616161\")", NULL,
534 NULL, getTexture, setPTitleBack},
535 {"UTitleBack", "(solid, gray)", NULL,
536 NULL, getTexture, setUTitleBack},
537 {"ResizebarBack", "(solid, gray)", NULL,
538 NULL, getTexture, setResizebarBack},
539 {"MenuTitleColor", "white", NULL,
540 NULL, getColor, setMenuTitleColor},
541 {"MenuTextColor", "black", NULL,
542 NULL, getColor, setMenuTextColor},
543 {"MenuDisabledColor", "\"#616161\"", NULL,
544 NULL, getColor, setMenuDisabledColor},
545 {"MenuTitleBack", "(solid, black)", NULL,
546 NULL, getTexture, setMenuTitleBack},
547 {"MenuTextBack", "(solid, gray)", NULL,
548 NULL, getTexture, setMenuTextBack},
549 {"IconTitleColor", "white", NULL,
550 NULL, getColor, setIconTitleColor},
551 {"IconTitleBack", "black", NULL,
552 NULL, getColor, setIconTitleBack},
553 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
554 NULL, getPropList, setSwPOptions},
555 /* keybindings */
556 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
557 NULL, getKeybind, setKeyGrab},
558 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
559 NULL, getKeybind, setKeyGrab},
560 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
561 NULL, getKeybind, setKeyGrab},
562 {"ClipLowerKey", "None", (void *)WKBD_CLIPLOWER,
563 NULL, getKeybind, setKeyGrab},
564 {"ClipRaiseKey", "None", (void *)WKBD_CLIPRAISE,
565 NULL, getKeybind, setKeyGrab},
566 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
567 NULL, getKeybind, setKeyGrab},
568 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
569 NULL, getKeybind, setKeyGrab},
570 {"HideKey", "None", (void *)WKBD_HIDE,
571 NULL, getKeybind, setKeyGrab},
572 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
573 NULL, getKeybind, setKeyGrab},
574 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
575 NULL, getKeybind, setKeyGrab},
576 {"CloseKey", "None", (void *)WKBD_CLOSE,
577 NULL, getKeybind, setKeyGrab},
578 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
579 NULL, getKeybind, setKeyGrab},
580 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
581 NULL, getKeybind, setKeyGrab},
582 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
583 NULL, getKeybind, setKeyGrab},
584 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
585 NULL, getKeybind, setKeyGrab},
586 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
587 NULL, getKeybind, setKeyGrab},
588 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
589 NULL, getKeybind, setKeyGrab},
590 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
591 NULL, getKeybind, setKeyGrab},
592 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
593 NULL, getKeybind, setKeyGrab},
594 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
595 NULL, getKeybind, setKeyGrab},
596 {"ShadeKey", "None", (void *)WKBD_SHADE,
597 NULL, getKeybind, setKeyGrab},
598 {"SelectKey", "None", (void *)WKBD_SELECT,
599 NULL, getKeybind, setKeyGrab},
600 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
601 NULL, getKeybind, setKeyGrab},
602 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
603 NULL, getKeybind, setKeyGrab},
604 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
605 NULL, getKeybind, setKeyGrab},
606 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
607 NULL, getKeybind, setKeyGrab},
608 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
609 NULL, getKeybind, setKeyGrab},
610 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
611 NULL, getKeybind, setKeyGrab},
612 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
613 NULL, getKeybind, setKeyGrab},
614 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
615 NULL, getKeybind, setKeyGrab},
616 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
617 NULL, getKeybind, setKeyGrab},
618 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
619 NULL, getKeybind, setKeyGrab},
620 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
621 NULL, getKeybind, setKeyGrab},
622 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
623 NULL, getKeybind, setKeyGrab},
624 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
625 NULL, getKeybind, setKeyGrab},
626 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
627 NULL, getKeybind, setKeyGrab},
628 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
629 NULL, getKeybind, setKeyGrab},
630 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
631 NULL, getKeybind, setKeyGrab},
632 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
633 NULL, getKeybind, setKeyGrab},
634 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
635 NULL, getKeybind, setKeyGrab},
636 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
637 NULL, getKeybind, setKeyGrab},
638 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
639 NULL, getKeybind, setKeyGrab}
640 , {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
641 NULL, getKeybind, setKeyGrab},
642 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
643 NULL, getKeybind, setKeyGrab},
644 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
645 NULL, getKeybind, setKeyGrab},
646 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
647 NULL, getKeybind, setKeyGrab},
648 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
649 NULL, getKeybind, setKeyGrab},
650 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
651 NULL, getKeybind, setKeyGrab},
652 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
653 NULL, getKeybind, setKeyGrab},
654
655 #ifdef KEEP_XKB_LOCK_STATUS
656 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
657 NULL, getKeybind, setKeyGrab},
658 {"KbdModeLock", "NO", NULL,
659 &wPreferences.modelock, getBool, NULL},
660 #endif /* KEEP_XKB_LOCK_STATUS */
661
662 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
663 NULL, getCursor, setCursor},
664 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
665 NULL, getCursor, setCursor},
666 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
667 NULL, getCursor, setCursor},
668 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
669 NULL, getCursor, setCursor},
670 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
671 (void *)WCUR_TOPLEFTRESIZE,
672 NULL, getCursor, setCursor},
673 {"TopRightResizeCursor", "(builtin, top_right_corner)",
674 (void *)WCUR_TOPRIGHTRESIZE,
675 NULL, getCursor, setCursor},
676 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
677 (void *)WCUR_BOTTOMLEFTRESIZE,
678 NULL, getCursor, setCursor},
679 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
680 (void *)WCUR_BOTTOMRIGHTRESIZE,
681 NULL, getCursor, setCursor},
682 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
683 (void *)WCUR_VERTICALRESIZE,
684 NULL, getCursor, setCursor},
685 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
686 (void *)WCUR_HORIZONRESIZE,
687 NULL, getCursor, setCursor},
688 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
689 NULL, getCursor, setCursor},
690 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
691 NULL, getCursor, setCursor},
692 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
693 NULL, getCursor, setCursor},
694 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
695 NULL, getCursor, setCursor},
696 {"DialogHistoryLines", "500", NULL,
697 &wPreferences.history_lines, getInt, NULL}
698 };
699
700 #if 0
701 static void rereadDefaults(void);
702 #endif
703
704 #if 0
705 static void rereadDefaults(void)
706 {
707 /* must defer the update because accessing X data from a
708 * signal handler can mess up Xlib */
709
710 }
711 #endif
712
713 static void initDefaults()
714 {
715 unsigned int i;
716 WDefaultEntry *entry;
717
718 WMPLSetCaseSensitive(False);
719
720 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
721 entry = &optionList[i];
722
723 entry->plkey = WMCreatePLString(entry->key);
724 if (entry->default_value)
725 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
726 else
727 entry->plvalue = NULL;
728 }
729
730 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
731 entry = &staticOptionList[i];
732
733 entry->plkey = WMCreatePLString(entry->key);
734 if (entry->default_value)
735 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
736 else
737 entry->plvalue = NULL;
738 }
739
740 /*
741 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
742 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
743
744 PLRegister(wDomainName, rereadDefaults);
745 PLRegister(wAttributeDomainName, rereadDefaults);
746 */
747 }
748
749 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
750 {
751 WMPropList *globalDict = NULL;
752 char path[PATH_MAX];
753 struct stat stbuf;
754
755 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
756 if (stat(path, &stbuf) >= 0) {
757 globalDict = WMReadPropListFromFile(path);
758 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
759 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
760 WMReleasePropList(globalDict);
761 globalDict = NULL;
762 } else if (!globalDict) {
763 wwarning(_("could not load domain %s from global defaults database"), domainName);
764 }
765 }
766
767 return globalDict;
768 }
769
770 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
771 static void prependMenu(WMPropList * destarr, WMPropList * array)
772 {
773 WMPropList *item;
774 int i;
775
776 for (i = 0; i < WMGetPropListItemCount(array); i++) {
777 item = WMGetFromPLArray(array, i);
778 if (item)
779 WMInsertInPLArray(destarr, i + 1, item);
780 }
781 }
782
783 static void appendMenu(WMPropList * destarr, WMPropList * array)
784 {
785 WMPropList *item;
786 int i;
787
788 for (i = 0; i < WMGetPropListItemCount(array); i++) {
789 item = WMGetFromPLArray(array, i);
790 if (item)
791 WMAddToPLArray(destarr, item);
792 }
793 }
794 #endif
795
796 /* Fixup paths for cached pixmaps from .AppInfo to Library/WindowMaker/... */
797 static Bool fixupCachedPixmapsPaths(WMPropList * dict)
798 {
799 WMPropList *allApps, *app, *props, *iconkey, *icon, *newicon;
800 char *path, *fixedpath, *ptr, *search;
801 int i, len, slen;
802 Bool changed = False;
803
804 search = "/.AppInfo/WindowMaker/";
805 slen = strlen(search);
806
807 iconkey = WMCreatePLString("Icon");
808 allApps = WMGetPLDictionaryKeys(dict);
809
810 for (i = 0; i < WMGetPropListItemCount(allApps); i++) {
811 app = WMGetFromPLArray(allApps, i);
812 props = WMGetFromPLDictionary(dict, app);
813 if (!props)
814 continue;
815 icon = WMGetFromPLDictionary(props, iconkey);
816 if (icon && WMIsPLString(icon)) {
817 path = WMGetFromPLString(icon);
818 ptr = strstr(path, search);
819 if (ptr) {
820 changed = True;
821 len = (ptr - path);
822 fixedpath = wmalloc(strlen(path) + 32);
823 strncpy(fixedpath, path, len);
824 fixedpath[len] = 0;
825 strcat(fixedpath, "/Library/WindowMaker/CachedPixmaps/");
826 strcat(fixedpath, ptr + slen);
827 newicon = WMCreatePLString(fixedpath);
828 WMPutInPLDictionary(props, iconkey, newicon);
829 WMReleasePropList(newicon);
830 wfree(fixedpath);
831 }
832 }
833 }
834
835 WMReleasePropList(allApps);
836 WMReleasePropList(iconkey);
837
838 return changed;
839 }
840
841 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
842 {
843 WMPropList *menu = menuDomain->dictionary;
844 WMPropList *submenu;
845
846 if (!menu || !WMIsPLArray(menu))
847 return;
848
849 #ifdef GLOBAL_PREAMBLE_MENU_FILE
850 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
851
852 if (submenu && !WMIsPLArray(submenu)) {
853 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
854 WMReleasePropList(submenu);
855 submenu = NULL;
856 }
857 if (submenu) {
858 prependMenu(menu, submenu);
859 WMReleasePropList(submenu);
860 }
861 #endif
862
863 #ifdef GLOBAL_EPILOGUE_MENU_FILE
864 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
865
866 if (submenu && !WMIsPLArray(submenu)) {
867 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
868 WMReleasePropList(submenu);
869 submenu = NULL;
870 }
871 if (submenu) {
872 appendMenu(menu, submenu);
873 WMReleasePropList(submenu);
874 }
875 #endif
876
877 menuDomain->dictionary = menu;
878 }
879
880 #if 0
881 WMPropList *wDefaultsInit(int screen_number)
882 {
883 static int defaults_inited = 0;
884 WMPropList *dict;
885
886 if (!defaults_inited) {
887 initDefaults();
888 }
889
890 dict = PLGetDomain(wDomainName);
891 if (!dict) {
892 wwarning(_("could not read domain \"%s\" from defaults database"), WMGetFromPLString(wDomainName));
893 }
894
895 return dict;
896 }
897 #endif
898
899 void wDefaultsDestroyDomain(WDDomain * domain)
900 {
901 if (domain->dictionary)
902 WMReleasePropList(domain->dictionary);
903 wfree(domain->path);
904 wfree(domain);
905 }
906
907 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
908 {
909 WDDomain *db;
910 struct stat stbuf;
911 static int inited = 0;
912 char path[PATH_MAX];
913 char *the_path;
914 WMPropList *shared_dict = NULL;
915
916 if (!inited) {
917 inited = 1;
918 initDefaults();
919 }
920
921 db = wmalloc(sizeof(WDDomain));
922 memset(db, 0, sizeof(WDDomain));
923 db->domain_name = domain;
924 db->path = wdefaultspathfordomain(domain);
925 the_path = db->path;
926
927 if (the_path && stat(the_path, &stbuf) >= 0) {
928 db->dictionary = WMReadPropListFromFile(the_path);
929 if (db->dictionary) {
930 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
931 WMReleasePropList(db->dictionary);
932 db->dictionary = NULL;
933 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
934 }
935 if (strcmp(domain, "WMWindowAttributes") == 0 && db->dictionary) {
936 if (fixupCachedPixmapsPaths(db->dictionary)) {
937 WMWritePropListToFile(db->dictionary, db->path, True);
938 /* re-read the timestamp. if this fails take current time */
939 if (stat(db->path, &stbuf) < 0) {
940 stbuf.st_mtime = time(NULL);
941 }
942 }
943 }
944 db->timestamp = stbuf.st_mtime;
945 } else {
946 wwarning(_("could not load domain %s from user defaults database"), domain);
947 }
948 }
949
950 /* global system dictionary */
951 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
952 if (stat(path, &stbuf) >= 0) {
953 shared_dict = WMReadPropListFromFile(path);
954 if (shared_dict) {
955 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
956 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
957 domain, path);
958 WMReleasePropList(shared_dict);
959 shared_dict = NULL;
960 } else {
961 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
962 WMIsPLDictionary(db->dictionary)) {
963 WMMergePLDictionaries(shared_dict, db->dictionary, True);
964 WMReleasePropList(db->dictionary);
965 db->dictionary = shared_dict;
966 if (stbuf.st_mtime > db->timestamp)
967 db->timestamp = stbuf.st_mtime;
968 } else if (!db->dictionary) {
969 db->dictionary = shared_dict;
970 if (stbuf.st_mtime > db->timestamp)
971 db->timestamp = stbuf.st_mtime;
972 }
973 }
974 } else {
975 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
976 }
977 }
978
979 return db;
980 }
981
982 void wReadStaticDefaults(WMPropList * dict)
983 {
984 WMPropList *plvalue;
985 WDefaultEntry *entry;
986 unsigned int i;
987 void *tdata;
988
989 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
990 entry = &staticOptionList[i];
991
992 if (dict)
993 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
994 else
995 plvalue = NULL;
996
997 if (!plvalue) {
998 /* no default in the DB. Use builtin default */
999 plvalue = entry->plvalue;
1000 }
1001
1002 if (plvalue) {
1003 /* convert data */
1004 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
1005 if (entry->update) {
1006 (*entry->update) (NULL, entry, tdata, entry->extra_data);
1007 }
1008 }
1009 }
1010 }
1011
1012 void wDefaultsCheckDomains(void)
1013 {
1014 WScreen *scr;
1015 struct stat stbuf;
1016 WMPropList *shared_dict = NULL;
1017 WMPropList *dict;
1018 int i;
1019
1020 #ifdef HEARTBEAT
1021 puts("Checking domains...");
1022 #endif
1023 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1024 #ifdef HEARTBEAT
1025 puts("Checking WindowMaker domain");
1026 #endif
1027 WDWindowMaker->timestamp = stbuf.st_mtime;
1028
1029 /* global dictionary */
1030 shared_dict = readGlobalDomain("WindowMaker", True);
1031 /* user dictionary */
1032 dict = WMReadPropListFromFile(WDWindowMaker->path);
1033 if (dict) {
1034 if (!WMIsPLDictionary(dict)) {
1035 WMReleasePropList(dict);
1036 dict = NULL;
1037 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1038 "WindowMaker", WDWindowMaker->path);
1039 } else {
1040 if (shared_dict) {
1041 WMMergePLDictionaries(shared_dict, dict, True);
1042 WMReleasePropList(dict);
1043 dict = shared_dict;
1044 shared_dict = NULL;
1045 }
1046 for (i = 0; i < wScreenCount; i++) {
1047 scr = wScreenWithNumber(i);
1048 if (scr)
1049 wReadDefaults(scr, dict);
1050 }
1051 if (WDWindowMaker->dictionary) {
1052 WMReleasePropList(WDWindowMaker->dictionary);
1053 }
1054 WDWindowMaker->dictionary = dict;
1055 }
1056 } else {
1057 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1058 }
1059 if (shared_dict) {
1060 WMReleasePropList(shared_dict);
1061 }
1062 }
1063
1064 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1065 #ifdef HEARTBEAT
1066 puts("Checking WMWindowAttributes domain");
1067 #endif
1068 /* global dictionary */
1069 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1070 /* user dictionary */
1071 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1072 if (dict) {
1073 if (!WMIsPLDictionary(dict)) {
1074 WMReleasePropList(dict);
1075 dict = NULL;
1076 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1077 "WMWindowAttributes", WDWindowAttributes->path);
1078 } else {
1079 if (shared_dict) {
1080 WMMergePLDictionaries(shared_dict, dict, True);
1081 WMReleasePropList(dict);
1082 dict = shared_dict;
1083 shared_dict = NULL;
1084 }
1085 if (WDWindowAttributes->dictionary) {
1086 WMReleasePropList(WDWindowAttributes->dictionary);
1087 }
1088 WDWindowAttributes->dictionary = dict;
1089 for (i = 0; i < wScreenCount; i++) {
1090 scr = wScreenWithNumber(i);
1091 if (scr) {
1092 RImage *image;
1093
1094 wDefaultUpdateIcons(scr);
1095
1096 /* Update the panel image if changed */
1097 /* Don't worry. If the image is the same these
1098 * functions will have no performance impact. */
1099 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1100
1101 if (!image) {
1102 wwarning(_("could not load logo image for panels: %s"),
1103 RMessageForError(RErrorCode));
1104 } else {
1105 WMSetApplicationIconImage(scr->wmscreen, image);
1106 RReleaseImage(image);
1107 }
1108 }
1109 }
1110 }
1111 } else {
1112 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1113 }
1114 WDWindowAttributes->timestamp = stbuf.st_mtime;
1115 if (shared_dict) {
1116 WMReleasePropList(shared_dict);
1117 }
1118 }
1119
1120 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1121 dict = WMReadPropListFromFile(WDRootMenu->path);
1122 #ifdef HEARTBEAT
1123 puts("Checking WMRootMenu domain");
1124 #endif
1125 if (dict) {
1126 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1127 WMReleasePropList(dict);
1128 dict = NULL;
1129 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1130 "WMRootMenu", WDRootMenu->path);
1131 } else {
1132 if (WDRootMenu->dictionary) {
1133 WMReleasePropList(WDRootMenu->dictionary);
1134 }
1135 WDRootMenu->dictionary = dict;
1136 wDefaultsMergeGlobalMenus(WDRootMenu);
1137 }
1138 } else {
1139 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1140 }
1141 WDRootMenu->timestamp = stbuf.st_mtime;
1142 }
1143 }
1144
1145 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1146 {
1147 WMPropList *plvalue, *old_value;
1148 WDefaultEntry *entry;
1149 unsigned int i, must_update;
1150 int update_workspace_back = 0; /* kluge :/ */
1151 unsigned int needs_refresh;
1152 void *tdata;
1153 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1154
1155 must_update = 0;
1156
1157 needs_refresh = 0;
1158
1159 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1160 entry = &optionList[i];
1161
1162 if (new_dict)
1163 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1164 else
1165 plvalue = NULL;
1166
1167 if (!old_dict)
1168 old_value = NULL;
1169 else
1170 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1171
1172 if (!plvalue && !old_value) {
1173 /* no default in the DB. Use builtin default */
1174 plvalue = entry->plvalue;
1175 if (plvalue && new_dict) {
1176 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1177 must_update = 1;
1178 }
1179 } else if (!plvalue) {
1180 /* value was deleted from DB. Keep current value */
1181 continue;
1182 } else if (!old_value) {
1183 /* set value for the 1st time */
1184 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1185 /* value has changed */
1186 } else {
1187
1188 if (strcmp(entry->key, "WorkspaceBack") == 0
1189 && update_workspace_back && scr->flags.backimage_helper_launched) {
1190 } else {
1191 /* value was not changed since last time */
1192 continue;
1193 }
1194 }
1195
1196 if (plvalue) {
1197 #ifdef DEBUG
1198 printf("Updating %s to %s\n", entry->key, WMGetPropListDescription(plvalue, False));
1199 #endif
1200 /* convert data */
1201 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1202 /*
1203 * If the WorkspaceSpecificBack data has been changed
1204 * so that the helper will be launched now, we must be
1205 * sure to send the default background texture config
1206 * to the helper.
1207 */
1208 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1209 && !scr->flags.backimage_helper_launched) {
1210 update_workspace_back = 1;
1211 }
1212 if (entry->update) {
1213 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1214 }
1215 }
1216 }
1217 }
1218
1219 if (needs_refresh != 0 && !scr->flags.startup) {
1220 int foo;
1221
1222 foo = 0;
1223 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1224 foo |= WTextureSettings;
1225 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1226 foo |= WFontSettings;
1227 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1228 foo |= WColorSettings;
1229 if (foo)
1230 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1231 (void *)(uintptr_t) foo);
1232
1233 foo = 0;
1234 if (needs_refresh & REFRESH_MENU_TEXTURE)
1235 foo |= WTextureSettings;
1236 if (needs_refresh & REFRESH_MENU_FONT)
1237 foo |= WFontSettings;
1238 if (needs_refresh & REFRESH_MENU_COLOR)
1239 foo |= WColorSettings;
1240 if (foo)
1241 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1242
1243 foo = 0;
1244 if (needs_refresh & REFRESH_WINDOW_FONT) {
1245 foo |= WFontSettings;
1246 }
1247 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1248 foo |= WTextureSettings;
1249 }
1250 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1251 foo |= WColorSettings;
1252 }
1253 if (foo)
1254 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1255
1256 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1257 foo = 0;
1258 if (needs_refresh & REFRESH_ICON_FONT) {
1259 foo |= WFontSettings;
1260 }
1261 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1262 foo |= WTextureSettings;
1263 }
1264 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1265 foo |= WTextureSettings;
1266 }
1267 if (foo)
1268 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1269 (void *)(uintptr_t) foo);
1270 }
1271 if (needs_refresh & REFRESH_ICON_TILE)
1272 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1273 }
1274 }
1275
1276 void wDefaultUpdateIcons(WScreen * scr)
1277 {
1278 WAppIcon *aicon = scr->app_icon_list;
1279 WWindow *wwin = scr->focused_window;
1280 char *file;
1281
1282 while (aicon) {
1283 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1284 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1285 || (file && !aicon->icon->file)) {
1286 RImage *new_image;
1287
1288 if (aicon->icon->file)
1289 wfree(aicon->icon->file);
1290 aicon->icon->file = wstrdup(file);
1291
1292 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1293 if (new_image) {
1294 wIconChangeImage(aicon->icon, new_image);
1295 wAppIconPaint(aicon);
1296 }
1297 }
1298 aicon = aicon->next;
1299 }
1300
1301 if (!wPreferences.flags.noclip)
1302 wClipIconPaint(scr->clip_icon);
1303
1304 while (wwin) {
1305 if (wwin->icon && wwin->flags.miniaturized) {
1306 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1307 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1308 || (file && !wwin->icon->file)) {
1309 RImage *new_image;
1310
1311 if (wwin->icon->file)
1312 wfree(wwin->icon->file);
1313 wwin->icon->file = wstrdup(file);
1314
1315 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1316 if (new_image)
1317 wIconChangeImage(wwin->icon, new_image);
1318 }
1319 }
1320 wwin = wwin->prev;
1321 }
1322 }
1323
1324 /* --------------------------- Local ----------------------- */
1325
1326 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1327 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1328 entry->key, x); \
1329 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1330 var = entry->default_value;\
1331 } else var = WMGetFromPLString(value)\
1332
1333
1334 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1335 {
1336 char *str;
1337 WOptionEnumeration *v;
1338 char buffer[TOTAL_VALUES_LENGTH];
1339
1340 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1341 for (v = values; v->string != NULL; v++) {
1342 if (strcasecmp(v->string, str) == 0)
1343 return v->value;
1344 }
1345 }
1346
1347 buffer[0] = 0;
1348 for (v = values; v->string != NULL; v++) {
1349 if (!v->is_alias) {
1350 if (buffer[0] != 0)
1351 strcat(buffer, ", ");
1352 strcat(buffer, v->string);
1353 }
1354 }
1355 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1356
1357 if (def) {
1358 return string2index(key, val, NULL, values);
1359 }
1360
1361 return -1;
1362 }
1363
1364 /*
1365 * value - is the value in the defaults DB
1366 * addr - is the address to store the data
1367 * ret - is the address to store a pointer to a temporary buffer. ret
1368 * must not be freed and is used by the set functions
1369 */
1370 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1371 {
1372 static char data;
1373 char *val;
1374 int second_pass = 0;
1375
1376 GET_STRING_OR_DEFAULT("Boolean", val);
1377
1378 again:
1379 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1380 || strcasecmp(val, "YES") == 0) {
1381
1382 data = 1;
1383 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1384 || strcasecmp(val, "NO") == 0) {
1385 data = 0;
1386 } else {
1387 int i;
1388 if (sscanf(val, "%i", &i) == 1) {
1389 if (i != 0)
1390 data = 1;
1391 else
1392 data = 0;
1393 } else {
1394 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1395 if (second_pass == 0) {
1396 val = WMGetFromPLString(entry->plvalue);
1397 second_pass = 1;
1398 wwarning(_("using default \"%s\" instead"), val);
1399 goto again;
1400 }
1401 return False;
1402 }
1403 }
1404
1405 if (ret)
1406 *ret = &data;
1407 if (addr)
1408 *(char *)addr = data;
1409
1410 return True;
1411 }
1412
1413 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1414 {
1415 static int data;
1416 char *val;
1417
1418 GET_STRING_OR_DEFAULT("Integer", val);
1419
1420 if (sscanf(val, "%i", &data) != 1) {
1421 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1422 val = WMGetFromPLString(entry->plvalue);
1423 wwarning(_("using default \"%s\" instead"), val);
1424 if (sscanf(val, "%i", &data) != 1) {
1425 return False;
1426 }
1427 }
1428
1429 if (ret)
1430 *ret = &data;
1431 if (addr)
1432 *(int *)addr = data;
1433
1434 return True;
1435 }
1436
1437 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1438 {
1439 static WCoord data;
1440 char *val_x, *val_y;
1441 int nelem, changed = 0;
1442 WMPropList *elem_x, *elem_y;
1443
1444 again:
1445 if (!WMIsPLArray(value)) {
1446 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1447 if (changed == 0) {
1448 value = entry->plvalue;
1449 changed = 1;
1450 wwarning(_("using default \"%s\" instead"), entry->default_value);
1451 goto again;
1452 }
1453 return False;
1454 }
1455
1456 nelem = WMGetPropListItemCount(value);
1457 if (nelem != 2) {
1458 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1459 if (changed == 0) {
1460 value = entry->plvalue;
1461 changed = 1;
1462 wwarning(_("using default \"%s\" instead"), entry->default_value);
1463 goto again;
1464 }
1465 return False;
1466 }
1467
1468 elem_x = WMGetFromPLArray(value, 0);
1469 elem_y = WMGetFromPLArray(value, 1);
1470
1471 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1472 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1473 if (changed == 0) {
1474 value = entry->plvalue;
1475 changed = 1;
1476 wwarning(_("using default \"%s\" instead"), entry->default_value);
1477 goto again;
1478 }
1479 return False;
1480 }
1481
1482 val_x = WMGetFromPLString(elem_x);
1483 val_y = WMGetFromPLString(elem_y);
1484
1485 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1486 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1487 if (changed == 0) {
1488 value = entry->plvalue;
1489 changed = 1;
1490 wwarning(_("using default \"%s\" instead"), entry->default_value);
1491 goto again;
1492 }
1493 return False;
1494 }
1495
1496 if (data.x < 0)
1497 data.x = 0;
1498 else if (data.x > scr->scr_width / 3)
1499 data.x = scr->scr_width / 3;
1500 if (data.y < 0)
1501 data.y = 0;
1502 else if (data.y > scr->scr_height / 3)
1503 data.y = scr->scr_height / 3;
1504
1505 if (ret)
1506 *ret = &data;
1507 if (addr)
1508 *(WCoord *) addr = data;
1509
1510 return True;
1511 }
1512
1513 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1514 {
1515 WMRetainPropList(value);
1516
1517 *ret = value;
1518
1519 return True;
1520 }
1521
1522 #if 0
1523 /* This function is not used at the moment. */
1524 static int getString(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1525 {
1526 static char *data;
1527
1528 GET_STRING_OR_DEFAULT("String", data);
1529
1530 if (!data) {
1531 data = WMGetFromPLString(entry->plvalue);
1532 if (!data)
1533 return False;
1534 }
1535
1536 if (ret)
1537 *ret = &data;
1538 if (addr)
1539 *(char **)addr = wstrdup(data);
1540
1541 return True;
1542 }
1543 #endif
1544
1545 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1546 {
1547 static char *data;
1548 int i, count, len;
1549 char *ptr;
1550 WMPropList *d;
1551 int changed = 0;
1552
1553 again:
1554 if (!WMIsPLArray(value)) {
1555 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1556 if (changed == 0) {
1557 value = entry->plvalue;
1558 changed = 1;
1559 wwarning(_("using default \"%s\" instead"), entry->default_value);
1560 goto again;
1561 }
1562 return False;
1563 }
1564
1565 i = 0;
1566 count = WMGetPropListItemCount(value);
1567 if (count < 1) {
1568 if (changed == 0) {
1569 value = entry->plvalue;
1570 changed = 1;
1571 wwarning(_("using default \"%s\" instead"), entry->default_value);
1572 goto again;
1573 }
1574 return False;
1575 }
1576
1577 len = 0;
1578 for (i = 0; i < count; i++) {
1579 d = WMGetFromPLArray(value, i);
1580 if (!d || !WMIsPLString(d)) {
1581 count = i;
1582 break;
1583 }
1584 len += strlen(WMGetFromPLString(d)) + 1;
1585 }
1586
1587 ptr = data = wmalloc(len + 1);
1588
1589 for (i = 0; i < count; i++) {
1590 d = WMGetFromPLArray(value, i);
1591 if (!d || !WMIsPLString(d)) {
1592 break;
1593 }
1594 strcpy(ptr, WMGetFromPLString(d));
1595 ptr += strlen(WMGetFromPLString(d));
1596 *ptr = ':';
1597 ptr++;
1598 }
1599 ptr--;
1600 *(ptr--) = 0;
1601
1602 if (*(char **)addr != NULL) {
1603 wfree(*(char **)addr);
1604 }
1605 *(char **)addr = data;
1606
1607 return True;
1608 }
1609
1610 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1611 {
1612 static signed char data;
1613
1614 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1615 if (data < 0)
1616 return False;
1617
1618 if (ret)
1619 *ret = &data;
1620 if (addr)
1621 *(signed char *)addr = data;
1622
1623 return True;
1624 }
1625
1626 /*
1627 * (solid <color>)
1628 * (hgradient <color> <color>)
1629 * (vgradient <color> <color>)
1630 * (dgradient <color> <color>)
1631 * (mhgradient <color> <color> ...)
1632 * (mvgradient <color> <color> ...)
1633 * (mdgradient <color> <color> ...)
1634 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1635 * (tpixmap <file> <color>)
1636 * (spixmap <file> <color>)
1637 * (cpixmap <file> <color>)
1638 * (thgradient <file> <opaqueness> <color> <color>)
1639 * (tvgradient <file> <opaqueness> <color> <color>)
1640 * (tdgradient <file> <opaqueness> <color> <color>)
1641 * (function <lib> <function> ...)
1642 */
1643
1644 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1645 {
1646 WMPropList *elem;
1647 char *val;
1648 int nelem;
1649 WTexture *texture = NULL;
1650
1651 nelem = WMGetPropListItemCount(pl);
1652 if (nelem < 1)
1653 return NULL;
1654
1655 elem = WMGetFromPLArray(pl, 0);
1656 if (!elem || !WMIsPLString(elem))
1657 return NULL;
1658 val = WMGetFromPLString(elem);
1659
1660 if (strcasecmp(val, "solid") == 0) {
1661 XColor color;
1662
1663 if (nelem != 2)
1664 return NULL;
1665
1666 /* get color */
1667
1668 elem = WMGetFromPLArray(pl, 1);
1669 if (!elem || !WMIsPLString(elem))
1670 return NULL;
1671 val = WMGetFromPLString(elem);
1672
1673 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1674 wwarning(_("\"%s\" is not a valid color name"), val);
1675 return NULL;
1676 }
1677
1678 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1679 } else if (strcasecmp(val, "dgradient") == 0
1680 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1681 RColor color1, color2;
1682 XColor xcolor;
1683 int type;
1684
1685 if (nelem != 3) {
1686 wwarning(_("bad number of arguments in gradient specification"));
1687 return NULL;
1688 }
1689
1690 if (val[0] == 'd' || val[0] == 'D')
1691 type = WTEX_DGRADIENT;
1692 else if (val[0] == 'h' || val[0] == 'H')
1693 type = WTEX_HGRADIENT;
1694 else
1695 type = WTEX_VGRADIENT;
1696
1697 /* get from color */
1698 elem = WMGetFromPLArray(pl, 1);
1699 if (!elem || !WMIsPLString(elem))
1700 return NULL;
1701 val = WMGetFromPLString(elem);
1702
1703 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1704 wwarning(_("\"%s\" is not a valid color name"), val);
1705 return NULL;
1706 }
1707 color1.alpha = 255;
1708 color1.red = xcolor.red >> 8;
1709 color1.green = xcolor.green >> 8;
1710 color1.blue = xcolor.blue >> 8;
1711
1712 /* get to color */
1713 elem = WMGetFromPLArray(pl, 2);
1714 if (!elem || !WMIsPLString(elem)) {
1715 return NULL;
1716 }
1717 val = WMGetFromPLString(elem);
1718
1719 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1720 wwarning(_("\"%s\" is not a valid color name"), val);
1721 return NULL;
1722 }
1723 color2.alpha = 255;
1724 color2.red = xcolor.red >> 8;
1725 color2.green = xcolor.green >> 8;
1726 color2.blue = xcolor.blue >> 8;
1727
1728 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1729
1730 } else if (strcasecmp(val, "igradient") == 0) {
1731 RColor colors1[2], colors2[2];
1732 int th1, th2;
1733 XColor xcolor;
1734 int i;
1735
1736 if (nelem != 7) {
1737 wwarning(_("bad number of arguments in gradient specification"));
1738 return NULL;
1739 }
1740
1741 /* get from color */
1742 for (i = 0; i < 2; i++) {
1743 elem = WMGetFromPLArray(pl, 1 + i);
1744 if (!elem || !WMIsPLString(elem))
1745 return NULL;
1746 val = WMGetFromPLString(elem);
1747
1748 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1749 wwarning(_("\"%s\" is not a valid color name"), val);
1750 return NULL;
1751 }
1752 colors1[i].alpha = 255;
1753 colors1[i].red = xcolor.red >> 8;
1754 colors1[i].green = xcolor.green >> 8;
1755 colors1[i].blue = xcolor.blue >> 8;
1756 }
1757 elem = WMGetFromPLArray(pl, 3);
1758 if (!elem || !WMIsPLString(elem))
1759 return NULL;
1760 val = WMGetFromPLString(elem);
1761 th1 = atoi(val);
1762
1763 /* get from color */
1764 for (i = 0; i < 2; i++) {
1765 elem = WMGetFromPLArray(pl, 4 + i);
1766 if (!elem || !WMIsPLString(elem))
1767 return NULL;
1768 val = WMGetFromPLString(elem);
1769
1770 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1771 wwarning(_("\"%s\" is not a valid color name"), val);
1772 return NULL;
1773 }
1774 colors2[i].alpha = 255;
1775 colors2[i].red = xcolor.red >> 8;
1776 colors2[i].green = xcolor.green >> 8;
1777 colors2[i].blue = xcolor.blue >> 8;
1778 }
1779 elem = WMGetFromPLArray(pl, 6);
1780 if (!elem || !WMIsPLString(elem))
1781 return NULL;
1782 val = WMGetFromPLString(elem);
1783 th2 = atoi(val);
1784
1785 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1786
1787 } else if (strcasecmp(val, "mhgradient") == 0
1788 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1789 XColor color;
1790 RColor **colors;
1791 int i, count;
1792 int type;
1793
1794 if (nelem < 3) {
1795 wwarning(_("too few arguments in multicolor gradient specification"));
1796 return NULL;
1797 }
1798
1799 if (val[1] == 'h' || val[1] == 'H')
1800 type = WTEX_MHGRADIENT;
1801 else if (val[1] == 'v' || val[1] == 'V')
1802 type = WTEX_MVGRADIENT;
1803 else
1804 type = WTEX_MDGRADIENT;
1805
1806 count = nelem - 1;
1807
1808 colors = wmalloc(sizeof(RColor *) * (count + 1));
1809
1810 for (i = 0; i < count; i++) {
1811 elem = WMGetFromPLArray(pl, i + 1);
1812 if (!elem || !WMIsPLString(elem)) {
1813 for (--i; i >= 0; --i) {
1814 wfree(colors[i]);
1815 }
1816 wfree(colors);
1817 return NULL;
1818 }
1819 val = WMGetFromPLString(elem);
1820
1821 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1822 wwarning(_("\"%s\" is not a valid color name"), val);
1823 for (--i; i >= 0; --i) {
1824 wfree(colors[i]);
1825 }
1826 wfree(colors);
1827 return NULL;
1828 } else {
1829 colors[i] = wmalloc(sizeof(RColor));
1830 colors[i]->red = color.red >> 8;
1831 colors[i]->green = color.green >> 8;
1832 colors[i]->blue = color.blue >> 8;
1833 }
1834 }
1835 colors[i] = NULL;
1836
1837 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1838 } else if (strcasecmp(val, "spixmap") == 0 ||
1839 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1840 XColor color;
1841 int type;
1842
1843 if (nelem != 3)
1844 return NULL;
1845
1846 if (val[0] == 's' || val[0] == 'S')
1847 type = WTP_SCALE;
1848 else if (val[0] == 'c' || val[0] == 'C')
1849 type = WTP_CENTER;
1850 else
1851 type = WTP_TILE;
1852
1853 /* get color */
1854 elem = WMGetFromPLArray(pl, 2);
1855 if (!elem || !WMIsPLString(elem)) {
1856 return NULL;
1857 }
1858 val = WMGetFromPLString(elem);
1859
1860 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1861 wwarning(_("\"%s\" is not a valid color name"), val);
1862 return NULL;
1863 }
1864
1865 /* file name */
1866 elem = WMGetFromPLArray(pl, 1);
1867 if (!elem || !WMIsPLString(elem))
1868 return NULL;
1869 val = WMGetFromPLString(elem);
1870
1871 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1872 } else if (strcasecmp(val, "thgradient") == 0
1873 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1874 RColor color1, color2;
1875 XColor xcolor;
1876 int opacity;
1877 int style;
1878
1879 if (val[1] == 'h' || val[1] == 'H')
1880 style = WTEX_THGRADIENT;
1881 else if (val[1] == 'v' || val[1] == 'V')
1882 style = WTEX_TVGRADIENT;
1883 else
1884 style = WTEX_TDGRADIENT;
1885
1886 if (nelem != 5) {
1887 wwarning(_("bad number of arguments in textured gradient specification"));
1888 return NULL;
1889 }
1890
1891 /* get from color */
1892 elem = WMGetFromPLArray(pl, 3);
1893 if (!elem || !WMIsPLString(elem))
1894 return NULL;
1895 val = WMGetFromPLString(elem);
1896
1897 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1898 wwarning(_("\"%s\" is not a valid color name"), val);
1899 return NULL;
1900 }
1901 color1.alpha = 255;
1902 color1.red = xcolor.red >> 8;
1903 color1.green = xcolor.green >> 8;
1904 color1.blue = xcolor.blue >> 8;
1905
1906 /* get to color */
1907 elem = WMGetFromPLArray(pl, 4);
1908 if (!elem || !WMIsPLString(elem)) {
1909 return NULL;
1910 }
1911 val = WMGetFromPLString(elem);
1912
1913 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1914 wwarning(_("\"%s\" is not a valid color name"), val);
1915 return NULL;
1916 }
1917 color2.alpha = 255;
1918 color2.red = xcolor.red >> 8;
1919 color2.green = xcolor.green >> 8;
1920 color2.blue = xcolor.blue >> 8;
1921
1922 /* get opacity */
1923 elem = WMGetFromPLArray(pl, 2);
1924 if (!elem || !WMIsPLString(elem))
1925 opacity = 128;
1926 else
1927 val = WMGetFromPLString(elem);
1928
1929 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1930 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1931 opacity = 128;
1932 }
1933
1934 /* get file name */
1935 elem = WMGetFromPLArray(pl, 1);
1936 if (!elem || !WMIsPLString(elem))
1937 return NULL;
1938 val = WMGetFromPLString(elem);
1939
1940 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1941 }
1942 #ifdef TEXTURE_PLUGIN
1943 else if (strcasecmp(val, "function") == 0) {
1944 WTexFunction *function;
1945 void (*initFunc) (Display *, Colormap);
1946 char *lib, *func, **argv;
1947 int i, argc;
1948
1949 if (nelem < 3)
1950 return NULL;
1951
1952 /* get the library name */
1953 elem = WMGetFromPLArray(pl, 1);
1954 if (!elem || !WMIsPLString(elem)) {
1955 return NULL;
1956 }
1957 lib = WMGetFromPLString(elem);
1958
1959 /* get the function name */
1960 elem = WMGetFromPLArray(pl, 2);
1961 if (!elem || !WMIsPLString(elem)) {
1962 return NULL;
1963 }
1964 func = WMGetFromPLString(elem);
1965
1966 argc = nelem - 2;
1967 argv = (char **)wmalloc(argc * sizeof(char *));
1968
1969 /* get the parameters */
1970 argv[0] = wstrdup(func);
1971 for (i = 0; i < argc - 1; i++) {
1972 elem = WMGetFromPLArray(pl, 3 + i);
1973 if (!elem || !WMIsPLString(elem)) {
1974 wfree(argv);
1975
1976 return NULL;
1977 }
1978 argv[i + 1] = wstrdup(WMGetFromPLString(elem));
1979 }
1980
1981 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1982
1983 #ifdef HAVE_DLFCN_H
1984 if (function) {
1985 initFunc = dlsym(function->handle, "initWindowMaker");
1986 if (initFunc) {
1987 initFunc(dpy, scr->w_colormap);
1988 } else {
1989 wwarning(_("could not initialize library %s"), lib);
1990 }
1991 } else {
1992 wwarning(_("could not find function %s::%s"), lib, func);
1993 }
1994 #endif /* HAVE_DLFCN_H */
1995 texture = (WTexture *) function;
1996 }
1997 #endif /* TEXTURE_PLUGIN */
1998 else {
1999 wwarning(_("invalid texture type %s"), val);
2000 return NULL;
2001 }
2002 return texture;
2003 }
2004
2005 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2006 {
2007 static WTexture *texture;
2008 int changed = 0;
2009
2010 again:
2011 if (!WMIsPLArray(value)) {
2012 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
2013 if (changed == 0) {
2014 value = entry->plvalue;
2015 changed = 1;
2016 wwarning(_("using default \"%s\" instead"), entry->default_value);
2017 goto again;
2018 }
2019 return False;
2020 }
2021
2022 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
2023 WMPropList *pl;
2024
2025 pl = WMGetFromPLArray(value, 0);
2026 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2027 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
2028 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2029 entry->key, "Solid Texture");
2030
2031 value = entry->plvalue;
2032 changed = 1;
2033 wwarning(_("using default \"%s\" instead"), entry->default_value);
2034 goto again;
2035 }
2036 }
2037
2038 texture = parse_texture(scr, value);
2039
2040 if (!texture) {
2041 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
2042 if (changed == 0) {
2043 value = entry->plvalue;
2044 changed = 1;
2045 wwarning(_("using default \"%s\" instead"), entry->default_value);
2046 goto again;
2047 }
2048 return False;
2049 }
2050
2051 if (ret)
2052 *ret = &texture;
2053
2054 if (addr)
2055 *(WTexture **) addr = texture;
2056
2057 return True;
2058 }
2059
2060 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2061 {
2062 WMPropList *elem;
2063 int changed = 0;
2064 char *val;
2065 int nelem;
2066
2067 again:
2068 if (!WMIsPLArray(value)) {
2069 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2070 "WorkspaceBack", "Texture or None");
2071 if (changed == 0) {
2072 value = entry->plvalue;
2073 changed = 1;
2074 wwarning(_("using default \"%s\" instead"), entry->default_value);
2075 goto again;
2076 }
2077 return False;
2078 }
2079
2080 /* only do basic error checking and verify for None texture */
2081
2082 nelem = WMGetPropListItemCount(value);
2083 if (nelem > 0) {
2084 elem = WMGetFromPLArray(value, 0);
2085 if (!elem || !WMIsPLString(elem)) {
2086 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2087 if (changed == 0) {
2088 value = entry->plvalue;
2089 changed = 1;
2090 wwarning(_("using default \"%s\" instead"), entry->default_value);
2091 goto again;
2092 }
2093 return False;
2094 }
2095 val = WMGetFromPLString(elem);
2096
2097 if (strcasecmp(val, "None") == 0)
2098 return True;
2099 }
2100 *ret = WMRetainPropList(value);
2101
2102 return True;
2103 }
2104
2105 static int
2106 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2107 {
2108 WMPropList *elem;
2109 int nelem;
2110 int changed = 0;
2111
2112 again:
2113 if (!WMIsPLArray(value)) {
2114 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2115 "WorkspaceSpecificBack", "an array of textures");
2116 if (changed == 0) {
2117 value = entry->plvalue;
2118 changed = 1;
2119 wwarning(_("using default \"%s\" instead"), entry->default_value);
2120 goto again;
2121 }
2122 return False;
2123 }
2124
2125 /* only do basic error checking and verify for None texture */
2126
2127 nelem = WMGetPropListItemCount(value);
2128 if (nelem > 0) {
2129 while (nelem--) {
2130 elem = WMGetFromPLArray(value, nelem);
2131 if (!elem || !WMIsPLArray(elem)) {
2132 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2133 nelem);
2134 }
2135 }
2136 }
2137
2138 *ret = WMRetainPropList(value);
2139
2140 #ifdef notworking
2141 /*
2142 * Kluge to force wmsetbg helper to set the default background.
2143 * If the WorkspaceSpecificBack is changed once wmaker has started,
2144 * the WorkspaceBack won't be sent to the helper, unless the user
2145 * changes it's value too. So, we must force this by removing the
2146 * value from the defaults DB.
2147 */
2148 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2149 WMPropList *key = WMCreatePLString("WorkspaceBack");
2150
2151 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2152
2153 WMReleasePropList(key);
2154 }
2155 #endif
2156 return True;
2157 }
2158
2159 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2160 {
2161 static WMFont *font;
2162 char *val;
2163
2164 GET_STRING_OR_DEFAULT("Font", val);
2165
2166 font = WMCreateFont(scr->wmscreen, val);
2167 if (!font)
2168 font = WMCreateFont(scr->wmscreen, "fixed");
2169
2170 if (!font) {
2171 wfatal(_("could not load any usable font!!!"));
2172 exit(1);
2173 }
2174
2175 if (ret)
2176 *ret = font;
2177
2178 /* can't assign font value outside update function */
2179 wassertrv(addr == NULL, True);
2180
2181 return True;
2182 }
2183
2184 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2185 {
2186 static XColor color;
2187 char *val;
2188 int second_pass = 0;
2189
2190 GET_STRING_OR_DEFAULT("Color", val);
2191
2192 again:
2193 if (!wGetColor(scr, val, &color)) {
2194 wwarning(_("could not get color for key \"%s\""), entry->key);
2195 if (second_pass == 0) {
2196 val = WMGetFromPLString(entry->plvalue);
2197 second_pass = 1;
2198 wwarning(_("using default \"%s\" instead"), val);
2199 goto again;
2200 }
2201 return False;
2202 }
2203
2204 if (ret)
2205 *ret = &color;
2206
2207 assert(addr == NULL);
2208 /*
2209 if (addr)
2210 *(unsigned long*)addr = pixel;
2211 */
2212
2213 return True;
2214 }
2215
2216 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2217 {
2218 static WShortKey shortcut;
2219 KeySym ksym;
2220 char *val;
2221 char *k;
2222 char buf[MAX_SHORTCUT_LENGTH], *b;
2223
2224 GET_STRING_OR_DEFAULT("Key spec", val);
2225
2226 if (!val || strcasecmp(val, "NONE") == 0) {
2227 shortcut.keycode = 0;
2228 shortcut.modifier = 0;
2229 if (ret)
2230 *ret = &shortcut;
2231 return True;
2232 }
2233
2234 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2235
2236 b = (char *)buf;
2237
2238 /* get modifiers */
2239 shortcut.modifier = 0;
2240 while ((k = strchr(b, '+')) != NULL) {
2241 int mod;
2242
2243 *k = 0;
2244 mod = wXModifierFromKey(b);
2245 if (mod < 0) {
2246 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2247 return False;
2248 }
2249 shortcut.modifier |= mod;
2250
2251 b = k + 1;
2252 }
2253
2254 /* get key */
2255 ksym = XStringToKeysym(b);
2256
2257 if (ksym == NoSymbol) {
2258 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2259 return False;
2260 }
2261
2262 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2263 if (shortcut.keycode == 0) {
2264 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2265 return False;
2266 }
2267
2268 if (ret)
2269 *ret = &shortcut;
2270
2271 return True;
2272 }
2273
2274 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2275 {
2276 static int mask;
2277 char *str;
2278
2279 GET_STRING_OR_DEFAULT("Modifier Key", str);
2280
2281 if (!str)
2282 return False;
2283
2284 mask = wXModifierFromKey(str);
2285 if (mask < 0) {
2286 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2287 mask = 0;
2288 return False;
2289 }
2290
2291 if (addr)
2292 *(int *)addr = mask;
2293
2294 if (ret)
2295 *ret = &mask;
2296
2297 return True;
2298 }
2299
2300 #ifdef NEWSTUFF
2301 static int getRImages(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2302 {
2303 unsigned int mask;
2304 char *str;
2305 RImage *image;
2306 int i, n;
2307 int w, h;
2308
2309 GET_STRING_OR_DEFAULT("Image File Path", str);
2310 if (!str)
2311 return False;
2312
2313 image = RLoadImage(scr->rcontext, str, 0);
2314 if (!image) {
2315 wwarning(_("could not load image in option %s: %s"), entry->key, RMessageForError(RErrorCode));
2316 return False;
2317 }
2318
2319 if (*(RImage **) addr) {
2320 RReleaseImage(*(RImage **) addr);
2321 }
2322 if (addr)
2323 *(RImage **) addr = image;
2324
2325 assert(ret == NULL);
2326 /*
2327 if (ret)
2328 *(RImage**)ret = image;
2329 */
2330
2331 return True;
2332 }
2333 #endif
2334
2335 # include <X11/cursorfont.h>
2336 typedef struct {
2337 char *name;
2338 int id;
2339 } WCursorLookup;
2340
2341 #define CURSOR_ID_NONE (XC_num_glyphs)
2342
2343 static WCursorLookup cursor_table[] = {
2344 {"X_cursor", XC_X_cursor},
2345 {"arrow", XC_arrow},
2346 {"based_arrow_down", XC_based_arrow_down},
2347 {"based_arrow_up", XC_based_arrow_up},
2348 {"boat", XC_boat},
2349 {"bogosity", XC_bogosity},
2350 {"bottom_left_corner", XC_bottom_left_corner},
2351 {"bottom_right_corner", XC_bottom_right_corner},
2352 {"bottom_side", XC_bottom_side},
2353 {"bottom_tee", XC_bottom_tee},
2354 {"box_spiral", XC_box_spiral},
2355 {"center_ptr", XC_center_ptr},
2356 {"circle", XC_circle},
2357 {"clock", XC_clock},
2358 {"coffee_mug", XC_coffee_mug},
2359 {"cross", XC_cross},
2360 {"cross_reverse", XC_cross_reverse},
2361 {"crosshair", XC_crosshair},
2362 {"diamond_cross", XC_diamond_cross},
2363 {"dot", XC_dot},
2364 {"dotbox", XC_dotbox},
2365 {"double_arrow", XC_double_arrow},
2366 {"draft_large", XC_draft_large},
2367 {"draft_small", XC_draft_small},
2368 {"draped_box", XC_draped_box},
2369 {"exchange", XC_exchange},
2370 {"fleur", XC_fleur},
2371 {"gobbler", XC_gobbler},
2372 {"gumby", XC_gumby},
2373 {"hand1", XC_hand1},
2374 {"hand2", XC_hand2},
2375 {"heart", XC_heart},
2376 {"icon", XC_icon},
2377 {"iron_cross", XC_iron_cross},
2378 {"left_ptr", XC_left_ptr},
2379 {"left_side", XC_left_side},
2380 {"left_tee", XC_left_tee},
2381 {"leftbutton", XC_leftbutton},
2382 {"ll_angle", XC_ll_angle},
2383 {"lr_angle", XC_lr_angle},
2384 {"man", XC_man},
2385 {"middlebutton", XC_middlebutton},
2386 {"mouse", XC_mouse},
2387 {"pencil", XC_pencil},
2388 {"pirate", XC_pirate},
2389 {"plus", XC_plus},
2390 {"question_arrow", XC_question_arrow},
2391 {"right_ptr", XC_right_ptr},
2392 {"right_side", XC_right_side},
2393 {"right_tee", XC_right_tee},
2394 {"rightbutton", XC_rightbutton},
2395 {"rtl_logo", XC_rtl_logo},
2396 {"sailboat", XC_sailboat},
2397 {"sb_down_arrow", XC_sb_down_arrow},
2398 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2399 {"sb_left_arrow", XC_sb_left_arrow},
2400 {"sb_right_arrow", XC_sb_right_arrow},
2401 {"sb_up_arrow", XC_sb_up_arrow},
2402 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2403 {"shuttle", XC_shuttle},
2404 {"sizing", XC_sizing},
2405 {"spider", XC_spider},
2406 {"spraycan", XC_spraycan},
2407 {"star", XC_star},
2408 {"target", XC_target},
2409 {"tcross", XC_tcross},
2410 {"top_left_arrow", XC_top_left_arrow},
2411 {"top_left_corner", XC_top_left_corner},
2412 {"top_right_corner", XC_top_right_corner},
2413 {"top_side", XC_top_side},
2414 {"top_tee", XC_top_tee},
2415 {"trek", XC_trek},
2416 {"ul_angle", XC_ul_angle},
2417 {"umbrella", XC_umbrella},
2418 {"ur_angle", XC_ur_angle},
2419 {"watch", XC_watch},
2420 {"xterm", XC_xterm},
2421 {NULL, CURSOR_ID_NONE}
2422 };
2423
2424 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2425 {
2426 switch (status) {
2427 case BitmapOpenFailed:
2428 wwarning(_("failed to open bitmap file \"%s\""), filename);
2429 break;
2430 case BitmapFileInvalid:
2431 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2432 break;
2433 case BitmapNoMemory:
2434 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2435 break;
2436 case BitmapSuccess:
2437 XFreePixmap(dpy, bitmap);
2438 break;
2439 }
2440 }
2441
2442 /*
2443 * (none)
2444 * (builtin, <cursor_name>)
2445 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2446 */
2447 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2448 {
2449 WMPropList *elem;
2450 char *val;
2451 int nelem;
2452 int status = 0;
2453
2454 nelem = WMGetPropListItemCount(pl);
2455 if (nelem < 1) {
2456 return (status);
2457 }
2458 elem = WMGetFromPLArray(pl, 0);
2459 if (!elem || !WMIsPLString(elem)) {
2460 return (status);
2461 }
2462 val = WMGetFromPLString(elem);
2463
2464 if (0 == strcasecmp(val, "none")) {
2465 status = 1;
2466 *cursor = None;
2467 } else if (0 == strcasecmp(val, "builtin")) {
2468 int i;
2469 int cursor_id = CURSOR_ID_NONE;
2470
2471 if (2 != nelem) {
2472 wwarning(_("bad number of arguments in cursor specification"));
2473 return (status);
2474 }
2475 elem = WMGetFromPLArray(pl, 1);
2476 if (!elem || !WMIsPLString(elem)) {
2477 return (status);
2478 }
2479 val = WMGetFromPLString(elem);
2480
2481 for (i = 0; NULL != cursor_table[i].name; i++) {
2482 if (0 == strcasecmp(val, cursor_table[i].name)) {
2483 cursor_id = cursor_table[i].id;
2484 break;
2485 }
2486 }
2487 if (CURSOR_ID_NONE == cursor_id) {
2488 wwarning(_("unknown builtin cursor name \"%s\""), val);
2489 } else {
2490 *cursor = XCreateFontCursor(dpy, cursor_id);
2491 status = 1;
2492 }
2493 } else if (0 == strcasecmp(val, "bitmap")) {
2494 char *bitmap_name;
2495 char *mask_name;
2496 int bitmap_status;
2497 int mask_status;
2498 Pixmap bitmap;
2499 Pixmap mask;
2500 unsigned int w, h;
2501 int x, y;
2502 XColor fg, bg;
2503
2504 if (3 != nelem) {
2505 wwarning(_("bad number of arguments in cursor specification"));
2506 return (status);
2507 }
2508 elem = WMGetFromPLArray(pl, 1);
2509 if (!elem || !WMIsPLString(elem)) {
2510 return (status);
2511 }
2512 val = WMGetFromPLString(elem);
2513 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2514 if (!bitmap_name) {
2515 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2516 return (status);
2517 }
2518 elem = WMGetFromPLArray(pl, 2);
2519 if (!elem || !WMIsPLString(elem)) {
2520 wfree(bitmap_name);
2521 return (status);
2522 }
2523 val = WMGetFromPLString(elem);
2524 mask_name = FindImage(wPreferences.pixmap_path, val);
2525 if (!mask_name) {
2526 wfree(bitmap_name);
2527 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2528 return (status);
2529 }
2530 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2531 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2532 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2533 fg.pixel = scr->black_pixel;
2534 bg.pixel = scr->white_pixel;
2535 XQueryColor(dpy, scr->w_colormap, &fg);
2536 XQueryColor(dpy, scr->w_colormap, &bg);
2537 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2538 status = 1;
2539 }
2540 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2541 check_bitmap_status(mask_status, mask_name, mask);
2542 wfree(bitmap_name);
2543 wfree(mask_name);
2544 }
2545 return (status);
2546 }
2547
2548 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2549 {
2550 static Cursor cursor;
2551 int status;
2552 int changed = 0;
2553
2554 again:
2555 if (!WMIsPLArray(value)) {
2556 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2557 entry->key, "cursor specification");
2558 if (!changed) {
2559 value = entry->plvalue;
2560 changed = 1;
2561 wwarning(_("using default \"%s\" instead"), entry->default_value);
2562 goto again;
2563 }
2564 return (False);
2565 }
2566 status = parse_cursor(scr, value, &cursor);
2567 if (!status) {
2568 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2569 if (!changed) {
2570 value = entry->plvalue;
2571 changed = 1;
2572 wwarning(_("using default \"%s\" instead"), entry->default_value);
2573 goto again;
2574 }
2575 return (False);
2576 }
2577 if (ret) {
2578 *ret = &cursor;
2579 }
2580 if (addr) {
2581 *(Cursor *) addr = cursor;
2582 }
2583 return (True);
2584 }
2585
2586 #undef CURSOR_ID_NONE
2587
2588 /* ---------------- value setting functions --------------- */
2589 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2590 {
2591 return REFRESH_WINDOW_TITLE_COLOR;
2592 }
2593
2594 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2595 {
2596 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2597 }
2598
2599 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2600 {
2601 switch (which) {
2602 case WM_DOCK:
2603 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2604 break;
2605 case WM_CLIP:
2606 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2607 break;
2608 default:
2609 break;
2610 }
2611 return 0;
2612 }
2613
2614 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2615 {
2616 if (scr->workspaces) {
2617 wWorkspaceForceChange(scr, scr->current_workspace);
2618 wArrangeIcons(scr, False);
2619 }
2620 return 0;
2621 }
2622
2623 #if not_used
2624 static int setPositive(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2625 {
2626 if (*value <= 0)
2627 *(int *)foo = 1;
2628
2629 return 0;
2630 }
2631 #endif
2632
2633 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2634 {
2635 Pixmap pixmap;
2636 RImage *img;
2637 int reset = 0;
2638
2639 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2640 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2641 ? WREL_ICON : WREL_FLAT);
2642 if (!img) {
2643 wwarning(_("could not render texture for icon background"));
2644 if (!entry->addr)
2645 wTextureDestroy(scr, *texture);
2646 return 0;
2647 }
2648 RConvertImage(scr->rcontext, img, &pixmap);
2649
2650 if (scr->icon_tile) {
2651 reset = 1;
2652 RReleaseImage(scr->icon_tile);
2653 XFreePixmap(dpy, scr->icon_tile_pixmap);
2654 }
2655
2656 scr->icon_tile = img;
2657
2658 /* put the icon in the noticeboard hint */
2659 PropSetIconTileHint(scr, img);
2660
2661 if (!wPreferences.flags.noclip) {
2662 if (scr->clip_tile) {
2663 RReleaseImage(scr->clip_tile);
2664 }
2665 scr->clip_tile = wClipMakeTile(scr, img);
2666 }
2667
2668 scr->icon_tile_pixmap = pixmap;
2669
2670 if (scr->def_icon_pixmap) {
2671 XFreePixmap(dpy, scr->def_icon_pixmap);
2672 scr->def_icon_pixmap = None;
2673 }
2674 if (scr->def_ticon_pixmap) {
2675 XFreePixmap(dpy, scr->def_ticon_pixmap);
2676 scr->def_ticon_pixmap = None;
2677 }
2678
2679 if (scr->icon_back_texture) {
2680 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2681 }
2682 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2683
2684 if (scr->clip_balloon)
2685 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2686
2687 /*
2688 * Free the texture as nobody else will use it, nor refer to it.
2689 */
2690 if (!entry->addr)
2691 wTextureDestroy(scr, *texture);
2692
2693 return (reset ? REFRESH_ICON_TILE : 0);
2694 }
2695
2696 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2697 {
2698 if (scr->title_font) {
2699 WMReleaseFont(scr->title_font);
2700 }
2701 scr->title_font = font;
2702
2703 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2704 }
2705
2706 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2707 {
2708 if (scr->menu_title_font) {
2709 WMReleaseFont(scr->menu_title_font);
2710 }
2711
2712 scr->menu_title_font = font;
2713
2714 return REFRESH_MENU_TITLE_FONT;
2715 }
2716
2717 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2718 {
2719 if (scr->menu_entry_font) {
2720 WMReleaseFont(scr->menu_entry_font);
2721 }
2722 scr->menu_entry_font = font;
2723
2724 return REFRESH_MENU_FONT;
2725 }
2726
2727 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2728 {
2729 if (scr->icon_title_font) {
2730 WMReleaseFont(scr->icon_title_font);
2731 }
2732
2733 scr->icon_title_font = font;
2734
2735 return REFRESH_ICON_FONT;
2736 }
2737
2738 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2739 {
2740 if (scr->clip_title_font) {
2741 WMReleaseFont(scr->clip_title_font);
2742 }
2743
2744 scr->clip_title_font = font;
2745
2746 return REFRESH_ICON_FONT;
2747 }
2748
2749 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2750 {
2751 if (scr->workspace_name_font) {
2752 WMReleaseFont(scr->workspace_name_font);
2753 }
2754
2755 scr->workspace_name_font = font;
2756
2757 return 0;
2758 }
2759
2760 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2761 {
2762 if (scr->select_color)
2763 WMReleaseColor(scr->select_color);
2764
2765 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2766
2767 wFreeColor(scr, color->pixel);
2768
2769 return REFRESH_MENU_COLOR;
2770 }
2771
2772 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2773 {
2774 if (scr->select_text_color)
2775 WMReleaseColor(scr->select_text_color);
2776
2777 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2778
2779 wFreeColor(scr, color->pixel);
2780
2781 return REFRESH_MENU_COLOR;
2782 }
2783
2784 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2785 {
2786 if (scr->clip_title_color[widx])
2787 WMReleaseColor(scr->clip_title_color[widx]);
2788 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2789 #ifdef GRADIENT_CLIP_ARROW
2790 if (widx == CLIP_NORMAL) {
2791 RImage *image;
2792 RColor color1, color2;
2793 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2794 int as = pt - 15; /* 15 = 5+5+5 */
2795
2796 FREE_PIXMAP(scr->clip_arrow_gradient);
2797
2798 color1.red = (color->red >> 8) * 6 / 10;
2799 color1.green = (color->green >> 8) * 6 / 10;
2800 color1.blue = (color->blue >> 8) * 6 / 10;
2801
2802 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2803 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2804 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2805
2806 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2807 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2808 RReleaseImage(image);
2809 }
2810 #endif /* GRADIENT_CLIP_ARROW */
2811
2812 wFreeColor(scr, color->pixel);
2813
2814 return REFRESH_ICON_TITLE_COLOR;
2815 }
2816
2817 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2818 {
2819 if (scr->window_title_color[widx])
2820 WMReleaseColor(scr->window_title_color[widx]);
2821
2822 scr->window_title_color[widx] =
2823 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2824
2825 wFreeColor(scr, color->pixel);
2826
2827 return REFRESH_WINDOW_TITLE_COLOR;
2828 }
2829
2830 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2831 {
2832 if (scr->menu_title_color[0])
2833 WMReleaseColor(scr->menu_title_color[0]);
2834
2835 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2836
2837 wFreeColor(scr, color->pixel);
2838
2839 return REFRESH_MENU_TITLE_COLOR;
2840 }
2841
2842 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2843 {
2844 if (scr->mtext_color)
2845 WMReleaseColor(scr->mtext_color);
2846
2847 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2848
2849 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2850 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2851 } else {
2852 WMSetColorAlpha(scr->dtext_color, 0xffff);
2853 }
2854
2855 wFreeColor(scr, color->pixel);
2856
2857 return REFRESH_MENU_COLOR;
2858 }
2859
2860 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2861 {
2862 if (scr->dtext_color)
2863 WMReleaseColor(scr->dtext_color);
2864
2865 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2866
2867 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2868 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2869 } else {
2870 WMSetColorAlpha(scr->dtext_color, 0xffff);
2871 }
2872
2873 wFreeColor(scr, color->pixel);
2874
2875 return REFRESH_MENU_COLOR;
2876 }
2877
2878 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2879 {
2880 if (scr->icon_title_color)
2881 WMReleaseColor(scr->icon_title_color);
2882 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2883
2884 wFreeColor(scr, color->pixel);
2885
2886 return REFRESH_ICON_TITLE_COLOR;
2887 }
2888
2889 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2890 {
2891 if (scr->icon_title_texture) {
2892 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2893 }
2894 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2895
2896 return REFRESH_ICON_TITLE_BACK;
2897 }
2898
2899 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2900 {
2901 close(scr->helper_fd);
2902 scr->helper_fd = 0;
2903 scr->helper_pid = 0;
2904 scr->flags.backimage_helper_launched = 0;
2905 }
2906
2907 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2908 {
2909 WMPropList *val;
2910 char *str;
2911 int i;
2912
2913 if (scr->flags.backimage_helper_launched) {
2914 if (WMGetPropListItemCount(value) == 0) {
2915 SendHelperMessage(scr, 'C', 0, NULL);
2916 SendHelperMessage(scr, 'K', 0, NULL);
2917
2918 WMReleasePropList(value);
2919 return 0;
2920 }
2921 } else {
2922 pid_t pid;
2923 int filedes[2];
2924
2925 if (WMGetPropListItemCount(value) == 0)
2926 return 0;
2927
2928 if (pipe(filedes) < 0) {
2929 wsyserror("pipe() failed:can't set workspace specific background image");
2930
2931 WMReleasePropList(value);
2932 return 0;
2933 }
2934
2935 pid = fork();
2936 if (pid < 0) {
2937 wsyserror("fork() failed:can't set workspace specific background image");
2938 if (close(filedes[0]) < 0)
2939 wsyserror("could not close pipe");
2940 if (close(filedes[1]) < 0)
2941 wsyserror("could not close pipe");
2942
2943 } else if (pid == 0) {
2944 char *dither;
2945
2946 SetupEnvironment(scr);
2947
2948 if (close(0) < 0)
2949 wsyserror("could not close pipe");
2950 if (dup(filedes[0]) < 0) {
2951 wsyserror("dup() failed:can't set workspace specific background image");
2952 }
2953 dither = wPreferences.no_dithering ? "-m" : "-d";
2954 if (wPreferences.smooth_workspace_back)
2955 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2956 else
2957 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2958 wsyserror("could not execute wmsetbg");
2959 exit(1);
2960 } else {
2961
2962 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2963 wsyserror("error setting close-on-exec flag");
2964 }
2965 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2966 wsyserror("error setting close-on-exec flag");
2967 }
2968
2969 scr->helper_fd = filedes[1];
2970 scr->helper_pid = pid;
2971 scr->flags.backimage_helper_launched = 1;
2972
2973 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2974
2975 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2976 }
2977
2978 }
2979
2980 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2981 val = WMGetFromPLArray(value, i);
2982 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2983 str = WMGetPropListDescription(val, False);
2984
2985 SendHelperMessage(scr, 'S', i + 1, str);
2986
2987 wfree(str);
2988 } else {
2989 SendHelperMessage(scr, 'U', i + 1, NULL);
2990 }
2991 }
2992 sleep(1);
2993
2994 WMReleasePropList(value);
2995 return 0;
2996 }
2997
2998 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2999 {
3000 if (scr->flags.backimage_helper_launched) {
3001 char *str;
3002
3003 if (WMGetPropListItemCount(value) == 0) {
3004 SendHelperMessage(scr, 'U', 0, NULL);
3005 } else {
3006 /* set the default workspace background to this one */
3007 str = WMGetPropListDescription(value, False);
3008 if (str) {
3009 SendHelperMessage(scr, 'S', 0, str);
3010 wfree(str);
3011 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
3012 } else {
3013 SendHelperMessage(scr, 'U', 0, NULL);
3014 }
3015 }
3016 } else if (WMGetPropListItemCount(value) > 0) {
3017 char *command;
3018 char *text;
3019 char *dither;
3020 int len;
3021
3022 SetupEnvironment(scr);
3023 text = WMGetPropListDescription(value, False);
3024 len = strlen(text) + 40;
3025 command = wmalloc(len);
3026 dither = wPreferences.no_dithering ? "-m" : "-d";
3027 if (wPreferences.smooth_workspace_back)
3028 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3029 else
3030 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3031 wfree(text);
3032 system(command);
3033 wfree(command);
3034 }
3035 WMReleasePropList(value);
3036
3037 return 0;
3038 }
3039
3040 #ifdef VIRTUAL_DESKTOP
3041 static int setVirtualDeskEnable(WScreen * scr, WDefaultEntry * entry, void *foo, void *bar)
3042 {
3043 wWorkspaceUpdateEdge(scr);
3044 return 0;
3045 }
3046 #endif
3047
3048 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3049 {
3050 if (scr->widget_texture) {
3051 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3052 }
3053 scr->widget_texture = *(WTexSolid **) texture;
3054
3055 return 0;
3056 }
3057
3058 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3059 {
3060 if (scr->window_title_texture[WS_FOCUSED]) {
3061 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3062 }
3063 scr->window_title_texture[WS_FOCUSED] = *texture;
3064
3065 return REFRESH_WINDOW_TEXTURES;
3066 }
3067
3068 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3069 {
3070 if (scr->window_title_texture[WS_PFOCUSED]) {
3071 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3072 }
3073 scr->window_title_texture[WS_PFOCUSED] = *texture;
3074
3075 return REFRESH_WINDOW_TEXTURES;
3076 }
3077
3078 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3079 {
3080 if (scr->window_title_texture[WS_UNFOCUSED]) {
3081 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3082 }
3083 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3084
3085 return REFRESH_WINDOW_TEXTURES;
3086 }
3087
3088 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3089 {
3090 if (scr->resizebar_texture[0]) {
3091 wTextureDestroy(scr, scr->resizebar_texture[0]);
3092 }
3093 scr->resizebar_texture[0] = *texture;
3094
3095 return REFRESH_WINDOW_TEXTURES;
3096 }
3097
3098 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3099 {
3100 if (scr->menu_title_texture[0]) {
3101 wTextureDestroy(scr, scr->menu_title_texture[0]);
3102 }
3103 scr->menu_title_texture[0] = *texture;
3104
3105 return REFRESH_MENU_TITLE_TEXTURE;
3106 }
3107
3108 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3109 {
3110 if (scr->menu_item_texture) {
3111 wTextureDestroy(scr, scr->menu_item_texture);
3112 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3113 }
3114 scr->menu_item_texture = *texture;
3115
3116 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3117
3118 return REFRESH_MENU_TEXTURE;
3119 }
3120
3121 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
3122 {
3123 WWindow *wwin;
3124 wKeyBindings[widx] = *shortcut;
3125
3126 wwin = scr->focused_window;
3127
3128 while (wwin != NULL) {
3129 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3130
3131 if (!WFLAGP(wwin, no_bind_keys)) {
3132 wWindowSetKeyGrabs(wwin);
3133 }
3134 wwin = wwin->prev;
3135 }
3136
3137 return 0;
3138 }
3139
3140 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3141 {
3142 wScreenUpdateUsableArea(scr);
3143 wArrangeIcons(scr, True);
3144
3145 return 0;
3146 }
3147
3148 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3149 {
3150 wScreenUpdateUsableArea(scr);
3151
3152 return 0;
3153 }
3154
3155 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3156 {
3157 return REFRESH_MENU_TEXTURE;
3158 }
3159
3160 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3161 {
3162 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3163
3164 RCopyArea(img, image, x, y, w, h, 0, 0);
3165
3166 return img;
3167 }
3168
3169 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
3170 {
3171 char *path;
3172 RImage *bgimage;
3173 int cwidth, cheight;
3174 WPreferences *prefs = (WPreferences *) foo;
3175
3176 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3177 if (prefs->swtileImage)
3178 RReleaseImage(prefs->swtileImage);
3179 prefs->swtileImage = NULL;
3180
3181 WMReleasePropList(array);
3182 return 0;
3183 }
3184
3185 switch (WMGetPropListItemCount(array)) {
3186 case 4:
3187 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3188 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3189 break;
3190 } else
3191 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3192
3193 if (!path) {
3194 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3195 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3196 } else {
3197 bgimage = RLoadImage(scr->rcontext, path, 0);
3198 if (!bgimage) {
3199 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3200 wfree(path);
3201 } else {
3202 wfree(path);
3203
3204 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3205 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3206
3207 if (cwidth <= 0 || cheight <= 0 ||
3208 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3209 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3210 else {
3211 int i;
3212 int swidth, theight;
3213 for (i = 0; i < 9; i++) {
3214 if (prefs->swbackImage[i])
3215 RReleaseImage(prefs->swbackImage[i]);
3216 prefs->swbackImage[i] = NULL;
3217 }
3218 swidth = (bgimage->width - cwidth) / 2;
3219 theight = (bgimage->height - cheight) / 2;
3220
3221 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3222 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3223 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3224 swidth, theight);
3225
3226 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3227 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3228 cwidth, cheight);
3229 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3230 swidth, cheight);
3231
3232 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3233 swidth, theight);
3234 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3235 cwidth, theight);
3236 prefs->swbackImage[8] =
3237 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3238 theight);
3239
3240 // check if anything failed
3241 for (i = 0; i < 9; i++) {
3242 if (!prefs->swbackImage[i]) {
3243 for (; i >= 0; --i) {
3244 RReleaseImage(prefs->swbackImage[i]);
3245 prefs->swbackImage[i] = NULL;
3246 }
3247 break;
3248 }
3249 }
3250 }
3251 RReleaseImage(bgimage);
3252 }
3253 }
3254
3255 case 1:
3256 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3257 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3258 break;
3259 } else
3260 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3261
3262 if (!path) {
3263 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3264 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3265 } else {
3266 if (prefs->swtileImage)
3267 RReleaseImage(prefs->swtileImage);
3268
3269 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3270 if (!prefs->swtileImage) {
3271 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3272 }
3273 wfree(path);
3274 }
3275 break;
3276
3277 default:
3278 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3279 break;
3280 }
3281
3282 WMReleasePropList(array);
3283
3284 return 0;
3285 }
3286
3287 /*
3288 static int
3289 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3290 {
3291 return REFRESH_BUTTON_IMAGES;
3292 }
3293 */
3294
3295 /*
3296 * Very ugly kluge.
3297 * Need access to the double click variables, so that all widgets in
3298 * wmaker panels will have the same dbl-click values.
3299 * TODO: figure a better way of dealing with it.
3300 */
3301 #include <WINGs/WINGsP.h>
3302
3303 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3304 {
3305 extern _WINGsConfiguration WINGsConfiguration;
3306
3307 if (*value <= 0)
3308 *(int *)foo = 1;
3309
3310 WINGsConfiguration.doubleClickDelay = *value;
3311
3312 return 0;
3313 }
3314
3315 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3316 {
3317 if (wCursor[widx] != None) {
3318 XFreeCursor(dpy, wCursor[widx]);
3319 }
3320
3321 wCursor[widx] = *cursor;
3322
3323 if (widx == WCUR_ROOT && *cursor != None) {
3324 XDefineCursor(dpy, scr->root_win, *cursor);
3325 }
3326
3327 return 0;
3328 }