Makefile: Beautify compilation messages
[wmaker-crm.git] / src / defaults.c
blobc07ad37b95614d887417fcebf98a8a74d7bc8319
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 <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <time.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <limits.h>
36 #include <signal.h>
38 #ifdef HAVE_DLFCN_H
39 # include <dlfcn.h>
40 #endif
44 #ifndef PATH_MAX
45 #define PATH_MAX DEFAULT_PATH_MAX
46 #endif
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #include <X11/keysym.h>
52 #include <wraster.h>
54 #include "WindowMaker.h"
55 #include "wcore.h"
56 #include "framewin.h"
57 #include "window.h"
58 #include "texture.h"
59 #include "screen.h"
60 #include "resources.h"
61 #include "defaults.h"
62 #include "keybind.h"
63 #include "xmodifier.h"
64 #include "icon.h"
65 #include "funcs.h"
66 #include "actions.h"
67 #include "dock.h"
68 #include "workspace.h"
69 #include "properties.h"
73 /***** Global *****/
75 extern WDDomain *WDWindowMaker;
76 extern WDDomain *WDWindowAttributes;
77 extern WDDomain *WDRootMenu;
79 extern int wScreenCount;
81 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
82 extern Atom _XA_WINDOWMAKER_ICON_TILE;
85 extern WMPropList *wDomainName;
86 extern WMPropList *wAttributeDomainName;
88 extern WPreferences wPreferences;
90 extern WShortKey wKeyBindings[WKBD_LAST];
92 typedef struct {
93 char *key;
94 char *default_value;
95 void *extra_data;
96 void *addr;
97 int (*convert)();
98 int (*update)();
99 WMPropList *plkey;
100 WMPropList *plvalue; /* default value */
101 } WDefaultEntry;
104 /* used to map strings to integers */
105 typedef struct {
106 char *string;
107 short value;
108 char is_alias;
109 } WOptionEnumeration;
112 /* type converters */
113 static int getBool();
114 static int getInt();
115 static int getCoord();
116 #if 0
117 /* this is not used yet */
118 static int getString();
119 #endif
120 static int getPathList();
121 static int getEnum();
122 static int getTexture();
123 static int getWSBackground();
124 static int getWSSpecificBackground();
125 static int getFont();
126 static int getColor();
127 static int getKeybind();
128 static int getModMask();
129 #ifdef NEWSTUFF
130 static int getRImage();
131 #endif
132 static int getPropList();
134 /* value setting functions */
135 static int setJustify();
136 static int setClearance();
137 static int setIfDockPresent();
138 static int setStickyIcons();
140 static int setPositive();
142 static int setWidgetColor();
143 static int setIconTile();
144 static int setWinTitleFont();
145 static int setMenuTitleFont();
146 static int setMenuTextFont();
147 static int setIconTitleFont();
148 static int setIconTitleColor();
149 static int setIconTitleBack();
150 static int setLargeDisplayFont();
151 static int setWTitleColor();
152 static int setFTitleBack();
153 static int setPTitleBack();
154 static int setUTitleBack();
155 static int setResizebarBack();
156 static int setWorkspaceBack();
157 static int setWorkspaceSpecificBack();
158 #ifdef VIRTUAL_DESKTOP
159 static int setVirtualDeskEnable();
160 #endif
161 static int setMenuTitleColor();
162 static int setMenuTextColor();
163 static int setMenuDisabledColor();
164 static int setMenuTitleBack();
165 static int setMenuTextBack();
166 static int setHightlight();
167 static int setHightlightText();
168 static int setKeyGrab();
169 static int setDoubleClick();
170 static int setIconPosition();
172 static int setClipTitleFont();
173 static int setClipTitleColor();
175 static int setMenuStyle();
176 static int setSwPOptions();
177 static int updateUsableArea();
180 extern Cursor wCursor[WCUR_LAST];
181 static int getCursor();
182 static int setCursor();
186 * Tables to convert strings to enumeration values.
187 * Values stored are char
191 /* WARNING: sum of length of all value strings must not exceed
192 * this value */
193 #define TOTAL_VALUES_LENGTH 80
198 #define REFRESH_WINDOW_TEXTURES (1<<0)
199 #define REFRESH_MENU_TEXTURE (1<<1)
200 #define REFRESH_MENU_FONT (1<<2)
201 #define REFRESH_MENU_COLOR (1<<3)
202 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
203 #define REFRESH_MENU_TITLE_FONT (1<<5)
204 #define REFRESH_MENU_TITLE_COLOR (1<<6)
205 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
206 #define REFRESH_WINDOW_FONT (1<<8)
207 #define REFRESH_ICON_TILE (1<<9)
208 #define REFRESH_ICON_FONT (1<<10)
209 #define REFRESH_WORKSPACE_BACK (1<<11)
211 #define REFRESH_BUTTON_IMAGES (1<<12)
213 #define REFRESH_ICON_TITLE_COLOR (1<<13)
214 #define REFRESH_ICON_TITLE_BACK (1<<14)
218 static WOptionEnumeration seFocusModes[] = {
219 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
220 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
221 {NULL, 0, 0}
224 static WOptionEnumeration seColormapModes[] = {
225 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
226 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
227 {NULL, 0, 0}
230 static WOptionEnumeration sePlacements[] = {
231 {"Auto", WPM_AUTO, 0},
232 {"Smart", WPM_SMART, 0},
233 {"Cascade", WPM_CASCADE, 0},
234 {"Random", WPM_RANDOM, 0},
235 {"Manual", WPM_MANUAL, 0},
236 {NULL, 0, 0}
239 static WOptionEnumeration seGeomDisplays[] = {
240 {"None", WDIS_NONE, 0},
241 {"Center", WDIS_CENTER, 0},
242 {"Corner", WDIS_TOPLEFT, 0},
243 {"Floating", WDIS_FRAME_CENTER, 0},
244 {"Line", WDIS_NEW, 0},
245 {NULL, 0, 0}
248 static WOptionEnumeration seSpeeds[] = {
249 {"UltraFast", SPEED_ULTRAFAST, 0},
250 {"Fast", SPEED_FAST, 0},
251 {"Medium", SPEED_MEDIUM, 0},
252 {"Slow", SPEED_SLOW, 0},
253 {"UltraSlow", SPEED_ULTRASLOW, 0},
254 {NULL, 0, 0}
257 static WOptionEnumeration seMouseButtonActions[] = {
258 {"None", WA_NONE, 0},
259 {"SelectWindows", WA_SELECT_WINDOWS, 0},
260 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
261 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
262 {NULL, 0, 0}
265 static WOptionEnumeration seMouseWheelActions[] = {
266 {"None", WA_NONE, 0},
267 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
268 {NULL, 0, 0}
271 static WOptionEnumeration seIconificationStyles[] = {
272 {"Zoom", WIS_ZOOM, 0},
273 {"Twist", WIS_TWIST, 0},
274 {"Flip", WIS_FLIP, 0},
275 {"None", WIS_NONE, 0},
276 {"random", WIS_RANDOM, 0},
277 {NULL, 0, 0}
280 static WOptionEnumeration seJustifications[] = {
281 {"Left", WTJ_LEFT, 0},
282 {"Center", WTJ_CENTER, 0},
283 {"Right", WTJ_RIGHT, 0},
284 {NULL, 0, 0}
287 static WOptionEnumeration seIconPositions[] = {
288 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
289 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
290 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
291 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
292 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
293 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
294 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
295 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
296 {NULL, 0, 0}
299 static WOptionEnumeration seMenuStyles[] = {
300 {"normal", MS_NORMAL, 0},
301 {"singletexture", MS_SINGLE_TEXTURE, 0},
302 {"flat", MS_FLAT, 0},
303 {NULL, 0, 0}
307 static WOptionEnumeration seDisplayPositions[] = {
308 {"none", WD_NONE, 0},
309 {"center", WD_CENTER, 0},
310 {"top", WD_TOP, 0},
311 {"bottom", WD_BOTTOM, 0},
312 {"topleft", WD_TOPLEFT, 0},
313 {"topright", WD_TOPRIGHT, 0},
314 {"bottomleft", WD_BOTTOMLEFT, 0},
315 {"bottomright", WD_BOTTOMRIGHT, 0},
316 {NULL, 0, 0}
319 static WOptionEnumeration seWorkspaceBorder[] = {
320 {"None", WB_NONE, 0},
321 {"LeftRight", WB_LEFTRIGHT, 0},
322 {"TopBottom", WB_TOPBOTTOM, 0},
323 {"AllDirections", WB_ALLDIRS, 0},
324 {NULL, 0, 0}
329 * ALL entries in the tables bellow, NEED to have a default value
330 * defined, and this value needs to be correct.
333 /* these options will only affect the window manager on startup
335 * static defaults can't access the screen data, because it is
336 * created after these defaults are read
338 WDefaultEntry staticOptionList[] = {
340 {"ColormapSize", "4", NULL,
341 &wPreferences.cmap_size, getInt, NULL
343 {"DisableDithering", "NO", NULL,
344 &wPreferences.no_dithering, getBool, NULL
346 /* static by laziness */
347 {"IconSize", "64", NULL,
348 &wPreferences.icon_size, getInt, NULL
350 {"ModifierKey", "Mod1", NULL,
351 &wPreferences.modifier_mask, getModMask, NULL
353 {"DisableWSMouseActions", "NO", NULL,
354 &wPreferences.disable_root_mouse, getBool, NULL
356 {"FocusMode", "manual", seFocusModes,
357 &wPreferences.focus_mode, getEnum, NULL
358 }, /* have a problem when switching from manual to sloppy without restart */
359 {"NewStyle", "NO", NULL,
360 &wPreferences.new_style, getBool, NULL
362 {"DisableDock", "NO", (void*) WM_DOCK,
363 NULL, getBool, setIfDockPresent
365 {"DisableClip", "NO", (void*) WM_CLIP,
366 NULL, getBool, setIfDockPresent
368 {"DisableMiniwindows", "NO", NULL,
369 &wPreferences.disable_miniwindows, getBool, NULL
375 WDefaultEntry optionList[] = {
376 /* dynamic options */
377 {"IconPosition", "blh", seIconPositions,
378 &wPreferences.icon_yard, getEnum, setIconPosition
380 {"IconificationStyle", "Zoom", seIconificationStyles,
381 &wPreferences.iconification_style, getEnum, NULL
383 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
384 &wPreferences.mouse_button1, getEnum, NULL
386 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
387 &wPreferences.mouse_button2, getEnum, NULL
389 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
390 &wPreferences.mouse_button3, getEnum, NULL
392 {"MouseWheelAction", "None", seMouseWheelActions,
393 &wPreferences.mouse_wheel, getEnum, NULL
395 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
396 &wPreferences.pixmap_path, getPathList, NULL
398 {"IconPath", DEF_ICON_PATHS, NULL,
399 &wPreferences.icon_path, getPathList, NULL
401 {"ColormapMode", "auto", seColormapModes,
402 &wPreferences.colormap_mode, getEnum, NULL
404 {"AutoFocus", "NO", NULL,
405 &wPreferences.auto_focus, getBool, NULL
407 {"RaiseDelay", "0", NULL,
408 &wPreferences.raise_delay, getInt, NULL
410 {"CirculateRaise", "NO", NULL,
411 &wPreferences.circ_raise, getBool, NULL
413 {"Superfluous", "NO", NULL,
414 &wPreferences.superfluous, getBool, NULL
416 {"AdvanceToNewWorkspace", "NO", NULL,
417 &wPreferences.ws_advance, getBool, NULL
419 {"CycleWorkspaces", "NO", NULL,
420 &wPreferences.ws_cycle, getBool, NULL
422 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
423 &wPreferences.workspace_name_display_position, getEnum, NULL
425 {"WorkspaceBorder", "None", seWorkspaceBorder,
426 &wPreferences.workspace_border_position, getEnum, updateUsableArea
428 {"WorkspaceBorderSize", "0", NULL,
429 &wPreferences.workspace_border_size, getInt, updateUsableArea
431 #ifdef VIRTUAL_DESKTOP
432 {"EnableVirtualDesktop", "NO", NULL,
433 &wPreferences.vdesk_enable, getBool, setVirtualDeskEnable
435 {"VirtualEdgeExtendSpace", "0", NULL,
436 &wPreferences.vedge_bordersize, getInt, NULL
438 {"VirtualEdgeHorizonScrollSpeed", "30", NULL,
439 &wPreferences.vedge_hscrollspeed, getInt, NULL
441 {"VirtualEdgeVerticalScrollSpeed", "30", NULL,
442 &wPreferences.vedge_vscrollspeed, getInt, NULL
444 {"VirtualEdgeResistance", "30", NULL,
445 &wPreferences.vedge_resistance, getInt, NULL
447 {"VirtualEdgeAttraction", "30", NULL,
448 &wPreferences.vedge_attraction, getInt, NULL
450 {"VirtualEdgeLeftKey", "None", (void*)WKBD_VDESK_LEFT,
451 NULL, getKeybind, setKeyGrab
453 {"VirtualEdgeRightKey", "None", (void*)WKBD_VDESK_RIGHT,
454 NULL, getKeybind, setKeyGrab
456 {"VirtualEdgeUpKey", "None", (void*)WKBD_VDESK_UP,
457 NULL, getKeybind, setKeyGrab
459 {"VirtualEdgeDownKey", "None", (void*)WKBD_VDESK_DOWN,
460 NULL, getKeybind, setKeyGrab
462 #endif
463 {"StickyIcons", "NO", NULL,
464 &wPreferences.sticky_icons, getBool, setStickyIcons
466 {"SaveSessionOnExit", "NO", NULL,
467 &wPreferences.save_session_on_exit, getBool, NULL
469 {"WrapMenus", "NO", NULL,
470 &wPreferences.wrap_menus, getBool, NULL
472 {"ScrollableMenus", "NO", NULL,
473 &wPreferences.scrollable_menus, getBool, NULL
475 {"MenuScrollSpeed", "medium", seSpeeds,
476 &wPreferences.menu_scroll_speed, getEnum, NULL
478 {"IconSlideSpeed", "medium", seSpeeds,
479 &wPreferences.icon_slide_speed, getEnum, NULL
481 {"ShadeSpeed", "medium", seSpeeds,
482 &wPreferences.shade_speed, getEnum, NULL
484 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
485 &wPreferences.dblclick_time, getInt, setDoubleClick,
487 {"AlignSubmenus", "NO", NULL,
488 &wPreferences.align_menus, getBool, NULL
490 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
491 &wPreferences.open_transients_with_parent, getBool, NULL
493 {"WindowPlacement", "auto", sePlacements,
494 &wPreferences.window_placement, getEnum, NULL
496 {"IgnoreFocusClick","NO", NULL,
497 &wPreferences.ignore_focus_click, getBool, NULL
499 {"UseSaveUnders", "NO", NULL,
500 &wPreferences.use_saveunders, getBool, NULL
502 {"OpaqueMove", "NO", NULL,
503 &wPreferences.opaque_move, getBool, NULL
505 {"DisableSound", "NO", NULL,
506 &wPreferences.no_sound, getBool, NULL
508 {"DisableAnimations", "NO", NULL,
509 &wPreferences.no_animations, getBool, NULL
511 {"DontLinkWorkspaces","NO", NULL,
512 &wPreferences.no_autowrap, getBool, NULL
514 {"AutoArrangeIcons", "NO", NULL,
515 &wPreferences.auto_arrange_icons, getBool, NULL
517 {"NoWindowOverDock", "NO", NULL,
518 &wPreferences.no_window_over_dock, getBool, updateUsableArea
520 {"NoWindowOverIcons", "NO", NULL,
521 &wPreferences.no_window_over_icons, getBool, updateUsableArea
523 {"WindowPlaceOrigin", "(0, 0)", NULL,
524 &wPreferences.window_place_origin, getCoord, NULL
526 {"ResizeDisplay", "corner", seGeomDisplays,
527 &wPreferences.size_display, getEnum, NULL
529 {"MoveDisplay", "corner", seGeomDisplays,
530 &wPreferences.move_display, getEnum, NULL
532 {"DontConfirmKill", "NO", NULL,
533 &wPreferences.dont_confirm_kill, getBool,NULL
535 {"WindowTitleBalloons", "NO", NULL,
536 &wPreferences.window_balloon, getBool, NULL
538 {"MiniwindowTitleBalloons", "NO", NULL,
539 &wPreferences.miniwin_balloon,getBool, NULL
541 {"AppIconBalloons", "NO", NULL,
542 &wPreferences.appicon_balloon,getBool, NULL
544 {"HelpBalloons", "NO", NULL,
545 &wPreferences.help_balloon, getBool, NULL
547 {"EdgeResistance", "30", NULL,
548 &wPreferences.edge_resistance,getInt, NULL
550 {"Attraction", "NO", NULL,
551 &wPreferences.attract, getBool, NULL
553 {"DisableBlinking", "NO", NULL,
554 &wPreferences.dont_blink, getBool, NULL
556 /* style options */
557 {"MenuStyle", "normal", seMenuStyles,
558 &wPreferences.menu_style, getEnum, setMenuStyle
560 {"WidgetColor", "(solid, gray)", NULL,
561 NULL, getTexture, setWidgetColor,
563 {"WorkspaceSpecificBack","()", NULL,
564 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
566 /* WorkspaceBack must come after WorkspaceSpecificBack or
567 * WorkspaceBack wont know WorkspaceSpecificBack was also
568 * specified and 2 copies of wmsetbg will be launched */
569 {"WorkspaceBack", "(solid, black)", NULL,
570 NULL, getWSBackground,setWorkspaceBack
572 {"SmoothWorkspaceBack", "NO", NULL,
573 NULL, getBool, NULL
575 {"IconBack", "(solid, gray)", NULL,
576 NULL, getTexture, setIconTile
578 {"TitleJustify", "center", seJustifications,
579 &wPreferences.title_justification, getEnum, setJustify
581 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
582 NULL, getFont, setWinTitleFont,
584 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
585 &wPreferences.window_title_clearance, getInt, setClearance
587 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
588 &wPreferences.menu_title_clearance, getInt, setClearance
590 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
591 &wPreferences.menu_text_clearance, getInt, setClearance
593 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
594 NULL, getFont, setMenuTitleFont
596 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
597 NULL, getFont, setMenuTextFont
599 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
600 NULL, getFont, setIconTitleFont
602 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
603 NULL, getFont, setClipTitleFont
605 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
606 NULL, getFont, setLargeDisplayFont
608 {"HighlightColor", "white", NULL,
609 NULL, getColor, setHightlight
611 {"HighlightTextColor", "black", NULL,
612 NULL, getColor, setHightlightText
614 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
615 NULL, getColor, setClipTitleColor
617 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
618 NULL, getColor, setClipTitleColor
620 {"FTitleColor", "white", (void*)WS_FOCUSED,
621 NULL, getColor, setWTitleColor
623 {"PTitleColor", "white", (void*)WS_PFOCUSED,
624 NULL, getColor, setWTitleColor
626 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
627 NULL, getColor, setWTitleColor
629 {"FTitleBack", "(solid, black)", NULL,
630 NULL, getTexture, setFTitleBack
632 {"PTitleBack", "(solid, \"#616161\")", NULL,
633 NULL, getTexture, setPTitleBack
635 {"UTitleBack", "(solid, gray)", NULL,
636 NULL, getTexture, setUTitleBack
638 {"ResizebarBack", "(solid, gray)", NULL,
639 NULL, getTexture, setResizebarBack
641 {"MenuTitleColor", "white", NULL,
642 NULL, getColor, setMenuTitleColor
644 {"MenuTextColor", "black", NULL,
645 NULL, getColor, setMenuTextColor
647 {"MenuDisabledColor", "\"#616161\"", NULL,
648 NULL, getColor, setMenuDisabledColor
650 {"MenuTitleBack", "(solid, black)", NULL,
651 NULL, getTexture, setMenuTitleBack
653 {"MenuTextBack", "(solid, gray)", NULL,
654 NULL, getTexture, setMenuTextBack
656 {"IconTitleColor", "white", NULL,
657 NULL, getColor, setIconTitleColor
659 {"IconTitleBack", "black", NULL,
660 NULL, getColor, setIconTitleBack
662 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
663 NULL, getPropList, setSwPOptions
665 /* keybindings */
666 #ifndef LITE
667 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
668 NULL, getKeybind, setKeyGrab
670 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
671 NULL, getKeybind, setKeyGrab
673 #endif /* LITE */
674 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
675 NULL, getKeybind, setKeyGrab
677 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
678 NULL, getKeybind, setKeyGrab
680 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
681 NULL, getKeybind, setKeyGrab
683 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
684 NULL, getKeybind, setKeyGrab
686 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
687 NULL, getKeybind, setKeyGrab
689 {"HideKey", "None", (void*)WKBD_HIDE,
690 NULL, getKeybind, setKeyGrab
692 {"HideOthersKey", "None", (void*)WKBD_HIDE_OTHERS,
693 NULL, getKeybind, setKeyGrab
695 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
696 NULL, getKeybind, setKeyGrab
698 {"CloseKey", "None", (void*)WKBD_CLOSE,
699 NULL, getKeybind, setKeyGrab
701 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
702 NULL, getKeybind, setKeyGrab
704 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
705 NULL, getKeybind, setKeyGrab
707 {"HMaximizeKey", "None", (void*)WKBD_HMAXIMIZE,
708 NULL, getKeybind, setKeyGrab
710 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
711 NULL, getKeybind, setKeyGrab
713 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
714 NULL, getKeybind, setKeyGrab
716 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
717 NULL, getKeybind, setKeyGrab
719 {"ShadeKey", "None", (void*)WKBD_SHADE,
720 NULL, getKeybind, setKeyGrab
722 {"SelectKey", "None", (void*)WKBD_SELECT,
723 NULL, getKeybind, setKeyGrab
725 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
726 NULL, getKeybind, setKeyGrab
728 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
729 NULL, getKeybind, setKeyGrab
731 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
732 NULL, getKeybind, setKeyGrab
734 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
735 NULL, getKeybind, setKeyGrab
737 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
738 NULL, getKeybind, setKeyGrab
740 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
741 NULL, getKeybind, setKeyGrab
743 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
744 NULL, getKeybind, setKeyGrab
746 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
747 NULL, getKeybind, setKeyGrab
749 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
750 NULL, getKeybind, setKeyGrab
752 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
753 NULL, getKeybind, setKeyGrab
755 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
756 NULL, getKeybind, setKeyGrab
758 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
759 NULL, getKeybind, setKeyGrab
761 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
762 NULL, getKeybind, setKeyGrab
764 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
765 NULL, getKeybind, setKeyGrab
767 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
768 NULL, getKeybind, setKeyGrab
770 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
771 NULL, getKeybind, setKeyGrab
773 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
774 NULL, getKeybind, setKeyGrab
776 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
777 NULL, getKeybind, setKeyGrab
779 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
780 NULL, getKeybind, setKeyGrab
782 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
783 NULL, getKeybind, setKeyGrab
785 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
786 NULL, getKeybind, setKeyGrab
788 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
789 NULL, getKeybind, setKeyGrab
791 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
792 NULL, getKeybind, setKeyGrab
794 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
795 NULL, getKeybind, setKeyGrab
797 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
798 NULL, getKeybind, setKeyGrab
800 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
801 NULL, getKeybind, setKeyGrab
803 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
804 NULL, getKeybind, setKeyGrab
807 #ifdef KEEP_XKB_LOCK_STATUS
808 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
809 NULL, getKeybind, setKeyGrab
811 {"KbdModeLock", "NO", NULL,
812 &wPreferences.modelock, getBool, NULL
814 #endif /* KEEP_XKB_LOCK_STATUS */
816 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
817 NULL, getCursor, setCursor
819 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
820 NULL, getCursor, setCursor
822 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
823 NULL, getCursor, setCursor
825 {"ResizeCursor", "(builtin, sizing)", (void*)WCUR_RESIZE,
826 NULL, getCursor, setCursor
828 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
829 (void*)WCUR_TOPLEFTRESIZE,
830 NULL, getCursor, setCursor
832 {"TopRightResizeCursor", "(builtin, top_right_corner)",
833 (void*)WCUR_TOPRIGHTRESIZE,
834 NULL, getCursor, setCursor
836 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
837 (void*)WCUR_BOTTOMLEFTRESIZE,
838 NULL, getCursor, setCursor
840 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
841 (void*)WCUR_BOTTOMRIGHTRESIZE,
842 NULL, getCursor, setCursor
844 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
845 (void*)WCUR_VERTICALRESIZE,
846 NULL, getCursor, setCursor
848 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
849 (void*)WCUR_HORIZONRESIZE,
850 NULL, getCursor, setCursor
852 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
853 NULL, getCursor, setCursor
855 {"QuestionCursor", "(builtin, question_arrow)", (void*)WCUR_QUESTION,
856 NULL, getCursor, setCursor
858 {"TextCursor", "(builtin, xterm)", (void*)WCUR_TEXT,
859 NULL, getCursor, setCursor
861 {"SelectCursor", "(builtin, cross)", (void*)WCUR_SELECT,
862 NULL, getCursor, setCursor
867 #if 0
868 static void rereadDefaults(void);
869 #endif
871 #if 0
872 static void
873 rereadDefaults(void)
875 /* must defer the update because accessing X data from a
876 * signal handler can mess up Xlib */
879 #endif
881 static void
882 initDefaults()
884 int i;
885 WDefaultEntry *entry;
887 WMPLSetCaseSensitive(False);
889 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
890 entry = &optionList[i];
892 entry->plkey = WMCreatePLString(entry->key);
893 if (entry->default_value)
894 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
895 else
896 entry->plvalue = NULL;
899 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
900 entry = &staticOptionList[i];
902 entry->plkey = WMCreatePLString(entry->key);
903 if (entry->default_value)
904 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
905 else
906 entry->plvalue = NULL;
910 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
911 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
913 PLRegister(wDomainName, rereadDefaults);
914 PLRegister(wAttributeDomainName, rereadDefaults);
919 static WMPropList*
920 readGlobalDomain(char *domainName, Bool requireDictionary)
922 WMPropList *globalDict = NULL;
923 char path[PATH_MAX];
924 struct stat stbuf;
926 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domainName);
927 if (stat(path, &stbuf)>=0) {
928 globalDict = WMReadPropListFromFile(path);
929 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
930 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
931 domainName, path);
932 WMReleasePropList(globalDict);
933 globalDict = NULL;
934 } else if (!globalDict) {
935 wwarning(_("could not load domain %s from global defaults database"),
936 domainName);
940 return globalDict;
944 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
945 static void
946 prependMenu(WMPropList *destarr, WMPropList *array)
948 WMPropList *item;
949 int i;
951 for (i=0; i<WMGetPropListItemCount(array); i++) {
952 item = WMGetFromPLArray(array, i);
953 if (item)
954 WMInsertInPLArray(destarr, i+1, item);
959 static void
960 appendMenu(WMPropList *destarr, WMPropList *array)
962 WMPropList *item;
963 int i;
965 for (i=0; i<WMGetPropListItemCount(array); i++) {
966 item = WMGetFromPLArray(array, i);
967 if (item)
968 WMAddToPLArray(destarr, item);
971 #endif
974 /* Fixup paths for cached pixmaps from .AppInfo to Library/WindowMaker/... */
975 static Bool
976 fixupCachedPixmapsPaths(WMPropList *dict)
978 WMPropList *allApps, *app, *props, *iconkey, *icon, *newicon;
979 char *path, *fixedpath, *ptr, *search, *replace;
980 int i, len, slen;
981 Bool changed = False;
983 search = "/.AppInfo/WindowMaker/";
984 slen = strlen(search);
986 iconkey = WMCreatePLString("Icon");
987 allApps = WMGetPLDictionaryKeys(dict);
989 for (i=0; i < WMGetPropListItemCount(allApps); i++) {
990 app = WMGetFromPLArray(allApps, i);
991 props = WMGetFromPLDictionary(dict, app);
992 if (!props)
993 continue;
994 icon = WMGetFromPLDictionary(props, iconkey);
995 if (icon && WMIsPLString(icon)) {
996 path = WMGetFromPLString(icon);
997 ptr = strstr(path, search);
998 if (ptr) {
999 changed = True;
1000 len = (ptr - path);
1001 fixedpath = wmalloc(strlen(path)+32);
1002 strncpy(fixedpath, path, len);
1003 fixedpath[len] = 0;
1004 strcat(fixedpath, "/Library/WindowMaker/CachedPixmaps/");
1005 strcat(fixedpath, ptr+slen);
1006 newicon = WMCreatePLString(fixedpath);
1007 WMPutInPLDictionary(props, iconkey, newicon);
1008 WMReleasePropList(newicon);
1009 wfree(fixedpath);
1014 WMReleasePropList(allApps);
1015 WMReleasePropList(iconkey);
1017 return changed;
1021 void
1022 wDefaultsMergeGlobalMenus(WDDomain *menuDomain)
1024 WMPropList *menu = menuDomain->dictionary;
1025 WMPropList *submenu;
1027 if (!menu || !WMIsPLArray(menu))
1028 return;
1030 #ifdef GLOBAL_PREAMBLE_MENU_FILE
1031 submenu = WMReadPropListFromFile(SYSCONFDIR"/WindowMaker/"GLOBAL_PREAMBLE_MENU_FILE);
1033 if (submenu && !WMIsPLArray(submenu)) {
1034 wwarning(_("invalid global menu file %s"),
1035 GLOBAL_PREAMBLE_MENU_FILE);
1036 WMReleasePropList(submenu);
1037 submenu = NULL;
1039 if (submenu) {
1040 prependMenu(menu, submenu);
1041 WMReleasePropList(submenu);
1043 #endif
1045 #ifdef GLOBAL_EPILOGUE_MENU_FILE
1046 submenu = WMReadPropListFromFile(SYSCONFDIR"/WindowMaker/"GLOBAL_EPILOGUE_MENU_FILE);
1048 if (submenu && !WMIsPLArray(submenu)) {
1049 wwarning(_("invalid global menu file %s"),
1050 GLOBAL_EPILOGUE_MENU_FILE);
1051 WMReleasePropList(submenu);
1052 submenu = NULL;
1054 if (submenu) {
1055 appendMenu(menu, submenu);
1056 WMReleasePropList(submenu);
1058 #endif
1060 menuDomain->dictionary = menu;
1064 #if 0
1065 WMPropList*
1066 wDefaultsInit(int screen_number)
1068 static int defaults_inited = 0;
1069 WMPropList *dict;
1071 if (!defaults_inited) {
1072 initDefaults();
1075 dict = PLGetDomain(wDomainName);
1076 if (!dict) {
1077 wwarning(_("could not read domain \"%s\" from defaults database"),
1078 WMGetFromPLString(wDomainName));
1081 return dict;
1083 #endif
1086 void
1087 wDefaultsDestroyDomain(WDDomain *domain)
1089 if (domain->dictionary)
1090 WMReleasePropList(domain->dictionary);
1091 wfree(domain->path);
1092 wfree(domain);
1096 WDDomain*
1097 wDefaultsInitDomain(char *domain, Bool requireDictionary)
1099 WDDomain *db;
1100 struct stat stbuf;
1101 static int inited = 0;
1102 char path[PATH_MAX];
1103 char *the_path;
1104 WMPropList *shared_dict=NULL;
1106 if (!inited) {
1107 inited = 1;
1108 initDefaults();
1111 db = wmalloc(sizeof(WDDomain));
1112 memset(db, 0, sizeof(WDDomain));
1113 db->domain_name = domain;
1114 db->path = wdefaultspathfordomain(domain);
1115 the_path = db->path;
1117 if (the_path && stat(the_path, &stbuf)>=0) {
1118 db->dictionary = WMReadPropListFromFile(the_path);
1119 if (db->dictionary) {
1120 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
1121 WMReleasePropList(db->dictionary);
1122 db->dictionary = NULL;
1123 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1124 domain, the_path);
1126 if (strcmp(domain, "WMWindowAttributes")==0 && db->dictionary) {
1127 if (fixupCachedPixmapsPaths(db->dictionary)) {
1128 WMWritePropListToFile(db->dictionary, db->path, True);
1129 /* re-read the timestamp. if this fails take current time */
1130 if (stat(db->path, &stbuf)<0) {
1131 stbuf.st_mtime = time(NULL);
1135 db->timestamp = stbuf.st_mtime;
1136 } else {
1137 wwarning(_("could not load domain %s from user defaults database"),
1138 domain);
1142 /* global system dictionary */
1143 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
1144 if (stat(path, &stbuf)>=0) {
1145 shared_dict = WMReadPropListFromFile(path);
1146 if (shared_dict) {
1147 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
1148 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1149 domain, path);
1150 WMReleasePropList(shared_dict);
1151 shared_dict = NULL;
1152 } else {
1153 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
1154 WMIsPLDictionary(db->dictionary)) {
1155 WMMergePLDictionaries(shared_dict, db->dictionary, True);
1156 WMReleasePropList(db->dictionary);
1157 db->dictionary = shared_dict;
1158 if (stbuf.st_mtime > db->timestamp)
1159 db->timestamp = stbuf.st_mtime;
1160 } else if (!db->dictionary) {
1161 db->dictionary = shared_dict;
1162 if (stbuf.st_mtime > db->timestamp)
1163 db->timestamp = stbuf.st_mtime;
1166 } else {
1167 wwarning(_("could not load domain %s from global defaults database (%s)"),
1168 domain, path);
1172 return db;
1176 void
1177 wReadStaticDefaults(WMPropList *dict)
1179 WMPropList *plvalue;
1180 WDefaultEntry *entry;
1181 int i;
1182 void *tdata;
1185 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1186 entry = &staticOptionList[i];
1188 if (dict)
1189 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
1190 else
1191 plvalue = NULL;
1193 if (!plvalue) {
1194 /* no default in the DB. Use builtin default */
1195 plvalue = entry->plvalue;
1198 if (plvalue) {
1199 /* convert data */
1200 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1201 if (entry->update) {
1202 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1210 void
1211 wDefaultsCheckDomains(void *foo)
1213 WScreen *scr;
1214 struct stat stbuf;
1215 WMPropList *shared_dict = NULL;
1216 WMPropList *dict;
1217 int i;
1219 #ifdef HEARTBEAT
1220 puts("Checking domains...");
1221 #endif
1222 if (stat(WDWindowMaker->path, &stbuf)>=0
1223 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1224 #ifdef HEARTBEAT
1225 puts("Checking WindowMaker domain");
1226 #endif
1227 WDWindowMaker->timestamp = stbuf.st_mtime;
1229 /* global dictionary */
1230 shared_dict = readGlobalDomain("WindowMaker", True);
1231 /* user dictionary */
1232 dict = WMReadPropListFromFile(WDWindowMaker->path);
1233 if (dict) {
1234 if (!WMIsPLDictionary(dict)) {
1235 WMReleasePropList(dict);
1236 dict = NULL;
1237 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1238 "WindowMaker", WDWindowMaker->path);
1239 } else {
1240 if (shared_dict) {
1241 WMMergePLDictionaries(shared_dict, dict, True);
1242 WMReleasePropList(dict);
1243 dict = shared_dict;
1244 shared_dict = NULL;
1246 for (i=0; i<wScreenCount; i++) {
1247 scr = wScreenWithNumber(i);
1248 if (scr)
1249 wReadDefaults(scr, dict);
1251 if (WDWindowMaker->dictionary) {
1252 WMReleasePropList(WDWindowMaker->dictionary);
1254 WDWindowMaker->dictionary = dict;
1256 } else {
1257 wwarning(_("could not load domain %s from user defaults database"),
1258 "WindowMaker");
1260 if (shared_dict) {
1261 WMReleasePropList(shared_dict);
1265 if (stat(WDWindowAttributes->path, &stbuf)>=0
1266 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1267 #ifdef HEARTBEAT
1268 puts("Checking WMWindowAttributes domain");
1269 #endif
1270 /* global dictionary */
1271 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1272 /* user dictionary */
1273 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1274 if (dict) {
1275 if (!WMIsPLDictionary(dict)) {
1276 WMReleasePropList(dict);
1277 dict = NULL;
1278 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1279 "WMWindowAttributes", WDWindowAttributes->path);
1280 } else {
1281 if (shared_dict) {
1282 WMMergePLDictionaries(shared_dict, dict, True);
1283 WMReleasePropList(dict);
1284 dict = shared_dict;
1285 shared_dict = NULL;
1287 if (WDWindowAttributes->dictionary) {
1288 WMReleasePropList(WDWindowAttributes->dictionary);
1290 WDWindowAttributes->dictionary = dict;
1291 for (i=0; i<wScreenCount; i++) {
1292 scr = wScreenWithNumber(i);
1293 if (scr) {
1294 RImage *image;
1296 wDefaultUpdateIcons(scr);
1298 /* Update the panel image if changed */
1299 /* Don't worry. If the image is the same these
1300 * functions will have no performance impact. */
1301 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1303 if (!image) {
1304 wwarning(_("could not load logo image for panels: %s"),
1305 RMessageForError(RErrorCode));
1306 } else {
1307 WMSetApplicationIconImage(scr->wmscreen, image);
1308 RReleaseImage(image);
1313 } else {
1314 wwarning(_("could not load domain %s from user defaults database"),
1315 "WMWindowAttributes");
1317 WDWindowAttributes->timestamp = stbuf.st_mtime;
1318 if (shared_dict) {
1319 WMReleasePropList(shared_dict);
1323 #ifndef LITE
1324 if (stat(WDRootMenu->path, &stbuf)>=0
1325 && WDRootMenu->timestamp < stbuf.st_mtime) {
1326 dict = WMReadPropListFromFile(WDRootMenu->path);
1327 #ifdef HEARTBEAT
1328 puts("Checking WMRootMenu domain");
1329 #endif
1330 if (dict) {
1331 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1332 WMReleasePropList(dict);
1333 dict = NULL;
1334 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1335 "WMRootMenu", WDRootMenu->path);
1336 } else {
1337 if (WDRootMenu->dictionary) {
1338 WMReleasePropList(WDRootMenu->dictionary);
1340 WDRootMenu->dictionary = dict;
1341 wDefaultsMergeGlobalMenus(WDRootMenu);
1343 } else {
1344 wwarning(_("could not load domain %s from user defaults database"),
1345 "WMRootMenu");
1347 WDRootMenu->timestamp = stbuf.st_mtime;
1349 #endif /* !LITE */
1354 void
1355 wReadDefaults(WScreen *scr, WMPropList *new_dict)
1357 WMPropList *plvalue, *old_value;
1358 WDefaultEntry *entry;
1359 int i, must_update;
1360 int update_workspace_back = 0; /* kluge :/ */
1361 int needs_refresh;
1362 void *tdata;
1363 WMPropList *old_dict = (WDWindowMaker->dictionary!=new_dict
1364 ? WDWindowMaker->dictionary : NULL);
1366 must_update = 0;
1368 needs_refresh = 0;
1370 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1371 entry = &optionList[i];
1373 if (new_dict)
1374 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1375 else
1376 plvalue = NULL;
1378 if (!old_dict)
1379 old_value = NULL;
1380 else
1381 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1384 if (!plvalue && !old_value) {
1385 /* no default in the DB. Use builtin default */
1386 plvalue = entry->plvalue;
1387 if (plvalue && new_dict) {
1388 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1389 must_update = 1;
1391 } else if (!plvalue) {
1392 /* value was deleted from DB. Keep current value */
1393 continue;
1394 } else if (!old_value) {
1395 /* set value for the 1st time */
1396 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1397 /* value has changed */
1398 } else {
1400 if (strcmp(entry->key, "WorkspaceBack") == 0
1401 && update_workspace_back
1402 && scr->flags.backimage_helper_launched) {
1403 } else {
1404 /* value was not changed since last time */
1405 continue;
1409 if (plvalue) {
1410 #ifdef DEBUG
1411 printf("Updating %s to %s\n", entry->key,
1412 WMGetPropListDescription(plvalue, False));
1413 #endif
1414 /* convert data */
1415 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1417 * If the WorkspaceSpecificBack data has been changed
1418 * so that the helper will be launched now, we must be
1419 * sure to send the default background texture config
1420 * to the helper.
1422 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1423 && !scr->flags.backimage_helper_launched) {
1424 update_workspace_back = 1;
1426 if (entry->update) {
1427 needs_refresh |=
1428 (*entry->update)(scr, entry, tdata, entry->extra_data);
1434 if (needs_refresh!=0 && !scr->flags.startup) {
1435 int foo;
1437 foo = 0;
1438 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1439 foo |= WTextureSettings;
1440 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1441 foo |= WFontSettings;
1442 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1443 foo |= WColorSettings;
1444 if (foo)
1445 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1446 (void*)foo);
1448 foo = 0;
1449 if (needs_refresh & REFRESH_MENU_TEXTURE)
1450 foo |= WTextureSettings;
1451 if (needs_refresh & REFRESH_MENU_FONT)
1452 foo |= WFontSettings;
1453 if (needs_refresh & REFRESH_MENU_COLOR)
1454 foo |= WColorSettings;
1455 if (foo)
1456 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1457 (void*)foo);
1459 foo = 0;
1460 if (needs_refresh & REFRESH_WINDOW_FONT) {
1461 foo |= WFontSettings;
1463 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1464 foo |= WTextureSettings;
1466 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1467 foo |= WColorSettings;
1469 if (foo)
1470 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1471 (void*)foo);
1473 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1474 foo = 0;
1475 if (needs_refresh & REFRESH_ICON_FONT) {
1476 foo |= WFontSettings;
1478 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1479 foo |= WTextureSettings;
1481 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1482 foo |= WTextureSettings;
1484 if (foo)
1485 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1486 (void*)foo);
1488 if (needs_refresh & REFRESH_ICON_TILE)
1489 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1494 void
1495 wDefaultUpdateIcons(WScreen *scr)
1497 WAppIcon *aicon = scr->app_icon_list;
1498 WWindow *wwin = scr->focused_window;
1499 char *file;
1501 while(aicon) {
1502 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1503 False);
1504 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1505 || (file && !aicon->icon->file)) {
1506 RImage *new_image;
1508 if (aicon->icon->file)
1509 wfree(aicon->icon->file);
1510 aicon->icon->file = wstrdup(file);
1512 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1513 aicon->wm_class);
1514 if (new_image) {
1515 wIconChangeImage(aicon->icon, new_image);
1516 wAppIconPaint(aicon);
1519 aicon = aicon->next;
1522 if (!wPreferences.flags.noclip)
1523 wClipIconPaint(scr->clip_icon);
1525 while (wwin) {
1526 if (wwin->icon && wwin->flags.miniaturized) {
1527 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1528 False);
1529 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1530 || (file && !wwin->icon->file)) {
1531 RImage *new_image;
1533 if (wwin->icon->file)
1534 wfree(wwin->icon->file);
1535 wwin->icon->file = wstrdup(file);
1537 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1538 wwin->wm_class);
1539 if (new_image)
1540 wIconChangeImage(wwin->icon, new_image);
1543 wwin = wwin->prev;
1548 /* --------------------------- Local ----------------------- */
1550 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1551 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1552 entry->key, x); \
1553 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1554 var = entry->default_value;\
1555 } else var = WMGetFromPLString(value)\
1561 static int
1562 string2index(WMPropList *key, WMPropList *val, char *def,
1563 WOptionEnumeration *values)
1565 char *str;
1566 WOptionEnumeration *v;
1567 char buffer[TOTAL_VALUES_LENGTH];
1569 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1570 for (v=values; v->string!=NULL; v++) {
1571 if (strcasecmp(v->string, str)==0)
1572 return v->value;
1576 buffer[0] = 0;
1577 for (v=values; v->string!=NULL; v++) {
1578 if (!v->is_alias) {
1579 if (buffer[0]!=0)
1580 strcat(buffer, ", ");
1581 strcat(buffer, v->string);
1584 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1585 WMGetFromPLString(key), buffer);
1587 if (def) {
1588 return string2index(key, val, NULL, values);
1591 return -1;
1598 * value - is the value in the defaults DB
1599 * addr - is the address to store the data
1600 * ret - is the address to store a pointer to a temporary buffer. ret
1601 * must not be freed and is used by the set functions
1603 static int
1604 getBool(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1605 void **ret)
1607 static char data;
1608 char *val;
1609 int second_pass=0;
1611 GET_STRING_OR_DEFAULT("Boolean", val);
1613 again:
1614 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1615 || strcasecmp(val, "YES")==0) {
1617 data = 1;
1618 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1619 || strcasecmp(val, "NO")==0) {
1620 data = 0;
1621 } else {
1622 int i;
1623 if (sscanf(val, "%i", &i)==1) {
1624 if (i!=0)
1625 data = 1;
1626 else
1627 data = 0;
1628 } else {
1629 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1630 val, entry->key);
1631 if (second_pass==0) {
1632 val = WMGetFromPLString(entry->plvalue);
1633 second_pass = 1;
1634 wwarning(_("using default \"%s\" instead"), val);
1635 goto again;
1637 return False;
1641 if (ret)
1642 *ret = &data;
1643 if (addr)
1644 *(char*)addr = data;
1646 return True;
1650 static int
1651 getInt(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1652 void **ret)
1654 static int data;
1655 char *val;
1658 GET_STRING_OR_DEFAULT("Integer", val);
1660 if (sscanf(val, "%i", &data)!=1) {
1661 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1662 val, entry->key);
1663 val = WMGetFromPLString(entry->plvalue);
1664 wwarning(_("using default \"%s\" instead"), val);
1665 if (sscanf(val, "%i", &data)!=1) {
1666 return False;
1670 if (ret)
1671 *ret = &data;
1672 if (addr)
1673 *(int*)addr = data;
1675 return True;
1679 static int
1680 getCoord(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1681 void **ret)
1683 static WCoord data;
1684 char *val_x, *val_y;
1685 int nelem, changed=0;
1686 WMPropList *elem_x, *elem_y;
1688 again:
1689 if (!WMIsPLArray(value)) {
1690 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1691 entry->key, "Coordinate");
1692 if (changed==0) {
1693 value = entry->plvalue;
1694 changed = 1;
1695 wwarning(_("using default \"%s\" instead"), entry->default_value);
1696 goto again;
1698 return False;
1701 nelem = WMGetPropListItemCount(value);
1702 if (nelem != 2) {
1703 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1704 entry->key);
1705 if (changed==0) {
1706 value = entry->plvalue;
1707 changed = 1;
1708 wwarning(_("using default \"%s\" instead"), entry->default_value);
1709 goto again;
1711 return False;
1714 elem_x = WMGetFromPLArray(value, 0);
1715 elem_y = WMGetFromPLArray(value, 1);
1717 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1718 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1719 entry->key);
1720 if (changed==0) {
1721 value = entry->plvalue;
1722 changed = 1;
1723 wwarning(_("using default \"%s\" instead"), entry->default_value);
1724 goto again;
1726 return False;
1729 val_x = WMGetFromPLString(elem_x);
1730 val_y = WMGetFromPLString(elem_y);
1732 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1733 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1734 if (changed==0) {
1735 value = entry->plvalue;
1736 changed = 1;
1737 wwarning(_("using default \"%s\" instead"), entry->default_value);
1738 goto again;
1740 return False;
1743 if (data.x < 0)
1744 data.x = 0;
1745 else if (data.x > scr->scr_width/3)
1746 data.x = scr->scr_width/3;
1747 if (data.y < 0)
1748 data.y = 0;
1749 else if (data.y > scr->scr_height/3)
1750 data.y = scr->scr_height/3;
1752 if (ret)
1753 *ret = &data;
1754 if (addr)
1755 *(WCoord*)addr = data;
1757 return True;
1761 static int
1762 getPropList(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1763 void **ret)
1765 WMRetainPropList(value);
1767 *ret= value;
1769 return True;
1772 #if 0
1773 /* This function is not used at the moment. */
1774 static int
1775 getString(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1776 void **ret)
1778 static char *data;
1780 GET_STRING_OR_DEFAULT("String", data);
1782 if (!data) {
1783 data = WMGetFromPLString(entry->plvalue);
1784 if (!data)
1785 return False;
1788 if (ret)
1789 *ret = &data;
1790 if (addr)
1791 *(char**)addr = wstrdup(data);
1793 return True;
1795 #endif
1798 static int
1799 getPathList(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1800 void **ret)
1802 static char *data;
1803 int i, count, len;
1804 char *ptr;
1805 WMPropList *d;
1806 int changed=0;
1808 again:
1809 if (!WMIsPLArray(value)) {
1810 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1811 entry->key, "an array of paths");
1812 if (changed==0) {
1813 value = entry->plvalue;
1814 changed = 1;
1815 wwarning(_("using default \"%s\" instead"), entry->default_value);
1816 goto again;
1818 return False;
1821 i = 0;
1822 count = WMGetPropListItemCount(value);
1823 if (count < 1) {
1824 if (changed==0) {
1825 value = entry->plvalue;
1826 changed = 1;
1827 wwarning(_("using default \"%s\" instead"), entry->default_value);
1828 goto again;
1830 return False;
1833 len = 0;
1834 for (i=0; i<count; i++) {
1835 d = WMGetFromPLArray(value, i);
1836 if (!d || !WMIsPLString(d)) {
1837 count = i;
1838 break;
1840 len += strlen(WMGetFromPLString(d))+1;
1843 ptr = data = wmalloc(len+1);
1845 for (i=0; i<count; i++) {
1846 d = WMGetFromPLArray(value, i);
1847 if (!d || !WMIsPLString(d)) {
1848 break;
1850 strcpy(ptr, WMGetFromPLString(d));
1851 ptr += strlen(WMGetFromPLString(d));
1852 *ptr = ':';
1853 ptr++;
1855 ptr--; *(ptr--) = 0;
1857 if (*(char**)addr!=NULL) {
1858 wfree(*(char**)addr);
1860 *(char**)addr = data;
1862 return True;
1866 static int
1867 getEnum(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1868 void **ret)
1870 static signed char data;
1872 data = string2index(entry->plkey, value, entry->default_value,
1873 (WOptionEnumeration*)entry->extra_data);
1874 if (data < 0)
1875 return False;
1877 if (ret)
1878 *ret = &data;
1879 if (addr)
1880 *(signed char*)addr = data;
1882 return True;
1888 * (solid <color>)
1889 * (hgradient <color> <color>)
1890 * (vgradient <color> <color>)
1891 * (dgradient <color> <color>)
1892 * (mhgradient <color> <color> ...)
1893 * (mvgradient <color> <color> ...)
1894 * (mdgradient <color> <color> ...)
1895 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1896 * (tpixmap <file> <color>)
1897 * (spixmap <file> <color>)
1898 * (cpixmap <file> <color>)
1899 * (thgradient <file> <opaqueness> <color> <color>)
1900 * (tvgradient <file> <opaqueness> <color> <color>)
1901 * (tdgradient <file> <opaqueness> <color> <color>)
1902 * (function <lib> <function> ...)
1905 static WTexture*
1906 parse_texture(WScreen *scr, WMPropList *pl)
1908 WMPropList *elem;
1909 char *val;
1910 int nelem;
1911 WTexture *texture=NULL;
1913 nelem = WMGetPropListItemCount(pl);
1914 if (nelem < 1)
1915 return NULL;
1918 elem = WMGetFromPLArray(pl, 0);
1919 if (!elem || !WMIsPLString(elem))
1920 return NULL;
1921 val = WMGetFromPLString(elem);
1924 if (strcasecmp(val, "solid")==0) {
1925 XColor color;
1927 if (nelem != 2)
1928 return NULL;
1930 /* get color */
1932 elem = WMGetFromPLArray(pl, 1);
1933 if (!elem || !WMIsPLString(elem))
1934 return NULL;
1935 val = WMGetFromPLString(elem);
1937 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1938 wwarning(_("\"%s\" is not a valid color name"), val);
1939 return NULL;
1942 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1943 } else if (strcasecmp(val, "dgradient")==0
1944 || strcasecmp(val, "vgradient")==0
1945 || strcasecmp(val, "hgradient")==0) {
1946 RColor color1, color2;
1947 XColor xcolor;
1948 int type;
1950 if (nelem != 3) {
1951 wwarning(_("bad number of arguments in gradient specification"));
1952 return NULL;
1955 if (val[0]=='d' || val[0]=='D')
1956 type = WTEX_DGRADIENT;
1957 else if (val[0]=='h' || val[0]=='H')
1958 type = WTEX_HGRADIENT;
1959 else
1960 type = WTEX_VGRADIENT;
1963 /* get from color */
1964 elem = WMGetFromPLArray(pl, 1);
1965 if (!elem || !WMIsPLString(elem))
1966 return NULL;
1967 val = WMGetFromPLString(elem);
1969 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1970 wwarning(_("\"%s\" is not a valid color name"), val);
1971 return NULL;
1973 color1.alpha = 255;
1974 color1.red = xcolor.red >> 8;
1975 color1.green = xcolor.green >> 8;
1976 color1.blue = xcolor.blue >> 8;
1978 /* get to color */
1979 elem = WMGetFromPLArray(pl, 2);
1980 if (!elem || !WMIsPLString(elem)) {
1981 return NULL;
1983 val = WMGetFromPLString(elem);
1985 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1986 wwarning(_("\"%s\" is not a valid color name"), val);
1987 return NULL;
1989 color2.alpha = 255;
1990 color2.red = xcolor.red >> 8;
1991 color2.green = xcolor.green >> 8;
1992 color2.blue = xcolor.blue >> 8;
1994 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1996 } else if (strcasecmp(val, "igradient")==0) {
1997 RColor colors1[2], colors2[2];
1998 int th1, th2;
1999 XColor xcolor;
2000 int i;
2002 if (nelem != 7) {
2003 wwarning(_("bad number of arguments in gradient specification"));
2004 return NULL;
2007 /* get from color */
2008 for (i = 0; i < 2; i++) {
2009 elem = WMGetFromPLArray(pl, 1+i);
2010 if (!elem || !WMIsPLString(elem))
2011 return NULL;
2012 val = WMGetFromPLString(elem);
2014 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2015 wwarning(_("\"%s\" is not a valid color name"), val);
2016 return NULL;
2018 colors1[i].alpha = 255;
2019 colors1[i].red = xcolor.red >> 8;
2020 colors1[i].green = xcolor.green >> 8;
2021 colors1[i].blue = xcolor.blue >> 8;
2023 elem = WMGetFromPLArray(pl, 3);
2024 if (!elem || !WMIsPLString(elem))
2025 return NULL;
2026 val = WMGetFromPLString(elem);
2027 th1 = atoi(val);
2030 /* get from color */
2031 for (i = 0; i < 2; i++) {
2032 elem = WMGetFromPLArray(pl, 4+i);
2033 if (!elem || !WMIsPLString(elem))
2034 return NULL;
2035 val = WMGetFromPLString(elem);
2037 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2038 wwarning(_("\"%s\" is not a valid color name"), val);
2039 return NULL;
2041 colors2[i].alpha = 255;
2042 colors2[i].red = xcolor.red >> 8;
2043 colors2[i].green = xcolor.green >> 8;
2044 colors2[i].blue = xcolor.blue >> 8;
2046 elem = WMGetFromPLArray(pl, 6);
2047 if (!elem || !WMIsPLString(elem))
2048 return NULL;
2049 val = WMGetFromPLString(elem);
2050 th2 = atoi(val);
2052 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
2053 th2, colors2);
2055 } else if (strcasecmp(val, "mhgradient")==0
2056 || strcasecmp(val, "mvgradient")==0
2057 || strcasecmp(val, "mdgradient")==0) {
2058 XColor color;
2059 RColor **colors;
2060 int i, count;
2061 int type;
2063 if (nelem < 3) {
2064 wwarning(_("too few arguments in multicolor gradient specification"));
2065 return NULL;
2068 if (val[1]=='h' || val[1]=='H')
2069 type = WTEX_MHGRADIENT;
2070 else if (val[1]=='v' || val[1]=='V')
2071 type = WTEX_MVGRADIENT;
2072 else
2073 type = WTEX_MDGRADIENT;
2075 count = nelem-1;
2077 colors = wmalloc(sizeof(RColor*)*(count+1));
2079 for (i=0; i<count; i++) {
2080 elem = WMGetFromPLArray(pl, i+1);
2081 if (!elem || !WMIsPLString(elem)) {
2082 for (--i; i>=0; --i) {
2083 wfree(colors[i]);
2085 wfree(colors);
2086 return NULL;
2088 val = WMGetFromPLString(elem);
2090 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
2091 wwarning(_("\"%s\" is not a valid color name"), val);
2092 for (--i; i>=0; --i) {
2093 wfree(colors[i]);
2095 wfree(colors);
2096 return NULL;
2097 } else {
2098 colors[i] = wmalloc(sizeof(RColor));
2099 colors[i]->red = color.red >> 8;
2100 colors[i]->green = color.green >> 8;
2101 colors[i]->blue = color.blue >> 8;
2104 colors[i] = NULL;
2106 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
2107 } else if (strcasecmp(val, "spixmap")==0 ||
2108 strcasecmp(val, "cpixmap")==0 ||
2109 strcasecmp(val, "tpixmap")==0) {
2110 XColor color;
2111 int type;
2113 if (nelem != 3)
2114 return NULL;
2116 if (val[0] == 's' || val[0] == 'S')
2117 type = WTP_SCALE;
2118 else if (val[0] == 'c' || val[0] == 'C')
2119 type = WTP_CENTER;
2120 else
2121 type = WTP_TILE;
2123 /* get color */
2124 elem = WMGetFromPLArray(pl, 2);
2125 if (!elem || !WMIsPLString(elem)) {
2126 return NULL;
2128 val = WMGetFromPLString(elem);
2130 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
2131 wwarning(_("\"%s\" is not a valid color name"), val);
2132 return NULL;
2135 /* file name */
2136 elem = WMGetFromPLArray(pl, 1);
2137 if (!elem || !WMIsPLString(elem))
2138 return NULL;
2139 val = WMGetFromPLString(elem);
2141 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
2142 } else if (strcasecmp(val, "thgradient")==0
2143 || strcasecmp(val, "tvgradient")==0
2144 || strcasecmp(val, "tdgradient")==0) {
2145 RColor color1, color2;
2146 XColor xcolor;
2147 int opacity;
2148 int style;
2150 if (val[1]=='h' || val[1]=='H')
2151 style = WTEX_THGRADIENT;
2152 else if (val[1]=='v' || val[1]=='V')
2153 style = WTEX_TVGRADIENT;
2154 else
2155 style = WTEX_TDGRADIENT;
2157 if (nelem != 5) {
2158 wwarning(_("bad number of arguments in textured gradient specification"));
2159 return NULL;
2162 /* get from color */
2163 elem = WMGetFromPLArray(pl, 3);
2164 if (!elem || !WMIsPLString(elem))
2165 return NULL;
2166 val = WMGetFromPLString(elem);
2168 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2169 wwarning(_("\"%s\" is not a valid color name"), val);
2170 return NULL;
2172 color1.alpha = 255;
2173 color1.red = xcolor.red >> 8;
2174 color1.green = xcolor.green >> 8;
2175 color1.blue = xcolor.blue >> 8;
2177 /* get to color */
2178 elem = WMGetFromPLArray(pl, 4);
2179 if (!elem || !WMIsPLString(elem)) {
2180 return NULL;
2182 val = WMGetFromPLString(elem);
2184 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2185 wwarning(_("\"%s\" is not a valid color name"), val);
2186 return NULL;
2188 color2.alpha = 255;
2189 color2.red = xcolor.red >> 8;
2190 color2.green = xcolor.green >> 8;
2191 color2.blue = xcolor.blue >> 8;
2193 /* get opacity */
2194 elem = WMGetFromPLArray(pl, 2);
2195 if (!elem || !WMIsPLString(elem))
2196 opacity = 128;
2197 else
2198 val = WMGetFromPLString(elem);
2200 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2201 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2202 opacity = 128;
2205 /* get file name */
2206 elem = WMGetFromPLArray(pl, 1);
2207 if (!elem || !WMIsPLString(elem))
2208 return NULL;
2209 val = WMGetFromPLString(elem);
2211 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2212 val, opacity);
2214 #ifdef TEXTURE_PLUGIN
2215 else if (strcasecmp(val, "function")==0) {
2216 WTexFunction *function;
2217 void (*initFunc) (Display *, Colormap);
2218 char *lib, *func, **argv;
2219 int i, argc;
2221 if (nelem < 3)
2222 return NULL;
2224 /* get the library name */
2225 elem = WMGetFromPLArray(pl, 1);
2226 if (!elem || !WMIsPLString(elem)) {
2227 return NULL;
2229 lib = WMGetFromPLString(elem);
2231 /* get the function name */
2232 elem = WMGetFromPLArray(pl, 2);
2233 if (!elem || !WMIsPLString(elem)) {
2234 return NULL;
2236 func = WMGetFromPLString(elem);
2238 argc = nelem - 2;
2239 argv = (char **)wmalloc(argc * sizeof(char *));
2241 /* get the parameters */
2242 argv[0] = wstrdup(func);
2243 for (i = 0; i < argc - 1; i++) {
2244 elem = WMGetFromPLArray(pl, 3 + i);
2245 if (!elem || !WMIsPLString(elem)) {
2246 wfree(argv);
2248 return NULL;
2250 argv[i+1] = wstrdup(WMGetFromPLString(elem));
2253 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2255 #ifdef HAVE_DLFCN_H
2256 if (function) {
2257 initFunc = dlsym(function->handle, "initWindowMaker");
2258 if (initFunc) {
2259 initFunc(dpy, scr->w_colormap);
2260 } else {
2261 wwarning(_("could not initialize library %s"), lib);
2263 } else {
2264 wwarning(_("could not find function %s::%s"), lib, func);
2266 #endif /* HAVE_DLFCN_H */
2267 texture = (WTexture*)function;
2269 #endif /* TEXTURE_PLUGIN */
2270 else {
2271 wwarning(_("invalid texture type %s"), val);
2272 return NULL;
2274 return texture;
2279 static int
2280 getTexture(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2281 void **ret)
2283 static WTexture *texture;
2284 int changed=0;
2286 again:
2287 if (!WMIsPLArray(value)) {
2288 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2289 entry->key, "Texture");
2290 if (changed==0) {
2291 value = entry->plvalue;
2292 changed = 1;
2293 wwarning(_("using default \"%s\" instead"), entry->default_value);
2294 goto again;
2296 return False;
2299 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2300 WMPropList *pl;
2302 pl = WMGetFromPLArray(value, 0);
2303 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2304 || strcasecmp(WMGetFromPLString(pl), "solid")!=0) {
2305 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2306 entry->key, "Solid Texture");
2308 value = entry->plvalue;
2309 changed = 1;
2310 wwarning(_("using default \"%s\" instead"), entry->default_value);
2311 goto again;
2315 texture = parse_texture(scr, value);
2317 if (!texture) {
2318 wwarning(_("Error in texture specification for key \"%s\""),
2319 entry->key);
2320 if (changed==0) {
2321 value = entry->plvalue;
2322 changed = 1;
2323 wwarning(_("using default \"%s\" instead"), entry->default_value);
2324 goto again;
2326 return False;
2329 if (ret)
2330 *ret = &texture;
2332 if (addr)
2333 *(WTexture**)addr = texture;
2335 return True;
2339 static int
2340 getWSBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2341 void *addr, void **ret)
2343 WMPropList *elem;
2344 int changed = 0;
2345 char *val;
2346 int nelem;
2348 again:
2349 if (!WMIsPLArray(value)) {
2350 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2351 "WorkspaceBack", "Texture or None");
2352 if (changed==0) {
2353 value = entry->plvalue;
2354 changed = 1;
2355 wwarning(_("using default \"%s\" instead"), entry->default_value);
2356 goto again;
2358 return False;
2361 /* only do basic error checking and verify for None texture */
2363 nelem = WMGetPropListItemCount(value);
2364 if (nelem > 0) {
2365 elem = WMGetFromPLArray(value, 0);
2366 if (!elem || !WMIsPLString(elem)) {
2367 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2368 if (changed==0) {
2369 value = entry->plvalue;
2370 changed = 1;
2371 wwarning(_("using default \"%s\" instead"), entry->default_value);
2372 goto again;
2374 return False;
2376 val = WMGetFromPLString(elem);
2378 if (strcasecmp(val, "None")==0)
2379 return True;
2381 *ret = WMRetainPropList(value);
2383 return True;
2387 static int
2388 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2389 void *addr, void **ret)
2391 WMPropList *elem;
2392 int nelem;
2393 int changed = 0;
2395 again:
2396 if (!WMIsPLArray(value)) {
2397 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2398 "WorkspaceSpecificBack", "an array of textures");
2399 if (changed==0) {
2400 value = entry->plvalue;
2401 changed = 1;
2402 wwarning(_("using default \"%s\" instead"), entry->default_value);
2403 goto again;
2405 return False;
2408 /* only do basic error checking and verify for None texture */
2410 nelem = WMGetPropListItemCount(value);
2411 if (nelem > 0) {
2412 while (nelem--) {
2413 elem = WMGetFromPLArray(value, nelem);
2414 if (!elem || !WMIsPLArray(elem)) {
2415 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2416 nelem);
2421 *ret = WMRetainPropList(value);
2423 #ifdef notworking
2425 * Kluge to force wmsetbg helper to set the default background.
2426 * If the WorkspaceSpecificBack is changed once wmaker has started,
2427 * the WorkspaceBack won't be sent to the helper, unless the user
2428 * changes it's value too. So, we must force this by removing the
2429 * value from the defaults DB.
2431 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2432 WMPropList *key = WMCreatePLString("WorkspaceBack");
2434 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2436 WMReleasePropList(key);
2438 #endif
2439 return True;
2443 static int
2444 getFont(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2445 void **ret)
2447 static WMFont *font;
2448 char *val;
2450 GET_STRING_OR_DEFAULT("Font", val);
2452 font = WMCreateFont(scr->wmscreen, val);
2453 if (!font)
2454 font = WMCreateFont(scr->wmscreen, "fixed");
2456 if (!font) {
2457 wfatal(_("could not load any usable font!!!"));
2458 exit(1);
2461 if (ret)
2462 *ret = font;
2464 /* can't assign font value outside update function */
2465 wassertrv(addr == NULL, True);
2467 return True;
2471 static int
2472 getColor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2473 void **ret)
2475 static XColor color;
2476 char *val;
2477 int second_pass=0;
2479 GET_STRING_OR_DEFAULT("Color", val);
2482 again:
2483 if (!wGetColor(scr, val, &color)) {
2484 wwarning(_("could not get color for key \"%s\""),
2485 entry->key);
2486 if (second_pass==0) {
2487 val = WMGetFromPLString(entry->plvalue);
2488 second_pass = 1;
2489 wwarning(_("using default \"%s\" instead"), val);
2490 goto again;
2492 return False;
2495 if (ret)
2496 *ret = &color;
2498 assert(addr==NULL);
2500 if (addr)
2501 *(unsigned long*)addr = pixel;
2504 return True;
2509 static int
2510 getKeybind(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2511 void **ret)
2513 static WShortKey shortcut;
2514 KeySym ksym;
2515 char *val;
2516 char *k;
2517 char buf[128], *b;
2520 GET_STRING_OR_DEFAULT("Key spec", val);
2522 if (!val || strcasecmp(val, "NONE")==0) {
2523 shortcut.keycode = 0;
2524 shortcut.modifier = 0;
2525 if (ret)
2526 *ret = &shortcut;
2527 return True;
2530 strcpy(buf, val);
2532 b = (char*)buf;
2534 /* get modifiers */
2535 shortcut.modifier = 0;
2536 while ((k = strchr(b, '+'))!=NULL) {
2537 int mod;
2539 *k = 0;
2540 mod = wXModifierFromKey(b);
2541 if (mod<0) {
2542 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2543 return False;
2545 shortcut.modifier |= mod;
2547 b = k+1;
2550 /* get key */
2551 ksym = XStringToKeysym(b);
2553 if (ksym==NoSymbol) {
2554 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2555 val);
2556 return False;
2559 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2560 if (shortcut.keycode==0) {
2561 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2562 return False;
2565 if (ret)
2566 *ret = &shortcut;
2568 return True;
2572 static int
2573 getModMask(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2574 void **ret)
2576 static unsigned int mask;
2577 char *str;
2579 GET_STRING_OR_DEFAULT("Modifier Key", str);
2581 if (!str)
2582 return False;
2584 mask = wXModifierFromKey(str);
2585 if (mask < 0) {
2586 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2587 mask = 0;
2588 return False;
2591 if (addr)
2592 *(unsigned int*)addr = mask;
2594 if (ret)
2595 *ret = &mask;
2597 return True;
2601 #ifdef NEWSTUFF
2602 static int
2603 getRImages(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2604 void *addr, void **ret)
2606 unsigned int mask;
2607 char *str;
2608 RImage *image;
2609 int i, n;
2610 int w, h;
2612 GET_STRING_OR_DEFAULT("Image File Path", str);
2613 if (!str)
2614 return False;
2616 image = RLoadImage(scr->rcontext, str, 0);
2617 if (!image) {
2618 wwarning(_("could not load image in option %s: %s"), entry->key,
2619 RMessageForError(RErrorCode));
2620 return False;
2623 if (*(RImage**)addr) {
2624 RReleaseImage(*(RImage**)addr);
2626 if (addr)
2627 *(RImage**)addr = image;
2629 assert(ret == NULL);
2631 if (ret)
2632 *(RImage**)ret = image;
2635 return True;
2637 #endif
2639 # include <X11/cursorfont.h>
2640 typedef struct
2642 char *name;
2643 int id;
2644 } WCursorLookup;
2646 #define CURSOR_ID_NONE (XC_num_glyphs)
2648 static WCursorLookup cursor_table[] =
2650 { "X_cursor", XC_X_cursor },
2651 { "arrow", XC_arrow },
2652 { "based_arrow_down", XC_based_arrow_down },
2653 { "based_arrow_up", XC_based_arrow_up },
2654 { "boat", XC_boat },
2655 { "bogosity", XC_bogosity },
2656 { "bottom_left_corner", XC_bottom_left_corner },
2657 { "bottom_right_corner", XC_bottom_right_corner },
2658 { "bottom_side", XC_bottom_side },
2659 { "bottom_tee", XC_bottom_tee },
2660 { "box_spiral", XC_box_spiral },
2661 { "center_ptr", XC_center_ptr },
2662 { "circle", XC_circle },
2663 { "clock", XC_clock },
2664 { "coffee_mug", XC_coffee_mug },
2665 { "cross", XC_cross },
2666 { "cross_reverse", XC_cross_reverse },
2667 { "crosshair", XC_crosshair },
2668 { "diamond_cross", XC_diamond_cross },
2669 { "dot", XC_dot },
2670 { "dotbox", XC_dotbox },
2671 { "double_arrow", XC_double_arrow },
2672 { "draft_large", XC_draft_large },
2673 { "draft_small", XC_draft_small },
2674 { "draped_box", XC_draped_box },
2675 { "exchange", XC_exchange },
2676 { "fleur", XC_fleur },
2677 { "gobbler", XC_gobbler },
2678 { "gumby", XC_gumby },
2679 { "hand1", XC_hand1 },
2680 { "hand2", XC_hand2 },
2681 { "heart", XC_heart },
2682 { "icon", XC_icon },
2683 { "iron_cross", XC_iron_cross },
2684 { "left_ptr", XC_left_ptr },
2685 { "left_side", XC_left_side },
2686 { "left_tee", XC_left_tee },
2687 { "leftbutton", XC_leftbutton },
2688 { "ll_angle", XC_ll_angle },
2689 { "lr_angle", XC_lr_angle },
2690 { "man", XC_man },
2691 { "middlebutton", XC_middlebutton },
2692 { "mouse", XC_mouse },
2693 { "pencil", XC_pencil },
2694 { "pirate", XC_pirate },
2695 { "plus", XC_plus },
2696 { "question_arrow", XC_question_arrow },
2697 { "right_ptr", XC_right_ptr },
2698 { "right_side", XC_right_side },
2699 { "right_tee", XC_right_tee },
2700 { "rightbutton", XC_rightbutton },
2701 { "rtl_logo", XC_rtl_logo },
2702 { "sailboat", XC_sailboat },
2703 { "sb_down_arrow", XC_sb_down_arrow },
2704 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2705 { "sb_left_arrow", XC_sb_left_arrow },
2706 { "sb_right_arrow", XC_sb_right_arrow },
2707 { "sb_up_arrow", XC_sb_up_arrow },
2708 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2709 { "shuttle", XC_shuttle },
2710 { "sizing", XC_sizing },
2711 { "spider", XC_spider },
2712 { "spraycan", XC_spraycan },
2713 { "star", XC_star },
2714 { "target", XC_target },
2715 { "tcross", XC_tcross },
2716 { "top_left_arrow", XC_top_left_arrow },
2717 { "top_left_corner", XC_top_left_corner },
2718 { "top_right_corner", XC_top_right_corner },
2719 { "top_side", XC_top_side },
2720 { "top_tee", XC_top_tee },
2721 { "trek", XC_trek },
2722 { "ul_angle", XC_ul_angle },
2723 { "umbrella", XC_umbrella },
2724 { "ur_angle", XC_ur_angle },
2725 { "watch", XC_watch },
2726 { "xterm", XC_xterm },
2727 { NULL, CURSOR_ID_NONE }
2730 static void
2731 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2733 switch(status) {
2734 case BitmapOpenFailed:
2735 wwarning(_("failed to open bitmap file \"%s\""), filename);
2736 break;
2737 case BitmapFileInvalid:
2738 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2739 break;
2740 case BitmapNoMemory:
2741 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2742 break;
2743 case BitmapSuccess:
2744 XFreePixmap(dpy, bitmap);
2745 break;
2750 * (none)
2751 * (builtin, <cursor_name>)
2752 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2754 static int
2755 parse_cursor(WScreen *scr, WMPropList *pl, Cursor *cursor)
2757 WMPropList *elem;
2758 char *val;
2759 int nelem;
2760 int status = 0;
2762 nelem = WMGetPropListItemCount(pl);
2763 if (nelem < 1) {
2764 return(status);
2766 elem = WMGetFromPLArray(pl, 0);
2767 if (!elem || !WMIsPLString(elem)) {
2768 return(status);
2770 val = WMGetFromPLString(elem);
2772 if (0 == strcasecmp(val, "none")) {
2773 status = 1;
2774 *cursor = None;
2775 } else if (0 == strcasecmp(val, "builtin")) {
2776 int i;
2777 int cursor_id = CURSOR_ID_NONE;
2779 if (2 != nelem) {
2780 wwarning(_("bad number of arguments in cursor specification"));
2781 return(status);
2783 elem = WMGetFromPLArray(pl, 1);
2784 if (!elem || !WMIsPLString(elem)) {
2785 return(status);
2787 val = WMGetFromPLString(elem);
2789 for (i = 0; NULL != cursor_table[i].name; i++) {
2790 if (0 == strcasecmp(val, cursor_table[i].name)) {
2791 cursor_id = cursor_table[i].id;
2792 break;
2795 if (CURSOR_ID_NONE == cursor_id) {
2796 wwarning(_("unknown builtin cursor name \"%s\""), val);
2797 } else {
2798 *cursor = XCreateFontCursor(dpy, cursor_id);
2799 status = 1;
2801 } else if (0 == strcasecmp(val, "bitmap")) {
2802 char *bitmap_name;
2803 char *mask_name;
2804 int bitmap_status;
2805 int mask_status;
2806 Pixmap bitmap;
2807 Pixmap mask;
2808 unsigned int w, h;
2809 int x, y;
2810 XColor fg, bg;
2812 if (3 != nelem) {
2813 wwarning(_("bad number of arguments in cursor specification"));
2814 return(status);
2816 elem = WMGetFromPLArray(pl, 1);
2817 if (!elem || !WMIsPLString(elem)) {
2818 return(status);
2820 val = WMGetFromPLString(elem);
2821 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2822 if (!bitmap_name) {
2823 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2824 return(status);
2826 elem = WMGetFromPLArray(pl, 2);
2827 if (!elem || !WMIsPLString(elem)) {
2828 wfree(bitmap_name);
2829 return(status);
2831 val = WMGetFromPLString(elem);
2832 mask_name = FindImage(wPreferences.pixmap_path, val);
2833 if (!mask_name) {
2834 wfree(bitmap_name);
2835 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2836 return(status);
2838 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2839 &mask, &x, &y);
2840 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2841 &bitmap, &x, &y);
2842 if ((BitmapSuccess == bitmap_status) &&
2843 (BitmapSuccess == mask_status)) {
2844 fg.pixel = scr->black_pixel;
2845 bg.pixel = scr->white_pixel;
2846 XQueryColor(dpy, scr->w_colormap, &fg);
2847 XQueryColor(dpy, scr->w_colormap, &bg);
2848 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2849 status = 1;
2851 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2852 check_bitmap_status(mask_status, mask_name, mask);
2853 wfree(bitmap_name);
2854 wfree(mask_name);
2856 return(status);
2860 static int
2861 getCursor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2862 void **ret)
2864 static Cursor cursor;
2865 int status;
2866 int changed = 0;
2868 again:
2869 if (!WMIsPLArray(value)) {
2870 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2871 entry->key, "cursor specification");
2872 if (!changed) {
2873 value = entry->plvalue;
2874 changed = 1;
2875 wwarning(_("using default \"%s\" instead"), entry->default_value);
2876 goto again;
2878 return(False);
2880 status = parse_cursor(scr, value, &cursor);
2881 if (!status) {
2882 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2883 if (!changed) {
2884 value = entry->plvalue;
2885 changed = 1;
2886 wwarning(_("using default \"%s\" instead"), entry->default_value);
2887 goto again;
2889 return(False);
2891 if (ret) {
2892 *ret = &cursor;
2894 if (addr) {
2895 *(Cursor *)addr = cursor;
2897 return(True);
2899 #undef CURSOR_ID_NONE
2902 /* ---------------- value setting functions --------------- */
2903 static int
2904 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2906 return REFRESH_WINDOW_TITLE_COLOR;
2909 static int
2910 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2912 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2915 static int
2916 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2918 switch (which) {
2919 case WM_DOCK:
2920 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2921 break;
2922 case WM_CLIP:
2923 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2924 break;
2925 default:
2926 break;
2928 return 0;
2932 static int
2933 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2935 if (scr->workspaces) {
2936 wWorkspaceForceChange(scr, scr->current_workspace);
2937 wArrangeIcons(scr, False);
2939 return 0;
2942 #if not_used
2943 static int
2944 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2946 if (*value <= 0)
2947 *(int*)foo = 1;
2949 return 0;
2951 #endif
2955 static int
2956 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2958 Pixmap pixmap;
2959 RImage *img;
2960 int reset = 0;
2962 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2963 wPreferences.icon_size,
2964 ((*texture)->any.type & WREL_BORDER_MASK)
2965 ? WREL_ICON : WREL_FLAT);
2966 if (!img) {
2967 wwarning(_("could not render texture for icon background"));
2968 if (!entry->addr)
2969 wTextureDestroy(scr, *texture);
2970 return 0;
2972 RConvertImage(scr->rcontext, img, &pixmap);
2974 if (scr->icon_tile) {
2975 reset = 1;
2976 RReleaseImage(scr->icon_tile);
2977 XFreePixmap(dpy, scr->icon_tile_pixmap);
2980 scr->icon_tile = img;
2983 /* put the icon in the noticeboard hint */
2984 PropSetIconTileHint(scr, img);
2987 if (!wPreferences.flags.noclip) {
2988 if (scr->clip_tile) {
2989 RReleaseImage(scr->clip_tile);
2991 scr->clip_tile = wClipMakeTile(scr, img);
2994 scr->icon_tile_pixmap = pixmap;
2996 if (scr->def_icon_pixmap) {
2997 XFreePixmap(dpy, scr->def_icon_pixmap);
2998 scr->def_icon_pixmap = None;
3000 if (scr->def_ticon_pixmap) {
3001 XFreePixmap(dpy, scr->def_ticon_pixmap);
3002 scr->def_ticon_pixmap = None;
3005 if (scr->icon_back_texture) {
3006 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
3008 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
3010 if (scr->clip_balloon)
3011 XSetWindowBackground(dpy, scr->clip_balloon,
3012 (*texture)->any.color.pixel);
3015 * Free the texture as nobody else will use it, nor refer to it.
3017 if (!entry->addr)
3018 wTextureDestroy(scr, *texture);
3020 return (reset ? REFRESH_ICON_TILE : 0);
3025 static int
3026 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3028 if (scr->title_font) {
3029 WMReleaseFont(scr->title_font);
3031 scr->title_font = font;
3033 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
3037 static int
3038 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3040 if (scr->menu_title_font) {
3041 WMReleaseFont(scr->menu_title_font);
3044 scr->menu_title_font = font;
3046 return REFRESH_MENU_TITLE_FONT;
3050 static int
3051 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3053 if (scr->menu_entry_font) {
3054 WMReleaseFont(scr->menu_entry_font);
3056 scr->menu_entry_font = font;
3058 return REFRESH_MENU_FONT;
3063 static int
3064 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3066 if (scr->icon_title_font) {
3067 WMReleaseFont(scr->icon_title_font);
3070 scr->icon_title_font = font;
3072 return REFRESH_ICON_FONT;
3076 static int
3077 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3079 if (scr->clip_title_font) {
3080 WMReleaseFont(scr->clip_title_font);
3083 scr->clip_title_font = font;
3085 return REFRESH_ICON_FONT;
3089 static int
3090 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3092 if (scr->workspace_name_font) {
3093 WMReleaseFont(scr->workspace_name_font);
3096 scr->workspace_name_font = font;
3098 return 0;
3102 static int
3103 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3105 if (scr->select_color)
3106 WMReleaseColor(scr->select_color);
3108 scr->select_color =
3109 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3110 color->blue, True);
3112 wFreeColor(scr, color->pixel);
3114 return REFRESH_MENU_COLOR;
3118 static int
3119 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3121 if (scr->select_text_color)
3122 WMReleaseColor(scr->select_text_color);
3124 scr->select_text_color =
3125 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3126 color->blue, True);
3128 wFreeColor(scr, color->pixel);
3130 return REFRESH_MENU_COLOR;
3134 static int
3135 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3137 if (scr->clip_title_color[index])
3138 WMReleaseColor(scr->clip_title_color[index]);
3139 scr->clip_title_color[index] = WMCreateRGBColor(scr->wmscreen, color->red,
3140 color->green, color->blue,
3141 True);
3142 #ifdef GRADIENT_CLIP_ARROW
3143 if (index == CLIP_NORMAL) {
3144 RImage *image;
3145 RColor color1, color2;
3146 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3147 int as = pt - 15; /* 15 = 5+5+5 */
3149 FREE_PIXMAP(scr->clip_arrow_gradient);
3151 color1.red = (color->red >> 8)*6/10;
3152 color1.green = (color->green >> 8)*6/10;
3153 color1.blue = (color->blue >> 8)*6/10;
3155 color2.red = WMIN((color->red >> 8)*20/10, 255);
3156 color2.green = WMIN((color->green >> 8)*20/10, 255);
3157 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3159 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3160 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3161 RReleaseImage(image);
3163 #endif /* GRADIENT_CLIP_ARROW */
3165 wFreeColor(scr, color->pixel);
3167 return REFRESH_ICON_TITLE_COLOR;
3171 static int
3172 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3174 if (scr->window_title_color[index])
3175 WMReleaseColor(scr->window_title_color[index]);
3177 scr->window_title_color[index] =
3178 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue,
3179 True);
3181 wFreeColor(scr, color->pixel);
3183 return REFRESH_WINDOW_TITLE_COLOR;
3187 static int
3188 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3190 if (scr->menu_title_color[0])
3191 WMReleaseColor(scr->menu_title_color[0]);
3193 scr->menu_title_color[0] =
3194 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3195 color->blue, True);
3197 wFreeColor(scr, color->pixel);
3199 return REFRESH_MENU_TITLE_COLOR;
3203 static int
3204 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3206 if (scr->mtext_color)
3207 WMReleaseColor(scr->mtext_color);
3209 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3210 color->green, color->blue, True);
3212 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3213 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3214 } else {
3215 WMSetColorAlpha(scr->dtext_color, 0xffff);
3218 wFreeColor(scr, color->pixel);
3220 return REFRESH_MENU_COLOR;
3224 static int
3225 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3227 if (scr->dtext_color)
3228 WMReleaseColor(scr->dtext_color);
3230 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3231 color->green, color->blue, True);
3233 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3234 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3235 } else {
3236 WMSetColorAlpha(scr->dtext_color, 0xffff);
3239 wFreeColor(scr, color->pixel);
3241 return REFRESH_MENU_COLOR;
3245 static int
3246 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3248 if (scr->icon_title_color)
3249 WMReleaseColor(scr->icon_title_color);
3250 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red,
3251 color->green, color->blue,
3252 True);
3254 wFreeColor(scr, color->pixel);
3256 return REFRESH_ICON_TITLE_COLOR;
3260 static int
3261 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3263 if (scr->icon_title_texture) {
3264 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3266 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3268 return REFRESH_ICON_TITLE_BACK;
3272 static void
3273 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3275 close(scr->helper_fd);
3276 scr->helper_fd = 0;
3277 scr->helper_pid = 0;
3278 scr->flags.backimage_helper_launched = 0;
3282 static int
3283 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3284 void *bar)
3286 WMPropList *val;
3287 char *str;
3288 int i;
3290 if (scr->flags.backimage_helper_launched) {
3291 if (WMGetPropListItemCount(value)==0) {
3292 SendHelperMessage(scr, 'C', 0, NULL);
3293 SendHelperMessage(scr, 'K', 0, NULL);
3295 WMReleasePropList(value);
3296 return 0;
3298 } else {
3299 pid_t pid;
3300 int filedes[2];
3302 if (WMGetPropListItemCount(value) == 0)
3303 return 0;
3305 if (pipe(filedes) < 0) {
3306 wsyserror("pipe() failed:can't set workspace specific background image");
3308 WMReleasePropList(value);
3309 return 0;
3312 pid = fork();
3313 if (pid < 0) {
3314 wsyserror("fork() failed:can't set workspace specific background image");
3315 if (close(filedes[0]) < 0)
3316 wsyserror("could not close pipe");
3317 if (close(filedes[1]) < 0)
3318 wsyserror("could not close pipe");
3320 } else if (pid == 0) {
3321 char *dither;
3323 SetupEnvironment(scr);
3325 if (close(0) < 0)
3326 wsyserror("could not close pipe");
3327 if (dup(filedes[0]) < 0) {
3328 wsyserror("dup() failed:can't set workspace specific background image");
3330 dither = wPreferences.no_dithering ? "-m" : "-d";
3331 if (wPreferences.smooth_workspace_back)
3332 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3333 else
3334 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3335 wsyserror("could not execute wmsetbg");
3336 exit(1);
3337 } else {
3339 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3340 wsyserror("error setting close-on-exec flag");
3342 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3343 wsyserror("error setting close-on-exec flag");
3346 scr->helper_fd = filedes[1];
3347 scr->helper_pid = pid;
3348 scr->flags.backimage_helper_launched = 1;
3350 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3352 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3357 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3358 val = WMGetFromPLArray(value, i);
3359 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val)>0) {
3360 str = WMGetPropListDescription(val, False);
3362 SendHelperMessage(scr, 'S', i+1, str);
3364 wfree(str);
3365 } else {
3366 SendHelperMessage(scr, 'U', i+1, NULL);
3369 sleep(1);
3371 WMReleasePropList(value);
3372 return 0;
3376 static int
3377 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3378 void *bar)
3380 if (scr->flags.backimage_helper_launched) {
3381 char *str;
3383 if (WMGetPropListItemCount(value)==0) {
3384 SendHelperMessage(scr, 'U', 0, NULL);
3385 } else {
3386 /* set the default workspace background to this one */
3387 str = WMGetPropListDescription(value, False);
3388 if (str) {
3389 SendHelperMessage(scr, 'S', 0, str);
3390 wfree(str);
3391 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3392 } else {
3393 SendHelperMessage(scr, 'U', 0, NULL);
3396 } else if (WMGetPropListItemCount(value) > 0) {
3397 char *command;
3398 char *text;
3399 char *dither;
3400 int len;
3402 SetupEnvironment(scr);
3403 text = WMGetPropListDescription(value, False);
3404 len = strlen(text)+40;
3405 command = wmalloc(len);
3406 dither = wPreferences.no_dithering ? "-m" : "-d";
3407 if (wPreferences.smooth_workspace_back)
3408 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3409 else
3410 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3411 wfree(text);
3412 system(command);
3413 wfree(command);
3415 WMReleasePropList(value);
3417 return 0;
3421 #ifdef VIRTUAL_DESKTOP
3422 static int
3423 setVirtualDeskEnable(WScreen *scr, WDefaultEntry *entry, void *foo, void *bar)
3425 wWorkspaceUpdateEdge(scr);
3426 return 0;
3428 #endif
3431 static int
3432 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3434 if (scr->widget_texture) {
3435 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3437 scr->widget_texture = *(WTexSolid**)texture;
3439 return 0;
3443 static int
3444 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3446 if (scr->window_title_texture[WS_FOCUSED]) {
3447 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3449 scr->window_title_texture[WS_FOCUSED] = *texture;
3451 return REFRESH_WINDOW_TEXTURES;
3455 static int
3456 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3458 if (scr->window_title_texture[WS_PFOCUSED]) {
3459 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3461 scr->window_title_texture[WS_PFOCUSED] = *texture;
3463 return REFRESH_WINDOW_TEXTURES;
3467 static int
3468 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3470 if (scr->window_title_texture[WS_UNFOCUSED]) {
3471 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3473 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3475 return REFRESH_WINDOW_TEXTURES;
3479 static int
3480 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3482 if (scr->resizebar_texture[0]) {
3483 wTextureDestroy(scr, scr->resizebar_texture[0]);
3485 scr->resizebar_texture[0] = *texture;
3487 return REFRESH_WINDOW_TEXTURES;
3491 static int
3492 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3494 if (scr->menu_title_texture[0]) {
3495 wTextureDestroy(scr, scr->menu_title_texture[0]);
3497 scr->menu_title_texture[0] = *texture;
3499 return REFRESH_MENU_TITLE_TEXTURE;
3503 static int
3504 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3506 if (scr->menu_item_texture) {
3507 wTextureDestroy(scr, scr->menu_item_texture);
3508 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3510 scr->menu_item_texture = *texture;
3512 scr->menu_item_auxtexture
3513 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3515 return REFRESH_MENU_TEXTURE;
3519 static int
3520 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3522 WWindow *wwin;
3523 wKeyBindings[index] = *shortcut;
3525 wwin = scr->focused_window;
3527 while (wwin!=NULL) {
3528 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3530 if (!WFLAGP(wwin, no_bind_keys)) {
3531 wWindowSetKeyGrabs(wwin);
3533 wwin = wwin->prev;
3536 return 0;
3540 static int
3541 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3543 wScreenUpdateUsableArea(scr);
3544 wArrangeIcons(scr, True);
3546 return 0;
3550 static int
3551 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3553 wScreenUpdateUsableArea(scr);
3555 return 0;
3559 static int
3560 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3562 return REFRESH_MENU_TEXTURE;
3566 static RImage *chopOffImage(RImage *image, int x, int y, int w, int h)
3568 RImage *img= RCreateImage(w, h, image->format == RRGBAFormat);
3570 RCopyArea(img, image, x, y, w, h, 0, 0);
3572 return img;
3575 static int
3576 setSwPOptions(WScreen *scr, WDefaultEntry *entry, WMPropList *array, void *foo)
3578 char *path;
3579 RImage *bgimage;
3580 int cwidth, cheight;
3581 WPreferences *prefs= (WPreferences*)foo;
3583 if (!WMIsPLArray(array) || WMGetPropListItemCount(array)==0) {
3584 if (prefs->swtileImage) RReleaseImage(prefs->swtileImage);
3585 prefs->swtileImage= NULL;
3587 WMReleasePropList(array);
3588 return 0;
3591 switch (WMGetPropListItemCount(array))
3593 case 4:
3594 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3595 wwarning(_("Invalid arguments for option \"%s\""),
3596 entry->key);
3597 break;
3598 } else
3599 path= FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3601 if (!path) {
3602 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3603 WMGetFromPLString(WMGetFromPLArray(array, 1)),
3604 entry->key);
3605 } else {
3606 bgimage= RLoadImage(scr->rcontext, path, 0);
3607 if (!bgimage) {
3608 wwarning(_("Could not load image \"%s\" for option \"%s\""),
3609 path, entry->key);
3610 wfree(path);
3611 } else {
3612 wfree(path);
3614 cwidth= atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3615 cheight= atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3617 if (cwidth <= 0 || cheight <= 0 ||
3618 cwidth >= bgimage->width - 2 ||
3619 cheight >= bgimage->height - 2)
3620 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3621 else {
3622 int i;
3623 int swidth, theight;
3624 for (i= 0; i < 9; i++) {
3625 if (prefs->swbackImage[i])
3626 RReleaseImage(prefs->swbackImage[i]);
3627 prefs->swbackImage[i]= NULL;
3629 swidth= (bgimage->width - cwidth) / 2;
3630 theight= (bgimage->height - cheight) / 2;
3632 prefs->swbackImage[0]= chopOffImage(bgimage, 0, 0,
3633 swidth, theight);
3634 prefs->swbackImage[1]= chopOffImage(bgimage, swidth, 0,
3635 cwidth, theight);
3636 prefs->swbackImage[2]= chopOffImage(bgimage, swidth+cwidth, 0,
3637 swidth, theight);
3639 prefs->swbackImage[3]= chopOffImage(bgimage, 0, theight,
3640 swidth, cheight);
3641 prefs->swbackImage[4]= chopOffImage(bgimage, swidth, theight,
3642 cwidth, cheight);
3643 prefs->swbackImage[5]= chopOffImage(bgimage, swidth+cwidth, theight,
3644 swidth, cheight);
3646 prefs->swbackImage[6]= chopOffImage(bgimage, 0, theight+cheight,
3647 swidth, theight);
3648 prefs->swbackImage[7]= chopOffImage(bgimage, swidth, theight+cheight,
3649 cwidth, theight);
3650 prefs->swbackImage[8]= chopOffImage(bgimage, swidth+cwidth, theight+cheight,
3651 swidth, theight);
3653 // check if anything failed
3654 for (i= 0; i < 9; i++) {
3655 if (!prefs->swbackImage[i]) {
3656 for (; i>=0; --i) {
3657 RReleaseImage(prefs->swbackImage[i]);
3658 prefs->swbackImage[i]= NULL;
3660 break;
3664 RReleaseImage(bgimage);
3668 case 1:
3669 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3670 wwarning(_("Invalid arguments for option \"%s\""),
3671 entry->key);
3672 break;
3673 } else
3674 path= FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3676 if (!path) {
3677 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3678 WMGetFromPLString(WMGetFromPLArray(array, 0)),
3679 entry->key);
3680 } else {
3681 if (prefs->swtileImage) RReleaseImage(prefs->swtileImage);
3683 prefs->swtileImage= RLoadImage(scr->rcontext, path, 0);
3684 if (!prefs->swtileImage) {
3685 wwarning(_("Could not load image \"%s\" for option \"%s\""),
3686 path, entry->key);
3688 wfree(path);
3690 break;
3692 default:
3693 wwarning(_("Invalid number of arguments for option \"%s\""),
3694 entry->key);
3695 break;
3698 WMReleasePropList(array);
3700 return 0;
3705 static int
3706 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3708 return REFRESH_BUTTON_IMAGES;
3713 * Very ugly kluge.
3714 * Need access to the double click variables, so that all widgets in
3715 * wmaker panels will have the same dbl-click values.
3716 * TODO: figure a better way of dealing with it.
3718 #include <WINGs/WINGsP.h>
3720 static int
3721 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3723 extern _WINGsConfiguration WINGsConfiguration;
3725 if (*value <= 0)
3726 *(int*)foo = 1;
3728 WINGsConfiguration.doubleClickDelay = *value;
3730 return 0;
3734 static int
3735 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3737 if (wCursor[index] != None) {
3738 XFreeCursor(dpy, wCursor[index]);
3741 wCursor[index] = *cursor;
3743 if (index==WCUR_ROOT && *cursor!=None) {
3744 XDefineCursor(dpy, scr->root_win, *cursor);
3747 return 0;