definable cursor code updates from Jim Knoble <jmknoble@pobox.com>
[wmaker-crm.git] / src / defaults.c
blob61c6be29c34688cece033014ead7aaee5a0d3fb5
1 /* defaults.c - manage configuration through defaults db
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998 Dan Pascu
7 *
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>
55 #include "WindowMaker.h"
56 #include "wcore.h"
57 #include "framewin.h"
58 #include "window.h"
59 #include "texture.h"
60 #include "screen.h"
61 #include "resources.h"
62 #include "defaults.h"
63 #include "keybind.h"
64 #include "xmodifier.h"
65 #include "icon.h"
66 #include "funcs.h"
67 #include "actions.h"
68 #include "dock.h"
69 #include "workspace.h"
70 #include "properties.h"
74 * Our own proplist reader parser. This one will not accept any
75 * syntax errors and is more descriptive in the error messages.
76 * It also doesn't seem to crash.
78 extern proplist_t ReadProplistFromFile(char *file);
81 /***** Global *****/
83 extern WDDomain *WDWindowMaker;
84 extern WDDomain *WDWindowAttributes;
85 extern WDDomain *WDRootMenu;
87 extern int wScreenCount;
89 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
90 extern Atom _XA_WINDOWMAKER_ICON_TILE;
93 extern proplist_t wDomainName;
94 extern proplist_t wAttributeDomainName;
96 extern WPreferences wPreferences;
98 extern WShortKey wKeyBindings[WKBD_LAST];
100 typedef struct {
101 char *key;
102 char *default_value;
103 void *extra_data;
104 void *addr;
105 int (*convert)();
106 int (*update)();
107 proplist_t plkey;
108 proplist_t plvalue; /* default value */
109 } WDefaultEntry;
112 /* used to map strings to integers */
113 typedef struct {
114 char *string;
115 short value;
116 char is_alias;
117 } WOptionEnumeration;
120 /* type converters */
121 static int getBool();
122 static int getInt();
123 static int getCoord();
124 #if 0
125 /* this is not used yet */
126 static int getString();
127 #endif
128 static int getPathList();
129 static int getEnum();
130 static int getTexture();
131 static int getWSBackground();
132 static int getWSSpecificBackground();
133 static int getFont();
134 static int getColor();
135 static int getKeybind();
136 static int getModMask();
137 #ifdef NEWSTUFF
138 static int getRImage();
139 #endif
142 /* value setting functions */
143 static int setJustify();
144 static int setClearance();
145 static int setIfDockPresent();
146 static int setStickyIcons();
148 static int setPositive();
150 static int setWidgetColor();
151 static int setIconTile();
152 static int setWinTitleFont();
153 static int setMenuTitleFont();
154 static int setMenuTextFont();
155 static int setIconTitleFont();
156 static int setIconTitleColor();
157 static int setIconTitleBack();
158 static int setLargeDisplayFont();
159 static int setWTitleColor();
160 static int setFTitleBack();
161 static int setPTitleBack();
162 static int setUTitleBack();
163 static int setResizebarBack();
164 static int setWorkspaceBack();
165 static int setWorkspaceSpecificBack();
166 static int setMenuTitleColor();
167 static int setMenuTextColor();
168 static int setMenuDisabledColor();
169 static int setMenuTitleBack();
170 static int setMenuTextBack();
171 static int setHightlight();
172 static int setHightlightText();
173 static int setKeyGrab();
174 static int setDoubleClick();
175 static int setIconPosition();
177 static int setClipTitleFont();
178 static int setClipTitleColor();
180 static int setMenuStyle();
181 #if 0
182 static int setMultiByte();
183 #endif
184 static int updateUsableArea();
186 #ifdef DEFINABLE_CURSOR
187 extern Cursor wCursor[WCUR_LAST];
188 static int getCursor();
189 static int setCursor();
190 #endif
194 * Tables to convert strings to enumeration values.
195 * Values stored are char
199 /* WARNING: sum of length of all value strings must not exceed
200 * this value */
201 #define TOTAL_VALUES_LENGTH 80
206 #define REFRESH_WINDOW_TEXTURES (1<<0)
207 #define REFRESH_MENU_TEXTURE (1<<1)
208 #define REFRESH_MENU_FONT (1<<2)
209 #define REFRESH_MENU_COLOR (1<<3)
210 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
211 #define REFRESH_MENU_TITLE_FONT (1<<5)
212 #define REFRESH_MENU_TITLE_COLOR (1<<6)
213 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
214 #define REFRESH_WINDOW_FONT (1<<8)
215 #define REFRESH_ICON_TILE (1<<9)
216 #define REFRESH_ICON_FONT (1<<10)
217 #define REFRESH_WORKSPACE_BACK (1<<11)
219 #define REFRESH_BUTTON_IMAGES (1<<12)
221 #define REFRESH_ICON_TITLE_COLOR (1<<13)
222 #define REFRESH_ICON_TITLE_BACK (1<<14)
226 static WOptionEnumeration seFocusModes[] = {
227 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
228 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
229 {NULL, 0, 0}
232 static WOptionEnumeration seColormapModes[] = {
233 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
234 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
235 {NULL, 0, 0}
238 static WOptionEnumeration sePlacements[] = {
239 {"Auto", WPM_AUTO, 0},
240 {"Smart", WPM_SMART, 0},
241 {"Cascade", WPM_CASCADE, 0},
242 {"Random", WPM_RANDOM, 0},
243 {"Manual", WPM_MANUAL, 0},
244 {NULL, 0, 0}
247 static WOptionEnumeration seGeomDisplays[] = {
248 {"None", WDIS_NONE, 0},
249 {"Center", WDIS_CENTER, 0},
250 {"Corner", WDIS_TOPLEFT, 0},
251 {"Floating", WDIS_FRAME_CENTER, 0},
252 {"Line", WDIS_NEW, 0},
253 {NULL, 0, 0}
256 static WOptionEnumeration seSpeeds[] = {
257 {"UltraFast", SPEED_ULTRAFAST, 0},
258 {"Fast", SPEED_FAST, 0},
259 {"Medium", SPEED_MEDIUM, 0},
260 {"Slow", SPEED_SLOW, 0},
261 {"UltraSlow", SPEED_ULTRASLOW, 0},
262 {NULL, 0, 0}
265 static WOptionEnumeration seMouseButtonActions[] = {
266 {"None", WA_NONE, 0},
267 {"SelectWindows", WA_SELECT_WINDOWS, 0},
268 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
269 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
270 {NULL, 0, 0}
273 static WOptionEnumeration seMouseWheelActions[] = {
274 {"None", WA_NONE, 0},
275 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
276 {NULL, 0, 0}
279 static WOptionEnumeration seIconificationStyles[] = {
280 {"Zoom", WIS_ZOOM, 0},
281 {"Twist", WIS_TWIST, 0},
282 {"Flip", WIS_FLIP, 0},
283 {"None", WIS_NONE, 0},
284 {"random", WIS_RANDOM, 0},
285 {NULL, 0, 0}
288 static WOptionEnumeration seJustifications[] = {
289 {"Left", WTJ_LEFT, 0},
290 {"Center", WTJ_CENTER, 0},
291 {"Right", WTJ_RIGHT, 0},
292 {NULL, 0, 0}
295 static WOptionEnumeration seIconPositions[] = {
296 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
297 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
298 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
299 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
300 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
301 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
302 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
303 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
304 {NULL, 0, 0}
307 static WOptionEnumeration seMenuStyles[] = {
308 {"normal", MS_NORMAL, 0},
309 {"singletexture", MS_SINGLE_TEXTURE, 0},
310 {"flat", MS_FLAT, 0},
311 {NULL, 0, 0}
315 static WOptionEnumeration seDisplayPositions[] = {
316 {"none", WD_NONE, 0},
317 {"center", WD_CENTER, 0},
318 {"top", WD_TOP, 0},
319 {"bottom", WD_BOTTOM, 0},
320 {"topleft", WD_TOPLEFT, 0},
321 {"topright", WD_TOPRIGHT, 0},
322 {"bottomleft", WD_BOTTOMLEFT, 0},
323 {"bottomright", WD_BOTTOMRIGHT, 0},
324 {NULL, 0, 0}
327 static WOptionEnumeration seWorkspaceBorder[] = {
328 {"None", WB_NONE, 0},
329 {"LeftRight", WB_LEFTRIGHT, 0},
330 {"TopBottom", WB_TOPBOTTOM, 0},
331 {"AllDirections", WB_ALLDIRS, 0},
332 {NULL, 0, 0}
337 * ALL entries in the tables bellow, NEED to have a default value
338 * defined, and this value needs to be correct.
341 /* these options will only affect the window manager on startup
343 * static defaults can't access the screen data, because it is
344 * created after these defaults are read
346 WDefaultEntry staticOptionList[] = {
348 {"ColormapSize", "4", NULL,
349 &wPreferences.cmap_size, getInt, NULL
351 {"DisableDithering", "NO", NULL,
352 &wPreferences.no_dithering, getBool, NULL
354 /* static by laziness */
355 {"IconSize", "64", NULL,
356 &wPreferences.icon_size, getInt, NULL
358 {"ModifierKey", "Mod1", NULL,
359 &wPreferences.modifier_mask, getModMask, NULL
361 {"DisableWSMouseActions", "NO", NULL,
362 &wPreferences.disable_root_mouse, getBool, NULL
364 {"FocusMode", "manual", seFocusModes,
365 &wPreferences.focus_mode, getEnum, NULL
366 }, /* have a problem when switching from manual to sloppy without restart */
367 {"NewStyle", "NO", NULL,
368 &wPreferences.new_style, getBool, NULL
370 {"DisableDock", "NO", (void*) WM_DOCK,
371 NULL, getBool, setIfDockPresent
373 {"DisableClip", "NO", (void*) WM_CLIP,
374 NULL, getBool, setIfDockPresent
376 {"DisableMiniwindows", "NO", NULL,
377 &wPreferences.disable_miniwindows, getBool, NULL
379 #if 0
380 ,{"MultiByteText", "NO", NULL,
381 &wPreferences.multi_byte_text, getBool, setMultiByte
383 #endif
388 WDefaultEntry optionList[] = {
389 /* dynamic options */
390 {"IconPosition", "blh", seIconPositions,
391 &wPreferences.icon_yard, getEnum, setIconPosition
393 {"IconificationStyle", "Zoom", seIconificationStyles,
394 &wPreferences.iconification_style, getEnum, NULL
396 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
397 &wPreferences.mouse_button1, getEnum, NULL
399 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
400 &wPreferences.mouse_button2, getEnum, NULL
402 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
403 &wPreferences.mouse_button3, getEnum, NULL
405 {"MouseWheelAction", "None", seMouseWheelActions,
406 &wPreferences.mouse_wheel, getEnum, NULL
408 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
409 &wPreferences.pixmap_path, getPathList, NULL
411 {"IconPath", DEF_ICON_PATHS, NULL,
412 &wPreferences.icon_path, getPathList, NULL
414 {"ColormapMode", "auto", seColormapModes,
415 &wPreferences.colormap_mode, getEnum, NULL
417 {"AutoFocus", "NO", NULL,
418 &wPreferences.auto_focus, getBool, NULL
420 {"RaiseDelay", "0", NULL,
421 &wPreferences.raise_delay, getInt, NULL
423 {"WindozeCycling", "NO", NULL,
424 &wPreferences.windows_cycling,getBool, NULL
426 {"CirculateRaise", "NO", NULL,
427 &wPreferences.circ_raise, getBool, NULL
429 {"Superfluous", "NO", NULL,
430 &wPreferences.superfluous, getBool, NULL
432 {"AdvanceToNewWorkspace", "NO", NULL,
433 &wPreferences.ws_advance, getBool, NULL
435 {"CycleWorkspaces", "NO", NULL,
436 &wPreferences.ws_cycle, getBool, NULL
438 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
439 &wPreferences.workspace_name_display_position, getEnum, NULL
441 {"WorkspaceBorder", "None", seWorkspaceBorder,
442 &wPreferences.workspace_border_position, getEnum, updateUsableArea
444 {"WorkspaceBorderSize", "0", NULL,
445 &wPreferences.workspace_border_size, getInt, updateUsableArea
447 #ifdef VIRTUAL_DESKTOP
448 {"VirtualEdgeThickness", "1", NULL,
449 &wPreferences.vedge_thickness, getInt, NULL
451 {"VirtualEdgeExtendSpace", "0", NULL,
452 &wPreferences.vedge_bordersize, getInt, NULL
454 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
455 &wPreferences.vedge_hscrollspeed, getInt, NULL
457 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
458 &wPreferences.vedge_vscrollspeed, getInt, NULL
460 {"VirtualEdgeMaximumWidth", "3000", NULL,
461 &wPreferences.vedge_maxwidth, getInt, NULL
463 {"VirtualEdgeMaximumHeight", "3000", NULL,
464 &wPreferences.vedge_maxheight, getInt, NULL
466 #endif
467 {"StickyIcons", "NO", NULL,
468 &wPreferences.sticky_icons, getBool, setStickyIcons
470 {"SaveSessionOnExit", "NO", NULL,
471 &wPreferences.save_session_on_exit, getBool, NULL
473 {"WrapMenus", "NO", NULL,
474 &wPreferences.wrap_menus, getBool, NULL
476 {"ScrollableMenus", "NO", NULL,
477 &wPreferences.scrollable_menus, getBool, NULL
479 {"MenuScrollSpeed", "medium", seSpeeds,
480 &wPreferences.menu_scroll_speed, getEnum, NULL
482 {"IconSlideSpeed", "medium", seSpeeds,
483 &wPreferences.icon_slide_speed, getEnum, NULL
485 {"ShadeSpeed", "medium", seSpeeds,
486 &wPreferences.shade_speed, getEnum, NULL
488 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
489 &wPreferences.dblclick_time, getInt, setDoubleClick,
491 {"AlignSubmenus", "NO", NULL,
492 &wPreferences.align_menus, getBool, NULL
494 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
495 &wPreferences.open_transients_with_parent, getBool, NULL
497 {"WindowPlacement", "auto", sePlacements,
498 &wPreferences.window_placement, getEnum, NULL
500 {"IgnoreFocusClick","NO", NULL,
501 &wPreferences.ignore_focus_click, getBool, NULL
503 {"UseSaveUnders", "NO", NULL,
504 &wPreferences.use_saveunders, getBool, NULL
506 {"OpaqueMove", "NO", NULL,
507 &wPreferences.opaque_move, getBool, NULL
509 {"DisableSound", "NO", NULL,
510 &wPreferences.no_sound, getBool, NULL
512 {"DisableAnimations", "NO", NULL,
513 &wPreferences.no_animations, getBool, NULL
515 {"DontLinkWorkspaces","NO", NULL,
516 &wPreferences.no_autowrap, getBool, NULL
518 {"AutoArrangeIcons", "NO", NULL,
519 &wPreferences.auto_arrange_icons, getBool, NULL
521 {"NoWindowOverDock", "NO", NULL,
522 &wPreferences.no_window_over_dock, getBool, updateUsableArea
524 {"NoWindowOverIcons", "NO", NULL,
525 &wPreferences.no_window_over_icons, getBool, updateUsableArea
527 {"WindowPlaceOrigin", "(0, 0)", NULL,
528 &wPreferences.window_place_origin, getCoord, NULL
530 {"ResizeDisplay", "corner", seGeomDisplays,
531 &wPreferences.size_display, getEnum, NULL
533 {"MoveDisplay", "corner", seGeomDisplays,
534 &wPreferences.move_display, getEnum, NULL
536 {"DontConfirmKill", "NO", NULL,
537 &wPreferences.dont_confirm_kill, getBool,NULL
539 {"WindowTitleBalloons", "NO", NULL,
540 &wPreferences.window_balloon, getBool, NULL
542 {"MiniwindowTitleBalloons", "NO", NULL,
543 &wPreferences.miniwin_balloon,getBool, NULL
545 {"AppIconBalloons", "NO", NULL,
546 &wPreferences.appicon_balloon,getBool, NULL
548 {"HelpBalloons", "NO", NULL,
549 &wPreferences.help_balloon, getBool, NULL
551 {"EdgeResistance", "30", NULL,
552 &wPreferences.edge_resistance,getInt, NULL
554 {"Attraction", "NO", NULL,
555 &wPreferences.attract, getBool, NULL
557 {"DisableBlinking", "NO", NULL,
558 &wPreferences.dont_blink, getBool, NULL
560 /* style options */
561 {"MenuStyle", "normal", seMenuStyles,
562 &wPreferences.menu_style, getEnum, setMenuStyle
564 {"WidgetColor", "(solid, gray)", NULL,
565 NULL, getTexture, setWidgetColor,
567 {"WorkspaceSpecificBack","()", NULL,
568 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
570 /* WorkspaceBack must come after WorkspaceSpecificBack or
571 * WorkspaceBack wont know WorkspaceSpecificBack was also
572 * specified and 2 copies of wmsetbg will be launched */
573 {"WorkspaceBack", "(solid, black)", NULL,
574 NULL, getWSBackground,setWorkspaceBack
576 {"SmoothWorkspaceBack", "NO", NULL,
577 NULL, getBool, NULL
579 {"IconBack", "(solid, gray)", NULL,
580 NULL, getTexture, setIconTile
582 {"TitleJustify", "center", seJustifications,
583 &wPreferences.title_justification, getEnum, setJustify
585 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
586 NULL, getFont, setWinTitleFont,
588 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
589 &wPreferences.window_title_clearance, getInt, setClearance
591 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
592 &wPreferences.menu_title_clearance, getInt, setClearance
594 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
595 &wPreferences.menu_text_clearance, getInt, setClearance
597 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
598 NULL, getFont, setMenuTitleFont
600 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
601 NULL, getFont, setMenuTextFont
603 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
604 NULL, getFont, setIconTitleFont
606 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
607 NULL, getFont, setClipTitleFont
609 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
610 NULL, getFont, setLargeDisplayFont
612 {"HighlightColor", "white", NULL,
613 NULL, getColor, setHightlight
615 {"HighlightTextColor", "black", NULL,
616 NULL, getColor, setHightlightText
618 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
619 NULL, getColor, setClipTitleColor
621 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
622 NULL, getColor, setClipTitleColor
624 {"FTitleColor", "white", (void*)WS_FOCUSED,
625 NULL, getColor, setWTitleColor
627 {"PTitleColor", "white", (void*)WS_PFOCUSED,
628 NULL, getColor, setWTitleColor
630 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
631 NULL, getColor, setWTitleColor
633 {"FTitleBack", "(solid, black)", NULL,
634 NULL, getTexture, setFTitleBack
636 {"PTitleBack", "(solid, \"#616161\")", NULL,
637 NULL, getTexture, setPTitleBack
639 {"UTitleBack", "(solid, gray)", NULL,
640 NULL, getTexture, setUTitleBack
642 {"ResizebarBack", "(solid, gray)", NULL,
643 NULL, getTexture, setResizebarBack
645 {"MenuTitleColor", "white", NULL,
646 NULL, getColor, setMenuTitleColor
648 {"MenuTextColor", "black", NULL,
649 NULL, getColor, setMenuTextColor
651 {"MenuDisabledColor", "\"#616161\"", NULL,
652 NULL, getColor, setMenuDisabledColor
654 {"MenuTitleBack", "(solid, black)", NULL,
655 NULL, getTexture, setMenuTitleBack
657 {"MenuTextBack", "(solid, gray)", NULL,
658 NULL, getTexture, setMenuTextBack
660 {"IconTitleColor", "white", NULL,
661 NULL, getColor, setIconTitleColor
663 {"IconTitleBack", "black", NULL,
664 NULL, getColor, setIconTitleBack
666 /* keybindings */
667 #ifndef LITE
668 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
669 NULL, getKeybind, setKeyGrab
671 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
672 NULL, getKeybind, setKeyGrab
674 #endif /* LITE */
675 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
676 NULL, getKeybind, setKeyGrab
678 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
679 NULL, getKeybind, setKeyGrab
681 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
682 NULL, getKeybind, setKeyGrab
684 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
685 NULL, getKeybind, setKeyGrab
687 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
688 NULL, getKeybind, setKeyGrab
690 {"HideKey", "None", (void*)WKBD_HIDE,
691 NULL, getKeybind, setKeyGrab
693 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
694 NULL, getKeybind, setKeyGrab
696 {"CloseKey", "None", (void*)WKBD_CLOSE,
697 NULL, getKeybind, setKeyGrab
699 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
700 NULL, getKeybind, setKeyGrab
702 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
703 NULL, getKeybind, setKeyGrab
705 {"HMaximizeKey", "None", (void*)WKBD_HMAXIMIZE,
706 NULL, getKeybind, setKeyGrab
708 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
709 NULL, getKeybind, setKeyGrab
711 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
712 NULL, getKeybind, setKeyGrab
714 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
715 NULL, getKeybind, setKeyGrab
717 {"ShadeKey", "None", (void*)WKBD_SHADE,
718 NULL, getKeybind, setKeyGrab
720 {"SelectKey", "None", (void*)WKBD_SELECT,
721 NULL, getKeybind, setKeyGrab
723 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
724 NULL, getKeybind, setKeyGrab
726 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
727 NULL, getKeybind, setKeyGrab
729 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
730 NULL, getKeybind, setKeyGrab
732 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
733 NULL, getKeybind, setKeyGrab
735 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
736 NULL, getKeybind, setKeyGrab
738 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
739 NULL, getKeybind, setKeyGrab
741 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
742 NULL, getKeybind, setKeyGrab
744 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
745 NULL, getKeybind, setKeyGrab
747 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
760 NULL, getKeybind, setKeyGrab
762 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
763 NULL, getKeybind, setKeyGrab
765 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
766 NULL, getKeybind, setKeyGrab
768 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
769 NULL, getKeybind, setKeyGrab
771 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
772 NULL, getKeybind, setKeyGrab
774 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
775 NULL, getKeybind, setKeyGrab
777 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
778 NULL, getKeybind, setKeyGrab
780 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
781 NULL, getKeybind, setKeyGrab
783 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
784 NULL, getKeybind, setKeyGrab
786 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
787 NULL, getKeybind, setKeyGrab
789 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
790 NULL, getKeybind, setKeyGrab
792 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
793 NULL, getKeybind, setKeyGrab
795 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
796 NULL, getKeybind, setKeyGrab
798 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
799 NULL, getKeybind, setKeyGrab
801 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
802 NULL, getKeybind, setKeyGrab
805 #ifdef KEEP_XKB_LOCK_STATUS
806 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
807 NULL, getKeybind, setKeyGrab
809 {"KbdModeLock", "NO", NULL,
810 &wPreferences.modelock, getBool, NULL
812 #endif /* KEEP_XKB_LOCK_STATUS */
813 #ifdef DEFINABLE_CURSOR
814 ,{"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
815 NULL, getCursor, setCursor
817 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
818 NULL, getCursor, setCursor
820 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
821 NULL, getCursor, setCursor
823 {"ResizeCursor", "(builtin, sizing)", (void*)WCUR_RESIZE,
824 NULL, getCursor, setCursor
826 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
827 (void*)WCUR_TOPLEFTRESIZE,
828 NULL, getCursor, setCursor
830 {"TopRightResizeCursor", "(builtin, top_right_corner)",
831 (void*)WCUR_TOPRIGHTRESIZE,
832 NULL, getCursor, setCursor
834 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
835 (void*)WCUR_BOTTOMLEFTRESIZE,
836 NULL, getCursor, setCursor
838 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
839 (void*)WCUR_BOTTOMRIGHTRESIZE,
840 NULL, getCursor, setCursor
842 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
843 (void*)WCUR_VERTICALRESIZE,
844 NULL, getCursor, setCursor
846 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
847 (void*)WCUR_HORIZONRESIZE,
848 NULL, getCursor, setCursor
850 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
851 NULL, getCursor, setCursor
853 {"QuestionCursor", "(builtin, question_arrow)", (void*)WCUR_QUESTION,
854 NULL, getCursor, setCursor
856 {"TextCursor", "(builtin, xterm)", (void*)WCUR_TEXT,
857 NULL, getCursor, setCursor
859 {"SelectCursor", "(builtin, cross)", (void*)WCUR_SELECT,
860 NULL, getCursor, setCursor
862 #endif /* DEFINABLE_CURSOR */
866 #if 0
867 static void rereadDefaults(void);
868 #endif
870 #if 0
871 static void
872 rereadDefaults(void)
874 /* must defer the update because accessing X data from a
875 * signal handler can mess up Xlib */
878 #endif
880 static void
881 initDefaults()
883 int i;
884 WDefaultEntry *entry;
886 PLSetStringCmpHook(StringCompareHook);
888 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
889 entry = &optionList[i];
891 entry->plkey = PLMakeString(entry->key);
892 if (entry->default_value)
893 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
894 else
895 entry->plvalue = NULL;
898 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
899 entry = &staticOptionList[i];
901 entry->plkey = PLMakeString(entry->key);
902 if (entry->default_value)
903 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
904 else
905 entry->plvalue = NULL;
909 wDomainName = PLMakeString(WMDOMAIN_NAME);
910 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
912 PLRegister(wDomainName, rereadDefaults);
913 PLRegister(wAttributeDomainName, rereadDefaults);
920 #if 0
921 proplist_t
922 wDefaultsInit(int screen_number)
924 static int defaults_inited = 0;
925 proplist_t dict;
927 if (!defaults_inited) {
928 initDefaults();
931 dict = PLGetDomain(wDomainName);
932 if (!dict) {
933 wwarning(_("could not read domain \"%s\" from defaults database"),
934 PLGetString(wDomainName));
937 return dict;
939 #endif
942 void
943 wDefaultsDestroyDomain(WDDomain *domain)
945 if (domain->dictionary)
946 PLRelease(domain->dictionary);
947 wfree(domain->path);
948 wfree(domain);
952 WDDomain*
953 wDefaultsInitDomain(char *domain, Bool requireDictionary)
955 WDDomain *db;
956 struct stat stbuf;
957 static int inited = 0;
958 char path[PATH_MAX];
959 char *the_path;
960 proplist_t shared_dict=NULL;
962 if (!inited) {
963 inited = 1;
964 initDefaults();
967 db = wmalloc(sizeof(WDDomain));
968 memset(db, 0, sizeof(WDDomain));
969 db->domain_name = domain;
970 db->path = wdefaultspathfordomain(domain);
971 the_path = db->path;
973 if (the_path && stat(the_path, &stbuf)>=0) {
974 db->dictionary = ReadProplistFromFile(the_path);
975 if (db->dictionary) {
976 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
977 PLRelease(db->dictionary);
978 db->dictionary = NULL;
979 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
980 domain, the_path);
982 db->timestamp = stbuf.st_mtime;
983 } else {
984 wwarning(_("could not load domain %s from user defaults database"),
985 domain);
989 /* global system dictionary */
990 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
991 if (stat(path, &stbuf)>=0) {
992 shared_dict = ReadProplistFromFile(path);
993 if (shared_dict) {
994 if (requireDictionary && !PLIsDictionary(shared_dict)) {
995 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
996 domain, path);
997 PLRelease(shared_dict);
998 shared_dict = NULL;
999 } else {
1000 if (db->dictionary && PLIsDictionary(shared_dict) &&
1001 PLIsDictionary(db->dictionary)) {
1002 PLMergeDictionaries(shared_dict, db->dictionary);
1003 PLRelease(db->dictionary);
1004 db->dictionary = shared_dict;
1005 if (stbuf.st_mtime > db->timestamp)
1006 db->timestamp = stbuf.st_mtime;
1007 } else if (!db->dictionary) {
1008 db->dictionary = shared_dict;
1009 if (stbuf.st_mtime > db->timestamp)
1010 db->timestamp = stbuf.st_mtime;
1013 } else {
1014 wwarning(_("could not load domain %s from global defaults database (%s)"),
1015 domain, path);
1019 /* set to save it in user's directory, no matter from where it was read */
1020 if (db->dictionary) {
1021 proplist_t tmp = PLMakeString(db->path);
1023 PLSetFilename(db->dictionary, tmp);
1024 PLRelease(tmp);
1027 return db;
1031 void
1032 wReadStaticDefaults(proplist_t dict)
1034 proplist_t plvalue;
1035 WDefaultEntry *entry;
1036 int i;
1037 void *tdata;
1040 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1041 entry = &staticOptionList[i];
1043 if (dict)
1044 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1045 else
1046 plvalue = NULL;
1048 if (!plvalue) {
1049 /* no default in the DB. Use builtin default */
1050 plvalue = entry->plvalue;
1053 if (plvalue) {
1054 /* convert data */
1055 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1056 if (entry->update) {
1057 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1064 void
1065 wDefaultsCheckDomains(void *foo)
1067 WScreen *scr;
1068 struct stat stbuf;
1069 proplist_t dict;
1070 int i;
1071 char path[PATH_MAX];
1073 #ifdef HEARTBEAT
1074 puts("Checking domains...");
1075 #endif
1076 if (stat(WDWindowMaker->path, &stbuf)>=0
1077 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1078 proplist_t shared_dict = NULL;
1079 #ifdef HEARTBEAT
1080 puts("Checking WindowMaker domain");
1081 #endif
1082 WDWindowMaker->timestamp = stbuf.st_mtime;
1084 /* global dictionary */
1085 snprintf(path, sizeof(path), "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1086 if (stat(path, &stbuf)>=0) {
1087 shared_dict = ReadProplistFromFile(path);
1088 if (shared_dict && !PLIsDictionary(shared_dict)) {
1089 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1090 "WindowMaker", path);
1091 PLRelease(shared_dict);
1092 shared_dict = NULL;
1093 } else if (!shared_dict) {
1094 wwarning(_("could not load domain %s from global defaults database"),
1095 "WindowMaker");
1098 /* user dictionary */
1099 dict = ReadProplistFromFile(WDWindowMaker->path);
1100 if (dict) {
1101 if (!PLIsDictionary(dict)) {
1102 PLRelease(dict);
1103 dict = NULL;
1104 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1105 "WindowMaker", WDWindowMaker->path);
1106 } else {
1107 if (shared_dict) {
1108 PLSetFilename(shared_dict, PLGetFilename(dict));
1109 PLMergeDictionaries(shared_dict, dict);
1110 PLRelease(dict);
1111 dict = shared_dict;
1112 shared_dict = NULL;
1114 for (i=0; i<wScreenCount; i++) {
1115 scr = wScreenWithNumber(i);
1116 if (scr)
1117 wReadDefaults(scr, dict);
1119 if (WDWindowMaker->dictionary) {
1120 PLRelease(WDWindowMaker->dictionary);
1122 WDWindowMaker->dictionary = dict;
1124 } else {
1125 wwarning(_("could not load domain %s from user defaults database"),
1126 "WindowMaker");
1128 if (shared_dict) {
1129 PLRelease(shared_dict);
1133 if (stat(WDWindowAttributes->path, &stbuf)>=0
1134 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1135 #ifdef HEARTBEAT
1136 puts("Checking WMWindowAttributes domain");
1137 #endif
1138 dict = ReadProplistFromFile(WDWindowAttributes->path);
1139 if (dict) {
1140 if (!PLIsDictionary(dict)) {
1141 PLRelease(dict);
1142 dict = NULL;
1143 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1144 "WMWindowAttributes", WDWindowAttributes->path);
1145 } else {
1146 if (WDWindowAttributes->dictionary)
1147 PLRelease(WDWindowAttributes->dictionary);
1148 WDWindowAttributes->dictionary = dict;
1149 for (i=0; i<wScreenCount; i++) {
1150 scr = wScreenWithNumber(i);
1151 if (scr) {
1152 RImage *image;
1154 wDefaultUpdateIcons(scr);
1156 /* Update the panel image if changed */
1157 /* Don't worry. If the image is the same these
1158 * functions will have no performance impact. */
1159 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1161 if (!image) {
1162 wwarning(_("could not load logo image for panels: %s"),
1163 RMessageForError(RErrorCode));
1164 } else {
1165 WMSetApplicationIconImage(scr->wmscreen, image);
1166 RReleaseImage(image);
1171 } else {
1172 wwarning(_("could not load domain %s from user defaults database"),
1173 "WMWindowAttributes");
1175 WDWindowAttributes->timestamp = stbuf.st_mtime;
1178 #ifndef LITE
1179 if (stat(WDRootMenu->path, &stbuf)>=0
1180 && WDRootMenu->timestamp < stbuf.st_mtime) {
1181 dict = ReadProplistFromFile(WDRootMenu->path);
1182 #ifdef HEARTBEAT
1183 puts("Checking WMRootMenu domain");
1184 #endif
1185 if (dict) {
1186 if (!PLIsArray(dict) && !PLIsString(dict)) {
1187 PLRelease(dict);
1188 dict = NULL;
1189 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1190 "WMRootMenu", WDRootMenu->path);
1191 } else {
1192 if (WDRootMenu->dictionary) {
1193 PLRelease(WDRootMenu->dictionary);
1195 WDRootMenu->dictionary = dict;
1197 } else {
1198 wwarning(_("could not load domain %s from user defaults database"),
1199 "WMRootMenu");
1201 WDRootMenu->timestamp = stbuf.st_mtime;
1203 #endif /* !LITE */
1205 if (!foo)
1206 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1210 void
1211 wReadDefaults(WScreen *scr, proplist_t new_dict)
1213 proplist_t plvalue, old_value;
1214 WDefaultEntry *entry;
1215 int i, must_update;
1216 int update_workspace_back = 0; /* kluge :/ */
1217 int needs_refresh;
1218 void *tdata;
1219 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1220 ? WDWindowMaker->dictionary : NULL);
1222 must_update = 0;
1224 needs_refresh = 0;
1226 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1227 entry = &optionList[i];
1229 if (new_dict)
1230 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1231 else
1232 plvalue = NULL;
1234 if (!old_dict)
1235 old_value = NULL;
1236 else
1237 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1240 if (!plvalue && !old_value) {
1241 /* no default in the DB. Use builtin default */
1242 plvalue = entry->plvalue;
1243 if (plvalue && new_dict) {
1244 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1245 must_update = 1;
1247 } else if (!plvalue) {
1248 /* value was deleted from DB. Keep current value */
1249 continue;
1250 } else if (!old_value) {
1251 /* set value for the 1st time */
1252 } else if (!PLIsEqual(plvalue, old_value)) {
1253 /* value has changed */
1254 } else {
1256 if (strcmp(entry->key, "WorkspaceBack") == 0
1257 && update_workspace_back
1258 && scr->flags.backimage_helper_launched) {
1259 } else {
1260 /* value was not changed since last time */
1261 continue;
1265 if (plvalue) {
1266 #ifdef DEBUG
1267 printf("Updating %s to %s\n", entry->key,
1268 PLGetDescription(plvalue));
1269 #endif
1270 /* convert data */
1271 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1273 * If the WorkspaceSpecificBack data has been changed
1274 * so that the helper will be launched now, we must be
1275 * sure to send the default background texture config
1276 * to the helper.
1278 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1279 && !scr->flags.backimage_helper_launched) {
1280 update_workspace_back = 1;
1282 if (entry->update) {
1283 needs_refresh |=
1284 (*entry->update)(scr, entry, tdata, entry->extra_data);
1290 if (needs_refresh!=0 && !scr->flags.startup) {
1291 int foo;
1293 foo = 0;
1294 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1295 foo |= WTextureSettings;
1296 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1297 foo |= WFontSettings;
1298 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1299 foo |= WColorSettings;
1300 if (foo)
1301 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1302 (void*)foo);
1304 foo = 0;
1305 if (needs_refresh & REFRESH_MENU_TEXTURE)
1306 foo |= WTextureSettings;
1307 if (needs_refresh & REFRESH_MENU_FONT)
1308 foo |= WFontSettings;
1309 if (needs_refresh & REFRESH_MENU_COLOR)
1310 foo |= WColorSettings;
1311 if (foo)
1312 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1313 (void*)foo);
1315 foo = 0;
1316 if (needs_refresh & REFRESH_WINDOW_FONT) {
1317 foo |= WFontSettings;
1319 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1320 foo |= WTextureSettings;
1322 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1323 foo |= WColorSettings;
1325 if (foo)
1326 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1327 (void*)foo);
1329 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1330 foo = 0;
1331 if (needs_refresh & REFRESH_ICON_FONT) {
1332 foo |= WFontSettings;
1334 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1335 foo |= WTextureSettings;
1337 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1338 foo |= WTextureSettings;
1340 if (foo)
1341 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1342 (void*)foo);
1344 if (needs_refresh & REFRESH_ICON_TILE)
1345 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1350 void
1351 wDefaultUpdateIcons(WScreen *scr)
1353 WAppIcon *aicon = scr->app_icon_list;
1354 WWindow *wwin = scr->focused_window;
1355 char *file;
1357 while(aicon) {
1358 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1359 False);
1360 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1361 || (file && !aicon->icon->file)) {
1362 RImage *new_image;
1364 if (aicon->icon->file)
1365 wfree(aicon->icon->file);
1366 aicon->icon->file = wstrdup(file);
1368 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1369 aicon->wm_class);
1370 if (new_image) {
1371 wIconChangeImage(aicon->icon, new_image);
1372 wAppIconPaint(aicon);
1375 aicon = aicon->next;
1378 if (!wPreferences.flags.noclip)
1379 wClipIconPaint(scr->clip_icon);
1381 while (wwin) {
1382 if (wwin->icon && wwin->flags.miniaturized) {
1383 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1384 False);
1385 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1386 || (file && !wwin->icon->file)) {
1387 RImage *new_image;
1389 if (wwin->icon->file)
1390 wfree(wwin->icon->file);
1391 wwin->icon->file = wstrdup(file);
1393 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1394 wwin->wm_class);
1395 if (new_image)
1396 wIconChangeImage(wwin->icon, new_image);
1399 wwin = wwin->prev;
1404 /* --------------------------- Local ----------------------- */
1406 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1407 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1408 entry->key, x); \
1409 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1410 var = entry->default_value;\
1411 } else var = PLGetString(value)\
1417 static int
1418 string2index(proplist_t key, proplist_t val, proplist_t def,
1419 WOptionEnumeration *values)
1421 char *str;
1422 WOptionEnumeration *v;
1423 char buffer[TOTAL_VALUES_LENGTH];
1425 if (PLIsString(val) && (str = PLGetString(val))) {
1426 for (v=values; v->string!=NULL; v++) {
1427 if (strcasecmp(v->string, str)==0)
1428 return v->value;
1432 buffer[0] = 0;
1433 for (v=values; v->string!=NULL; v++) {
1434 if (!v->is_alias) {
1435 if (buffer[0]!=0)
1436 strcat(buffer, ", ");
1437 strcat(buffer, v->string);
1440 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1441 PLGetString(key), buffer);
1443 if (def) {
1444 return string2index(key, val, NULL, values);
1447 return -1;
1454 * value - is the value in the defaults DB
1455 * addr - is the address to store the data
1456 * ret - is the address to store a pointer to a temporary buffer. ret
1457 * must not be freed and is used by the set functions
1459 static int
1460 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1461 void **ret)
1463 static char data;
1464 char *val;
1465 int second_pass=0;
1467 GET_STRING_OR_DEFAULT("Boolean", val);
1469 again:
1470 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1471 || strcasecmp(val, "YES")==0) {
1473 data = 1;
1474 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1475 || strcasecmp(val, "NO")==0) {
1476 data = 0;
1477 } else {
1478 int i;
1479 if (sscanf(val, "%i", &i)==1) {
1480 if (i!=0)
1481 data = 1;
1482 else
1483 data = 0;
1484 } else {
1485 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1486 val, entry->key);
1487 if (second_pass==0) {
1488 val = PLGetString(entry->plvalue);
1489 second_pass = 1;
1490 wwarning(_("using default \"%s\" instead"), val);
1491 goto again;
1493 return False;
1497 if (ret)
1498 *ret = &data;
1500 if (addr) {
1501 *(char*)addr = data;
1504 return True;
1508 static int
1509 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1510 void **ret)
1512 static int data;
1513 char *val;
1516 GET_STRING_OR_DEFAULT("Integer", val);
1518 if (sscanf(val, "%i", &data)!=1) {
1519 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1520 val, entry->key);
1521 val = PLGetString(entry->plvalue);
1522 wwarning(_("using default \"%s\" instead"), val);
1523 if (sscanf(val, "%i", &data)!=1) {
1524 return False;
1528 if (ret)
1529 *ret = &data;
1531 if (addr) {
1532 *(int*)addr = data;
1534 return True;
1538 static int
1539 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1540 void **ret)
1542 static WCoord data;
1543 char *val_x, *val_y;
1544 int nelem, changed=0;
1545 proplist_t elem_x, elem_y;
1547 again:
1548 if (!PLIsArray(value)) {
1549 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1550 entry->key, "Coordinate");
1551 if (changed==0) {
1552 value = entry->plvalue;
1553 changed = 1;
1554 wwarning(_("using default \"%s\" instead"), entry->default_value);
1555 goto again;
1557 return False;
1560 nelem = PLGetNumberOfElements(value);
1561 if (nelem != 2) {
1562 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1563 entry->key);
1564 if (changed==0) {
1565 value = entry->plvalue;
1566 changed = 1;
1567 wwarning(_("using default \"%s\" instead"), entry->default_value);
1568 goto again;
1570 return False;
1573 elem_x = PLGetArrayElement(value, 0);
1574 elem_y = PLGetArrayElement(value, 1);
1576 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1577 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1578 entry->key);
1579 if (changed==0) {
1580 value = entry->plvalue;
1581 changed = 1;
1582 wwarning(_("using default \"%s\" instead"), entry->default_value);
1583 goto again;
1585 return False;
1588 val_x = PLGetString(elem_x);
1589 val_y = PLGetString(elem_y);
1591 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1592 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1593 if (changed==0) {
1594 value = entry->plvalue;
1595 changed = 1;
1596 wwarning(_("using default \"%s\" instead"), entry->default_value);
1597 goto again;
1599 return False;
1602 if (data.x < 0)
1603 data.x = 0;
1604 else if (data.x > scr->scr_width/3)
1605 data.x = scr->scr_width/3;
1606 if (data.y < 0)
1607 data.y = 0;
1608 else if (data.y > scr->scr_height/3)
1609 data.y = scr->scr_height/3;
1611 if (ret)
1612 *ret = &data;
1614 if (addr) {
1615 *(WCoord*)addr = data;
1618 return True;
1622 #if 0
1623 /* This function is not used at the moment. */
1624 static int
1625 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1626 void **ret)
1628 static char *data;
1630 GET_STRING_OR_DEFAULT("String", data);
1632 if (!data) {
1633 data = PLGetString(entry->plvalue);
1634 if (!data)
1635 return False;
1638 if (ret)
1639 *ret = &data;
1641 if (addr)
1642 *(char**)addr = wstrdup(data);
1644 return True;
1646 #endif
1649 static int
1650 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1651 void **ret)
1653 static char *data;
1654 int i, count, len;
1655 char *ptr;
1656 proplist_t d;
1657 int changed=0;
1659 again:
1660 if (!PLIsArray(value)) {
1661 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1662 entry->key, "an array of paths");
1663 if (changed==0) {
1664 value = entry->plvalue;
1665 changed = 1;
1666 wwarning(_("using default \"%s\" instead"), entry->default_value);
1667 goto again;
1669 return False;
1672 i = 0;
1673 count = PLGetNumberOfElements(value);
1674 if (count < 1) {
1675 if (changed==0) {
1676 value = entry->plvalue;
1677 changed = 1;
1678 wwarning(_("using default \"%s\" instead"), entry->default_value);
1679 goto again;
1681 return False;
1684 len = 0;
1685 for (i=0; i<count; i++) {
1686 d = PLGetArrayElement(value, i);
1687 if (!d || !PLIsString(d)) {
1688 count = i;
1689 break;
1691 len += strlen(PLGetString(d))+1;
1694 ptr = data = wmalloc(len+1);
1696 for (i=0; i<count; i++) {
1697 d = PLGetArrayElement(value, i);
1698 if (!d || !PLIsString(d)) {
1699 break;
1701 strcpy(ptr, PLGetString(d));
1702 ptr += strlen(PLGetString(d));
1703 *ptr = ':';
1704 ptr++;
1706 ptr--; *(ptr--) = 0;
1708 if (*(char**)addr!=NULL) {
1709 wfree(*(char**)addr);
1711 *(char**)addr = data;
1713 return True;
1717 static int
1718 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1719 void **ret)
1721 static signed char data;
1723 data = string2index(entry->plkey, value, entry->default_value,
1724 (WOptionEnumeration*)entry->extra_data);
1725 if (data < 0)
1726 return False;
1728 if (ret)
1729 *ret = &data;
1731 if (addr)
1732 *(signed char*)addr = data;
1734 return True;
1740 * (solid <color>)
1741 * (hgradient <color> <color>)
1742 * (vgradient <color> <color>)
1743 * (dgradient <color> <color>)
1744 * (mhgradient <color> <color> ...)
1745 * (mvgradient <color> <color> ...)
1746 * (mdgradient <color> <color> ...)
1747 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1748 * (tpixmap <file> <color>)
1749 * (spixmap <file> <color>)
1750 * (cpixmap <file> <color>)
1751 * (thgradient <file> <opaqueness> <color> <color>)
1752 * (tvgradient <file> <opaqueness> <color> <color>)
1753 * (tdgradient <file> <opaqueness> <color> <color>)
1754 * (function <lib> <function> ...)
1757 static WTexture*
1758 parse_texture(WScreen *scr, proplist_t pl)
1760 proplist_t elem;
1761 char *val;
1762 int nelem;
1763 WTexture *texture=NULL;
1765 nelem = PLGetNumberOfElements(pl);
1766 if (nelem < 1)
1767 return NULL;
1770 elem = PLGetArrayElement(pl, 0);
1771 if (!elem || !PLIsString(elem))
1772 return NULL;
1773 val = PLGetString(elem);
1776 if (strcasecmp(val, "solid")==0) {
1777 XColor color;
1779 if (nelem != 2)
1780 return NULL;
1782 /* get color */
1784 elem = PLGetArrayElement(pl, 1);
1785 if (!elem || !PLIsString(elem))
1786 return NULL;
1787 val = PLGetString(elem);
1789 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1790 wwarning(_("\"%s\" is not a valid color name"), val);
1791 return NULL;
1794 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1795 } else if (strcasecmp(val, "dgradient")==0
1796 || strcasecmp(val, "vgradient")==0
1797 || strcasecmp(val, "hgradient")==0) {
1798 RColor color1, color2;
1799 XColor xcolor;
1800 int type;
1802 if (nelem != 3) {
1803 wwarning(_("bad number of arguments in gradient specification"));
1804 return NULL;
1807 if (val[0]=='d' || val[0]=='D')
1808 type = WTEX_DGRADIENT;
1809 else if (val[0]=='h' || val[0]=='H')
1810 type = WTEX_HGRADIENT;
1811 else
1812 type = WTEX_VGRADIENT;
1815 /* get from color */
1816 elem = PLGetArrayElement(pl, 1);
1817 if (!elem || !PLIsString(elem))
1818 return NULL;
1819 val = PLGetString(elem);
1821 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1822 wwarning(_("\"%s\" is not a valid color name"), val);
1823 return NULL;
1825 color1.alpha = 255;
1826 color1.red = xcolor.red >> 8;
1827 color1.green = xcolor.green >> 8;
1828 color1.blue = xcolor.blue >> 8;
1830 /* get to color */
1831 elem = PLGetArrayElement(pl, 2);
1832 if (!elem || !PLIsString(elem)) {
1833 return NULL;
1835 val = PLGetString(elem);
1837 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1838 wwarning(_("\"%s\" is not a valid color name"), val);
1839 return NULL;
1841 color2.alpha = 255;
1842 color2.red = xcolor.red >> 8;
1843 color2.green = xcolor.green >> 8;
1844 color2.blue = xcolor.blue >> 8;
1846 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1848 } else if (strcasecmp(val, "igradient")==0) {
1849 RColor colors1[2], colors2[2];
1850 int th1, th2;
1851 XColor xcolor;
1852 int i;
1854 if (nelem != 7) {
1855 wwarning(_("bad number of arguments in gradient specification"));
1856 return NULL;
1859 /* get from color */
1860 for (i = 0; i < 2; i++) {
1861 elem = PLGetArrayElement(pl, 1+i);
1862 if (!elem || !PLIsString(elem))
1863 return NULL;
1864 val = PLGetString(elem);
1866 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1867 wwarning(_("\"%s\" is not a valid color name"), val);
1868 return NULL;
1870 colors1[i].alpha = 255;
1871 colors1[i].red = xcolor.red >> 8;
1872 colors1[i].green = xcolor.green >> 8;
1873 colors1[i].blue = xcolor.blue >> 8;
1875 elem = PLGetArrayElement(pl, 3);
1876 if (!elem || !PLIsString(elem))
1877 return NULL;
1878 val = PLGetString(elem);
1879 th1 = atoi(val);
1882 /* get from color */
1883 for (i = 0; i < 2; i++) {
1884 elem = PLGetArrayElement(pl, 4+i);
1885 if (!elem || !PLIsString(elem))
1886 return NULL;
1887 val = PLGetString(elem);
1889 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1890 wwarning(_("\"%s\" is not a valid color name"), val);
1891 return NULL;
1893 colors2[i].alpha = 255;
1894 colors2[i].red = xcolor.red >> 8;
1895 colors2[i].green = xcolor.green >> 8;
1896 colors2[i].blue = xcolor.blue >> 8;
1898 elem = PLGetArrayElement(pl, 6);
1899 if (!elem || !PLIsString(elem))
1900 return NULL;
1901 val = PLGetString(elem);
1902 th2 = atoi(val);
1904 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1905 th2, colors2);
1907 } else if (strcasecmp(val, "mhgradient")==0
1908 || strcasecmp(val, "mvgradient")==0
1909 || strcasecmp(val, "mdgradient")==0) {
1910 XColor color;
1911 RColor **colors;
1912 int i, count;
1913 int type;
1915 if (nelem < 3) {
1916 wwarning(_("too few arguments in multicolor gradient specification"));
1917 return NULL;
1920 if (val[1]=='h' || val[1]=='H')
1921 type = WTEX_MHGRADIENT;
1922 else if (val[1]=='v' || val[1]=='V')
1923 type = WTEX_MVGRADIENT;
1924 else
1925 type = WTEX_MDGRADIENT;
1927 count = nelem-1;
1929 colors = wmalloc(sizeof(RColor*)*(count+1));
1931 for (i=0; i<count; i++) {
1932 elem = PLGetArrayElement(pl, i+1);
1933 if (!elem || !PLIsString(elem)) {
1934 for (--i; i>=0; --i) {
1935 wfree(colors[i]);
1937 wfree(colors);
1938 return NULL;
1940 val = PLGetString(elem);
1942 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1943 wwarning(_("\"%s\" is not a valid color name"), val);
1944 for (--i; i>=0; --i) {
1945 wfree(colors[i]);
1947 wfree(colors);
1948 return NULL;
1949 } else {
1950 colors[i] = wmalloc(sizeof(RColor));
1951 colors[i]->red = color.red >> 8;
1952 colors[i]->green = color.green >> 8;
1953 colors[i]->blue = color.blue >> 8;
1956 colors[i] = NULL;
1958 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1959 } else if (strcasecmp(val, "spixmap")==0 ||
1960 strcasecmp(val, "cpixmap")==0 ||
1961 strcasecmp(val, "tpixmap")==0) {
1962 XColor color;
1963 int type;
1965 if (nelem != 3)
1966 return NULL;
1968 if (val[0] == 's' || val[0] == 'S')
1969 type = WTP_SCALE;
1970 else if (val[0] == 'c' || val[0] == 'C')
1971 type = WTP_CENTER;
1972 else
1973 type = WTP_TILE;
1975 /* get color */
1976 elem = PLGetArrayElement(pl, 2);
1977 if (!elem || !PLIsString(elem)) {
1978 return NULL;
1980 val = PLGetString(elem);
1982 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1983 wwarning(_("\"%s\" is not a valid color name"), val);
1984 return NULL;
1987 /* file name */
1988 elem = PLGetArrayElement(pl, 1);
1989 if (!elem || !PLIsString(elem))
1990 return NULL;
1991 val = PLGetString(elem);
1993 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1994 } else if (strcasecmp(val, "thgradient")==0
1995 || strcasecmp(val, "tvgradient")==0
1996 || strcasecmp(val, "tdgradient")==0) {
1997 RColor color1, color2;
1998 XColor xcolor;
1999 int opacity;
2000 int style;
2002 if (val[1]=='h' || val[1]=='H')
2003 style = WTEX_THGRADIENT;
2004 else if (val[1]=='v' || val[1]=='V')
2005 style = WTEX_TVGRADIENT;
2006 else
2007 style = WTEX_TDGRADIENT;
2009 if (nelem != 5) {
2010 wwarning(_("bad number of arguments in textured gradient specification"));
2011 return NULL;
2014 /* get from color */
2015 elem = PLGetArrayElement(pl, 3);
2016 if (!elem || !PLIsString(elem))
2017 return NULL;
2018 val = PLGetString(elem);
2020 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2021 wwarning(_("\"%s\" is not a valid color name"), val);
2022 return NULL;
2024 color1.alpha = 255;
2025 color1.red = xcolor.red >> 8;
2026 color1.green = xcolor.green >> 8;
2027 color1.blue = xcolor.blue >> 8;
2029 /* get to color */
2030 elem = PLGetArrayElement(pl, 4);
2031 if (!elem || !PLIsString(elem)) {
2032 return NULL;
2034 val = PLGetString(elem);
2036 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2037 wwarning(_("\"%s\" is not a valid color name"), val);
2038 return NULL;
2040 color2.alpha = 255;
2041 color2.red = xcolor.red >> 8;
2042 color2.green = xcolor.green >> 8;
2043 color2.blue = xcolor.blue >> 8;
2045 /* get opacity */
2046 elem = PLGetArrayElement(pl, 2);
2047 if (!elem || !PLIsString(elem))
2048 opacity = 128;
2049 else
2050 val = PLGetString(elem);
2052 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2053 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2054 opacity = 128;
2057 /* get file name */
2058 elem = PLGetArrayElement(pl, 1);
2059 if (!elem || !PLIsString(elem))
2060 return NULL;
2061 val = PLGetString(elem);
2063 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2064 val, opacity);
2066 #ifdef TEXTURE_PLUGIN
2067 else if (strcasecmp(val, "function")==0) {
2068 WTexFunction *function;
2069 void (*initFunc) (Display *, Colormap);
2070 char *lib, *func, **argv;
2071 int i, argc;
2073 if (nelem < 3)
2074 return NULL;
2076 /* get the library name */
2077 elem = PLGetArrayElement(pl, 1);
2078 if (!elem || !PLIsString(elem)) {
2079 return NULL;
2081 lib = PLGetString(elem);
2083 /* get the function name */
2084 elem = PLGetArrayElement(pl, 2);
2085 if (!elem || !PLIsString(elem)) {
2086 return NULL;
2088 func = PLGetString(elem);
2090 argc = nelem - 2;
2091 argv = (char **)wmalloc(argc * sizeof(char *));
2093 /* get the parameters */
2094 argv[0] = wstrdup(func);
2095 for (i = 0; i < argc - 1; i++) {
2096 elem = PLGetArrayElement(pl, 3 + i);
2097 if (!elem || !PLIsString(elem)) {
2098 wfree(argv);
2100 return NULL;
2102 argv[i+1] = wstrdup(PLGetString(elem));
2105 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2107 #ifdef HAVE_DLFCN_H
2108 if (function) {
2109 initFunc = dlsym(function->handle, "initWindowMaker");
2110 if (initFunc) {
2111 initFunc(dpy, scr->w_colormap);
2112 } else {
2113 wwarning(_("could not initialize library %s"), lib);
2115 } else {
2116 wwarning(_("could not find function %s::%s"), lib, func);
2118 #endif /* HAVE_DLFCN_H */
2119 texture = (WTexture*)function;
2121 #endif /* TEXTURE_PLUGIN */
2122 else {
2123 wwarning(_("invalid texture type %s"), val);
2124 return NULL;
2126 return texture;
2131 static int
2132 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2133 void **ret)
2135 static WTexture *texture;
2136 int changed=0;
2138 again:
2139 if (!PLIsArray(value)) {
2140 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2141 entry->key, "Texture");
2142 if (changed==0) {
2143 value = entry->plvalue;
2144 changed = 1;
2145 wwarning(_("using default \"%s\" instead"), entry->default_value);
2146 goto again;
2148 return False;
2151 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2152 proplist_t pl;
2154 pl = PLGetArrayElement(value, 0);
2155 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2156 || strcasecmp(PLGetString(pl), "solid")!=0) {
2157 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2158 entry->key, "Solid Texture");
2160 value = entry->plvalue;
2161 changed = 1;
2162 wwarning(_("using default \"%s\" instead"), entry->default_value);
2163 goto again;
2167 texture = parse_texture(scr, value);
2169 if (!texture) {
2170 wwarning(_("Error in texture specification for key \"%s\""),
2171 entry->key);
2172 if (changed==0) {
2173 value = entry->plvalue;
2174 changed = 1;
2175 wwarning(_("using default \"%s\" instead"), entry->default_value);
2176 goto again;
2178 return False;
2181 if (ret)
2182 *ret = &texture;
2184 if (addr)
2185 *(WTexture**)addr = texture;
2187 return True;
2191 static int
2192 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2193 void *addr, void **ret)
2195 proplist_t elem;
2196 int changed = 0;
2197 char *val;
2198 int nelem;
2200 again:
2201 if (!PLIsArray(value)) {
2202 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2203 "WorkspaceBack", "Texture or None");
2204 if (changed==0) {
2205 value = entry->plvalue;
2206 changed = 1;
2207 wwarning(_("using default \"%s\" instead"), entry->default_value);
2208 goto again;
2210 return False;
2213 /* only do basic error checking and verify for None texture */
2215 nelem = PLGetNumberOfElements(value);
2216 if (nelem > 0) {
2217 elem = PLGetArrayElement(value, 0);
2218 if (!elem || !PLIsString(elem)) {
2219 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2220 if (changed==0) {
2221 value = entry->plvalue;
2222 changed = 1;
2223 wwarning(_("using default \"%s\" instead"), entry->default_value);
2224 goto again;
2226 return False;
2228 val = PLGetString(elem);
2230 if (strcasecmp(val, "None")==0)
2231 return True;
2233 *ret = PLRetain(value);
2235 return True;
2239 static int
2240 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2241 void *addr, void **ret)
2243 proplist_t elem;
2244 int nelem;
2245 int changed = 0;
2247 again:
2248 if (!PLIsArray(value)) {
2249 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2250 "WorkspaceSpecificBack", "an array of textures");
2251 if (changed==0) {
2252 value = entry->plvalue;
2253 changed = 1;
2254 wwarning(_("using default \"%s\" instead"), entry->default_value);
2255 goto again;
2257 return False;
2260 /* only do basic error checking and verify for None texture */
2262 nelem = PLGetNumberOfElements(value);
2263 if (nelem > 0) {
2264 while (nelem--) {
2265 elem = PLGetArrayElement(value, nelem);
2266 if (!elem || !PLIsArray(elem)) {
2267 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2268 nelem);
2273 *ret = PLRetain(value);
2275 #ifdef notworking
2277 * Kluge to force wmsetbg helper to set the default background.
2278 * If the WorkspaceSpecificBack is changed once wmaker has started,
2279 * the WorkspaceBack won't be sent to the helper, unless the user
2280 * changes it's value too. So, we must force this by removing the
2281 * value from the defaults DB.
2283 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2284 proplist_t key = PLMakeString("WorkspaceBack");
2286 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2288 PLRelease(key);
2290 #endif
2291 return True;
2295 static int
2296 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2297 void **ret)
2299 static WMFont *font;
2300 char *val;
2302 GET_STRING_OR_DEFAULT("Font", val);
2304 font = WMCreateFont(scr->wmscreen, val);
2305 if (!font)
2306 font = WMCreateFont(scr->wmscreen, "fixed");
2308 if (!font) {
2309 wfatal(_("could not load any usable font!!!"));
2310 exit(1);
2313 if (ret)
2314 *ret = font;
2316 /* can't assign font value outside update function */
2317 wassertrv(addr == NULL, True);
2319 return True;
2323 static int
2324 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2325 void **ret)
2327 static XColor color;
2328 char *val;
2329 int second_pass=0;
2331 GET_STRING_OR_DEFAULT("Color", val);
2334 again:
2335 if (!wGetColor(scr, val, &color)) {
2336 wwarning(_("could not get color for key \"%s\""),
2337 entry->key);
2338 if (second_pass==0) {
2339 val = PLGetString(entry->plvalue);
2340 second_pass = 1;
2341 wwarning(_("using default \"%s\" instead"), val);
2342 goto again;
2344 return False;
2347 if (ret)
2348 *ret = &color;
2350 assert(addr==NULL);
2352 if (addr)
2353 *(unsigned long*)addr = pixel;
2356 return True;
2361 static int
2362 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2363 void **ret)
2365 static WShortKey shortcut;
2366 KeySym ksym;
2367 char *val;
2368 char *k;
2369 char buf[128], *b;
2372 GET_STRING_OR_DEFAULT("Key spec", val);
2374 if (!val || strcasecmp(val, "NONE")==0) {
2375 shortcut.keycode = 0;
2376 shortcut.modifier = 0;
2377 if (ret)
2378 *ret = &shortcut;
2379 return True;
2382 strcpy(buf, val);
2384 b = (char*)buf;
2386 /* get modifiers */
2387 shortcut.modifier = 0;
2388 while ((k = strchr(b, '+'))!=NULL) {
2389 int mod;
2391 *k = 0;
2392 mod = wXModifierFromKey(b);
2393 if (mod<0) {
2394 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2395 return False;
2397 shortcut.modifier |= mod;
2399 b = k+1;
2402 /* get key */
2403 ksym = XStringToKeysym(b);
2405 if (ksym==NoSymbol) {
2406 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2407 val);
2408 return False;
2411 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2412 if (shortcut.keycode==0) {
2413 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2414 return False;
2417 if (ret)
2418 *ret = &shortcut;
2420 return True;
2424 static int
2425 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2426 void **ret)
2428 static unsigned int mask;
2429 char *str;
2431 GET_STRING_OR_DEFAULT("Modifier Key", str);
2433 if (!str)
2434 return False;
2436 mask = wXModifierFromKey(str);
2437 if (mask < 0) {
2438 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2439 mask = 0;
2440 return False;
2443 if (addr)
2444 *(unsigned int*)addr = mask;
2446 if (ret)
2447 *ret = &mask;
2449 return True;
2453 #ifdef NEWSTUFF
2454 static int
2455 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2456 void *addr, void **ret)
2458 unsigned int mask;
2459 char *str;
2460 RImage *image;
2461 int i, n;
2462 int w, h;
2464 GET_STRING_OR_DEFAULT("Image File Path", str);
2465 if (!str)
2466 return False;
2468 image = RLoadImage(scr->rcontext, str, 0);
2469 if (!image) {
2470 wwarning(_("could not load image in option %s: %s"), entry->key,
2471 RMessageForError(RErrorCode));
2472 return False;
2475 if (*(RImage**)addr) {
2476 RReleaseImage(*(RImage**)addr);
2478 if (addr)
2479 *(RImage**)addr = image;
2481 assert(ret == NULL);
2483 if (ret)
2484 *(RImage**)ret = image;
2487 return True;
2489 #endif
2491 #ifdef DEFINABLE_CURSOR
2493 # include <X11/cursorfont.h>
2494 typedef struct
2496 char *name;
2497 int id;
2498 } WCursorLookup;
2500 #define CURSOR_ID_NONE (XC_num_glyphs)
2502 static WCursorLookup cursor_table[] =
2504 { "X_cursor", XC_X_cursor },
2505 { "arrow", XC_arrow },
2506 { "based_arrow_down", XC_based_arrow_down },
2507 { "based_arrow_up", XC_based_arrow_up },
2508 { "boat", XC_boat },
2509 { "bogosity", XC_bogosity },
2510 { "bottom_left_corner", XC_bottom_left_corner },
2511 { "bottom_right_corner", XC_bottom_right_corner },
2512 { "bottom_side", XC_bottom_side },
2513 { "bottom_tee", XC_bottom_tee },
2514 { "box_spiral", XC_box_spiral },
2515 { "center_ptr", XC_center_ptr },
2516 { "circle", XC_circle },
2517 { "clock", XC_clock },
2518 { "coffee_mug", XC_coffee_mug },
2519 { "cross", XC_cross },
2520 { "cross_reverse", XC_cross_reverse },
2521 { "crosshair", XC_crosshair },
2522 { "diamond_cross", XC_diamond_cross },
2523 { "dot", XC_dot },
2524 { "dotbox", XC_dotbox },
2525 { "double_arrow", XC_double_arrow },
2526 { "draft_large", XC_draft_large },
2527 { "draft_small", XC_draft_small },
2528 { "draped_box", XC_draped_box },
2529 { "exchange", XC_exchange },
2530 { "fleur", XC_fleur },
2531 { "gobbler", XC_gobbler },
2532 { "gumby", XC_gumby },
2533 { "hand1", XC_hand1 },
2534 { "hand2", XC_hand2 },
2535 { "heart", XC_heart },
2536 { "icon", XC_icon },
2537 { "iron_cross", XC_iron_cross },
2538 { "left_ptr", XC_left_ptr },
2539 { "left_side", XC_left_side },
2540 { "left_tee", XC_left_tee },
2541 { "leftbutton", XC_leftbutton },
2542 { "ll_angle", XC_ll_angle },
2543 { "lr_angle", XC_lr_angle },
2544 { "man", XC_man },
2545 { "middlebutton", XC_middlebutton },
2546 { "mouse", XC_mouse },
2547 { "pencil", XC_pencil },
2548 { "pirate", XC_pirate },
2549 { "plus", XC_plus },
2550 { "question_arrow", XC_question_arrow },
2551 { "right_ptr", XC_right_ptr },
2552 { "right_side", XC_right_side },
2553 { "right_tee", XC_right_tee },
2554 { "rightbutton", XC_rightbutton },
2555 { "rtl_logo", XC_rtl_logo },
2556 { "sailboat", XC_sailboat },
2557 { "sb_down_arrow", XC_sb_down_arrow },
2558 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2559 { "sb_left_arrow", XC_sb_left_arrow },
2560 { "sb_right_arrow", XC_sb_right_arrow },
2561 { "sb_up_arrow", XC_sb_up_arrow },
2562 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2563 { "shuttle", XC_shuttle },
2564 { "sizing", XC_sizing },
2565 { "spider", XC_spider },
2566 { "spraycan", XC_spraycan },
2567 { "star", XC_star },
2568 { "target", XC_target },
2569 { "tcross", XC_tcross },
2570 { "top_left_arrow", XC_top_left_arrow },
2571 { "top_left_corner", XC_top_left_corner },
2572 { "top_right_corner", XC_top_right_corner },
2573 { "top_side", XC_top_side },
2574 { "top_tee", XC_top_tee },
2575 { "trek", XC_trek },
2576 { "ul_angle", XC_ul_angle },
2577 { "umbrella", XC_umbrella },
2578 { "ur_angle", XC_ur_angle },
2579 { "watch", XC_watch },
2580 { "xterm", XC_xterm },
2581 { NULL, CURSOR_ID_NONE }
2584 static void
2585 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2587 switch(status) {
2588 case BitmapOpenFailed:
2589 wwarning(_("failed to open bitmap file \"%s\""), filename);
2590 break;
2591 case BitmapFileInvalid:
2592 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2593 break;
2594 case BitmapNoMemory:
2595 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2596 break;
2597 case BitmapSuccess:
2598 XFreePixmap(dpy, bitmap);
2599 break;
2604 * (none)
2605 * (builtin, <cursor_name>)
2606 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2608 static int
2609 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2611 proplist_t elem;
2612 char *val;
2613 int nelem;
2614 int status = 0;
2616 nelem = PLGetNumberOfElements(pl);
2617 if (nelem < 1) {
2618 return(status);
2620 elem = PLGetArrayElement(pl, 0);
2621 if (!elem || !PLIsString(elem)) {
2622 return(status);
2624 val = PLGetString(elem);
2626 if (0 == strcasecmp(val, "none")) {
2627 status = 1;
2628 *cursor = None;
2629 } else if (0 == strcasecmp(val, "builtin")) {
2630 int i;
2631 int cursor_id = CURSOR_ID_NONE;
2633 if (2 != nelem) {
2634 wwarning(_("bad number of arguments in cursor specification"));
2635 return(status);
2637 elem = PLGetArrayElement(pl, 1);
2638 if (!elem || !PLIsString(elem)) {
2639 return(status);
2641 val = PLGetString(elem);
2643 for (i = 0; NULL != cursor_table[i].name; i++) {
2644 if (0 == strcasecmp(val, cursor_table[i].name)) {
2645 cursor_id = cursor_table[i].id;
2646 break;
2649 if (CURSOR_ID_NONE == cursor_id) {
2650 wwarning(_("unknown builtin cursor name \"%s\""), val);
2651 } else {
2652 *cursor = XCreateFontCursor(dpy, cursor_id);
2653 status = 1;
2655 } else if (0 == strcasecmp(val, "bitmap")) {
2656 char *bitmap_name;
2657 char *mask_name;
2658 int bitmap_status;
2659 int mask_status;
2660 Pixmap bitmap;
2661 Pixmap mask;
2662 unsigned int w, h;
2663 int x, y;
2664 XColor fg, bg;
2666 if (3 != nelem) {
2667 wwarning(_("bad number of arguments in cursor specification"));
2668 return(status);
2670 elem = PLGetArrayElement(pl, 1);
2671 if (!elem || !PLIsString(elem)) {
2672 return(status);
2674 val = PLGetString(elem);
2675 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2676 if (!bitmap_name) {
2677 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2678 return(status);
2680 elem = PLGetArrayElement(pl, 2);
2681 if (!elem || !PLIsString(elem)) {
2682 wfree(bitmap_name);
2683 return(status);
2685 val = PLGetString(elem);
2686 mask_name = FindImage(wPreferences.pixmap_path, val);
2687 if (!mask_name) {
2688 wfree(bitmap_name);
2689 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2690 return(status);
2692 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2693 &mask, &x, &y);
2694 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2695 &bitmap, &x, &y);
2696 if ((BitmapSuccess == bitmap_status) &&
2697 (BitmapSuccess == mask_status)) {
2698 fg.pixel = scr->black_pixel;
2699 bg.pixel = scr->white_pixel;
2700 XQueryColor(dpy, scr->w_colormap, &fg);
2701 XQueryColor(dpy, scr->w_colormap, &bg);
2702 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2703 status = 1;
2705 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2706 check_bitmap_status(mask_status, mask_name, mask);
2707 wfree(bitmap_name);
2708 wfree(mask_name);
2710 return(status);
2714 static int
2715 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2716 void **ret)
2718 static Cursor cursor;
2719 int status;
2720 int changed = 0;
2722 again:
2723 if (!PLIsArray(value)) {
2724 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2725 entry->key, "cursor specification");
2726 if (!changed) {
2727 value = entry->plvalue;
2728 changed = 1;
2729 wwarning(_("using default \"%s\" instead"), entry->default_value);
2730 goto again;
2732 return(False);
2734 status = parse_cursor(scr, value, &cursor);
2735 if (!status) {
2736 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2737 if (!changed) {
2738 value = entry->plvalue;
2739 changed = 1;
2740 wwarning(_("using default \"%s\" instead"), entry->default_value);
2741 goto again;
2743 return(False);
2745 if (ret) {
2746 *ret = &cursor;
2748 if (addr) {
2749 *(Cursor *)addr = cursor;
2751 return(True);
2753 #undef CURSOR_ID_NONE
2755 #endif /* DEFINABLE_CURSOR */
2758 /* ---------------- value setting functions --------------- */
2759 static int
2760 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2762 return REFRESH_WINDOW_TITLE_COLOR;
2765 static int
2766 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2768 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2771 static int
2772 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2774 switch (which) {
2775 case WM_DOCK:
2776 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2777 break;
2778 case WM_CLIP:
2779 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2780 break;
2781 default:
2782 break;
2784 return 0;
2788 static int
2789 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2791 if (scr->workspaces) {
2792 wWorkspaceForceChange(scr, scr->current_workspace);
2793 wArrangeIcons(scr, False);
2795 return 0;
2798 #if not_used
2799 static int
2800 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2802 if (*value <= 0)
2803 *(int*)foo = 1;
2805 return 0;
2807 #endif
2811 static int
2812 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2814 Pixmap pixmap;
2815 RImage *img;
2816 int reset = 0;
2818 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2819 wPreferences.icon_size,
2820 ((*texture)->any.type & WREL_BORDER_MASK)
2821 ? WREL_ICON : WREL_FLAT);
2822 if (!img) {
2823 wwarning(_("could not render texture for icon background"));
2824 if (!entry->addr)
2825 wTextureDestroy(scr, *texture);
2826 return 0;
2828 RConvertImage(scr->rcontext, img, &pixmap);
2830 if (scr->icon_tile) {
2831 reset = 1;
2832 RReleaseImage(scr->icon_tile);
2833 XFreePixmap(dpy, scr->icon_tile_pixmap);
2836 scr->icon_tile = img;
2839 /* put the icon in the noticeboard hint */
2840 PropSetIconTileHint(scr, img);
2843 if (!wPreferences.flags.noclip) {
2844 if (scr->clip_tile) {
2845 RReleaseImage(scr->clip_tile);
2847 scr->clip_tile = wClipMakeTile(scr, img);
2850 scr->icon_tile_pixmap = pixmap;
2852 if (scr->def_icon_pixmap) {
2853 XFreePixmap(dpy, scr->def_icon_pixmap);
2854 scr->def_icon_pixmap = None;
2856 if (scr->def_ticon_pixmap) {
2857 XFreePixmap(dpy, scr->def_ticon_pixmap);
2858 scr->def_ticon_pixmap = None;
2861 if (scr->icon_back_texture) {
2862 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2864 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2866 if (scr->clip_balloon)
2867 XSetWindowBackground(dpy, scr->clip_balloon,
2868 (*texture)->any.color.pixel);
2871 * Free the texture as nobody else will use it, nor refer to it.
2873 if (!entry->addr)
2874 wTextureDestroy(scr, *texture);
2876 return (reset ? REFRESH_ICON_TILE : 0);
2881 static int
2882 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2884 if (scr->title_font) {
2885 WMReleaseFont(scr->title_font);
2887 scr->title_font = font;
2889 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2893 static int
2894 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2896 if (scr->menu_title_font) {
2897 WMReleaseFont(scr->menu_title_font);
2900 scr->menu_title_font = font;
2902 return REFRESH_MENU_TITLE_FONT;
2906 static int
2907 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2909 if (scr->menu_entry_font) {
2910 WMReleaseFont(scr->menu_entry_font);
2912 scr->menu_entry_font = font;
2914 return REFRESH_MENU_FONT;
2919 static int
2920 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2922 if (scr->icon_title_font) {
2923 WMReleaseFont(scr->icon_title_font);
2926 scr->icon_title_font = font;
2928 return REFRESH_ICON_FONT;
2932 static int
2933 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2935 if (scr->clip_title_font) {
2936 WMReleaseFont(scr->clip_title_font);
2939 scr->clip_title_font = font;
2941 return REFRESH_ICON_FONT;
2945 static int
2946 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2948 if (scr->workspace_name_font) {
2949 WMReleaseFont(scr->workspace_name_font);
2952 scr->workspace_name_font = font;
2954 return 0;
2958 static int
2959 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2961 if (scr->select_pixel!=scr->white_pixel &&
2962 scr->select_pixel!=scr->black_pixel) {
2963 wFreeColor(scr, scr->select_pixel);
2966 scr->select_pixel = color->pixel;
2968 return REFRESH_MENU_COLOR;
2972 static int
2973 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2975 if (scr->select_text_pixel!=scr->white_pixel &&
2976 scr->select_text_pixel!=scr->black_pixel) {
2977 wFreeColor(scr, scr->select_text_pixel);
2980 scr->select_text_pixel = color->pixel;
2982 return REFRESH_MENU_COLOR;
2986 static int
2987 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2989 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2990 scr->clip_title_pixel[index]!=scr->black_pixel) {
2991 wFreeColor(scr, scr->clip_title_pixel[index]);
2993 scr->clip_title_pixel[index] = color->pixel;
2995 #ifdef GRADIENT_CLIP_ARROW
2996 if (index == CLIP_NORMAL) {
2997 RImage *image;
2998 RColor color1, color2;
2999 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3000 int as = pt - 15; /* 15 = 5+5+5 */
3002 FREE_PIXMAP(scr->clip_arrow_gradient);
3004 color1.red = (color->red >> 8)*6/10;
3005 color1.green = (color->green >> 8)*6/10;
3006 color1.blue = (color->blue >> 8)*6/10;
3008 color2.red = WMIN((color->red >> 8)*20/10, 255);
3009 color2.green = WMIN((color->green >> 8)*20/10, 255);
3010 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3012 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3013 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3014 RReleaseImage(image);
3016 #endif /* GRADIENT_CLIP_ARROW */
3018 return REFRESH_ICON_TITLE_COLOR;
3022 static int
3023 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3025 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3026 scr->window_title_pixel[index]!=scr->black_pixel) {
3027 wFreeColor(scr, scr->window_title_pixel[index]);
3030 scr->window_title_pixel[index] = color->pixel;
3032 if (index == WS_UNFOCUSED)
3033 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3035 return REFRESH_WINDOW_TITLE_COLOR;
3039 static int
3040 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3042 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3043 scr->menu_title_pixel[0]!=scr->black_pixel) {
3044 wFreeColor(scr, scr->menu_title_pixel[0]);
3047 scr->menu_title_pixel[0] = color->pixel;
3048 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3050 return REFRESH_MENU_TITLE_COLOR;
3054 static int
3055 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3057 XGCValues gcv;
3058 #define gcm (GCForeground|GCBackground|GCFillStyle)
3060 if (scr->mtext_pixel!=scr->white_pixel &&
3061 scr->mtext_pixel!=scr->black_pixel) {
3062 wFreeColor(scr, scr->mtext_pixel);
3065 scr->mtext_pixel = color->pixel;
3067 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3070 if (scr->dtext_pixel == scr->mtext_pixel) {
3071 gcv.foreground = scr->white_pixel;
3072 gcv.background = scr->black_pixel;
3073 gcv.fill_style = FillStippled;
3074 } else {
3075 gcv.foreground = scr->dtext_pixel;
3076 gcv.fill_style = FillSolid;
3078 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3080 return REFRESH_MENU_COLOR;
3081 #undef gcm
3085 static int
3086 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3088 XGCValues gcv;
3089 #define gcm (GCForeground|GCBackground|GCFillStyle)
3091 if (scr->dtext_pixel!=scr->white_pixel &&
3092 scr->dtext_pixel!=scr->black_pixel) {
3093 wFreeColor(scr, scr->dtext_pixel);
3096 scr->dtext_pixel = color->pixel;
3098 if (scr->dtext_pixel == scr->mtext_pixel) {
3099 gcv.foreground = scr->white_pixel;
3100 gcv.background = scr->black_pixel;
3101 gcv.fill_style = FillStippled;
3102 } else {
3103 gcv.foreground = scr->dtext_pixel;
3104 gcv.fill_style = FillSolid;
3106 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3108 return REFRESH_MENU_COLOR;
3109 #undef gcm
3112 static int
3113 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3115 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3117 return REFRESH_ICON_TITLE_COLOR;
3121 static int
3122 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3124 if (scr->icon_title_texture) {
3125 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
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, proplist_t value,
3146 void *bar)
3148 int i;
3149 proplist_t val;
3150 char *str;
3152 if (scr->flags.backimage_helper_launched) {
3153 if (PLGetNumberOfElements(value)==0) {
3154 SendHelperMessage(scr, 'C', 0, NULL);
3155 SendHelperMessage(scr, 'K', 0, NULL);
3157 PLRelease(value);
3158 return 0;
3160 } else {
3161 pid_t pid;
3162 int filedes[2];
3164 if (PLGetNumberOfElements(value) == 0)
3165 return 0;
3167 if (pipe(filedes) < 0) {
3168 wsyserror("pipe() failed:can't set workspace specific background image");
3170 PLRelease(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 < PLGetNumberOfElements(value); i++) {
3220 val = PLGetArrayElement(value, i);
3221 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3222 str = PLGetDescription(val);
3224 SendHelperMessage(scr, 'S', i+1, str);
3226 wfree(str);
3227 } else {
3228 SendHelperMessage(scr, 'U', i+1, NULL);
3231 sleep(1);
3233 PLRelease(value);
3234 return 0;
3238 static int
3239 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3240 void *bar)
3242 if (scr->flags.backimage_helper_launched) {
3243 char *str;
3245 if (PLGetNumberOfElements(value)==0) {
3246 SendHelperMessage(scr, 'U', 0, NULL);
3247 } else {
3248 /* set the default workspace background to this one */
3249 str = PLGetDescription(value);
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 (PLGetNumberOfElements(value) > 0) {
3259 char *command;
3260 char *text;
3261 char *dither;
3262 int len;
3264 SetupEnvironment(scr);
3265 text = PLGetDescription(value);
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 PLRelease(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
3459 #ifdef DEFINABLE_CURSOR
3460 static int
3461 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3463 if (None != wCursor[index])
3465 XFreeCursor(dpy, wCursor[index]);
3468 wCursor[index] = *cursor;
3470 if ((WCUR_ROOT == index) && (None != *cursor))
3472 XDefineCursor(dpy, scr->root_win, *cursor);
3475 return 0;
3477 #endif /* DEFINABLE_CURSOR*/