- removed unnecessary include of WINGsP.h in some places
[wmaker-crm.git] / src / defaults.c
bloba6961f124122678fcf56ca4b1604aa702d401518
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2002 Alfredo K. Kojima
6 * Copyright (c) 1998-2002 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
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 static int setMenuTitleColor();
159 static int setMenuTextColor();
160 static int setMenuDisabledColor();
161 static int setMenuTitleBack();
162 static int setMenuTextBack();
163 static int setHightlight();
164 static int setHightlightText();
165 static int setKeyGrab();
166 static int setDoubleClick();
167 static int setIconPosition();
169 static int setClipTitleFont();
170 static int setClipTitleColor();
172 static int setMenuStyle();
173 #if 0
174 static int setMultiByte();
175 #endif
176 static int updateUsableArea();
178 extern Cursor wCursor[WCUR_LAST];
179 static int getCursor();
180 static int setCursor();
184 * Tables to convert strings to enumeration values.
185 * Values stored are char
189 /* WARNING: sum of length of all value strings must not exceed
190 * this value */
191 #define TOTAL_VALUES_LENGTH 80
196 #define REFRESH_WINDOW_TEXTURES (1<<0)
197 #define REFRESH_MENU_TEXTURE (1<<1)
198 #define REFRESH_MENU_FONT (1<<2)
199 #define REFRESH_MENU_COLOR (1<<3)
200 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
201 #define REFRESH_MENU_TITLE_FONT (1<<5)
202 #define REFRESH_MENU_TITLE_COLOR (1<<6)
203 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
204 #define REFRESH_WINDOW_FONT (1<<8)
205 #define REFRESH_ICON_TILE (1<<9)
206 #define REFRESH_ICON_FONT (1<<10)
207 #define REFRESH_WORKSPACE_BACK (1<<11)
209 #define REFRESH_BUTTON_IMAGES (1<<12)
211 #define REFRESH_ICON_TITLE_COLOR (1<<13)
212 #define REFRESH_ICON_TITLE_BACK (1<<14)
216 static WOptionEnumeration seFocusModes[] = {
217 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
218 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
219 {NULL, 0, 0}
222 static WOptionEnumeration seColormapModes[] = {
223 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
224 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
225 {NULL, 0, 0}
228 static WOptionEnumeration sePlacements[] = {
229 {"Auto", WPM_AUTO, 0},
230 {"Smart", WPM_SMART, 0},
231 {"Cascade", WPM_CASCADE, 0},
232 {"Random", WPM_RANDOM, 0},
233 {"Manual", WPM_MANUAL, 0},
234 {NULL, 0, 0}
237 static WOptionEnumeration seGeomDisplays[] = {
238 {"None", WDIS_NONE, 0},
239 {"Center", WDIS_CENTER, 0},
240 {"Corner", WDIS_TOPLEFT, 0},
241 {"Floating", WDIS_FRAME_CENTER, 0},
242 {"Line", WDIS_NEW, 0},
243 {NULL, 0, 0}
246 static WOptionEnumeration seSpeeds[] = {
247 {"UltraFast", SPEED_ULTRAFAST, 0},
248 {"Fast", SPEED_FAST, 0},
249 {"Medium", SPEED_MEDIUM, 0},
250 {"Slow", SPEED_SLOW, 0},
251 {"UltraSlow", SPEED_ULTRASLOW, 0},
252 {NULL, 0, 0}
255 static WOptionEnumeration seMouseButtonActions[] = {
256 {"None", WA_NONE, 0},
257 {"SelectWindows", WA_SELECT_WINDOWS, 0},
258 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
259 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
260 {NULL, 0, 0}
263 static WOptionEnumeration seMouseWheelActions[] = {
264 {"None", WA_NONE, 0},
265 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
266 {NULL, 0, 0}
269 static WOptionEnumeration seIconificationStyles[] = {
270 {"Zoom", WIS_ZOOM, 0},
271 {"Twist", WIS_TWIST, 0},
272 {"Flip", WIS_FLIP, 0},
273 {"None", WIS_NONE, 0},
274 {"random", WIS_RANDOM, 0},
275 {NULL, 0, 0}
278 static WOptionEnumeration seJustifications[] = {
279 {"Left", WTJ_LEFT, 0},
280 {"Center", WTJ_CENTER, 0},
281 {"Right", WTJ_RIGHT, 0},
282 {NULL, 0, 0}
285 static WOptionEnumeration seIconPositions[] = {
286 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
287 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
288 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
289 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
290 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
291 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
292 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
293 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
294 {NULL, 0, 0}
297 static WOptionEnumeration seMenuStyles[] = {
298 {"normal", MS_NORMAL, 0},
299 {"singletexture", MS_SINGLE_TEXTURE, 0},
300 {"flat", MS_FLAT, 0},
301 {NULL, 0, 0}
305 static WOptionEnumeration seDisplayPositions[] = {
306 {"none", WD_NONE, 0},
307 {"center", WD_CENTER, 0},
308 {"top", WD_TOP, 0},
309 {"bottom", WD_BOTTOM, 0},
310 {"topleft", WD_TOPLEFT, 0},
311 {"topright", WD_TOPRIGHT, 0},
312 {"bottomleft", WD_BOTTOMLEFT, 0},
313 {"bottomright", WD_BOTTOMRIGHT, 0},
314 {NULL, 0, 0}
317 static WOptionEnumeration seWorkspaceBorder[] = {
318 {"None", WB_NONE, 0},
319 {"LeftRight", WB_LEFTRIGHT, 0},
320 {"TopBottom", WB_TOPBOTTOM, 0},
321 {"AllDirections", WB_ALLDIRS, 0},
322 {NULL, 0, 0}
327 * ALL entries in the tables bellow, NEED to have a default value
328 * defined, and this value needs to be correct.
331 /* these options will only affect the window manager on startup
333 * static defaults can't access the screen data, because it is
334 * created after these defaults are read
336 WDefaultEntry staticOptionList[] = {
338 {"ColormapSize", "4", NULL,
339 &wPreferences.cmap_size, getInt, NULL
341 {"DisableDithering", "NO", NULL,
342 &wPreferences.no_dithering, getBool, NULL
344 /* static by laziness */
345 {"IconSize", "64", NULL,
346 &wPreferences.icon_size, getInt, NULL
348 {"ModifierKey", "Mod1", NULL,
349 &wPreferences.modifier_mask, getModMask, NULL
351 {"DisableWSMouseActions", "NO", NULL,
352 &wPreferences.disable_root_mouse, getBool, NULL
354 {"FocusMode", "manual", seFocusModes,
355 &wPreferences.focus_mode, getEnum, NULL
356 }, /* have a problem when switching from manual to sloppy without restart */
357 {"NewStyle", "NO", NULL,
358 &wPreferences.new_style, getBool, NULL
360 {"DisableDock", "NO", (void*) WM_DOCK,
361 NULL, getBool, setIfDockPresent
363 {"DisableClip", "NO", (void*) WM_CLIP,
364 NULL, getBool, setIfDockPresent
366 {"DisableMiniwindows", "NO", NULL,
367 &wPreferences.disable_miniwindows, getBool, NULL
369 #if 0
370 ,{"MultiByteText", "NO", NULL,
371 &wPreferences.multi_byte_text, getBool, setMultiByte
373 #endif
378 WDefaultEntry optionList[] = {
379 /* dynamic options */
380 {"IconPosition", "blh", seIconPositions,
381 &wPreferences.icon_yard, getEnum, setIconPosition
383 {"IconificationStyle", "Zoom", seIconificationStyles,
384 &wPreferences.iconification_style, getEnum, NULL
386 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
387 &wPreferences.mouse_button1, getEnum, NULL
389 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
390 &wPreferences.mouse_button2, getEnum, NULL
392 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
393 &wPreferences.mouse_button3, getEnum, NULL
395 {"MouseWheelAction", "None", seMouseWheelActions,
396 &wPreferences.mouse_wheel, getEnum, NULL
398 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
399 &wPreferences.pixmap_path, getPathList, NULL
401 {"IconPath", DEF_ICON_PATHS, NULL,
402 &wPreferences.icon_path, getPathList, NULL
404 {"ColormapMode", "auto", seColormapModes,
405 &wPreferences.colormap_mode, getEnum, NULL
407 {"AutoFocus", "NO", NULL,
408 &wPreferences.auto_focus, getBool, NULL
410 {"RaiseDelay", "0", NULL,
411 &wPreferences.raise_delay, getInt, NULL
413 {"WindozeCycling", "NO", NULL,
414 &wPreferences.windows_cycling,getBool, NULL
416 {"CirculateRaise", "NO", NULL,
417 &wPreferences.circ_raise, getBool, NULL
419 {"Superfluous", "NO", NULL,
420 &wPreferences.superfluous, getBool, NULL
422 {"AdvanceToNewWorkspace", "NO", NULL,
423 &wPreferences.ws_advance, getBool, NULL
425 {"CycleWorkspaces", "NO", NULL,
426 &wPreferences.ws_cycle, getBool, NULL
428 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
429 &wPreferences.workspace_name_display_position, getEnum, NULL
431 {"WorkspaceBorder", "None", seWorkspaceBorder,
432 &wPreferences.workspace_border_position, getEnum, updateUsableArea
434 {"WorkspaceBorderSize", "0", NULL,
435 &wPreferences.workspace_border_size, getInt, updateUsableArea
437 #ifdef VIRTUAL_DESKTOP
438 {"VirtualEdgeThickness", "1", NULL,
439 &wPreferences.vedge_thickness, getInt, NULL
441 {"VirtualEdgeExtendSpace", "0", NULL,
442 &wPreferences.vedge_bordersize, getInt, NULL
444 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
445 &wPreferences.vedge_hscrollspeed, getInt, NULL
447 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
448 &wPreferences.vedge_vscrollspeed, getInt, NULL
450 {"VirtualEdgeMaximumWidth", "3000", NULL,
451 &wPreferences.vedge_maxwidth, getInt, NULL
453 {"VirtualEdgeMaximumHeight", "3000", NULL,
454 &wPreferences.vedge_maxheight, getInt, NULL
456 #endif
457 {"StickyIcons", "NO", NULL,
458 &wPreferences.sticky_icons, getBool, setStickyIcons
460 {"SaveSessionOnExit", "NO", NULL,
461 &wPreferences.save_session_on_exit, getBool, NULL
463 {"WrapMenus", "NO", NULL,
464 &wPreferences.wrap_menus, getBool, NULL
466 {"ScrollableMenus", "NO", NULL,
467 &wPreferences.scrollable_menus, getBool, NULL
469 {"MenuScrollSpeed", "medium", seSpeeds,
470 &wPreferences.menu_scroll_speed, getEnum, NULL
472 {"IconSlideSpeed", "medium", seSpeeds,
473 &wPreferences.icon_slide_speed, getEnum, NULL
475 {"ShadeSpeed", "medium", seSpeeds,
476 &wPreferences.shade_speed, getEnum, NULL
478 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
479 &wPreferences.dblclick_time, getInt, setDoubleClick,
481 {"AlignSubmenus", "NO", NULL,
482 &wPreferences.align_menus, getBool, NULL
484 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
485 &wPreferences.open_transients_with_parent, getBool, NULL
487 {"WindowPlacement", "auto", sePlacements,
488 &wPreferences.window_placement, getEnum, NULL
490 {"IgnoreFocusClick","NO", NULL,
491 &wPreferences.ignore_focus_click, getBool, NULL
493 {"UseSaveUnders", "NO", NULL,
494 &wPreferences.use_saveunders, getBool, NULL
496 {"OpaqueMove", "NO", NULL,
497 &wPreferences.opaque_move, getBool, NULL
499 {"DisableSound", "NO", NULL,
500 &wPreferences.no_sound, getBool, NULL
502 {"DisableAnimations", "NO", NULL,
503 &wPreferences.no_animations, getBool, NULL
505 {"DontLinkWorkspaces","NO", NULL,
506 &wPreferences.no_autowrap, getBool, NULL
508 {"AutoArrangeIcons", "NO", NULL,
509 &wPreferences.auto_arrange_icons, getBool, NULL
511 {"NoWindowOverDock", "NO", NULL,
512 &wPreferences.no_window_over_dock, getBool, updateUsableArea
514 {"NoWindowOverIcons", "NO", NULL,
515 &wPreferences.no_window_over_icons, getBool, updateUsableArea
517 {"WindowPlaceOrigin", "(0, 0)", NULL,
518 &wPreferences.window_place_origin, getCoord, NULL
520 {"ResizeDisplay", "corner", seGeomDisplays,
521 &wPreferences.size_display, getEnum, NULL
523 {"MoveDisplay", "corner", seGeomDisplays,
524 &wPreferences.move_display, getEnum, NULL
526 {"DontConfirmKill", "NO", NULL,
527 &wPreferences.dont_confirm_kill, getBool,NULL
529 {"WindowTitleBalloons", "NO", NULL,
530 &wPreferences.window_balloon, getBool, NULL
532 {"MiniwindowTitleBalloons", "NO", NULL,
533 &wPreferences.miniwin_balloon,getBool, NULL
535 {"AppIconBalloons", "NO", NULL,
536 &wPreferences.appicon_balloon,getBool, NULL
538 {"HelpBalloons", "NO", NULL,
539 &wPreferences.help_balloon, getBool, NULL
541 {"EdgeResistance", "30", NULL,
542 &wPreferences.edge_resistance,getInt, NULL
544 {"Attraction", "NO", NULL,
545 &wPreferences.attract, getBool, NULL
547 {"DisableBlinking", "NO", NULL,
548 &wPreferences.dont_blink, getBool, NULL
550 /* style options */
551 {"MenuStyle", "normal", seMenuStyles,
552 &wPreferences.menu_style, getEnum, setMenuStyle
554 {"WidgetColor", "(solid, gray)", NULL,
555 NULL, getTexture, setWidgetColor,
557 {"WorkspaceSpecificBack","()", NULL,
558 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
560 /* WorkspaceBack must come after WorkspaceSpecificBack or
561 * WorkspaceBack wont know WorkspaceSpecificBack was also
562 * specified and 2 copies of wmsetbg will be launched */
563 {"WorkspaceBack", "(solid, black)", NULL,
564 NULL, getWSBackground,setWorkspaceBack
566 {"SmoothWorkspaceBack", "NO", NULL,
567 NULL, getBool, NULL
569 {"IconBack", "(solid, gray)", NULL,
570 NULL, getTexture, setIconTile
572 {"TitleJustify", "center", seJustifications,
573 &wPreferences.title_justification, getEnum, setJustify
575 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
576 NULL, getFont, setWinTitleFont,
578 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
579 &wPreferences.window_title_clearance, getInt, setClearance
581 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
582 &wPreferences.menu_title_clearance, getInt, setClearance
584 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
585 &wPreferences.menu_text_clearance, getInt, setClearance
587 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
588 NULL, getFont, setMenuTitleFont
590 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
591 NULL, getFont, setMenuTextFont
593 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
594 NULL, getFont, setIconTitleFont
596 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
597 NULL, getFont, setClipTitleFont
599 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
600 NULL, getFont, setLargeDisplayFont
602 {"HighlightColor", "white", NULL,
603 NULL, getColor, setHightlight
605 {"HighlightTextColor", "black", NULL,
606 NULL, getColor, setHightlightText
608 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
609 NULL, getColor, setClipTitleColor
611 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
612 NULL, getColor, setClipTitleColor
614 {"FTitleColor", "white", (void*)WS_FOCUSED,
615 NULL, getColor, setWTitleColor
617 {"PTitleColor", "white", (void*)WS_PFOCUSED,
618 NULL, getColor, setWTitleColor
620 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
621 NULL, getColor, setWTitleColor
623 {"FTitleBack", "(solid, black)", NULL,
624 NULL, getTexture, setFTitleBack
626 {"PTitleBack", "(solid, \"#616161\")", NULL,
627 NULL, getTexture, setPTitleBack
629 {"UTitleBack", "(solid, gray)", NULL,
630 NULL, getTexture, setUTitleBack
632 {"ResizebarBack", "(solid, gray)", NULL,
633 NULL, getTexture, setResizebarBack
635 {"MenuTitleColor", "white", NULL,
636 NULL, getColor, setMenuTitleColor
638 {"MenuTextColor", "black", NULL,
639 NULL, getColor, setMenuTextColor
641 {"MenuDisabledColor", "\"#616161\"", NULL,
642 NULL, getColor, setMenuDisabledColor
644 {"MenuTitleBack", "(solid, black)", NULL,
645 NULL, getTexture, setMenuTitleBack
647 {"MenuTextBack", "(solid, gray)", NULL,
648 NULL, getTexture, setMenuTextBack
650 {"IconTitleColor", "white", NULL,
651 NULL, getColor, setIconTitleColor
653 {"IconTitleBack", "black", NULL,
654 NULL, getColor, setIconTitleBack
656 /* keybindings */
657 #ifndef LITE
658 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
659 NULL, getKeybind, setKeyGrab
661 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
662 NULL, getKeybind, setKeyGrab
664 #endif /* LITE */
665 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
666 NULL, getKeybind, setKeyGrab
668 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
669 NULL, getKeybind, setKeyGrab
671 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
672 NULL, getKeybind, setKeyGrab
674 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
675 NULL, getKeybind, setKeyGrab
677 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
678 NULL, getKeybind, setKeyGrab
680 {"HideKey", "None", (void*)WKBD_HIDE,
681 NULL, getKeybind, setKeyGrab
683 {"HideOthersKey", "None", (void*)WKBD_HIDE_OTHERS,
684 NULL, getKeybind, setKeyGrab
686 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
687 NULL, getKeybind, setKeyGrab
689 {"CloseKey", "None", (void*)WKBD_CLOSE,
690 NULL, getKeybind, setKeyGrab
692 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
693 NULL, getKeybind, setKeyGrab
695 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
696 NULL, getKeybind, setKeyGrab
698 {"HMaximizeKey", "None", (void*)WKBD_HMAXIMIZE,
699 NULL, getKeybind, setKeyGrab
701 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
702 NULL, getKeybind, setKeyGrab
704 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
705 NULL, getKeybind, setKeyGrab
707 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
708 NULL, getKeybind, setKeyGrab
710 {"ShadeKey", "None", (void*)WKBD_SHADE,
711 NULL, getKeybind, setKeyGrab
713 {"SelectKey", "None", (void*)WKBD_SELECT,
714 NULL, getKeybind, setKeyGrab
716 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
717 NULL, getKeybind, setKeyGrab
719 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
720 NULL, getKeybind, setKeyGrab
722 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
723 NULL, getKeybind, setKeyGrab
725 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
726 NULL, getKeybind, setKeyGrab
728 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
729 NULL, getKeybind, setKeyGrab
731 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
732 NULL, getKeybind, setKeyGrab
734 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
735 NULL, getKeybind, setKeyGrab
737 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
738 NULL, getKeybind, setKeyGrab
740 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
741 NULL, getKeybind, setKeyGrab
743 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
744 NULL, getKeybind, setKeyGrab
746 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
747 NULL, getKeybind, setKeyGrab
749 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
750 NULL, getKeybind, setKeyGrab
752 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
753 NULL, getKeybind, setKeyGrab
755 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
756 NULL, getKeybind, setKeyGrab
758 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
759 NULL, getKeybind, setKeyGrab
761 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
762 NULL, getKeybind, setKeyGrab
764 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
765 NULL, getKeybind, setKeyGrab
767 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
768 NULL, getKeybind, setKeyGrab
770 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
771 NULL, getKeybind, setKeyGrab
773 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
774 NULL, getKeybind, setKeyGrab
776 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
777 NULL, getKeybind, setKeyGrab
779 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
780 NULL, getKeybind, setKeyGrab
782 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
783 NULL, getKeybind, setKeyGrab
785 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
786 NULL, getKeybind, setKeyGrab
788 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
789 NULL, getKeybind, setKeyGrab
791 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
792 NULL, getKeybind, setKeyGrab
794 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
795 NULL, getKeybind, setKeyGrab
798 #ifdef KEEP_XKB_LOCK_STATUS
799 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
800 NULL, getKeybind, setKeyGrab
802 {"KbdModeLock", "NO", NULL,
803 &wPreferences.modelock, getBool, NULL
805 #endif /* KEEP_XKB_LOCK_STATUS */
807 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
808 NULL, getCursor, setCursor
810 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
811 NULL, getCursor, setCursor
813 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
814 NULL, getCursor, setCursor
816 {"ResizeCursor", "(builtin, sizing)", (void*)WCUR_RESIZE,
817 NULL, getCursor, setCursor
819 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
820 (void*)WCUR_TOPLEFTRESIZE,
821 NULL, getCursor, setCursor
823 {"TopRightResizeCursor", "(builtin, top_right_corner)",
824 (void*)WCUR_TOPRIGHTRESIZE,
825 NULL, getCursor, setCursor
827 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
828 (void*)WCUR_BOTTOMLEFTRESIZE,
829 NULL, getCursor, setCursor
831 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
832 (void*)WCUR_BOTTOMRIGHTRESIZE,
833 NULL, getCursor, setCursor
835 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
836 (void*)WCUR_VERTICALRESIZE,
837 NULL, getCursor, setCursor
839 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
840 (void*)WCUR_HORIZONRESIZE,
841 NULL, getCursor, setCursor
843 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
844 NULL, getCursor, setCursor
846 {"QuestionCursor", "(builtin, question_arrow)", (void*)WCUR_QUESTION,
847 NULL, getCursor, setCursor
849 {"TextCursor", "(builtin, xterm)", (void*)WCUR_TEXT,
850 NULL, getCursor, setCursor
852 {"SelectCursor", "(builtin, cross)", (void*)WCUR_SELECT,
853 NULL, getCursor, setCursor
858 #if 0
859 static void rereadDefaults(void);
860 #endif
862 #if 0
863 static void
864 rereadDefaults(void)
866 /* must defer the update because accessing X data from a
867 * signal handler can mess up Xlib */
870 #endif
872 static void
873 initDefaults()
875 int i;
876 WDefaultEntry *entry;
878 WMPLSetCaseSensitive(False);
880 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
881 entry = &optionList[i];
883 entry->plkey = WMCreatePLString(entry->key);
884 if (entry->default_value)
885 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
886 else
887 entry->plvalue = NULL;
890 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
891 entry = &staticOptionList[i];
893 entry->plkey = WMCreatePLString(entry->key);
894 if (entry->default_value)
895 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
896 else
897 entry->plvalue = NULL;
901 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
902 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
904 PLRegister(wDomainName, rereadDefaults);
905 PLRegister(wAttributeDomainName, rereadDefaults);
910 static WMPropList*
911 readGlobalDomain(char *domainName, Bool requireDictionary)
913 WMPropList *globalDict = NULL;
914 char path[PATH_MAX];
915 struct stat stbuf;
917 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domainName);
918 if (stat(path, &stbuf)>=0) {
919 globalDict = WMReadPropListFromFile(path);
920 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
921 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
922 domainName, path);
923 WMReleasePropList(globalDict);
924 globalDict = NULL;
925 } else if (!globalDict) {
926 wwarning(_("could not load domain %s from global defaults database"),
927 domainName);
931 return globalDict;
935 #if 0
936 WMPropList*
937 wDefaultsInit(int screen_number)
939 static int defaults_inited = 0;
940 WMPropList *dict;
942 if (!defaults_inited) {
943 initDefaults();
946 dict = PLGetDomain(wDomainName);
947 if (!dict) {
948 wwarning(_("could not read domain \"%s\" from defaults database"),
949 WMGetFromPLString(wDomainName));
952 return dict;
954 #endif
957 void
958 wDefaultsDestroyDomain(WDDomain *domain)
960 if (domain->dictionary)
961 WMReleasePropList(domain->dictionary);
962 wfree(domain->path);
963 wfree(domain);
967 WDDomain*
968 wDefaultsInitDomain(char *domain, Bool requireDictionary)
970 WDDomain *db;
971 struct stat stbuf;
972 static int inited = 0;
973 char path[PATH_MAX];
974 char *the_path;
975 WMPropList *shared_dict=NULL;
977 if (!inited) {
978 inited = 1;
979 initDefaults();
982 db = wmalloc(sizeof(WDDomain));
983 memset(db, 0, sizeof(WDDomain));
984 db->domain_name = domain;
985 db->path = wdefaultspathfordomain(domain);
986 the_path = db->path;
988 if (the_path && stat(the_path, &stbuf)>=0) {
989 db->dictionary = WMReadPropListFromFile(the_path);
990 if (db->dictionary) {
991 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
992 WMReleasePropList(db->dictionary);
993 db->dictionary = NULL;
994 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
995 domain, the_path);
997 db->timestamp = stbuf.st_mtime;
998 } else {
999 wwarning(_("could not load domain %s from user defaults database"),
1000 domain);
1004 /* global system dictionary */
1005 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
1006 if (stat(path, &stbuf)>=0) {
1007 shared_dict = WMReadPropListFromFile(path);
1008 if (shared_dict) {
1009 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
1010 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1011 domain, path);
1012 WMReleasePropList(shared_dict);
1013 shared_dict = NULL;
1014 } else {
1015 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
1016 WMIsPLDictionary(db->dictionary)) {
1017 WMMergePLDictionaries(shared_dict, db->dictionary, True);
1018 WMReleasePropList(db->dictionary);
1019 db->dictionary = shared_dict;
1020 if (stbuf.st_mtime > db->timestamp)
1021 db->timestamp = stbuf.st_mtime;
1022 } else if (!db->dictionary) {
1023 db->dictionary = shared_dict;
1024 if (stbuf.st_mtime > db->timestamp)
1025 db->timestamp = stbuf.st_mtime;
1028 } else {
1029 wwarning(_("could not load domain %s from global defaults database (%s)"),
1030 domain, path);
1034 return db;
1038 void
1039 wReadStaticDefaults(WMPropList *dict)
1041 WMPropList *plvalue;
1042 WDefaultEntry *entry;
1043 int i;
1044 void *tdata;
1047 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1048 entry = &staticOptionList[i];
1050 if (dict)
1051 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
1052 else
1053 plvalue = NULL;
1055 if (!plvalue) {
1056 /* no default in the DB. Use builtin default */
1057 plvalue = entry->plvalue;
1060 if (plvalue) {
1061 /* convert data */
1062 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1063 if (entry->update) {
1064 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1071 void
1072 wDefaultsCheckDomains(void *foo)
1074 WScreen *scr;
1075 struct stat stbuf;
1076 WMPropList *shared_dict = NULL;
1077 WMPropList *dict;
1078 int i;
1080 #ifdef HEARTBEAT
1081 puts("Checking domains...");
1082 #endif
1083 if (stat(WDWindowMaker->path, &stbuf)>=0
1084 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1085 #ifdef HEARTBEAT
1086 puts("Checking WindowMaker domain");
1087 #endif
1088 WDWindowMaker->timestamp = stbuf.st_mtime;
1090 /* global dictionary */
1091 shared_dict = readGlobalDomain("WindowMaker", True);
1092 /* user dictionary */
1093 dict = WMReadPropListFromFile(WDWindowMaker->path);
1094 if (dict) {
1095 if (!WMIsPLDictionary(dict)) {
1096 WMReleasePropList(dict);
1097 dict = NULL;
1098 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1099 "WindowMaker", WDWindowMaker->path);
1100 } else {
1101 if (shared_dict) {
1102 WMMergePLDictionaries(shared_dict, dict, True);
1103 WMReleasePropList(dict);
1104 dict = shared_dict;
1105 shared_dict = NULL;
1107 for (i=0; i<wScreenCount; i++) {
1108 scr = wScreenWithNumber(i);
1109 if (scr)
1110 wReadDefaults(scr, dict);
1112 if (WDWindowMaker->dictionary) {
1113 WMReleasePropList(WDWindowMaker->dictionary);
1115 WDWindowMaker->dictionary = dict;
1117 } else {
1118 wwarning(_("could not load domain %s from user defaults database"),
1119 "WindowMaker");
1121 if (shared_dict) {
1122 WMReleasePropList(shared_dict);
1126 if (stat(WDWindowAttributes->path, &stbuf)>=0
1127 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1128 #ifdef HEARTBEAT
1129 puts("Checking WMWindowAttributes domain");
1130 #endif
1131 /* global dictionary */
1132 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1133 /* user dictionary */
1134 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1135 if (dict) {
1136 if (!WMIsPLDictionary(dict)) {
1137 WMReleasePropList(dict);
1138 dict = NULL;
1139 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1140 "WMWindowAttributes", WDWindowAttributes->path);
1141 } else {
1142 if (shared_dict) {
1143 WMMergePLDictionaries(shared_dict, dict, True);
1144 WMReleasePropList(dict);
1145 dict = shared_dict;
1146 shared_dict = NULL;
1148 if (WDWindowAttributes->dictionary) {
1149 WMReleasePropList(WDWindowAttributes->dictionary);
1151 WDWindowAttributes->dictionary = dict;
1152 for (i=0; i<wScreenCount; i++) {
1153 scr = wScreenWithNumber(i);
1154 if (scr) {
1155 RImage *image;
1157 wDefaultUpdateIcons(scr);
1159 /* Update the panel image if changed */
1160 /* Don't worry. If the image is the same these
1161 * functions will have no performance impact. */
1162 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1164 if (!image) {
1165 wwarning(_("could not load logo image for panels: %s"),
1166 RMessageForError(RErrorCode));
1167 } else {
1168 WMSetApplicationIconImage(scr->wmscreen, image);
1169 RReleaseImage(image);
1174 } else {
1175 wwarning(_("could not load domain %s from user defaults database"),
1176 "WMWindowAttributes");
1178 WDWindowAttributes->timestamp = stbuf.st_mtime;
1179 if (shared_dict) {
1180 WMReleasePropList(shared_dict);
1184 #ifndef LITE
1185 if (stat(WDRootMenu->path, &stbuf)>=0
1186 && WDRootMenu->timestamp < stbuf.st_mtime) {
1187 dict = WMReadPropListFromFile(WDRootMenu->path);
1188 #ifdef HEARTBEAT
1189 puts("Checking WMRootMenu domain");
1190 #endif
1191 if (dict) {
1192 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1193 WMReleasePropList(dict);
1194 dict = NULL;
1195 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1196 "WMRootMenu", WDRootMenu->path);
1197 } else {
1198 if (WDRootMenu->dictionary) {
1199 WMReleasePropList(WDRootMenu->dictionary);
1201 WDRootMenu->dictionary = dict;
1203 } else {
1204 wwarning(_("could not load domain %s from user defaults database"),
1205 "WMRootMenu");
1207 WDRootMenu->timestamp = stbuf.st_mtime;
1209 #endif /* !LITE */
1211 if (!foo)
1212 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1216 void
1217 wReadDefaults(WScreen *scr, WMPropList *new_dict)
1219 WMPropList *plvalue, *old_value;
1220 WDefaultEntry *entry;
1221 int i, must_update;
1222 int update_workspace_back = 0; /* kluge :/ */
1223 int needs_refresh;
1224 void *tdata;
1225 WMPropList *old_dict = (WDWindowMaker->dictionary!=new_dict
1226 ? WDWindowMaker->dictionary : NULL);
1228 must_update = 0;
1230 needs_refresh = 0;
1232 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1233 entry = &optionList[i];
1235 if (new_dict)
1236 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1237 else
1238 plvalue = NULL;
1240 if (!old_dict)
1241 old_value = NULL;
1242 else
1243 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1246 if (!plvalue && !old_value) {
1247 /* no default in the DB. Use builtin default */
1248 plvalue = entry->plvalue;
1249 if (plvalue && new_dict) {
1250 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1251 must_update = 1;
1253 } else if (!plvalue) {
1254 /* value was deleted from DB. Keep current value */
1255 continue;
1256 } else if (!old_value) {
1257 /* set value for the 1st time */
1258 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1259 /* value has changed */
1260 } else {
1262 if (strcmp(entry->key, "WorkspaceBack") == 0
1263 && update_workspace_back
1264 && scr->flags.backimage_helper_launched) {
1265 } else {
1266 /* value was not changed since last time */
1267 continue;
1271 if (plvalue) {
1272 #ifdef DEBUG
1273 printf("Updating %s to %s\n", entry->key,
1274 WMGetPropListDescription(plvalue, False));
1275 #endif
1276 /* convert data */
1277 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1279 * If the WorkspaceSpecificBack data has been changed
1280 * so that the helper will be launched now, we must be
1281 * sure to send the default background texture config
1282 * to the helper.
1284 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1285 && !scr->flags.backimage_helper_launched) {
1286 update_workspace_back = 1;
1288 if (entry->update) {
1289 needs_refresh |=
1290 (*entry->update)(scr, entry, tdata, entry->extra_data);
1296 if (needs_refresh!=0 && !scr->flags.startup) {
1297 int foo;
1299 foo = 0;
1300 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1301 foo |= WTextureSettings;
1302 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1303 foo |= WFontSettings;
1304 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1305 foo |= WColorSettings;
1306 if (foo)
1307 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1308 (void*)foo);
1310 foo = 0;
1311 if (needs_refresh & REFRESH_MENU_TEXTURE)
1312 foo |= WTextureSettings;
1313 if (needs_refresh & REFRESH_MENU_FONT)
1314 foo |= WFontSettings;
1315 if (needs_refresh & REFRESH_MENU_COLOR)
1316 foo |= WColorSettings;
1317 if (foo)
1318 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1319 (void*)foo);
1321 foo = 0;
1322 if (needs_refresh & REFRESH_WINDOW_FONT) {
1323 foo |= WFontSettings;
1325 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1326 foo |= WTextureSettings;
1328 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1329 foo |= WColorSettings;
1331 if (foo)
1332 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1333 (void*)foo);
1335 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1336 foo = 0;
1337 if (needs_refresh & REFRESH_ICON_FONT) {
1338 foo |= WFontSettings;
1340 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1341 foo |= WTextureSettings;
1343 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1344 foo |= WTextureSettings;
1346 if (foo)
1347 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1348 (void*)foo);
1350 if (needs_refresh & REFRESH_ICON_TILE)
1351 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1356 void
1357 wDefaultUpdateIcons(WScreen *scr)
1359 WAppIcon *aicon = scr->app_icon_list;
1360 WWindow *wwin = scr->focused_window;
1361 char *file;
1363 while(aicon) {
1364 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1365 False);
1366 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1367 || (file && !aicon->icon->file)) {
1368 RImage *new_image;
1370 if (aicon->icon->file)
1371 wfree(aicon->icon->file);
1372 aicon->icon->file = wstrdup(file);
1374 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1375 aicon->wm_class);
1376 if (new_image) {
1377 wIconChangeImage(aicon->icon, new_image);
1378 wAppIconPaint(aicon);
1381 aicon = aicon->next;
1384 if (!wPreferences.flags.noclip)
1385 wClipIconPaint(scr->clip_icon);
1387 while (wwin) {
1388 if (wwin->icon && wwin->flags.miniaturized) {
1389 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1390 False);
1391 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1392 || (file && !wwin->icon->file)) {
1393 RImage *new_image;
1395 if (wwin->icon->file)
1396 wfree(wwin->icon->file);
1397 wwin->icon->file = wstrdup(file);
1399 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1400 wwin->wm_class);
1401 if (new_image)
1402 wIconChangeImage(wwin->icon, new_image);
1405 wwin = wwin->prev;
1410 /* --------------------------- Local ----------------------- */
1412 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1413 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1414 entry->key, x); \
1415 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1416 var = entry->default_value;\
1417 } else var = WMGetFromPLString(value)\
1423 static int
1424 string2index(WMPropList *key, WMPropList *val, char *def,
1425 WOptionEnumeration *values)
1427 char *str;
1428 WOptionEnumeration *v;
1429 char buffer[TOTAL_VALUES_LENGTH];
1431 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1432 for (v=values; v->string!=NULL; v++) {
1433 if (strcasecmp(v->string, str)==0)
1434 return v->value;
1438 buffer[0] = 0;
1439 for (v=values; v->string!=NULL; v++) {
1440 if (!v->is_alias) {
1441 if (buffer[0]!=0)
1442 strcat(buffer, ", ");
1443 strcat(buffer, v->string);
1446 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1447 WMGetFromPLString(key), buffer);
1449 if (def) {
1450 return string2index(key, val, NULL, values);
1453 return -1;
1460 * value - is the value in the defaults DB
1461 * addr - is the address to store the data
1462 * ret - is the address to store a pointer to a temporary buffer. ret
1463 * must not be freed and is used by the set functions
1465 static int
1466 getBool(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1467 void **ret)
1469 static char data;
1470 char *val;
1471 int second_pass=0;
1473 GET_STRING_OR_DEFAULT("Boolean", val);
1475 again:
1476 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1477 || strcasecmp(val, "YES")==0) {
1479 data = 1;
1480 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1481 || strcasecmp(val, "NO")==0) {
1482 data = 0;
1483 } else {
1484 int i;
1485 if (sscanf(val, "%i", &i)==1) {
1486 if (i!=0)
1487 data = 1;
1488 else
1489 data = 0;
1490 } else {
1491 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1492 val, entry->key);
1493 if (second_pass==0) {
1494 val = WMGetFromPLString(entry->plvalue);
1495 second_pass = 1;
1496 wwarning(_("using default \"%s\" instead"), val);
1497 goto again;
1499 return False;
1503 if (ret)
1504 *ret = &data;
1506 if (addr) {
1507 *(char*)addr = data;
1510 return True;
1514 static int
1515 getInt(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1516 void **ret)
1518 static int data;
1519 char *val;
1522 GET_STRING_OR_DEFAULT("Integer", val);
1524 if (sscanf(val, "%i", &data)!=1) {
1525 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1526 val, entry->key);
1527 val = WMGetFromPLString(entry->plvalue);
1528 wwarning(_("using default \"%s\" instead"), val);
1529 if (sscanf(val, "%i", &data)!=1) {
1530 return False;
1534 if (ret)
1535 *ret = &data;
1537 if (addr) {
1538 *(int*)addr = data;
1540 return True;
1544 static int
1545 getCoord(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1546 void **ret)
1548 static WCoord data;
1549 char *val_x, *val_y;
1550 int nelem, changed=0;
1551 WMPropList *elem_x, *elem_y;
1553 again:
1554 if (!WMIsPLArray(value)) {
1555 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1556 entry->key, "Coordinate");
1557 if (changed==0) {
1558 value = entry->plvalue;
1559 changed = 1;
1560 wwarning(_("using default \"%s\" instead"), entry->default_value);
1561 goto again;
1563 return False;
1566 nelem = WMGetPropListItemCount(value);
1567 if (nelem != 2) {
1568 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1569 entry->key);
1570 if (changed==0) {
1571 value = entry->plvalue;
1572 changed = 1;
1573 wwarning(_("using default \"%s\" instead"), entry->default_value);
1574 goto again;
1576 return False;
1579 elem_x = WMGetFromPLArray(value, 0);
1580 elem_y = WMGetFromPLArray(value, 1);
1582 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1583 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1584 entry->key);
1585 if (changed==0) {
1586 value = entry->plvalue;
1587 changed = 1;
1588 wwarning(_("using default \"%s\" instead"), entry->default_value);
1589 goto again;
1591 return False;
1594 val_x = WMGetFromPLString(elem_x);
1595 val_y = WMGetFromPLString(elem_y);
1597 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1598 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1599 if (changed==0) {
1600 value = entry->plvalue;
1601 changed = 1;
1602 wwarning(_("using default \"%s\" instead"), entry->default_value);
1603 goto again;
1605 return False;
1608 if (data.x < 0)
1609 data.x = 0;
1610 else if (data.x > scr->scr_width/3)
1611 data.x = scr->scr_width/3;
1612 if (data.y < 0)
1613 data.y = 0;
1614 else if (data.y > scr->scr_height/3)
1615 data.y = scr->scr_height/3;
1617 if (ret)
1618 *ret = &data;
1620 if (addr) {
1621 *(WCoord*)addr = data;
1624 return True;
1628 #if 0
1629 /* This function is not used at the moment. */
1630 static int
1631 getString(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1632 void **ret)
1634 static char *data;
1636 GET_STRING_OR_DEFAULT("String", data);
1638 if (!data) {
1639 data = WMGetFromPLString(entry->plvalue);
1640 if (!data)
1641 return False;
1644 if (ret)
1645 *ret = &data;
1647 if (addr)
1648 *(char**)addr = wstrdup(data);
1650 return True;
1652 #endif
1655 static int
1656 getPathList(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1657 void **ret)
1659 static char *data;
1660 int i, count, len;
1661 char *ptr;
1662 WMPropList *d;
1663 int changed=0;
1665 again:
1666 if (!WMIsPLArray(value)) {
1667 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1668 entry->key, "an array of paths");
1669 if (changed==0) {
1670 value = entry->plvalue;
1671 changed = 1;
1672 wwarning(_("using default \"%s\" instead"), entry->default_value);
1673 goto again;
1675 return False;
1678 i = 0;
1679 count = WMGetPropListItemCount(value);
1680 if (count < 1) {
1681 if (changed==0) {
1682 value = entry->plvalue;
1683 changed = 1;
1684 wwarning(_("using default \"%s\" instead"), entry->default_value);
1685 goto again;
1687 return False;
1690 len = 0;
1691 for (i=0; i<count; i++) {
1692 d = WMGetFromPLArray(value, i);
1693 if (!d || !WMIsPLString(d)) {
1694 count = i;
1695 break;
1697 len += strlen(WMGetFromPLString(d))+1;
1700 ptr = data = wmalloc(len+1);
1702 for (i=0; i<count; i++) {
1703 d = WMGetFromPLArray(value, i);
1704 if (!d || !WMIsPLString(d)) {
1705 break;
1707 strcpy(ptr, WMGetFromPLString(d));
1708 ptr += strlen(WMGetFromPLString(d));
1709 *ptr = ':';
1710 ptr++;
1712 ptr--; *(ptr--) = 0;
1714 if (*(char**)addr!=NULL) {
1715 wfree(*(char**)addr);
1717 *(char**)addr = data;
1719 return True;
1723 static int
1724 getEnum(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1725 void **ret)
1727 static signed char data;
1729 data = string2index(entry->plkey, value, entry->default_value,
1730 (WOptionEnumeration*)entry->extra_data);
1731 if (data < 0)
1732 return False;
1734 if (ret)
1735 *ret = &data;
1737 if (addr)
1738 *(signed char*)addr = data;
1740 return True;
1746 * (solid <color>)
1747 * (hgradient <color> <color>)
1748 * (vgradient <color> <color>)
1749 * (dgradient <color> <color>)
1750 * (mhgradient <color> <color> ...)
1751 * (mvgradient <color> <color> ...)
1752 * (mdgradient <color> <color> ...)
1753 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1754 * (tpixmap <file> <color>)
1755 * (spixmap <file> <color>)
1756 * (cpixmap <file> <color>)
1757 * (thgradient <file> <opaqueness> <color> <color>)
1758 * (tvgradient <file> <opaqueness> <color> <color>)
1759 * (tdgradient <file> <opaqueness> <color> <color>)
1760 * (function <lib> <function> ...)
1763 static WTexture*
1764 parse_texture(WScreen *scr, WMPropList *pl)
1766 WMPropList *elem;
1767 char *val;
1768 int nelem;
1769 WTexture *texture=NULL;
1771 nelem = WMGetPropListItemCount(pl);
1772 if (nelem < 1)
1773 return NULL;
1776 elem = WMGetFromPLArray(pl, 0);
1777 if (!elem || !WMIsPLString(elem))
1778 return NULL;
1779 val = WMGetFromPLString(elem);
1782 if (strcasecmp(val, "solid")==0) {
1783 XColor color;
1785 if (nelem != 2)
1786 return NULL;
1788 /* get color */
1790 elem = WMGetFromPLArray(pl, 1);
1791 if (!elem || !WMIsPLString(elem))
1792 return NULL;
1793 val = WMGetFromPLString(elem);
1795 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1796 wwarning(_("\"%s\" is not a valid color name"), val);
1797 return NULL;
1800 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1801 } else if (strcasecmp(val, "dgradient")==0
1802 || strcasecmp(val, "vgradient")==0
1803 || strcasecmp(val, "hgradient")==0) {
1804 RColor color1, color2;
1805 XColor xcolor;
1806 int type;
1808 if (nelem != 3) {
1809 wwarning(_("bad number of arguments in gradient specification"));
1810 return NULL;
1813 if (val[0]=='d' || val[0]=='D')
1814 type = WTEX_DGRADIENT;
1815 else if (val[0]=='h' || val[0]=='H')
1816 type = WTEX_HGRADIENT;
1817 else
1818 type = WTEX_VGRADIENT;
1821 /* get from color */
1822 elem = WMGetFromPLArray(pl, 1);
1823 if (!elem || !WMIsPLString(elem))
1824 return NULL;
1825 val = WMGetFromPLString(elem);
1827 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1828 wwarning(_("\"%s\" is not a valid color name"), val);
1829 return NULL;
1831 color1.alpha = 255;
1832 color1.red = xcolor.red >> 8;
1833 color1.green = xcolor.green >> 8;
1834 color1.blue = xcolor.blue >> 8;
1836 /* get to color */
1837 elem = WMGetFromPLArray(pl, 2);
1838 if (!elem || !WMIsPLString(elem)) {
1839 return NULL;
1841 val = WMGetFromPLString(elem);
1843 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1844 wwarning(_("\"%s\" is not a valid color name"), val);
1845 return NULL;
1847 color2.alpha = 255;
1848 color2.red = xcolor.red >> 8;
1849 color2.green = xcolor.green >> 8;
1850 color2.blue = xcolor.blue >> 8;
1852 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1854 } else if (strcasecmp(val, "igradient")==0) {
1855 RColor colors1[2], colors2[2];
1856 int th1, th2;
1857 XColor xcolor;
1858 int i;
1860 if (nelem != 7) {
1861 wwarning(_("bad number of arguments in gradient specification"));
1862 return NULL;
1865 /* get from color */
1866 for (i = 0; i < 2; i++) {
1867 elem = WMGetFromPLArray(pl, 1+i);
1868 if (!elem || !WMIsPLString(elem))
1869 return NULL;
1870 val = WMGetFromPLString(elem);
1872 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1873 wwarning(_("\"%s\" is not a valid color name"), val);
1874 return NULL;
1876 colors1[i].alpha = 255;
1877 colors1[i].red = xcolor.red >> 8;
1878 colors1[i].green = xcolor.green >> 8;
1879 colors1[i].blue = xcolor.blue >> 8;
1881 elem = WMGetFromPLArray(pl, 3);
1882 if (!elem || !WMIsPLString(elem))
1883 return NULL;
1884 val = WMGetFromPLString(elem);
1885 th1 = atoi(val);
1888 /* get from color */
1889 for (i = 0; i < 2; i++) {
1890 elem = WMGetFromPLArray(pl, 4+i);
1891 if (!elem || !WMIsPLString(elem))
1892 return NULL;
1893 val = WMGetFromPLString(elem);
1895 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1896 wwarning(_("\"%s\" is not a valid color name"), val);
1897 return NULL;
1899 colors2[i].alpha = 255;
1900 colors2[i].red = xcolor.red >> 8;
1901 colors2[i].green = xcolor.green >> 8;
1902 colors2[i].blue = xcolor.blue >> 8;
1904 elem = WMGetFromPLArray(pl, 6);
1905 if (!elem || !WMIsPLString(elem))
1906 return NULL;
1907 val = WMGetFromPLString(elem);
1908 th2 = atoi(val);
1910 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1911 th2, colors2);
1913 } else if (strcasecmp(val, "mhgradient")==0
1914 || strcasecmp(val, "mvgradient")==0
1915 || strcasecmp(val, "mdgradient")==0) {
1916 XColor color;
1917 RColor **colors;
1918 int i, count;
1919 int type;
1921 if (nelem < 3) {
1922 wwarning(_("too few arguments in multicolor gradient specification"));
1923 return NULL;
1926 if (val[1]=='h' || val[1]=='H')
1927 type = WTEX_MHGRADIENT;
1928 else if (val[1]=='v' || val[1]=='V')
1929 type = WTEX_MVGRADIENT;
1930 else
1931 type = WTEX_MDGRADIENT;
1933 count = nelem-1;
1935 colors = wmalloc(sizeof(RColor*)*(count+1));
1937 for (i=0; i<count; i++) {
1938 elem = WMGetFromPLArray(pl, i+1);
1939 if (!elem || !WMIsPLString(elem)) {
1940 for (--i; i>=0; --i) {
1941 wfree(colors[i]);
1943 wfree(colors);
1944 return NULL;
1946 val = WMGetFromPLString(elem);
1948 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1949 wwarning(_("\"%s\" is not a valid color name"), val);
1950 for (--i; i>=0; --i) {
1951 wfree(colors[i]);
1953 wfree(colors);
1954 return NULL;
1955 } else {
1956 colors[i] = wmalloc(sizeof(RColor));
1957 colors[i]->red = color.red >> 8;
1958 colors[i]->green = color.green >> 8;
1959 colors[i]->blue = color.blue >> 8;
1962 colors[i] = NULL;
1964 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1965 } else if (strcasecmp(val, "spixmap")==0 ||
1966 strcasecmp(val, "cpixmap")==0 ||
1967 strcasecmp(val, "tpixmap")==0) {
1968 XColor color;
1969 int type;
1971 if (nelem != 3)
1972 return NULL;
1974 if (val[0] == 's' || val[0] == 'S')
1975 type = WTP_SCALE;
1976 else if (val[0] == 'c' || val[0] == 'C')
1977 type = WTP_CENTER;
1978 else
1979 type = WTP_TILE;
1981 /* get color */
1982 elem = WMGetFromPLArray(pl, 2);
1983 if (!elem || !WMIsPLString(elem)) {
1984 return NULL;
1986 val = WMGetFromPLString(elem);
1988 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1989 wwarning(_("\"%s\" is not a valid color name"), val);
1990 return NULL;
1993 /* file name */
1994 elem = WMGetFromPLArray(pl, 1);
1995 if (!elem || !WMIsPLString(elem))
1996 return NULL;
1997 val = WMGetFromPLString(elem);
1999 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
2000 } else if (strcasecmp(val, "thgradient")==0
2001 || strcasecmp(val, "tvgradient")==0
2002 || strcasecmp(val, "tdgradient")==0) {
2003 RColor color1, color2;
2004 XColor xcolor;
2005 int opacity;
2006 int style;
2008 if (val[1]=='h' || val[1]=='H')
2009 style = WTEX_THGRADIENT;
2010 else if (val[1]=='v' || val[1]=='V')
2011 style = WTEX_TVGRADIENT;
2012 else
2013 style = WTEX_TDGRADIENT;
2015 if (nelem != 5) {
2016 wwarning(_("bad number of arguments in textured gradient specification"));
2017 return NULL;
2020 /* get from color */
2021 elem = WMGetFromPLArray(pl, 3);
2022 if (!elem || !WMIsPLString(elem))
2023 return NULL;
2024 val = WMGetFromPLString(elem);
2026 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2027 wwarning(_("\"%s\" is not a valid color name"), val);
2028 return NULL;
2030 color1.alpha = 255;
2031 color1.red = xcolor.red >> 8;
2032 color1.green = xcolor.green >> 8;
2033 color1.blue = xcolor.blue >> 8;
2035 /* get to color */
2036 elem = WMGetFromPLArray(pl, 4);
2037 if (!elem || !WMIsPLString(elem)) {
2038 return NULL;
2040 val = WMGetFromPLString(elem);
2042 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2043 wwarning(_("\"%s\" is not a valid color name"), val);
2044 return NULL;
2046 color2.alpha = 255;
2047 color2.red = xcolor.red >> 8;
2048 color2.green = xcolor.green >> 8;
2049 color2.blue = xcolor.blue >> 8;
2051 /* get opacity */
2052 elem = WMGetFromPLArray(pl, 2);
2053 if (!elem || !WMIsPLString(elem))
2054 opacity = 128;
2055 else
2056 val = WMGetFromPLString(elem);
2058 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2059 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2060 opacity = 128;
2063 /* get file name */
2064 elem = WMGetFromPLArray(pl, 1);
2065 if (!elem || !WMIsPLString(elem))
2066 return NULL;
2067 val = WMGetFromPLString(elem);
2069 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2070 val, opacity);
2072 #ifdef TEXTURE_PLUGIN
2073 else if (strcasecmp(val, "function")==0) {
2074 WTexFunction *function;
2075 void (*initFunc) (Display *, Colormap);
2076 char *lib, *func, **argv;
2077 int i, argc;
2079 if (nelem < 3)
2080 return NULL;
2082 /* get the library name */
2083 elem = WMGetFromPLArray(pl, 1);
2084 if (!elem || !WMIsPLString(elem)) {
2085 return NULL;
2087 lib = WMGetFromPLString(elem);
2089 /* get the function name */
2090 elem = WMGetFromPLArray(pl, 2);
2091 if (!elem || !WMIsPLString(elem)) {
2092 return NULL;
2094 func = WMGetFromPLString(elem);
2096 argc = nelem - 2;
2097 argv = (char **)wmalloc(argc * sizeof(char *));
2099 /* get the parameters */
2100 argv[0] = wstrdup(func);
2101 for (i = 0; i < argc - 1; i++) {
2102 elem = WMGetFromPLArray(pl, 3 + i);
2103 if (!elem || !WMIsPLString(elem)) {
2104 wfree(argv);
2106 return NULL;
2108 argv[i+1] = wstrdup(WMGetFromPLString(elem));
2111 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2113 #ifdef HAVE_DLFCN_H
2114 if (function) {
2115 initFunc = dlsym(function->handle, "initWindowMaker");
2116 if (initFunc) {
2117 initFunc(dpy, scr->w_colormap);
2118 } else {
2119 wwarning(_("could not initialize library %s"), lib);
2121 } else {
2122 wwarning(_("could not find function %s::%s"), lib, func);
2124 #endif /* HAVE_DLFCN_H */
2125 texture = (WTexture*)function;
2127 #endif /* TEXTURE_PLUGIN */
2128 else {
2129 wwarning(_("invalid texture type %s"), val);
2130 return NULL;
2132 return texture;
2137 static int
2138 getTexture(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2139 void **ret)
2141 static WTexture *texture;
2142 int changed=0;
2144 again:
2145 if (!WMIsPLArray(value)) {
2146 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2147 entry->key, "Texture");
2148 if (changed==0) {
2149 value = entry->plvalue;
2150 changed = 1;
2151 wwarning(_("using default \"%s\" instead"), entry->default_value);
2152 goto again;
2154 return False;
2157 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2158 WMPropList *pl;
2160 pl = WMGetFromPLArray(value, 0);
2161 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2162 || strcasecmp(WMGetFromPLString(pl), "solid")!=0) {
2163 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2164 entry->key, "Solid Texture");
2166 value = entry->plvalue;
2167 changed = 1;
2168 wwarning(_("using default \"%s\" instead"), entry->default_value);
2169 goto again;
2173 texture = parse_texture(scr, value);
2175 if (!texture) {
2176 wwarning(_("Error in texture specification for key \"%s\""),
2177 entry->key);
2178 if (changed==0) {
2179 value = entry->plvalue;
2180 changed = 1;
2181 wwarning(_("using default \"%s\" instead"), entry->default_value);
2182 goto again;
2184 return False;
2187 if (ret)
2188 *ret = &texture;
2190 if (addr)
2191 *(WTexture**)addr = texture;
2193 return True;
2197 static int
2198 getWSBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2199 void *addr, void **ret)
2201 WMPropList *elem;
2202 int changed = 0;
2203 char *val;
2204 int nelem;
2206 again:
2207 if (!WMIsPLArray(value)) {
2208 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2209 "WorkspaceBack", "Texture or None");
2210 if (changed==0) {
2211 value = entry->plvalue;
2212 changed = 1;
2213 wwarning(_("using default \"%s\" instead"), entry->default_value);
2214 goto again;
2216 return False;
2219 /* only do basic error checking and verify for None texture */
2221 nelem = WMGetPropListItemCount(value);
2222 if (nelem > 0) {
2223 elem = WMGetFromPLArray(value, 0);
2224 if (!elem || !WMIsPLString(elem)) {
2225 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2226 if (changed==0) {
2227 value = entry->plvalue;
2228 changed = 1;
2229 wwarning(_("using default \"%s\" instead"), entry->default_value);
2230 goto again;
2232 return False;
2234 val = WMGetFromPLString(elem);
2236 if (strcasecmp(val, "None")==0)
2237 return True;
2239 *ret = WMRetainPropList(value);
2241 return True;
2245 static int
2246 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2247 void *addr, void **ret)
2249 WMPropList *elem;
2250 int nelem;
2251 int changed = 0;
2253 again:
2254 if (!WMIsPLArray(value)) {
2255 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2256 "WorkspaceSpecificBack", "an array of textures");
2257 if (changed==0) {
2258 value = entry->plvalue;
2259 changed = 1;
2260 wwarning(_("using default \"%s\" instead"), entry->default_value);
2261 goto again;
2263 return False;
2266 /* only do basic error checking and verify for None texture */
2268 nelem = WMGetPropListItemCount(value);
2269 if (nelem > 0) {
2270 while (nelem--) {
2271 elem = WMGetFromPLArray(value, nelem);
2272 if (!elem || !WMIsPLArray(elem)) {
2273 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2274 nelem);
2279 *ret = WMRetainPropList(value);
2281 #ifdef notworking
2283 * Kluge to force wmsetbg helper to set the default background.
2284 * If the WorkspaceSpecificBack is changed once wmaker has started,
2285 * the WorkspaceBack won't be sent to the helper, unless the user
2286 * changes it's value too. So, we must force this by removing the
2287 * value from the defaults DB.
2289 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2290 WMPropList *key = WMCreatePLString("WorkspaceBack");
2292 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2294 WMReleasePropList(key);
2296 #endif
2297 return True;
2301 static int
2302 getFont(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2303 void **ret)
2305 static WMFont *font;
2306 char *val;
2308 GET_STRING_OR_DEFAULT("Font", val);
2310 font = WMCreateFont(scr->wmscreen, val);
2311 if (!font)
2312 font = WMCreateFont(scr->wmscreen, "fixed");
2314 if (!font) {
2315 wfatal(_("could not load any usable font!!!"));
2316 exit(1);
2319 if (ret)
2320 *ret = font;
2322 /* can't assign font value outside update function */
2323 wassertrv(addr == NULL, True);
2325 return True;
2329 static int
2330 getColor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2331 void **ret)
2333 static XColor color;
2334 char *val;
2335 int second_pass=0;
2337 GET_STRING_OR_DEFAULT("Color", val);
2340 again:
2341 if (!wGetColor(scr, val, &color)) {
2342 wwarning(_("could not get color for key \"%s\""),
2343 entry->key);
2344 if (second_pass==0) {
2345 val = WMGetFromPLString(entry->plvalue);
2346 second_pass = 1;
2347 wwarning(_("using default \"%s\" instead"), val);
2348 goto again;
2350 return False;
2353 if (ret)
2354 *ret = &color;
2356 assert(addr==NULL);
2358 if (addr)
2359 *(unsigned long*)addr = pixel;
2362 return True;
2367 static int
2368 getKeybind(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2369 void **ret)
2371 static WShortKey shortcut;
2372 KeySym ksym;
2373 char *val;
2374 char *k;
2375 char buf[128], *b;
2378 GET_STRING_OR_DEFAULT("Key spec", val);
2380 if (!val || strcasecmp(val, "NONE")==0) {
2381 shortcut.keycode = 0;
2382 shortcut.modifier = 0;
2383 if (ret)
2384 *ret = &shortcut;
2385 return True;
2388 strcpy(buf, val);
2390 b = (char*)buf;
2392 /* get modifiers */
2393 shortcut.modifier = 0;
2394 while ((k = strchr(b, '+'))!=NULL) {
2395 int mod;
2397 *k = 0;
2398 mod = wXModifierFromKey(b);
2399 if (mod<0) {
2400 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2401 return False;
2403 shortcut.modifier |= mod;
2405 b = k+1;
2408 /* get key */
2409 ksym = XStringToKeysym(b);
2411 if (ksym==NoSymbol) {
2412 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2413 val);
2414 return False;
2417 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2418 if (shortcut.keycode==0) {
2419 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2420 return False;
2423 if (ret)
2424 *ret = &shortcut;
2426 return True;
2430 static int
2431 getModMask(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2432 void **ret)
2434 static unsigned int mask;
2435 char *str;
2437 GET_STRING_OR_DEFAULT("Modifier Key", str);
2439 if (!str)
2440 return False;
2442 mask = wXModifierFromKey(str);
2443 if (mask < 0) {
2444 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2445 mask = 0;
2446 return False;
2449 if (addr)
2450 *(unsigned int*)addr = mask;
2452 if (ret)
2453 *ret = &mask;
2455 return True;
2459 #ifdef NEWSTUFF
2460 static int
2461 getRImages(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2462 void *addr, void **ret)
2464 unsigned int mask;
2465 char *str;
2466 RImage *image;
2467 int i, n;
2468 int w, h;
2470 GET_STRING_OR_DEFAULT("Image File Path", str);
2471 if (!str)
2472 return False;
2474 image = RLoadImage(scr->rcontext, str, 0);
2475 if (!image) {
2476 wwarning(_("could not load image in option %s: %s"), entry->key,
2477 RMessageForError(RErrorCode));
2478 return False;
2481 if (*(RImage**)addr) {
2482 RReleaseImage(*(RImage**)addr);
2484 if (addr)
2485 *(RImage**)addr = image;
2487 assert(ret == NULL);
2489 if (ret)
2490 *(RImage**)ret = image;
2493 return True;
2495 #endif
2497 # include <X11/cursorfont.h>
2498 typedef struct
2500 char *name;
2501 int id;
2502 } WCursorLookup;
2504 #define CURSOR_ID_NONE (XC_num_glyphs)
2506 static WCursorLookup cursor_table[] =
2508 { "X_cursor", XC_X_cursor },
2509 { "arrow", XC_arrow },
2510 { "based_arrow_down", XC_based_arrow_down },
2511 { "based_arrow_up", XC_based_arrow_up },
2512 { "boat", XC_boat },
2513 { "bogosity", XC_bogosity },
2514 { "bottom_left_corner", XC_bottom_left_corner },
2515 { "bottom_right_corner", XC_bottom_right_corner },
2516 { "bottom_side", XC_bottom_side },
2517 { "bottom_tee", XC_bottom_tee },
2518 { "box_spiral", XC_box_spiral },
2519 { "center_ptr", XC_center_ptr },
2520 { "circle", XC_circle },
2521 { "clock", XC_clock },
2522 { "coffee_mug", XC_coffee_mug },
2523 { "cross", XC_cross },
2524 { "cross_reverse", XC_cross_reverse },
2525 { "crosshair", XC_crosshair },
2526 { "diamond_cross", XC_diamond_cross },
2527 { "dot", XC_dot },
2528 { "dotbox", XC_dotbox },
2529 { "double_arrow", XC_double_arrow },
2530 { "draft_large", XC_draft_large },
2531 { "draft_small", XC_draft_small },
2532 { "draped_box", XC_draped_box },
2533 { "exchange", XC_exchange },
2534 { "fleur", XC_fleur },
2535 { "gobbler", XC_gobbler },
2536 { "gumby", XC_gumby },
2537 { "hand1", XC_hand1 },
2538 { "hand2", XC_hand2 },
2539 { "heart", XC_heart },
2540 { "icon", XC_icon },
2541 { "iron_cross", XC_iron_cross },
2542 { "left_ptr", XC_left_ptr },
2543 { "left_side", XC_left_side },
2544 { "left_tee", XC_left_tee },
2545 { "leftbutton", XC_leftbutton },
2546 { "ll_angle", XC_ll_angle },
2547 { "lr_angle", XC_lr_angle },
2548 { "man", XC_man },
2549 { "middlebutton", XC_middlebutton },
2550 { "mouse", XC_mouse },
2551 { "pencil", XC_pencil },
2552 { "pirate", XC_pirate },
2553 { "plus", XC_plus },
2554 { "question_arrow", XC_question_arrow },
2555 { "right_ptr", XC_right_ptr },
2556 { "right_side", XC_right_side },
2557 { "right_tee", XC_right_tee },
2558 { "rightbutton", XC_rightbutton },
2559 { "rtl_logo", XC_rtl_logo },
2560 { "sailboat", XC_sailboat },
2561 { "sb_down_arrow", XC_sb_down_arrow },
2562 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2563 { "sb_left_arrow", XC_sb_left_arrow },
2564 { "sb_right_arrow", XC_sb_right_arrow },
2565 { "sb_up_arrow", XC_sb_up_arrow },
2566 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2567 { "shuttle", XC_shuttle },
2568 { "sizing", XC_sizing },
2569 { "spider", XC_spider },
2570 { "spraycan", XC_spraycan },
2571 { "star", XC_star },
2572 { "target", XC_target },
2573 { "tcross", XC_tcross },
2574 { "top_left_arrow", XC_top_left_arrow },
2575 { "top_left_corner", XC_top_left_corner },
2576 { "top_right_corner", XC_top_right_corner },
2577 { "top_side", XC_top_side },
2578 { "top_tee", XC_top_tee },
2579 { "trek", XC_trek },
2580 { "ul_angle", XC_ul_angle },
2581 { "umbrella", XC_umbrella },
2582 { "ur_angle", XC_ur_angle },
2583 { "watch", XC_watch },
2584 { "xterm", XC_xterm },
2585 { NULL, CURSOR_ID_NONE }
2588 static void
2589 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2591 switch(status) {
2592 case BitmapOpenFailed:
2593 wwarning(_("failed to open bitmap file \"%s\""), filename);
2594 break;
2595 case BitmapFileInvalid:
2596 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2597 break;
2598 case BitmapNoMemory:
2599 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2600 break;
2601 case BitmapSuccess:
2602 XFreePixmap(dpy, bitmap);
2603 break;
2608 * (none)
2609 * (builtin, <cursor_name>)
2610 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2612 static int
2613 parse_cursor(WScreen *scr, WMPropList *pl, Cursor *cursor)
2615 WMPropList *elem;
2616 char *val;
2617 int nelem;
2618 int status = 0;
2620 nelem = WMGetPropListItemCount(pl);
2621 if (nelem < 1) {
2622 return(status);
2624 elem = WMGetFromPLArray(pl, 0);
2625 if (!elem || !WMIsPLString(elem)) {
2626 return(status);
2628 val = WMGetFromPLString(elem);
2630 if (0 == strcasecmp(val, "none")) {
2631 status = 1;
2632 *cursor = None;
2633 } else if (0 == strcasecmp(val, "builtin")) {
2634 int i;
2635 int cursor_id = CURSOR_ID_NONE;
2637 if (2 != nelem) {
2638 wwarning(_("bad number of arguments in cursor specification"));
2639 return(status);
2641 elem = WMGetFromPLArray(pl, 1);
2642 if (!elem || !WMIsPLString(elem)) {
2643 return(status);
2645 val = WMGetFromPLString(elem);
2647 for (i = 0; NULL != cursor_table[i].name; i++) {
2648 if (0 == strcasecmp(val, cursor_table[i].name)) {
2649 cursor_id = cursor_table[i].id;
2650 break;
2653 if (CURSOR_ID_NONE == cursor_id) {
2654 wwarning(_("unknown builtin cursor name \"%s\""), val);
2655 } else {
2656 *cursor = XCreateFontCursor(dpy, cursor_id);
2657 status = 1;
2659 } else if (0 == strcasecmp(val, "bitmap")) {
2660 char *bitmap_name;
2661 char *mask_name;
2662 int bitmap_status;
2663 int mask_status;
2664 Pixmap bitmap;
2665 Pixmap mask;
2666 unsigned int w, h;
2667 int x, y;
2668 XColor fg, bg;
2670 if (3 != nelem) {
2671 wwarning(_("bad number of arguments in cursor specification"));
2672 return(status);
2674 elem = WMGetFromPLArray(pl, 1);
2675 if (!elem || !WMIsPLString(elem)) {
2676 return(status);
2678 val = WMGetFromPLString(elem);
2679 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2680 if (!bitmap_name) {
2681 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2682 return(status);
2684 elem = WMGetFromPLArray(pl, 2);
2685 if (!elem || !WMIsPLString(elem)) {
2686 wfree(bitmap_name);
2687 return(status);
2689 val = WMGetFromPLString(elem);
2690 mask_name = FindImage(wPreferences.pixmap_path, val);
2691 if (!mask_name) {
2692 wfree(bitmap_name);
2693 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2694 return(status);
2696 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2697 &mask, &x, &y);
2698 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2699 &bitmap, &x, &y);
2700 if ((BitmapSuccess == bitmap_status) &&
2701 (BitmapSuccess == mask_status)) {
2702 fg.pixel = scr->black_pixel;
2703 bg.pixel = scr->white_pixel;
2704 XQueryColor(dpy, scr->w_colormap, &fg);
2705 XQueryColor(dpy, scr->w_colormap, &bg);
2706 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2707 status = 1;
2709 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2710 check_bitmap_status(mask_status, mask_name, mask);
2711 wfree(bitmap_name);
2712 wfree(mask_name);
2714 return(status);
2718 static int
2719 getCursor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2720 void **ret)
2722 static Cursor cursor;
2723 int status;
2724 int changed = 0;
2726 again:
2727 if (!WMIsPLArray(value)) {
2728 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2729 entry->key, "cursor specification");
2730 if (!changed) {
2731 value = entry->plvalue;
2732 changed = 1;
2733 wwarning(_("using default \"%s\" instead"), entry->default_value);
2734 goto again;
2736 return(False);
2738 status = parse_cursor(scr, value, &cursor);
2739 if (!status) {
2740 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2741 if (!changed) {
2742 value = entry->plvalue;
2743 changed = 1;
2744 wwarning(_("using default \"%s\" instead"), entry->default_value);
2745 goto again;
2747 return(False);
2749 if (ret) {
2750 *ret = &cursor;
2752 if (addr) {
2753 *(Cursor *)addr = cursor;
2755 return(True);
2757 #undef CURSOR_ID_NONE
2760 /* ---------------- value setting functions --------------- */
2761 static int
2762 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2764 return REFRESH_WINDOW_TITLE_COLOR;
2767 static int
2768 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2770 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2773 static int
2774 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2776 switch (which) {
2777 case WM_DOCK:
2778 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2779 break;
2780 case WM_CLIP:
2781 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2782 break;
2783 default:
2784 break;
2786 return 0;
2790 static int
2791 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2793 if (scr->workspaces) {
2794 wWorkspaceForceChange(scr, scr->current_workspace);
2795 wArrangeIcons(scr, False);
2797 return 0;
2800 #if not_used
2801 static int
2802 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2804 if (*value <= 0)
2805 *(int*)foo = 1;
2807 return 0;
2809 #endif
2813 static int
2814 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2816 Pixmap pixmap;
2817 RImage *img;
2818 int reset = 0;
2820 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2821 wPreferences.icon_size,
2822 ((*texture)->any.type & WREL_BORDER_MASK)
2823 ? WREL_ICON : WREL_FLAT);
2824 if (!img) {
2825 wwarning(_("could not render texture for icon background"));
2826 if (!entry->addr)
2827 wTextureDestroy(scr, *texture);
2828 return 0;
2830 RConvertImage(scr->rcontext, img, &pixmap);
2832 if (scr->icon_tile) {
2833 reset = 1;
2834 RReleaseImage(scr->icon_tile);
2835 XFreePixmap(dpy, scr->icon_tile_pixmap);
2838 scr->icon_tile = img;
2841 /* put the icon in the noticeboard hint */
2842 PropSetIconTileHint(scr, img);
2845 if (!wPreferences.flags.noclip) {
2846 if (scr->clip_tile) {
2847 RReleaseImage(scr->clip_tile);
2849 scr->clip_tile = wClipMakeTile(scr, img);
2852 scr->icon_tile_pixmap = pixmap;
2854 if (scr->def_icon_pixmap) {
2855 XFreePixmap(dpy, scr->def_icon_pixmap);
2856 scr->def_icon_pixmap = None;
2858 if (scr->def_ticon_pixmap) {
2859 XFreePixmap(dpy, scr->def_ticon_pixmap);
2860 scr->def_ticon_pixmap = None;
2863 if (scr->icon_back_texture) {
2864 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2866 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2868 if (scr->clip_balloon)
2869 XSetWindowBackground(dpy, scr->clip_balloon,
2870 (*texture)->any.color.pixel);
2873 * Free the texture as nobody else will use it, nor refer to it.
2875 if (!entry->addr)
2876 wTextureDestroy(scr, *texture);
2878 return (reset ? REFRESH_ICON_TILE : 0);
2883 static int
2884 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2886 if (scr->title_font) {
2887 WMReleaseFont(scr->title_font);
2889 scr->title_font = font;
2891 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2895 static int
2896 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2898 if (scr->menu_title_font) {
2899 WMReleaseFont(scr->menu_title_font);
2902 scr->menu_title_font = font;
2904 return REFRESH_MENU_TITLE_FONT;
2908 static int
2909 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2911 if (scr->menu_entry_font) {
2912 WMReleaseFont(scr->menu_entry_font);
2914 scr->menu_entry_font = font;
2916 return REFRESH_MENU_FONT;
2921 static int
2922 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2924 if (scr->icon_title_font) {
2925 WMReleaseFont(scr->icon_title_font);
2928 scr->icon_title_font = font;
2930 return REFRESH_ICON_FONT;
2934 static int
2935 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2937 if (scr->clip_title_font) {
2938 WMReleaseFont(scr->clip_title_font);
2941 scr->clip_title_font = font;
2943 return REFRESH_ICON_FONT;
2947 static int
2948 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2950 if (scr->workspace_name_font) {
2951 WMReleaseFont(scr->workspace_name_font);
2954 scr->workspace_name_font = font;
2956 return 0;
2960 static int
2961 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2963 if (scr->select_color)
2964 WMReleaseColor(scr->select_color);
2966 scr->select_color =
2967 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
2968 color->blue, True);
2970 wFreeColor(scr, color->pixel);
2972 return REFRESH_MENU_COLOR;
2976 static int
2977 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2979 if (scr->select_text_color)
2980 WMReleaseColor(scr->select_text_color);
2982 scr->select_text_color =
2983 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
2984 color->blue, True);
2986 wFreeColor(scr, color->pixel);
2988 return REFRESH_MENU_COLOR;
2992 static int
2993 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2995 if (scr->clip_title_color[index])
2996 WMReleaseColor(scr->clip_title_color[index]);
2997 scr->clip_title_color[index] = WMCreateRGBColor(scr->wmscreen, color->red,
2998 color->green, color->blue,
2999 True);
3000 #ifdef GRADIENT_CLIP_ARROW
3001 if (index == CLIP_NORMAL) {
3002 RImage *image;
3003 RColor color1, color2;
3004 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3005 int as = pt - 15; /* 15 = 5+5+5 */
3007 FREE_PIXMAP(scr->clip_arrow_gradient);
3009 color1.red = (color->red >> 8)*6/10;
3010 color1.green = (color->green >> 8)*6/10;
3011 color1.blue = (color->blue >> 8)*6/10;
3013 color2.red = WMIN((color->red >> 8)*20/10, 255);
3014 color2.green = WMIN((color->green >> 8)*20/10, 255);
3015 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3017 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3018 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3019 RReleaseImage(image);
3021 #endif /* GRADIENT_CLIP_ARROW */
3023 wFreeColor(scr, color->pixel);
3025 return REFRESH_ICON_TITLE_COLOR;
3029 static int
3030 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3032 if (scr->window_title_color[index])
3033 WMReleaseColor(scr->window_title_color[index]);
3035 scr->window_title_color[index] =
3036 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue,
3037 True);
3039 wFreeColor(scr, color->pixel);
3041 return REFRESH_WINDOW_TITLE_COLOR;
3045 static int
3046 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3048 if (scr->menu_title_color[0])
3049 WMReleaseColor(scr->menu_title_color[0]);
3051 scr->menu_title_color[0] =
3052 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3053 color->blue, True);
3055 wFreeColor(scr, color->pixel);
3057 return REFRESH_MENU_TITLE_COLOR;
3061 static int
3062 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3064 if (scr->mtext_color)
3065 WMReleaseColor(scr->mtext_color);
3067 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3068 color->green, color->blue, True);
3070 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3071 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3072 } else {
3073 WMSetColorAlpha(scr->dtext_color, 0xffff);
3076 wFreeColor(scr, color->pixel);
3078 return REFRESH_MENU_COLOR;
3082 static int
3083 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3085 if (scr->dtext_color)
3086 WMReleaseColor(scr->dtext_color);
3088 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3089 color->green, color->blue, True);
3091 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3092 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3093 } else {
3094 WMSetColorAlpha(scr->dtext_color, 0xffff);
3097 wFreeColor(scr, color->pixel);
3099 return REFRESH_MENU_COLOR;
3103 static int
3104 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3106 if (scr->icon_title_color)
3107 WMReleaseColor(scr->icon_title_color);
3108 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red,
3109 color->green, color->blue,
3110 True);
3112 wFreeColor(scr, color->pixel);
3114 return REFRESH_ICON_TITLE_COLOR;
3118 static int
3119 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3121 if (scr->icon_title_texture) {
3122 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3124 // ?? why is this necessary? color was already parsed and alloced
3125 XQueryColor (dpy, scr->w_colormap, color);
3126 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3128 return REFRESH_ICON_TITLE_BACK;
3132 static void
3133 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3135 close(scr->helper_fd);
3136 scr->helper_fd = 0;
3137 scr->helper_pid = 0;
3138 scr->flags.backimage_helper_launched = 0;
3142 static int
3143 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3144 void *bar)
3146 WMPropList *val;
3147 char *str;
3148 int i;
3150 if (scr->flags.backimage_helper_launched) {
3151 if (WMGetPropListItemCount(value)==0) {
3152 SendHelperMessage(scr, 'C', 0, NULL);
3153 SendHelperMessage(scr, 'K', 0, NULL);
3155 WMReleasePropList(value);
3156 return 0;
3158 } else {
3159 pid_t pid;
3160 int filedes[2];
3162 if (WMGetPropListItemCount(value) == 0)
3163 return 0;
3165 if (pipe(filedes) < 0) {
3166 wsyserror("pipe() failed:can't set workspace specific background image");
3168 WMReleasePropList(value);
3169 return 0;
3172 pid = fork();
3173 if (pid < 0) {
3174 wsyserror("fork() failed:can't set workspace specific background image");
3175 if (close(filedes[0]) < 0)
3176 wsyserror("could not close pipe");
3177 if (close(filedes[1]) < 0)
3178 wsyserror("could not close pipe");
3180 } else if (pid == 0) {
3181 char *dither;
3183 SetupEnvironment(scr);
3185 if (close(0) < 0)
3186 wsyserror("could not close pipe");
3187 if (dup(filedes[0]) < 0) {
3188 wsyserror("dup() failed:can't set workspace specific background image");
3190 dither = wPreferences.no_dithering ? "-m" : "-d";
3191 if (wPreferences.smooth_workspace_back)
3192 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3193 else
3194 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3195 wsyserror("could not execute wmsetbg");
3196 exit(1);
3197 } else {
3199 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3200 wsyserror("error setting close-on-exec flag");
3202 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3203 wsyserror("error setting close-on-exec flag");
3206 scr->helper_fd = filedes[1];
3207 scr->helper_pid = pid;
3208 scr->flags.backimage_helper_launched = 1;
3210 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3212 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3217 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3218 val = WMGetFromPLArray(value, i);
3219 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val)>0) {
3220 str = WMGetPropListDescription(val, False);
3222 SendHelperMessage(scr, 'S', i+1, str);
3224 wfree(str);
3225 } else {
3226 SendHelperMessage(scr, 'U', i+1, NULL);
3229 sleep(1);
3231 WMReleasePropList(value);
3232 return 0;
3236 static int
3237 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3238 void *bar)
3240 if (scr->flags.backimage_helper_launched) {
3241 char *str;
3243 if (WMGetPropListItemCount(value)==0) {
3244 SendHelperMessage(scr, 'U', 0, NULL);
3245 } else {
3246 /* set the default workspace background to this one */
3247 str = WMGetPropListDescription(value, False);
3248 if (str) {
3249 SendHelperMessage(scr, 'S', 0, str);
3250 wfree(str);
3251 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3252 } else {
3253 SendHelperMessage(scr, 'U', 0, NULL);
3256 } else if (WMGetPropListItemCount(value) > 0) {
3257 char *command;
3258 char *text;
3259 char *dither;
3260 int len;
3262 SetupEnvironment(scr);
3263 text = WMGetPropListDescription(value, False);
3264 len = strlen(text)+40;
3265 command = wmalloc(len);
3266 dither = wPreferences.no_dithering ? "-m" : "-d";
3267 if (wPreferences.smooth_workspace_back)
3268 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3269 else
3270 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3271 wfree(text);
3272 system(command);
3273 wfree(command);
3275 WMReleasePropList(value);
3277 return 0;
3281 static int
3282 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3284 if (scr->widget_texture) {
3285 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3287 scr->widget_texture = *(WTexSolid**)texture;
3289 return 0;
3293 static int
3294 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3296 if (scr->window_title_texture[WS_FOCUSED]) {
3297 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3299 scr->window_title_texture[WS_FOCUSED] = *texture;
3301 return REFRESH_WINDOW_TEXTURES;
3305 static int
3306 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3308 if (scr->window_title_texture[WS_PFOCUSED]) {
3309 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3311 scr->window_title_texture[WS_PFOCUSED] = *texture;
3313 return REFRESH_WINDOW_TEXTURES;
3317 static int
3318 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3320 if (scr->window_title_texture[WS_UNFOCUSED]) {
3321 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3323 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3325 return REFRESH_WINDOW_TEXTURES;
3329 static int
3330 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3332 if (scr->resizebar_texture[0]) {
3333 wTextureDestroy(scr, scr->resizebar_texture[0]);
3335 scr->resizebar_texture[0] = *texture;
3337 return REFRESH_WINDOW_TEXTURES;
3341 static int
3342 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3344 if (scr->menu_title_texture[0]) {
3345 wTextureDestroy(scr, scr->menu_title_texture[0]);
3347 scr->menu_title_texture[0] = *texture;
3349 return REFRESH_MENU_TITLE_TEXTURE;
3353 static int
3354 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3356 if (scr->menu_item_texture) {
3357 wTextureDestroy(scr, scr->menu_item_texture);
3358 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3360 scr->menu_item_texture = *texture;
3362 scr->menu_item_auxtexture
3363 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3365 return REFRESH_MENU_TEXTURE;
3369 static int
3370 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3372 WWindow *wwin;
3373 wKeyBindings[index] = *shortcut;
3375 wwin = scr->focused_window;
3377 while (wwin!=NULL) {
3378 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3380 if (!WFLAGP(wwin, no_bind_keys)) {
3381 wWindowSetKeyGrabs(wwin);
3383 wwin = wwin->prev;
3386 return 0;
3390 static int
3391 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3393 wArrangeIcons(scr, True);
3395 return 0;
3399 static int
3400 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3402 wScreenUpdateUsableArea(scr);
3404 return 0;
3408 static int
3409 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3411 return REFRESH_MENU_TEXTURE;
3416 static int
3417 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3419 return REFRESH_BUTTON_IMAGES;
3424 * Very ugly kluge.
3425 * Need access to the double click variables, so that all widgets in
3426 * wmaker panels will have the same dbl-click values.
3427 * TODO: figure a better way of dealing with it.
3429 #include <WINGs/WINGsP.h>
3431 static int
3432 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3434 extern _WINGsConfiguration WINGsConfiguration;
3436 if (*value <= 0)
3437 *(int*)foo = 1;
3439 WINGsConfiguration.doubleClickDelay = *value;
3441 return 0;
3445 #if 0
3446 static int
3447 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3449 extern _WINGsConfiguration WINGsConfiguration;
3451 WINGsConfiguration.useMultiByte = *value;
3453 return 0;
3455 #endif
3458 static int
3459 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3461 if (wCursor[index] != None) {
3462 XFreeCursor(dpy, wCursor[index]);
3465 wCursor[index] = *cursor;
3467 if (index==WCUR_ROOT && *cursor!=None) {
3468 XDefineCursor(dpy, scr->root_win, *cursor);
3471 return 0;