Change to the linux kernel coding style
[wmaker-crm.git] / src / defaults.c
blob1d4b107a4bd357d522a0190ad0f6d2a11fc48b7a
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 */
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifdef HAVE_DLFCN_H
40 # include <dlfcn.h>
41 #endif
43 #ifndef PATH_MAX
44 #define PATH_MAX DEFAULT_PATH_MAX
45 #endif
47 #include <X11/Xlib.h>
48 #include <X11/Xutil.h>
49 #include <X11/keysym.h>
51 #include <wraster.h>
53 #include "WindowMaker.h"
54 #include "wcore.h"
55 #include "framewin.h"
56 #include "window.h"
57 #include "texture.h"
58 #include "screen.h"
59 #include "resources.h"
60 #include "defaults.h"
61 #include "keybind.h"
62 #include "xmodifier.h"
63 #include "icon.h"
64 #include "funcs.h"
65 #include "actions.h"
66 #include "dock.h"
67 #include "workspace.h"
68 #include "properties.h"
70 #define MAX_SHORTCUT_LENGTH 32
72 /***** Global *****/
74 extern WDDomain *WDWindowMaker;
75 extern WDDomain *WDWindowAttributes;
76 extern WDDomain *WDRootMenu;
78 extern int wScreenCount;
80 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
81 extern Atom _XA_WINDOWMAKER_ICON_TILE;
83 /*
84 extern WMPropList *wDomainName;
85 extern WMPropList *wAttributeDomainName;
86 */
87 extern WPreferences wPreferences;
89 extern WShortKey wKeyBindings[WKBD_LAST];
91 typedef struct {
92 char *key;
93 char *default_value;
94 void *extra_data;
95 void *addr;
96 int (*convert) ();
97 int (*update) ();
98 WMPropList *plkey;
99 WMPropList *plvalue; /* default value */
100 } WDefaultEntry;
102 /* used to map strings to integers */
103 typedef struct {
104 char *string;
105 short value;
106 char is_alias;
107 } WOptionEnumeration;
109 /* type converters */
110 static int getBool();
111 static int getInt();
112 static int getCoord();
113 #if 0
114 /* this is not used yet */
115 static int getString();
116 #endif
117 static int getPathList();
118 static int getEnum();
119 static int getTexture();
120 static int getWSBackground();
121 static int getWSSpecificBackground();
122 static int getFont();
123 static int getColor();
124 static int getKeybind();
125 static int getModMask();
126 #ifdef NEWSTUFF
127 static int getRImage();
128 #endif
129 static int getPropList();
131 /* value setting functions */
132 static int setJustify();
133 static int setClearance();
134 static int setIfDockPresent();
135 static int setStickyIcons();
136 /*
137 static int setPositive();
138 */
139 static int setWidgetColor();
140 static int setIconTile();
141 static int setWinTitleFont();
142 static int setMenuTitleFont();
143 static int setMenuTextFont();
144 static int setIconTitleFont();
145 static int setIconTitleColor();
146 static int setIconTitleBack();
147 static int setLargeDisplayFont();
148 static int setWTitleColor();
149 static int setFTitleBack();
150 static int setPTitleBack();
151 static int setUTitleBack();
152 static int setResizebarBack();
153 static int setWorkspaceBack();
154 static int setWorkspaceSpecificBack();
155 #ifdef VIRTUAL_DESKTOP
156 static int setVirtualDeskEnable();
157 #endif
158 static int setMenuTitleColor();
159 static int setMenuTextColor();
160 static int setMenuDisabledColor();
161 static int setMenuTitleBack();
162 static int setMenuTextBack();
163 static int setHightlight();
164 static int setHightlightText();
165 static int setKeyGrab();
166 static int setDoubleClick();
167 static int setIconPosition();
169 static int setClipTitleFont();
170 static int setClipTitleColor();
172 static int setMenuStyle();
173 static int setSwPOptions();
174 static int updateUsableArea();
176 extern Cursor wCursor[WCUR_LAST];
177 static int getCursor();
178 static int setCursor();
180 /*
181 * Tables to convert strings to enumeration values.
182 * Values stored are char
183 */
185 /* WARNING: sum of length of all value strings must not exceed
186 * this value */
187 #define TOTAL_VALUES_LENGTH 80
189 #define REFRESH_WINDOW_TEXTURES (1<<0)
190 #define REFRESH_MENU_TEXTURE (1<<1)
191 #define REFRESH_MENU_FONT (1<<2)
192 #define REFRESH_MENU_COLOR (1<<3)
193 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
194 #define REFRESH_MENU_TITLE_FONT (1<<5)
195 #define REFRESH_MENU_TITLE_COLOR (1<<6)
196 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
197 #define REFRESH_WINDOW_FONT (1<<8)
198 #define REFRESH_ICON_TILE (1<<9)
199 #define REFRESH_ICON_FONT (1<<10)
200 #define REFRESH_WORKSPACE_BACK (1<<11)
202 #define REFRESH_BUTTON_IMAGES (1<<12)
204 #define REFRESH_ICON_TITLE_COLOR (1<<13)
205 #define REFRESH_ICON_TITLE_BACK (1<<14)
207 static WOptionEnumeration seFocusModes[] = {
208 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
209 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
210 {NULL, 0, 0}
211 };
213 static WOptionEnumeration seColormapModes[] = {
214 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
215 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
216 {NULL, 0, 0}
217 };
219 static WOptionEnumeration sePlacements[] = {
220 {"Auto", WPM_AUTO, 0},
221 {"Smart", WPM_SMART, 0},
222 {"Cascade", WPM_CASCADE, 0},
223 {"Random", WPM_RANDOM, 0},
224 {"Manual", WPM_MANUAL, 0},
225 {NULL, 0, 0}
226 };
228 static WOptionEnumeration seGeomDisplays[] = {
229 {"None", WDIS_NONE, 0},
230 {"Center", WDIS_CENTER, 0},
231 {"Corner", WDIS_TOPLEFT, 0},
232 {"Floating", WDIS_FRAME_CENTER, 0},
233 {"Line", WDIS_NEW, 0},
234 {NULL, 0, 0}
235 };
237 static WOptionEnumeration seSpeeds[] = {
238 {"UltraFast", SPEED_ULTRAFAST, 0},
239 {"Fast", SPEED_FAST, 0},
240 {"Medium", SPEED_MEDIUM, 0},
241 {"Slow", SPEED_SLOW, 0},
242 {"UltraSlow", SPEED_ULTRASLOW, 0},
243 {NULL, 0, 0}
244 };
246 static WOptionEnumeration seMouseButtonActions[] = {
247 {"None", WA_NONE, 0},
248 {"SelectWindows", WA_SELECT_WINDOWS, 0},
249 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
250 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
251 {NULL, 0, 0}
252 };
254 static WOptionEnumeration seMouseWheelActions[] = {
255 {"None", WA_NONE, 0},
256 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
257 {NULL, 0, 0}
258 };
260 static WOptionEnumeration seIconificationStyles[] = {
261 {"Zoom", WIS_ZOOM, 0},
262 {"Twist", WIS_TWIST, 0},
263 {"Flip", WIS_FLIP, 0},
264 {"None", WIS_NONE, 0},
265 {"random", WIS_RANDOM, 0},
266 {NULL, 0, 0}
267 };
269 static WOptionEnumeration seJustifications[] = {
270 {"Left", WTJ_LEFT, 0},
271 {"Center", WTJ_CENTER, 0},
272 {"Right", WTJ_RIGHT, 0},
273 {NULL, 0, 0}
274 };
276 static WOptionEnumeration seIconPositions[] = {
277 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
278 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
279 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
280 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
281 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
282 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
283 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
284 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
285 {NULL, 0, 0}
286 };
288 static WOptionEnumeration seMenuStyles[] = {
289 {"normal", MS_NORMAL, 0},
290 {"singletexture", MS_SINGLE_TEXTURE, 0},
291 {"flat", MS_FLAT, 0},
292 {NULL, 0, 0}
293 };
295 static WOptionEnumeration seDisplayPositions[] = {
296 {"none", WD_NONE, 0},
297 {"center", WD_CENTER, 0},
298 {"top", WD_TOP, 0},
299 {"bottom", WD_BOTTOM, 0},
300 {"topleft", WD_TOPLEFT, 0},
301 {"topright", WD_TOPRIGHT, 0},
302 {"bottomleft", WD_BOTTOMLEFT, 0},
303 {"bottomright", WD_BOTTOMRIGHT, 0},
304 {NULL, 0, 0}
305 };
307 static WOptionEnumeration seWorkspaceBorder[] = {
308 {"None", WB_NONE, 0},
309 {"LeftRight", WB_LEFTRIGHT, 0},
310 {"TopBottom", WB_TOPBOTTOM, 0},
311 {"AllDirections", WB_ALLDIRS, 0},
312 {NULL, 0, 0}
313 };
315 /*
316 * ALL entries in the tables bellow, NEED to have a default value
317 * defined, and this value needs to be correct.
318 */
320 /* these options will only affect the window manager on startup
322 * static defaults can't access the screen data, because it is
323 * created after these defaults are read
324 */
325 WDefaultEntry staticOptionList[] = {
327 {"ColormapSize", "4", NULL,
328 &wPreferences.cmap_size, getInt, NULL},
329 {"DisableDithering", "NO", NULL,
330 &wPreferences.no_dithering, getBool, NULL},
331 /* static by laziness */
332 {"IconSize", "64", NULL,
333 &wPreferences.icon_size, getInt, NULL},
334 {"ModifierKey", "Mod1", NULL,
335 &wPreferences.modifier_mask, getModMask, NULL},
336 {"DisableWSMouseActions", "NO", NULL,
337 &wPreferences.disable_root_mouse, getBool, NULL},
338 {"FocusMode", "manual", seFocusModes,
339 &wPreferences.focus_mode, getEnum, NULL}, /* have a problem when switching from manual to sloppy without restart */
340 {"NewStyle", "NO", NULL,
341 &wPreferences.new_style, getBool, NULL},
342 {"DisableDock", "NO", (void *)WM_DOCK,
343 NULL, getBool, setIfDockPresent},
344 {"DisableClip", "NO", (void *)WM_CLIP,
345 NULL, getBool, setIfDockPresent},
346 {"DisableMiniwindows", "NO", NULL,
347 &wPreferences.disable_miniwindows, getBool, NULL}
348 };
350 WDefaultEntry optionList[] = {
351 /* dynamic options */
352 {"IconPosition", "blh", seIconPositions,
353 &wPreferences.icon_yard, getEnum, setIconPosition},
354 {"IconificationStyle", "Zoom", seIconificationStyles,
355 &wPreferences.iconification_style, getEnum, NULL},
356 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
357 &wPreferences.mouse_button1, getEnum, NULL},
358 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
359 &wPreferences.mouse_button2, getEnum, NULL},
360 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
361 &wPreferences.mouse_button3, getEnum, NULL},
362 {"MouseWheelAction", "None", seMouseWheelActions,
363 &wPreferences.mouse_wheel, getEnum, NULL},
364 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
365 &wPreferences.pixmap_path, getPathList, NULL},
366 {"IconPath", DEF_ICON_PATHS, NULL,
367 &wPreferences.icon_path, getPathList, NULL},
368 {"ColormapMode", "auto", seColormapModes,
369 &wPreferences.colormap_mode, getEnum, NULL},
370 {"AutoFocus", "NO", NULL,
371 &wPreferences.auto_focus, getBool, NULL},
372 {"RaiseDelay", "0", NULL,
373 &wPreferences.raise_delay, getInt, NULL},
374 {"CirculateRaise", "NO", NULL,
375 &wPreferences.circ_raise, getBool, NULL},
376 {"Superfluous", "NO", NULL,
377 &wPreferences.superfluous, getBool, NULL},
378 {"AdvanceToNewWorkspace", "NO", NULL,
379 &wPreferences.ws_advance, getBool, NULL},
380 {"CycleWorkspaces", "NO", NULL,
381 &wPreferences.ws_cycle, getBool, NULL},
382 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
383 &wPreferences.workspace_name_display_position, getEnum, NULL},
384 {"WorkspaceBorder", "None", seWorkspaceBorder,
385 &wPreferences.workspace_border_position, getEnum, updateUsableArea},
386 {"WorkspaceBorderSize", "0", NULL,
387 &wPreferences.workspace_border_size, getInt, updateUsableArea},
388 #ifdef VIRTUAL_DESKTOP
389 {"EnableVirtualDesktop", "NO", NULL,
390 &wPreferences.vdesk_enable, getBool, setVirtualDeskEnable},
391 {"VirtualEdgeExtendSpace", "0", NULL,
392 &wPreferences.vedge_bordersize, getInt, NULL},
393 {"VirtualEdgeHorizonScrollSpeed", "30", NULL,
394 &wPreferences.vedge_hscrollspeed, getInt, NULL},
395 {"VirtualEdgeVerticalScrollSpeed", "30", NULL,
396 &wPreferences.vedge_vscrollspeed, getInt, NULL},
397 {"VirtualEdgeResistance", "30", NULL,
398 &wPreferences.vedge_resistance, getInt, NULL},
399 {"VirtualEdgeAttraction", "30", NULL,
400 &wPreferences.vedge_attraction, getInt, NULL},
401 {"VirtualEdgeLeftKey", "None", (void *)WKBD_VDESK_LEFT,
402 NULL, getKeybind, setKeyGrab},
403 {"VirtualEdgeRightKey", "None", (void *)WKBD_VDESK_RIGHT,
404 NULL, getKeybind, setKeyGrab},
405 {"VirtualEdgeUpKey", "None", (void *)WKBD_VDESK_UP,
406 NULL, getKeybind, setKeyGrab},
407 {"VirtualEdgeDownKey", "None", (void *)WKBD_VDESK_DOWN,
408 NULL, getKeybind, setKeyGrab},
409 #endif
410 {"StickyIcons", "NO", NULL,
411 &wPreferences.sticky_icons, getBool, setStickyIcons},
412 {"SaveSessionOnExit", "NO", NULL,
413 &wPreferences.save_session_on_exit, getBool, NULL},
414 {"WrapMenus", "NO", NULL,
415 &wPreferences.wrap_menus, getBool, NULL},
416 {"ScrollableMenus", "NO", NULL,
417 &wPreferences.scrollable_menus, getBool, NULL},
418 {"MenuScrollSpeed", "medium", seSpeeds,
419 &wPreferences.menu_scroll_speed, getEnum, NULL},
420 {"IconSlideSpeed", "medium", seSpeeds,
421 &wPreferences.icon_slide_speed, getEnum, NULL},
422 {"ShadeSpeed", "medium", seSpeeds,
423 &wPreferences.shade_speed, getEnum, NULL},
424 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
425 &wPreferences.dblclick_time, getInt, setDoubleClick,
426 },
427 {"AlignSubmenus", "NO", NULL,
428 &wPreferences.align_menus, getBool, NULL},
429 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
430 &wPreferences.open_transients_with_parent, getBool, NULL},
431 {"WindowPlacement", "auto", sePlacements,
432 &wPreferences.window_placement, getEnum, NULL},
433 {"IgnoreFocusClick", "NO", NULL,
434 &wPreferences.ignore_focus_click, getBool, NULL},
435 {"UseSaveUnders", "NO", NULL,
436 &wPreferences.use_saveunders, getBool, NULL},
437 {"OpaqueMove", "NO", NULL,
438 &wPreferences.opaque_move, getBool, NULL},
439 {"DisableSound", "NO", NULL,
440 &wPreferences.no_sound, getBool, NULL},
441 {"DisableAnimations", "NO", NULL,
442 &wPreferences.no_animations, getBool, NULL},
443 {"DontLinkWorkspaces", "NO", NULL,
444 &wPreferences.no_autowrap, getBool, NULL},
445 {"AutoArrangeIcons", "NO", NULL,
446 &wPreferences.auto_arrange_icons, getBool, NULL},
447 {"NoWindowOverDock", "NO", NULL,
448 &wPreferences.no_window_over_dock, getBool, updateUsableArea},
449 {"NoWindowOverIcons", "NO", NULL,
450 &wPreferences.no_window_over_icons, getBool, updateUsableArea},
451 {"WindowPlaceOrigin", "(0, 0)", NULL,
452 &wPreferences.window_place_origin, getCoord, NULL},
453 {"ResizeDisplay", "corner", seGeomDisplays,
454 &wPreferences.size_display, getEnum, NULL},
455 {"MoveDisplay", "corner", seGeomDisplays,
456 &wPreferences.move_display, getEnum, NULL},
457 {"DontConfirmKill", "NO", NULL,
458 &wPreferences.dont_confirm_kill, getBool, NULL},
459 {"WindowTitleBalloons", "NO", NULL,
460 &wPreferences.window_balloon, getBool, NULL},
461 {"MiniwindowTitleBalloons", "NO", NULL,
462 &wPreferences.miniwin_balloon, getBool, NULL},
463 {"AppIconBalloons", "NO", NULL,
464 &wPreferences.appicon_balloon, getBool, NULL},
465 {"HelpBalloons", "NO", NULL,
466 &wPreferences.help_balloon, getBool, NULL},
467 {"EdgeResistance", "30", NULL,
468 &wPreferences.edge_resistance, getInt, NULL},
469 {"Attraction", "NO", NULL,
470 &wPreferences.attract, getBool, NULL},
471 {"DisableBlinking", "NO", NULL,
472 &wPreferences.dont_blink, getBool, NULL},
473 /* style options */
474 {"MenuStyle", "normal", seMenuStyles,
475 &wPreferences.menu_style, getEnum, setMenuStyle},
476 {"WidgetColor", "(solid, gray)", NULL,
477 NULL, getTexture, setWidgetColor,
478 },
479 {"WorkspaceSpecificBack", "()", NULL,
480 NULL, getWSSpecificBackground, setWorkspaceSpecificBack},
481 /* WorkspaceBack must come after WorkspaceSpecificBack or
482 * WorkspaceBack wont know WorkspaceSpecificBack was also
483 * specified and 2 copies of wmsetbg will be launched */
484 {"WorkspaceBack", "(solid, black)", NULL,
485 NULL, getWSBackground, setWorkspaceBack},
486 {"SmoothWorkspaceBack", "NO", NULL,
487 NULL, getBool, NULL},
488 {"IconBack", "(solid, gray)", NULL,
489 NULL, getTexture, setIconTile},
490 {"TitleJustify", "center", seJustifications,
491 &wPreferences.title_justification, getEnum, setJustify},
492 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
493 NULL, getFont, setWinTitleFont,
494 },
495 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
496 &wPreferences.window_title_clearance, getInt, setClearance},
497 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
498 &wPreferences.menu_title_clearance, getInt, setClearance},
499 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
500 &wPreferences.menu_text_clearance, getInt, setClearance},
501 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
502 NULL, getFont, setMenuTitleFont},
503 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
504 NULL, getFont, setMenuTextFont},
505 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
506 NULL, getFont, setIconTitleFont},
507 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
508 NULL, getFont, setClipTitleFont},
509 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
510 NULL, getFont, setLargeDisplayFont},
511 {"HighlightColor", "white", NULL,
512 NULL, getColor, setHightlight},
513 {"HighlightTextColor", "black", NULL,
514 NULL, getColor, setHightlightText},
515 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
516 NULL, getColor, setClipTitleColor},
517 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
518 NULL, getColor, setClipTitleColor},
519 {"FTitleColor", "white", (void *)WS_FOCUSED,
520 NULL, getColor, setWTitleColor},
521 {"PTitleColor", "white", (void *)WS_PFOCUSED,
522 NULL, getColor, setWTitleColor},
523 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
524 NULL, getColor, setWTitleColor},
525 {"FTitleBack", "(solid, black)", NULL,
526 NULL, getTexture, setFTitleBack},
527 {"PTitleBack", "(solid, \"#616161\")", NULL,
528 NULL, getTexture, setPTitleBack},
529 {"UTitleBack", "(solid, gray)", NULL,
530 NULL, getTexture, setUTitleBack},
531 {"ResizebarBack", "(solid, gray)", NULL,
532 NULL, getTexture, setResizebarBack},
533 {"MenuTitleColor", "white", NULL,
534 NULL, getColor, setMenuTitleColor},
535 {"MenuTextColor", "black", NULL,
536 NULL, getColor, setMenuTextColor},
537 {"MenuDisabledColor", "\"#616161\"", NULL,
538 NULL, getColor, setMenuDisabledColor},
539 {"MenuTitleBack", "(solid, black)", NULL,
540 NULL, getTexture, setMenuTitleBack},
541 {"MenuTextBack", "(solid, gray)", NULL,
542 NULL, getTexture, setMenuTextBack},
543 {"IconTitleColor", "white", NULL,
544 NULL, getColor, setIconTitleColor},
545 {"IconTitleBack", "black", NULL,
546 NULL, getColor, setIconTitleBack},
547 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
548 NULL, getPropList, setSwPOptions},
549 /* keybindings */
550 #ifndef LITE
551 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
552 NULL, getKeybind, setKeyGrab},
553 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
554 NULL, getKeybind, setKeyGrab},
555 #endif /* LITE */
556 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
557 NULL, getKeybind, setKeyGrab},
558 {"ClipLowerKey", "None", (void *)WKBD_CLIPLOWER,
559 NULL, getKeybind, setKeyGrab},
560 {"ClipRaiseKey", "None", (void *)WKBD_CLIPRAISE,
561 NULL, getKeybind, setKeyGrab},
562 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
563 NULL, getKeybind, setKeyGrab},
564 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
565 NULL, getKeybind, setKeyGrab},
566 {"HideKey", "None", (void *)WKBD_HIDE,
567 NULL, getKeybind, setKeyGrab},
568 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
569 NULL, getKeybind, setKeyGrab},
570 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
571 NULL, getKeybind, setKeyGrab},
572 {"CloseKey", "None", (void *)WKBD_CLOSE,
573 NULL, getKeybind, setKeyGrab},
574 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
575 NULL, getKeybind, setKeyGrab},
576 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
577 NULL, getKeybind, setKeyGrab},
578 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
579 NULL, getKeybind, setKeyGrab},
580 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
581 NULL, getKeybind, setKeyGrab},
582 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
583 NULL, getKeybind, setKeyGrab},
584 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
585 NULL, getKeybind, setKeyGrab},
586 {"ShadeKey", "None", (void *)WKBD_SHADE,
587 NULL, getKeybind, setKeyGrab},
588 {"SelectKey", "None", (void *)WKBD_SELECT,
589 NULL, getKeybind, setKeyGrab},
590 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
591 NULL, getKeybind, setKeyGrab},
592 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
593 NULL, getKeybind, setKeyGrab},
594 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
595 NULL, getKeybind, setKeyGrab},
596 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
597 NULL, getKeybind, setKeyGrab},
598 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
599 NULL, getKeybind, setKeyGrab},
600 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
601 NULL, getKeybind, setKeyGrab},
602 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
603 NULL, getKeybind, setKeyGrab},
604 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
605 NULL, getKeybind, setKeyGrab},
606 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
607 NULL, getKeybind, setKeyGrab},
608 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
609 NULL, getKeybind, setKeyGrab},
610 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
611 NULL, getKeybind, setKeyGrab},
612 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
613 NULL, getKeybind, setKeyGrab},
614 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
615 NULL, getKeybind, setKeyGrab},
616 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
617 NULL, getKeybind, setKeyGrab},
618 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
619 NULL, getKeybind, setKeyGrab},
620 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
621 NULL, getKeybind, setKeyGrab},
622 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
623 NULL, getKeybind, setKeyGrab},
624 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
625 NULL, getKeybind, setKeyGrab},
626 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
627 NULL, getKeybind, setKeyGrab},
628 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
629 NULL, getKeybind, setKeyGrab}
630 , {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
631 NULL, getKeybind, setKeyGrab},
632 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
633 NULL, getKeybind, setKeyGrab},
634 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
635 NULL, getKeybind, setKeyGrab},
636 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
637 NULL, getKeybind, setKeyGrab},
638 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
639 NULL, getKeybind, setKeyGrab},
640 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
641 NULL, getKeybind, setKeyGrab},
642 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
643 NULL, getKeybind, setKeyGrab},
645 #ifdef KEEP_XKB_LOCK_STATUS
646 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
647 NULL, getKeybind, setKeyGrab},
648 {"KbdModeLock", "NO", NULL,
649 &wPreferences.modelock, getBool, NULL},
650 #endif /* KEEP_XKB_LOCK_STATUS */
652 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
653 NULL, getCursor, setCursor},
654 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
655 NULL, getCursor, setCursor},
656 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
657 NULL, getCursor, setCursor},
658 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
659 NULL, getCursor, setCursor},
660 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
661 (void *)WCUR_TOPLEFTRESIZE,
662 NULL, getCursor, setCursor},
663 {"TopRightResizeCursor", "(builtin, top_right_corner)",
664 (void *)WCUR_TOPRIGHTRESIZE,
665 NULL, getCursor, setCursor},
666 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
667 (void *)WCUR_BOTTOMLEFTRESIZE,
668 NULL, getCursor, setCursor},
669 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
670 (void *)WCUR_BOTTOMRIGHTRESIZE,
671 NULL, getCursor, setCursor},
672 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
673 (void *)WCUR_VERTICALRESIZE,
674 NULL, getCursor, setCursor},
675 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
676 (void *)WCUR_HORIZONRESIZE,
677 NULL, getCursor, setCursor},
678 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
679 NULL, getCursor, setCursor},
680 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
681 NULL, getCursor, setCursor},
682 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
683 NULL, getCursor, setCursor},
684 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
685 NULL, getCursor, setCursor}
686 };
688 #if 0
689 static void rereadDefaults(void);
690 #endif
692 #if 0
693 static void rereadDefaults(void)
695 /* must defer the update because accessing X data from a
696 * signal handler can mess up Xlib */
699 #endif
701 static void initDefaults()
703 unsigned int i;
704 WDefaultEntry *entry;
706 WMPLSetCaseSensitive(False);
708 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
709 entry = &optionList[i];
711 entry->plkey = WMCreatePLString(entry->key);
712 if (entry->default_value)
713 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
714 else
715 entry->plvalue = NULL;
718 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
719 entry = &staticOptionList[i];
721 entry->plkey = WMCreatePLString(entry->key);
722 if (entry->default_value)
723 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
724 else
725 entry->plvalue = NULL;
728 /*
729 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
730 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
732 PLRegister(wDomainName, rereadDefaults);
733 PLRegister(wAttributeDomainName, rereadDefaults);
734 */
737 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
739 WMPropList *globalDict = NULL;
740 char path[PATH_MAX];
741 struct stat stbuf;
743 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domainName);
744 if (stat(path, &stbuf) >= 0) {
745 globalDict = WMReadPropListFromFile(path);
746 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
747 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
748 WMReleasePropList(globalDict);
749 globalDict = NULL;
750 } else if (!globalDict) {
751 wwarning(_("could not load domain %s from global defaults database"), domainName);
755 return globalDict;
758 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
759 static void prependMenu(WMPropList * destarr, WMPropList * array)
761 WMPropList *item;
762 int i;
764 for (i = 0; i < WMGetPropListItemCount(array); i++) {
765 item = WMGetFromPLArray(array, i);
766 if (item)
767 WMInsertInPLArray(destarr, i + 1, item);
771 static void appendMenu(WMPropList * destarr, WMPropList * array)
773 WMPropList *item;
774 int i;
776 for (i = 0; i < WMGetPropListItemCount(array); i++) {
777 item = WMGetFromPLArray(array, i);
778 if (item)
779 WMAddToPLArray(destarr, item);
782 #endif
784 /* Fixup paths for cached pixmaps from .AppInfo to Library/WindowMaker/... */
785 static Bool fixupCachedPixmapsPaths(WMPropList * dict)
787 WMPropList *allApps, *app, *props, *iconkey, *icon, *newicon;
788 char *path, *fixedpath, *ptr, *search;
789 int i, len, slen;
790 Bool changed = False;
792 search = "/.AppInfo/WindowMaker/";
793 slen = strlen(search);
795 iconkey = WMCreatePLString("Icon");
796 allApps = WMGetPLDictionaryKeys(dict);
798 for (i = 0; i < WMGetPropListItemCount(allApps); i++) {
799 app = WMGetFromPLArray(allApps, i);
800 props = WMGetFromPLDictionary(dict, app);
801 if (!props)
802 continue;
803 icon = WMGetFromPLDictionary(props, iconkey);
804 if (icon && WMIsPLString(icon)) {
805 path = WMGetFromPLString(icon);
806 ptr = strstr(path, search);
807 if (ptr) {
808 changed = True;
809 len = (ptr - path);
810 fixedpath = wmalloc(strlen(path) + 32);
811 strncpy(fixedpath, path, len);
812 fixedpath[len] = 0;
813 strcat(fixedpath, "/Library/WindowMaker/CachedPixmaps/");
814 strcat(fixedpath, ptr + slen);
815 newicon = WMCreatePLString(fixedpath);
816 WMPutInPLDictionary(props, iconkey, newicon);
817 WMReleasePropList(newicon);
818 wfree(fixedpath);
823 WMReleasePropList(allApps);
824 WMReleasePropList(iconkey);
826 return changed;
829 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
831 WMPropList *menu = menuDomain->dictionary;
832 WMPropList *submenu;
834 if (!menu || !WMIsPLArray(menu))
835 return;
837 #ifdef GLOBAL_PREAMBLE_MENU_FILE
838 submenu = WMReadPropListFromFile(SYSCONFDIR "/WindowMaker/" GLOBAL_PREAMBLE_MENU_FILE);
840 if (submenu && !WMIsPLArray(submenu)) {
841 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
842 WMReleasePropList(submenu);
843 submenu = NULL;
845 if (submenu) {
846 prependMenu(menu, submenu);
847 WMReleasePropList(submenu);
849 #endif
851 #ifdef GLOBAL_EPILOGUE_MENU_FILE
852 submenu = WMReadPropListFromFile(SYSCONFDIR "/WindowMaker/" GLOBAL_EPILOGUE_MENU_FILE);
854 if (submenu && !WMIsPLArray(submenu)) {
855 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
856 WMReleasePropList(submenu);
857 submenu = NULL;
859 if (submenu) {
860 appendMenu(menu, submenu);
861 WMReleasePropList(submenu);
863 #endif
865 menuDomain->dictionary = menu;
868 #if 0
869 WMPropList *wDefaultsInit(int screen_number)
871 static int defaults_inited = 0;
872 WMPropList *dict;
874 if (!defaults_inited) {
875 initDefaults();
878 dict = PLGetDomain(wDomainName);
879 if (!dict) {
880 wwarning(_("could not read domain \"%s\" from defaults database"), WMGetFromPLString(wDomainName));
883 return dict;
885 #endif
887 void wDefaultsDestroyDomain(WDDomain * domain)
889 if (domain->dictionary)
890 WMReleasePropList(domain->dictionary);
891 wfree(domain->path);
892 wfree(domain);
895 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
897 WDDomain *db;
898 struct stat stbuf;
899 static int inited = 0;
900 char path[PATH_MAX];
901 char *the_path;
902 WMPropList *shared_dict = NULL;
904 if (!inited) {
905 inited = 1;
906 initDefaults();
909 db = wmalloc(sizeof(WDDomain));
910 memset(db, 0, sizeof(WDDomain));
911 db->domain_name = domain;
912 db->path = wdefaultspathfordomain(domain);
913 the_path = db->path;
915 if (the_path && stat(the_path, &stbuf) >= 0) {
916 db->dictionary = WMReadPropListFromFile(the_path);
917 if (db->dictionary) {
918 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
919 WMReleasePropList(db->dictionary);
920 db->dictionary = NULL;
921 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
923 if (strcmp(domain, "WMWindowAttributes") == 0 && db->dictionary) {
924 if (fixupCachedPixmapsPaths(db->dictionary)) {
925 WMWritePropListToFile(db->dictionary, db->path, True);
926 /* re-read the timestamp. if this fails take current time */
927 if (stat(db->path, &stbuf) < 0) {
928 stbuf.st_mtime = time(NULL);
932 db->timestamp = stbuf.st_mtime;
933 } else {
934 wwarning(_("could not load domain %s from user defaults database"), domain);
938 /* global system dictionary */
939 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
940 if (stat(path, &stbuf) >= 0) {
941 shared_dict = WMReadPropListFromFile(path);
942 if (shared_dict) {
943 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
944 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
945 domain, path);
946 WMReleasePropList(shared_dict);
947 shared_dict = NULL;
948 } else {
949 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
950 WMIsPLDictionary(db->dictionary)) {
951 WMMergePLDictionaries(shared_dict, db->dictionary, True);
952 WMReleasePropList(db->dictionary);
953 db->dictionary = shared_dict;
954 if (stbuf.st_mtime > db->timestamp)
955 db->timestamp = stbuf.st_mtime;
956 } else if (!db->dictionary) {
957 db->dictionary = shared_dict;
958 if (stbuf.st_mtime > db->timestamp)
959 db->timestamp = stbuf.st_mtime;
962 } else {
963 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
967 return db;
970 void wReadStaticDefaults(WMPropList * dict)
972 WMPropList *plvalue;
973 WDefaultEntry *entry;
974 unsigned int i;
975 void *tdata;
977 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
978 entry = &staticOptionList[i];
980 if (dict)
981 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
982 else
983 plvalue = NULL;
985 if (!plvalue) {
986 /* no default in the DB. Use builtin default */
987 plvalue = entry->plvalue;
990 if (plvalue) {
991 /* convert data */
992 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
993 if (entry->update) {
994 (*entry->update) (NULL, entry, tdata, entry->extra_data);
1000 void wDefaultsCheckDomains(void)
1002 WScreen *scr;
1003 struct stat stbuf;
1004 WMPropList *shared_dict = NULL;
1005 WMPropList *dict;
1006 int i;
1008 #ifdef HEARTBEAT
1009 puts("Checking domains...");
1010 #endif
1011 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1012 #ifdef HEARTBEAT
1013 puts("Checking WindowMaker domain");
1014 #endif
1015 WDWindowMaker->timestamp = stbuf.st_mtime;
1017 /* global dictionary */
1018 shared_dict = readGlobalDomain("WindowMaker", True);
1019 /* user dictionary */
1020 dict = WMReadPropListFromFile(WDWindowMaker->path);
1021 if (dict) {
1022 if (!WMIsPLDictionary(dict)) {
1023 WMReleasePropList(dict);
1024 dict = NULL;
1025 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1026 "WindowMaker", WDWindowMaker->path);
1027 } else {
1028 if (shared_dict) {
1029 WMMergePLDictionaries(shared_dict, dict, True);
1030 WMReleasePropList(dict);
1031 dict = shared_dict;
1032 shared_dict = NULL;
1034 for (i = 0; i < wScreenCount; i++) {
1035 scr = wScreenWithNumber(i);
1036 if (scr)
1037 wReadDefaults(scr, dict);
1039 if (WDWindowMaker->dictionary) {
1040 WMReleasePropList(WDWindowMaker->dictionary);
1042 WDWindowMaker->dictionary = dict;
1044 } else {
1045 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1047 if (shared_dict) {
1048 WMReleasePropList(shared_dict);
1052 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1053 #ifdef HEARTBEAT
1054 puts("Checking WMWindowAttributes domain");
1055 #endif
1056 /* global dictionary */
1057 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1058 /* user dictionary */
1059 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1060 if (dict) {
1061 if (!WMIsPLDictionary(dict)) {
1062 WMReleasePropList(dict);
1063 dict = NULL;
1064 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1065 "WMWindowAttributes", WDWindowAttributes->path);
1066 } else {
1067 if (shared_dict) {
1068 WMMergePLDictionaries(shared_dict, dict, True);
1069 WMReleasePropList(dict);
1070 dict = shared_dict;
1071 shared_dict = NULL;
1073 if (WDWindowAttributes->dictionary) {
1074 WMReleasePropList(WDWindowAttributes->dictionary);
1076 WDWindowAttributes->dictionary = dict;
1077 for (i = 0; i < wScreenCount; i++) {
1078 scr = wScreenWithNumber(i);
1079 if (scr) {
1080 RImage *image;
1082 wDefaultUpdateIcons(scr);
1084 /* Update the panel image if changed */
1085 /* Don't worry. If the image is the same these
1086 * functions will have no performance impact. */
1087 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1089 if (!image) {
1090 wwarning(_("could not load logo image for panels: %s"),
1091 RMessageForError(RErrorCode));
1092 } else {
1093 WMSetApplicationIconImage(scr->wmscreen, image);
1094 RReleaseImage(image);
1099 } else {
1100 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1102 WDWindowAttributes->timestamp = stbuf.st_mtime;
1103 if (shared_dict) {
1104 WMReleasePropList(shared_dict);
1107 #ifndef LITE
1108 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1109 dict = WMReadPropListFromFile(WDRootMenu->path);
1110 #ifdef HEARTBEAT
1111 puts("Checking WMRootMenu domain");
1112 #endif
1113 if (dict) {
1114 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1115 WMReleasePropList(dict);
1116 dict = NULL;
1117 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1118 "WMRootMenu", WDRootMenu->path);
1119 } else {
1120 if (WDRootMenu->dictionary) {
1121 WMReleasePropList(WDRootMenu->dictionary);
1123 WDRootMenu->dictionary = dict;
1124 wDefaultsMergeGlobalMenus(WDRootMenu);
1126 } else {
1127 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1129 WDRootMenu->timestamp = stbuf.st_mtime;
1131 #endif /* !LITE */
1135 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1137 WMPropList *plvalue, *old_value;
1138 WDefaultEntry *entry;
1139 unsigned int i, must_update;
1140 int update_workspace_back = 0; /* kluge :/ */
1141 unsigned int needs_refresh;
1142 void *tdata;
1143 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1145 must_update = 0;
1147 needs_refresh = 0;
1149 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1150 entry = &optionList[i];
1152 if (new_dict)
1153 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1154 else
1155 plvalue = NULL;
1157 if (!old_dict)
1158 old_value = NULL;
1159 else
1160 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1162 if (!plvalue && !old_value) {
1163 /* no default in the DB. Use builtin default */
1164 plvalue = entry->plvalue;
1165 if (plvalue && new_dict) {
1166 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1167 must_update = 1;
1169 } else if (!plvalue) {
1170 /* value was deleted from DB. Keep current value */
1171 continue;
1172 } else if (!old_value) {
1173 /* set value for the 1st time */
1174 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1175 /* value has changed */
1176 } else {
1178 if (strcmp(entry->key, "WorkspaceBack") == 0
1179 && update_workspace_back && scr->flags.backimage_helper_launched) {
1180 } else {
1181 /* value was not changed since last time */
1182 continue;
1186 if (plvalue) {
1187 #ifdef DEBUG
1188 printf("Updating %s to %s\n", entry->key, WMGetPropListDescription(plvalue, False));
1189 #endif
1190 /* convert data */
1191 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1192 /*
1193 * If the WorkspaceSpecificBack data has been changed
1194 * so that the helper will be launched now, we must be
1195 * sure to send the default background texture config
1196 * to the helper.
1197 */
1198 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1199 && !scr->flags.backimage_helper_launched) {
1200 update_workspace_back = 1;
1202 if (entry->update) {
1203 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1209 if (needs_refresh != 0 && !scr->flags.startup) {
1210 int foo;
1212 foo = 0;
1213 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1214 foo |= WTextureSettings;
1215 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1216 foo |= WFontSettings;
1217 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1218 foo |= WColorSettings;
1219 if (foo)
1220 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1221 (void *)(uintptr_t) foo);
1223 foo = 0;
1224 if (needs_refresh & REFRESH_MENU_TEXTURE)
1225 foo |= WTextureSettings;
1226 if (needs_refresh & REFRESH_MENU_FONT)
1227 foo |= WFontSettings;
1228 if (needs_refresh & REFRESH_MENU_COLOR)
1229 foo |= WColorSettings;
1230 if (foo)
1231 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1233 foo = 0;
1234 if (needs_refresh & REFRESH_WINDOW_FONT) {
1235 foo |= WFontSettings;
1237 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1238 foo |= WTextureSettings;
1240 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1241 foo |= WColorSettings;
1243 if (foo)
1244 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1246 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1247 foo = 0;
1248 if (needs_refresh & REFRESH_ICON_FONT) {
1249 foo |= WFontSettings;
1251 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1252 foo |= WTextureSettings;
1254 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1255 foo |= WTextureSettings;
1257 if (foo)
1258 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1259 (void *)(uintptr_t) foo);
1261 if (needs_refresh & REFRESH_ICON_TILE)
1262 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1266 void wDefaultUpdateIcons(WScreen * scr)
1268 WAppIcon *aicon = scr->app_icon_list;
1269 WWindow *wwin = scr->focused_window;
1270 char *file;
1272 while (aicon) {
1273 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1274 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1275 || (file && !aicon->icon->file)) {
1276 RImage *new_image;
1278 if (aicon->icon->file)
1279 wfree(aicon->icon->file);
1280 aicon->icon->file = wstrdup(file);
1282 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1283 if (new_image) {
1284 wIconChangeImage(aicon->icon, new_image);
1285 wAppIconPaint(aicon);
1288 aicon = aicon->next;
1291 if (!wPreferences.flags.noclip)
1292 wClipIconPaint(scr->clip_icon);
1294 while (wwin) {
1295 if (wwin->icon && wwin->flags.miniaturized) {
1296 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1297 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1298 || (file && !wwin->icon->file)) {
1299 RImage *new_image;
1301 if (wwin->icon->file)
1302 wfree(wwin->icon->file);
1303 wwin->icon->file = wstrdup(file);
1305 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1306 if (new_image)
1307 wIconChangeImage(wwin->icon, new_image);
1310 wwin = wwin->prev;
1314 /* --------------------------- Local ----------------------- */
1316 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1317 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1318 entry->key, x); \
1319 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1320 var = entry->default_value;\
1321 } else var = WMGetFromPLString(value)\
1324 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1326 char *str;
1327 WOptionEnumeration *v;
1328 char buffer[TOTAL_VALUES_LENGTH];
1330 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1331 for (v = values; v->string != NULL; v++) {
1332 if (strcasecmp(v->string, str) == 0)
1333 return v->value;
1337 buffer[0] = 0;
1338 for (v = values; v->string != NULL; v++) {
1339 if (!v->is_alias) {
1340 if (buffer[0] != 0)
1341 strcat(buffer, ", ");
1342 strcat(buffer, v->string);
1345 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1347 if (def) {
1348 return string2index(key, val, NULL, values);
1351 return -1;
1354 /*
1355 * value - is the value in the defaults DB
1356 * addr - is the address to store the data
1357 * ret - is the address to store a pointer to a temporary buffer. ret
1358 * must not be freed and is used by the set functions
1359 */
1360 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1362 static char data;
1363 char *val;
1364 int second_pass = 0;
1366 GET_STRING_OR_DEFAULT("Boolean", val);
1368 again:
1369 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1370 || strcasecmp(val, "YES") == 0) {
1372 data = 1;
1373 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1374 || strcasecmp(val, "NO") == 0) {
1375 data = 0;
1376 } else {
1377 int i;
1378 if (sscanf(val, "%i", &i) == 1) {
1379 if (i != 0)
1380 data = 1;
1381 else
1382 data = 0;
1383 } else {
1384 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1385 if (second_pass == 0) {
1386 val = WMGetFromPLString(entry->plvalue);
1387 second_pass = 1;
1388 wwarning(_("using default \"%s\" instead"), val);
1389 goto again;
1391 return False;
1395 if (ret)
1396 *ret = &data;
1397 if (addr)
1398 *(char *)addr = data;
1400 return True;
1403 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1405 static int data;
1406 char *val;
1408 GET_STRING_OR_DEFAULT("Integer", val);
1410 if (sscanf(val, "%i", &data) != 1) {
1411 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1412 val = WMGetFromPLString(entry->plvalue);
1413 wwarning(_("using default \"%s\" instead"), val);
1414 if (sscanf(val, "%i", &data) != 1) {
1415 return False;
1419 if (ret)
1420 *ret = &data;
1421 if (addr)
1422 *(int *)addr = data;
1424 return True;
1427 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1429 static WCoord data;
1430 char *val_x, *val_y;
1431 int nelem, changed = 0;
1432 WMPropList *elem_x, *elem_y;
1434 again:
1435 if (!WMIsPLArray(value)) {
1436 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1437 if (changed == 0) {
1438 value = entry->plvalue;
1439 changed = 1;
1440 wwarning(_("using default \"%s\" instead"), entry->default_value);
1441 goto again;
1443 return False;
1446 nelem = WMGetPropListItemCount(value);
1447 if (nelem != 2) {
1448 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1449 if (changed == 0) {
1450 value = entry->plvalue;
1451 changed = 1;
1452 wwarning(_("using default \"%s\" instead"), entry->default_value);
1453 goto again;
1455 return False;
1458 elem_x = WMGetFromPLArray(value, 0);
1459 elem_y = WMGetFromPLArray(value, 1);
1461 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1462 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1463 if (changed == 0) {
1464 value = entry->plvalue;
1465 changed = 1;
1466 wwarning(_("using default \"%s\" instead"), entry->default_value);
1467 goto again;
1469 return False;
1472 val_x = WMGetFromPLString(elem_x);
1473 val_y = WMGetFromPLString(elem_y);
1475 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1476 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1477 if (changed == 0) {
1478 value = entry->plvalue;
1479 changed = 1;
1480 wwarning(_("using default \"%s\" instead"), entry->default_value);
1481 goto again;
1483 return False;
1486 if (data.x < 0)
1487 data.x = 0;
1488 else if (data.x > scr->scr_width / 3)
1489 data.x = scr->scr_width / 3;
1490 if (data.y < 0)
1491 data.y = 0;
1492 else if (data.y > scr->scr_height / 3)
1493 data.y = scr->scr_height / 3;
1495 if (ret)
1496 *ret = &data;
1497 if (addr)
1498 *(WCoord *) addr = data;
1500 return True;
1503 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1505 WMRetainPropList(value);
1507 *ret = value;
1509 return True;
1512 #if 0
1513 /* This function is not used at the moment. */
1514 static int getString(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1516 static char *data;
1518 GET_STRING_OR_DEFAULT("String", data);
1520 if (!data) {
1521 data = WMGetFromPLString(entry->plvalue);
1522 if (!data)
1523 return False;
1526 if (ret)
1527 *ret = &data;
1528 if (addr)
1529 *(char **)addr = wstrdup(data);
1531 return True;
1533 #endif
1535 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1537 static char *data;
1538 int i, count, len;
1539 char *ptr;
1540 WMPropList *d;
1541 int changed = 0;
1543 again:
1544 if (!WMIsPLArray(value)) {
1545 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1546 if (changed == 0) {
1547 value = entry->plvalue;
1548 changed = 1;
1549 wwarning(_("using default \"%s\" instead"), entry->default_value);
1550 goto again;
1552 return False;
1555 i = 0;
1556 count = WMGetPropListItemCount(value);
1557 if (count < 1) {
1558 if (changed == 0) {
1559 value = entry->plvalue;
1560 changed = 1;
1561 wwarning(_("using default \"%s\" instead"), entry->default_value);
1562 goto again;
1564 return False;
1567 len = 0;
1568 for (i = 0; i < count; i++) {
1569 d = WMGetFromPLArray(value, i);
1570 if (!d || !WMIsPLString(d)) {
1571 count = i;
1572 break;
1574 len += strlen(WMGetFromPLString(d)) + 1;
1577 ptr = data = wmalloc(len + 1);
1579 for (i = 0; i < count; i++) {
1580 d = WMGetFromPLArray(value, i);
1581 if (!d || !WMIsPLString(d)) {
1582 break;
1584 strcpy(ptr, WMGetFromPLString(d));
1585 ptr += strlen(WMGetFromPLString(d));
1586 *ptr = ':';
1587 ptr++;
1589 ptr--;
1590 *(ptr--) = 0;
1592 if (*(char **)addr != NULL) {
1593 wfree(*(char **)addr);
1595 *(char **)addr = data;
1597 return True;
1600 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1602 static signed char data;
1604 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1605 if (data < 0)
1606 return False;
1608 if (ret)
1609 *ret = &data;
1610 if (addr)
1611 *(signed char *)addr = data;
1613 return True;
1616 /*
1617 * (solid <color>)
1618 * (hgradient <color> <color>)
1619 * (vgradient <color> <color>)
1620 * (dgradient <color> <color>)
1621 * (mhgradient <color> <color> ...)
1622 * (mvgradient <color> <color> ...)
1623 * (mdgradient <color> <color> ...)
1624 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1625 * (tpixmap <file> <color>)
1626 * (spixmap <file> <color>)
1627 * (cpixmap <file> <color>)
1628 * (thgradient <file> <opaqueness> <color> <color>)
1629 * (tvgradient <file> <opaqueness> <color> <color>)
1630 * (tdgradient <file> <opaqueness> <color> <color>)
1631 * (function <lib> <function> ...)
1632 */
1634 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1636 WMPropList *elem;
1637 char *val;
1638 int nelem;
1639 WTexture *texture = NULL;
1641 nelem = WMGetPropListItemCount(pl);
1642 if (nelem < 1)
1643 return NULL;
1645 elem = WMGetFromPLArray(pl, 0);
1646 if (!elem || !WMIsPLString(elem))
1647 return NULL;
1648 val = WMGetFromPLString(elem);
1650 if (strcasecmp(val, "solid") == 0) {
1651 XColor color;
1653 if (nelem != 2)
1654 return NULL;
1656 /* get color */
1658 elem = WMGetFromPLArray(pl, 1);
1659 if (!elem || !WMIsPLString(elem))
1660 return NULL;
1661 val = WMGetFromPLString(elem);
1663 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1664 wwarning(_("\"%s\" is not a valid color name"), val);
1665 return NULL;
1668 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1669 } else if (strcasecmp(val, "dgradient") == 0
1670 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1671 RColor color1, color2;
1672 XColor xcolor;
1673 int type;
1675 if (nelem != 3) {
1676 wwarning(_("bad number of arguments in gradient specification"));
1677 return NULL;
1680 if (val[0] == 'd' || val[0] == 'D')
1681 type = WTEX_DGRADIENT;
1682 else if (val[0] == 'h' || val[0] == 'H')
1683 type = WTEX_HGRADIENT;
1684 else
1685 type = WTEX_VGRADIENT;
1687 /* get from color */
1688 elem = WMGetFromPLArray(pl, 1);
1689 if (!elem || !WMIsPLString(elem))
1690 return NULL;
1691 val = WMGetFromPLString(elem);
1693 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1694 wwarning(_("\"%s\" is not a valid color name"), val);
1695 return NULL;
1697 color1.alpha = 255;
1698 color1.red = xcolor.red >> 8;
1699 color1.green = xcolor.green >> 8;
1700 color1.blue = xcolor.blue >> 8;
1702 /* get to color */
1703 elem = WMGetFromPLArray(pl, 2);
1704 if (!elem || !WMIsPLString(elem)) {
1705 return NULL;
1707 val = WMGetFromPLString(elem);
1709 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1710 wwarning(_("\"%s\" is not a valid color name"), val);
1711 return NULL;
1713 color2.alpha = 255;
1714 color2.red = xcolor.red >> 8;
1715 color2.green = xcolor.green >> 8;
1716 color2.blue = xcolor.blue >> 8;
1718 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1720 } else if (strcasecmp(val, "igradient") == 0) {
1721 RColor colors1[2], colors2[2];
1722 int th1, th2;
1723 XColor xcolor;
1724 int i;
1726 if (nelem != 7) {
1727 wwarning(_("bad number of arguments in gradient specification"));
1728 return NULL;
1731 /* get from color */
1732 for (i = 0; i < 2; i++) {
1733 elem = WMGetFromPLArray(pl, 1 + i);
1734 if (!elem || !WMIsPLString(elem))
1735 return NULL;
1736 val = WMGetFromPLString(elem);
1738 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1739 wwarning(_("\"%s\" is not a valid color name"), val);
1740 return NULL;
1742 colors1[i].alpha = 255;
1743 colors1[i].red = xcolor.red >> 8;
1744 colors1[i].green = xcolor.green >> 8;
1745 colors1[i].blue = xcolor.blue >> 8;
1747 elem = WMGetFromPLArray(pl, 3);
1748 if (!elem || !WMIsPLString(elem))
1749 return NULL;
1750 val = WMGetFromPLString(elem);
1751 th1 = atoi(val);
1753 /* get from color */
1754 for (i = 0; i < 2; i++) {
1755 elem = WMGetFromPLArray(pl, 4 + i);
1756 if (!elem || !WMIsPLString(elem))
1757 return NULL;
1758 val = WMGetFromPLString(elem);
1760 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1761 wwarning(_("\"%s\" is not a valid color name"), val);
1762 return NULL;
1764 colors2[i].alpha = 255;
1765 colors2[i].red = xcolor.red >> 8;
1766 colors2[i].green = xcolor.green >> 8;
1767 colors2[i].blue = xcolor.blue >> 8;
1769 elem = WMGetFromPLArray(pl, 6);
1770 if (!elem || !WMIsPLString(elem))
1771 return NULL;
1772 val = WMGetFromPLString(elem);
1773 th2 = atoi(val);
1775 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1777 } else if (strcasecmp(val, "mhgradient") == 0
1778 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1779 XColor color;
1780 RColor **colors;
1781 int i, count;
1782 int type;
1784 if (nelem < 3) {
1785 wwarning(_("too few arguments in multicolor gradient specification"));
1786 return NULL;
1789 if (val[1] == 'h' || val[1] == 'H')
1790 type = WTEX_MHGRADIENT;
1791 else if (val[1] == 'v' || val[1] == 'V')
1792 type = WTEX_MVGRADIENT;
1793 else
1794 type = WTEX_MDGRADIENT;
1796 count = nelem - 1;
1798 colors = wmalloc(sizeof(RColor *) * (count + 1));
1800 for (i = 0; i < count; i++) {
1801 elem = WMGetFromPLArray(pl, i + 1);
1802 if (!elem || !WMIsPLString(elem)) {
1803 for (--i; i >= 0; --i) {
1804 wfree(colors[i]);
1806 wfree(colors);
1807 return NULL;
1809 val = WMGetFromPLString(elem);
1811 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1812 wwarning(_("\"%s\" is not a valid color name"), val);
1813 for (--i; i >= 0; --i) {
1814 wfree(colors[i]);
1816 wfree(colors);
1817 return NULL;
1818 } else {
1819 colors[i] = wmalloc(sizeof(RColor));
1820 colors[i]->red = color.red >> 8;
1821 colors[i]->green = color.green >> 8;
1822 colors[i]->blue = color.blue >> 8;
1825 colors[i] = NULL;
1827 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1828 } else if (strcasecmp(val, "spixmap") == 0 ||
1829 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1830 XColor color;
1831 int type;
1833 if (nelem != 3)
1834 return NULL;
1836 if (val[0] == 's' || val[0] == 'S')
1837 type = WTP_SCALE;
1838 else if (val[0] == 'c' || val[0] == 'C')
1839 type = WTP_CENTER;
1840 else
1841 type = WTP_TILE;
1843 /* get color */
1844 elem = WMGetFromPLArray(pl, 2);
1845 if (!elem || !WMIsPLString(elem)) {
1846 return NULL;
1848 val = WMGetFromPLString(elem);
1850 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1851 wwarning(_("\"%s\" is not a valid color name"), val);
1852 return NULL;
1855 /* file name */
1856 elem = WMGetFromPLArray(pl, 1);
1857 if (!elem || !WMIsPLString(elem))
1858 return NULL;
1859 val = WMGetFromPLString(elem);
1861 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1862 } else if (strcasecmp(val, "thgradient") == 0
1863 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1864 RColor color1, color2;
1865 XColor xcolor;
1866 int opacity;
1867 int style;
1869 if (val[1] == 'h' || val[1] == 'H')
1870 style = WTEX_THGRADIENT;
1871 else if (val[1] == 'v' || val[1] == 'V')
1872 style = WTEX_TVGRADIENT;
1873 else
1874 style = WTEX_TDGRADIENT;
1876 if (nelem != 5) {
1877 wwarning(_("bad number of arguments in textured gradient specification"));
1878 return NULL;
1881 /* get from color */
1882 elem = WMGetFromPLArray(pl, 3);
1883 if (!elem || !WMIsPLString(elem))
1884 return NULL;
1885 val = WMGetFromPLString(elem);
1887 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1888 wwarning(_("\"%s\" is not a valid color name"), val);
1889 return NULL;
1891 color1.alpha = 255;
1892 color1.red = xcolor.red >> 8;
1893 color1.green = xcolor.green >> 8;
1894 color1.blue = xcolor.blue >> 8;
1896 /* get to color */
1897 elem = WMGetFromPLArray(pl, 4);
1898 if (!elem || !WMIsPLString(elem)) {
1899 return NULL;
1901 val = WMGetFromPLString(elem);
1903 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1904 wwarning(_("\"%s\" is not a valid color name"), val);
1905 return NULL;
1907 color2.alpha = 255;
1908 color2.red = xcolor.red >> 8;
1909 color2.green = xcolor.green >> 8;
1910 color2.blue = xcolor.blue >> 8;
1912 /* get opacity */
1913 elem = WMGetFromPLArray(pl, 2);
1914 if (!elem || !WMIsPLString(elem))
1915 opacity = 128;
1916 else
1917 val = WMGetFromPLString(elem);
1919 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1920 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1921 opacity = 128;
1924 /* get file name */
1925 elem = WMGetFromPLArray(pl, 1);
1926 if (!elem || !WMIsPLString(elem))
1927 return NULL;
1928 val = WMGetFromPLString(elem);
1930 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1932 #ifdef TEXTURE_PLUGIN
1933 else if (strcasecmp(val, "function") == 0) {
1934 WTexFunction *function;
1935 void (*initFunc) (Display *, Colormap);
1936 char *lib, *func, **argv;
1937 int i, argc;
1939 if (nelem < 3)
1940 return NULL;
1942 /* get the library name */
1943 elem = WMGetFromPLArray(pl, 1);
1944 if (!elem || !WMIsPLString(elem)) {
1945 return NULL;
1947 lib = WMGetFromPLString(elem);
1949 /* get the function name */
1950 elem = WMGetFromPLArray(pl, 2);
1951 if (!elem || !WMIsPLString(elem)) {
1952 return NULL;
1954 func = WMGetFromPLString(elem);
1956 argc = nelem - 2;
1957 argv = (char **)wmalloc(argc * sizeof(char *));
1959 /* get the parameters */
1960 argv[0] = wstrdup(func);
1961 for (i = 0; i < argc - 1; i++) {
1962 elem = WMGetFromPLArray(pl, 3 + i);
1963 if (!elem || !WMIsPLString(elem)) {
1964 wfree(argv);
1966 return NULL;
1968 argv[i + 1] = wstrdup(WMGetFromPLString(elem));
1971 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1973 #ifdef HAVE_DLFCN_H
1974 if (function) {
1975 initFunc = dlsym(function->handle, "initWindowMaker");
1976 if (initFunc) {
1977 initFunc(dpy, scr->w_colormap);
1978 } else {
1979 wwarning(_("could not initialize library %s"), lib);
1981 } else {
1982 wwarning(_("could not find function %s::%s"), lib, func);
1984 #endif /* HAVE_DLFCN_H */
1985 texture = (WTexture *) function;
1987 #endif /* TEXTURE_PLUGIN */
1988 else {
1989 wwarning(_("invalid texture type %s"), val);
1990 return NULL;
1992 return texture;
1995 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1997 static WTexture *texture;
1998 int changed = 0;
2000 again:
2001 if (!WMIsPLArray(value)) {
2002 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
2003 if (changed == 0) {
2004 value = entry->plvalue;
2005 changed = 1;
2006 wwarning(_("using default \"%s\" instead"), entry->default_value);
2007 goto again;
2009 return False;
2012 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
2013 WMPropList *pl;
2015 pl = WMGetFromPLArray(value, 0);
2016 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2017 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
2018 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2019 entry->key, "Solid Texture");
2021 value = entry->plvalue;
2022 changed = 1;
2023 wwarning(_("using default \"%s\" instead"), entry->default_value);
2024 goto again;
2028 texture = parse_texture(scr, value);
2030 if (!texture) {
2031 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
2032 if (changed == 0) {
2033 value = entry->plvalue;
2034 changed = 1;
2035 wwarning(_("using default \"%s\" instead"), entry->default_value);
2036 goto again;
2038 return False;
2041 if (ret)
2042 *ret = &texture;
2044 if (addr)
2045 *(WTexture **) addr = texture;
2047 return True;
2050 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2052 WMPropList *elem;
2053 int changed = 0;
2054 char *val;
2055 int nelem;
2057 again:
2058 if (!WMIsPLArray(value)) {
2059 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2060 "WorkspaceBack", "Texture or None");
2061 if (changed == 0) {
2062 value = entry->plvalue;
2063 changed = 1;
2064 wwarning(_("using default \"%s\" instead"), entry->default_value);
2065 goto again;
2067 return False;
2070 /* only do basic error checking and verify for None texture */
2072 nelem = WMGetPropListItemCount(value);
2073 if (nelem > 0) {
2074 elem = WMGetFromPLArray(value, 0);
2075 if (!elem || !WMIsPLString(elem)) {
2076 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2077 if (changed == 0) {
2078 value = entry->plvalue;
2079 changed = 1;
2080 wwarning(_("using default \"%s\" instead"), entry->default_value);
2081 goto again;
2083 return False;
2085 val = WMGetFromPLString(elem);
2087 if (strcasecmp(val, "None") == 0)
2088 return True;
2090 *ret = WMRetainPropList(value);
2092 return True;
2095 static int
2096 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2098 WMPropList *elem;
2099 int nelem;
2100 int changed = 0;
2102 again:
2103 if (!WMIsPLArray(value)) {
2104 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2105 "WorkspaceSpecificBack", "an array of textures");
2106 if (changed == 0) {
2107 value = entry->plvalue;
2108 changed = 1;
2109 wwarning(_("using default \"%s\" instead"), entry->default_value);
2110 goto again;
2112 return False;
2115 /* only do basic error checking and verify for None texture */
2117 nelem = WMGetPropListItemCount(value);
2118 if (nelem > 0) {
2119 while (nelem--) {
2120 elem = WMGetFromPLArray(value, nelem);
2121 if (!elem || !WMIsPLArray(elem)) {
2122 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2123 nelem);
2128 *ret = WMRetainPropList(value);
2130 #ifdef notworking
2131 /*
2132 * Kluge to force wmsetbg helper to set the default background.
2133 * If the WorkspaceSpecificBack is changed once wmaker has started,
2134 * the WorkspaceBack won't be sent to the helper, unless the user
2135 * changes it's value too. So, we must force this by removing the
2136 * value from the defaults DB.
2137 */
2138 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2139 WMPropList *key = WMCreatePLString("WorkspaceBack");
2141 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2143 WMReleasePropList(key);
2145 #endif
2146 return True;
2149 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2151 static WMFont *font;
2152 char *val;
2154 GET_STRING_OR_DEFAULT("Font", val);
2156 font = WMCreateFont(scr->wmscreen, val);
2157 if (!font)
2158 font = WMCreateFont(scr->wmscreen, "fixed");
2160 if (!font) {
2161 wfatal(_("could not load any usable font!!!"));
2162 exit(1);
2165 if (ret)
2166 *ret = font;
2168 /* can't assign font value outside update function */
2169 wassertrv(addr == NULL, True);
2171 return True;
2174 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2176 static XColor color;
2177 char *val;
2178 int second_pass = 0;
2180 GET_STRING_OR_DEFAULT("Color", val);
2182 again:
2183 if (!wGetColor(scr, val, &color)) {
2184 wwarning(_("could not get color for key \"%s\""), entry->key);
2185 if (second_pass == 0) {
2186 val = WMGetFromPLString(entry->plvalue);
2187 second_pass = 1;
2188 wwarning(_("using default \"%s\" instead"), val);
2189 goto again;
2191 return False;
2194 if (ret)
2195 *ret = &color;
2197 assert(addr == NULL);
2198 /*
2199 if (addr)
2200 *(unsigned long*)addr = pixel;
2201 */
2203 return True;
2206 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2208 static WShortKey shortcut;
2209 KeySym ksym;
2210 char *val;
2211 char *k;
2212 char buf[MAX_SHORTCUT_LENGTH], *b;
2214 GET_STRING_OR_DEFAULT("Key spec", val);
2216 if (!val || strcasecmp(val, "NONE") == 0) {
2217 shortcut.keycode = 0;
2218 shortcut.modifier = 0;
2219 if (ret)
2220 *ret = &shortcut;
2221 return True;
2224 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2226 b = (char *)buf;
2228 /* get modifiers */
2229 shortcut.modifier = 0;
2230 while ((k = strchr(b, '+')) != NULL) {
2231 int mod;
2233 *k = 0;
2234 mod = wXModifierFromKey(b);
2235 if (mod < 0) {
2236 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2237 return False;
2239 shortcut.modifier |= mod;
2241 b = k + 1;
2244 /* get key */
2245 ksym = XStringToKeysym(b);
2247 if (ksym == NoSymbol) {
2248 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2249 return False;
2252 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2253 if (shortcut.keycode == 0) {
2254 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2255 return False;
2258 if (ret)
2259 *ret = &shortcut;
2261 return True;
2264 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2266 static int mask;
2267 char *str;
2269 GET_STRING_OR_DEFAULT("Modifier Key", str);
2271 if (!str)
2272 return False;
2274 mask = wXModifierFromKey(str);
2275 if (mask < 0) {
2276 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2277 mask = 0;
2278 return False;
2281 if (addr)
2282 *(int *)addr = mask;
2284 if (ret)
2285 *ret = &mask;
2287 return True;
2290 #ifdef NEWSTUFF
2291 static int getRImages(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2293 unsigned int mask;
2294 char *str;
2295 RImage *image;
2296 int i, n;
2297 int w, h;
2299 GET_STRING_OR_DEFAULT("Image File Path", str);
2300 if (!str)
2301 return False;
2303 image = RLoadImage(scr->rcontext, str, 0);
2304 if (!image) {
2305 wwarning(_("could not load image in option %s: %s"), entry->key, RMessageForError(RErrorCode));
2306 return False;
2309 if (*(RImage **) addr) {
2310 RReleaseImage(*(RImage **) addr);
2312 if (addr)
2313 *(RImage **) addr = image;
2315 assert(ret == NULL);
2316 /*
2317 if (ret)
2318 *(RImage**)ret = image;
2319 */
2321 return True;
2323 #endif
2325 # include <X11/cursorfont.h>
2326 typedef struct {
2327 char *name;
2328 int id;
2329 } WCursorLookup;
2331 #define CURSOR_ID_NONE (XC_num_glyphs)
2333 static WCursorLookup cursor_table[] = {
2334 {"X_cursor", XC_X_cursor},
2335 {"arrow", XC_arrow},
2336 {"based_arrow_down", XC_based_arrow_down},
2337 {"based_arrow_up", XC_based_arrow_up},
2338 {"boat", XC_boat},
2339 {"bogosity", XC_bogosity},
2340 {"bottom_left_corner", XC_bottom_left_corner},
2341 {"bottom_right_corner", XC_bottom_right_corner},
2342 {"bottom_side", XC_bottom_side},
2343 {"bottom_tee", XC_bottom_tee},
2344 {"box_spiral", XC_box_spiral},
2345 {"center_ptr", XC_center_ptr},
2346 {"circle", XC_circle},
2347 {"clock", XC_clock},
2348 {"coffee_mug", XC_coffee_mug},
2349 {"cross", XC_cross},
2350 {"cross_reverse", XC_cross_reverse},
2351 {"crosshair", XC_crosshair},
2352 {"diamond_cross", XC_diamond_cross},
2353 {"dot", XC_dot},
2354 {"dotbox", XC_dotbox},
2355 {"double_arrow", XC_double_arrow},
2356 {"draft_large", XC_draft_large},
2357 {"draft_small", XC_draft_small},
2358 {"draped_box", XC_draped_box},
2359 {"exchange", XC_exchange},
2360 {"fleur", XC_fleur},
2361 {"gobbler", XC_gobbler},
2362 {"gumby", XC_gumby},
2363 {"hand1", XC_hand1},
2364 {"hand2", XC_hand2},
2365 {"heart", XC_heart},
2366 {"icon", XC_icon},
2367 {"iron_cross", XC_iron_cross},
2368 {"left_ptr", XC_left_ptr},
2369 {"left_side", XC_left_side},
2370 {"left_tee", XC_left_tee},
2371 {"leftbutton", XC_leftbutton},
2372 {"ll_angle", XC_ll_angle},
2373 {"lr_angle", XC_lr_angle},
2374 {"man", XC_man},
2375 {"middlebutton", XC_middlebutton},
2376 {"mouse", XC_mouse},
2377 {"pencil", XC_pencil},
2378 {"pirate", XC_pirate},
2379 {"plus", XC_plus},
2380 {"question_arrow", XC_question_arrow},
2381 {"right_ptr", XC_right_ptr},
2382 {"right_side", XC_right_side},
2383 {"right_tee", XC_right_tee},
2384 {"rightbutton", XC_rightbutton},
2385 {"rtl_logo", XC_rtl_logo},
2386 {"sailboat", XC_sailboat},
2387 {"sb_down_arrow", XC_sb_down_arrow},
2388 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2389 {"sb_left_arrow", XC_sb_left_arrow},
2390 {"sb_right_arrow", XC_sb_right_arrow},
2391 {"sb_up_arrow", XC_sb_up_arrow},
2392 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2393 {"shuttle", XC_shuttle},
2394 {"sizing", XC_sizing},
2395 {"spider", XC_spider},
2396 {"spraycan", XC_spraycan},
2397 {"star", XC_star},
2398 {"target", XC_target},
2399 {"tcross", XC_tcross},
2400 {"top_left_arrow", XC_top_left_arrow},
2401 {"top_left_corner", XC_top_left_corner},
2402 {"top_right_corner", XC_top_right_corner},
2403 {"top_side", XC_top_side},
2404 {"top_tee", XC_top_tee},
2405 {"trek", XC_trek},
2406 {"ul_angle", XC_ul_angle},
2407 {"umbrella", XC_umbrella},
2408 {"ur_angle", XC_ur_angle},
2409 {"watch", XC_watch},
2410 {"xterm", XC_xterm},
2411 {NULL, CURSOR_ID_NONE}
2412 };
2414 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2416 switch (status) {
2417 case BitmapOpenFailed:
2418 wwarning(_("failed to open bitmap file \"%s\""), filename);
2419 break;
2420 case BitmapFileInvalid:
2421 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2422 break;
2423 case BitmapNoMemory:
2424 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2425 break;
2426 case BitmapSuccess:
2427 XFreePixmap(dpy, bitmap);
2428 break;
2432 /*
2433 * (none)
2434 * (builtin, <cursor_name>)
2435 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2436 */
2437 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2439 WMPropList *elem;
2440 char *val;
2441 int nelem;
2442 int status = 0;
2444 nelem = WMGetPropListItemCount(pl);
2445 if (nelem < 1) {
2446 return (status);
2448 elem = WMGetFromPLArray(pl, 0);
2449 if (!elem || !WMIsPLString(elem)) {
2450 return (status);
2452 val = WMGetFromPLString(elem);
2454 if (0 == strcasecmp(val, "none")) {
2455 status = 1;
2456 *cursor = None;
2457 } else if (0 == strcasecmp(val, "builtin")) {
2458 int i;
2459 int cursor_id = CURSOR_ID_NONE;
2461 if (2 != nelem) {
2462 wwarning(_("bad number of arguments in cursor specification"));
2463 return (status);
2465 elem = WMGetFromPLArray(pl, 1);
2466 if (!elem || !WMIsPLString(elem)) {
2467 return (status);
2469 val = WMGetFromPLString(elem);
2471 for (i = 0; NULL != cursor_table[i].name; i++) {
2472 if (0 == strcasecmp(val, cursor_table[i].name)) {
2473 cursor_id = cursor_table[i].id;
2474 break;
2477 if (CURSOR_ID_NONE == cursor_id) {
2478 wwarning(_("unknown builtin cursor name \"%s\""), val);
2479 } else {
2480 *cursor = XCreateFontCursor(dpy, cursor_id);
2481 status = 1;
2483 } else if (0 == strcasecmp(val, "bitmap")) {
2484 char *bitmap_name;
2485 char *mask_name;
2486 int bitmap_status;
2487 int mask_status;
2488 Pixmap bitmap;
2489 Pixmap mask;
2490 unsigned int w, h;
2491 int x, y;
2492 XColor fg, bg;
2494 if (3 != nelem) {
2495 wwarning(_("bad number of arguments in cursor specification"));
2496 return (status);
2498 elem = WMGetFromPLArray(pl, 1);
2499 if (!elem || !WMIsPLString(elem)) {
2500 return (status);
2502 val = WMGetFromPLString(elem);
2503 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2504 if (!bitmap_name) {
2505 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2506 return (status);
2508 elem = WMGetFromPLArray(pl, 2);
2509 if (!elem || !WMIsPLString(elem)) {
2510 wfree(bitmap_name);
2511 return (status);
2513 val = WMGetFromPLString(elem);
2514 mask_name = FindImage(wPreferences.pixmap_path, val);
2515 if (!mask_name) {
2516 wfree(bitmap_name);
2517 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2518 return (status);
2520 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2521 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2522 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2523 fg.pixel = scr->black_pixel;
2524 bg.pixel = scr->white_pixel;
2525 XQueryColor(dpy, scr->w_colormap, &fg);
2526 XQueryColor(dpy, scr->w_colormap, &bg);
2527 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2528 status = 1;
2530 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2531 check_bitmap_status(mask_status, mask_name, mask);
2532 wfree(bitmap_name);
2533 wfree(mask_name);
2535 return (status);
2538 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2540 static Cursor cursor;
2541 int status;
2542 int changed = 0;
2544 again:
2545 if (!WMIsPLArray(value)) {
2546 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2547 entry->key, "cursor specification");
2548 if (!changed) {
2549 value = entry->plvalue;
2550 changed = 1;
2551 wwarning(_("using default \"%s\" instead"), entry->default_value);
2552 goto again;
2554 return (False);
2556 status = parse_cursor(scr, value, &cursor);
2557 if (!status) {
2558 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2559 if (!changed) {
2560 value = entry->plvalue;
2561 changed = 1;
2562 wwarning(_("using default \"%s\" instead"), entry->default_value);
2563 goto again;
2565 return (False);
2567 if (ret) {
2568 *ret = &cursor;
2570 if (addr) {
2571 *(Cursor *) addr = cursor;
2573 return (True);
2576 #undef CURSOR_ID_NONE
2578 /* ---------------- value setting functions --------------- */
2579 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2581 return REFRESH_WINDOW_TITLE_COLOR;
2584 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2586 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2589 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2591 switch (which) {
2592 case WM_DOCK:
2593 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2594 break;
2595 case WM_CLIP:
2596 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2597 break;
2598 default:
2599 break;
2601 return 0;
2604 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2606 if (scr->workspaces) {
2607 wWorkspaceForceChange(scr, scr->current_workspace);
2608 wArrangeIcons(scr, False);
2610 return 0;
2613 #if not_used
2614 static int setPositive(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2616 if (*value <= 0)
2617 *(int *)foo = 1;
2619 return 0;
2621 #endif
2623 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2625 Pixmap pixmap;
2626 RImage *img;
2627 int reset = 0;
2629 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2630 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2631 ? WREL_ICON : WREL_FLAT);
2632 if (!img) {
2633 wwarning(_("could not render texture for icon background"));
2634 if (!entry->addr)
2635 wTextureDestroy(scr, *texture);
2636 return 0;
2638 RConvertImage(scr->rcontext, img, &pixmap);
2640 if (scr->icon_tile) {
2641 reset = 1;
2642 RReleaseImage(scr->icon_tile);
2643 XFreePixmap(dpy, scr->icon_tile_pixmap);
2646 scr->icon_tile = img;
2648 /* put the icon in the noticeboard hint */
2649 PropSetIconTileHint(scr, img);
2651 if (!wPreferences.flags.noclip) {
2652 if (scr->clip_tile) {
2653 RReleaseImage(scr->clip_tile);
2655 scr->clip_tile = wClipMakeTile(scr, img);
2658 scr->icon_tile_pixmap = pixmap;
2660 if (scr->def_icon_pixmap) {
2661 XFreePixmap(dpy, scr->def_icon_pixmap);
2662 scr->def_icon_pixmap = None;
2664 if (scr->def_ticon_pixmap) {
2665 XFreePixmap(dpy, scr->def_ticon_pixmap);
2666 scr->def_ticon_pixmap = None;
2669 if (scr->icon_back_texture) {
2670 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2672 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2674 if (scr->clip_balloon)
2675 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2677 /*
2678 * Free the texture as nobody else will use it, nor refer to it.
2679 */
2680 if (!entry->addr)
2681 wTextureDestroy(scr, *texture);
2683 return (reset ? REFRESH_ICON_TILE : 0);
2686 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2688 if (scr->title_font) {
2689 WMReleaseFont(scr->title_font);
2691 scr->title_font = font;
2693 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2696 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2698 if (scr->menu_title_font) {
2699 WMReleaseFont(scr->menu_title_font);
2702 scr->menu_title_font = font;
2704 return REFRESH_MENU_TITLE_FONT;
2707 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2709 if (scr->menu_entry_font) {
2710 WMReleaseFont(scr->menu_entry_font);
2712 scr->menu_entry_font = font;
2714 return REFRESH_MENU_FONT;
2717 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2719 if (scr->icon_title_font) {
2720 WMReleaseFont(scr->icon_title_font);
2723 scr->icon_title_font = font;
2725 return REFRESH_ICON_FONT;
2728 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2730 if (scr->clip_title_font) {
2731 WMReleaseFont(scr->clip_title_font);
2734 scr->clip_title_font = font;
2736 return REFRESH_ICON_FONT;
2739 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2741 if (scr->workspace_name_font) {
2742 WMReleaseFont(scr->workspace_name_font);
2745 scr->workspace_name_font = font;
2747 return 0;
2750 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2752 if (scr->select_color)
2753 WMReleaseColor(scr->select_color);
2755 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2757 wFreeColor(scr, color->pixel);
2759 return REFRESH_MENU_COLOR;
2762 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2764 if (scr->select_text_color)
2765 WMReleaseColor(scr->select_text_color);
2767 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2769 wFreeColor(scr, color->pixel);
2771 return REFRESH_MENU_COLOR;
2774 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2776 if (scr->clip_title_color[widx])
2777 WMReleaseColor(scr->clip_title_color[widx]);
2778 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2779 #ifdef GRADIENT_CLIP_ARROW
2780 if (widx == CLIP_NORMAL) {
2781 RImage *image;
2782 RColor color1, color2;
2783 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2784 int as = pt - 15; /* 15 = 5+5+5 */
2786 FREE_PIXMAP(scr->clip_arrow_gradient);
2788 color1.red = (color->red >> 8) * 6 / 10;
2789 color1.green = (color->green >> 8) * 6 / 10;
2790 color1.blue = (color->blue >> 8) * 6 / 10;
2792 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2793 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2794 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2796 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2797 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2798 RReleaseImage(image);
2800 #endif /* GRADIENT_CLIP_ARROW */
2802 wFreeColor(scr, color->pixel);
2804 return REFRESH_ICON_TITLE_COLOR;
2807 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2809 if (scr->window_title_color[widx])
2810 WMReleaseColor(scr->window_title_color[widx]);
2812 scr->window_title_color[widx] =
2813 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2815 wFreeColor(scr, color->pixel);
2817 return REFRESH_WINDOW_TITLE_COLOR;
2820 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2822 if (scr->menu_title_color[0])
2823 WMReleaseColor(scr->menu_title_color[0]);
2825 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2827 wFreeColor(scr, color->pixel);
2829 return REFRESH_MENU_TITLE_COLOR;
2832 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2834 if (scr->mtext_color)
2835 WMReleaseColor(scr->mtext_color);
2837 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2839 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2840 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2841 } else {
2842 WMSetColorAlpha(scr->dtext_color, 0xffff);
2845 wFreeColor(scr, color->pixel);
2847 return REFRESH_MENU_COLOR;
2850 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2852 if (scr->dtext_color)
2853 WMReleaseColor(scr->dtext_color);
2855 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2857 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2858 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2859 } else {
2860 WMSetColorAlpha(scr->dtext_color, 0xffff);
2863 wFreeColor(scr, color->pixel);
2865 return REFRESH_MENU_COLOR;
2868 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2870 if (scr->icon_title_color)
2871 WMReleaseColor(scr->icon_title_color);
2872 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2874 wFreeColor(scr, color->pixel);
2876 return REFRESH_ICON_TITLE_COLOR;
2879 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2881 if (scr->icon_title_texture) {
2882 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2884 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2886 return REFRESH_ICON_TITLE_BACK;
2889 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2891 close(scr->helper_fd);
2892 scr->helper_fd = 0;
2893 scr->helper_pid = 0;
2894 scr->flags.backimage_helper_launched = 0;
2897 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2899 WMPropList *val;
2900 char *str;
2901 int i;
2903 if (scr->flags.backimage_helper_launched) {
2904 if (WMGetPropListItemCount(value) == 0) {
2905 SendHelperMessage(scr, 'C', 0, NULL);
2906 SendHelperMessage(scr, 'K', 0, NULL);
2908 WMReleasePropList(value);
2909 return 0;
2911 } else {
2912 pid_t pid;
2913 int filedes[2];
2915 if (WMGetPropListItemCount(value) == 0)
2916 return 0;
2918 if (pipe(filedes) < 0) {
2919 wsyserror("pipe() failed:can't set workspace specific background image");
2921 WMReleasePropList(value);
2922 return 0;
2925 pid = fork();
2926 if (pid < 0) {
2927 wsyserror("fork() failed:can't set workspace specific background image");
2928 if (close(filedes[0]) < 0)
2929 wsyserror("could not close pipe");
2930 if (close(filedes[1]) < 0)
2931 wsyserror("could not close pipe");
2933 } else if (pid == 0) {
2934 char *dither;
2936 SetupEnvironment(scr);
2938 if (close(0) < 0)
2939 wsyserror("could not close pipe");
2940 if (dup(filedes[0]) < 0) {
2941 wsyserror("dup() failed:can't set workspace specific background image");
2943 dither = wPreferences.no_dithering ? "-m" : "-d";
2944 if (wPreferences.smooth_workspace_back)
2945 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2946 else
2947 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2948 wsyserror("could not execute wmsetbg");
2949 exit(1);
2950 } else {
2952 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2953 wsyserror("error setting close-on-exec flag");
2955 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2956 wsyserror("error setting close-on-exec flag");
2959 scr->helper_fd = filedes[1];
2960 scr->helper_pid = pid;
2961 scr->flags.backimage_helper_launched = 1;
2963 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2965 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2970 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2971 val = WMGetFromPLArray(value, i);
2972 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2973 str = WMGetPropListDescription(val, False);
2975 SendHelperMessage(scr, 'S', i + 1, str);
2977 wfree(str);
2978 } else {
2979 SendHelperMessage(scr, 'U', i + 1, NULL);
2982 sleep(1);
2984 WMReleasePropList(value);
2985 return 0;
2988 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2990 if (scr->flags.backimage_helper_launched) {
2991 char *str;
2993 if (WMGetPropListItemCount(value) == 0) {
2994 SendHelperMessage(scr, 'U', 0, NULL);
2995 } else {
2996 /* set the default workspace background to this one */
2997 str = WMGetPropListDescription(value, False);
2998 if (str) {
2999 SendHelperMessage(scr, 'S', 0, str);
3000 wfree(str);
3001 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
3002 } else {
3003 SendHelperMessage(scr, 'U', 0, NULL);
3006 } else if (WMGetPropListItemCount(value) > 0) {
3007 char *command;
3008 char *text;
3009 char *dither;
3010 int len;
3012 SetupEnvironment(scr);
3013 text = WMGetPropListDescription(value, False);
3014 len = strlen(text) + 40;
3015 command = wmalloc(len);
3016 dither = wPreferences.no_dithering ? "-m" : "-d";
3017 if (wPreferences.smooth_workspace_back)
3018 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3019 else
3020 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3021 wfree(text);
3022 system(command);
3023 wfree(command);
3025 WMReleasePropList(value);
3027 return 0;
3030 #ifdef VIRTUAL_DESKTOP
3031 static int setVirtualDeskEnable(WScreen * scr, WDefaultEntry * entry, void *foo, void *bar)
3033 wWorkspaceUpdateEdge(scr);
3034 return 0;
3036 #endif
3038 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3040 if (scr->widget_texture) {
3041 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3043 scr->widget_texture = *(WTexSolid **) texture;
3045 return 0;
3048 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3050 if (scr->window_title_texture[WS_FOCUSED]) {
3051 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3053 scr->window_title_texture[WS_FOCUSED] = *texture;
3055 return REFRESH_WINDOW_TEXTURES;
3058 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3060 if (scr->window_title_texture[WS_PFOCUSED]) {
3061 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3063 scr->window_title_texture[WS_PFOCUSED] = *texture;
3065 return REFRESH_WINDOW_TEXTURES;
3068 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3070 if (scr->window_title_texture[WS_UNFOCUSED]) {
3071 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3073 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3075 return REFRESH_WINDOW_TEXTURES;
3078 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3080 if (scr->resizebar_texture[0]) {
3081 wTextureDestroy(scr, scr->resizebar_texture[0]);
3083 scr->resizebar_texture[0] = *texture;
3085 return REFRESH_WINDOW_TEXTURES;
3088 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3090 if (scr->menu_title_texture[0]) {
3091 wTextureDestroy(scr, scr->menu_title_texture[0]);
3093 scr->menu_title_texture[0] = *texture;
3095 return REFRESH_MENU_TITLE_TEXTURE;
3098 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3100 if (scr->menu_item_texture) {
3101 wTextureDestroy(scr, scr->menu_item_texture);
3102 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3104 scr->menu_item_texture = *texture;
3106 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3108 return REFRESH_MENU_TEXTURE;
3111 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
3113 WWindow *wwin;
3114 wKeyBindings[widx] = *shortcut;
3116 wwin = scr->focused_window;
3118 while (wwin != NULL) {
3119 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3121 if (!WFLAGP(wwin, no_bind_keys)) {
3122 wWindowSetKeyGrabs(wwin);
3124 wwin = wwin->prev;
3127 return 0;
3130 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3132 wScreenUpdateUsableArea(scr);
3133 wArrangeIcons(scr, True);
3135 return 0;
3138 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3140 wScreenUpdateUsableArea(scr);
3142 return 0;
3145 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3147 return REFRESH_MENU_TEXTURE;
3150 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3152 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3154 RCopyArea(img, image, x, y, w, h, 0, 0);
3156 return img;
3159 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
3161 char *path;
3162 RImage *bgimage;
3163 int cwidth, cheight;
3164 WPreferences *prefs = (WPreferences *) foo;
3166 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3167 if (prefs->swtileImage)
3168 RReleaseImage(prefs->swtileImage);
3169 prefs->swtileImage = NULL;
3171 WMReleasePropList(array);
3172 return 0;
3175 switch (WMGetPropListItemCount(array)) {
3176 case 4:
3177 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3178 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3179 break;
3180 } else
3181 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3183 if (!path) {
3184 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3185 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3186 } else {
3187 bgimage = RLoadImage(scr->rcontext, path, 0);
3188 if (!bgimage) {
3189 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3190 wfree(path);
3191 } else {
3192 wfree(path);
3194 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3195 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3197 if (cwidth <= 0 || cheight <= 0 ||
3198 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3199 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3200 else {
3201 int i;
3202 int swidth, theight;
3203 for (i = 0; i < 9; i++) {
3204 if (prefs->swbackImage[i])
3205 RReleaseImage(prefs->swbackImage[i]);
3206 prefs->swbackImage[i] = NULL;
3208 swidth = (bgimage->width - cwidth) / 2;
3209 theight = (bgimage->height - cheight) / 2;
3211 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3212 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3213 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3214 swidth, theight);
3216 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3217 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3218 cwidth, cheight);
3219 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3220 swidth, cheight);
3222 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3223 swidth, theight);
3224 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3225 cwidth, theight);
3226 prefs->swbackImage[8] =
3227 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3228 theight);
3230 // check if anything failed
3231 for (i = 0; i < 9; i++) {
3232 if (!prefs->swbackImage[i]) {
3233 for (; i >= 0; --i) {
3234 RReleaseImage(prefs->swbackImage[i]);
3235 prefs->swbackImage[i] = NULL;
3237 break;
3241 RReleaseImage(bgimage);
3245 case 1:
3246 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3247 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3248 break;
3249 } else
3250 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3252 if (!path) {
3253 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3254 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3255 } else {
3256 if (prefs->swtileImage)
3257 RReleaseImage(prefs->swtileImage);
3259 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3260 if (!prefs->swtileImage) {
3261 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3263 wfree(path);
3265 break;
3267 default:
3268 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3269 break;
3272 WMReleasePropList(array);
3274 return 0;
3277 /*
3278 static int
3279 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3281 return REFRESH_BUTTON_IMAGES;
3283 */
3285 /*
3286 * Very ugly kluge.
3287 * Need access to the double click variables, so that all widgets in
3288 * wmaker panels will have the same dbl-click values.
3289 * TODO: figure a better way of dealing with it.
3290 */
3291 #include <WINGs/WINGsP.h>
3293 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3295 extern _WINGsConfiguration WINGsConfiguration;
3297 if (*value <= 0)
3298 *(int *)foo = 1;
3300 WINGsConfiguration.doubleClickDelay = *value;
3302 return 0;
3305 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3307 if (wCursor[widx] != None) {
3308 XFreeCursor(dpy, wCursor[widx]);
3311 wCursor[widx] = *cursor;
3313 if (widx == WCUR_ROOT && *cursor != None) {
3314 XDefineCursor(dpy, scr->root_win, *cursor);
3317 return 0;