- Fixed a few typos
[wmaker-crm.git] / src / defaults.c
blob724e915e939640d0fa0b091890ee4e2ab208dbca
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\")", &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 void
975 wDefaultsMergeGlobalMenus(WDDomain *menuDomain)
977 WMPropList *menu = menuDomain->dictionary;
978 WMPropList *submenu;
980 if (!menu || !WMIsPLArray(menu))
981 return;
983 #ifdef GLOBAL_PREAMBLE_MENU_FILE
984 submenu = WMReadPropListFromFile(SYSCONFDIR"/WindowMaker/"GLOBAL_PREAMBLE_MENU_FILE);
986 if (submenu && !WMIsPLArray(submenu)) {
987 wwarning(_("invalid global menu file %s"),
988 GLOBAL_PREAMBLE_MENU_FILE);
989 WMReleasePropList(submenu);
990 submenu = NULL;
992 if (submenu) {
993 prependMenu(menu, submenu);
994 WMReleasePropList(submenu);
996 #endif
998 #ifdef GLOBAL_EPILOGUE_MENU_FILE
999 submenu = WMReadPropListFromFile(SYSCONFDIR"/WindowMaker/"GLOBAL_EPILOGUE_MENU_FILE);
1001 if (submenu && !WMIsPLArray(submenu)) {
1002 wwarning(_("invalid global menu file %s"),
1003 GLOBAL_EPILOGUE_MENU_FILE);
1004 WMReleasePropList(submenu);
1005 submenu = NULL;
1007 if (submenu) {
1008 appendMenu(menu, submenu);
1009 WMReleasePropList(submenu);
1011 #endif
1013 menuDomain->dictionary = menu;
1017 #if 0
1018 WMPropList*
1019 wDefaultsInit(int screen_number)
1021 static int defaults_inited = 0;
1022 WMPropList *dict;
1024 if (!defaults_inited) {
1025 initDefaults();
1028 dict = PLGetDomain(wDomainName);
1029 if (!dict) {
1030 wwarning(_("could not read domain \"%s\" from defaults database"),
1031 WMGetFromPLString(wDomainName));
1034 return dict;
1036 #endif
1039 void
1040 wDefaultsDestroyDomain(WDDomain *domain)
1042 if (domain->dictionary)
1043 WMReleasePropList(domain->dictionary);
1044 wfree(domain->path);
1045 wfree(domain);
1049 WDDomain*
1050 wDefaultsInitDomain(char *domain, Bool requireDictionary)
1052 WDDomain *db;
1053 struct stat stbuf;
1054 static int inited = 0;
1055 char path[PATH_MAX];
1056 char *the_path;
1057 WMPropList *shared_dict=NULL;
1059 if (!inited) {
1060 inited = 1;
1061 initDefaults();
1064 db = wmalloc(sizeof(WDDomain));
1065 memset(db, 0, sizeof(WDDomain));
1066 db->domain_name = domain;
1067 db->path = wdefaultspathfordomain(domain);
1068 the_path = db->path;
1070 if (the_path && stat(the_path, &stbuf)>=0) {
1071 db->dictionary = WMReadPropListFromFile(the_path);
1072 if (db->dictionary) {
1073 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
1074 WMReleasePropList(db->dictionary);
1075 db->dictionary = NULL;
1076 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1077 domain, the_path);
1079 db->timestamp = stbuf.st_mtime;
1080 } else {
1081 wwarning(_("could not load domain %s from user defaults database"),
1082 domain);
1086 /* global system dictionary */
1087 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
1088 if (stat(path, &stbuf)>=0) {
1089 shared_dict = WMReadPropListFromFile(path);
1090 if (shared_dict) {
1091 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
1092 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1093 domain, path);
1094 WMReleasePropList(shared_dict);
1095 shared_dict = NULL;
1096 } else {
1097 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
1098 WMIsPLDictionary(db->dictionary)) {
1099 WMMergePLDictionaries(shared_dict, db->dictionary, True);
1100 WMReleasePropList(db->dictionary);
1101 db->dictionary = shared_dict;
1102 if (stbuf.st_mtime > db->timestamp)
1103 db->timestamp = stbuf.st_mtime;
1104 } else if (!db->dictionary) {
1105 db->dictionary = shared_dict;
1106 if (stbuf.st_mtime > db->timestamp)
1107 db->timestamp = stbuf.st_mtime;
1110 } else {
1111 wwarning(_("could not load domain %s from global defaults database (%s)"),
1112 domain, path);
1116 return db;
1120 void
1121 wReadStaticDefaults(WMPropList *dict)
1123 WMPropList *plvalue;
1124 WDefaultEntry *entry;
1125 int i;
1126 void *tdata;
1129 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1130 entry = &staticOptionList[i];
1132 if (dict)
1133 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
1134 else
1135 plvalue = NULL;
1137 if (!plvalue) {
1138 /* no default in the DB. Use builtin default */
1139 plvalue = entry->plvalue;
1142 if (plvalue) {
1143 /* convert data */
1144 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1145 if (entry->update) {
1146 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1154 void
1155 wDefaultsCheckDomains(void *foo)
1157 WScreen *scr;
1158 struct stat stbuf;
1159 WMPropList *shared_dict = NULL;
1160 WMPropList *dict;
1161 int i;
1163 #ifdef HEARTBEAT
1164 puts("Checking domains...");
1165 #endif
1166 if (stat(WDWindowMaker->path, &stbuf)>=0
1167 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1168 #ifdef HEARTBEAT
1169 puts("Checking WindowMaker domain");
1170 #endif
1171 WDWindowMaker->timestamp = stbuf.st_mtime;
1173 /* global dictionary */
1174 shared_dict = readGlobalDomain("WindowMaker", True);
1175 /* user dictionary */
1176 dict = WMReadPropListFromFile(WDWindowMaker->path);
1177 if (dict) {
1178 if (!WMIsPLDictionary(dict)) {
1179 WMReleasePropList(dict);
1180 dict = NULL;
1181 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1182 "WindowMaker", WDWindowMaker->path);
1183 } else {
1184 if (shared_dict) {
1185 WMMergePLDictionaries(shared_dict, dict, True);
1186 WMReleasePropList(dict);
1187 dict = shared_dict;
1188 shared_dict = NULL;
1190 for (i=0; i<wScreenCount; i++) {
1191 scr = wScreenWithNumber(i);
1192 if (scr)
1193 wReadDefaults(scr, dict);
1195 if (WDWindowMaker->dictionary) {
1196 WMReleasePropList(WDWindowMaker->dictionary);
1198 WDWindowMaker->dictionary = dict;
1200 } else {
1201 wwarning(_("could not load domain %s from user defaults database"),
1202 "WindowMaker");
1204 if (shared_dict) {
1205 WMReleasePropList(shared_dict);
1209 if (stat(WDWindowAttributes->path, &stbuf)>=0
1210 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1211 #ifdef HEARTBEAT
1212 puts("Checking WMWindowAttributes domain");
1213 #endif
1214 /* global dictionary */
1215 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1216 /* user dictionary */
1217 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1218 if (dict) {
1219 if (!WMIsPLDictionary(dict)) {
1220 WMReleasePropList(dict);
1221 dict = NULL;
1222 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1223 "WMWindowAttributes", WDWindowAttributes->path);
1224 } else {
1225 if (shared_dict) {
1226 WMMergePLDictionaries(shared_dict, dict, True);
1227 WMReleasePropList(dict);
1228 dict = shared_dict;
1229 shared_dict = NULL;
1231 if (WDWindowAttributes->dictionary) {
1232 WMReleasePropList(WDWindowAttributes->dictionary);
1234 WDWindowAttributes->dictionary = dict;
1235 for (i=0; i<wScreenCount; i++) {
1236 scr = wScreenWithNumber(i);
1237 if (scr) {
1238 RImage *image;
1240 wDefaultUpdateIcons(scr);
1242 /* Update the panel image if changed */
1243 /* Don't worry. If the image is the same these
1244 * functions will have no performance impact. */
1245 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1247 if (!image) {
1248 wwarning(_("could not load logo image for panels: %s"),
1249 RMessageForError(RErrorCode));
1250 } else {
1251 WMSetApplicationIconImage(scr->wmscreen, image);
1252 RReleaseImage(image);
1257 } else {
1258 wwarning(_("could not load domain %s from user defaults database"),
1259 "WMWindowAttributes");
1261 WDWindowAttributes->timestamp = stbuf.st_mtime;
1262 if (shared_dict) {
1263 WMReleasePropList(shared_dict);
1267 #ifndef LITE
1268 if (stat(WDRootMenu->path, &stbuf)>=0
1269 && WDRootMenu->timestamp < stbuf.st_mtime) {
1270 dict = WMReadPropListFromFile(WDRootMenu->path);
1271 #ifdef HEARTBEAT
1272 puts("Checking WMRootMenu domain");
1273 #endif
1274 if (dict) {
1275 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1276 WMReleasePropList(dict);
1277 dict = NULL;
1278 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1279 "WMRootMenu", WDRootMenu->path);
1280 } else {
1281 if (WDRootMenu->dictionary) {
1282 WMReleasePropList(WDRootMenu->dictionary);
1284 WDRootMenu->dictionary = dict;
1285 wDefaultsMergeGlobalMenus(WDRootMenu);
1287 } else {
1288 wwarning(_("could not load domain %s from user defaults database"),
1289 "WMRootMenu");
1291 WDRootMenu->timestamp = stbuf.st_mtime;
1293 #endif /* !LITE */
1295 if (!foo)
1296 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1300 void
1301 wReadDefaults(WScreen *scr, WMPropList *new_dict)
1303 WMPropList *plvalue, *old_value;
1304 WDefaultEntry *entry;
1305 int i, must_update;
1306 int update_workspace_back = 0; /* kluge :/ */
1307 int needs_refresh;
1308 void *tdata;
1309 WMPropList *old_dict = (WDWindowMaker->dictionary!=new_dict
1310 ? WDWindowMaker->dictionary : NULL);
1312 must_update = 0;
1314 needs_refresh = 0;
1316 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1317 entry = &optionList[i];
1319 if (new_dict)
1320 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1321 else
1322 plvalue = NULL;
1324 if (!old_dict)
1325 old_value = NULL;
1326 else
1327 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1330 if (!plvalue && !old_value) {
1331 /* no default in the DB. Use builtin default */
1332 plvalue = entry->plvalue;
1333 if (plvalue && new_dict) {
1334 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1335 must_update = 1;
1337 } else if (!plvalue) {
1338 /* value was deleted from DB. Keep current value */
1339 continue;
1340 } else if (!old_value) {
1341 /* set value for the 1st time */
1342 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1343 /* value has changed */
1344 } else {
1346 if (strcmp(entry->key, "WorkspaceBack") == 0
1347 && update_workspace_back
1348 && scr->flags.backimage_helper_launched) {
1349 } else {
1350 /* value was not changed since last time */
1351 continue;
1355 if (plvalue) {
1356 #ifdef DEBUG
1357 printf("Updating %s to %s\n", entry->key,
1358 WMGetPropListDescription(plvalue, False));
1359 #endif
1360 /* convert data */
1361 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1363 * If the WorkspaceSpecificBack data has been changed
1364 * so that the helper will be launched now, we must be
1365 * sure to send the default background texture config
1366 * to the helper.
1368 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1369 && !scr->flags.backimage_helper_launched) {
1370 update_workspace_back = 1;
1372 if (entry->update) {
1373 needs_refresh |=
1374 (*entry->update)(scr, entry, tdata, entry->extra_data);
1380 if (needs_refresh!=0 && !scr->flags.startup) {
1381 int foo;
1383 foo = 0;
1384 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1385 foo |= WTextureSettings;
1386 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1387 foo |= WFontSettings;
1388 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1389 foo |= WColorSettings;
1390 if (foo)
1391 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1392 (void*)foo);
1394 foo = 0;
1395 if (needs_refresh & REFRESH_MENU_TEXTURE)
1396 foo |= WTextureSettings;
1397 if (needs_refresh & REFRESH_MENU_FONT)
1398 foo |= WFontSettings;
1399 if (needs_refresh & REFRESH_MENU_COLOR)
1400 foo |= WColorSettings;
1401 if (foo)
1402 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1403 (void*)foo);
1405 foo = 0;
1406 if (needs_refresh & REFRESH_WINDOW_FONT) {
1407 foo |= WFontSettings;
1409 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1410 foo |= WTextureSettings;
1412 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1413 foo |= WColorSettings;
1415 if (foo)
1416 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1417 (void*)foo);
1419 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1420 foo = 0;
1421 if (needs_refresh & REFRESH_ICON_FONT) {
1422 foo |= WFontSettings;
1424 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1425 foo |= WTextureSettings;
1427 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1428 foo |= WTextureSettings;
1430 if (foo)
1431 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1432 (void*)foo);
1434 if (needs_refresh & REFRESH_ICON_TILE)
1435 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1440 void
1441 wDefaultUpdateIcons(WScreen *scr)
1443 WAppIcon *aicon = scr->app_icon_list;
1444 WWindow *wwin = scr->focused_window;
1445 char *file;
1447 while(aicon) {
1448 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1449 False);
1450 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1451 || (file && !aicon->icon->file)) {
1452 RImage *new_image;
1454 if (aicon->icon->file)
1455 wfree(aicon->icon->file);
1456 aicon->icon->file = wstrdup(file);
1458 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1459 aicon->wm_class);
1460 if (new_image) {
1461 wIconChangeImage(aicon->icon, new_image);
1462 wAppIconPaint(aicon);
1465 aicon = aicon->next;
1468 if (!wPreferences.flags.noclip)
1469 wClipIconPaint(scr->clip_icon);
1471 while (wwin) {
1472 if (wwin->icon && wwin->flags.miniaturized) {
1473 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1474 False);
1475 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1476 || (file && !wwin->icon->file)) {
1477 RImage *new_image;
1479 if (wwin->icon->file)
1480 wfree(wwin->icon->file);
1481 wwin->icon->file = wstrdup(file);
1483 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1484 wwin->wm_class);
1485 if (new_image)
1486 wIconChangeImage(wwin->icon, new_image);
1489 wwin = wwin->prev;
1494 /* --------------------------- Local ----------------------- */
1496 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1497 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1498 entry->key, x); \
1499 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1500 var = entry->default_value;\
1501 } else var = WMGetFromPLString(value)\
1507 static int
1508 string2index(WMPropList *key, WMPropList *val, char *def,
1509 WOptionEnumeration *values)
1511 char *str;
1512 WOptionEnumeration *v;
1513 char buffer[TOTAL_VALUES_LENGTH];
1515 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1516 for (v=values; v->string!=NULL; v++) {
1517 if (strcasecmp(v->string, str)==0)
1518 return v->value;
1522 buffer[0] = 0;
1523 for (v=values; v->string!=NULL; v++) {
1524 if (!v->is_alias) {
1525 if (buffer[0]!=0)
1526 strcat(buffer, ", ");
1527 strcat(buffer, v->string);
1530 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1531 WMGetFromPLString(key), buffer);
1533 if (def) {
1534 return string2index(key, val, NULL, values);
1537 return -1;
1544 * value - is the value in the defaults DB
1545 * addr - is the address to store the data
1546 * ret - is the address to store a pointer to a temporary buffer. ret
1547 * must not be freed and is used by the set functions
1549 static int
1550 getBool(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1551 void **ret)
1553 static char data;
1554 char *val;
1555 int second_pass=0;
1557 GET_STRING_OR_DEFAULT("Boolean", val);
1559 again:
1560 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1561 || strcasecmp(val, "YES")==0) {
1563 data = 1;
1564 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1565 || strcasecmp(val, "NO")==0) {
1566 data = 0;
1567 } else {
1568 int i;
1569 if (sscanf(val, "%i", &i)==1) {
1570 if (i!=0)
1571 data = 1;
1572 else
1573 data = 0;
1574 } else {
1575 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1576 val, entry->key);
1577 if (second_pass==0) {
1578 val = WMGetFromPLString(entry->plvalue);
1579 second_pass = 1;
1580 wwarning(_("using default \"%s\" instead"), val);
1581 goto again;
1583 return False;
1587 if (ret)
1588 *ret = &data;
1589 if (addr)
1590 *(char*)addr = data;
1592 return True;
1596 static int
1597 getInt(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1598 void **ret)
1600 static int data;
1601 char *val;
1604 GET_STRING_OR_DEFAULT("Integer", val);
1606 if (sscanf(val, "%i", &data)!=1) {
1607 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1608 val, entry->key);
1609 val = WMGetFromPLString(entry->plvalue);
1610 wwarning(_("using default \"%s\" instead"), val);
1611 if (sscanf(val, "%i", &data)!=1) {
1612 return False;
1616 if (ret)
1617 *ret = &data;
1618 if (addr)
1619 *(int*)addr = data;
1621 return True;
1625 static int
1626 getCoord(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1627 void **ret)
1629 static WCoord data;
1630 char *val_x, *val_y;
1631 int nelem, changed=0;
1632 WMPropList *elem_x, *elem_y;
1634 again:
1635 if (!WMIsPLArray(value)) {
1636 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1637 entry->key, "Coordinate");
1638 if (changed==0) {
1639 value = entry->plvalue;
1640 changed = 1;
1641 wwarning(_("using default \"%s\" instead"), entry->default_value);
1642 goto again;
1644 return False;
1647 nelem = WMGetPropListItemCount(value);
1648 if (nelem != 2) {
1649 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1650 entry->key);
1651 if (changed==0) {
1652 value = entry->plvalue;
1653 changed = 1;
1654 wwarning(_("using default \"%s\" instead"), entry->default_value);
1655 goto again;
1657 return False;
1660 elem_x = WMGetFromPLArray(value, 0);
1661 elem_y = WMGetFromPLArray(value, 1);
1663 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1664 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1665 entry->key);
1666 if (changed==0) {
1667 value = entry->plvalue;
1668 changed = 1;
1669 wwarning(_("using default \"%s\" instead"), entry->default_value);
1670 goto again;
1672 return False;
1675 val_x = WMGetFromPLString(elem_x);
1676 val_y = WMGetFromPLString(elem_y);
1678 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1679 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1680 if (changed==0) {
1681 value = entry->plvalue;
1682 changed = 1;
1683 wwarning(_("using default \"%s\" instead"), entry->default_value);
1684 goto again;
1686 return False;
1689 if (data.x < 0)
1690 data.x = 0;
1691 else if (data.x > scr->scr_width/3)
1692 data.x = scr->scr_width/3;
1693 if (data.y < 0)
1694 data.y = 0;
1695 else if (data.y > scr->scr_height/3)
1696 data.y = scr->scr_height/3;
1698 if (ret)
1699 *ret = &data;
1700 if (addr)
1701 *(WCoord*)addr = data;
1703 return True;
1707 static int
1708 getPropList(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1709 void **ret)
1711 WMRetainPropList(value);
1713 *ret= value;
1715 return True;
1718 #if 0
1719 /* This function is not used at the moment. */
1720 static int
1721 getString(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1722 void **ret)
1724 static char *data;
1726 GET_STRING_OR_DEFAULT("String", data);
1728 if (!data) {
1729 data = WMGetFromPLString(entry->plvalue);
1730 if (!data)
1731 return False;
1734 if (ret)
1735 *ret = &data;
1736 if (addr)
1737 *(char**)addr = wstrdup(data);
1739 return True;
1741 #endif
1744 static int
1745 getPathList(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1746 void **ret)
1748 static char *data;
1749 int i, count, len;
1750 char *ptr;
1751 WMPropList *d;
1752 int changed=0;
1754 again:
1755 if (!WMIsPLArray(value)) {
1756 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1757 entry->key, "an array of paths");
1758 if (changed==0) {
1759 value = entry->plvalue;
1760 changed = 1;
1761 wwarning(_("using default \"%s\" instead"), entry->default_value);
1762 goto again;
1764 return False;
1767 i = 0;
1768 count = WMGetPropListItemCount(value);
1769 if (count < 1) {
1770 if (changed==0) {
1771 value = entry->plvalue;
1772 changed = 1;
1773 wwarning(_("using default \"%s\" instead"), entry->default_value);
1774 goto again;
1776 return False;
1779 len = 0;
1780 for (i=0; i<count; i++) {
1781 d = WMGetFromPLArray(value, i);
1782 if (!d || !WMIsPLString(d)) {
1783 count = i;
1784 break;
1786 len += strlen(WMGetFromPLString(d))+1;
1789 ptr = data = wmalloc(len+1);
1791 for (i=0; i<count; i++) {
1792 d = WMGetFromPLArray(value, i);
1793 if (!d || !WMIsPLString(d)) {
1794 break;
1796 strcpy(ptr, WMGetFromPLString(d));
1797 ptr += strlen(WMGetFromPLString(d));
1798 *ptr = ':';
1799 ptr++;
1801 ptr--; *(ptr--) = 0;
1803 if (*(char**)addr!=NULL) {
1804 wfree(*(char**)addr);
1806 *(char**)addr = data;
1808 return True;
1812 static int
1813 getEnum(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1814 void **ret)
1816 static signed char data;
1818 data = string2index(entry->plkey, value, entry->default_value,
1819 (WOptionEnumeration*)entry->extra_data);
1820 if (data < 0)
1821 return False;
1823 if (ret)
1824 *ret = &data;
1825 if (addr)
1826 *(signed char*)addr = data;
1828 return True;
1834 * (solid <color>)
1835 * (hgradient <color> <color>)
1836 * (vgradient <color> <color>)
1837 * (dgradient <color> <color>)
1838 * (mhgradient <color> <color> ...)
1839 * (mvgradient <color> <color> ...)
1840 * (mdgradient <color> <color> ...)
1841 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1842 * (tpixmap <file> <color>)
1843 * (spixmap <file> <color>)
1844 * (cpixmap <file> <color>)
1845 * (thgradient <file> <opaqueness> <color> <color>)
1846 * (tvgradient <file> <opaqueness> <color> <color>)
1847 * (tdgradient <file> <opaqueness> <color> <color>)
1848 * (function <lib> <function> ...)
1851 static WTexture*
1852 parse_texture(WScreen *scr, WMPropList *pl)
1854 WMPropList *elem;
1855 char *val;
1856 int nelem;
1857 WTexture *texture=NULL;
1859 nelem = WMGetPropListItemCount(pl);
1860 if (nelem < 1)
1861 return NULL;
1864 elem = WMGetFromPLArray(pl, 0);
1865 if (!elem || !WMIsPLString(elem))
1866 return NULL;
1867 val = WMGetFromPLString(elem);
1870 if (strcasecmp(val, "solid")==0) {
1871 XColor color;
1873 if (nelem != 2)
1874 return NULL;
1876 /* get color */
1878 elem = WMGetFromPLArray(pl, 1);
1879 if (!elem || !WMIsPLString(elem))
1880 return NULL;
1881 val = WMGetFromPLString(elem);
1883 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1884 wwarning(_("\"%s\" is not a valid color name"), val);
1885 return NULL;
1888 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1889 } else if (strcasecmp(val, "dgradient")==0
1890 || strcasecmp(val, "vgradient")==0
1891 || strcasecmp(val, "hgradient")==0) {
1892 RColor color1, color2;
1893 XColor xcolor;
1894 int type;
1896 if (nelem != 3) {
1897 wwarning(_("bad number of arguments in gradient specification"));
1898 return NULL;
1901 if (val[0]=='d' || val[0]=='D')
1902 type = WTEX_DGRADIENT;
1903 else if (val[0]=='h' || val[0]=='H')
1904 type = WTEX_HGRADIENT;
1905 else
1906 type = WTEX_VGRADIENT;
1909 /* get from color */
1910 elem = WMGetFromPLArray(pl, 1);
1911 if (!elem || !WMIsPLString(elem))
1912 return NULL;
1913 val = WMGetFromPLString(elem);
1915 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1916 wwarning(_("\"%s\" is not a valid color name"), val);
1917 return NULL;
1919 color1.alpha = 255;
1920 color1.red = xcolor.red >> 8;
1921 color1.green = xcolor.green >> 8;
1922 color1.blue = xcolor.blue >> 8;
1924 /* get to color */
1925 elem = WMGetFromPLArray(pl, 2);
1926 if (!elem || !WMIsPLString(elem)) {
1927 return NULL;
1929 val = WMGetFromPLString(elem);
1931 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1932 wwarning(_("\"%s\" is not a valid color name"), val);
1933 return NULL;
1935 color2.alpha = 255;
1936 color2.red = xcolor.red >> 8;
1937 color2.green = xcolor.green >> 8;
1938 color2.blue = xcolor.blue >> 8;
1940 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1942 } else if (strcasecmp(val, "igradient")==0) {
1943 RColor colors1[2], colors2[2];
1944 int th1, th2;
1945 XColor xcolor;
1946 int i;
1948 if (nelem != 7) {
1949 wwarning(_("bad number of arguments in gradient specification"));
1950 return NULL;
1953 /* get from color */
1954 for (i = 0; i < 2; i++) {
1955 elem = WMGetFromPLArray(pl, 1+i);
1956 if (!elem || !WMIsPLString(elem))
1957 return NULL;
1958 val = WMGetFromPLString(elem);
1960 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1961 wwarning(_("\"%s\" is not a valid color name"), val);
1962 return NULL;
1964 colors1[i].alpha = 255;
1965 colors1[i].red = xcolor.red >> 8;
1966 colors1[i].green = xcolor.green >> 8;
1967 colors1[i].blue = xcolor.blue >> 8;
1969 elem = WMGetFromPLArray(pl, 3);
1970 if (!elem || !WMIsPLString(elem))
1971 return NULL;
1972 val = WMGetFromPLString(elem);
1973 th1 = atoi(val);
1976 /* get from color */
1977 for (i = 0; i < 2; i++) {
1978 elem = WMGetFromPLArray(pl, 4+i);
1979 if (!elem || !WMIsPLString(elem))
1980 return NULL;
1981 val = WMGetFromPLString(elem);
1983 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1984 wwarning(_("\"%s\" is not a valid color name"), val);
1985 return NULL;
1987 colors2[i].alpha = 255;
1988 colors2[i].red = xcolor.red >> 8;
1989 colors2[i].green = xcolor.green >> 8;
1990 colors2[i].blue = xcolor.blue >> 8;
1992 elem = WMGetFromPLArray(pl, 6);
1993 if (!elem || !WMIsPLString(elem))
1994 return NULL;
1995 val = WMGetFromPLString(elem);
1996 th2 = atoi(val);
1998 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1999 th2, colors2);
2001 } else if (strcasecmp(val, "mhgradient")==0
2002 || strcasecmp(val, "mvgradient")==0
2003 || strcasecmp(val, "mdgradient")==0) {
2004 XColor color;
2005 RColor **colors;
2006 int i, count;
2007 int type;
2009 if (nelem < 3) {
2010 wwarning(_("too few arguments in multicolor gradient specification"));
2011 return NULL;
2014 if (val[1]=='h' || val[1]=='H')
2015 type = WTEX_MHGRADIENT;
2016 else if (val[1]=='v' || val[1]=='V')
2017 type = WTEX_MVGRADIENT;
2018 else
2019 type = WTEX_MDGRADIENT;
2021 count = nelem-1;
2023 colors = wmalloc(sizeof(RColor*)*(count+1));
2025 for (i=0; i<count; i++) {
2026 elem = WMGetFromPLArray(pl, i+1);
2027 if (!elem || !WMIsPLString(elem)) {
2028 for (--i; i>=0; --i) {
2029 wfree(colors[i]);
2031 wfree(colors);
2032 return NULL;
2034 val = WMGetFromPLString(elem);
2036 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
2037 wwarning(_("\"%s\" is not a valid color name"), val);
2038 for (--i; i>=0; --i) {
2039 wfree(colors[i]);
2041 wfree(colors);
2042 return NULL;
2043 } else {
2044 colors[i] = wmalloc(sizeof(RColor));
2045 colors[i]->red = color.red >> 8;
2046 colors[i]->green = color.green >> 8;
2047 colors[i]->blue = color.blue >> 8;
2050 colors[i] = NULL;
2052 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
2053 } else if (strcasecmp(val, "spixmap")==0 ||
2054 strcasecmp(val, "cpixmap")==0 ||
2055 strcasecmp(val, "tpixmap")==0) {
2056 XColor color;
2057 int type;
2059 if (nelem != 3)
2060 return NULL;
2062 if (val[0] == 's' || val[0] == 'S')
2063 type = WTP_SCALE;
2064 else if (val[0] == 'c' || val[0] == 'C')
2065 type = WTP_CENTER;
2066 else
2067 type = WTP_TILE;
2069 /* get color */
2070 elem = WMGetFromPLArray(pl, 2);
2071 if (!elem || !WMIsPLString(elem)) {
2072 return NULL;
2074 val = WMGetFromPLString(elem);
2076 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
2077 wwarning(_("\"%s\" is not a valid color name"), val);
2078 return NULL;
2081 /* file name */
2082 elem = WMGetFromPLArray(pl, 1);
2083 if (!elem || !WMIsPLString(elem))
2084 return NULL;
2085 val = WMGetFromPLString(elem);
2087 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
2088 } else if (strcasecmp(val, "thgradient")==0
2089 || strcasecmp(val, "tvgradient")==0
2090 || strcasecmp(val, "tdgradient")==0) {
2091 RColor color1, color2;
2092 XColor xcolor;
2093 int opacity;
2094 int style;
2096 if (val[1]=='h' || val[1]=='H')
2097 style = WTEX_THGRADIENT;
2098 else if (val[1]=='v' || val[1]=='V')
2099 style = WTEX_TVGRADIENT;
2100 else
2101 style = WTEX_TDGRADIENT;
2103 if (nelem != 5) {
2104 wwarning(_("bad number of arguments in textured gradient specification"));
2105 return NULL;
2108 /* get from color */
2109 elem = WMGetFromPLArray(pl, 3);
2110 if (!elem || !WMIsPLString(elem))
2111 return NULL;
2112 val = WMGetFromPLString(elem);
2114 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2115 wwarning(_("\"%s\" is not a valid color name"), val);
2116 return NULL;
2118 color1.alpha = 255;
2119 color1.red = xcolor.red >> 8;
2120 color1.green = xcolor.green >> 8;
2121 color1.blue = xcolor.blue >> 8;
2123 /* get to color */
2124 elem = WMGetFromPLArray(pl, 4);
2125 if (!elem || !WMIsPLString(elem)) {
2126 return NULL;
2128 val = WMGetFromPLString(elem);
2130 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2131 wwarning(_("\"%s\" is not a valid color name"), val);
2132 return NULL;
2134 color2.alpha = 255;
2135 color2.red = xcolor.red >> 8;
2136 color2.green = xcolor.green >> 8;
2137 color2.blue = xcolor.blue >> 8;
2139 /* get opacity */
2140 elem = WMGetFromPLArray(pl, 2);
2141 if (!elem || !WMIsPLString(elem))
2142 opacity = 128;
2143 else
2144 val = WMGetFromPLString(elem);
2146 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2147 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2148 opacity = 128;
2151 /* get file name */
2152 elem = WMGetFromPLArray(pl, 1);
2153 if (!elem || !WMIsPLString(elem))
2154 return NULL;
2155 val = WMGetFromPLString(elem);
2157 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2158 val, opacity);
2160 #ifdef TEXTURE_PLUGIN
2161 else if (strcasecmp(val, "function")==0) {
2162 WTexFunction *function;
2163 void (*initFunc) (Display *, Colormap);
2164 char *lib, *func, **argv;
2165 int i, argc;
2167 if (nelem < 3)
2168 return NULL;
2170 /* get the library name */
2171 elem = WMGetFromPLArray(pl, 1);
2172 if (!elem || !WMIsPLString(elem)) {
2173 return NULL;
2175 lib = WMGetFromPLString(elem);
2177 /* get the function name */
2178 elem = WMGetFromPLArray(pl, 2);
2179 if (!elem || !WMIsPLString(elem)) {
2180 return NULL;
2182 func = WMGetFromPLString(elem);
2184 argc = nelem - 2;
2185 argv = (char **)wmalloc(argc * sizeof(char *));
2187 /* get the parameters */
2188 argv[0] = wstrdup(func);
2189 for (i = 0; i < argc - 1; i++) {
2190 elem = WMGetFromPLArray(pl, 3 + i);
2191 if (!elem || !WMIsPLString(elem)) {
2192 wfree(argv);
2194 return NULL;
2196 argv[i+1] = wstrdup(WMGetFromPLString(elem));
2199 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2201 #ifdef HAVE_DLFCN_H
2202 if (function) {
2203 initFunc = dlsym(function->handle, "initWindowMaker");
2204 if (initFunc) {
2205 initFunc(dpy, scr->w_colormap);
2206 } else {
2207 wwarning(_("could not initialize library %s"), lib);
2209 } else {
2210 wwarning(_("could not find function %s::%s"), lib, func);
2212 #endif /* HAVE_DLFCN_H */
2213 texture = (WTexture*)function;
2215 #endif /* TEXTURE_PLUGIN */
2216 else {
2217 wwarning(_("invalid texture type %s"), val);
2218 return NULL;
2220 return texture;
2225 static int
2226 getTexture(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2227 void **ret)
2229 static WTexture *texture;
2230 int changed=0;
2232 again:
2233 if (!WMIsPLArray(value)) {
2234 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2235 entry->key, "Texture");
2236 if (changed==0) {
2237 value = entry->plvalue;
2238 changed = 1;
2239 wwarning(_("using default \"%s\" instead"), entry->default_value);
2240 goto again;
2242 return False;
2245 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2246 WMPropList *pl;
2248 pl = WMGetFromPLArray(value, 0);
2249 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2250 || strcasecmp(WMGetFromPLString(pl), "solid")!=0) {
2251 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2252 entry->key, "Solid Texture");
2254 value = entry->plvalue;
2255 changed = 1;
2256 wwarning(_("using default \"%s\" instead"), entry->default_value);
2257 goto again;
2261 texture = parse_texture(scr, value);
2263 if (!texture) {
2264 wwarning(_("Error in texture specification for key \"%s\""),
2265 entry->key);
2266 if (changed==0) {
2267 value = entry->plvalue;
2268 changed = 1;
2269 wwarning(_("using default \"%s\" instead"), entry->default_value);
2270 goto again;
2272 return False;
2275 if (ret)
2276 *ret = &texture;
2278 if (addr)
2279 *(WTexture**)addr = texture;
2281 return True;
2285 static int
2286 getWSBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2287 void *addr, void **ret)
2289 WMPropList *elem;
2290 int changed = 0;
2291 char *val;
2292 int nelem;
2294 again:
2295 if (!WMIsPLArray(value)) {
2296 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2297 "WorkspaceBack", "Texture or None");
2298 if (changed==0) {
2299 value = entry->plvalue;
2300 changed = 1;
2301 wwarning(_("using default \"%s\" instead"), entry->default_value);
2302 goto again;
2304 return False;
2307 /* only do basic error checking and verify for None texture */
2309 nelem = WMGetPropListItemCount(value);
2310 if (nelem > 0) {
2311 elem = WMGetFromPLArray(value, 0);
2312 if (!elem || !WMIsPLString(elem)) {
2313 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2314 if (changed==0) {
2315 value = entry->plvalue;
2316 changed = 1;
2317 wwarning(_("using default \"%s\" instead"), entry->default_value);
2318 goto again;
2320 return False;
2322 val = WMGetFromPLString(elem);
2324 if (strcasecmp(val, "None")==0)
2325 return True;
2327 *ret = WMRetainPropList(value);
2329 return True;
2333 static int
2334 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2335 void *addr, void **ret)
2337 WMPropList *elem;
2338 int nelem;
2339 int changed = 0;
2341 again:
2342 if (!WMIsPLArray(value)) {
2343 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2344 "WorkspaceSpecificBack", "an array of textures");
2345 if (changed==0) {
2346 value = entry->plvalue;
2347 changed = 1;
2348 wwarning(_("using default \"%s\" instead"), entry->default_value);
2349 goto again;
2351 return False;
2354 /* only do basic error checking and verify for None texture */
2356 nelem = WMGetPropListItemCount(value);
2357 if (nelem > 0) {
2358 while (nelem--) {
2359 elem = WMGetFromPLArray(value, nelem);
2360 if (!elem || !WMIsPLArray(elem)) {
2361 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2362 nelem);
2367 *ret = WMRetainPropList(value);
2369 #ifdef notworking
2371 * Kluge to force wmsetbg helper to set the default background.
2372 * If the WorkspaceSpecificBack is changed once wmaker has started,
2373 * the WorkspaceBack won't be sent to the helper, unless the user
2374 * changes it's value too. So, we must force this by removing the
2375 * value from the defaults DB.
2377 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2378 WMPropList *key = WMCreatePLString("WorkspaceBack");
2380 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2382 WMReleasePropList(key);
2384 #endif
2385 return True;
2389 static int
2390 getFont(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2391 void **ret)
2393 static WMFont *font;
2394 char *val;
2396 GET_STRING_OR_DEFAULT("Font", val);
2398 font = WMCreateFont(scr->wmscreen, val);
2399 if (!font)
2400 font = WMCreateFont(scr->wmscreen, "fixed");
2402 if (!font) {
2403 wfatal(_("could not load any usable font!!!"));
2404 exit(1);
2407 if (ret)
2408 *ret = font;
2410 /* can't assign font value outside update function */
2411 wassertrv(addr == NULL, True);
2413 return True;
2417 static int
2418 getColor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2419 void **ret)
2421 static XColor color;
2422 char *val;
2423 int second_pass=0;
2425 GET_STRING_OR_DEFAULT("Color", val);
2428 again:
2429 if (!wGetColor(scr, val, &color)) {
2430 wwarning(_("could not get color for key \"%s\""),
2431 entry->key);
2432 if (second_pass==0) {
2433 val = WMGetFromPLString(entry->plvalue);
2434 second_pass = 1;
2435 wwarning(_("using default \"%s\" instead"), val);
2436 goto again;
2438 return False;
2441 if (ret)
2442 *ret = &color;
2444 assert(addr==NULL);
2446 if (addr)
2447 *(unsigned long*)addr = pixel;
2450 return True;
2455 static int
2456 getKeybind(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2457 void **ret)
2459 static WShortKey shortcut;
2460 KeySym ksym;
2461 char *val;
2462 char *k;
2463 char buf[128], *b;
2466 GET_STRING_OR_DEFAULT("Key spec", val);
2468 if (!val || strcasecmp(val, "NONE")==0) {
2469 shortcut.keycode = 0;
2470 shortcut.modifier = 0;
2471 if (ret)
2472 *ret = &shortcut;
2473 return True;
2476 strcpy(buf, val);
2478 b = (char*)buf;
2480 /* get modifiers */
2481 shortcut.modifier = 0;
2482 while ((k = strchr(b, '+'))!=NULL) {
2483 int mod;
2485 *k = 0;
2486 mod = wXModifierFromKey(b);
2487 if (mod<0) {
2488 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2489 return False;
2491 shortcut.modifier |= mod;
2493 b = k+1;
2496 /* get key */
2497 ksym = XStringToKeysym(b);
2499 if (ksym==NoSymbol) {
2500 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2501 val);
2502 return False;
2505 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2506 if (shortcut.keycode==0) {
2507 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2508 return False;
2511 if (ret)
2512 *ret = &shortcut;
2514 return True;
2518 static int
2519 getModMask(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2520 void **ret)
2522 static unsigned int mask;
2523 char *str;
2525 GET_STRING_OR_DEFAULT("Modifier Key", str);
2527 if (!str)
2528 return False;
2530 mask = wXModifierFromKey(str);
2531 if (mask < 0) {
2532 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2533 mask = 0;
2534 return False;
2537 if (addr)
2538 *(unsigned int*)addr = mask;
2540 if (ret)
2541 *ret = &mask;
2543 return True;
2547 #ifdef NEWSTUFF
2548 static int
2549 getRImages(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2550 void *addr, void **ret)
2552 unsigned int mask;
2553 char *str;
2554 RImage *image;
2555 int i, n;
2556 int w, h;
2558 GET_STRING_OR_DEFAULT("Image File Path", str);
2559 if (!str)
2560 return False;
2562 image = RLoadImage(scr->rcontext, str, 0);
2563 if (!image) {
2564 wwarning(_("could not load image in option %s: %s"), entry->key,
2565 RMessageForError(RErrorCode));
2566 return False;
2569 if (*(RImage**)addr) {
2570 RReleaseImage(*(RImage**)addr);
2572 if (addr)
2573 *(RImage**)addr = image;
2575 assert(ret == NULL);
2577 if (ret)
2578 *(RImage**)ret = image;
2581 return True;
2583 #endif
2585 # include <X11/cursorfont.h>
2586 typedef struct
2588 char *name;
2589 int id;
2590 } WCursorLookup;
2592 #define CURSOR_ID_NONE (XC_num_glyphs)
2594 static WCursorLookup cursor_table[] =
2596 { "X_cursor", XC_X_cursor },
2597 { "arrow", XC_arrow },
2598 { "based_arrow_down", XC_based_arrow_down },
2599 { "based_arrow_up", XC_based_arrow_up },
2600 { "boat", XC_boat },
2601 { "bogosity", XC_bogosity },
2602 { "bottom_left_corner", XC_bottom_left_corner },
2603 { "bottom_right_corner", XC_bottom_right_corner },
2604 { "bottom_side", XC_bottom_side },
2605 { "bottom_tee", XC_bottom_tee },
2606 { "box_spiral", XC_box_spiral },
2607 { "center_ptr", XC_center_ptr },
2608 { "circle", XC_circle },
2609 { "clock", XC_clock },
2610 { "coffee_mug", XC_coffee_mug },
2611 { "cross", XC_cross },
2612 { "cross_reverse", XC_cross_reverse },
2613 { "crosshair", XC_crosshair },
2614 { "diamond_cross", XC_diamond_cross },
2615 { "dot", XC_dot },
2616 { "dotbox", XC_dotbox },
2617 { "double_arrow", XC_double_arrow },
2618 { "draft_large", XC_draft_large },
2619 { "draft_small", XC_draft_small },
2620 { "draped_box", XC_draped_box },
2621 { "exchange", XC_exchange },
2622 { "fleur", XC_fleur },
2623 { "gobbler", XC_gobbler },
2624 { "gumby", XC_gumby },
2625 { "hand1", XC_hand1 },
2626 { "hand2", XC_hand2 },
2627 { "heart", XC_heart },
2628 { "icon", XC_icon },
2629 { "iron_cross", XC_iron_cross },
2630 { "left_ptr", XC_left_ptr },
2631 { "left_side", XC_left_side },
2632 { "left_tee", XC_left_tee },
2633 { "leftbutton", XC_leftbutton },
2634 { "ll_angle", XC_ll_angle },
2635 { "lr_angle", XC_lr_angle },
2636 { "man", XC_man },
2637 { "middlebutton", XC_middlebutton },
2638 { "mouse", XC_mouse },
2639 { "pencil", XC_pencil },
2640 { "pirate", XC_pirate },
2641 { "plus", XC_plus },
2642 { "question_arrow", XC_question_arrow },
2643 { "right_ptr", XC_right_ptr },
2644 { "right_side", XC_right_side },
2645 { "right_tee", XC_right_tee },
2646 { "rightbutton", XC_rightbutton },
2647 { "rtl_logo", XC_rtl_logo },
2648 { "sailboat", XC_sailboat },
2649 { "sb_down_arrow", XC_sb_down_arrow },
2650 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2651 { "sb_left_arrow", XC_sb_left_arrow },
2652 { "sb_right_arrow", XC_sb_right_arrow },
2653 { "sb_up_arrow", XC_sb_up_arrow },
2654 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2655 { "shuttle", XC_shuttle },
2656 { "sizing", XC_sizing },
2657 { "spider", XC_spider },
2658 { "spraycan", XC_spraycan },
2659 { "star", XC_star },
2660 { "target", XC_target },
2661 { "tcross", XC_tcross },
2662 { "top_left_arrow", XC_top_left_arrow },
2663 { "top_left_corner", XC_top_left_corner },
2664 { "top_right_corner", XC_top_right_corner },
2665 { "top_side", XC_top_side },
2666 { "top_tee", XC_top_tee },
2667 { "trek", XC_trek },
2668 { "ul_angle", XC_ul_angle },
2669 { "umbrella", XC_umbrella },
2670 { "ur_angle", XC_ur_angle },
2671 { "watch", XC_watch },
2672 { "xterm", XC_xterm },
2673 { NULL, CURSOR_ID_NONE }
2676 static void
2677 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2679 switch(status) {
2680 case BitmapOpenFailed:
2681 wwarning(_("failed to open bitmap file \"%s\""), filename);
2682 break;
2683 case BitmapFileInvalid:
2684 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2685 break;
2686 case BitmapNoMemory:
2687 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2688 break;
2689 case BitmapSuccess:
2690 XFreePixmap(dpy, bitmap);
2691 break;
2696 * (none)
2697 * (builtin, <cursor_name>)
2698 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2700 static int
2701 parse_cursor(WScreen *scr, WMPropList *pl, Cursor *cursor)
2703 WMPropList *elem;
2704 char *val;
2705 int nelem;
2706 int status = 0;
2708 nelem = WMGetPropListItemCount(pl);
2709 if (nelem < 1) {
2710 return(status);
2712 elem = WMGetFromPLArray(pl, 0);
2713 if (!elem || !WMIsPLString(elem)) {
2714 return(status);
2716 val = WMGetFromPLString(elem);
2718 if (0 == strcasecmp(val, "none")) {
2719 status = 1;
2720 *cursor = None;
2721 } else if (0 == strcasecmp(val, "builtin")) {
2722 int i;
2723 int cursor_id = CURSOR_ID_NONE;
2725 if (2 != nelem) {
2726 wwarning(_("bad number of arguments in cursor specification"));
2727 return(status);
2729 elem = WMGetFromPLArray(pl, 1);
2730 if (!elem || !WMIsPLString(elem)) {
2731 return(status);
2733 val = WMGetFromPLString(elem);
2735 for (i = 0; NULL != cursor_table[i].name; i++) {
2736 if (0 == strcasecmp(val, cursor_table[i].name)) {
2737 cursor_id = cursor_table[i].id;
2738 break;
2741 if (CURSOR_ID_NONE == cursor_id) {
2742 wwarning(_("unknown builtin cursor name \"%s\""), val);
2743 } else {
2744 *cursor = XCreateFontCursor(dpy, cursor_id);
2745 status = 1;
2747 } else if (0 == strcasecmp(val, "bitmap")) {
2748 char *bitmap_name;
2749 char *mask_name;
2750 int bitmap_status;
2751 int mask_status;
2752 Pixmap bitmap;
2753 Pixmap mask;
2754 unsigned int w, h;
2755 int x, y;
2756 XColor fg, bg;
2758 if (3 != nelem) {
2759 wwarning(_("bad number of arguments in cursor specification"));
2760 return(status);
2762 elem = WMGetFromPLArray(pl, 1);
2763 if (!elem || !WMIsPLString(elem)) {
2764 return(status);
2766 val = WMGetFromPLString(elem);
2767 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2768 if (!bitmap_name) {
2769 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2770 return(status);
2772 elem = WMGetFromPLArray(pl, 2);
2773 if (!elem || !WMIsPLString(elem)) {
2774 wfree(bitmap_name);
2775 return(status);
2777 val = WMGetFromPLString(elem);
2778 mask_name = FindImage(wPreferences.pixmap_path, val);
2779 if (!mask_name) {
2780 wfree(bitmap_name);
2781 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2782 return(status);
2784 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2785 &mask, &x, &y);
2786 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2787 &bitmap, &x, &y);
2788 if ((BitmapSuccess == bitmap_status) &&
2789 (BitmapSuccess == mask_status)) {
2790 fg.pixel = scr->black_pixel;
2791 bg.pixel = scr->white_pixel;
2792 XQueryColor(dpy, scr->w_colormap, &fg);
2793 XQueryColor(dpy, scr->w_colormap, &bg);
2794 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2795 status = 1;
2797 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2798 check_bitmap_status(mask_status, mask_name, mask);
2799 wfree(bitmap_name);
2800 wfree(mask_name);
2802 return(status);
2806 static int
2807 getCursor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2808 void **ret)
2810 static Cursor cursor;
2811 int status;
2812 int changed = 0;
2814 again:
2815 if (!WMIsPLArray(value)) {
2816 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2817 entry->key, "cursor specification");
2818 if (!changed) {
2819 value = entry->plvalue;
2820 changed = 1;
2821 wwarning(_("using default \"%s\" instead"), entry->default_value);
2822 goto again;
2824 return(False);
2826 status = parse_cursor(scr, value, &cursor);
2827 if (!status) {
2828 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2829 if (!changed) {
2830 value = entry->plvalue;
2831 changed = 1;
2832 wwarning(_("using default \"%s\" instead"), entry->default_value);
2833 goto again;
2835 return(False);
2837 if (ret) {
2838 *ret = &cursor;
2840 if (addr) {
2841 *(Cursor *)addr = cursor;
2843 return(True);
2845 #undef CURSOR_ID_NONE
2848 /* ---------------- value setting functions --------------- */
2849 static int
2850 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2852 return REFRESH_WINDOW_TITLE_COLOR;
2855 static int
2856 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2858 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2861 static int
2862 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2864 switch (which) {
2865 case WM_DOCK:
2866 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2867 break;
2868 case WM_CLIP:
2869 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2870 break;
2871 default:
2872 break;
2874 return 0;
2878 static int
2879 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2881 if (scr->workspaces) {
2882 wWorkspaceForceChange(scr, scr->current_workspace);
2883 wArrangeIcons(scr, False);
2885 return 0;
2888 #if not_used
2889 static int
2890 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2892 if (*value <= 0)
2893 *(int*)foo = 1;
2895 return 0;
2897 #endif
2901 static int
2902 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2904 Pixmap pixmap;
2905 RImage *img;
2906 int reset = 0;
2908 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2909 wPreferences.icon_size,
2910 ((*texture)->any.type & WREL_BORDER_MASK)
2911 ? WREL_ICON : WREL_FLAT);
2912 if (!img) {
2913 wwarning(_("could not render texture for icon background"));
2914 if (!entry->addr)
2915 wTextureDestroy(scr, *texture);
2916 return 0;
2918 RConvertImage(scr->rcontext, img, &pixmap);
2920 if (scr->icon_tile) {
2921 reset = 1;
2922 RReleaseImage(scr->icon_tile);
2923 XFreePixmap(dpy, scr->icon_tile_pixmap);
2926 scr->icon_tile = img;
2929 /* put the icon in the noticeboard hint */
2930 PropSetIconTileHint(scr, img);
2933 if (!wPreferences.flags.noclip) {
2934 if (scr->clip_tile) {
2935 RReleaseImage(scr->clip_tile);
2937 scr->clip_tile = wClipMakeTile(scr, img);
2940 scr->icon_tile_pixmap = pixmap;
2942 if (scr->def_icon_pixmap) {
2943 XFreePixmap(dpy, scr->def_icon_pixmap);
2944 scr->def_icon_pixmap = None;
2946 if (scr->def_ticon_pixmap) {
2947 XFreePixmap(dpy, scr->def_ticon_pixmap);
2948 scr->def_ticon_pixmap = None;
2951 if (scr->icon_back_texture) {
2952 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2954 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2956 if (scr->clip_balloon)
2957 XSetWindowBackground(dpy, scr->clip_balloon,
2958 (*texture)->any.color.pixel);
2961 * Free the texture as nobody else will use it, nor refer to it.
2963 if (!entry->addr)
2964 wTextureDestroy(scr, *texture);
2966 return (reset ? REFRESH_ICON_TILE : 0);
2971 static int
2972 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2974 if (scr->title_font) {
2975 WMReleaseFont(scr->title_font);
2977 scr->title_font = font;
2979 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2983 static int
2984 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2986 if (scr->menu_title_font) {
2987 WMReleaseFont(scr->menu_title_font);
2990 scr->menu_title_font = font;
2992 return REFRESH_MENU_TITLE_FONT;
2996 static int
2997 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2999 if (scr->menu_entry_font) {
3000 WMReleaseFont(scr->menu_entry_font);
3002 scr->menu_entry_font = font;
3004 return REFRESH_MENU_FONT;
3009 static int
3010 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3012 if (scr->icon_title_font) {
3013 WMReleaseFont(scr->icon_title_font);
3016 scr->icon_title_font = font;
3018 return REFRESH_ICON_FONT;
3022 static int
3023 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3025 if (scr->clip_title_font) {
3026 WMReleaseFont(scr->clip_title_font);
3029 scr->clip_title_font = font;
3031 return REFRESH_ICON_FONT;
3035 static int
3036 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3038 if (scr->workspace_name_font) {
3039 WMReleaseFont(scr->workspace_name_font);
3042 scr->workspace_name_font = font;
3044 return 0;
3048 static int
3049 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3051 if (scr->select_color)
3052 WMReleaseColor(scr->select_color);
3054 scr->select_color =
3055 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3056 color->blue, True);
3058 wFreeColor(scr, color->pixel);
3060 return REFRESH_MENU_COLOR;
3064 static int
3065 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3067 if (scr->select_text_color)
3068 WMReleaseColor(scr->select_text_color);
3070 scr->select_text_color =
3071 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3072 color->blue, True);
3074 wFreeColor(scr, color->pixel);
3076 return REFRESH_MENU_COLOR;
3080 static int
3081 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3083 if (scr->clip_title_color[index])
3084 WMReleaseColor(scr->clip_title_color[index]);
3085 scr->clip_title_color[index] = WMCreateRGBColor(scr->wmscreen, color->red,
3086 color->green, color->blue,
3087 True);
3088 #ifdef GRADIENT_CLIP_ARROW
3089 if (index == CLIP_NORMAL) {
3090 RImage *image;
3091 RColor color1, color2;
3092 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3093 int as = pt - 15; /* 15 = 5+5+5 */
3095 FREE_PIXMAP(scr->clip_arrow_gradient);
3097 color1.red = (color->red >> 8)*6/10;
3098 color1.green = (color->green >> 8)*6/10;
3099 color1.blue = (color->blue >> 8)*6/10;
3101 color2.red = WMIN((color->red >> 8)*20/10, 255);
3102 color2.green = WMIN((color->green >> 8)*20/10, 255);
3103 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3105 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3106 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3107 RReleaseImage(image);
3109 #endif /* GRADIENT_CLIP_ARROW */
3111 wFreeColor(scr, color->pixel);
3113 return REFRESH_ICON_TITLE_COLOR;
3117 static int
3118 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3120 if (scr->window_title_color[index])
3121 WMReleaseColor(scr->window_title_color[index]);
3123 scr->window_title_color[index] =
3124 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue,
3125 True);
3127 wFreeColor(scr, color->pixel);
3129 return REFRESH_WINDOW_TITLE_COLOR;
3133 static int
3134 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3136 if (scr->menu_title_color[0])
3137 WMReleaseColor(scr->menu_title_color[0]);
3139 scr->menu_title_color[0] =
3140 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3141 color->blue, True);
3143 wFreeColor(scr, color->pixel);
3145 return REFRESH_MENU_TITLE_COLOR;
3149 static int
3150 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3152 if (scr->mtext_color)
3153 WMReleaseColor(scr->mtext_color);
3155 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3156 color->green, color->blue, True);
3158 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3159 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3160 } else {
3161 WMSetColorAlpha(scr->dtext_color, 0xffff);
3164 wFreeColor(scr, color->pixel);
3166 return REFRESH_MENU_COLOR;
3170 static int
3171 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3173 if (scr->dtext_color)
3174 WMReleaseColor(scr->dtext_color);
3176 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3177 color->green, color->blue, True);
3179 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3180 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3181 } else {
3182 WMSetColorAlpha(scr->dtext_color, 0xffff);
3185 wFreeColor(scr, color->pixel);
3187 return REFRESH_MENU_COLOR;
3191 static int
3192 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3194 if (scr->icon_title_color)
3195 WMReleaseColor(scr->icon_title_color);
3196 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red,
3197 color->green, color->blue,
3198 True);
3200 wFreeColor(scr, color->pixel);
3202 return REFRESH_ICON_TITLE_COLOR;
3206 static int
3207 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3209 if (scr->icon_title_texture) {
3210 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3212 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3214 return REFRESH_ICON_TITLE_BACK;
3218 static void
3219 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3221 close(scr->helper_fd);
3222 scr->helper_fd = 0;
3223 scr->helper_pid = 0;
3224 scr->flags.backimage_helper_launched = 0;
3228 static int
3229 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3230 void *bar)
3232 WMPropList *val;
3233 char *str;
3234 int i;
3236 if (scr->flags.backimage_helper_launched) {
3237 if (WMGetPropListItemCount(value)==0) {
3238 SendHelperMessage(scr, 'C', 0, NULL);
3239 SendHelperMessage(scr, 'K', 0, NULL);
3241 WMReleasePropList(value);
3242 return 0;
3244 } else {
3245 pid_t pid;
3246 int filedes[2];
3248 if (WMGetPropListItemCount(value) == 0)
3249 return 0;
3251 if (pipe(filedes) < 0) {
3252 wsyserror("pipe() failed:can't set workspace specific background image");
3254 WMReleasePropList(value);
3255 return 0;
3258 pid = fork();
3259 if (pid < 0) {
3260 wsyserror("fork() failed:can't set workspace specific background image");
3261 if (close(filedes[0]) < 0)
3262 wsyserror("could not close pipe");
3263 if (close(filedes[1]) < 0)
3264 wsyserror("could not close pipe");
3266 } else if (pid == 0) {
3267 char *dither;
3269 SetupEnvironment(scr);
3271 if (close(0) < 0)
3272 wsyserror("could not close pipe");
3273 if (dup(filedes[0]) < 0) {
3274 wsyserror("dup() failed:can't set workspace specific background image");
3276 dither = wPreferences.no_dithering ? "-m" : "-d";
3277 if (wPreferences.smooth_workspace_back)
3278 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3279 else
3280 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3281 wsyserror("could not execute wmsetbg");
3282 exit(1);
3283 } else {
3285 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3286 wsyserror("error setting close-on-exec flag");
3288 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3289 wsyserror("error setting close-on-exec flag");
3292 scr->helper_fd = filedes[1];
3293 scr->helper_pid = pid;
3294 scr->flags.backimage_helper_launched = 1;
3296 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3298 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3303 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3304 val = WMGetFromPLArray(value, i);
3305 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val)>0) {
3306 str = WMGetPropListDescription(val, False);
3308 SendHelperMessage(scr, 'S', i+1, str);
3310 wfree(str);
3311 } else {
3312 SendHelperMessage(scr, 'U', i+1, NULL);
3315 sleep(1);
3317 WMReleasePropList(value);
3318 return 0;
3322 static int
3323 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3324 void *bar)
3326 if (scr->flags.backimage_helper_launched) {
3327 char *str;
3329 if (WMGetPropListItemCount(value)==0) {
3330 SendHelperMessage(scr, 'U', 0, NULL);
3331 } else {
3332 /* set the default workspace background to this one */
3333 str = WMGetPropListDescription(value, False);
3334 if (str) {
3335 SendHelperMessage(scr, 'S', 0, str);
3336 wfree(str);
3337 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3338 } else {
3339 SendHelperMessage(scr, 'U', 0, NULL);
3342 } else if (WMGetPropListItemCount(value) > 0) {
3343 char *command;
3344 char *text;
3345 char *dither;
3346 int len;
3348 SetupEnvironment(scr);
3349 text = WMGetPropListDescription(value, False);
3350 len = strlen(text)+40;
3351 command = wmalloc(len);
3352 dither = wPreferences.no_dithering ? "-m" : "-d";
3353 if (wPreferences.smooth_workspace_back)
3354 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3355 else
3356 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3357 wfree(text);
3358 system(command);
3359 wfree(command);
3361 WMReleasePropList(value);
3363 return 0;
3367 #ifdef VIRTUAL_DESKTOP
3368 static int
3369 setVirtualDeskEnable(WScreen *scr, WDefaultEntry *entry, void *foo, void *bar)
3371 wWorkspaceUpdateEdge(scr);
3372 return 0;
3374 #endif
3377 static int
3378 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3380 if (scr->widget_texture) {
3381 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3383 scr->widget_texture = *(WTexSolid**)texture;
3385 return 0;
3389 static int
3390 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3392 if (scr->window_title_texture[WS_FOCUSED]) {
3393 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3395 scr->window_title_texture[WS_FOCUSED] = *texture;
3397 return REFRESH_WINDOW_TEXTURES;
3401 static int
3402 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3404 if (scr->window_title_texture[WS_PFOCUSED]) {
3405 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3407 scr->window_title_texture[WS_PFOCUSED] = *texture;
3409 return REFRESH_WINDOW_TEXTURES;
3413 static int
3414 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3416 if (scr->window_title_texture[WS_UNFOCUSED]) {
3417 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3419 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3421 return REFRESH_WINDOW_TEXTURES;
3425 static int
3426 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3428 if (scr->resizebar_texture[0]) {
3429 wTextureDestroy(scr, scr->resizebar_texture[0]);
3431 scr->resizebar_texture[0] = *texture;
3433 return REFRESH_WINDOW_TEXTURES;
3437 static int
3438 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3440 if (scr->menu_title_texture[0]) {
3441 wTextureDestroy(scr, scr->menu_title_texture[0]);
3443 scr->menu_title_texture[0] = *texture;
3445 return REFRESH_MENU_TITLE_TEXTURE;
3449 static int
3450 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3452 if (scr->menu_item_texture) {
3453 wTextureDestroy(scr, scr->menu_item_texture);
3454 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3456 scr->menu_item_texture = *texture;
3458 scr->menu_item_auxtexture
3459 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3461 return REFRESH_MENU_TEXTURE;
3465 static int
3466 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3468 WWindow *wwin;
3469 wKeyBindings[index] = *shortcut;
3471 wwin = scr->focused_window;
3473 while (wwin!=NULL) {
3474 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3476 if (!WFLAGP(wwin, no_bind_keys)) {
3477 wWindowSetKeyGrabs(wwin);
3479 wwin = wwin->prev;
3482 return 0;
3486 static int
3487 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3489 wScreenUpdateUsableArea(scr);
3490 wArrangeIcons(scr, True);
3492 return 0;
3496 static int
3497 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3499 wScreenUpdateUsableArea(scr);
3501 return 0;
3505 static int
3506 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3508 return REFRESH_MENU_TEXTURE;
3512 static RImage *chopOffImage(RImage *image, int x, int y, int w, int h)
3514 RImage *img= RCreateImage(w, h, image->format == RRGBAFormat);
3516 RCopyArea(img, image, x, y, w, h, 0, 0);
3518 return img;
3521 static int
3522 setSwPOptions(WScreen *scr, WDefaultEntry *entry, WMPropList *array, void *foo)
3524 char *path;
3525 RImage *bgimage;
3526 int cwidth, cheight;
3527 WPreferences *prefs= (WPreferences*)foo;
3529 if (!WMIsPLArray(array) || WMGetPropListItemCount(array)==0) {
3530 if (prefs->swtileImage) RReleaseImage(prefs->swtileImage);
3531 prefs->swtileImage= NULL;
3533 WMReleasePropList(array);
3534 return 0;
3537 switch (WMGetPropListItemCount(array))
3539 case 4:
3540 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3541 wwarning(_("Invalid arguments for option \"%s\""),
3542 entry->key);
3543 break;
3544 } else
3545 path= FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3547 if (!path) {
3548 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3549 WMGetFromPLString(WMGetFromPLArray(array, 1)),
3550 entry->key);
3551 } else {
3552 bgimage= RLoadImage(scr->rcontext, path, 0);
3553 if (!bgimage) {
3554 wwarning(_("Could not load image \"%s\" for option \"%s\""),
3555 path, entry->key);
3556 wfree(path);
3557 } else {
3558 wfree(path);
3560 cwidth= atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3561 cheight= atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3563 if (cwidth <= 0 || cheight <= 0 ||
3564 cwidth >= bgimage->width - 2 ||
3565 cheight >= bgimage->height - 2)
3566 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3567 else {
3568 int i;
3569 int swidth, theight;
3570 for (i= 0; i < 9; i++) {
3571 if (prefs->swbackImage[i])
3572 RReleaseImage(prefs->swbackImage[i]);
3573 prefs->swbackImage[i]= NULL;
3575 swidth= (bgimage->width - cwidth) / 2;
3576 theight= (bgimage->height - cheight) / 2;
3578 prefs->swbackImage[0]= chopOffImage(bgimage, 0, 0,
3579 swidth, theight);
3580 prefs->swbackImage[1]= chopOffImage(bgimage, swidth, 0,
3581 cwidth, theight);
3582 prefs->swbackImage[2]= chopOffImage(bgimage, swidth+cwidth, 0,
3583 swidth, theight);
3585 prefs->swbackImage[3]= chopOffImage(bgimage, 0, theight,
3586 swidth, cheight);
3587 prefs->swbackImage[4]= chopOffImage(bgimage, swidth, theight,
3588 cwidth, cheight);
3589 prefs->swbackImage[5]= chopOffImage(bgimage, swidth+cwidth, theight,
3590 swidth, cheight);
3592 prefs->swbackImage[6]= chopOffImage(bgimage, 0, theight+cheight,
3593 swidth, theight);
3594 prefs->swbackImage[7]= chopOffImage(bgimage, swidth, theight+cheight,
3595 cwidth, theight);
3596 prefs->swbackImage[8]= chopOffImage(bgimage, swidth+cwidth, theight+cheight,
3597 swidth, theight);
3599 // check if anything failed
3600 for (i= 0; i < 9; i++) {
3601 if (!prefs->swbackImage[i]) {
3602 for (; i>=0; --i) {
3603 RReleaseImage(prefs->swbackImage[i]);
3604 prefs->swbackImage[i]= NULL;
3606 break;
3610 RReleaseImage(bgimage);
3614 case 1:
3615 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3616 wwarning(_("Invalid arguments for option \"%s\""),
3617 entry->key);
3618 break;
3619 } else
3620 path= FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3622 if (!path) {
3623 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3624 WMGetFromPLString(WMGetFromPLArray(array, 0)),
3625 entry->key);
3626 } else {
3627 if (prefs->swtileImage) RReleaseImage(prefs->swtileImage);
3629 prefs->swtileImage= RLoadImage(scr->rcontext, path, 0);
3630 if (!prefs->swtileImage) {
3631 wwarning(_("Could not load image \"%s\" for option \"%s\""),
3632 path, entry->key);
3634 wfree(path);
3636 break;
3638 default:
3639 wwarning(_("Invalid number of arguments for option \"%s\""),
3640 entry->key);
3641 break;
3644 WMReleasePropList(array);
3646 return 0;
3651 static int
3652 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3654 return REFRESH_BUTTON_IMAGES;
3659 * Very ugly kluge.
3660 * Need access to the double click variables, so that all widgets in
3661 * wmaker panels will have the same dbl-click values.
3662 * TODO: figure a better way of dealing with it.
3664 #include <WINGs/WINGsP.h>
3666 static int
3667 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3669 extern _WINGsConfiguration WINGsConfiguration;
3671 if (*value <= 0)
3672 *(int*)foo = 1;
3674 WINGsConfiguration.doubleClickDelay = *value;
3676 return 0;
3680 static int
3681 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3683 if (wCursor[index] != None) {
3684 XFreeCursor(dpy, wCursor[index]);
3687 wCursor[index] = *cursor;
3689 if (index==WCUR_ROOT && *cursor!=None) {
3690 XDefineCursor(dpy, scr->root_win, *cursor);
3693 return 0;