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