Small fix for wmaker nightly build script 2
[wmaker-crm.git] / src / defaults.c
blob2d8fea993324abaa3ea2f0cc80e39e3db6e29ee1
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifdef HAVE_DLFCN_H
40 # include <dlfcn.h>
41 #endif
43 #ifndef PATH_MAX
44 #define PATH_MAX DEFAULT_PATH_MAX
45 #endif
47 #include <X11/Xlib.h>
48 #include <X11/Xutil.h>
49 #include <X11/keysym.h>
51 #include <wraster.h>
53 #include "WindowMaker.h"
54 #include "wcore.h"
55 #include "framewin.h"
56 #include "window.h"
57 #include "texture.h"
58 #include "screen.h"
59 #include "resources.h"
60 #include "defaults.h"
61 #include "keybind.h"
62 #include "xmodifier.h"
63 #include "icon.h"
64 #include "funcs.h"
65 #include "actions.h"
66 #include "dock.h"
67 #include "workspace.h"
68 #include "properties.h"
70 #define MAX_SHORTCUT_LENGTH 32
72 #ifndef GLOBAL_DEFAULTS_SUBDIR
73 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
74 #endif
76 /***** Global *****/
78 extern WDDomain *WDWindowMaker;
79 extern WDDomain *WDWindowAttributes;
80 extern WDDomain *WDRootMenu;
82 extern int wScreenCount;
84 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
85 extern Atom _XA_WINDOWMAKER_ICON_TILE;
88 extern WMPropList *wDomainName;
89 extern WMPropList *wAttributeDomainName;
91 extern WPreferences wPreferences;
93 extern WShortKey wKeyBindings[WKBD_LAST];
95 typedef struct {
96 char *key;
97 char *default_value;
98 void *extra_data;
99 void *addr;
100 int (*convert) ();
101 int (*update) ();
102 WMPropList *plkey;
103 WMPropList *plvalue; /* default value */
104 } WDefaultEntry;
106 /* used to map strings to integers */
107 typedef struct {
108 char *string;
109 short value;
110 char is_alias;
111 } WOptionEnumeration;
113 /* type converters */
114 static int getBool();
115 static int getInt();
116 static int getCoord();
117 #if 0
118 /* this is not used yet */
119 static int getString();
120 #endif
121 static int getPathList();
122 static int getEnum();
123 static int getTexture();
124 static int getWSBackground();
125 static int getWSSpecificBackground();
126 static int getFont();
127 static int getColor();
128 static int getKeybind();
129 static int getModMask();
130 #ifdef NEWSTUFF
131 static int getRImage();
132 #endif
133 static int getPropList();
135 /* value setting functions */
136 static int setJustify();
137 static int setClearance();
138 static int setIfDockPresent();
139 static int setStickyIcons();
141 static int setPositive();
143 static int setWidgetColor();
144 static int setIconTile();
145 static int setWinTitleFont();
146 static int setMenuTitleFont();
147 static int setMenuTextFont();
148 static int setIconTitleFont();
149 static int setIconTitleColor();
150 static int setIconTitleBack();
151 static int setLargeDisplayFont();
152 static int setWTitleColor();
153 static int setFTitleBack();
154 static int setPTitleBack();
155 static int setUTitleBack();
156 static int setResizebarBack();
157 static int setWorkspaceBack();
158 static int setWorkspaceSpecificBack();
159 static int setMenuTitleColor();
160 static int setMenuTextColor();
161 static int setMenuDisabledColor();
162 static int setMenuTitleBack();
163 static int setMenuTextBack();
164 static int setHightlight();
165 static int setHightlightText();
166 static int setKeyGrab();
167 static int setDoubleClick();
168 static int setIconPosition();
170 static int setClipTitleFont();
171 static int setClipTitleColor();
173 static int setMenuStyle();
174 static int setSwPOptions();
175 static int updateUsableArea();
177 extern Cursor wCursor[WCUR_LAST];
178 static int getCursor();
179 static int setCursor();
182 * Tables to convert strings to enumeration values.
183 * Values stored are char
186 /* WARNING: sum of length of all value strings must not exceed
187 * this value */
188 #define TOTAL_VALUES_LENGTH 80
190 #define REFRESH_WINDOW_TEXTURES (1<<0)
191 #define REFRESH_MENU_TEXTURE (1<<1)
192 #define REFRESH_MENU_FONT (1<<2)
193 #define REFRESH_MENU_COLOR (1<<3)
194 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
195 #define REFRESH_MENU_TITLE_FONT (1<<5)
196 #define REFRESH_MENU_TITLE_COLOR (1<<6)
197 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
198 #define REFRESH_WINDOW_FONT (1<<8)
199 #define REFRESH_ICON_TILE (1<<9)
200 #define REFRESH_ICON_FONT (1<<10)
201 #define REFRESH_WORKSPACE_BACK (1<<11)
203 #define REFRESH_BUTTON_IMAGES (1<<12)
205 #define REFRESH_ICON_TITLE_COLOR (1<<13)
206 #define REFRESH_ICON_TITLE_BACK (1<<14)
208 static WOptionEnumeration seFocusModes[] = {
209 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
210 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
211 {NULL, 0, 0}
214 static WOptionEnumeration seColormapModes[] = {
215 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
216 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
217 {NULL, 0, 0}
220 static WOptionEnumeration sePlacements[] = {
221 {"Auto", WPM_AUTO, 0},
222 {"Smart", WPM_SMART, 0},
223 {"Cascade", WPM_CASCADE, 0},
224 {"Random", WPM_RANDOM, 0},
225 {"Manual", WPM_MANUAL, 0},
226 {NULL, 0, 0}
229 static WOptionEnumeration seGeomDisplays[] = {
230 {"None", WDIS_NONE, 0},
231 {"Center", WDIS_CENTER, 0},
232 {"Corner", WDIS_TOPLEFT, 0},
233 {"Floating", WDIS_FRAME_CENTER, 0},
234 {"Line", WDIS_NEW, 0},
235 {NULL, 0, 0}
238 static WOptionEnumeration seSpeeds[] = {
239 {"UltraFast", SPEED_ULTRAFAST, 0},
240 {"Fast", SPEED_FAST, 0},
241 {"Medium", SPEED_MEDIUM, 0},
242 {"Slow", SPEED_SLOW, 0},
243 {"UltraSlow", SPEED_ULTRASLOW, 0},
244 {NULL, 0, 0}
247 static WOptionEnumeration seMouseButtonActions[] = {
248 {"None", WA_NONE, 0},
249 {"SelectWindows", WA_SELECT_WINDOWS, 0},
250 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
251 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
252 {NULL, 0, 0}
255 static WOptionEnumeration seMouseWheelActions[] = {
256 {"None", WA_NONE, 0},
257 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
258 {NULL, 0, 0}
261 static WOptionEnumeration seIconificationStyles[] = {
262 {"Zoom", WIS_ZOOM, 0},
263 {"Twist", WIS_TWIST, 0},
264 {"Flip", WIS_FLIP, 0},
265 {"None", WIS_NONE, 0},
266 {"random", WIS_RANDOM, 0},
267 {NULL, 0, 0}
270 static WOptionEnumeration seJustifications[] = {
271 {"Left", WTJ_LEFT, 0},
272 {"Center", WTJ_CENTER, 0},
273 {"Right", WTJ_RIGHT, 0},
274 {NULL, 0, 0}
277 static WOptionEnumeration seIconPositions[] = {
278 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
279 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
280 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
281 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
282 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
283 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
284 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
285 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
286 {NULL, 0, 0}
289 static WOptionEnumeration seMenuStyles[] = {
290 {"normal", MS_NORMAL, 0},
291 {"singletexture", MS_SINGLE_TEXTURE, 0},
292 {"flat", MS_FLAT, 0},
293 {NULL, 0, 0}
296 static WOptionEnumeration seDisplayPositions[] = {
297 {"none", WD_NONE, 0},
298 {"center", WD_CENTER, 0},
299 {"top", WD_TOP, 0},
300 {"bottom", WD_BOTTOM, 0},
301 {"topleft", WD_TOPLEFT, 0},
302 {"topright", WD_TOPRIGHT, 0},
303 {"bottomleft", WD_BOTTOMLEFT, 0},
304 {"bottomright", WD_BOTTOMRIGHT, 0},
305 {NULL, 0, 0}
308 static WOptionEnumeration seWorkspaceBorder[] = {
309 {"None", WB_NONE, 0},
310 {"LeftRight", WB_LEFTRIGHT, 0},
311 {"TopBottom", WB_TOPBOTTOM, 0},
312 {"AllDirections", WB_ALLDIRS, 0},
313 {NULL, 0, 0}
317 * ALL entries in the tables bellow, NEED to have a default value
318 * defined, and this value needs to be correct.
321 /* these options will only affect the window manager on startup
323 * static defaults can't access the screen data, because it is
324 * created after these defaults are read
326 WDefaultEntry staticOptionList[] = {
328 {"ColormapSize", "4", NULL,
329 &wPreferences.cmap_size, getInt, NULL},
330 {"DisableDithering", "NO", NULL,
331 &wPreferences.no_dithering, getBool, NULL},
332 /* static by laziness */
333 {"IconSize", "64", NULL,
334 &wPreferences.icon_size, getInt, NULL},
335 {"ModifierKey", "Mod1", NULL,
336 &wPreferences.modifier_mask, getModMask, NULL},
337 {"DisableWSMouseActions", "NO", NULL,
338 &wPreferences.disable_root_mouse, getBool, NULL},
339 {"FocusMode", "manual", seFocusModes,
340 &wPreferences.focus_mode, getEnum, NULL}, /* have a problem when switching from manual to sloppy without restart */
341 {"NewStyle", "NO", NULL,
342 &wPreferences.new_style, getBool, NULL},
343 {"DisableDock", "NO", (void *)WM_DOCK,
344 NULL, getBool, setIfDockPresent},
345 {"DisableClip", "NO", (void *)WM_CLIP,
346 NULL, getBool, setIfDockPresent},
347 {"DisableMiniwindows", "NO", NULL,
348 &wPreferences.disable_miniwindows, getBool, NULL}
351 WDefaultEntry optionList[] = {
352 /* dynamic options */
353 {"IconPosition", "blh", seIconPositions,
354 &wPreferences.icon_yard, getEnum, setIconPosition},
355 {"IconificationStyle", "Zoom", seIconificationStyles,
356 &wPreferences.iconification_style, getEnum, NULL},
357 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
358 &wPreferences.mouse_button1, getEnum, NULL},
359 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
360 &wPreferences.mouse_button2, getEnum, NULL},
361 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
362 &wPreferences.mouse_button3, getEnum, NULL},
363 {"MouseWheelAction", "None", seMouseWheelActions,
364 &wPreferences.mouse_wheel, getEnum, NULL},
365 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
366 &wPreferences.pixmap_path, getPathList, NULL},
367 {"IconPath", DEF_ICON_PATHS, NULL,
368 &wPreferences.icon_path, getPathList, NULL},
369 {"ColormapMode", "auto", seColormapModes,
370 &wPreferences.colormap_mode, getEnum, NULL},
371 {"AutoFocus", "NO", NULL,
372 &wPreferences.auto_focus, getBool, NULL},
373 {"RaiseDelay", "0", NULL,
374 &wPreferences.raise_delay, getInt, NULL},
375 {"CirculateRaise", "NO", NULL,
376 &wPreferences.circ_raise, getBool, NULL},
377 {"Superfluous", "NO", NULL,
378 &wPreferences.superfluous, getBool, NULL},
379 {"AdvanceToNewWorkspace", "NO", NULL,
380 &wPreferences.ws_advance, getBool, NULL},
381 {"CycleWorkspaces", "NO", NULL,
382 &wPreferences.ws_cycle, getBool, NULL},
383 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
384 &wPreferences.workspace_name_display_position, getEnum, NULL},
385 {"WorkspaceBorder", "None", seWorkspaceBorder,
386 &wPreferences.workspace_border_position, getEnum, updateUsableArea},
387 {"WorkspaceBorderSize", "0", NULL,
388 &wPreferences.workspace_border_size, getInt, updateUsableArea},
389 {"StickyIcons", "NO", NULL,
390 &wPreferences.sticky_icons, getBool, setStickyIcons},
391 {"SaveSessionOnExit", "NO", NULL,
392 &wPreferences.save_session_on_exit, getBool, NULL},
393 {"WrapMenus", "NO", NULL,
394 &wPreferences.wrap_menus, getBool, NULL},
395 {"ScrollableMenus", "NO", NULL,
396 &wPreferences.scrollable_menus, getBool, NULL},
397 {"MenuScrollSpeed", "medium", seSpeeds,
398 &wPreferences.menu_scroll_speed, getEnum, NULL},
399 {"IconSlideSpeed", "medium", seSpeeds,
400 &wPreferences.icon_slide_speed, getEnum, NULL},
401 {"ShadeSpeed", "medium", seSpeeds,
402 &wPreferences.shade_speed, getEnum, NULL},
403 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
404 &wPreferences.dblclick_time, getInt, setDoubleClick,
406 {"AlignSubmenus", "NO", NULL,
407 &wPreferences.align_menus, getBool, NULL},
408 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
409 &wPreferences.open_transients_with_parent, getBool, NULL},
410 {"WindowPlacement", "auto", sePlacements,
411 &wPreferences.window_placement, getEnum, NULL},
412 {"IgnoreFocusClick", "NO", NULL,
413 &wPreferences.ignore_focus_click, getBool, NULL},
414 {"UseSaveUnders", "NO", NULL,
415 &wPreferences.use_saveunders, getBool, NULL},
416 {"OpaqueMove", "NO", NULL,
417 &wPreferences.opaque_move, getBool, NULL},
418 {"DisableAnimations", "NO", NULL,
419 &wPreferences.no_animations, getBool, NULL},
420 {"DontLinkWorkspaces", "NO", NULL,
421 &wPreferences.no_autowrap, getBool, NULL},
422 {"AutoArrangeIcons", "NO", NULL,
423 &wPreferences.auto_arrange_icons, getBool, NULL},
424 {"NoWindowOverDock", "NO", NULL,
425 &wPreferences.no_window_over_dock, getBool, updateUsableArea},
426 {"NoWindowOverIcons", "NO", NULL,
427 &wPreferences.no_window_over_icons, getBool, updateUsableArea},
428 {"WindowPlaceOrigin", "(0, 0)", NULL,
429 &wPreferences.window_place_origin, getCoord, NULL},
430 {"ResizeDisplay", "corner", seGeomDisplays,
431 &wPreferences.size_display, getEnum, NULL},
432 {"MoveDisplay", "corner", seGeomDisplays,
433 &wPreferences.move_display, getEnum, NULL},
434 {"DontConfirmKill", "NO", NULL,
435 &wPreferences.dont_confirm_kill, getBool, NULL},
436 {"WindowTitleBalloons", "NO", NULL,
437 &wPreferences.window_balloon, getBool, NULL},
438 {"MiniwindowTitleBalloons", "NO", NULL,
439 &wPreferences.miniwin_balloon, getBool, NULL},
440 {"AppIconBalloons", "NO", NULL,
441 &wPreferences.appicon_balloon, getBool, NULL},
442 {"HelpBalloons", "NO", NULL,
443 &wPreferences.help_balloon, getBool, NULL},
444 {"EdgeResistance", "30", NULL,
445 &wPreferences.edge_resistance, getInt, NULL},
446 {"ResizeIncrement", "32", NULL,
447 &wPreferences.resize_increment, getInt, NULL},
448 {"Attraction", "NO", NULL,
449 &wPreferences.attract, getBool, NULL},
450 {"DisableBlinking", "NO", NULL,
451 &wPreferences.dont_blink, getBool, NULL},
452 {"SingleClickLaunch", "NO", NULL,
453 &wPreferences.single_click, getBool, NULL},
454 /* style options */
455 {"MenuStyle", "normal", seMenuStyles,
456 &wPreferences.menu_style, getEnum, setMenuStyle},
457 {"WidgetColor", "(solid, gray)", NULL,
458 NULL, getTexture, setWidgetColor,
460 {"WorkspaceSpecificBack", "()", NULL,
461 NULL, getWSSpecificBackground, setWorkspaceSpecificBack},
462 /* WorkspaceBack must come after WorkspaceSpecificBack or
463 * WorkspaceBack wont know WorkspaceSpecificBack was also
464 * specified and 2 copies of wmsetbg will be launched */
465 {"WorkspaceBack", "(solid, black)", NULL,
466 NULL, getWSBackground, setWorkspaceBack},
467 {"SmoothWorkspaceBack", "NO", NULL,
468 NULL, getBool, NULL},
469 {"IconBack", "(solid, gray)", NULL,
470 NULL, getTexture, setIconTile},
471 {"TitleJustify", "center", seJustifications,
472 &wPreferences.title_justification, getEnum, setJustify},
473 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
474 NULL, getFont, setWinTitleFont,
476 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
477 &wPreferences.window_title_clearance, getInt, setClearance},
478 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
479 &wPreferences.menu_title_clearance, getInt, setClearance},
480 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
481 &wPreferences.menu_text_clearance, getInt, setClearance},
482 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
483 NULL, getFont, setMenuTitleFont},
484 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
485 NULL, getFont, setMenuTextFont},
486 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
487 NULL, getFont, setIconTitleFont},
488 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
489 NULL, getFont, setClipTitleFont},
490 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
491 NULL, getFont, setLargeDisplayFont},
492 {"HighlightColor", "white", NULL,
493 NULL, getColor, setHightlight},
494 {"HighlightTextColor", "black", NULL,
495 NULL, getColor, setHightlightText},
496 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
497 NULL, getColor, setClipTitleColor},
498 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
499 NULL, getColor, setClipTitleColor},
500 {"FTitleColor", "white", (void *)WS_FOCUSED,
501 NULL, getColor, setWTitleColor},
502 {"PTitleColor", "white", (void *)WS_PFOCUSED,
503 NULL, getColor, setWTitleColor},
504 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
505 NULL, getColor, setWTitleColor},
506 {"FTitleBack", "(solid, black)", NULL,
507 NULL, getTexture, setFTitleBack},
508 {"PTitleBack", "(solid, \"#616161\")", NULL,
509 NULL, getTexture, setPTitleBack},
510 {"UTitleBack", "(solid, gray)", NULL,
511 NULL, getTexture, setUTitleBack},
512 {"ResizebarBack", "(solid, gray)", NULL,
513 NULL, getTexture, setResizebarBack},
514 {"MenuTitleColor", "white", NULL,
515 NULL, getColor, setMenuTitleColor},
516 {"MenuTextColor", "black", NULL,
517 NULL, getColor, setMenuTextColor},
518 {"MenuDisabledColor", "\"#616161\"", NULL,
519 NULL, getColor, setMenuDisabledColor},
520 {"MenuTitleBack", "(solid, black)", NULL,
521 NULL, getTexture, setMenuTitleBack},
522 {"MenuTextBack", "(solid, gray)", NULL,
523 NULL, getTexture, setMenuTextBack},
524 {"IconTitleColor", "white", NULL,
525 NULL, getColor, setIconTitleColor},
526 {"IconTitleBack", "black", NULL,
527 NULL, getColor, setIconTitleBack},
528 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
529 NULL, getPropList, setSwPOptions},
530 /* keybindings */
531 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
532 NULL, getKeybind, setKeyGrab},
533 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
534 NULL, getKeybind, setKeyGrab},
535 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
536 NULL, getKeybind, setKeyGrab},
537 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
538 NULL, getKeybind, setKeyGrab},
539 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
540 NULL, getKeybind, setKeyGrab},
541 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
542 NULL, getKeybind, setKeyGrab},
543 {"HideKey", "None", (void *)WKBD_HIDE,
544 NULL, getKeybind, setKeyGrab},
545 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
546 NULL, getKeybind, setKeyGrab},
547 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
548 NULL, getKeybind, setKeyGrab},
549 {"CloseKey", "None", (void *)WKBD_CLOSE,
550 NULL, getKeybind, setKeyGrab},
551 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
552 NULL, getKeybind, setKeyGrab},
553 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
554 NULL, getKeybind, setKeyGrab},
555 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
556 NULL, getKeybind, setKeyGrab},
557 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
558 NULL, getKeybind, setKeyGrab},
559 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
560 NULL, getKeybind, setKeyGrab},
561 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
562 NULL, getKeybind, setKeyGrab},
563 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
564 NULL, getKeybind, setKeyGrab},
565 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
566 NULL, getKeybind, setKeyGrab},
567 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
568 NULL, getKeybind, setKeyGrab},
569 {"ShadeKey", "None", (void *)WKBD_SHADE,
570 NULL, getKeybind, setKeyGrab},
571 {"SelectKey", "None", (void *)WKBD_SELECT,
572 NULL, getKeybind, setKeyGrab},
573 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
574 NULL, getKeybind, setKeyGrab},
575 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
576 NULL, getKeybind, setKeyGrab},
577 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
578 NULL, getKeybind, setKeyGrab},
579 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
580 NULL, getKeybind, setKeyGrab},
581 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
582 NULL, getKeybind, setKeyGrab},
583 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
584 NULL, getKeybind, setKeyGrab},
585 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
586 NULL, getKeybind, setKeyGrab},
587 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
588 NULL, getKeybind, setKeyGrab},
589 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
590 NULL, getKeybind, setKeyGrab},
591 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
592 NULL, getKeybind, setKeyGrab},
593 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
594 NULL, getKeybind, setKeyGrab},
595 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
596 NULL, getKeybind, setKeyGrab},
597 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
598 NULL, getKeybind, setKeyGrab},
599 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
600 NULL, getKeybind, setKeyGrab},
601 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
602 NULL, getKeybind, setKeyGrab},
603 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
604 NULL, getKeybind, setKeyGrab},
605 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
606 NULL, getKeybind, setKeyGrab},
607 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
608 NULL, getKeybind, setKeyGrab},
609 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
610 NULL, getKeybind, setKeyGrab},
611 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
612 NULL, getKeybind, setKeyGrab},
613 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
614 NULL, getKeybind, setKeyGrab},
615 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
616 NULL, getKeybind, setKeyGrab}
617 , {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
618 NULL, getKeybind, setKeyGrab},
619 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
620 NULL, getKeybind, setKeyGrab},
621 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
622 NULL, getKeybind, setKeyGrab},
623 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
624 NULL, getKeybind, setKeyGrab},
625 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
626 NULL, getKeybind, setKeyGrab},
627 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
628 NULL, getKeybind, setKeyGrab},
629 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
630 NULL, getKeybind, setKeyGrab},
632 #ifdef KEEP_XKB_LOCK_STATUS
633 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
634 NULL, getKeybind, setKeyGrab},
635 {"KbdModeLock", "NO", NULL,
636 &wPreferences.modelock, getBool, NULL},
637 #endif /* KEEP_XKB_LOCK_STATUS */
639 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
640 NULL, getCursor, setCursor},
641 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
642 NULL, getCursor, setCursor},
643 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
644 NULL, getCursor, setCursor},
645 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
646 NULL, getCursor, setCursor},
647 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
648 (void *)WCUR_TOPLEFTRESIZE,
649 NULL, getCursor, setCursor},
650 {"TopRightResizeCursor", "(builtin, top_right_corner)",
651 (void *)WCUR_TOPRIGHTRESIZE,
652 NULL, getCursor, setCursor},
653 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
654 (void *)WCUR_BOTTOMLEFTRESIZE,
655 NULL, getCursor, setCursor},
656 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
657 (void *)WCUR_BOTTOMRIGHTRESIZE,
658 NULL, getCursor, setCursor},
659 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
660 (void *)WCUR_VERTICALRESIZE,
661 NULL, getCursor, setCursor},
662 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
663 (void *)WCUR_HORIZONRESIZE,
664 NULL, getCursor, setCursor},
665 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
666 NULL, getCursor, setCursor},
667 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
668 NULL, getCursor, setCursor},
669 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
670 NULL, getCursor, setCursor},
671 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
672 NULL, getCursor, setCursor},
673 {"DialogHistoryLines", "500", NULL,
674 &wPreferences.history_lines, getInt, NULL}
677 #if 0
678 static void rereadDefaults(void);
679 #endif
681 #if 0
682 static void rereadDefaults(void)
684 /* must defer the update because accessing X data from a
685 * signal handler can mess up Xlib */
688 #endif
690 static void initDefaults()
692 unsigned int i;
693 WDefaultEntry *entry;
695 WMPLSetCaseSensitive(False);
697 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
698 entry = &optionList[i];
700 entry->plkey = WMCreatePLString(entry->key);
701 if (entry->default_value)
702 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
703 else
704 entry->plvalue = NULL;
707 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
708 entry = &staticOptionList[i];
710 entry->plkey = WMCreatePLString(entry->key);
711 if (entry->default_value)
712 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
713 else
714 entry->plvalue = NULL;
718 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
719 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
721 PLRegister(wDomainName, rereadDefaults);
722 PLRegister(wAttributeDomainName, rereadDefaults);
726 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
728 WMPropList *globalDict = NULL;
729 char path[PATH_MAX];
730 struct stat stbuf;
732 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
733 if (stat(path, &stbuf) >= 0) {
734 globalDict = WMReadPropListFromFile(path);
735 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
736 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
737 WMReleasePropList(globalDict);
738 globalDict = NULL;
739 } else if (!globalDict) {
740 wwarning(_("could not load domain %s from global defaults database"), domainName);
744 return globalDict;
747 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
748 static void prependMenu(WMPropList * destarr, WMPropList * array)
750 WMPropList *item;
751 int i;
753 for (i = 0; i < WMGetPropListItemCount(array); i++) {
754 item = WMGetFromPLArray(array, i);
755 if (item)
756 WMInsertInPLArray(destarr, i + 1, item);
760 static void appendMenu(WMPropList * destarr, WMPropList * array)
762 WMPropList *item;
763 int i;
765 for (i = 0; i < WMGetPropListItemCount(array); i++) {
766 item = WMGetFromPLArray(array, i);
767 if (item)
768 WMAddToPLArray(destarr, item);
771 #endif
773 /* Fixup paths for cached pixmaps from .AppInfo to Library/WindowMaker/... */
774 static Bool fixupCachedPixmapsPaths(WMPropList * dict)
776 WMPropList *allApps, *app, *props, *iconkey, *icon, *newicon;
777 char *path, *fixedpath, *ptr, *search;
778 int i, len, slen;
779 Bool changed = False;
781 search = "/.AppInfo/WindowMaker/";
782 slen = strlen(search);
784 iconkey = WMCreatePLString("Icon");
785 allApps = WMGetPLDictionaryKeys(dict);
787 for (i = 0; i < WMGetPropListItemCount(allApps); i++) {
788 app = WMGetFromPLArray(allApps, i);
789 props = WMGetFromPLDictionary(dict, app);
790 if (!props)
791 continue;
792 icon = WMGetFromPLDictionary(props, iconkey);
793 if (icon && WMIsPLString(icon)) {
794 path = WMGetFromPLString(icon);
795 ptr = strstr(path, search);
796 if (ptr) {
797 changed = True;
798 len = (ptr - path);
799 fixedpath = wmalloc(strlen(path) + 32);
800 strncpy(fixedpath, path, len);
801 fixedpath[len] = 0;
802 strcat(fixedpath, "/Library/WindowMaker/CachedPixmaps/");
803 strcat(fixedpath, ptr + slen);
804 newicon = WMCreatePLString(fixedpath);
805 WMPutInPLDictionary(props, iconkey, newicon);
806 WMReleasePropList(newicon);
807 wfree(fixedpath);
812 WMReleasePropList(allApps);
813 WMReleasePropList(iconkey);
815 return changed;
818 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
820 WMPropList *menu = menuDomain->dictionary;
821 WMPropList *submenu;
823 if (!menu || !WMIsPLArray(menu))
824 return;
826 #ifdef GLOBAL_PREAMBLE_MENU_FILE
827 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
829 if (submenu && !WMIsPLArray(submenu)) {
830 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
831 WMReleasePropList(submenu);
832 submenu = NULL;
834 if (submenu) {
835 prependMenu(menu, submenu);
836 WMReleasePropList(submenu);
838 #endif
840 #ifdef GLOBAL_EPILOGUE_MENU_FILE
841 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
843 if (submenu && !WMIsPLArray(submenu)) {
844 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
845 WMReleasePropList(submenu);
846 submenu = NULL;
848 if (submenu) {
849 appendMenu(menu, submenu);
850 WMReleasePropList(submenu);
852 #endif
854 menuDomain->dictionary = menu;
857 #if 0
858 WMPropList *wDefaultsInit(int screen_number)
860 static int defaults_inited = 0;
861 WMPropList *dict;
863 if (!defaults_inited) {
864 initDefaults();
867 dict = PLGetDomain(wDomainName);
868 if (!dict) {
869 wwarning(_("could not read domain \"%s\" from defaults database"), WMGetFromPLString(wDomainName));
872 return dict;
874 #endif
876 void wDefaultsDestroyDomain(WDDomain * domain)
878 if (domain->dictionary)
879 WMReleasePropList(domain->dictionary);
880 wfree(domain->path);
881 wfree(domain);
884 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
886 WDDomain *db;
887 struct stat stbuf;
888 static int inited = 0;
889 char path[PATH_MAX];
890 char *the_path;
891 WMPropList *shared_dict = NULL;
893 if (!inited) {
894 inited = 1;
895 initDefaults();
898 db = wmalloc(sizeof(WDDomain));
899 memset(db, 0, sizeof(WDDomain));
900 db->domain_name = domain;
901 db->path = wdefaultspathfordomain(domain);
902 the_path = db->path;
904 if (the_path && stat(the_path, &stbuf) >= 0) {
905 db->dictionary = WMReadPropListFromFile(the_path);
906 if (db->dictionary) {
907 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
908 WMReleasePropList(db->dictionary);
909 db->dictionary = NULL;
910 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
912 if (strcmp(domain, "WMWindowAttributes") == 0 && db->dictionary) {
913 if (fixupCachedPixmapsPaths(db->dictionary)) {
914 WMWritePropListToFile(db->dictionary, db->path, True);
915 /* re-read the timestamp. if this fails take current time */
916 if (stat(db->path, &stbuf) < 0) {
917 stbuf.st_mtime = time(NULL);
921 db->timestamp = stbuf.st_mtime;
922 } else {
923 wwarning(_("could not load domain %s from user defaults database"), domain);
927 /* global system dictionary */
928 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
929 if (stat(path, &stbuf) >= 0) {
930 shared_dict = WMReadPropListFromFile(path);
931 if (shared_dict) {
932 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
933 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
934 domain, path);
935 WMReleasePropList(shared_dict);
936 shared_dict = NULL;
937 } else {
938 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
939 WMIsPLDictionary(db->dictionary)) {
940 WMMergePLDictionaries(shared_dict, db->dictionary, True);
941 WMReleasePropList(db->dictionary);
942 db->dictionary = shared_dict;
943 if (stbuf.st_mtime > db->timestamp)
944 db->timestamp = stbuf.st_mtime;
945 } else if (!db->dictionary) {
946 db->dictionary = shared_dict;
947 if (stbuf.st_mtime > db->timestamp)
948 db->timestamp = stbuf.st_mtime;
951 } else {
952 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
956 return db;
959 void wReadStaticDefaults(WMPropList * dict)
961 WMPropList *plvalue;
962 WDefaultEntry *entry;
963 unsigned int i;
964 void *tdata;
966 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
967 entry = &staticOptionList[i];
969 if (dict)
970 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
971 else
972 plvalue = NULL;
974 if (!plvalue) {
975 /* no default in the DB. Use builtin default */
976 plvalue = entry->plvalue;
979 if (plvalue) {
980 /* convert data */
981 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
982 if (entry->update) {
983 (*entry->update) (NULL, entry, tdata, entry->extra_data);
989 void wDefaultsCheckDomains(void)
991 WScreen *scr;
992 struct stat stbuf;
993 WMPropList *shared_dict = NULL;
994 WMPropList *dict;
995 int i;
997 #ifdef HEARTBEAT
998 puts("Checking domains...");
999 #endif
1000 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1001 #ifdef HEARTBEAT
1002 puts("Checking WindowMaker domain");
1003 #endif
1004 WDWindowMaker->timestamp = stbuf.st_mtime;
1006 /* global dictionary */
1007 shared_dict = readGlobalDomain("WindowMaker", True);
1008 /* user dictionary */
1009 dict = WMReadPropListFromFile(WDWindowMaker->path);
1010 if (dict) {
1011 if (!WMIsPLDictionary(dict)) {
1012 WMReleasePropList(dict);
1013 dict = NULL;
1014 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1015 "WindowMaker", WDWindowMaker->path);
1016 } else {
1017 if (shared_dict) {
1018 WMMergePLDictionaries(shared_dict, dict, True);
1019 WMReleasePropList(dict);
1020 dict = shared_dict;
1021 shared_dict = NULL;
1023 for (i = 0; i < wScreenCount; i++) {
1024 scr = wScreenWithNumber(i);
1025 if (scr)
1026 wReadDefaults(scr, dict);
1028 if (WDWindowMaker->dictionary) {
1029 WMReleasePropList(WDWindowMaker->dictionary);
1031 WDWindowMaker->dictionary = dict;
1033 } else {
1034 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1036 if (shared_dict) {
1037 WMReleasePropList(shared_dict);
1041 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1042 #ifdef HEARTBEAT
1043 puts("Checking WMWindowAttributes domain");
1044 #endif
1045 /* global dictionary */
1046 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1047 /* user dictionary */
1048 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1049 if (dict) {
1050 if (!WMIsPLDictionary(dict)) {
1051 WMReleasePropList(dict);
1052 dict = NULL;
1053 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1054 "WMWindowAttributes", WDWindowAttributes->path);
1055 } else {
1056 if (shared_dict) {
1057 WMMergePLDictionaries(shared_dict, dict, True);
1058 WMReleasePropList(dict);
1059 dict = shared_dict;
1060 shared_dict = NULL;
1062 if (WDWindowAttributes->dictionary) {
1063 WMReleasePropList(WDWindowAttributes->dictionary);
1065 WDWindowAttributes->dictionary = dict;
1066 for (i = 0; i < wScreenCount; i++) {
1067 scr = wScreenWithNumber(i);
1068 if (scr) {
1069 RImage *image;
1071 wDefaultUpdateIcons(scr);
1073 /* Update the panel image if changed */
1074 /* Don't worry. If the image is the same these
1075 * functions will have no performance impact. */
1076 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1078 if (!image) {
1079 wwarning(_("could not load logo image for panels: %s"),
1080 RMessageForError(RErrorCode));
1081 } else {
1082 WMSetApplicationIconImage(scr->wmscreen, image);
1083 RReleaseImage(image);
1088 } else {
1089 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1091 WDWindowAttributes->timestamp = stbuf.st_mtime;
1092 if (shared_dict) {
1093 WMReleasePropList(shared_dict);
1097 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1098 dict = WMReadPropListFromFile(WDRootMenu->path);
1099 #ifdef HEARTBEAT
1100 puts("Checking WMRootMenu domain");
1101 #endif
1102 if (dict) {
1103 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1104 WMReleasePropList(dict);
1105 dict = NULL;
1106 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1107 "WMRootMenu", WDRootMenu->path);
1108 } else {
1109 if (WDRootMenu->dictionary) {
1110 WMReleasePropList(WDRootMenu->dictionary);
1112 WDRootMenu->dictionary = dict;
1113 wDefaultsMergeGlobalMenus(WDRootMenu);
1115 } else {
1116 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1118 WDRootMenu->timestamp = stbuf.st_mtime;
1122 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1124 WMPropList *plvalue, *old_value;
1125 WDefaultEntry *entry;
1126 unsigned int i, must_update;
1127 int update_workspace_back = 0; /* kluge :/ */
1128 unsigned int needs_refresh;
1129 void *tdata;
1130 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1132 must_update = 0;
1134 needs_refresh = 0;
1136 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1137 entry = &optionList[i];
1139 if (new_dict)
1140 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1141 else
1142 plvalue = NULL;
1144 if (!old_dict)
1145 old_value = NULL;
1146 else
1147 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1149 if (!plvalue && !old_value) {
1150 /* no default in the DB. Use builtin default */
1151 plvalue = entry->plvalue;
1152 if (plvalue && new_dict) {
1153 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1154 must_update = 1;
1156 } else if (!plvalue) {
1157 /* value was deleted from DB. Keep current value */
1158 continue;
1159 } else if (!old_value) {
1160 /* set value for the 1st time */
1161 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1162 /* value has changed */
1163 } else {
1165 if (strcmp(entry->key, "WorkspaceBack") == 0
1166 && update_workspace_back && scr->flags.backimage_helper_launched) {
1167 } else {
1168 /* value was not changed since last time */
1169 continue;
1173 if (plvalue) {
1174 #ifdef DEBUG
1175 printf("Updating %s to %s\n", entry->key, WMGetPropListDescription(plvalue, False));
1176 #endif
1177 /* convert data */
1178 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1180 * If the WorkspaceSpecificBack data has been changed
1181 * so that the helper will be launched now, we must be
1182 * sure to send the default background texture config
1183 * to the helper.
1185 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1186 && !scr->flags.backimage_helper_launched) {
1187 update_workspace_back = 1;
1189 if (entry->update) {
1190 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1196 if (needs_refresh != 0 && !scr->flags.startup) {
1197 int foo;
1199 foo = 0;
1200 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1201 foo |= WTextureSettings;
1202 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1203 foo |= WFontSettings;
1204 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1205 foo |= WColorSettings;
1206 if (foo)
1207 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1208 (void *)(uintptr_t) foo);
1210 foo = 0;
1211 if (needs_refresh & REFRESH_MENU_TEXTURE)
1212 foo |= WTextureSettings;
1213 if (needs_refresh & REFRESH_MENU_FONT)
1214 foo |= WFontSettings;
1215 if (needs_refresh & REFRESH_MENU_COLOR)
1216 foo |= WColorSettings;
1217 if (foo)
1218 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1220 foo = 0;
1221 if (needs_refresh & REFRESH_WINDOW_FONT) {
1222 foo |= WFontSettings;
1224 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1225 foo |= WTextureSettings;
1227 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1228 foo |= WColorSettings;
1230 if (foo)
1231 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1233 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1234 foo = 0;
1235 if (needs_refresh & REFRESH_ICON_FONT) {
1236 foo |= WFontSettings;
1238 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1239 foo |= WTextureSettings;
1241 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1242 foo |= WTextureSettings;
1244 if (foo)
1245 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1246 (void *)(uintptr_t) foo);
1248 if (needs_refresh & REFRESH_ICON_TILE)
1249 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1253 void wDefaultUpdateIcons(WScreen * scr)
1255 WAppIcon *aicon = scr->app_icon_list;
1256 WWindow *wwin = scr->focused_window;
1257 char *file;
1259 while (aicon) {
1260 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1261 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1262 || (file && !aicon->icon->file)) {
1263 RImage *new_image;
1265 if (aicon->icon->file)
1266 wfree(aicon->icon->file);
1267 aicon->icon->file = wstrdup(file);
1269 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1270 if (new_image) {
1271 wIconChangeImage(aicon->icon, new_image);
1272 wAppIconPaint(aicon);
1275 aicon = aicon->next;
1278 if (!wPreferences.flags.noclip)
1279 wClipIconPaint(scr->clip_icon);
1281 while (wwin) {
1282 if (wwin->icon && wwin->flags.miniaturized) {
1283 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1284 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1285 || (file && !wwin->icon->file)) {
1286 RImage *new_image;
1288 if (wwin->icon->file)
1289 wfree(wwin->icon->file);
1290 wwin->icon->file = wstrdup(file);
1292 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1293 if (new_image)
1294 wIconChangeImage(wwin->icon, new_image);
1297 wwin = wwin->prev;
1301 /* --------------------------- Local ----------------------- */
1303 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1304 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1305 entry->key, x); \
1306 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1307 var = entry->default_value;\
1308 } else var = WMGetFromPLString(value)\
1311 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1313 char *str;
1314 WOptionEnumeration *v;
1315 char buffer[TOTAL_VALUES_LENGTH];
1317 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1318 for (v = values; v->string != NULL; v++) {
1319 if (strcasecmp(v->string, str) == 0)
1320 return v->value;
1324 buffer[0] = 0;
1325 for (v = values; v->string != NULL; v++) {
1326 if (!v->is_alias) {
1327 if (buffer[0] != 0)
1328 strcat(buffer, ", ");
1329 strcat(buffer, v->string);
1332 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1334 if (def) {
1335 return string2index(key, val, NULL, values);
1338 return -1;
1342 * value - is the value in the defaults DB
1343 * addr - is the address to store the data
1344 * ret - is the address to store a pointer to a temporary buffer. ret
1345 * must not be freed and is used by the set functions
1347 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1349 static char data;
1350 char *val;
1351 int second_pass = 0;
1353 GET_STRING_OR_DEFAULT("Boolean", val);
1355 again:
1356 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1357 || strcasecmp(val, "YES") == 0) {
1359 data = 1;
1360 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1361 || strcasecmp(val, "NO") == 0) {
1362 data = 0;
1363 } else {
1364 int i;
1365 if (sscanf(val, "%i", &i) == 1) {
1366 if (i != 0)
1367 data = 1;
1368 else
1369 data = 0;
1370 } else {
1371 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1372 if (second_pass == 0) {
1373 val = WMGetFromPLString(entry->plvalue);
1374 second_pass = 1;
1375 wwarning(_("using default \"%s\" instead"), val);
1376 goto again;
1378 return False;
1382 if (ret)
1383 *ret = &data;
1384 if (addr)
1385 *(char *)addr = data;
1387 return True;
1390 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1392 static int data;
1393 char *val;
1395 GET_STRING_OR_DEFAULT("Integer", val);
1397 if (sscanf(val, "%i", &data) != 1) {
1398 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1399 val = WMGetFromPLString(entry->plvalue);
1400 wwarning(_("using default \"%s\" instead"), val);
1401 if (sscanf(val, "%i", &data) != 1) {
1402 return False;
1406 if (ret)
1407 *ret = &data;
1408 if (addr)
1409 *(int *)addr = data;
1411 return True;
1414 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1416 static WCoord data;
1417 char *val_x, *val_y;
1418 int nelem, changed = 0;
1419 WMPropList *elem_x, *elem_y;
1421 again:
1422 if (!WMIsPLArray(value)) {
1423 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1424 if (changed == 0) {
1425 value = entry->plvalue;
1426 changed = 1;
1427 wwarning(_("using default \"%s\" instead"), entry->default_value);
1428 goto again;
1430 return False;
1433 nelem = WMGetPropListItemCount(value);
1434 if (nelem != 2) {
1435 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1436 if (changed == 0) {
1437 value = entry->plvalue;
1438 changed = 1;
1439 wwarning(_("using default \"%s\" instead"), entry->default_value);
1440 goto again;
1442 return False;
1445 elem_x = WMGetFromPLArray(value, 0);
1446 elem_y = WMGetFromPLArray(value, 1);
1448 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1449 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1450 if (changed == 0) {
1451 value = entry->plvalue;
1452 changed = 1;
1453 wwarning(_("using default \"%s\" instead"), entry->default_value);
1454 goto again;
1456 return False;
1459 val_x = WMGetFromPLString(elem_x);
1460 val_y = WMGetFromPLString(elem_y);
1462 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1463 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1464 if (changed == 0) {
1465 value = entry->plvalue;
1466 changed = 1;
1467 wwarning(_("using default \"%s\" instead"), entry->default_value);
1468 goto again;
1470 return False;
1473 if (data.x < 0)
1474 data.x = 0;
1475 else if (data.x > scr->scr_width / 3)
1476 data.x = scr->scr_width / 3;
1477 if (data.y < 0)
1478 data.y = 0;
1479 else if (data.y > scr->scr_height / 3)
1480 data.y = scr->scr_height / 3;
1482 if (ret)
1483 *ret = &data;
1484 if (addr)
1485 *(WCoord *) addr = data;
1487 return True;
1490 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1492 WMRetainPropList(value);
1494 *ret = value;
1496 return True;
1499 #if 0
1500 /* This function is not used at the moment. */
1501 static int getString(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1503 static char *data;
1505 GET_STRING_OR_DEFAULT("String", data);
1507 if (!data) {
1508 data = WMGetFromPLString(entry->plvalue);
1509 if (!data)
1510 return False;
1513 if (ret)
1514 *ret = &data;
1515 if (addr)
1516 *(char **)addr = wstrdup(data);
1518 return True;
1520 #endif
1522 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1524 static char *data;
1525 int i, count, len;
1526 char *ptr;
1527 WMPropList *d;
1528 int changed = 0;
1530 again:
1531 if (!WMIsPLArray(value)) {
1532 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1533 if (changed == 0) {
1534 value = entry->plvalue;
1535 changed = 1;
1536 wwarning(_("using default \"%s\" instead"), entry->default_value);
1537 goto again;
1539 return False;
1542 i = 0;
1543 count = WMGetPropListItemCount(value);
1544 if (count < 1) {
1545 if (changed == 0) {
1546 value = entry->plvalue;
1547 changed = 1;
1548 wwarning(_("using default \"%s\" instead"), entry->default_value);
1549 goto again;
1551 return False;
1554 len = 0;
1555 for (i = 0; i < count; i++) {
1556 d = WMGetFromPLArray(value, i);
1557 if (!d || !WMIsPLString(d)) {
1558 count = i;
1559 break;
1561 len += strlen(WMGetFromPLString(d)) + 1;
1564 ptr = data = wmalloc(len + 1);
1566 for (i = 0; i < count; i++) {
1567 d = WMGetFromPLArray(value, i);
1568 if (!d || !WMIsPLString(d)) {
1569 break;
1571 strcpy(ptr, WMGetFromPLString(d));
1572 ptr += strlen(WMGetFromPLString(d));
1573 *ptr = ':';
1574 ptr++;
1576 ptr--;
1577 *(ptr--) = 0;
1579 if (*(char **)addr != NULL) {
1580 wfree(*(char **)addr);
1582 *(char **)addr = data;
1584 return True;
1587 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1589 static signed char data;
1591 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1592 if (data < 0)
1593 return False;
1595 if (ret)
1596 *ret = &data;
1597 if (addr)
1598 *(signed char *)addr = data;
1600 return True;
1604 * (solid <color>)
1605 * (hgradient <color> <color>)
1606 * (vgradient <color> <color>)
1607 * (dgradient <color> <color>)
1608 * (mhgradient <color> <color> ...)
1609 * (mvgradient <color> <color> ...)
1610 * (mdgradient <color> <color> ...)
1611 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1612 * (tpixmap <file> <color>)
1613 * (spixmap <file> <color>)
1614 * (cpixmap <file> <color>)
1615 * (thgradient <file> <opaqueness> <color> <color>)
1616 * (tvgradient <file> <opaqueness> <color> <color>)
1617 * (tdgradient <file> <opaqueness> <color> <color>)
1618 * (function <lib> <function> ...)
1621 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1623 WMPropList *elem;
1624 char *val;
1625 int nelem;
1626 WTexture *texture = NULL;
1628 nelem = WMGetPropListItemCount(pl);
1629 if (nelem < 1)
1630 return NULL;
1632 elem = WMGetFromPLArray(pl, 0);
1633 if (!elem || !WMIsPLString(elem))
1634 return NULL;
1635 val = WMGetFromPLString(elem);
1637 if (strcasecmp(val, "solid") == 0) {
1638 XColor color;
1640 if (nelem != 2)
1641 return NULL;
1643 /* get color */
1645 elem = WMGetFromPLArray(pl, 1);
1646 if (!elem || !WMIsPLString(elem))
1647 return NULL;
1648 val = WMGetFromPLString(elem);
1650 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1651 wwarning(_("\"%s\" is not a valid color name"), val);
1652 return NULL;
1655 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1656 } else if (strcasecmp(val, "dgradient") == 0
1657 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1658 RColor color1, color2;
1659 XColor xcolor;
1660 int type;
1662 if (nelem != 3) {
1663 wwarning(_("bad number of arguments in gradient specification"));
1664 return NULL;
1667 if (val[0] == 'd' || val[0] == 'D')
1668 type = WTEX_DGRADIENT;
1669 else if (val[0] == 'h' || val[0] == 'H')
1670 type = WTEX_HGRADIENT;
1671 else
1672 type = WTEX_VGRADIENT;
1674 /* get from color */
1675 elem = WMGetFromPLArray(pl, 1);
1676 if (!elem || !WMIsPLString(elem))
1677 return NULL;
1678 val = WMGetFromPLString(elem);
1680 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1681 wwarning(_("\"%s\" is not a valid color name"), val);
1682 return NULL;
1684 color1.alpha = 255;
1685 color1.red = xcolor.red >> 8;
1686 color1.green = xcolor.green >> 8;
1687 color1.blue = xcolor.blue >> 8;
1689 /* get to color */
1690 elem = WMGetFromPLArray(pl, 2);
1691 if (!elem || !WMIsPLString(elem)) {
1692 return NULL;
1694 val = WMGetFromPLString(elem);
1696 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1697 wwarning(_("\"%s\" is not a valid color name"), val);
1698 return NULL;
1700 color2.alpha = 255;
1701 color2.red = xcolor.red >> 8;
1702 color2.green = xcolor.green >> 8;
1703 color2.blue = xcolor.blue >> 8;
1705 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1707 } else if (strcasecmp(val, "igradient") == 0) {
1708 RColor colors1[2], colors2[2];
1709 int th1, th2;
1710 XColor xcolor;
1711 int i;
1713 if (nelem != 7) {
1714 wwarning(_("bad number of arguments in gradient specification"));
1715 return NULL;
1718 /* get from color */
1719 for (i = 0; i < 2; i++) {
1720 elem = WMGetFromPLArray(pl, 1 + i);
1721 if (!elem || !WMIsPLString(elem))
1722 return NULL;
1723 val = WMGetFromPLString(elem);
1725 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1726 wwarning(_("\"%s\" is not a valid color name"), val);
1727 return NULL;
1729 colors1[i].alpha = 255;
1730 colors1[i].red = xcolor.red >> 8;
1731 colors1[i].green = xcolor.green >> 8;
1732 colors1[i].blue = xcolor.blue >> 8;
1734 elem = WMGetFromPLArray(pl, 3);
1735 if (!elem || !WMIsPLString(elem))
1736 return NULL;
1737 val = WMGetFromPLString(elem);
1738 th1 = atoi(val);
1740 /* get from color */
1741 for (i = 0; i < 2; i++) {
1742 elem = WMGetFromPLArray(pl, 4 + i);
1743 if (!elem || !WMIsPLString(elem))
1744 return NULL;
1745 val = WMGetFromPLString(elem);
1747 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1748 wwarning(_("\"%s\" is not a valid color name"), val);
1749 return NULL;
1751 colors2[i].alpha = 255;
1752 colors2[i].red = xcolor.red >> 8;
1753 colors2[i].green = xcolor.green >> 8;
1754 colors2[i].blue = xcolor.blue >> 8;
1756 elem = WMGetFromPLArray(pl, 6);
1757 if (!elem || !WMIsPLString(elem))
1758 return NULL;
1759 val = WMGetFromPLString(elem);
1760 th2 = atoi(val);
1762 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1764 } else if (strcasecmp(val, "mhgradient") == 0
1765 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1766 XColor color;
1767 RColor **colors;
1768 int i, count;
1769 int type;
1771 if (nelem < 3) {
1772 wwarning(_("too few arguments in multicolor gradient specification"));
1773 return NULL;
1776 if (val[1] == 'h' || val[1] == 'H')
1777 type = WTEX_MHGRADIENT;
1778 else if (val[1] == 'v' || val[1] == 'V')
1779 type = WTEX_MVGRADIENT;
1780 else
1781 type = WTEX_MDGRADIENT;
1783 count = nelem - 1;
1785 colors = wmalloc(sizeof(RColor *) * (count + 1));
1787 for (i = 0; i < count; i++) {
1788 elem = WMGetFromPLArray(pl, i + 1);
1789 if (!elem || !WMIsPLString(elem)) {
1790 for (--i; i >= 0; --i) {
1791 wfree(colors[i]);
1793 wfree(colors);
1794 return NULL;
1796 val = WMGetFromPLString(elem);
1798 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1799 wwarning(_("\"%s\" is not a valid color name"), val);
1800 for (--i; i >= 0; --i) {
1801 wfree(colors[i]);
1803 wfree(colors);
1804 return NULL;
1805 } else {
1806 colors[i] = wmalloc(sizeof(RColor));
1807 colors[i]->red = color.red >> 8;
1808 colors[i]->green = color.green >> 8;
1809 colors[i]->blue = color.blue >> 8;
1812 colors[i] = NULL;
1814 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1815 } else if (strcasecmp(val, "spixmap") == 0 ||
1816 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1817 XColor color;
1818 int type;
1820 if (nelem != 3)
1821 return NULL;
1823 if (val[0] == 's' || val[0] == 'S')
1824 type = WTP_SCALE;
1825 else if (val[0] == 'c' || val[0] == 'C')
1826 type = WTP_CENTER;
1827 else
1828 type = WTP_TILE;
1830 /* get color */
1831 elem = WMGetFromPLArray(pl, 2);
1832 if (!elem || !WMIsPLString(elem)) {
1833 return NULL;
1835 val = WMGetFromPLString(elem);
1837 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1838 wwarning(_("\"%s\" is not a valid color name"), val);
1839 return NULL;
1842 /* file name */
1843 elem = WMGetFromPLArray(pl, 1);
1844 if (!elem || !WMIsPLString(elem))
1845 return NULL;
1846 val = WMGetFromPLString(elem);
1848 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1849 } else if (strcasecmp(val, "thgradient") == 0
1850 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1851 RColor color1, color2;
1852 XColor xcolor;
1853 int opacity;
1854 int style;
1856 if (val[1] == 'h' || val[1] == 'H')
1857 style = WTEX_THGRADIENT;
1858 else if (val[1] == 'v' || val[1] == 'V')
1859 style = WTEX_TVGRADIENT;
1860 else
1861 style = WTEX_TDGRADIENT;
1863 if (nelem != 5) {
1864 wwarning(_("bad number of arguments in textured gradient specification"));
1865 return NULL;
1868 /* get from color */
1869 elem = WMGetFromPLArray(pl, 3);
1870 if (!elem || !WMIsPLString(elem))
1871 return NULL;
1872 val = WMGetFromPLString(elem);
1874 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1875 wwarning(_("\"%s\" is not a valid color name"), val);
1876 return NULL;
1878 color1.alpha = 255;
1879 color1.red = xcolor.red >> 8;
1880 color1.green = xcolor.green >> 8;
1881 color1.blue = xcolor.blue >> 8;
1883 /* get to color */
1884 elem = WMGetFromPLArray(pl, 4);
1885 if (!elem || !WMIsPLString(elem)) {
1886 return NULL;
1888 val = WMGetFromPLString(elem);
1890 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1891 wwarning(_("\"%s\" is not a valid color name"), val);
1892 return NULL;
1894 color2.alpha = 255;
1895 color2.red = xcolor.red >> 8;
1896 color2.green = xcolor.green >> 8;
1897 color2.blue = xcolor.blue >> 8;
1899 /* get opacity */
1900 elem = WMGetFromPLArray(pl, 2);
1901 if (!elem || !WMIsPLString(elem))
1902 opacity = 128;
1903 else
1904 val = WMGetFromPLString(elem);
1906 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1907 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1908 opacity = 128;
1911 /* get file name */
1912 elem = WMGetFromPLArray(pl, 1);
1913 if (!elem || !WMIsPLString(elem))
1914 return NULL;
1915 val = WMGetFromPLString(elem);
1917 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1919 #ifdef TEXTURE_PLUGIN
1920 else if (strcasecmp(val, "function") == 0) {
1921 WTexFunction *function;
1922 void (*initFunc) (Display *, Colormap);
1923 char *lib, *func, **argv;
1924 int i, argc;
1926 if (nelem < 3)
1927 return NULL;
1929 /* get the library name */
1930 elem = WMGetFromPLArray(pl, 1);
1931 if (!elem || !WMIsPLString(elem)) {
1932 return NULL;
1934 lib = WMGetFromPLString(elem);
1936 /* get the function name */
1937 elem = WMGetFromPLArray(pl, 2);
1938 if (!elem || !WMIsPLString(elem)) {
1939 return NULL;
1941 func = WMGetFromPLString(elem);
1943 argc = nelem - 2;
1944 argv = (char **)wmalloc(argc * sizeof(char *));
1946 /* get the parameters */
1947 argv[0] = wstrdup(func);
1948 for (i = 0; i < argc - 1; i++) {
1949 elem = WMGetFromPLArray(pl, 3 + i);
1950 if (!elem || !WMIsPLString(elem)) {
1951 wfree(argv);
1953 return NULL;
1955 argv[i + 1] = wstrdup(WMGetFromPLString(elem));
1958 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1960 #ifdef HAVE_DLFCN_H
1961 if (function) {
1962 initFunc = dlsym(function->handle, "initWindowMaker");
1963 if (initFunc) {
1964 initFunc(dpy, scr->w_colormap);
1965 } else {
1966 wwarning(_("could not initialize library %s"), lib);
1968 } else {
1969 wwarning(_("could not find function %s::%s"), lib, func);
1971 #endif /* HAVE_DLFCN_H */
1972 texture = (WTexture *) function;
1974 #endif /* TEXTURE_PLUGIN */
1975 else {
1976 wwarning(_("invalid texture type %s"), val);
1977 return NULL;
1979 return texture;
1982 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1984 static WTexture *texture;
1985 int changed = 0;
1987 again:
1988 if (!WMIsPLArray(value)) {
1989 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1990 if (changed == 0) {
1991 value = entry->plvalue;
1992 changed = 1;
1993 wwarning(_("using default \"%s\" instead"), entry->default_value);
1994 goto again;
1996 return False;
1999 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
2000 WMPropList *pl;
2002 pl = WMGetFromPLArray(value, 0);
2003 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2004 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
2005 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2006 entry->key, "Solid Texture");
2008 value = entry->plvalue;
2009 changed = 1;
2010 wwarning(_("using default \"%s\" instead"), entry->default_value);
2011 goto again;
2015 texture = parse_texture(scr, value);
2017 if (!texture) {
2018 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
2019 if (changed == 0) {
2020 value = entry->plvalue;
2021 changed = 1;
2022 wwarning(_("using default \"%s\" instead"), entry->default_value);
2023 goto again;
2025 return False;
2028 if (ret)
2029 *ret = &texture;
2031 if (addr)
2032 *(WTexture **) addr = texture;
2034 return True;
2037 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2039 WMPropList *elem;
2040 int changed = 0;
2041 char *val;
2042 int nelem;
2044 again:
2045 if (!WMIsPLArray(value)) {
2046 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2047 "WorkspaceBack", "Texture or None");
2048 if (changed == 0) {
2049 value = entry->plvalue;
2050 changed = 1;
2051 wwarning(_("using default \"%s\" instead"), entry->default_value);
2052 goto again;
2054 return False;
2057 /* only do basic error checking and verify for None texture */
2059 nelem = WMGetPropListItemCount(value);
2060 if (nelem > 0) {
2061 elem = WMGetFromPLArray(value, 0);
2062 if (!elem || !WMIsPLString(elem)) {
2063 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2064 if (changed == 0) {
2065 value = entry->plvalue;
2066 changed = 1;
2067 wwarning(_("using default \"%s\" instead"), entry->default_value);
2068 goto again;
2070 return False;
2072 val = WMGetFromPLString(elem);
2074 if (strcasecmp(val, "None") == 0)
2075 return True;
2077 *ret = WMRetainPropList(value);
2079 return True;
2082 static int
2083 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2085 WMPropList *elem;
2086 int nelem;
2087 int changed = 0;
2089 again:
2090 if (!WMIsPLArray(value)) {
2091 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2092 "WorkspaceSpecificBack", "an array of textures");
2093 if (changed == 0) {
2094 value = entry->plvalue;
2095 changed = 1;
2096 wwarning(_("using default \"%s\" instead"), entry->default_value);
2097 goto again;
2099 return False;
2102 /* only do basic error checking and verify for None texture */
2104 nelem = WMGetPropListItemCount(value);
2105 if (nelem > 0) {
2106 while (nelem--) {
2107 elem = WMGetFromPLArray(value, nelem);
2108 if (!elem || !WMIsPLArray(elem)) {
2109 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2110 nelem);
2115 *ret = WMRetainPropList(value);
2117 #ifdef notworking
2119 * Kluge to force wmsetbg helper to set the default background.
2120 * If the WorkspaceSpecificBack is changed once wmaker has started,
2121 * the WorkspaceBack won't be sent to the helper, unless the user
2122 * changes it's value too. So, we must force this by removing the
2123 * value from the defaults DB.
2125 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2126 WMPropList *key = WMCreatePLString("WorkspaceBack");
2128 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2130 WMReleasePropList(key);
2132 #endif
2133 return True;
2136 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2138 static WMFont *font;
2139 char *val;
2141 GET_STRING_OR_DEFAULT("Font", val);
2143 font = WMCreateFont(scr->wmscreen, val);
2144 if (!font)
2145 font = WMCreateFont(scr->wmscreen, "fixed");
2147 if (!font) {
2148 wfatal(_("could not load any usable font!!!"));
2149 exit(1);
2152 if (ret)
2153 *ret = font;
2155 /* can't assign font value outside update function */
2156 wassertrv(addr == NULL, True);
2158 return True;
2161 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2163 static XColor color;
2164 char *val;
2165 int second_pass = 0;
2167 GET_STRING_OR_DEFAULT("Color", val);
2169 again:
2170 if (!wGetColor(scr, val, &color)) {
2171 wwarning(_("could not get color for key \"%s\""), entry->key);
2172 if (second_pass == 0) {
2173 val = WMGetFromPLString(entry->plvalue);
2174 second_pass = 1;
2175 wwarning(_("using default \"%s\" instead"), val);
2176 goto again;
2178 return False;
2181 if (ret)
2182 *ret = &color;
2184 assert(addr == NULL);
2186 if (addr)
2187 *(unsigned long*)addr = pixel;
2190 return True;
2193 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2195 static WShortKey shortcut;
2196 KeySym ksym;
2197 char *val;
2198 char *k;
2199 char buf[MAX_SHORTCUT_LENGTH], *b;
2201 GET_STRING_OR_DEFAULT("Key spec", val);
2203 if (!val || strcasecmp(val, "NONE") == 0) {
2204 shortcut.keycode = 0;
2205 shortcut.modifier = 0;
2206 if (ret)
2207 *ret = &shortcut;
2208 return True;
2211 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2213 b = (char *)buf;
2215 /* get modifiers */
2216 shortcut.modifier = 0;
2217 while ((k = strchr(b, '+')) != NULL) {
2218 int mod;
2220 *k = 0;
2221 mod = wXModifierFromKey(b);
2222 if (mod < 0) {
2223 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2224 return False;
2226 shortcut.modifier |= mod;
2228 b = k + 1;
2231 /* get key */
2232 ksym = XStringToKeysym(b);
2234 if (ksym == NoSymbol) {
2235 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2236 return False;
2239 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2240 if (shortcut.keycode == 0) {
2241 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2242 return False;
2245 if (ret)
2246 *ret = &shortcut;
2248 return True;
2251 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2253 static int mask;
2254 char *str;
2256 GET_STRING_OR_DEFAULT("Modifier Key", str);
2258 if (!str)
2259 return False;
2261 mask = wXModifierFromKey(str);
2262 if (mask < 0) {
2263 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2264 mask = 0;
2265 return False;
2268 if (addr)
2269 *(int *)addr = mask;
2271 if (ret)
2272 *ret = &mask;
2274 return True;
2277 # include <X11/cursorfont.h>
2278 typedef struct {
2279 char *name;
2280 int id;
2281 } WCursorLookup;
2283 #define CURSOR_ID_NONE (XC_num_glyphs)
2285 static WCursorLookup cursor_table[] = {
2286 {"X_cursor", XC_X_cursor},
2287 {"arrow", XC_arrow},
2288 {"based_arrow_down", XC_based_arrow_down},
2289 {"based_arrow_up", XC_based_arrow_up},
2290 {"boat", XC_boat},
2291 {"bogosity", XC_bogosity},
2292 {"bottom_left_corner", XC_bottom_left_corner},
2293 {"bottom_right_corner", XC_bottom_right_corner},
2294 {"bottom_side", XC_bottom_side},
2295 {"bottom_tee", XC_bottom_tee},
2296 {"box_spiral", XC_box_spiral},
2297 {"center_ptr", XC_center_ptr},
2298 {"circle", XC_circle},
2299 {"clock", XC_clock},
2300 {"coffee_mug", XC_coffee_mug},
2301 {"cross", XC_cross},
2302 {"cross_reverse", XC_cross_reverse},
2303 {"crosshair", XC_crosshair},
2304 {"diamond_cross", XC_diamond_cross},
2305 {"dot", XC_dot},
2306 {"dotbox", XC_dotbox},
2307 {"double_arrow", XC_double_arrow},
2308 {"draft_large", XC_draft_large},
2309 {"draft_small", XC_draft_small},
2310 {"draped_box", XC_draped_box},
2311 {"exchange", XC_exchange},
2312 {"fleur", XC_fleur},
2313 {"gobbler", XC_gobbler},
2314 {"gumby", XC_gumby},
2315 {"hand1", XC_hand1},
2316 {"hand2", XC_hand2},
2317 {"heart", XC_heart},
2318 {"icon", XC_icon},
2319 {"iron_cross", XC_iron_cross},
2320 {"left_ptr", XC_left_ptr},
2321 {"left_side", XC_left_side},
2322 {"left_tee", XC_left_tee},
2323 {"leftbutton", XC_leftbutton},
2324 {"ll_angle", XC_ll_angle},
2325 {"lr_angle", XC_lr_angle},
2326 {"man", XC_man},
2327 {"middlebutton", XC_middlebutton},
2328 {"mouse", XC_mouse},
2329 {"pencil", XC_pencil},
2330 {"pirate", XC_pirate},
2331 {"plus", XC_plus},
2332 {"question_arrow", XC_question_arrow},
2333 {"right_ptr", XC_right_ptr},
2334 {"right_side", XC_right_side},
2335 {"right_tee", XC_right_tee},
2336 {"rightbutton", XC_rightbutton},
2337 {"rtl_logo", XC_rtl_logo},
2338 {"sailboat", XC_sailboat},
2339 {"sb_down_arrow", XC_sb_down_arrow},
2340 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2341 {"sb_left_arrow", XC_sb_left_arrow},
2342 {"sb_right_arrow", XC_sb_right_arrow},
2343 {"sb_up_arrow", XC_sb_up_arrow},
2344 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2345 {"shuttle", XC_shuttle},
2346 {"sizing", XC_sizing},
2347 {"spider", XC_spider},
2348 {"spraycan", XC_spraycan},
2349 {"star", XC_star},
2350 {"target", XC_target},
2351 {"tcross", XC_tcross},
2352 {"top_left_arrow", XC_top_left_arrow},
2353 {"top_left_corner", XC_top_left_corner},
2354 {"top_right_corner", XC_top_right_corner},
2355 {"top_side", XC_top_side},
2356 {"top_tee", XC_top_tee},
2357 {"trek", XC_trek},
2358 {"ul_angle", XC_ul_angle},
2359 {"umbrella", XC_umbrella},
2360 {"ur_angle", XC_ur_angle},
2361 {"watch", XC_watch},
2362 {"xterm", XC_xterm},
2363 {NULL, CURSOR_ID_NONE}
2366 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2368 switch (status) {
2369 case BitmapOpenFailed:
2370 wwarning(_("failed to open bitmap file \"%s\""), filename);
2371 break;
2372 case BitmapFileInvalid:
2373 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2374 break;
2375 case BitmapNoMemory:
2376 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2377 break;
2378 case BitmapSuccess:
2379 XFreePixmap(dpy, bitmap);
2380 break;
2385 * (none)
2386 * (builtin, <cursor_name>)
2387 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2389 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2391 WMPropList *elem;
2392 char *val;
2393 int nelem;
2394 int status = 0;
2396 nelem = WMGetPropListItemCount(pl);
2397 if (nelem < 1) {
2398 return (status);
2400 elem = WMGetFromPLArray(pl, 0);
2401 if (!elem || !WMIsPLString(elem)) {
2402 return (status);
2404 val = WMGetFromPLString(elem);
2406 if (0 == strcasecmp(val, "none")) {
2407 status = 1;
2408 *cursor = None;
2409 } else if (0 == strcasecmp(val, "builtin")) {
2410 int i;
2411 int cursor_id = CURSOR_ID_NONE;
2413 if (2 != nelem) {
2414 wwarning(_("bad number of arguments in cursor specification"));
2415 return (status);
2417 elem = WMGetFromPLArray(pl, 1);
2418 if (!elem || !WMIsPLString(elem)) {
2419 return (status);
2421 val = WMGetFromPLString(elem);
2423 for (i = 0; NULL != cursor_table[i].name; i++) {
2424 if (0 == strcasecmp(val, cursor_table[i].name)) {
2425 cursor_id = cursor_table[i].id;
2426 break;
2429 if (CURSOR_ID_NONE == cursor_id) {
2430 wwarning(_("unknown builtin cursor name \"%s\""), val);
2431 } else {
2432 *cursor = XCreateFontCursor(dpy, cursor_id);
2433 status = 1;
2435 } else if (0 == strcasecmp(val, "bitmap")) {
2436 char *bitmap_name;
2437 char *mask_name;
2438 int bitmap_status;
2439 int mask_status;
2440 Pixmap bitmap;
2441 Pixmap mask;
2442 unsigned int w, h;
2443 int x, y;
2444 XColor fg, bg;
2446 if (3 != nelem) {
2447 wwarning(_("bad number of arguments in cursor specification"));
2448 return (status);
2450 elem = WMGetFromPLArray(pl, 1);
2451 if (!elem || !WMIsPLString(elem)) {
2452 return (status);
2454 val = WMGetFromPLString(elem);
2455 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2456 if (!bitmap_name) {
2457 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2458 return (status);
2460 elem = WMGetFromPLArray(pl, 2);
2461 if (!elem || !WMIsPLString(elem)) {
2462 wfree(bitmap_name);
2463 return (status);
2465 val = WMGetFromPLString(elem);
2466 mask_name = FindImage(wPreferences.pixmap_path, val);
2467 if (!mask_name) {
2468 wfree(bitmap_name);
2469 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2470 return (status);
2472 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2473 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2474 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2475 fg.pixel = scr->black_pixel;
2476 bg.pixel = scr->white_pixel;
2477 XQueryColor(dpy, scr->w_colormap, &fg);
2478 XQueryColor(dpy, scr->w_colormap, &bg);
2479 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2480 status = 1;
2482 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2483 check_bitmap_status(mask_status, mask_name, mask);
2484 wfree(bitmap_name);
2485 wfree(mask_name);
2487 return (status);
2490 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2492 static Cursor cursor;
2493 int status;
2494 int changed = 0;
2496 again:
2497 if (!WMIsPLArray(value)) {
2498 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2499 entry->key, "cursor specification");
2500 if (!changed) {
2501 value = entry->plvalue;
2502 changed = 1;
2503 wwarning(_("using default \"%s\" instead"), entry->default_value);
2504 goto again;
2506 return (False);
2508 status = parse_cursor(scr, value, &cursor);
2509 if (!status) {
2510 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2511 if (!changed) {
2512 value = entry->plvalue;
2513 changed = 1;
2514 wwarning(_("using default \"%s\" instead"), entry->default_value);
2515 goto again;
2517 return (False);
2519 if (ret) {
2520 *ret = &cursor;
2522 if (addr) {
2523 *(Cursor *) addr = cursor;
2525 return (True);
2528 #undef CURSOR_ID_NONE
2530 /* ---------------- value setting functions --------------- */
2531 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2533 return REFRESH_WINDOW_TITLE_COLOR;
2536 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2538 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2541 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2543 switch (which) {
2544 case WM_DOCK:
2545 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2546 break;
2547 case WM_CLIP:
2548 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2549 break;
2550 default:
2551 break;
2553 return 0;
2556 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2558 if (scr->workspaces) {
2559 wWorkspaceForceChange(scr, scr->current_workspace);
2560 wArrangeIcons(scr, False);
2562 return 0;
2565 #if not_used
2566 static int setPositive(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2568 if (*value <= 0)
2569 *(int *)foo = 1;
2571 return 0;
2573 #endif
2575 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2577 Pixmap pixmap;
2578 RImage *img;
2579 int reset = 0;
2581 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2582 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2583 ? WREL_ICON : WREL_FLAT);
2584 if (!img) {
2585 wwarning(_("could not render texture for icon background"));
2586 if (!entry->addr)
2587 wTextureDestroy(scr, *texture);
2588 return 0;
2590 RConvertImage(scr->rcontext, img, &pixmap);
2592 if (scr->icon_tile) {
2593 reset = 1;
2594 RReleaseImage(scr->icon_tile);
2595 XFreePixmap(dpy, scr->icon_tile_pixmap);
2598 scr->icon_tile = img;
2600 /* put the icon in the noticeboard hint */
2601 PropSetIconTileHint(scr, img);
2603 if (!wPreferences.flags.noclip) {
2604 if (scr->clip_tile) {
2605 RReleaseImage(scr->clip_tile);
2607 scr->clip_tile = wClipMakeTile(scr, img);
2610 scr->icon_tile_pixmap = pixmap;
2612 if (scr->def_icon_pixmap) {
2613 XFreePixmap(dpy, scr->def_icon_pixmap);
2614 scr->def_icon_pixmap = None;
2616 if (scr->def_ticon_pixmap) {
2617 XFreePixmap(dpy, scr->def_ticon_pixmap);
2618 scr->def_ticon_pixmap = None;
2621 if (scr->icon_back_texture) {
2622 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2624 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2626 if (scr->clip_balloon)
2627 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2630 * Free the texture as nobody else will use it, nor refer to it.
2632 if (!entry->addr)
2633 wTextureDestroy(scr, *texture);
2635 return (reset ? REFRESH_ICON_TILE : 0);
2638 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2640 if (scr->title_font) {
2641 WMReleaseFont(scr->title_font);
2643 scr->title_font = font;
2645 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2648 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2650 if (scr->menu_title_font) {
2651 WMReleaseFont(scr->menu_title_font);
2654 scr->menu_title_font = font;
2656 return REFRESH_MENU_TITLE_FONT;
2659 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2661 if (scr->menu_entry_font) {
2662 WMReleaseFont(scr->menu_entry_font);
2664 scr->menu_entry_font = font;
2666 return REFRESH_MENU_FONT;
2669 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2671 if (scr->icon_title_font) {
2672 WMReleaseFont(scr->icon_title_font);
2675 scr->icon_title_font = font;
2677 return REFRESH_ICON_FONT;
2680 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2682 if (scr->clip_title_font) {
2683 WMReleaseFont(scr->clip_title_font);
2686 scr->clip_title_font = font;
2688 return REFRESH_ICON_FONT;
2691 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2693 if (scr->workspace_name_font) {
2694 WMReleaseFont(scr->workspace_name_font);
2697 scr->workspace_name_font = font;
2699 return 0;
2702 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2704 if (scr->select_color)
2705 WMReleaseColor(scr->select_color);
2707 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2709 wFreeColor(scr, color->pixel);
2711 return REFRESH_MENU_COLOR;
2714 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2716 if (scr->select_text_color)
2717 WMReleaseColor(scr->select_text_color);
2719 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2721 wFreeColor(scr, color->pixel);
2723 return REFRESH_MENU_COLOR;
2726 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2728 if (scr->clip_title_color[widx])
2729 WMReleaseColor(scr->clip_title_color[widx]);
2730 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2731 #ifdef GRADIENT_CLIP_ARROW
2732 if (widx == CLIP_NORMAL) {
2733 RImage *image;
2734 RColor color1, color2;
2735 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2736 int as = pt - 15; /* 15 = 5+5+5 */
2738 FREE_PIXMAP(scr->clip_arrow_gradient);
2740 color1.red = (color->red >> 8) * 6 / 10;
2741 color1.green = (color->green >> 8) * 6 / 10;
2742 color1.blue = (color->blue >> 8) * 6 / 10;
2744 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2745 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2746 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2748 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2749 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2750 RReleaseImage(image);
2752 #endif /* GRADIENT_CLIP_ARROW */
2754 wFreeColor(scr, color->pixel);
2756 return REFRESH_ICON_TITLE_COLOR;
2759 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2761 if (scr->window_title_color[widx])
2762 WMReleaseColor(scr->window_title_color[widx]);
2764 scr->window_title_color[widx] =
2765 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2767 wFreeColor(scr, color->pixel);
2769 return REFRESH_WINDOW_TITLE_COLOR;
2772 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2774 if (scr->menu_title_color[0])
2775 WMReleaseColor(scr->menu_title_color[0]);
2777 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2779 wFreeColor(scr, color->pixel);
2781 return REFRESH_MENU_TITLE_COLOR;
2784 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2786 if (scr->mtext_color)
2787 WMReleaseColor(scr->mtext_color);
2789 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2791 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2792 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2793 } else {
2794 WMSetColorAlpha(scr->dtext_color, 0xffff);
2797 wFreeColor(scr, color->pixel);
2799 return REFRESH_MENU_COLOR;
2802 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2804 if (scr->dtext_color)
2805 WMReleaseColor(scr->dtext_color);
2807 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2809 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2810 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2811 } else {
2812 WMSetColorAlpha(scr->dtext_color, 0xffff);
2815 wFreeColor(scr, color->pixel);
2817 return REFRESH_MENU_COLOR;
2820 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2822 if (scr->icon_title_color)
2823 WMReleaseColor(scr->icon_title_color);
2824 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2826 wFreeColor(scr, color->pixel);
2828 return REFRESH_ICON_TITLE_COLOR;
2831 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2833 if (scr->icon_title_texture) {
2834 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2836 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2838 return REFRESH_ICON_TITLE_BACK;
2841 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2843 close(scr->helper_fd);
2844 scr->helper_fd = 0;
2845 scr->helper_pid = 0;
2846 scr->flags.backimage_helper_launched = 0;
2849 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2851 WMPropList *val;
2852 char *str;
2853 int i;
2855 if (scr->flags.backimage_helper_launched) {
2856 if (WMGetPropListItemCount(value) == 0) {
2857 SendHelperMessage(scr, 'C', 0, NULL);
2858 SendHelperMessage(scr, 'K', 0, NULL);
2860 WMReleasePropList(value);
2861 return 0;
2863 } else {
2864 pid_t pid;
2865 int filedes[2];
2867 if (WMGetPropListItemCount(value) == 0)
2868 return 0;
2870 if (pipe(filedes) < 0) {
2871 wsyserror("pipe() failed:can't set workspace specific background image");
2873 WMReleasePropList(value);
2874 return 0;
2877 pid = fork();
2878 if (pid < 0) {
2879 wsyserror("fork() failed:can't set workspace specific background image");
2880 if (close(filedes[0]) < 0)
2881 wsyserror("could not close pipe");
2882 if (close(filedes[1]) < 0)
2883 wsyserror("could not close pipe");
2885 } else if (pid == 0) {
2886 char *dither;
2888 SetupEnvironment(scr);
2890 if (close(0) < 0)
2891 wsyserror("could not close pipe");
2892 if (dup(filedes[0]) < 0) {
2893 wsyserror("dup() failed:can't set workspace specific background image");
2895 dither = wPreferences.no_dithering ? "-m" : "-d";
2896 if (wPreferences.smooth_workspace_back)
2897 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2898 else
2899 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2900 wsyserror("could not execute wmsetbg");
2901 exit(1);
2902 } else {
2904 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2905 wsyserror("error setting close-on-exec flag");
2907 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2908 wsyserror("error setting close-on-exec flag");
2911 scr->helper_fd = filedes[1];
2912 scr->helper_pid = pid;
2913 scr->flags.backimage_helper_launched = 1;
2915 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2917 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2922 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2923 val = WMGetFromPLArray(value, i);
2924 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2925 str = WMGetPropListDescription(val, False);
2927 SendHelperMessage(scr, 'S', i + 1, str);
2929 wfree(str);
2930 } else {
2931 SendHelperMessage(scr, 'U', i + 1, NULL);
2934 sleep(1);
2936 WMReleasePropList(value);
2937 return 0;
2940 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2942 if (scr->flags.backimage_helper_launched) {
2943 char *str;
2945 if (WMGetPropListItemCount(value) == 0) {
2946 SendHelperMessage(scr, 'U', 0, NULL);
2947 } else {
2948 /* set the default workspace background to this one */
2949 str = WMGetPropListDescription(value, False);
2950 if (str) {
2951 SendHelperMessage(scr, 'S', 0, str);
2952 wfree(str);
2953 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2954 } else {
2955 SendHelperMessage(scr, 'U', 0, NULL);
2958 } else if (WMGetPropListItemCount(value) > 0) {
2959 char *command;
2960 char *text;
2961 char *dither;
2962 int len;
2964 text = WMGetPropListDescription(value, False);
2965 len = strlen(text) + 40;
2966 command = wmalloc(len);
2967 dither = wPreferences.no_dithering ? "-m" : "-d";
2968 if (wPreferences.smooth_workspace_back)
2969 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2970 else
2971 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2972 wfree(text);
2973 ExecuteShellCommand(scr, command);
2974 wfree(command);
2976 WMReleasePropList(value);
2978 return 0;
2981 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2983 if (scr->widget_texture) {
2984 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2986 scr->widget_texture = *(WTexSolid **) texture;
2988 return 0;
2991 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2993 if (scr->window_title_texture[WS_FOCUSED]) {
2994 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2996 scr->window_title_texture[WS_FOCUSED] = *texture;
2998 return REFRESH_WINDOW_TEXTURES;
3001 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3003 if (scr->window_title_texture[WS_PFOCUSED]) {
3004 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3006 scr->window_title_texture[WS_PFOCUSED] = *texture;
3008 return REFRESH_WINDOW_TEXTURES;
3011 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3013 if (scr->window_title_texture[WS_UNFOCUSED]) {
3014 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3016 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3018 return REFRESH_WINDOW_TEXTURES;
3021 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3023 if (scr->resizebar_texture[0]) {
3024 wTextureDestroy(scr, scr->resizebar_texture[0]);
3026 scr->resizebar_texture[0] = *texture;
3028 return REFRESH_WINDOW_TEXTURES;
3031 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3033 if (scr->menu_title_texture[0]) {
3034 wTextureDestroy(scr, scr->menu_title_texture[0]);
3036 scr->menu_title_texture[0] = *texture;
3038 return REFRESH_MENU_TITLE_TEXTURE;
3041 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3043 if (scr->menu_item_texture) {
3044 wTextureDestroy(scr, scr->menu_item_texture);
3045 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3047 scr->menu_item_texture = *texture;
3049 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3051 return REFRESH_MENU_TEXTURE;
3054 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
3056 WWindow *wwin;
3057 wKeyBindings[widx] = *shortcut;
3059 wwin = scr->focused_window;
3061 while (wwin != NULL) {
3062 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3064 if (!WFLAGP(wwin, no_bind_keys)) {
3065 wWindowSetKeyGrabs(wwin);
3067 wwin = wwin->prev;
3070 return 0;
3073 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3075 wScreenUpdateUsableArea(scr);
3076 wArrangeIcons(scr, True);
3078 return 0;
3081 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3083 wScreenUpdateUsableArea(scr);
3085 return 0;
3088 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3090 return REFRESH_MENU_TEXTURE;
3093 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3095 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3097 RCopyArea(img, image, x, y, w, h, 0, 0);
3099 return img;
3102 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
3104 char *path;
3105 RImage *bgimage;
3106 int cwidth, cheight;
3107 WPreferences *prefs = (WPreferences *) foo;
3109 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3110 if (prefs->swtileImage)
3111 RReleaseImage(prefs->swtileImage);
3112 prefs->swtileImage = NULL;
3114 WMReleasePropList(array);
3115 return 0;
3118 switch (WMGetPropListItemCount(array)) {
3119 case 4:
3120 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3121 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3122 break;
3123 } else
3124 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3126 if (!path) {
3127 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3128 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3129 } else {
3130 bgimage = RLoadImage(scr->rcontext, path, 0);
3131 if (!bgimage) {
3132 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3133 wfree(path);
3134 } else {
3135 wfree(path);
3137 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3138 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3140 if (cwidth <= 0 || cheight <= 0 ||
3141 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3142 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3143 else {
3144 int i;
3145 int swidth, theight;
3146 for (i = 0; i < 9; i++) {
3147 if (prefs->swbackImage[i])
3148 RReleaseImage(prefs->swbackImage[i]);
3149 prefs->swbackImage[i] = NULL;
3151 swidth = (bgimage->width - cwidth) / 2;
3152 theight = (bgimage->height - cheight) / 2;
3154 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3155 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3156 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3157 swidth, theight);
3159 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3160 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3161 cwidth, cheight);
3162 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3163 swidth, cheight);
3165 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3166 swidth, theight);
3167 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3168 cwidth, theight);
3169 prefs->swbackImage[8] =
3170 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3171 theight);
3173 // check if anything failed
3174 for (i = 0; i < 9; i++) {
3175 if (!prefs->swbackImage[i]) {
3176 for (; i >= 0; --i) {
3177 RReleaseImage(prefs->swbackImage[i]);
3178 prefs->swbackImage[i] = NULL;
3180 break;
3184 RReleaseImage(bgimage);
3188 case 1:
3189 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3190 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3191 break;
3192 } else
3193 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3195 if (!path) {
3196 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3197 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3198 } else {
3199 if (prefs->swtileImage)
3200 RReleaseImage(prefs->swtileImage);
3202 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3203 if (!prefs->swtileImage) {
3204 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3206 wfree(path);
3208 break;
3210 default:
3211 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3212 break;
3215 WMReleasePropList(array);
3217 return 0;
3221 static int
3222 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3224 return REFRESH_BUTTON_IMAGES;
3229 * Very ugly kluge.
3230 * Need access to the double click variables, so that all widgets in
3231 * wmaker panels will have the same dbl-click values.
3232 * TODO: figure a better way of dealing with it.
3234 #include <WINGs/WINGsP.h>
3236 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3238 extern _WINGsConfiguration WINGsConfiguration;
3240 if (*value <= 0)
3241 *(int *)foo = 1;
3243 WINGsConfiguration.doubleClickDelay = *value;
3245 return 0;
3248 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3250 if (wCursor[widx] != None) {
3251 XFreeCursor(dpy, wCursor[widx]);
3254 wCursor[widx] = *cursor;
3256 if (widx == WCUR_ROOT && *cursor != None) {
3257 XDefineCursor(dpy, scr->root_win, *cursor);
3260 return 0;