- More cleanups for obsoleted xxx_gc's and xxx_pixel's in WScreen
[wmaker-crm.git] / src / defaults.c
blobdf5f351fc832ae8f2ab0873cbc2d9a293534d790
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 <WINGs/WINGsP.h>
56 #include "WindowMaker.h"
57 #include "wcore.h"
58 #include "framewin.h"
59 #include "window.h"
60 #include "texture.h"
61 #include "screen.h"
62 #include "resources.h"
63 #include "defaults.h"
64 #include "keybind.h"
65 #include "xmodifier.h"
66 #include "icon.h"
67 #include "funcs.h"
68 #include "actions.h"
69 #include "dock.h"
70 #include "workspace.h"
71 #include "properties.h"
75 /***** Global *****/
77 extern WDDomain *WDWindowMaker;
78 extern WDDomain *WDWindowAttributes;
79 extern WDDomain *WDRootMenu;
81 extern int wScreenCount;
83 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
84 extern Atom _XA_WINDOWMAKER_ICON_TILE;
87 extern WMPropList *wDomainName;
88 extern WMPropList *wAttributeDomainName;
90 extern WPreferences wPreferences;
92 extern WShortKey wKeyBindings[WKBD_LAST];
94 typedef struct {
95 char *key;
96 char *default_value;
97 void *extra_data;
98 void *addr;
99 int (*convert)();
100 int (*update)();
101 WMPropList *plkey;
102 WMPropList *plvalue; /* default value */
103 } WDefaultEntry;
106 /* used to map strings to integers */
107 typedef struct {
108 char *string;
109 short value;
110 char is_alias;
111 } WOptionEnumeration;
114 /* type converters */
115 static int getBool();
116 static int getInt();
117 static int getCoord();
118 #if 0
119 /* this is not used yet */
120 static int getString();
121 #endif
122 static int getPathList();
123 static int getEnum();
124 static int getTexture();
125 static int getWSBackground();
126 static int getWSSpecificBackground();
127 static int getFont();
128 static int getColor();
129 static int getKeybind();
130 static int getModMask();
131 #ifdef NEWSTUFF
132 static int getRImage();
133 #endif
136 /* value setting functions */
137 static int setJustify();
138 static int setClearance();
139 static int setIfDockPresent();
140 static int setStickyIcons();
142 static int setPositive();
144 static int setWidgetColor();
145 static int setIconTile();
146 static int setWinTitleFont();
147 static int setMenuTitleFont();
148 static int setMenuTextFont();
149 static int setIconTitleFont();
150 static int setIconTitleColor();
151 static int setIconTitleBack();
152 static int setLargeDisplayFont();
153 static int setWTitleColor();
154 static int setFTitleBack();
155 static int setPTitleBack();
156 static int setUTitleBack();
157 static int setResizebarBack();
158 static int setWorkspaceBack();
159 static int setWorkspaceSpecificBack();
160 static int setMenuTitleColor();
161 static int setMenuTextColor();
162 static int setMenuDisabledColor();
163 static int setMenuTitleBack();
164 static int setMenuTextBack();
165 static int setHightlight();
166 static int setHightlightText();
167 static int setKeyGrab();
168 static int setDoubleClick();
169 static int setIconPosition();
171 static int setClipTitleFont();
172 static int setClipTitleColor();
174 static int setMenuStyle();
175 #if 0
176 static int setMultiByte();
177 #endif
178 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
371 #if 0
372 ,{"MultiByteText", "NO", NULL,
373 &wPreferences.multi_byte_text, getBool, setMultiByte
375 #endif
380 WDefaultEntry optionList[] = {
381 /* dynamic options */
382 {"IconPosition", "blh", seIconPositions,
383 &wPreferences.icon_yard, getEnum, setIconPosition
385 {"IconificationStyle", "Zoom", seIconificationStyles,
386 &wPreferences.iconification_style, getEnum, NULL
388 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
389 &wPreferences.mouse_button1, getEnum, NULL
391 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
392 &wPreferences.mouse_button2, getEnum, NULL
394 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
395 &wPreferences.mouse_button3, getEnum, NULL
397 {"MouseWheelAction", "None", seMouseWheelActions,
398 &wPreferences.mouse_wheel, getEnum, NULL
400 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
401 &wPreferences.pixmap_path, getPathList, NULL
403 {"IconPath", DEF_ICON_PATHS, NULL,
404 &wPreferences.icon_path, getPathList, NULL
406 {"ColormapMode", "auto", seColormapModes,
407 &wPreferences.colormap_mode, getEnum, NULL
409 {"AutoFocus", "NO", NULL,
410 &wPreferences.auto_focus, getBool, NULL
412 {"RaiseDelay", "0", NULL,
413 &wPreferences.raise_delay, getInt, NULL
415 {"WindozeCycling", "NO", NULL,
416 &wPreferences.windows_cycling,getBool, NULL
418 {"CirculateRaise", "NO", NULL,
419 &wPreferences.circ_raise, getBool, NULL
421 {"Superfluous", "NO", NULL,
422 &wPreferences.superfluous, getBool, NULL
424 {"AdvanceToNewWorkspace", "NO", NULL,
425 &wPreferences.ws_advance, getBool, NULL
427 {"CycleWorkspaces", "NO", NULL,
428 &wPreferences.ws_cycle, getBool, NULL
430 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
431 &wPreferences.workspace_name_display_position, getEnum, NULL
433 {"WorkspaceBorder", "None", seWorkspaceBorder,
434 &wPreferences.workspace_border_position, getEnum, updateUsableArea
436 {"WorkspaceBorderSize", "0", NULL,
437 &wPreferences.workspace_border_size, getInt, updateUsableArea
439 #ifdef VIRTUAL_DESKTOP
440 {"VirtualEdgeThickness", "1", NULL,
441 &wPreferences.vedge_thickness, getInt, NULL
443 {"VirtualEdgeExtendSpace", "0", NULL,
444 &wPreferences.vedge_bordersize, getInt, NULL
446 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
447 &wPreferences.vedge_hscrollspeed, getInt, NULL
449 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
450 &wPreferences.vedge_vscrollspeed, getInt, NULL
452 {"VirtualEdgeMaximumWidth", "3000", NULL,
453 &wPreferences.vedge_maxwidth, getInt, NULL
455 {"VirtualEdgeMaximumHeight", "3000", NULL,
456 &wPreferences.vedge_maxheight, getInt, NULL
458 #endif
459 {"StickyIcons", "NO", NULL,
460 &wPreferences.sticky_icons, getBool, setStickyIcons
462 {"SaveSessionOnExit", "NO", NULL,
463 &wPreferences.save_session_on_exit, getBool, NULL
465 {"WrapMenus", "NO", NULL,
466 &wPreferences.wrap_menus, getBool, NULL
468 {"ScrollableMenus", "NO", NULL,
469 &wPreferences.scrollable_menus, getBool, NULL
471 {"MenuScrollSpeed", "medium", seSpeeds,
472 &wPreferences.menu_scroll_speed, getEnum, NULL
474 {"IconSlideSpeed", "medium", seSpeeds,
475 &wPreferences.icon_slide_speed, getEnum, NULL
477 {"ShadeSpeed", "medium", seSpeeds,
478 &wPreferences.shade_speed, getEnum, NULL
480 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
481 &wPreferences.dblclick_time, getInt, setDoubleClick,
483 {"AlignSubmenus", "NO", NULL,
484 &wPreferences.align_menus, getBool, NULL
486 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
487 &wPreferences.open_transients_with_parent, getBool, NULL
489 {"WindowPlacement", "auto", sePlacements,
490 &wPreferences.window_placement, getEnum, NULL
492 {"IgnoreFocusClick","NO", NULL,
493 &wPreferences.ignore_focus_click, getBool, NULL
495 {"UseSaveUnders", "NO", NULL,
496 &wPreferences.use_saveunders, getBool, NULL
498 {"OpaqueMove", "NO", NULL,
499 &wPreferences.opaque_move, getBool, NULL
501 {"DisableSound", "NO", NULL,
502 &wPreferences.no_sound, getBool, NULL
504 {"DisableAnimations", "NO", NULL,
505 &wPreferences.no_animations, getBool, NULL
507 {"DontLinkWorkspaces","NO", NULL,
508 &wPreferences.no_autowrap, getBool, NULL
510 {"AutoArrangeIcons", "NO", NULL,
511 &wPreferences.auto_arrange_icons, getBool, NULL
513 {"NoWindowOverDock", "NO", NULL,
514 &wPreferences.no_window_over_dock, getBool, updateUsableArea
516 {"NoWindowOverIcons", "NO", NULL,
517 &wPreferences.no_window_over_icons, getBool, updateUsableArea
519 {"WindowPlaceOrigin", "(0, 0)", NULL,
520 &wPreferences.window_place_origin, getCoord, NULL
522 {"ResizeDisplay", "corner", seGeomDisplays,
523 &wPreferences.size_display, getEnum, NULL
525 {"MoveDisplay", "corner", seGeomDisplays,
526 &wPreferences.move_display, getEnum, NULL
528 {"DontConfirmKill", "NO", NULL,
529 &wPreferences.dont_confirm_kill, getBool,NULL
531 {"WindowTitleBalloons", "NO", NULL,
532 &wPreferences.window_balloon, getBool, NULL
534 {"MiniwindowTitleBalloons", "NO", NULL,
535 &wPreferences.miniwin_balloon,getBool, NULL
537 {"AppIconBalloons", "NO", NULL,
538 &wPreferences.appicon_balloon,getBool, NULL
540 {"HelpBalloons", "NO", NULL,
541 &wPreferences.help_balloon, getBool, NULL
543 {"EdgeResistance", "30", NULL,
544 &wPreferences.edge_resistance,getInt, NULL
546 {"Attraction", "NO", NULL,
547 &wPreferences.attract, getBool, NULL
549 {"DisableBlinking", "NO", NULL,
550 &wPreferences.dont_blink, getBool, NULL
552 /* style options */
553 {"MenuStyle", "normal", seMenuStyles,
554 &wPreferences.menu_style, getEnum, setMenuStyle
556 {"WidgetColor", "(solid, gray)", NULL,
557 NULL, getTexture, setWidgetColor,
559 {"WorkspaceSpecificBack","()", NULL,
560 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
562 /* WorkspaceBack must come after WorkspaceSpecificBack or
563 * WorkspaceBack wont know WorkspaceSpecificBack was also
564 * specified and 2 copies of wmsetbg will be launched */
565 {"WorkspaceBack", "(solid, black)", NULL,
566 NULL, getWSBackground,setWorkspaceBack
568 {"SmoothWorkspaceBack", "NO", NULL,
569 NULL, getBool, NULL
571 {"IconBack", "(solid, gray)", NULL,
572 NULL, getTexture, setIconTile
574 {"TitleJustify", "center", seJustifications,
575 &wPreferences.title_justification, getEnum, setJustify
577 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
578 NULL, getFont, setWinTitleFont,
580 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
581 &wPreferences.window_title_clearance, getInt, setClearance
583 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
584 &wPreferences.menu_title_clearance, getInt, setClearance
586 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
587 &wPreferences.menu_text_clearance, getInt, setClearance
589 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
590 NULL, getFont, setMenuTitleFont
592 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
593 NULL, getFont, setMenuTextFont
595 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
596 NULL, getFont, setIconTitleFont
598 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
599 NULL, getFont, setClipTitleFont
601 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
602 NULL, getFont, setLargeDisplayFont
604 {"HighlightColor", "white", NULL,
605 NULL, getColor, setHightlight
607 {"HighlightTextColor", "black", NULL,
608 NULL, getColor, setHightlightText
610 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
611 NULL, getColor, setClipTitleColor
613 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
614 NULL, getColor, setClipTitleColor
616 {"FTitleColor", "white", (void*)WS_FOCUSED,
617 NULL, getColor, setWTitleColor
619 {"PTitleColor", "white", (void*)WS_PFOCUSED,
620 NULL, getColor, setWTitleColor
622 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
623 NULL, getColor, setWTitleColor
625 {"FTitleBack", "(solid, black)", NULL,
626 NULL, getTexture, setFTitleBack
628 {"PTitleBack", "(solid, \"#616161\")", NULL,
629 NULL, getTexture, setPTitleBack
631 {"UTitleBack", "(solid, gray)", NULL,
632 NULL, getTexture, setUTitleBack
634 {"ResizebarBack", "(solid, gray)", NULL,
635 NULL, getTexture, setResizebarBack
637 {"MenuTitleColor", "white", NULL,
638 NULL, getColor, setMenuTitleColor
640 {"MenuTextColor", "black", NULL,
641 NULL, getColor, setMenuTextColor
643 {"MenuDisabledColor", "\"#616161\"", NULL,
644 NULL, getColor, setMenuDisabledColor
646 {"MenuTitleBack", "(solid, black)", NULL,
647 NULL, getTexture, setMenuTitleBack
649 {"MenuTextBack", "(solid, gray)", NULL,
650 NULL, getTexture, setMenuTextBack
652 {"IconTitleColor", "white", NULL,
653 NULL, getColor, setIconTitleColor
655 {"IconTitleBack", "black", NULL,
656 NULL, getColor, setIconTitleBack
658 /* keybindings */
659 #ifndef LITE
660 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
661 NULL, getKeybind, setKeyGrab
663 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
664 NULL, getKeybind, setKeyGrab
666 #endif /* LITE */
667 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
668 NULL, getKeybind, setKeyGrab
670 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
671 NULL, getKeybind, setKeyGrab
673 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
674 NULL, getKeybind, setKeyGrab
676 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
677 NULL, getKeybind, setKeyGrab
679 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
680 NULL, getKeybind, setKeyGrab
682 {"HideKey", "None", (void*)WKBD_HIDE,
683 NULL, getKeybind, setKeyGrab
685 {"HideOthersKey", "None", (void*)WKBD_HIDE_OTHERS,
686 NULL, getKeybind, setKeyGrab
688 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
689 NULL, getKeybind, setKeyGrab
691 {"CloseKey", "None", (void*)WKBD_CLOSE,
692 NULL, getKeybind, setKeyGrab
694 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
695 NULL, getKeybind, setKeyGrab
697 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
698 NULL, getKeybind, setKeyGrab
700 {"HMaximizeKey", "None", (void*)WKBD_HMAXIMIZE,
701 NULL, getKeybind, setKeyGrab
703 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
704 NULL, getKeybind, setKeyGrab
706 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
707 NULL, getKeybind, setKeyGrab
709 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
710 NULL, getKeybind, setKeyGrab
712 {"ShadeKey", "None", (void*)WKBD_SHADE,
713 NULL, getKeybind, setKeyGrab
715 {"SelectKey", "None", (void*)WKBD_SELECT,
716 NULL, getKeybind, setKeyGrab
718 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
719 NULL, getKeybind, setKeyGrab
721 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
722 NULL, getKeybind, setKeyGrab
724 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
725 NULL, getKeybind, setKeyGrab
727 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
728 NULL, getKeybind, setKeyGrab
730 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
731 NULL, getKeybind, setKeyGrab
733 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
734 NULL, getKeybind, setKeyGrab
736 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
737 NULL, getKeybind, setKeyGrab
739 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
740 NULL, getKeybind, setKeyGrab
742 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
743 NULL, getKeybind, setKeyGrab
745 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
746 NULL, getKeybind, setKeyGrab
748 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
749 NULL, getKeybind, setKeyGrab
751 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
752 NULL, getKeybind, setKeyGrab
754 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
755 NULL, getKeybind, setKeyGrab
757 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
758 NULL, getKeybind, setKeyGrab
760 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
761 NULL, getKeybind, setKeyGrab
763 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
764 NULL, getKeybind, setKeyGrab
766 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
767 NULL, getKeybind, setKeyGrab
769 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
770 NULL, getKeybind, setKeyGrab
772 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
773 NULL, getKeybind, setKeyGrab
775 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
776 NULL, getKeybind, setKeyGrab
778 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
779 NULL, getKeybind, setKeyGrab
781 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
782 NULL, getKeybind, setKeyGrab
784 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
785 NULL, getKeybind, setKeyGrab
787 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
788 NULL, getKeybind, setKeyGrab
790 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
791 NULL, getKeybind, setKeyGrab
793 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
794 NULL, getKeybind, setKeyGrab
796 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
797 NULL, getKeybind, setKeyGrab
800 #ifdef KEEP_XKB_LOCK_STATUS
801 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
802 NULL, getKeybind, setKeyGrab
804 {"KbdModeLock", "NO", NULL,
805 &wPreferences.modelock, getBool, NULL
807 #endif /* KEEP_XKB_LOCK_STATUS */
809 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
810 NULL, getCursor, setCursor
812 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
813 NULL, getCursor, setCursor
815 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
816 NULL, getCursor, setCursor
818 {"ResizeCursor", "(builtin, sizing)", (void*)WCUR_RESIZE,
819 NULL, getCursor, setCursor
821 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
822 (void*)WCUR_TOPLEFTRESIZE,
823 NULL, getCursor, setCursor
825 {"TopRightResizeCursor", "(builtin, top_right_corner)",
826 (void*)WCUR_TOPRIGHTRESIZE,
827 NULL, getCursor, setCursor
829 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
830 (void*)WCUR_BOTTOMLEFTRESIZE,
831 NULL, getCursor, setCursor
833 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
834 (void*)WCUR_BOTTOMRIGHTRESIZE,
835 NULL, getCursor, setCursor
837 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
838 (void*)WCUR_VERTICALRESIZE,
839 NULL, getCursor, setCursor
841 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
842 (void*)WCUR_HORIZONRESIZE,
843 NULL, getCursor, setCursor
845 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
846 NULL, getCursor, setCursor
848 {"QuestionCursor", "(builtin, question_arrow)", (void*)WCUR_QUESTION,
849 NULL, getCursor, setCursor
851 {"TextCursor", "(builtin, xterm)", (void*)WCUR_TEXT,
852 NULL, getCursor, setCursor
854 {"SelectCursor", "(builtin, cross)", (void*)WCUR_SELECT,
855 NULL, getCursor, setCursor
860 #if 0
861 static void rereadDefaults(void);
862 #endif
864 #if 0
865 static void
866 rereadDefaults(void)
868 /* must defer the update because accessing X data from a
869 * signal handler can mess up Xlib */
872 #endif
874 static void
875 initDefaults()
877 int i;
878 WDefaultEntry *entry;
880 WMPLSetCaseSensitive(False);
882 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
883 entry = &optionList[i];
885 entry->plkey = WMCreatePLString(entry->key);
886 if (entry->default_value)
887 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
888 else
889 entry->plvalue = NULL;
892 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
893 entry = &staticOptionList[i];
895 entry->plkey = WMCreatePLString(entry->key);
896 if (entry->default_value)
897 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
898 else
899 entry->plvalue = NULL;
903 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
904 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
906 PLRegister(wDomainName, rereadDefaults);
907 PLRegister(wAttributeDomainName, rereadDefaults);
912 static WMPropList*
913 readGlobalDomain(char *domainName, Bool requireDictionary)
915 WMPropList *globalDict = NULL;
916 char path[PATH_MAX];
917 struct stat stbuf;
919 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domainName);
920 if (stat(path, &stbuf)>=0) {
921 globalDict = WMReadPropListFromFile(path);
922 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
923 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
924 domainName, path);
925 WMReleasePropList(globalDict);
926 globalDict = NULL;
927 } else if (!globalDict) {
928 wwarning(_("could not load domain %s from global defaults database"),
929 domainName);
933 return globalDict;
937 #if 0
938 WMPropList*
939 wDefaultsInit(int screen_number)
941 static int defaults_inited = 0;
942 WMPropList *dict;
944 if (!defaults_inited) {
945 initDefaults();
948 dict = PLGetDomain(wDomainName);
949 if (!dict) {
950 wwarning(_("could not read domain \"%s\" from defaults database"),
951 WMGetFromPLString(wDomainName));
954 return dict;
956 #endif
959 void
960 wDefaultsDestroyDomain(WDDomain *domain)
962 if (domain->dictionary)
963 WMReleasePropList(domain->dictionary);
964 wfree(domain->path);
965 wfree(domain);
969 WDDomain*
970 wDefaultsInitDomain(char *domain, Bool requireDictionary)
972 WDDomain *db;
973 struct stat stbuf;
974 static int inited = 0;
975 char path[PATH_MAX];
976 char *the_path;
977 WMPropList *shared_dict=NULL;
979 if (!inited) {
980 inited = 1;
981 initDefaults();
984 db = wmalloc(sizeof(WDDomain));
985 memset(db, 0, sizeof(WDDomain));
986 db->domain_name = domain;
987 db->path = wdefaultspathfordomain(domain);
988 the_path = db->path;
990 if (the_path && stat(the_path, &stbuf)>=0) {
991 db->dictionary = WMReadPropListFromFile(the_path);
992 if (db->dictionary) {
993 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
994 WMReleasePropList(db->dictionary);
995 db->dictionary = NULL;
996 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
997 domain, the_path);
999 db->timestamp = stbuf.st_mtime;
1000 } else {
1001 wwarning(_("could not load domain %s from user defaults database"),
1002 domain);
1006 /* global system dictionary */
1007 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
1008 if (stat(path, &stbuf)>=0) {
1009 shared_dict = WMReadPropListFromFile(path);
1010 if (shared_dict) {
1011 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
1012 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1013 domain, path);
1014 WMReleasePropList(shared_dict);
1015 shared_dict = NULL;
1016 } else {
1017 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
1018 WMIsPLDictionary(db->dictionary)) {
1019 WMMergePLDictionaries(shared_dict, db->dictionary, True);
1020 WMReleasePropList(db->dictionary);
1021 db->dictionary = shared_dict;
1022 if (stbuf.st_mtime > db->timestamp)
1023 db->timestamp = stbuf.st_mtime;
1024 } else if (!db->dictionary) {
1025 db->dictionary = shared_dict;
1026 if (stbuf.st_mtime > db->timestamp)
1027 db->timestamp = stbuf.st_mtime;
1030 } else {
1031 wwarning(_("could not load domain %s from global defaults database (%s)"),
1032 domain, path);
1036 return db;
1040 void
1041 wReadStaticDefaults(WMPropList *dict)
1043 WMPropList *plvalue;
1044 WDefaultEntry *entry;
1045 int i;
1046 void *tdata;
1049 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1050 entry = &staticOptionList[i];
1052 if (dict)
1053 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
1054 else
1055 plvalue = NULL;
1057 if (!plvalue) {
1058 /* no default in the DB. Use builtin default */
1059 plvalue = entry->plvalue;
1062 if (plvalue) {
1063 /* convert data */
1064 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1065 if (entry->update) {
1066 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1073 void
1074 wDefaultsCheckDomains(void *foo)
1076 WScreen *scr;
1077 struct stat stbuf;
1078 WMPropList *shared_dict = NULL;
1079 WMPropList *dict;
1080 int i;
1082 #ifdef HEARTBEAT
1083 puts("Checking domains...");
1084 #endif
1085 if (stat(WDWindowMaker->path, &stbuf)>=0
1086 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1087 #ifdef HEARTBEAT
1088 puts("Checking WindowMaker domain");
1089 #endif
1090 WDWindowMaker->timestamp = stbuf.st_mtime;
1092 /* global dictionary */
1093 shared_dict = readGlobalDomain("WindowMaker", True);
1094 /* user dictionary */
1095 dict = WMReadPropListFromFile(WDWindowMaker->path);
1096 if (dict) {
1097 if (!WMIsPLDictionary(dict)) {
1098 WMReleasePropList(dict);
1099 dict = NULL;
1100 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1101 "WindowMaker", WDWindowMaker->path);
1102 } else {
1103 if (shared_dict) {
1104 WMMergePLDictionaries(shared_dict, dict, True);
1105 WMReleasePropList(dict);
1106 dict = shared_dict;
1107 shared_dict = NULL;
1109 for (i=0; i<wScreenCount; i++) {
1110 scr = wScreenWithNumber(i);
1111 if (scr)
1112 wReadDefaults(scr, dict);
1114 if (WDWindowMaker->dictionary) {
1115 WMReleasePropList(WDWindowMaker->dictionary);
1117 WDWindowMaker->dictionary = dict;
1119 } else {
1120 wwarning(_("could not load domain %s from user defaults database"),
1121 "WindowMaker");
1123 if (shared_dict) {
1124 WMReleasePropList(shared_dict);
1128 if (stat(WDWindowAttributes->path, &stbuf)>=0
1129 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1130 #ifdef HEARTBEAT
1131 puts("Checking WMWindowAttributes domain");
1132 #endif
1133 /* global dictionary */
1134 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1135 /* user dictionary */
1136 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1137 if (dict) {
1138 if (!WMIsPLDictionary(dict)) {
1139 WMReleasePropList(dict);
1140 dict = NULL;
1141 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1142 "WMWindowAttributes", WDWindowAttributes->path);
1143 } else {
1144 if (shared_dict) {
1145 WMMergePLDictionaries(shared_dict, dict, True);
1146 WMReleasePropList(dict);
1147 dict = shared_dict;
1148 shared_dict = NULL;
1150 if (WDWindowAttributes->dictionary) {
1151 WMReleasePropList(WDWindowAttributes->dictionary);
1153 WDWindowAttributes->dictionary = dict;
1154 for (i=0; i<wScreenCount; i++) {
1155 scr = wScreenWithNumber(i);
1156 if (scr) {
1157 RImage *image;
1159 wDefaultUpdateIcons(scr);
1161 /* Update the panel image if changed */
1162 /* Don't worry. If the image is the same these
1163 * functions will have no performance impact. */
1164 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1166 if (!image) {
1167 wwarning(_("could not load logo image for panels: %s"),
1168 RMessageForError(RErrorCode));
1169 } else {
1170 WMSetApplicationIconImage(scr->wmscreen, image);
1171 RReleaseImage(image);
1176 } else {
1177 wwarning(_("could not load domain %s from user defaults database"),
1178 "WMWindowAttributes");
1180 WDWindowAttributes->timestamp = stbuf.st_mtime;
1181 if (shared_dict) {
1182 WMReleasePropList(shared_dict);
1186 #ifndef LITE
1187 if (stat(WDRootMenu->path, &stbuf)>=0
1188 && WDRootMenu->timestamp < stbuf.st_mtime) {
1189 dict = WMReadPropListFromFile(WDRootMenu->path);
1190 #ifdef HEARTBEAT
1191 puts("Checking WMRootMenu domain");
1192 #endif
1193 if (dict) {
1194 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1195 WMReleasePropList(dict);
1196 dict = NULL;
1197 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1198 "WMRootMenu", WDRootMenu->path);
1199 } else {
1200 if (WDRootMenu->dictionary) {
1201 WMReleasePropList(WDRootMenu->dictionary);
1203 WDRootMenu->dictionary = dict;
1205 } else {
1206 wwarning(_("could not load domain %s from user defaults database"),
1207 "WMRootMenu");
1209 WDRootMenu->timestamp = stbuf.st_mtime;
1211 #endif /* !LITE */
1213 if (!foo)
1214 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1218 void
1219 wReadDefaults(WScreen *scr, WMPropList *new_dict)
1221 WMPropList *plvalue, *old_value;
1222 WDefaultEntry *entry;
1223 int i, must_update;
1224 int update_workspace_back = 0; /* kluge :/ */
1225 int needs_refresh;
1226 void *tdata;
1227 WMPropList *old_dict = (WDWindowMaker->dictionary!=new_dict
1228 ? WDWindowMaker->dictionary : NULL);
1230 must_update = 0;
1232 needs_refresh = 0;
1234 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1235 entry = &optionList[i];
1237 if (new_dict)
1238 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1239 else
1240 plvalue = NULL;
1242 if (!old_dict)
1243 old_value = NULL;
1244 else
1245 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1248 if (!plvalue && !old_value) {
1249 /* no default in the DB. Use builtin default */
1250 plvalue = entry->plvalue;
1251 if (plvalue && new_dict) {
1252 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1253 must_update = 1;
1255 } else if (!plvalue) {
1256 /* value was deleted from DB. Keep current value */
1257 continue;
1258 } else if (!old_value) {
1259 /* set value for the 1st time */
1260 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1261 /* value has changed */
1262 } else {
1264 if (strcmp(entry->key, "WorkspaceBack") == 0
1265 && update_workspace_back
1266 && scr->flags.backimage_helper_launched) {
1267 } else {
1268 /* value was not changed since last time */
1269 continue;
1273 if (plvalue) {
1274 #ifdef DEBUG
1275 printf("Updating %s to %s\n", entry->key,
1276 WMGetPropListDescription(plvalue, False));
1277 #endif
1278 /* convert data */
1279 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1281 * If the WorkspaceSpecificBack data has been changed
1282 * so that the helper will be launched now, we must be
1283 * sure to send the default background texture config
1284 * to the helper.
1286 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1287 && !scr->flags.backimage_helper_launched) {
1288 update_workspace_back = 1;
1290 if (entry->update) {
1291 needs_refresh |=
1292 (*entry->update)(scr, entry, tdata, entry->extra_data);
1298 if (needs_refresh!=0 && !scr->flags.startup) {
1299 int foo;
1301 foo = 0;
1302 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1303 foo |= WTextureSettings;
1304 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1305 foo |= WFontSettings;
1306 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1307 foo |= WColorSettings;
1308 if (foo)
1309 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1310 (void*)foo);
1312 foo = 0;
1313 if (needs_refresh & REFRESH_MENU_TEXTURE)
1314 foo |= WTextureSettings;
1315 if (needs_refresh & REFRESH_MENU_FONT)
1316 foo |= WFontSettings;
1317 if (needs_refresh & REFRESH_MENU_COLOR)
1318 foo |= WColorSettings;
1319 if (foo)
1320 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1321 (void*)foo);
1323 foo = 0;
1324 if (needs_refresh & REFRESH_WINDOW_FONT) {
1325 foo |= WFontSettings;
1327 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1328 foo |= WTextureSettings;
1330 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1331 foo |= WColorSettings;
1333 if (foo)
1334 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1335 (void*)foo);
1337 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1338 foo = 0;
1339 if (needs_refresh & REFRESH_ICON_FONT) {
1340 foo |= WFontSettings;
1342 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1343 foo |= WTextureSettings;
1345 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1346 foo |= WTextureSettings;
1348 if (foo)
1349 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1350 (void*)foo);
1352 if (needs_refresh & REFRESH_ICON_TILE)
1353 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1358 void
1359 wDefaultUpdateIcons(WScreen *scr)
1361 WAppIcon *aicon = scr->app_icon_list;
1362 WWindow *wwin = scr->focused_window;
1363 char *file;
1365 while(aicon) {
1366 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1367 False);
1368 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1369 || (file && !aicon->icon->file)) {
1370 RImage *new_image;
1372 if (aicon->icon->file)
1373 wfree(aicon->icon->file);
1374 aicon->icon->file = wstrdup(file);
1376 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1377 aicon->wm_class);
1378 if (new_image) {
1379 wIconChangeImage(aicon->icon, new_image);
1380 wAppIconPaint(aicon);
1383 aicon = aicon->next;
1386 if (!wPreferences.flags.noclip)
1387 wClipIconPaint(scr->clip_icon);
1389 while (wwin) {
1390 if (wwin->icon && wwin->flags.miniaturized) {
1391 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1392 False);
1393 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1394 || (file && !wwin->icon->file)) {
1395 RImage *new_image;
1397 if (wwin->icon->file)
1398 wfree(wwin->icon->file);
1399 wwin->icon->file = wstrdup(file);
1401 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1402 wwin->wm_class);
1403 if (new_image)
1404 wIconChangeImage(wwin->icon, new_image);
1407 wwin = wwin->prev;
1412 /* --------------------------- Local ----------------------- */
1414 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1415 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1416 entry->key, x); \
1417 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1418 var = entry->default_value;\
1419 } else var = WMGetFromPLString(value)\
1425 static int
1426 string2index(WMPropList *key, WMPropList *val, char *def,
1427 WOptionEnumeration *values)
1429 char *str;
1430 WOptionEnumeration *v;
1431 char buffer[TOTAL_VALUES_LENGTH];
1433 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1434 for (v=values; v->string!=NULL; v++) {
1435 if (strcasecmp(v->string, str)==0)
1436 return v->value;
1440 buffer[0] = 0;
1441 for (v=values; v->string!=NULL; v++) {
1442 if (!v->is_alias) {
1443 if (buffer[0]!=0)
1444 strcat(buffer, ", ");
1445 strcat(buffer, v->string);
1448 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1449 WMGetFromPLString(key), buffer);
1451 if (def) {
1452 return string2index(key, val, NULL, values);
1455 return -1;
1462 * value - is the value in the defaults DB
1463 * addr - is the address to store the data
1464 * ret - is the address to store a pointer to a temporary buffer. ret
1465 * must not be freed and is used by the set functions
1467 static int
1468 getBool(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1469 void **ret)
1471 static char data;
1472 char *val;
1473 int second_pass=0;
1475 GET_STRING_OR_DEFAULT("Boolean", val);
1477 again:
1478 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1479 || strcasecmp(val, "YES")==0) {
1481 data = 1;
1482 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1483 || strcasecmp(val, "NO")==0) {
1484 data = 0;
1485 } else {
1486 int i;
1487 if (sscanf(val, "%i", &i)==1) {
1488 if (i!=0)
1489 data = 1;
1490 else
1491 data = 0;
1492 } else {
1493 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1494 val, entry->key);
1495 if (second_pass==0) {
1496 val = WMGetFromPLString(entry->plvalue);
1497 second_pass = 1;
1498 wwarning(_("using default \"%s\" instead"), val);
1499 goto again;
1501 return False;
1505 if (ret)
1506 *ret = &data;
1508 if (addr) {
1509 *(char*)addr = data;
1512 return True;
1516 static int
1517 getInt(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1518 void **ret)
1520 static int data;
1521 char *val;
1524 GET_STRING_OR_DEFAULT("Integer", val);
1526 if (sscanf(val, "%i", &data)!=1) {
1527 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1528 val, entry->key);
1529 val = WMGetFromPLString(entry->plvalue);
1530 wwarning(_("using default \"%s\" instead"), val);
1531 if (sscanf(val, "%i", &data)!=1) {
1532 return False;
1536 if (ret)
1537 *ret = &data;
1539 if (addr) {
1540 *(int*)addr = data;
1542 return True;
1546 static int
1547 getCoord(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1548 void **ret)
1550 static WCoord data;
1551 char *val_x, *val_y;
1552 int nelem, changed=0;
1553 WMPropList *elem_x, *elem_y;
1555 again:
1556 if (!WMIsPLArray(value)) {
1557 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1558 entry->key, "Coordinate");
1559 if (changed==0) {
1560 value = entry->plvalue;
1561 changed = 1;
1562 wwarning(_("using default \"%s\" instead"), entry->default_value);
1563 goto again;
1565 return False;
1568 nelem = WMGetPropListItemCount(value);
1569 if (nelem != 2) {
1570 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1571 entry->key);
1572 if (changed==0) {
1573 value = entry->plvalue;
1574 changed = 1;
1575 wwarning(_("using default \"%s\" instead"), entry->default_value);
1576 goto again;
1578 return False;
1581 elem_x = WMGetFromPLArray(value, 0);
1582 elem_y = WMGetFromPLArray(value, 1);
1584 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1585 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1586 entry->key);
1587 if (changed==0) {
1588 value = entry->plvalue;
1589 changed = 1;
1590 wwarning(_("using default \"%s\" instead"), entry->default_value);
1591 goto again;
1593 return False;
1596 val_x = WMGetFromPLString(elem_x);
1597 val_y = WMGetFromPLString(elem_y);
1599 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1600 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1601 if (changed==0) {
1602 value = entry->plvalue;
1603 changed = 1;
1604 wwarning(_("using default \"%s\" instead"), entry->default_value);
1605 goto again;
1607 return False;
1610 if (data.x < 0)
1611 data.x = 0;
1612 else if (data.x > scr->scr_width/3)
1613 data.x = scr->scr_width/3;
1614 if (data.y < 0)
1615 data.y = 0;
1616 else if (data.y > scr->scr_height/3)
1617 data.y = scr->scr_height/3;
1619 if (ret)
1620 *ret = &data;
1622 if (addr) {
1623 *(WCoord*)addr = data;
1626 return True;
1630 #if 0
1631 /* This function is not used at the moment. */
1632 static int
1633 getString(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1634 void **ret)
1636 static char *data;
1638 GET_STRING_OR_DEFAULT("String", data);
1640 if (!data) {
1641 data = WMGetFromPLString(entry->plvalue);
1642 if (!data)
1643 return False;
1646 if (ret)
1647 *ret = &data;
1649 if (addr)
1650 *(char**)addr = wstrdup(data);
1652 return True;
1654 #endif
1657 static int
1658 getPathList(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1659 void **ret)
1661 static char *data;
1662 int i, count, len;
1663 char *ptr;
1664 WMPropList *d;
1665 int changed=0;
1667 again:
1668 if (!WMIsPLArray(value)) {
1669 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1670 entry->key, "an array of paths");
1671 if (changed==0) {
1672 value = entry->plvalue;
1673 changed = 1;
1674 wwarning(_("using default \"%s\" instead"), entry->default_value);
1675 goto again;
1677 return False;
1680 i = 0;
1681 count = WMGetPropListItemCount(value);
1682 if (count < 1) {
1683 if (changed==0) {
1684 value = entry->plvalue;
1685 changed = 1;
1686 wwarning(_("using default \"%s\" instead"), entry->default_value);
1687 goto again;
1689 return False;
1692 len = 0;
1693 for (i=0; i<count; i++) {
1694 d = WMGetFromPLArray(value, i);
1695 if (!d || !WMIsPLString(d)) {
1696 count = i;
1697 break;
1699 len += strlen(WMGetFromPLString(d))+1;
1702 ptr = data = wmalloc(len+1);
1704 for (i=0; i<count; i++) {
1705 d = WMGetFromPLArray(value, i);
1706 if (!d || !WMIsPLString(d)) {
1707 break;
1709 strcpy(ptr, WMGetFromPLString(d));
1710 ptr += strlen(WMGetFromPLString(d));
1711 *ptr = ':';
1712 ptr++;
1714 ptr--; *(ptr--) = 0;
1716 if (*(char**)addr!=NULL) {
1717 wfree(*(char**)addr);
1719 *(char**)addr = data;
1721 return True;
1725 static int
1726 getEnum(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1727 void **ret)
1729 static signed char data;
1731 data = string2index(entry->plkey, value, entry->default_value,
1732 (WOptionEnumeration*)entry->extra_data);
1733 if (data < 0)
1734 return False;
1736 if (ret)
1737 *ret = &data;
1739 if (addr)
1740 *(signed char*)addr = data;
1742 return True;
1748 * (solid <color>)
1749 * (hgradient <color> <color>)
1750 * (vgradient <color> <color>)
1751 * (dgradient <color> <color>)
1752 * (mhgradient <color> <color> ...)
1753 * (mvgradient <color> <color> ...)
1754 * (mdgradient <color> <color> ...)
1755 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1756 * (tpixmap <file> <color>)
1757 * (spixmap <file> <color>)
1758 * (cpixmap <file> <color>)
1759 * (thgradient <file> <opaqueness> <color> <color>)
1760 * (tvgradient <file> <opaqueness> <color> <color>)
1761 * (tdgradient <file> <opaqueness> <color> <color>)
1762 * (function <lib> <function> ...)
1765 static WTexture*
1766 parse_texture(WScreen *scr, WMPropList *pl)
1768 WMPropList *elem;
1769 char *val;
1770 int nelem;
1771 WTexture *texture=NULL;
1773 nelem = WMGetPropListItemCount(pl);
1774 if (nelem < 1)
1775 return NULL;
1778 elem = WMGetFromPLArray(pl, 0);
1779 if (!elem || !WMIsPLString(elem))
1780 return NULL;
1781 val = WMGetFromPLString(elem);
1784 if (strcasecmp(val, "solid")==0) {
1785 XColor color;
1787 if (nelem != 2)
1788 return NULL;
1790 /* get color */
1792 elem = WMGetFromPLArray(pl, 1);
1793 if (!elem || !WMIsPLString(elem))
1794 return NULL;
1795 val = WMGetFromPLString(elem);
1797 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1798 wwarning(_("\"%s\" is not a valid color name"), val);
1799 return NULL;
1802 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1803 } else if (strcasecmp(val, "dgradient")==0
1804 || strcasecmp(val, "vgradient")==0
1805 || strcasecmp(val, "hgradient")==0) {
1806 RColor color1, color2;
1807 XColor xcolor;
1808 int type;
1810 if (nelem != 3) {
1811 wwarning(_("bad number of arguments in gradient specification"));
1812 return NULL;
1815 if (val[0]=='d' || val[0]=='D')
1816 type = WTEX_DGRADIENT;
1817 else if (val[0]=='h' || val[0]=='H')
1818 type = WTEX_HGRADIENT;
1819 else
1820 type = WTEX_VGRADIENT;
1823 /* get from color */
1824 elem = WMGetFromPLArray(pl, 1);
1825 if (!elem || !WMIsPLString(elem))
1826 return NULL;
1827 val = WMGetFromPLString(elem);
1829 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1830 wwarning(_("\"%s\" is not a valid color name"), val);
1831 return NULL;
1833 color1.alpha = 255;
1834 color1.red = xcolor.red >> 8;
1835 color1.green = xcolor.green >> 8;
1836 color1.blue = xcolor.blue >> 8;
1838 /* get to color */
1839 elem = WMGetFromPLArray(pl, 2);
1840 if (!elem || !WMIsPLString(elem)) {
1841 return NULL;
1843 val = WMGetFromPLString(elem);
1845 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1846 wwarning(_("\"%s\" is not a valid color name"), val);
1847 return NULL;
1849 color2.alpha = 255;
1850 color2.red = xcolor.red >> 8;
1851 color2.green = xcolor.green >> 8;
1852 color2.blue = xcolor.blue >> 8;
1854 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1856 } else if (strcasecmp(val, "igradient")==0) {
1857 RColor colors1[2], colors2[2];
1858 int th1, th2;
1859 XColor xcolor;
1860 int i;
1862 if (nelem != 7) {
1863 wwarning(_("bad number of arguments in gradient specification"));
1864 return NULL;
1867 /* get from color */
1868 for (i = 0; i < 2; i++) {
1869 elem = WMGetFromPLArray(pl, 1+i);
1870 if (!elem || !WMIsPLString(elem))
1871 return NULL;
1872 val = WMGetFromPLString(elem);
1874 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1875 wwarning(_("\"%s\" is not a valid color name"), val);
1876 return NULL;
1878 colors1[i].alpha = 255;
1879 colors1[i].red = xcolor.red >> 8;
1880 colors1[i].green = xcolor.green >> 8;
1881 colors1[i].blue = xcolor.blue >> 8;
1883 elem = WMGetFromPLArray(pl, 3);
1884 if (!elem || !WMIsPLString(elem))
1885 return NULL;
1886 val = WMGetFromPLString(elem);
1887 th1 = atoi(val);
1890 /* get from color */
1891 for (i = 0; i < 2; i++) {
1892 elem = WMGetFromPLArray(pl, 4+i);
1893 if (!elem || !WMIsPLString(elem))
1894 return NULL;
1895 val = WMGetFromPLString(elem);
1897 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1898 wwarning(_("\"%s\" is not a valid color name"), val);
1899 return NULL;
1901 colors2[i].alpha = 255;
1902 colors2[i].red = xcolor.red >> 8;
1903 colors2[i].green = xcolor.green >> 8;
1904 colors2[i].blue = xcolor.blue >> 8;
1906 elem = WMGetFromPLArray(pl, 6);
1907 if (!elem || !WMIsPLString(elem))
1908 return NULL;
1909 val = WMGetFromPLString(elem);
1910 th2 = atoi(val);
1912 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1913 th2, colors2);
1915 } else if (strcasecmp(val, "mhgradient")==0
1916 || strcasecmp(val, "mvgradient")==0
1917 || strcasecmp(val, "mdgradient")==0) {
1918 XColor color;
1919 RColor **colors;
1920 int i, count;
1921 int type;
1923 if (nelem < 3) {
1924 wwarning(_("too few arguments in multicolor gradient specification"));
1925 return NULL;
1928 if (val[1]=='h' || val[1]=='H')
1929 type = WTEX_MHGRADIENT;
1930 else if (val[1]=='v' || val[1]=='V')
1931 type = WTEX_MVGRADIENT;
1932 else
1933 type = WTEX_MDGRADIENT;
1935 count = nelem-1;
1937 colors = wmalloc(sizeof(RColor*)*(count+1));
1939 for (i=0; i<count; i++) {
1940 elem = WMGetFromPLArray(pl, i+1);
1941 if (!elem || !WMIsPLString(elem)) {
1942 for (--i; i>=0; --i) {
1943 wfree(colors[i]);
1945 wfree(colors);
1946 return NULL;
1948 val = WMGetFromPLString(elem);
1950 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1951 wwarning(_("\"%s\" is not a valid color name"), val);
1952 for (--i; i>=0; --i) {
1953 wfree(colors[i]);
1955 wfree(colors);
1956 return NULL;
1957 } else {
1958 colors[i] = wmalloc(sizeof(RColor));
1959 colors[i]->red = color.red >> 8;
1960 colors[i]->green = color.green >> 8;
1961 colors[i]->blue = color.blue >> 8;
1964 colors[i] = NULL;
1966 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1967 } else if (strcasecmp(val, "spixmap")==0 ||
1968 strcasecmp(val, "cpixmap")==0 ||
1969 strcasecmp(val, "tpixmap")==0) {
1970 XColor color;
1971 int type;
1973 if (nelem != 3)
1974 return NULL;
1976 if (val[0] == 's' || val[0] == 'S')
1977 type = WTP_SCALE;
1978 else if (val[0] == 'c' || val[0] == 'C')
1979 type = WTP_CENTER;
1980 else
1981 type = WTP_TILE;
1983 /* get color */
1984 elem = WMGetFromPLArray(pl, 2);
1985 if (!elem || !WMIsPLString(elem)) {
1986 return NULL;
1988 val = WMGetFromPLString(elem);
1990 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1991 wwarning(_("\"%s\" is not a valid color name"), val);
1992 return NULL;
1995 /* file name */
1996 elem = WMGetFromPLArray(pl, 1);
1997 if (!elem || !WMIsPLString(elem))
1998 return NULL;
1999 val = WMGetFromPLString(elem);
2001 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
2002 } else if (strcasecmp(val, "thgradient")==0
2003 || strcasecmp(val, "tvgradient")==0
2004 || strcasecmp(val, "tdgradient")==0) {
2005 RColor color1, color2;
2006 XColor xcolor;
2007 int opacity;
2008 int style;
2010 if (val[1]=='h' || val[1]=='H')
2011 style = WTEX_THGRADIENT;
2012 else if (val[1]=='v' || val[1]=='V')
2013 style = WTEX_TVGRADIENT;
2014 else
2015 style = WTEX_TDGRADIENT;
2017 if (nelem != 5) {
2018 wwarning(_("bad number of arguments in textured gradient specification"));
2019 return NULL;
2022 /* get from color */
2023 elem = WMGetFromPLArray(pl, 3);
2024 if (!elem || !WMIsPLString(elem))
2025 return NULL;
2026 val = WMGetFromPLString(elem);
2028 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2029 wwarning(_("\"%s\" is not a valid color name"), val);
2030 return NULL;
2032 color1.alpha = 255;
2033 color1.red = xcolor.red >> 8;
2034 color1.green = xcolor.green >> 8;
2035 color1.blue = xcolor.blue >> 8;
2037 /* get to color */
2038 elem = WMGetFromPLArray(pl, 4);
2039 if (!elem || !WMIsPLString(elem)) {
2040 return NULL;
2042 val = WMGetFromPLString(elem);
2044 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2045 wwarning(_("\"%s\" is not a valid color name"), val);
2046 return NULL;
2048 color2.alpha = 255;
2049 color2.red = xcolor.red >> 8;
2050 color2.green = xcolor.green >> 8;
2051 color2.blue = xcolor.blue >> 8;
2053 /* get opacity */
2054 elem = WMGetFromPLArray(pl, 2);
2055 if (!elem || !WMIsPLString(elem))
2056 opacity = 128;
2057 else
2058 val = WMGetFromPLString(elem);
2060 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2061 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2062 opacity = 128;
2065 /* get file name */
2066 elem = WMGetFromPLArray(pl, 1);
2067 if (!elem || !WMIsPLString(elem))
2068 return NULL;
2069 val = WMGetFromPLString(elem);
2071 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2072 val, opacity);
2074 #ifdef TEXTURE_PLUGIN
2075 else if (strcasecmp(val, "function")==0) {
2076 WTexFunction *function;
2077 void (*initFunc) (Display *, Colormap);
2078 char *lib, *func, **argv;
2079 int i, argc;
2081 if (nelem < 3)
2082 return NULL;
2084 /* get the library name */
2085 elem = WMGetFromPLArray(pl, 1);
2086 if (!elem || !WMIsPLString(elem)) {
2087 return NULL;
2089 lib = WMGetFromPLString(elem);
2091 /* get the function name */
2092 elem = WMGetFromPLArray(pl, 2);
2093 if (!elem || !WMIsPLString(elem)) {
2094 return NULL;
2096 func = WMGetFromPLString(elem);
2098 argc = nelem - 2;
2099 argv = (char **)wmalloc(argc * sizeof(char *));
2101 /* get the parameters */
2102 argv[0] = wstrdup(func);
2103 for (i = 0; i < argc - 1; i++) {
2104 elem = WMGetFromPLArray(pl, 3 + i);
2105 if (!elem || !WMIsPLString(elem)) {
2106 wfree(argv);
2108 return NULL;
2110 argv[i+1] = wstrdup(WMGetFromPLString(elem));
2113 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2115 #ifdef HAVE_DLFCN_H
2116 if (function) {
2117 initFunc = dlsym(function->handle, "initWindowMaker");
2118 if (initFunc) {
2119 initFunc(dpy, scr->w_colormap);
2120 } else {
2121 wwarning(_("could not initialize library %s"), lib);
2123 } else {
2124 wwarning(_("could not find function %s::%s"), lib, func);
2126 #endif /* HAVE_DLFCN_H */
2127 texture = (WTexture*)function;
2129 #endif /* TEXTURE_PLUGIN */
2130 else {
2131 wwarning(_("invalid texture type %s"), val);
2132 return NULL;
2134 return texture;
2139 static int
2140 getTexture(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2141 void **ret)
2143 static WTexture *texture;
2144 int changed=0;
2146 again:
2147 if (!WMIsPLArray(value)) {
2148 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2149 entry->key, "Texture");
2150 if (changed==0) {
2151 value = entry->plvalue;
2152 changed = 1;
2153 wwarning(_("using default \"%s\" instead"), entry->default_value);
2154 goto again;
2156 return False;
2159 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2160 WMPropList *pl;
2162 pl = WMGetFromPLArray(value, 0);
2163 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2164 || strcasecmp(WMGetFromPLString(pl), "solid")!=0) {
2165 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2166 entry->key, "Solid Texture");
2168 value = entry->plvalue;
2169 changed = 1;
2170 wwarning(_("using default \"%s\" instead"), entry->default_value);
2171 goto again;
2175 texture = parse_texture(scr, value);
2177 if (!texture) {
2178 wwarning(_("Error in texture specification for key \"%s\""),
2179 entry->key);
2180 if (changed==0) {
2181 value = entry->plvalue;
2182 changed = 1;
2183 wwarning(_("using default \"%s\" instead"), entry->default_value);
2184 goto again;
2186 return False;
2189 if (ret)
2190 *ret = &texture;
2192 if (addr)
2193 *(WTexture**)addr = texture;
2195 return True;
2199 static int
2200 getWSBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2201 void *addr, void **ret)
2203 WMPropList *elem;
2204 int changed = 0;
2205 char *val;
2206 int nelem;
2208 again:
2209 if (!WMIsPLArray(value)) {
2210 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2211 "WorkspaceBack", "Texture or None");
2212 if (changed==0) {
2213 value = entry->plvalue;
2214 changed = 1;
2215 wwarning(_("using default \"%s\" instead"), entry->default_value);
2216 goto again;
2218 return False;
2221 /* only do basic error checking and verify for None texture */
2223 nelem = WMGetPropListItemCount(value);
2224 if (nelem > 0) {
2225 elem = WMGetFromPLArray(value, 0);
2226 if (!elem || !WMIsPLString(elem)) {
2227 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2228 if (changed==0) {
2229 value = entry->plvalue;
2230 changed = 1;
2231 wwarning(_("using default \"%s\" instead"), entry->default_value);
2232 goto again;
2234 return False;
2236 val = WMGetFromPLString(elem);
2238 if (strcasecmp(val, "None")==0)
2239 return True;
2241 *ret = WMRetainPropList(value);
2243 return True;
2247 static int
2248 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2249 void *addr, void **ret)
2251 WMPropList *elem;
2252 int nelem;
2253 int changed = 0;
2255 again:
2256 if (!WMIsPLArray(value)) {
2257 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2258 "WorkspaceSpecificBack", "an array of textures");
2259 if (changed==0) {
2260 value = entry->plvalue;
2261 changed = 1;
2262 wwarning(_("using default \"%s\" instead"), entry->default_value);
2263 goto again;
2265 return False;
2268 /* only do basic error checking and verify for None texture */
2270 nelem = WMGetPropListItemCount(value);
2271 if (nelem > 0) {
2272 while (nelem--) {
2273 elem = WMGetFromPLArray(value, nelem);
2274 if (!elem || !WMIsPLArray(elem)) {
2275 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2276 nelem);
2281 *ret = WMRetainPropList(value);
2283 #ifdef notworking
2285 * Kluge to force wmsetbg helper to set the default background.
2286 * If the WorkspaceSpecificBack is changed once wmaker has started,
2287 * the WorkspaceBack won't be sent to the helper, unless the user
2288 * changes it's value too. So, we must force this by removing the
2289 * value from the defaults DB.
2291 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2292 WMPropList *key = WMCreatePLString("WorkspaceBack");
2294 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2296 WMReleasePropList(key);
2298 #endif
2299 return True;
2303 static int
2304 getFont(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2305 void **ret)
2307 static WMFont *font;
2308 char *val;
2310 GET_STRING_OR_DEFAULT("Font", val);
2312 font = WMCreateFont(scr->wmscreen, val);
2313 if (!font)
2314 font = WMCreateFont(scr->wmscreen, "fixed");
2316 if (!font) {
2317 wfatal(_("could not load any usable font!!!"));
2318 exit(1);
2321 if (ret)
2322 *ret = font;
2324 /* can't assign font value outside update function */
2325 wassertrv(addr == NULL, True);
2327 return True;
2331 static int
2332 getColor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2333 void **ret)
2335 static XColor color;
2336 char *val;
2337 int second_pass=0;
2339 GET_STRING_OR_DEFAULT("Color", val);
2342 again:
2343 if (!wGetColor(scr, val, &color)) {
2344 wwarning(_("could not get color for key \"%s\""),
2345 entry->key);
2346 if (second_pass==0) {
2347 val = WMGetFromPLString(entry->plvalue);
2348 second_pass = 1;
2349 wwarning(_("using default \"%s\" instead"), val);
2350 goto again;
2352 return False;
2355 if (ret)
2356 *ret = &color;
2358 assert(addr==NULL);
2360 if (addr)
2361 *(unsigned long*)addr = pixel;
2364 return True;
2369 static int
2370 getKeybind(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2371 void **ret)
2373 static WShortKey shortcut;
2374 KeySym ksym;
2375 char *val;
2376 char *k;
2377 char buf[128], *b;
2380 GET_STRING_OR_DEFAULT("Key spec", val);
2382 if (!val || strcasecmp(val, "NONE")==0) {
2383 shortcut.keycode = 0;
2384 shortcut.modifier = 0;
2385 if (ret)
2386 *ret = &shortcut;
2387 return True;
2390 strcpy(buf, val);
2392 b = (char*)buf;
2394 /* get modifiers */
2395 shortcut.modifier = 0;
2396 while ((k = strchr(b, '+'))!=NULL) {
2397 int mod;
2399 *k = 0;
2400 mod = wXModifierFromKey(b);
2401 if (mod<0) {
2402 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2403 return False;
2405 shortcut.modifier |= mod;
2407 b = k+1;
2410 /* get key */
2411 ksym = XStringToKeysym(b);
2413 if (ksym==NoSymbol) {
2414 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2415 val);
2416 return False;
2419 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2420 if (shortcut.keycode==0) {
2421 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2422 return False;
2425 if (ret)
2426 *ret = &shortcut;
2428 return True;
2432 static int
2433 getModMask(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2434 void **ret)
2436 static unsigned int mask;
2437 char *str;
2439 GET_STRING_OR_DEFAULT("Modifier Key", str);
2441 if (!str)
2442 return False;
2444 mask = wXModifierFromKey(str);
2445 if (mask < 0) {
2446 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2447 mask = 0;
2448 return False;
2451 if (addr)
2452 *(unsigned int*)addr = mask;
2454 if (ret)
2455 *ret = &mask;
2457 return True;
2461 #ifdef NEWSTUFF
2462 static int
2463 getRImages(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2464 void *addr, void **ret)
2466 unsigned int mask;
2467 char *str;
2468 RImage *image;
2469 int i, n;
2470 int w, h;
2472 GET_STRING_OR_DEFAULT("Image File Path", str);
2473 if (!str)
2474 return False;
2476 image = RLoadImage(scr->rcontext, str, 0);
2477 if (!image) {
2478 wwarning(_("could not load image in option %s: %s"), entry->key,
2479 RMessageForError(RErrorCode));
2480 return False;
2483 if (*(RImage**)addr) {
2484 RReleaseImage(*(RImage**)addr);
2486 if (addr)
2487 *(RImage**)addr = image;
2489 assert(ret == NULL);
2491 if (ret)
2492 *(RImage**)ret = image;
2495 return True;
2497 #endif
2499 # include <X11/cursorfont.h>
2500 typedef struct
2502 char *name;
2503 int id;
2504 } WCursorLookup;
2506 #define CURSOR_ID_NONE (XC_num_glyphs)
2508 static WCursorLookup cursor_table[] =
2510 { "X_cursor", XC_X_cursor },
2511 { "arrow", XC_arrow },
2512 { "based_arrow_down", XC_based_arrow_down },
2513 { "based_arrow_up", XC_based_arrow_up },
2514 { "boat", XC_boat },
2515 { "bogosity", XC_bogosity },
2516 { "bottom_left_corner", XC_bottom_left_corner },
2517 { "bottom_right_corner", XC_bottom_right_corner },
2518 { "bottom_side", XC_bottom_side },
2519 { "bottom_tee", XC_bottom_tee },
2520 { "box_spiral", XC_box_spiral },
2521 { "center_ptr", XC_center_ptr },
2522 { "circle", XC_circle },
2523 { "clock", XC_clock },
2524 { "coffee_mug", XC_coffee_mug },
2525 { "cross", XC_cross },
2526 { "cross_reverse", XC_cross_reverse },
2527 { "crosshair", XC_crosshair },
2528 { "diamond_cross", XC_diamond_cross },
2529 { "dot", XC_dot },
2530 { "dotbox", XC_dotbox },
2531 { "double_arrow", XC_double_arrow },
2532 { "draft_large", XC_draft_large },
2533 { "draft_small", XC_draft_small },
2534 { "draped_box", XC_draped_box },
2535 { "exchange", XC_exchange },
2536 { "fleur", XC_fleur },
2537 { "gobbler", XC_gobbler },
2538 { "gumby", XC_gumby },
2539 { "hand1", XC_hand1 },
2540 { "hand2", XC_hand2 },
2541 { "heart", XC_heart },
2542 { "icon", XC_icon },
2543 { "iron_cross", XC_iron_cross },
2544 { "left_ptr", XC_left_ptr },
2545 { "left_side", XC_left_side },
2546 { "left_tee", XC_left_tee },
2547 { "leftbutton", XC_leftbutton },
2548 { "ll_angle", XC_ll_angle },
2549 { "lr_angle", XC_lr_angle },
2550 { "man", XC_man },
2551 { "middlebutton", XC_middlebutton },
2552 { "mouse", XC_mouse },
2553 { "pencil", XC_pencil },
2554 { "pirate", XC_pirate },
2555 { "plus", XC_plus },
2556 { "question_arrow", XC_question_arrow },
2557 { "right_ptr", XC_right_ptr },
2558 { "right_side", XC_right_side },
2559 { "right_tee", XC_right_tee },
2560 { "rightbutton", XC_rightbutton },
2561 { "rtl_logo", XC_rtl_logo },
2562 { "sailboat", XC_sailboat },
2563 { "sb_down_arrow", XC_sb_down_arrow },
2564 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2565 { "sb_left_arrow", XC_sb_left_arrow },
2566 { "sb_right_arrow", XC_sb_right_arrow },
2567 { "sb_up_arrow", XC_sb_up_arrow },
2568 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2569 { "shuttle", XC_shuttle },
2570 { "sizing", XC_sizing },
2571 { "spider", XC_spider },
2572 { "spraycan", XC_spraycan },
2573 { "star", XC_star },
2574 { "target", XC_target },
2575 { "tcross", XC_tcross },
2576 { "top_left_arrow", XC_top_left_arrow },
2577 { "top_left_corner", XC_top_left_corner },
2578 { "top_right_corner", XC_top_right_corner },
2579 { "top_side", XC_top_side },
2580 { "top_tee", XC_top_tee },
2581 { "trek", XC_trek },
2582 { "ul_angle", XC_ul_angle },
2583 { "umbrella", XC_umbrella },
2584 { "ur_angle", XC_ur_angle },
2585 { "watch", XC_watch },
2586 { "xterm", XC_xterm },
2587 { NULL, CURSOR_ID_NONE }
2590 static void
2591 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2593 switch(status) {
2594 case BitmapOpenFailed:
2595 wwarning(_("failed to open bitmap file \"%s\""), filename);
2596 break;
2597 case BitmapFileInvalid:
2598 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2599 break;
2600 case BitmapNoMemory:
2601 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2602 break;
2603 case BitmapSuccess:
2604 XFreePixmap(dpy, bitmap);
2605 break;
2610 * (none)
2611 * (builtin, <cursor_name>)
2612 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2614 static int
2615 parse_cursor(WScreen *scr, WMPropList *pl, Cursor *cursor)
2617 WMPropList *elem;
2618 char *val;
2619 int nelem;
2620 int status = 0;
2622 nelem = WMGetPropListItemCount(pl);
2623 if (nelem < 1) {
2624 return(status);
2626 elem = WMGetFromPLArray(pl, 0);
2627 if (!elem || !WMIsPLString(elem)) {
2628 return(status);
2630 val = WMGetFromPLString(elem);
2632 if (0 == strcasecmp(val, "none")) {
2633 status = 1;
2634 *cursor = None;
2635 } else if (0 == strcasecmp(val, "builtin")) {
2636 int i;
2637 int cursor_id = CURSOR_ID_NONE;
2639 if (2 != nelem) {
2640 wwarning(_("bad number of arguments in cursor specification"));
2641 return(status);
2643 elem = WMGetFromPLArray(pl, 1);
2644 if (!elem || !WMIsPLString(elem)) {
2645 return(status);
2647 val = WMGetFromPLString(elem);
2649 for (i = 0; NULL != cursor_table[i].name; i++) {
2650 if (0 == strcasecmp(val, cursor_table[i].name)) {
2651 cursor_id = cursor_table[i].id;
2652 break;
2655 if (CURSOR_ID_NONE == cursor_id) {
2656 wwarning(_("unknown builtin cursor name \"%s\""), val);
2657 } else {
2658 *cursor = XCreateFontCursor(dpy, cursor_id);
2659 status = 1;
2661 } else if (0 == strcasecmp(val, "bitmap")) {
2662 char *bitmap_name;
2663 char *mask_name;
2664 int bitmap_status;
2665 int mask_status;
2666 Pixmap bitmap;
2667 Pixmap mask;
2668 unsigned int w, h;
2669 int x, y;
2670 XColor fg, bg;
2672 if (3 != nelem) {
2673 wwarning(_("bad number of arguments in cursor specification"));
2674 return(status);
2676 elem = WMGetFromPLArray(pl, 1);
2677 if (!elem || !WMIsPLString(elem)) {
2678 return(status);
2680 val = WMGetFromPLString(elem);
2681 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2682 if (!bitmap_name) {
2683 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2684 return(status);
2686 elem = WMGetFromPLArray(pl, 2);
2687 if (!elem || !WMIsPLString(elem)) {
2688 wfree(bitmap_name);
2689 return(status);
2691 val = WMGetFromPLString(elem);
2692 mask_name = FindImage(wPreferences.pixmap_path, val);
2693 if (!mask_name) {
2694 wfree(bitmap_name);
2695 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2696 return(status);
2698 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2699 &mask, &x, &y);
2700 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2701 &bitmap, &x, &y);
2702 if ((BitmapSuccess == bitmap_status) &&
2703 (BitmapSuccess == mask_status)) {
2704 fg.pixel = scr->black_pixel;
2705 bg.pixel = scr->white_pixel;
2706 XQueryColor(dpy, scr->w_colormap, &fg);
2707 XQueryColor(dpy, scr->w_colormap, &bg);
2708 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2709 status = 1;
2711 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2712 check_bitmap_status(mask_status, mask_name, mask);
2713 wfree(bitmap_name);
2714 wfree(mask_name);
2716 return(status);
2720 static int
2721 getCursor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2722 void **ret)
2724 static Cursor cursor;
2725 int status;
2726 int changed = 0;
2728 again:
2729 if (!WMIsPLArray(value)) {
2730 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2731 entry->key, "cursor specification");
2732 if (!changed) {
2733 value = entry->plvalue;
2734 changed = 1;
2735 wwarning(_("using default \"%s\" instead"), entry->default_value);
2736 goto again;
2738 return(False);
2740 status = parse_cursor(scr, value, &cursor);
2741 if (!status) {
2742 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2743 if (!changed) {
2744 value = entry->plvalue;
2745 changed = 1;
2746 wwarning(_("using default \"%s\" instead"), entry->default_value);
2747 goto again;
2749 return(False);
2751 if (ret) {
2752 *ret = &cursor;
2754 if (addr) {
2755 *(Cursor *)addr = cursor;
2757 return(True);
2759 #undef CURSOR_ID_NONE
2762 /* ---------------- value setting functions --------------- */
2763 static int
2764 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2766 return REFRESH_WINDOW_TITLE_COLOR;
2769 static int
2770 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2772 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2775 static int
2776 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2778 switch (which) {
2779 case WM_DOCK:
2780 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2781 break;
2782 case WM_CLIP:
2783 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2784 break;
2785 default:
2786 break;
2788 return 0;
2792 static int
2793 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2795 if (scr->workspaces) {
2796 wWorkspaceForceChange(scr, scr->current_workspace);
2797 wArrangeIcons(scr, False);
2799 return 0;
2802 #if not_used
2803 static int
2804 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2806 if (*value <= 0)
2807 *(int*)foo = 1;
2809 return 0;
2811 #endif
2815 static int
2816 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2818 Pixmap pixmap;
2819 RImage *img;
2820 int reset = 0;
2822 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2823 wPreferences.icon_size,
2824 ((*texture)->any.type & WREL_BORDER_MASK)
2825 ? WREL_ICON : WREL_FLAT);
2826 if (!img) {
2827 wwarning(_("could not render texture for icon background"));
2828 if (!entry->addr)
2829 wTextureDestroy(scr, *texture);
2830 return 0;
2832 RConvertImage(scr->rcontext, img, &pixmap);
2834 if (scr->icon_tile) {
2835 reset = 1;
2836 RReleaseImage(scr->icon_tile);
2837 XFreePixmap(dpy, scr->icon_tile_pixmap);
2840 scr->icon_tile = img;
2843 /* put the icon in the noticeboard hint */
2844 PropSetIconTileHint(scr, img);
2847 if (!wPreferences.flags.noclip) {
2848 if (scr->clip_tile) {
2849 RReleaseImage(scr->clip_tile);
2851 scr->clip_tile = wClipMakeTile(scr, img);
2854 scr->icon_tile_pixmap = pixmap;
2856 if (scr->def_icon_pixmap) {
2857 XFreePixmap(dpy, scr->def_icon_pixmap);
2858 scr->def_icon_pixmap = None;
2860 if (scr->def_ticon_pixmap) {
2861 XFreePixmap(dpy, scr->def_ticon_pixmap);
2862 scr->def_ticon_pixmap = None;
2865 if (scr->icon_back_texture) {
2866 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2868 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2870 if (scr->clip_balloon)
2871 XSetWindowBackground(dpy, scr->clip_balloon,
2872 (*texture)->any.color.pixel);
2875 * Free the texture as nobody else will use it, nor refer to it.
2877 if (!entry->addr)
2878 wTextureDestroy(scr, *texture);
2880 return (reset ? REFRESH_ICON_TILE : 0);
2885 static int
2886 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2888 if (scr->title_font) {
2889 WMReleaseFont(scr->title_font);
2891 scr->title_font = font;
2893 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2897 static int
2898 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2900 if (scr->menu_title_font) {
2901 WMReleaseFont(scr->menu_title_font);
2904 scr->menu_title_font = font;
2906 return REFRESH_MENU_TITLE_FONT;
2910 static int
2911 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2913 if (scr->menu_entry_font) {
2914 WMReleaseFont(scr->menu_entry_font);
2916 scr->menu_entry_font = font;
2918 return REFRESH_MENU_FONT;
2923 static int
2924 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2926 if (scr->icon_title_font) {
2927 WMReleaseFont(scr->icon_title_font);
2930 scr->icon_title_font = font;
2932 return REFRESH_ICON_FONT;
2936 static int
2937 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2939 if (scr->clip_title_font) {
2940 WMReleaseFont(scr->clip_title_font);
2943 scr->clip_title_font = font;
2945 return REFRESH_ICON_FONT;
2949 static int
2950 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2952 if (scr->workspace_name_font) {
2953 WMReleaseFont(scr->workspace_name_font);
2956 scr->workspace_name_font = font;
2958 return 0;
2962 static int
2963 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2965 if (scr->select_color)
2966 WMReleaseColor(scr->select_color);
2968 scr->select_color =
2969 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
2970 color->blue, True);
2972 wFreeColor(scr, color->pixel);
2974 return REFRESH_MENU_COLOR;
2978 static int
2979 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2981 if (scr->select_text_color)
2982 WMReleaseColor(scr->select_text_color);
2984 scr->select_text_color =
2985 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
2986 color->blue, True);
2988 wFreeColor(scr, color->pixel);
2990 return REFRESH_MENU_COLOR;
2994 static int
2995 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2997 if (scr->clip_title_color[index])
2998 WMReleaseColor(scr->clip_title_color[index]);
2999 scr->clip_title_color[index] = WMCreateRGBColor(scr->wmscreen, color->red,
3000 color->green, color->blue,
3001 True);
3002 #ifdef GRADIENT_CLIP_ARROW
3003 if (index == CLIP_NORMAL) {
3004 RImage *image;
3005 RColor color1, color2;
3006 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3007 int as = pt - 15; /* 15 = 5+5+5 */
3009 FREE_PIXMAP(scr->clip_arrow_gradient);
3011 color1.red = (color->red >> 8)*6/10;
3012 color1.green = (color->green >> 8)*6/10;
3013 color1.blue = (color->blue >> 8)*6/10;
3015 color2.red = WMIN((color->red >> 8)*20/10, 255);
3016 color2.green = WMIN((color->green >> 8)*20/10, 255);
3017 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3019 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3020 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3021 RReleaseImage(image);
3023 #endif /* GRADIENT_CLIP_ARROW */
3025 wFreeColor(scr, color->pixel);
3027 return REFRESH_ICON_TITLE_COLOR;
3031 static int
3032 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3034 if (scr->window_title_color[index])
3035 WMReleaseColor(scr->window_title_color[index]);
3037 scr->window_title_color[index] =
3038 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue,
3039 True);
3041 wFreeColor(scr, color->pixel);
3043 return REFRESH_WINDOW_TITLE_COLOR;
3047 static int
3048 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3050 if (scr->menu_title_color[0])
3051 WMReleaseColor(scr->menu_title_color[0]);
3053 scr->menu_title_color[0] =
3054 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3055 color->blue, True);
3057 wFreeColor(scr, color->pixel);
3059 return REFRESH_MENU_TITLE_COLOR;
3063 static int
3064 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3066 if (scr->mtext_color)
3067 WMReleaseColor(scr->mtext_color);
3069 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3070 color->green, color->blue, True);
3072 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3073 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3074 } else {
3075 WMSetColorAlpha(scr->dtext_color, 0xffff);
3078 wFreeColor(scr, color->pixel);
3080 return REFRESH_MENU_COLOR;
3084 static int
3085 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3087 if (scr->dtext_color)
3088 WMReleaseColor(scr->dtext_color);
3090 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3091 color->green, color->blue, True);
3093 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3094 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3095 } else {
3096 WMSetColorAlpha(scr->dtext_color, 0xffff);
3099 wFreeColor(scr, color->pixel);
3101 return REFRESH_MENU_COLOR;
3105 static int
3106 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3108 if (scr->icon_title_color)
3109 WMReleaseColor(scr->icon_title_color);
3110 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red,
3111 color->green, color->blue,
3112 True);
3114 wFreeColor(scr, color->pixel);
3116 return REFRESH_ICON_TITLE_COLOR;
3120 static int
3121 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3123 if (scr->icon_title_texture) {
3124 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3126 // ?? why is this necessary? color was already parsed and alloced
3127 XQueryColor (dpy, scr->w_colormap, color);
3128 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3130 return REFRESH_ICON_TITLE_BACK;
3134 static void
3135 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3137 close(scr->helper_fd);
3138 scr->helper_fd = 0;
3139 scr->helper_pid = 0;
3140 scr->flags.backimage_helper_launched = 0;
3144 static int
3145 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3146 void *bar)
3148 WMPropList *val;
3149 char *str;
3150 int i;
3152 if (scr->flags.backimage_helper_launched) {
3153 if (WMGetPropListItemCount(value)==0) {
3154 SendHelperMessage(scr, 'C', 0, NULL);
3155 SendHelperMessage(scr, 'K', 0, NULL);
3157 WMReleasePropList(value);
3158 return 0;
3160 } else {
3161 pid_t pid;
3162 int filedes[2];
3164 if (WMGetPropListItemCount(value) == 0)
3165 return 0;
3167 if (pipe(filedes) < 0) {
3168 wsyserror("pipe() failed:can't set workspace specific background image");
3170 WMReleasePropList(value);
3171 return 0;
3174 pid = fork();
3175 if (pid < 0) {
3176 wsyserror("fork() failed:can't set workspace specific background image");
3177 if (close(filedes[0]) < 0)
3178 wsyserror("could not close pipe");
3179 if (close(filedes[1]) < 0)
3180 wsyserror("could not close pipe");
3182 } else if (pid == 0) {
3183 char *dither;
3185 SetupEnvironment(scr);
3187 if (close(0) < 0)
3188 wsyserror("could not close pipe");
3189 if (dup(filedes[0]) < 0) {
3190 wsyserror("dup() failed:can't set workspace specific background image");
3192 dither = wPreferences.no_dithering ? "-m" : "-d";
3193 if (wPreferences.smooth_workspace_back)
3194 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3195 else
3196 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3197 wsyserror("could not execute wmsetbg");
3198 exit(1);
3199 } else {
3201 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3202 wsyserror("error setting close-on-exec flag");
3204 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3205 wsyserror("error setting close-on-exec flag");
3208 scr->helper_fd = filedes[1];
3209 scr->helper_pid = pid;
3210 scr->flags.backimage_helper_launched = 1;
3212 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3214 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3219 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3220 val = WMGetFromPLArray(value, i);
3221 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val)>0) {
3222 str = WMGetPropListDescription(val, False);
3224 SendHelperMessage(scr, 'S', i+1, str);
3226 wfree(str);
3227 } else {
3228 SendHelperMessage(scr, 'U', i+1, NULL);
3231 sleep(1);
3233 WMReleasePropList(value);
3234 return 0;
3238 static int
3239 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3240 void *bar)
3242 if (scr->flags.backimage_helper_launched) {
3243 char *str;
3245 if (WMGetPropListItemCount(value)==0) {
3246 SendHelperMessage(scr, 'U', 0, NULL);
3247 } else {
3248 /* set the default workspace background to this one */
3249 str = WMGetPropListDescription(value, False);
3250 if (str) {
3251 SendHelperMessage(scr, 'S', 0, str);
3252 wfree(str);
3253 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3254 } else {
3255 SendHelperMessage(scr, 'U', 0, NULL);
3258 } else if (WMGetPropListItemCount(value) > 0) {
3259 char *command;
3260 char *text;
3261 char *dither;
3262 int len;
3264 SetupEnvironment(scr);
3265 text = WMGetPropListDescription(value, False);
3266 len = strlen(text)+40;
3267 command = wmalloc(len);
3268 dither = wPreferences.no_dithering ? "-m" : "-d";
3269 if (wPreferences.smooth_workspace_back)
3270 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3271 else
3272 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3273 wfree(text);
3274 system(command);
3275 wfree(command);
3277 WMReleasePropList(value);
3279 return 0;
3283 static int
3284 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3286 if (scr->widget_texture) {
3287 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3289 scr->widget_texture = *(WTexSolid**)texture;
3291 return 0;
3295 static int
3296 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3298 if (scr->window_title_texture[WS_FOCUSED]) {
3299 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3301 scr->window_title_texture[WS_FOCUSED] = *texture;
3303 return REFRESH_WINDOW_TEXTURES;
3307 static int
3308 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3310 if (scr->window_title_texture[WS_PFOCUSED]) {
3311 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3313 scr->window_title_texture[WS_PFOCUSED] = *texture;
3315 return REFRESH_WINDOW_TEXTURES;
3319 static int
3320 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3322 if (scr->window_title_texture[WS_UNFOCUSED]) {
3323 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3325 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3327 return REFRESH_WINDOW_TEXTURES;
3331 static int
3332 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3334 if (scr->resizebar_texture[0]) {
3335 wTextureDestroy(scr, scr->resizebar_texture[0]);
3337 scr->resizebar_texture[0] = *texture;
3339 return REFRESH_WINDOW_TEXTURES;
3343 static int
3344 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3346 if (scr->menu_title_texture[0]) {
3347 wTextureDestroy(scr, scr->menu_title_texture[0]);
3349 scr->menu_title_texture[0] = *texture;
3351 return REFRESH_MENU_TITLE_TEXTURE;
3355 static int
3356 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3358 if (scr->menu_item_texture) {
3359 wTextureDestroy(scr, scr->menu_item_texture);
3360 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3362 scr->menu_item_texture = *texture;
3364 scr->menu_item_auxtexture
3365 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3367 return REFRESH_MENU_TEXTURE;
3371 static int
3372 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3374 WWindow *wwin;
3375 wKeyBindings[index] = *shortcut;
3377 wwin = scr->focused_window;
3379 while (wwin!=NULL) {
3380 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3382 if (!WFLAGP(wwin, no_bind_keys)) {
3383 wWindowSetKeyGrabs(wwin);
3385 wwin = wwin->prev;
3388 return 0;
3392 static int
3393 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3395 wArrangeIcons(scr, True);
3397 return 0;
3401 static int
3402 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3404 wScreenUpdateUsableArea(scr);
3406 return 0;
3410 static int
3411 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3413 return REFRESH_MENU_TEXTURE;
3418 static int
3419 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3421 return REFRESH_BUTTON_IMAGES;
3426 * Very ugly kluge.
3427 * Need access to the double click variables, so that all widgets in
3428 * wmaker panels will have the same dbl-click values.
3429 * TODO: figure a better way of dealing with it.
3431 #include <WINGs/WINGsP.h>
3433 static int
3434 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3436 extern _WINGsConfiguration WINGsConfiguration;
3438 if (*value <= 0)
3439 *(int*)foo = 1;
3441 WINGsConfiguration.doubleClickDelay = *value;
3443 return 0;
3447 #if 0
3448 static int
3449 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3451 extern _WINGsConfiguration WINGsConfiguration;
3453 WINGsConfiguration.useMultiByte = *value;
3455 return 0;
3457 #endif
3460 static int
3461 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3463 if (wCursor[index] != None) {
3464 XFreeCursor(dpy, wCursor[index]);
3467 wCursor[index] = *cursor;
3469 if (index==WCUR_ROOT && *cursor!=None) {
3470 XDefineCursor(dpy, scr->root_win, *cursor);
3473 return 0;