more dnd changes
[wmaker-crm.git] / src / defaults.c
blob0fc8cc7840350af11ce4cf6b753e674774d1df4a
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"
25 #include "plugin.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifdef HAVE_DLFCN_H
40 # include <dlfcn.h>
41 #endif
45 #ifndef PATH_MAX
46 #define PATH_MAX DEFAULT_PATH_MAX
47 #endif
49 #include <X11/Xlib.h>
50 #include <X11/Xutil.h>
51 #include <X11/keysym.h>
53 #include <wraster.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 * Our own proplist reader parser. This one will not accept any
76 * syntax errors and is more descriptive in the error messages.
77 * It also doesn't seem to crash.
79 extern proplist_t ReadProplistFromFile(char *file);
82 /***** Global *****/
84 extern WDDomain *WDWindowMaker;
85 extern WDDomain *WDWindowAttributes;
86 extern WDDomain *WDRootMenu;
88 extern int wScreenCount;
90 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
91 extern Atom _XA_WINDOWMAKER_ICON_TILE;
94 extern proplist_t wDomainName;
95 extern proplist_t wAttributeDomainName;
97 extern WPreferences wPreferences;
99 extern WShortKey wKeyBindings[WKBD_LAST];
101 typedef struct {
102 char *key;
103 char *default_value;
104 void *extra_data;
105 void *addr;
106 int (*convert)();
107 int (*update)();
108 proplist_t plkey;
109 proplist_t plvalue; /* default value */
110 } WDefaultEntry;
113 /* used to map strings to integers */
114 typedef struct {
115 char *string;
116 short value;
117 char is_alias;
118 } WOptionEnumeration;
121 /* type converters */
122 static int getBool();
123 static int getInt();
124 static int getCoord();
125 #if 0
126 /* this is not used yet */
127 static int getString();
128 #endif
129 static int getPathList();
130 static int getEnum();
131 static int getTexture();
132 #ifdef DRAWSTRING_PLUGIN
133 static int getTextRenderer();
134 #endif
135 static int getWSBackground();
136 static int getWSSpecificBackground();
137 static int getFont();
138 static int getColor();
139 static int getKeybind();
140 static int getModMask();
141 #ifdef NEWSTUFF
142 static int getRImage();
143 #endif
146 /* value setting functions */
147 static int setJustify();
148 static int setClearance();
149 static int setIfDockPresent();
150 static int setStickyIcons();
152 static int setPositive();
154 static int setWidgetColor();
155 static int setIconTile();
156 static int setWinTitleFont();
157 static int setMenuTitleFont();
158 static int setMenuTextFont();
159 static int setIconTitleFont();
160 static int setIconTitleColor();
161 static int setIconTitleBack();
162 static int setLargeDisplayFont();
163 static int setWTitleColor();
164 static int setFTitleBack();
165 static int setPTitleBack();
166 static int setUTitleBack();
167 static int setResizebarBack();
168 static int setWorkspaceBack();
169 static int setWorkspaceSpecificBack();
170 static int setMenuTitleColor();
171 static int setMenuTextColor();
172 static int setMenuDisabledColor();
173 static int setMenuTitleBack();
174 static int setMenuTextBack();
175 static int setHightlight();
176 static int setHightlightText();
177 static int setKeyGrab();
178 static int setDoubleClick();
179 static int setIconPosition();
181 static int setClipTitleFont();
182 static int setClipTitleColor();
184 static int setMenuStyle();
185 static int setMultiByte();
187 static int updateUsableArea();
189 #ifdef DEFINABLE_CURSOR
190 extern Cursor wCursor[WCUR_LAST];
191 static int getCursor();
192 static int setCursor();
193 #endif
197 * Tables to convert strings to enumeration values.
198 * Values stored are char
202 /* WARNING: sum of length of all value strings must not exceed
203 * this value */
204 #define TOTAL_VALUES_LENGTH 80
209 #define REFRESH_WINDOW_TEXTURES (1<<0)
210 #define REFRESH_MENU_TEXTURE (1<<1)
211 #define REFRESH_MENU_FONT (1<<2)
212 #define REFRESH_MENU_COLOR (1<<3)
213 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
214 #define REFRESH_MENU_TITLE_FONT (1<<5)
215 #define REFRESH_MENU_TITLE_COLOR (1<<6)
216 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
217 #define REFRESH_WINDOW_FONT (1<<8)
218 #define REFRESH_ICON_TILE (1<<9)
219 #define REFRESH_ICON_FONT (1<<10)
220 #define REFRESH_WORKSPACE_BACK (1<<11)
222 #define REFRESH_BUTTON_IMAGES (1<<12)
224 #define REFRESH_ICON_TITLE_COLOR (1<<13)
225 #define REFRESH_ICON_TITLE_BACK (1<<14)
229 static WOptionEnumeration seFocusModes[] = {
230 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
231 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
232 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
233 {NULL, 0, 0}
236 static WOptionEnumeration seColormapModes[] = {
237 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
238 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
239 {NULL, 0, 0}
242 static WOptionEnumeration sePlacements[] = {
243 {"Auto", WPM_AUTO, 0},
244 {"Smart", WPM_SMART, 0},
245 {"Cascade", WPM_CASCADE, 0},
246 {"Random", WPM_RANDOM, 0},
247 {"Manual", WPM_MANUAL, 0},
248 {NULL, 0, 0}
251 static WOptionEnumeration seGeomDisplays[] = {
252 {"Center", WDIS_CENTER, 0},
253 {"Corner", WDIS_TOPLEFT, 0},
254 {"Floating", WDIS_FRAME_CENTER, 0},
255 {"Line", WDIS_NEW, 0},
256 {NULL, 0, 0}
259 static WOptionEnumeration seSpeeds[] = {
260 {"UltraFast", SPEED_ULTRAFAST, 0},
261 {"Fast", SPEED_FAST, 0},
262 {"Medium", SPEED_MEDIUM, 0},
263 {"Slow", SPEED_SLOW, 0},
264 {"UltraSlow", SPEED_ULTRASLOW, 0},
265 {NULL, 0, 0}
268 static WOptionEnumeration seMouseButtons[] = {
269 {"None", -1, 0},
270 {"Left", Button1, 0}, {"Button1", Button1, 1},
271 {"Middle", Button2, 0}, {"Button2", Button2, 1},
272 {"Right", Button3, 0}, {"Button3", Button3, 1},
273 {"Button4", Button4, 0},
274 {"Button5", Button5, 0},
275 {NULL, 0, 0}
278 static WOptionEnumeration seIconificationStyles[] = {
279 {"Zoom", WIS_ZOOM, 0},
280 {"Twist", WIS_TWIST, 0},
281 {"Flip", WIS_FLIP, 0},
282 {"None", WIS_NONE, 0},
283 {"random", WIS_RANDOM, 0},
284 {NULL, 0, 0}
287 static WOptionEnumeration seJustifications[] = {
288 {"Left", WTJ_LEFT, 0},
289 {"Center", WTJ_CENTER, 0},
290 {"Right", WTJ_RIGHT, 0},
291 {NULL, 0, 0}
294 static WOptionEnumeration seIconPositions[] = {
295 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
296 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
297 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
298 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
299 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
300 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
301 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
302 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
303 {NULL, 0, 0}
306 static WOptionEnumeration seMenuStyles[] = {
307 {"normal", MS_NORMAL, 0},
308 {"singletexture", MS_SINGLE_TEXTURE, 0},
309 {"flat", MS_FLAT, 0},
310 {NULL, 0, 0}
314 static WOptionEnumeration seDisplayPositions[] = {
315 {"none", WD_NONE, 0},
316 {"center", WD_CENTER, 0},
317 {"top", WD_TOP, 0},
318 {"bottom", WD_BOTTOM, 0},
319 {"topleft", WD_TOPLEFT, 0},
320 {"topright", WD_TOPRIGHT, 0},
321 {"bottomleft", WD_BOTTOMLEFT, 0},
322 {"bottomright", WD_BOTTOMRIGHT, 0}
327 * ALL entries in the tables bellow, NEED to have a default value
328 * defined, and this value needs to be correct.
331 /* these options will only affect the window manager on startup
333 * static defaults can't access the screen data, because it is
334 * created after these defaults are read
336 WDefaultEntry staticOptionList[] = {
338 {"ColormapSize", "4", NULL,
339 &wPreferences.cmap_size, getInt, NULL
341 {"DisableDithering", "NO", NULL,
342 &wPreferences.no_dithering, getBool, NULL
344 /* static by laziness */
345 {"IconSize", "64", NULL,
346 &wPreferences.icon_size, getInt, NULL
348 {"ModifierKey", "Mod1", NULL,
349 &wPreferences.modifier_mask, getModMask, NULL
351 {"DisableWSMouseActions", "NO", NULL,
352 &wPreferences.disable_root_mouse, getBool, NULL
354 {"FocusMode", "manual", seFocusModes,
355 &wPreferences.focus_mode, getEnum, NULL
356 }, /* have a problem when switching from manual to sloppy without restart */
357 {"NewStyle", "NO", NULL,
358 &wPreferences.new_style, getBool, NULL
360 {"DisableDock", "NO", (void*) WM_DOCK,
361 NULL, getBool, setIfDockPresent
363 {"DisableClip", "NO", (void*) WM_CLIP,
364 NULL, getBool, setIfDockPresent
366 {"DisableMiniwindows", "NO", NULL,
367 &wPreferences.disable_miniwindows, getBool, NULL
369 {"MultiByteText", "NO", NULL,
370 &wPreferences.multi_byte_text, getBool, setMultiByte
376 WDefaultEntry optionList[] = {
377 /* dynamic options */
378 {"IconPosition", "blh", seIconPositions,
379 &wPreferences.icon_yard, getEnum, setIconPosition
381 {"IconificationStyle", "Zoom", seIconificationStyles,
382 &wPreferences.iconification_style, getEnum, NULL
384 {"SelectWindowsMouseButton", "Left", seMouseButtons,
385 &wPreferences.select_button, getEnum, NULL
387 {"WindowListMouseButton", "Middle", seMouseButtons,
388 &wPreferences.windowl_button, getEnum, NULL
390 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
391 &wPreferences.menu_button, getEnum, NULL
393 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
394 &wPreferences.pixmap_path, getPathList, NULL
396 {"IconPath", DEF_ICON_PATHS, NULL,
397 &wPreferences.icon_path, getPathList, NULL
399 {"ColormapMode", "auto", seColormapModes,
400 &wPreferences.colormap_mode, getEnum, NULL
402 {"AutoFocus", "NO", NULL,
403 &wPreferences.auto_focus, getBool, NULL
405 {"RaiseDelay", "0", NULL,
406 &wPreferences.raise_delay, getInt, NULL
408 {"WindowsCycling", "YES", NULL,
409 &wPreferences.windows_cycling,getBool, NULL
411 {"CirculateRaise", "NO", NULL,
412 &wPreferences.circ_raise, getBool, NULL
414 {"Superfluous", "NO", NULL,
415 &wPreferences.superfluous, getBool, NULL
417 {"AdvanceToNewWorkspace", "NO", NULL,
418 &wPreferences.ws_advance, getBool, NULL
420 {"CycleWorkspaces", "NO", NULL,
421 &wPreferences.ws_cycle, getBool, NULL
423 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
424 &wPreferences.workspace_name_display_position, getEnum, NULL
426 #ifdef VIRTUAL_DESKTOP
427 {"VirtualEdgeThickness", "1", NULL,
428 &wPreferences.vedge_thickness, getInt, NULL
430 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
431 &wPreferences.vedge_hscrollspeed, getInt, NULL
433 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
434 &wPreferences.vedge_vscrollspeed, getInt, NULL
436 {"VirtualEdgeWidth", "2000", NULL,
437 &wPreferences.vedge_width, getInt, NULL
439 {"VirtualEdgeHeight", "2000", NULL,
440 &wPreferences.vedge_height, getInt, NULL
442 #endif
443 {"StickyIcons", "NO", NULL,
444 &wPreferences.sticky_icons, getBool, setStickyIcons
446 {"SaveSessionOnExit", "NO", NULL,
447 &wPreferences.save_session_on_exit, getBool, NULL
449 {"WrapMenus", "NO", NULL,
450 &wPreferences.wrap_menus, getBool, NULL
452 {"ScrollableMenus", "NO", NULL,
453 &wPreferences.scrollable_menus, getBool, NULL
455 {"MenuScrollSpeed", "medium", seSpeeds,
456 &wPreferences.menu_scroll_speed, getEnum, NULL
458 {"IconSlideSpeed", "medium", seSpeeds,
459 &wPreferences.icon_slide_speed, getEnum, NULL
461 {"ShadeSpeed", "medium", seSpeeds,
462 &wPreferences.shade_speed, getEnum, NULL
464 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
465 &wPreferences.dblclick_time, getInt, setDoubleClick,
467 {"AlignSubmenus", "NO", NULL,
468 &wPreferences.align_menus, getBool, NULL
470 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
471 &wPreferences.open_transients_with_parent, getBool, NULL
473 {"WindowPlacement", "auto", sePlacements,
474 &wPreferences.window_placement, getEnum, NULL
476 {"IgnoreFocusClick","NO", NULL,
477 &wPreferences.ignore_focus_click, getBool, NULL
479 {"UseSaveUnders", "NO", NULL,
480 &wPreferences.use_saveunders, getBool, NULL
482 {"OpaqueMove", "NO", NULL,
483 &wPreferences.opaque_move, getBool, NULL
485 {"DisableSound", "NO", NULL,
486 &wPreferences.no_sound, getBool, NULL
488 {"DisableAnimations", "NO", NULL,
489 &wPreferences.no_animations, getBool, NULL
491 {"DontLinkWorkspaces","NO", NULL,
492 &wPreferences.no_autowrap, getBool, NULL
494 {"AutoArrangeIcons", "NO", NULL,
495 &wPreferences.auto_arrange_icons, getBool, NULL
497 {"NoWindowOverDock", "NO", NULL,
498 &wPreferences.no_window_over_dock, getBool, updateUsableArea
500 {"NoWindowOverIcons", "NO", NULL,
501 &wPreferences.no_window_over_icons, getBool, updateUsableArea
503 {"WindowPlaceOrigin", "(0, 0)", NULL,
504 &wPreferences.window_place_origin, getCoord, NULL
506 {"ResizeDisplay", "corner", seGeomDisplays,
507 &wPreferences.size_display, getEnum, NULL
509 {"MoveDisplay", "corner", seGeomDisplays,
510 &wPreferences.move_display, getEnum, NULL
512 {"DontConfirmKill", "NO", NULL,
513 &wPreferences.dont_confirm_kill, getBool,NULL
515 {"WindowTitleBalloons", "NO", NULL,
516 &wPreferences.window_balloon, getBool, NULL
518 {"MiniwindowTitleBalloons", "NO", NULL,
519 &wPreferences.miniwin_balloon,getBool, NULL
521 {"AppIconBalloons", "NO", NULL,
522 &wPreferences.appicon_balloon,getBool, NULL
524 {"HelpBalloons", "NO", NULL,
525 &wPreferences.help_balloon, getBool, NULL
527 {"EdgeResistance", "30", NULL,
528 &wPreferences.edge_resistance,getInt, NULL
530 {"Attraction", "NO", NULL,
531 &wPreferences.attract, getBool, NULL
533 {"DisableBlinking", "NO", NULL,
534 &wPreferences.dont_blink, getBool, NULL
536 /* style options */
537 {"MenuStyle", "normal", seMenuStyles,
538 &wPreferences.menu_style, getEnum, setMenuStyle
540 {"WidgetColor", "(solid, gray)", NULL,
541 NULL, getTexture, setWidgetColor,
543 {"WorkspaceSpecificBack","()", NULL,
544 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
546 /* WorkspaceBack must come after WorkspaceSpecificBack or
547 * WorkspaceBack wont know WorkspaceSpecificBack was also
548 * specified and 2 copies of wmsetbg will be launched */
549 {"WorkspaceBack", "(solid, black)", NULL,
550 NULL, getWSBackground,setWorkspaceBack
552 {"SmoothWorkspaceBack", "NO", NULL,
553 NULL, getBool, NULL
555 {"IconBack", "(solid, gray)", NULL,
556 NULL, getTexture, setIconTile
558 {"TitleJustify", "center", seJustifications,
559 &wPreferences.title_justification, getEnum, setJustify
561 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
562 NULL, getFont, setWinTitleFont,
564 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
565 &wPreferences.window_title_clearance, getInt, setClearance
567 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
568 &wPreferences.menu_title_clearance, getInt, setClearance
570 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
571 &wPreferences.menu_text_clearance, getInt, setClearance
573 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
574 NULL, getFont, setMenuTitleFont
576 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
577 NULL, getFont, setMenuTextFont
579 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
580 NULL, getFont, setIconTitleFont
582 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
583 NULL, getFont, setClipTitleFont
585 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
586 NULL, getFont, setLargeDisplayFont
588 {"HighlightColor", "white", NULL,
589 NULL, getColor, setHightlight
591 {"HighlightTextColor", "black", NULL,
592 NULL, getColor, setHightlightText
594 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
595 NULL, getColor, setClipTitleColor
597 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
598 NULL, getColor, setClipTitleColor
600 #ifdef DRAWSTRING_PLUGIN
601 {"FTitleColor", "white", (void*)WS_FOCUSED,
602 NULL, getTextRenderer, setWTitleColor
604 {"PTitleColor", "white", (void*)WS_PFOCUSED,
605 NULL, getTextRenderer, setWTitleColor
607 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
608 NULL, getTextRenderer, setWTitleColor
610 #else
611 {"FTitleColor", "white", (void*)WS_FOCUSED,
612 NULL, getColor, setWTitleColor
614 {"PTitleColor", "white", (void*)WS_PFOCUSED,
615 NULL, getColor, setWTitleColor
617 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
618 NULL, getColor, setWTitleColor
620 #endif
621 {"FTitleBack", "(solid, black)", NULL,
622 NULL, getTexture, setFTitleBack
624 {"PTitleBack", "(solid, \"#616161\")", NULL,
625 NULL, getTexture, setPTitleBack
627 {"UTitleBack", "(solid, gray)", NULL,
628 NULL, getTexture, setUTitleBack
630 {"ResizebarBack", "(solid, gray)", NULL,
631 NULL, getTexture, setResizebarBack
633 #ifdef DRAWSTRING_PLUGIN
634 {"MenuTitleColor", "white", NULL,
635 NULL, getTextRenderer, setMenuTitleColor
637 #else
638 {"MenuTitleColor", "white", NULL,
639 NULL, getColor, setMenuTitleColor
641 #endif
642 {"MenuTextColor", "black", NULL,
643 NULL, getColor, setMenuTextColor
645 {"MenuDisabledColor", "\"#616161\"", NULL,
646 NULL, getColor, setMenuDisabledColor
648 {"MenuTitleBack", "(solid, black)", NULL,
649 NULL, getTexture, setMenuTitleBack
651 {"MenuTextBack", "(solid, gray)", NULL,
652 NULL, getTexture, setMenuTextBack
654 {"IconTitleColor", "white", NULL,
655 NULL, getColor, setIconTitleColor
657 {"IconTitleBack", "black", NULL,
658 NULL, getColor, setIconTitleBack
660 /* keybindings */
661 #ifndef LITE
662 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
663 NULL, getKeybind, setKeyGrab
665 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
666 NULL, getKeybind, setKeyGrab
668 #endif /* LITE */
669 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
670 NULL, getKeybind, setKeyGrab
672 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
673 NULL, getKeybind, setKeyGrab
675 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
676 NULL, getKeybind, setKeyGrab
678 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
679 NULL, getKeybind, setKeyGrab
681 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
682 NULL, getKeybind, setKeyGrab
684 {"HideKey", "None", (void*)WKBD_HIDE,
685 NULL, getKeybind, setKeyGrab
687 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
688 NULL, getKeybind, setKeyGrab
690 {"CloseKey", "None", (void*)WKBD_CLOSE,
691 NULL, getKeybind, setKeyGrab
693 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
694 NULL, getKeybind, setKeyGrab
696 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
697 NULL, getKeybind, setKeyGrab
699 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
700 NULL, getKeybind, setKeyGrab
702 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
703 NULL, getKeybind, setKeyGrab
705 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
706 NULL, getKeybind, setKeyGrab
708 {"ShadeKey", "None", (void*)WKBD_SHADE,
709 NULL, getKeybind, setKeyGrab
711 {"SelectKey", "None", (void*)WKBD_SELECT,
712 NULL, getKeybind, setKeyGrab
714 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
715 NULL, getKeybind, setKeyGrab
717 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
718 NULL, getKeybind, setKeyGrab
720 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
721 NULL, getKeybind, setKeyGrab
723 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
724 NULL, getKeybind, setKeyGrab
726 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
727 NULL, getKeybind, setKeyGrab
729 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
730 NULL, getKeybind, setKeyGrab
732 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
733 NULL, getKeybind, setKeyGrab
735 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
736 NULL, getKeybind, setKeyGrab
738 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
739 NULL, getKeybind, setKeyGrab
741 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
742 NULL, getKeybind, setKeyGrab
744 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
745 NULL, getKeybind, setKeyGrab
747 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
760 NULL, getKeybind, setKeyGrab
762 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
763 NULL, getKeybind, setKeyGrab
765 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
766 NULL, getKeybind, setKeyGrab
768 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
769 NULL, getKeybind, setKeyGrab
771 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
772 NULL, getKeybind, setKeyGrab
774 #ifdef EXTEND_WINDOWSHORTCUT
775 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
776 NULL, getKeybind, setKeyGrab
778 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
779 NULL, getKeybind, setKeyGrab
781 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
782 NULL, getKeybind, setKeyGrab
784 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
785 NULL, getKeybind, setKeyGrab
787 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
788 NULL, getKeybind, setKeyGrab
790 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
791 NULL, getKeybind, setKeyGrab
793 #endif /* EXTEND_WINDOWSHORTCUT */
795 #ifdef KEEP_XKB_LOCK_STATUS
796 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
797 NULL, getKeybind, setKeyGrab
799 {"KbdModeLock", "NO", NULL,
800 &wPreferences.modelock, getBool, NULL
802 #endif /* KEEP_XKB_LOCK_STATUS */
803 #ifdef DEFINABLE_CURSOR
804 ,{"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
805 NULL, getCursor, setCursor
807 ,{"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
808 NULL, getCursor, setCursor
810 #if 0
811 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
812 NULL, getCursor, setCursor
814 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
815 NULL, getCursor, setCursor
817 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
818 NULL, getCursor, setCursor
820 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
821 NULL, getCursor, setCursor
823 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
824 NULL, getCursor, setCursor
826 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
827 NULL, getCursor, setCursor
829 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
830 NULL, getCursor, setCursor
832 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
833 NULL, getCursor, setCursor
835 {"QuestionCursor", "(builtin, question_arrow)", (void*)WCUR_QUESTION,
836 NULL, getCursor, setCursor
838 {"TextCursor", "(builtin, xterm)", (void*)WCUR_TEXT,
839 NULL, getCursor, setCursor
841 #endif
842 #endif /* DEFINABLE_CURSOR */
846 #if 0
847 static void rereadDefaults(void);
848 #endif
850 #if 0
851 static void
852 rereadDefaults(void)
854 /* must defer the update because accessing X data from a
855 * signal handler can mess up Xlib */
858 #endif
860 static void
861 initDefaults()
863 int i;
864 WDefaultEntry *entry;
866 PLSetStringCmpHook(StringCompareHook);
868 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
869 entry = &optionList[i];
871 entry->plkey = PLMakeString(entry->key);
872 if (entry->default_value)
873 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
874 else
875 entry->plvalue = NULL;
878 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
879 entry = &staticOptionList[i];
881 entry->plkey = PLMakeString(entry->key);
882 if (entry->default_value)
883 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
884 else
885 entry->plvalue = NULL;
889 wDomainName = PLMakeString(WMDOMAIN_NAME);
890 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
892 PLRegister(wDomainName, rereadDefaults);
893 PLRegister(wAttributeDomainName, rereadDefaults);
900 #if 0
901 proplist_t
902 wDefaultsInit(int screen_number)
904 static int defaults_inited = 0;
905 proplist_t dict;
907 if (!defaults_inited) {
908 initDefaults();
911 dict = PLGetDomain(wDomainName);
912 if (!dict) {
913 wwarning(_("could not read domain \"%s\" from defaults database"),
914 PLGetString(wDomainName));
917 return dict;
919 #endif
922 void
923 wDefaultsDestroyDomain(WDDomain *domain)
925 if (domain->dictionary)
926 PLRelease(domain->dictionary);
927 free(domain->path);
928 free(domain);
932 WDDomain*
933 wDefaultsInitDomain(char *domain, Bool requireDictionary)
935 WDDomain *db;
936 struct stat stbuf;
937 static int inited = 0;
938 char path[PATH_MAX];
939 char *the_path;
940 proplist_t shared_dict=NULL;
942 if (!inited) {
943 inited = 1;
944 initDefaults();
947 db = wmalloc(sizeof(WDDomain));
948 memset(db, 0, sizeof(WDDomain));
949 db->domain_name = domain;
950 db->path = wdefaultspathfordomain(domain);
951 the_path = db->path;
953 if (the_path && stat(the_path, &stbuf)>=0) {
954 db->dictionary = ReadProplistFromFile(the_path);
955 if (db->dictionary) {
956 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
957 PLRelease(db->dictionary);
958 db->dictionary = NULL;
959 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
960 domain, the_path);
962 db->timestamp = stbuf.st_mtime;
963 } else {
964 wwarning(_("could not load domain %s from user defaults database"),
965 domain);
969 /* global system dictionary */
970 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
971 if (stat(path, &stbuf)>=0) {
972 shared_dict = ReadProplistFromFile(path);
973 if (shared_dict) {
974 if (requireDictionary && !PLIsDictionary(shared_dict)) {
975 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
976 domain, path);
977 PLRelease(shared_dict);
978 shared_dict = NULL;
979 } else {
980 if (db->dictionary && PLIsDictionary(shared_dict) &&
981 PLIsDictionary(db->dictionary)) {
982 PLMergeDictionaries(shared_dict, db->dictionary);
983 PLRelease(db->dictionary);
984 db->dictionary = shared_dict;
985 if (stbuf.st_mtime > db->timestamp)
986 db->timestamp = stbuf.st_mtime;
987 } else if (!db->dictionary) {
988 db->dictionary = shared_dict;
989 if (stbuf.st_mtime > db->timestamp)
990 db->timestamp = stbuf.st_mtime;
993 } else {
994 wwarning(_("could not load domain %s from global defaults database (%s)"),
995 domain, path);
999 /* set to save it in user's directory, no matter from where it was read */
1000 if (db->dictionary) {
1001 proplist_t tmp = PLMakeString(db->path);
1003 PLSetFilename(db->dictionary, tmp);
1004 PLRelease(tmp);
1007 return db;
1011 void
1012 wReadStaticDefaults(proplist_t dict)
1014 proplist_t plvalue;
1015 WDefaultEntry *entry;
1016 int i;
1017 void *tdata;
1020 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1021 entry = &staticOptionList[i];
1023 if (dict)
1024 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1025 else
1026 plvalue = NULL;
1028 if (!plvalue) {
1029 /* no default in the DB. Use builtin default */
1030 plvalue = entry->plvalue;
1033 if (plvalue) {
1034 /* convert data */
1035 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1036 if (entry->update) {
1037 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1044 void
1045 wDefaultsCheckDomains(void *foo)
1047 WScreen *scr;
1048 struct stat stbuf;
1049 proplist_t dict;
1050 int i;
1051 char path[PATH_MAX];
1053 #ifdef HEARTBEAT
1054 puts("Checking domains...");
1055 #endif
1056 if (stat(WDWindowMaker->path, &stbuf)>=0
1057 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1058 proplist_t shared_dict = NULL;
1059 #ifdef HEARTBEAT
1060 puts("Checking WindowMaker domain");
1061 #endif
1062 WDWindowMaker->timestamp = stbuf.st_mtime;
1064 /* global dictionary */
1065 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1066 if (stat(path, &stbuf)>=0) {
1067 shared_dict = ReadProplistFromFile(path);
1068 if (shared_dict && !PLIsDictionary(shared_dict)) {
1069 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1070 "WindowMaker", path);
1071 PLRelease(shared_dict);
1072 shared_dict = NULL;
1073 } else if (!shared_dict) {
1074 wwarning(_("could not load domain %s from global defaults database"),
1075 "WindowMaker");
1078 /* user dictionary */
1079 dict = ReadProplistFromFile(WDWindowMaker->path);
1080 if (dict) {
1081 if (!PLIsDictionary(dict)) {
1082 PLRelease(dict);
1083 dict = NULL;
1084 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1085 "WindowMaker", WDWindowMaker->path);
1086 } else {
1087 if (shared_dict) {
1088 PLSetFilename(shared_dict, PLGetFilename(dict));
1089 PLMergeDictionaries(shared_dict, dict);
1090 PLRelease(dict);
1091 dict = shared_dict;
1092 shared_dict = NULL;
1094 for (i=0; i<wScreenCount; i++) {
1095 scr = wScreenWithNumber(i);
1096 if (scr)
1097 wReadDefaults(scr, dict);
1099 if (WDWindowMaker->dictionary) {
1100 PLRelease(WDWindowMaker->dictionary);
1102 WDWindowMaker->dictionary = dict;
1104 } else {
1105 wwarning(_("could not load domain %s from user defaults database"),
1106 "WindowMaker");
1108 if (shared_dict) {
1109 PLRelease(shared_dict);
1113 if (stat(WDWindowAttributes->path, &stbuf)>=0
1114 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1115 #ifdef HEARTBEAT
1116 puts("Checking WMWindowAttributes domain");
1117 #endif
1118 dict = ReadProplistFromFile(WDWindowAttributes->path);
1119 if (dict) {
1120 if (!PLIsDictionary(dict)) {
1121 PLRelease(dict);
1122 dict = NULL;
1123 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1124 "WMWindowAttributes", WDWindowAttributes->path);
1125 } else {
1126 if (WDWindowAttributes->dictionary)
1127 PLRelease(WDWindowAttributes->dictionary);
1128 WDWindowAttributes->dictionary = dict;
1129 for (i=0; i<wScreenCount; i++) {
1130 scr = wScreenWithNumber(i);
1131 if (scr)
1132 wDefaultUpdateIcons(scr);
1135 } else {
1136 wwarning(_("could not load domain %s from user defaults database"),
1137 "WMWindowAttributes");
1139 WDWindowAttributes->timestamp = stbuf.st_mtime;
1142 #ifndef LITE
1143 if (stat(WDRootMenu->path, &stbuf)>=0
1144 && WDRootMenu->timestamp < stbuf.st_mtime) {
1145 dict = ReadProplistFromFile(WDRootMenu->path);
1146 #ifdef HEARTBEAT
1147 puts("Checking WMRootMenu domain");
1148 #endif
1149 if (dict) {
1150 if (!PLIsArray(dict) && !PLIsString(dict)) {
1151 PLRelease(dict);
1152 dict = NULL;
1153 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1154 "WMRootMenu", WDRootMenu->path);
1155 } else {
1156 if (WDRootMenu->dictionary) {
1157 PLRelease(WDRootMenu->dictionary);
1159 WDRootMenu->dictionary = dict;
1161 } else {
1162 wwarning(_("could not load domain %s from user defaults database"),
1163 "WMRootMenu");
1165 WDRootMenu->timestamp = stbuf.st_mtime;
1167 #endif /* !LITE */
1169 if (!foo)
1170 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1174 void
1175 wReadDefaults(WScreen *scr, proplist_t new_dict)
1177 proplist_t plvalue, old_value;
1178 WDefaultEntry *entry;
1179 int i, must_update;
1180 int update_workspace_back = 0; /* kluge :/ */
1181 int needs_refresh;
1182 void *tdata;
1183 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1184 ? WDWindowMaker->dictionary : NULL);
1186 must_update = 0;
1188 needs_refresh = 0;
1190 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1191 entry = &optionList[i];
1193 if (new_dict)
1194 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1195 else
1196 plvalue = NULL;
1198 if (!old_dict)
1199 old_value = NULL;
1200 else
1201 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1204 if (!plvalue && !old_value) {
1205 /* no default in the DB. Use builtin default */
1206 plvalue = entry->plvalue;
1207 if (plvalue && new_dict) {
1208 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1209 must_update = 1;
1211 } else if (!plvalue) {
1212 /* value was deleted from DB. Keep current value */
1213 continue;
1214 } else if (!old_value) {
1215 /* set value for the 1st time */
1216 } else if (!PLIsEqual(plvalue, old_value)) {
1217 /* value has changed */
1218 } else {
1220 if (strcmp(entry->key, "WorkspaceBack") == 0
1221 && update_workspace_back
1222 && scr->flags.backimage_helper_launched) {
1223 } else {
1224 /* value was not changed since last time */
1225 continue;
1229 if (plvalue) {
1230 #ifdef DEBUG
1231 printf("Updating %s to %s\n", entry->key,
1232 PLGetDescription(plvalue));
1233 #endif
1234 /* convert data */
1235 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1237 * If the WorkspaceSpecificBack data has been changed
1238 * so that the helper will be launched now, we must be
1239 * sure to send the default background texture config
1240 * to the helper.
1242 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1243 && !scr->flags.backimage_helper_launched) {
1244 update_workspace_back = 1;
1246 if (entry->update) {
1247 needs_refresh |=
1248 (*entry->update)(scr, entry, tdata, entry->extra_data);
1254 if (needs_refresh!=0 && !scr->flags.startup) {
1255 int foo;
1257 foo = 0;
1258 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1259 foo |= WTextureSettings;
1260 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1261 foo |= WFontSettings;
1262 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1263 foo |= WColorSettings;
1264 if (foo)
1265 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1266 (void*)foo);
1268 foo = 0;
1269 if (needs_refresh & REFRESH_MENU_TEXTURE)
1270 foo |= WTextureSettings;
1271 if (needs_refresh & REFRESH_MENU_FONT)
1272 foo |= WFontSettings;
1273 if (needs_refresh & REFRESH_MENU_COLOR)
1274 foo |= WColorSettings;
1275 if (foo)
1276 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1277 (void*)foo);
1279 foo = 0;
1280 if (needs_refresh & REFRESH_WINDOW_FONT) {
1281 foo |= WFontSettings;
1283 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1284 foo |= WTextureSettings;
1286 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1287 foo |= WColorSettings;
1289 if (foo)
1290 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1291 (void*)foo);
1293 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1294 foo = 0;
1295 if (needs_refresh & REFRESH_ICON_FONT) {
1296 foo |= WFontSettings;
1298 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1299 foo |= WTextureSettings;
1301 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1302 foo |= WTextureSettings;
1304 if (foo)
1305 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1306 (void*)foo);
1308 if (needs_refresh & REFRESH_ICON_TILE)
1309 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1314 void
1315 wDefaultUpdateIcons(WScreen *scr)
1317 WAppIcon *aicon = scr->app_icon_list;
1318 WWindow *wwin = scr->focused_window;
1319 char *file;
1321 while(aicon) {
1322 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1323 False);
1324 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1325 || (file && !aicon->icon->file)) {
1326 RImage *new_image;
1328 if (aicon->icon->file)
1329 free(aicon->icon->file);
1330 aicon->icon->file = wstrdup(file);
1332 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1333 aicon->wm_class);
1334 if (new_image) {
1335 wIconChangeImage(aicon->icon, new_image);
1336 wAppIconPaint(aicon);
1339 aicon = aicon->next;
1342 if (!wPreferences.flags.noclip)
1343 wClipIconPaint(scr->clip_icon);
1345 while (wwin) {
1346 if (wwin->icon && wwin->flags.miniaturized) {
1347 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1348 False);
1349 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1350 || (file && !wwin->icon->file)) {
1351 RImage *new_image;
1353 if (wwin->icon->file)
1354 free(wwin->icon->file);
1355 wwin->icon->file = wstrdup(file);
1357 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1358 wwin->wm_class);
1359 if (new_image)
1360 wIconChangeImage(wwin->icon, new_image);
1363 wwin = wwin->prev;
1368 /* --------------------------- Local ----------------------- */
1370 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1371 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1372 entry->key, x); \
1373 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1374 var = entry->default_value;\
1375 } else var = PLGetString(value)\
1381 static int
1382 string2index(proplist_t key, proplist_t val, proplist_t def,
1383 WOptionEnumeration *values)
1385 char *str;
1386 WOptionEnumeration *v;
1387 char buffer[TOTAL_VALUES_LENGTH];
1389 if (PLIsString(val) && (str = PLGetString(val))) {
1390 for (v=values; v->string!=NULL; v++) {
1391 if (strcasecmp(v->string, str)==0)
1392 return v->value;
1396 buffer[0] = 0;
1397 for (v=values; v->string!=NULL; v++) {
1398 if (!v->is_alias) {
1399 if (buffer[0]!=0)
1400 strcat(buffer, ", ");
1401 strcat(buffer, v->string);
1404 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1405 PLGetString(key), buffer);
1407 if (def) {
1408 return string2index(key, val, NULL, values);
1411 return -1;
1418 * value - is the value in the defaults DB
1419 * addr - is the address to store the data
1420 * ret - is the address to store a pointer to a temporary buffer. ret
1421 * must not be freed and is used by the set functions
1423 static int
1424 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1425 void **ret)
1427 static char data;
1428 char *val;
1429 int second_pass=0;
1431 GET_STRING_OR_DEFAULT("Boolean", val);
1433 again:
1434 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1435 || strcasecmp(val, "YES")==0) {
1437 data = 1;
1438 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1439 || strcasecmp(val, "NO")==0) {
1440 data = 0;
1441 } else {
1442 int i;
1443 if (sscanf(val, "%i", &i)==1) {
1444 if (i!=0)
1445 data = 1;
1446 else
1447 data = 0;
1448 } else {
1449 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1450 val, entry->key);
1451 if (second_pass==0) {
1452 val = PLGetString(entry->plvalue);
1453 second_pass = 1;
1454 wwarning(_("using default \"%s\" instead"), val);
1455 goto again;
1457 return False;
1461 if (ret)
1462 *ret = &data;
1464 if (addr) {
1465 *(char*)addr = data;
1468 return True;
1472 static int
1473 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1474 void **ret)
1476 static int data;
1477 char *val;
1480 GET_STRING_OR_DEFAULT("Integer", val);
1482 if (sscanf(val, "%i", &data)!=1) {
1483 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1484 val, entry->key);
1485 val = PLGetString(entry->plvalue);
1486 wwarning(_("using default \"%s\" instead"), val);
1487 if (sscanf(val, "%i", &data)!=1) {
1488 return False;
1492 if (ret)
1493 *ret = &data;
1495 if (addr) {
1496 *(int*)addr = data;
1498 return True;
1502 static int
1503 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1504 void **ret)
1506 static WCoord data;
1507 char *val_x, *val_y;
1508 int nelem, changed=0;
1509 proplist_t elem_x, elem_y;
1511 again:
1512 if (!PLIsArray(value)) {
1513 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1514 entry->key, "Coordinate");
1515 if (changed==0) {
1516 value = entry->plvalue;
1517 changed = 1;
1518 wwarning(_("using default \"%s\" instead"), entry->default_value);
1519 goto again;
1521 return False;
1524 nelem = PLGetNumberOfElements(value);
1525 if (nelem != 2) {
1526 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1527 entry->key);
1528 if (changed==0) {
1529 value = entry->plvalue;
1530 changed = 1;
1531 wwarning(_("using default \"%s\" instead"), entry->default_value);
1532 goto again;
1534 return False;
1537 elem_x = PLGetArrayElement(value, 0);
1538 elem_y = PLGetArrayElement(value, 1);
1540 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1541 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1542 entry->key);
1543 if (changed==0) {
1544 value = entry->plvalue;
1545 changed = 1;
1546 wwarning(_("using default \"%s\" instead"), entry->default_value);
1547 goto again;
1549 return False;
1552 val_x = PLGetString(elem_x);
1553 val_y = PLGetString(elem_y);
1555 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1556 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1557 if (changed==0) {
1558 value = entry->plvalue;
1559 changed = 1;
1560 wwarning(_("using default \"%s\" instead"), entry->default_value);
1561 goto again;
1563 return False;
1566 if (data.x < 0)
1567 data.x = 0;
1568 else if (data.x > scr->scr_width/3)
1569 data.x = scr->scr_width/3;
1570 if (data.y < 0)
1571 data.y = 0;
1572 else if (data.y > scr->scr_height/3)
1573 data.y = scr->scr_height/3;
1575 if (ret)
1576 *ret = &data;
1578 if (addr) {
1579 *(WCoord*)addr = data;
1582 return True;
1586 #if 0
1587 /* This function is not used at the moment. */
1588 static int
1589 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1590 void **ret)
1592 static char *data;
1594 GET_STRING_OR_DEFAULT("String", data);
1596 if (!data) {
1597 data = PLGetString(entry->plvalue);
1598 if (!data)
1599 return False;
1602 if (ret)
1603 *ret = &data;
1605 if (addr)
1606 *(char**)addr = wstrdup(data);
1608 return True;
1610 #endif
1613 static int
1614 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1615 void **ret)
1617 static char *data;
1618 int i, count, len;
1619 char *ptr;
1620 proplist_t d;
1621 int changed=0;
1623 again:
1624 if (!PLIsArray(value)) {
1625 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1626 entry->key, "an array of paths");
1627 if (changed==0) {
1628 value = entry->plvalue;
1629 changed = 1;
1630 wwarning(_("using default \"%s\" instead"), entry->default_value);
1631 goto again;
1633 return False;
1636 i = 0;
1637 count = PLGetNumberOfElements(value);
1638 if (count < 1) {
1639 if (changed==0) {
1640 value = entry->plvalue;
1641 changed = 1;
1642 wwarning(_("using default \"%s\" instead"), entry->default_value);
1643 goto again;
1645 return False;
1648 len = 0;
1649 for (i=0; i<count; i++) {
1650 d = PLGetArrayElement(value, i);
1651 if (!d || !PLIsString(d)) {
1652 count = i;
1653 break;
1655 len += strlen(PLGetString(d))+1;
1658 ptr = data = wmalloc(len+1);
1660 for (i=0; i<count; i++) {
1661 d = PLGetArrayElement(value, i);
1662 if (!d || !PLIsString(d)) {
1663 break;
1665 strcpy(ptr, PLGetString(d));
1666 ptr += strlen(PLGetString(d));
1667 *ptr = ':';
1668 ptr++;
1670 ptr--; *(ptr--) = 0;
1672 if (*(char**)addr!=NULL) {
1673 free(*(char**)addr);
1675 *(char**)addr = data;
1677 return True;
1681 static int
1682 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1683 void **ret)
1685 static signed char data;
1687 data = string2index(entry->plkey, value, entry->default_value,
1688 (WOptionEnumeration*)entry->extra_data);
1689 if (data < 0)
1690 return False;
1692 if (ret)
1693 *ret = &data;
1695 if (addr)
1696 *(signed char*)addr = data;
1698 return True;
1704 * (solid <color>)
1705 * (hgradient <color> <color>)
1706 * (vgradient <color> <color>)
1707 * (dgradient <color> <color>)
1708 * (mhgradient <color> <color> ...)
1709 * (mvgradient <color> <color> ...)
1710 * (tpixmap <file> <color>)
1711 * (spixmap <file> <color>)
1712 * (cpixmap <file> <color>)
1713 * (thgradient <file> <opaqueness> <color> <color>)
1714 * (tvgradient <file> <opaqueness> <color> <color>)
1715 * (tdgradient <file> <opaqueness> <color> <color>)
1716 * (function <lib> <function> ...)
1719 static WTexture*
1720 parse_texture(WScreen *scr, proplist_t pl)
1722 proplist_t elem;
1723 char *val;
1724 int nelem;
1725 WTexture *texture=NULL;
1727 nelem = PLGetNumberOfElements(pl);
1728 if (nelem < 1)
1729 return NULL;
1732 elem = PLGetArrayElement(pl, 0);
1733 if (!elem || !PLIsString(elem))
1734 return NULL;
1735 val = PLGetString(elem);
1738 if (strcasecmp(val, "solid")==0) {
1739 XColor color;
1741 if (nelem != 2)
1742 return NULL;
1744 /* get color */
1746 elem = PLGetArrayElement(pl, 1);
1747 if (!elem || !PLIsString(elem))
1748 return NULL;
1749 val = PLGetString(elem);
1751 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1752 wwarning(_("\"%s\" is not a valid color name"), val);
1753 return NULL;
1756 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1757 } else if (strcasecmp(val, "dgradient")==0
1758 || strcasecmp(val, "vgradient")==0
1759 || strcasecmp(val, "hgradient")==0) {
1760 RColor color1, color2;
1761 XColor xcolor;
1762 int type;
1764 if (nelem != 3) {
1765 wwarning(_("bad number of arguments in gradient specification"));
1766 return NULL;
1769 if (val[0]=='d' || val[0]=='D')
1770 type = WTEX_DGRADIENT;
1771 else if (val[0]=='h' || val[0]=='H')
1772 type = WTEX_HGRADIENT;
1773 else
1774 type = WTEX_VGRADIENT;
1777 /* get from color */
1778 elem = PLGetArrayElement(pl, 1);
1779 if (!elem || !PLIsString(elem))
1780 return NULL;
1781 val = PLGetString(elem);
1783 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1784 wwarning(_("\"%s\" is not a valid color name"), val);
1785 return NULL;
1787 color1.alpha = 255;
1788 color1.red = xcolor.red >> 8;
1789 color1.green = xcolor.green >> 8;
1790 color1.blue = xcolor.blue >> 8;
1792 /* get to color */
1793 elem = PLGetArrayElement(pl, 2);
1794 if (!elem || !PLIsString(elem)) {
1795 return NULL;
1797 val = PLGetString(elem);
1799 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1800 wwarning(_("\"%s\" is not a valid color name"), val);
1801 return NULL;
1803 color2.alpha = 255;
1804 color2.red = xcolor.red >> 8;
1805 color2.green = xcolor.green >> 8;
1806 color2.blue = xcolor.blue >> 8;
1808 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1810 } else if (strcasecmp(val, "mhgradient")==0
1811 || strcasecmp(val, "mvgradient")==0
1812 || strcasecmp(val, "mdgradient")==0) {
1813 XColor color;
1814 RColor **colors;
1815 int i, count;
1816 int type;
1818 if (nelem < 3) {
1819 wwarning(_("too few arguments in multicolor gradient specification"));
1820 return NULL;
1823 if (val[1]=='h' || val[1]=='H')
1824 type = WTEX_MHGRADIENT;
1825 else if (val[1]=='v' || val[1]=='V')
1826 type = WTEX_MVGRADIENT;
1827 else
1828 type = WTEX_MDGRADIENT;
1830 count = nelem-1;
1832 colors = wmalloc(sizeof(RColor*)*(count+1));
1834 for (i=0; i<count; i++) {
1835 elem = PLGetArrayElement(pl, i+1);
1836 if (!elem || !PLIsString(elem)) {
1837 for (--i; i>=0; --i) {
1838 free(colors[i]);
1840 free(colors);
1841 return NULL;
1843 val = PLGetString(elem);
1845 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1846 wwarning(_("\"%s\" is not a valid color name"), val);
1847 for (--i; i>=0; --i) {
1848 free(colors[i]);
1850 free(colors);
1851 return NULL;
1852 } else {
1853 colors[i] = wmalloc(sizeof(RColor));
1854 colors[i]->red = color.red >> 8;
1855 colors[i]->green = color.green >> 8;
1856 colors[i]->blue = color.blue >> 8;
1859 colors[i] = NULL;
1861 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1862 } else if (strcasecmp(val, "spixmap")==0 ||
1863 strcasecmp(val, "cpixmap")==0 ||
1864 strcasecmp(val, "tpixmap")==0) {
1865 XColor color;
1866 int type;
1868 if (nelem != 3)
1869 return NULL;
1871 if (val[0] == 's' || val[0] == 'S')
1872 type = WTP_SCALE;
1873 else if (val[0] == 'c' || val[0] == 'C')
1874 type = WTP_CENTER;
1875 else
1876 type = WTP_TILE;
1878 /* get color */
1879 elem = PLGetArrayElement(pl, 2);
1880 if (!elem || !PLIsString(elem)) {
1881 return NULL;
1883 val = PLGetString(elem);
1885 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1886 wwarning(_("\"%s\" is not a valid color name"), val);
1887 return NULL;
1890 /* file name */
1891 elem = PLGetArrayElement(pl, 1);
1892 if (!elem || !PLIsString(elem))
1893 return NULL;
1894 val = PLGetString(elem);
1896 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1897 } else if (strcasecmp(val, "thgradient")==0
1898 || strcasecmp(val, "tvgradient")==0
1899 || strcasecmp(val, "tdgradient")==0) {
1900 RColor color1, color2;
1901 XColor xcolor;
1902 int opacity;
1903 int style;
1905 if (val[1]=='h' || val[1]=='H')
1906 style = WTEX_THGRADIENT;
1907 else if (val[1]=='v' || val[1]=='V')
1908 style = WTEX_TVGRADIENT;
1909 else
1910 style = WTEX_TDGRADIENT;
1912 if (nelem != 5) {
1913 wwarning(_("bad number of arguments in textured gradient specification"));
1914 return NULL;
1917 /* get from color */
1918 elem = PLGetArrayElement(pl, 3);
1919 if (!elem || !PLIsString(elem))
1920 return NULL;
1921 val = PLGetString(elem);
1923 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1924 wwarning(_("\"%s\" is not a valid color name"), val);
1925 return NULL;
1927 color1.alpha = 255;
1928 color1.red = xcolor.red >> 8;
1929 color1.green = xcolor.green >> 8;
1930 color1.blue = xcolor.blue >> 8;
1932 /* get to color */
1933 elem = PLGetArrayElement(pl, 4);
1934 if (!elem || !PLIsString(elem)) {
1935 return NULL;
1937 val = PLGetString(elem);
1939 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1940 wwarning(_("\"%s\" is not a valid color name"), val);
1941 return NULL;
1943 color2.alpha = 255;
1944 color2.red = xcolor.red >> 8;
1945 color2.green = xcolor.green >> 8;
1946 color2.blue = xcolor.blue >> 8;
1948 /* get opacity */
1949 elem = PLGetArrayElement(pl, 2);
1950 if (!elem || !PLIsString(elem))
1951 opacity = 128;
1952 else
1953 val = PLGetString(elem);
1955 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1956 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1957 opacity = 128;
1960 /* get file name */
1961 elem = PLGetArrayElement(pl, 1);
1962 if (!elem || !PLIsString(elem))
1963 return NULL;
1964 val = PLGetString(elem);
1966 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1967 val, opacity);
1969 #ifdef TEXTURE_PLUGIN
1970 else if (strcasecmp(val, "function")==0) {
1971 WTexFunction *function;
1972 void (*initFunc) (Display *, Colormap);
1973 char *lib, *func, **argv;
1974 int i, argc;
1976 if (nelem < 3)
1977 return NULL;
1979 /* get the library name */
1980 elem = PLGetArrayElement(pl, 1);
1981 if (!elem || !PLIsString(elem)) {
1982 return NULL;
1984 lib = PLGetString(elem);
1986 /* get the function name */
1987 elem = PLGetArrayElement(pl, 2);
1988 if (!elem || !PLIsString(elem)) {
1989 return NULL;
1991 func = PLGetString(elem);
1993 argc = nelem - 2;
1994 argv = (char **)wmalloc(argc * sizeof(char *));
1996 /* get the parameters */
1997 argv[0] = wstrdup(func);
1998 for (i = 0; i < argc - 1; i++) {
1999 elem = PLGetArrayElement(pl, 3 + i);
2000 if (!elem || !PLIsString(elem)) {
2001 free(argv);
2003 return NULL;
2005 argv[i+1] = wstrdup(PLGetString(elem));
2008 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2010 #ifdef HAVE_DLFCN_H
2011 if (function) {
2012 initFunc = dlsym(function->handle, "initWindowMaker");
2013 if (initFunc) {
2014 initFunc(dpy, scr->w_colormap);
2015 } else {
2016 wwarning(_("could not initialize library %s"), lib);
2018 } else {
2019 wwarning(_("could not find function %s::%s"), lib, func);
2021 #endif /* HAVE_DLFCN_H */
2022 texture = (WTexture*)function;
2024 #endif /* TEXTURE_PLUGIN */
2025 else {
2026 wwarning(_("invalid texture type %s"), val);
2027 return NULL;
2029 return texture;
2034 static int
2035 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2036 void **ret)
2038 static WTexture *texture;
2039 int changed=0;
2041 again:
2042 if (!PLIsArray(value)) {
2043 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2044 entry->key, "Texture");
2045 if (changed==0) {
2046 value = entry->plvalue;
2047 changed = 1;
2048 wwarning(_("using default \"%s\" instead"), entry->default_value);
2049 goto again;
2051 return False;
2054 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2055 proplist_t pl;
2057 pl = PLGetArrayElement(value, 0);
2058 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2059 || strcasecmp(PLGetString(pl), "solid")!=0) {
2060 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2061 entry->key, "Solid Texture");
2063 value = entry->plvalue;
2064 changed = 1;
2065 wwarning(_("using default \"%s\" instead"), entry->default_value);
2066 goto again;
2070 texture = parse_texture(scr, value);
2072 if (!texture) {
2073 wwarning(_("Error in texture specification for key \"%s\""),
2074 entry->key);
2075 if (changed==0) {
2076 value = entry->plvalue;
2077 changed = 1;
2078 wwarning(_("using default \"%s\" instead"), entry->default_value);
2079 goto again;
2081 return False;
2084 if (ret)
2085 *ret = &texture;
2087 if (addr)
2088 *(WTexture**)addr = texture;
2090 return True;
2095 #ifdef DRAWSTRING_PLUGIN
2096 static int
2097 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2098 void *addr, void **ret)
2100 proplist_t elem;
2101 char *val, *lib, *func, **argv;
2102 int argc, changed;
2104 if (strcmp(entry->key, "FTitleColor")==0) {
2105 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2106 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2107 } else if (strcmp(entry->key, "UTitleColor")==0) {
2108 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2109 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2110 } else if (strcmp(entry->key, "PTitleColor")==0) {
2111 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2112 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2113 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2114 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2115 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2116 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2117 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2118 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2121 if (PLIsArray(value)) {
2122 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2123 argc -= 2;
2124 argv = (char **)wmalloc(argc * sizeof(char *));
2126 elem = PLGetArrayElement(value,0);
2127 if (!elem || !PLIsString(elem)) return False;
2128 val = PLGetString(elem);
2129 if (strcasecmp(val, "function")==0) {
2130 elem = PLGetArrayElement(value, 1); /* library name */
2131 if (!elem || !PLIsString(elem)) return False;
2132 lib = PLGetString(elem);
2133 elem = PLGetArrayElement(value, 2); /* function name */
2134 if (!elem || !PLIsString(elem)) return False;
2135 func = PLGetString(elem);
2136 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2137 lib, "initDrawString", func, NULL, value,
2138 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2141 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2142 } else if (PLIsString(value)) {
2143 return getColor(scr, entry, value, addr, ret);
2146 return False;
2148 #endif /* DRAWSTRING_PLUGIN */
2152 static int
2153 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2154 void *addr, void **ret)
2156 proplist_t elem;
2157 int changed = 0;
2158 char *val;
2159 int nelem;
2161 again:
2162 if (!PLIsArray(value)) {
2163 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2164 "WorkspaceBack", "Texture or None");
2165 if (changed==0) {
2166 value = entry->plvalue;
2167 changed = 1;
2168 wwarning(_("using default \"%s\" instead"), entry->default_value);
2169 goto again;
2171 return False;
2174 /* only do basic error checking and verify for None texture */
2176 nelem = PLGetNumberOfElements(value);
2177 if (nelem > 0) {
2178 elem = PLGetArrayElement(value, 0);
2179 if (!elem || !PLIsString(elem)) {
2180 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2181 if (changed==0) {
2182 value = entry->plvalue;
2183 changed = 1;
2184 wwarning(_("using default \"%s\" instead"), entry->default_value);
2185 goto again;
2187 return False;
2189 val = PLGetString(elem);
2191 if (strcasecmp(val, "None")==0)
2192 return True;
2194 *ret = PLRetain(value);
2196 return True;
2200 static int
2201 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2202 void *addr, void **ret)
2204 proplist_t elem;
2205 int nelem;
2206 int changed = 0;
2208 again:
2209 if (!PLIsArray(value)) {
2210 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2211 "WorkspaceSpecificBack", "an array of textures");
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 = PLGetNumberOfElements(value);
2224 if (nelem > 0) {
2225 while (nelem--) {
2226 elem = PLGetArrayElement(value, nelem);
2227 if (!elem || !PLIsArray(elem)) {
2228 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2229 nelem);
2234 *ret = PLRetain(value);
2236 #ifdef notworking
2238 * Kluge to force wmsetbg helper to set the default background.
2239 * If the WorkspaceSpecificBack is changed once wmaker has started,
2240 * the WorkspaceBack won't be sent to the helper, unless the user
2241 * changes it's value too. So, we must force this by removing the
2242 * value from the defaults DB.
2244 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2245 proplist_t key = PLMakeString("WorkspaceBack");
2247 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2249 PLRelease(key);
2251 #endif
2252 return True;
2256 static int
2257 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2258 void **ret)
2260 static WMFont *font;
2261 char *val;
2263 GET_STRING_OR_DEFAULT("Font", val);
2265 font = WMCreateFont(scr->wmscreen, val);
2266 if (!font)
2267 font = WMCreateFont(scr->wmscreen, "fixed");
2269 if (!font) {
2270 wfatal(_("could not load any usable font!!!"));
2271 exit(1);
2274 if (ret)
2275 *ret = font;
2277 /* can't assign font value outside update function */
2278 wassertrv(addr == NULL, True);
2280 return True;
2284 static int
2285 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2286 void **ret)
2288 static XColor color;
2289 char *val;
2290 int second_pass=0;
2292 GET_STRING_OR_DEFAULT("Color", val);
2295 again:
2296 if (!wGetColor(scr, val, &color)) {
2297 wwarning(_("could not get color for key \"%s\""),
2298 entry->key);
2299 if (second_pass==0) {
2300 val = PLGetString(entry->plvalue);
2301 second_pass = 1;
2302 wwarning(_("using default \"%s\" instead"), val);
2303 goto again;
2305 return False;
2308 if (ret)
2309 *ret = &color;
2311 assert(addr==NULL);
2313 if (addr)
2314 *(unsigned long*)addr = pixel;
2317 return True;
2322 static int
2323 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2324 void **ret)
2326 static WShortKey shortcut;
2327 KeySym ksym;
2328 char *val;
2329 char *k;
2330 char buf[128], *b;
2333 GET_STRING_OR_DEFAULT("Key spec", val);
2335 if (!val || strcasecmp(val, "NONE")==0) {
2336 shortcut.keycode = 0;
2337 shortcut.modifier = 0;
2338 if (ret)
2339 *ret = &shortcut;
2340 return True;
2343 strcpy(buf, val);
2345 b = (char*)buf;
2347 /* get modifiers */
2348 shortcut.modifier = 0;
2349 while ((k = strchr(b, '+'))!=NULL) {
2350 int mod;
2352 *k = 0;
2353 mod = wXModifierFromKey(b);
2354 if (mod<0) {
2355 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2356 return False;
2358 shortcut.modifier |= mod;
2360 b = k+1;
2363 /* get key */
2364 ksym = XStringToKeysym(b);
2366 if (ksym==NoSymbol) {
2367 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2368 val);
2369 return False;
2372 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2373 if (shortcut.keycode==0) {
2374 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2375 return False;
2378 if (ret)
2379 *ret = &shortcut;
2381 return True;
2385 static int
2386 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2387 void **ret)
2389 static unsigned int mask;
2390 char *str;
2392 GET_STRING_OR_DEFAULT("Modifier Key", str);
2394 if (!str)
2395 return False;
2397 mask = wXModifierFromKey(str);
2398 if (mask < 0) {
2399 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2400 mask = 0;
2401 return False;
2404 if (addr)
2405 *(unsigned int*)addr = mask;
2407 if (ret)
2408 *ret = &mask;
2410 return True;
2414 #ifdef NEWSTUFF
2415 static int
2416 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2417 void *addr, void **ret)
2419 unsigned int mask;
2420 char *str;
2421 RImage *image;
2422 int i, n;
2423 int w, h;
2425 GET_STRING_OR_DEFAULT("Image File Path", str);
2426 if (!str)
2427 return False;
2429 image = RLoadImage(scr->rcontext, str, 0);
2430 if (!image) {
2431 wwarning(_("could not load image in option %s: %s"), entry->key,
2432 RMessageForError(RErrorCode));
2433 return False;
2436 if (*(RImage**)addr) {
2437 RDestroyImage(*(RImage**)addr);
2439 if (addr)
2440 *(RImage**)addr = image;
2442 assert(ret == NULL);
2444 if (ret)
2445 *(RImage**)ret = image;
2448 return True;
2450 #endif
2452 #ifdef DEFINABLE_CURSOR
2454 # include <X11/cursorfont.h>
2455 typedef struct
2457 char *name;
2458 int id;
2459 } WCursorLookup;
2461 #define CURSOR_ID_NONE (XC_num_glyphs)
2463 static WCursorLookup cursor_table[] =
2465 { "X_cursor", XC_X_cursor },
2466 { "arrow", XC_arrow },
2467 { "based_arrow_down", XC_based_arrow_down },
2468 { "based_arrow_up", XC_based_arrow_up },
2469 { "boat", XC_boat },
2470 { "bogosity", XC_bogosity },
2471 { "bottom_left_corner", XC_bottom_left_corner },
2472 { "bottom_right_corner", XC_bottom_right_corner },
2473 { "bottom_side", XC_bottom_side },
2474 { "bottom_tee", XC_bottom_tee },
2475 { "box_spiral", XC_box_spiral },
2476 { "center_ptr", XC_center_ptr },
2477 { "circle", XC_circle },
2478 { "clock", XC_clock },
2479 { "coffee_mug", XC_coffee_mug },
2480 { "cross", XC_cross },
2481 { "cross_reverse", XC_cross_reverse },
2482 { "crosshair", XC_crosshair },
2483 { "diamond_cross", XC_diamond_cross },
2484 { "dot", XC_dot },
2485 { "dotbox", XC_dotbox },
2486 { "double_arrow", XC_double_arrow },
2487 { "draft_large", XC_draft_large },
2488 { "draft_small", XC_draft_small },
2489 { "draped_box", XC_draped_box },
2490 { "exchange", XC_exchange },
2491 { "fleur", XC_fleur },
2492 { "gobbler", XC_gobbler },
2493 { "gumby", XC_gumby },
2494 { "hand1", XC_hand1 },
2495 { "hand2", XC_hand2 },
2496 { "heart", XC_heart },
2497 { "icon", XC_icon },
2498 { "iron_cross", XC_iron_cross },
2499 { "left_ptr", XC_left_ptr },
2500 { "left_side", XC_left_side },
2501 { "left_tee", XC_left_tee },
2502 { "leftbutton", XC_leftbutton },
2503 { "ll_angle", XC_ll_angle },
2504 { "lr_angle", XC_lr_angle },
2505 { "man", XC_man },
2506 { "middlebutton", XC_middlebutton },
2507 { "mouse", XC_mouse },
2508 { "pencil", XC_pencil },
2509 { "pirate", XC_pirate },
2510 { "plus", XC_plus },
2511 { "question_arrow", XC_question_arrow },
2512 { "right_ptr", XC_right_ptr },
2513 { "right_side", XC_right_side },
2514 { "right_tee", XC_right_tee },
2515 { "rightbutton", XC_rightbutton },
2516 { "rtl_logo", XC_rtl_logo },
2517 { "sailboat", XC_sailboat },
2518 { "sb_down_arrow", XC_sb_down_arrow },
2519 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2520 { "sb_left_arrow", XC_sb_left_arrow },
2521 { "sb_right_arrow", XC_sb_right_arrow },
2522 { "sb_up_arrow", XC_sb_up_arrow },
2523 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2524 { "shuttle", XC_shuttle },
2525 { "sizing", XC_sizing },
2526 { "spider", XC_spider },
2527 { "spraycan", XC_spraycan },
2528 { "star", XC_star },
2529 { "target", XC_target },
2530 { "tcross", XC_tcross },
2531 { "top_left_arrow", XC_top_left_arrow },
2532 { "top_left_corner", XC_top_left_corner },
2533 { "top_right_corner", XC_top_right_corner },
2534 { "top_side", XC_top_side },
2535 { "top_tee", XC_top_tee },
2536 { "trek", XC_trek },
2537 { "ul_angle", XC_ul_angle },
2538 { "umbrella", XC_umbrella },
2539 { "ur_angle", XC_ur_angle },
2540 { "watch", XC_watch },
2541 { "xterm", XC_xterm },
2542 { NULL, CURSOR_ID_NONE }
2545 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2547 switch(status) {
2548 case BitmapOpenFailed:
2549 wwarning(_("failed to open bitmap file \"%s\""), filename);
2550 break;
2551 case BitmapFileInvalid:
2552 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2553 break;
2554 case BitmapNoMemory:
2555 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2556 break;
2557 case BitmapSuccess:
2558 XFreePixmap(dpy, bitmap);
2559 break;
2564 * (none)
2565 * (builtin, <cursor_name>)
2566 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2568 static int parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2570 proplist_t elem;
2571 char *val;
2572 int nelem;
2573 int status = 0;
2575 nelem = PLGetNumberOfElements(pl);
2576 if (nelem < 1) {
2577 return(status);
2579 elem = PLGetArrayElement(pl, 0);
2580 if (!elem || !PLIsString(elem)) {
2581 return(status);
2583 val = PLGetString(elem);
2585 if (0 == strcasecmp(val, "none")) {
2586 status = 1;
2587 *cursor = None;
2588 } else if (0 == strcasecmp(val, "builtin")) {
2589 int i;
2590 int cursor_id = CURSOR_ID_NONE;
2592 if (2 != nelem) {
2593 wwarning(_("bad number of arguments in cursor specification"));
2594 return(status);
2596 elem = PLGetArrayElement(pl, 1);
2597 if (!elem || !PLIsString(elem)) {
2598 return(status);
2600 val = PLGetString(elem);
2602 for (i = 0; NULL != cursor_table[i].name; i++) {
2603 if (0 == strcasecmp(val, cursor_table[i].name)) {
2604 cursor_id = cursor_table[i].id;
2605 break;
2608 if (CURSOR_ID_NONE == cursor_id) {
2609 wwarning(_("unknown builtin cursor name \"%s\""), val);
2610 } else {
2611 *cursor = XCreateFontCursor(dpy, cursor_id);
2612 status = 1;
2614 } else if (0 == strcasecmp(val, "bitmap")) {
2615 char *bitmap_name;
2616 char *mask_name;
2617 int bitmap_status;
2618 int mask_status;
2619 Pixmap bitmap;
2620 Pixmap mask;
2621 unsigned int w, h;
2622 int x, y;
2623 XColor fg, bg;
2625 if (3 != nelem) {
2626 wwarning(_("bad number of arguments in cursor specification"));
2627 return(status);
2629 elem = PLGetArrayElement(pl, 1);
2630 if (!elem || !PLIsString(elem)) {
2631 return(status);
2633 val = PLGetString(elem);
2634 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2635 if (!bitmap_name) {
2636 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2637 return(status);
2639 elem = PLGetArrayElement(pl, 2);
2640 if (!elem || !PLIsString(elem)) {
2641 free(bitmap_name);
2642 return(status);
2644 val = PLGetString(elem);
2645 mask_name = FindImage(wPreferences.pixmap_path, val);
2646 if (!mask_name) {
2647 free(bitmap_name);
2648 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2649 return(status);
2651 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2652 &mask, &x, &y);
2653 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2654 &bitmap, &x, &y);
2655 if ((BitmapSuccess == bitmap_status) &&
2656 (BitmapSuccess == mask_status)) {
2657 fg.pixel = scr->black_pixel;
2658 bg.pixel = scr->white_pixel;
2659 XQueryColor(dpy, scr->w_colormap, &fg);
2660 XQueryColor(dpy, scr->w_colormap, &bg);
2661 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2662 status = 1;
2664 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2665 check_bitmap_status(mask_status, mask_name, mask);
2666 free(bitmap_name);
2667 free(mask_name);
2669 return(status);
2673 static int
2674 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2675 void **ret)
2677 static Cursor cursor;
2678 int status;
2679 int changed = 0;
2681 again:
2682 if (!PLIsArray(value)) {
2683 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2684 entry->key, "cursor specification");
2685 if (!changed) {
2686 value = entry->plvalue;
2687 changed = 1;
2688 wwarning(_("using default \"%s\" instead"), entry->default_value);
2689 goto again;
2691 return(False);
2693 status = parse_cursor(scr, value, &cursor);
2694 if (!status) {
2695 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2696 if (!changed) {
2697 value = entry->plvalue;
2698 changed = 1;
2699 wwarning(_("using default \"%s\" instead"), entry->default_value);
2700 goto again;
2702 return(False);
2704 if (ret) {
2705 *ret = &cursor;
2707 if (addr) {
2708 *(Cursor *)addr = cursor;
2710 return(True);
2712 #undef CURSOR_ID_NONE
2714 #endif /* DEFINABLE_CURSOR */
2717 /* ---------------- value setting functions --------------- */
2718 static int
2719 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2721 return REFRESH_WINDOW_TITLE_COLOR;
2724 static int
2725 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2727 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2730 static int
2731 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2733 switch (which) {
2734 case WM_DOCK:
2735 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2736 break;
2737 case WM_CLIP:
2738 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2739 break;
2740 default:
2741 break;
2743 return 0;
2747 static int
2748 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2750 if (scr->workspaces) {
2751 wWorkspaceForceChange(scr, scr->current_workspace);
2752 wArrangeIcons(scr, False);
2754 return 0;
2757 #if not_used
2758 static int
2759 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2761 if (*value <= 0)
2762 *(int*)foo = 1;
2764 return 0;
2766 #endif
2770 static int
2771 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2773 Pixmap pixmap;
2774 RImage *img;
2775 int reset = 0;
2777 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2778 wPreferences.icon_size,
2779 ((*texture)->any.type & WREL_BORDER_MASK)
2780 ? WREL_ICON : WREL_FLAT);
2781 if (!img) {
2782 wwarning(_("could not render texture for icon background"));
2783 if (!entry->addr)
2784 wTextureDestroy(scr, *texture);
2785 return 0;
2787 RConvertImage(scr->rcontext, img, &pixmap);
2789 if (scr->icon_tile) {
2790 reset = 1;
2791 RDestroyImage(scr->icon_tile);
2792 XFreePixmap(dpy, scr->icon_tile_pixmap);
2795 scr->icon_tile = img;
2798 /* put the icon in the noticeboard hint */
2799 PropSetIconTileHint(scr, img);
2802 if (!wPreferences.flags.noclip) {
2803 if (scr->clip_tile) {
2804 RDestroyImage(scr->clip_tile);
2806 scr->clip_tile = wClipMakeTile(scr, img);
2809 scr->icon_tile_pixmap = pixmap;
2811 if (scr->def_icon_pixmap) {
2812 XFreePixmap(dpy, scr->def_icon_pixmap);
2813 scr->def_icon_pixmap = None;
2815 if (scr->def_ticon_pixmap) {
2816 XFreePixmap(dpy, scr->def_ticon_pixmap);
2817 scr->def_ticon_pixmap = None;
2820 if (scr->icon_back_texture) {
2821 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2823 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2825 if (scr->clip_balloon)
2826 XSetWindowBackground(dpy, scr->clip_balloon,
2827 (*texture)->any.color.pixel);
2830 * Free the texture as nobody else will use it, nor refer to it.
2832 if (!entry->addr)
2833 wTextureDestroy(scr, *texture);
2835 return (reset ? REFRESH_ICON_TILE : 0);
2840 static int
2841 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2843 if (scr->title_font) {
2844 WMReleaseFont(scr->title_font);
2846 scr->title_font = font;
2848 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2852 static int
2853 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2855 if (scr->menu_title_font) {
2856 WMReleaseFont(scr->menu_title_font);
2859 scr->menu_title_font = font;
2861 return REFRESH_MENU_TITLE_FONT;
2865 static int
2866 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2868 if (scr->menu_entry_font) {
2869 WMReleaseFont(scr->menu_entry_font);
2871 scr->menu_entry_font = font;
2873 return REFRESH_MENU_FONT;
2878 static int
2879 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2881 if (scr->icon_title_font) {
2882 WMReleaseFont(scr->icon_title_font);
2885 scr->icon_title_font = font;
2887 return REFRESH_ICON_FONT;
2891 static int
2892 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2894 if (scr->clip_title_font) {
2895 WMReleaseFont(scr->clip_title_font);
2898 scr->clip_title_font = font;
2900 return REFRESH_ICON_FONT;
2904 static int
2905 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2907 if (scr->workspace_name_font) {
2908 WMReleaseFont(scr->workspace_name_font);
2911 scr->workspace_name_font = font;
2913 return 0;
2917 static int
2918 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2920 if (scr->select_pixel!=scr->white_pixel &&
2921 scr->select_pixel!=scr->black_pixel) {
2922 wFreeColor(scr, scr->select_pixel);
2925 scr->select_pixel = color->pixel;
2927 return REFRESH_MENU_COLOR;
2931 static int
2932 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2934 if (scr->select_text_pixel!=scr->white_pixel &&
2935 scr->select_text_pixel!=scr->black_pixel) {
2936 wFreeColor(scr, scr->select_text_pixel);
2939 scr->select_text_pixel = color->pixel;
2941 return REFRESH_MENU_COLOR;
2945 static int
2946 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2948 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2949 scr->clip_title_pixel[index]!=scr->black_pixel) {
2950 wFreeColor(scr, scr->clip_title_pixel[index]);
2952 scr->clip_title_pixel[index] = color->pixel;
2954 #ifdef GRADIENT_CLIP_ARROW
2955 if (index == CLIP_NORMAL) {
2956 RImage *image;
2957 RColor color1, color2;
2958 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2959 int as = pt - 15; /* 15 = 5+5+5 */
2961 FREE_PIXMAP(scr->clip_arrow_gradient);
2963 color1.red = (color->red >> 8)*6/10;
2964 color1.green = (color->green >> 8)*6/10;
2965 color1.blue = (color->blue >> 8)*6/10;
2967 color2.red = WMIN((color->red >> 8)*20/10, 255);
2968 color2.green = WMIN((color->green >> 8)*20/10, 255);
2969 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2971 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2972 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2973 RDestroyImage(image);
2975 #endif /* GRADIENT_CLIP_ARROW */
2977 return REFRESH_ICON_TITLE_COLOR;
2981 static int
2982 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2984 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2985 scr->window_title_pixel[index]!=scr->black_pixel) {
2986 wFreeColor(scr, scr->window_title_pixel[index]);
2989 scr->window_title_pixel[index] = color->pixel;
2991 if (index == WS_UNFOCUSED)
2992 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2994 return REFRESH_WINDOW_TITLE_COLOR;
2998 static int
2999 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3001 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3002 scr->menu_title_pixel[0]!=scr->black_pixel) {
3003 #ifdef DRAWSTRING_PLUGIN
3004 if(!scr->drawstring_func[W_STRING_MTITLE])
3005 #endif
3006 wFreeColor(scr, scr->menu_title_pixel[0]);
3009 scr->menu_title_pixel[0] = color->pixel;
3010 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3012 return REFRESH_MENU_TITLE_COLOR;
3016 static int
3017 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3019 XGCValues gcv;
3020 #define gcm (GCForeground|GCBackground|GCFillStyle)
3022 if (scr->mtext_pixel!=scr->white_pixel &&
3023 scr->mtext_pixel!=scr->black_pixel) {
3024 wFreeColor(scr, scr->mtext_pixel);
3027 scr->mtext_pixel = color->pixel;
3029 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3032 if (scr->dtext_pixel == scr->mtext_pixel) {
3033 gcv.foreground = scr->white_pixel;
3034 gcv.background = scr->black_pixel;
3035 gcv.fill_style = FillStippled;
3036 } else {
3037 gcv.foreground = scr->dtext_pixel;
3038 gcv.fill_style = FillSolid;
3040 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3042 return REFRESH_MENU_COLOR;
3043 #undef gcm
3047 static int
3048 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3050 XGCValues gcv;
3051 #define gcm (GCForeground|GCBackground|GCFillStyle)
3053 if (scr->dtext_pixel!=scr->white_pixel &&
3054 scr->dtext_pixel!=scr->black_pixel) {
3055 wFreeColor(scr, scr->dtext_pixel);
3058 scr->dtext_pixel = color->pixel;
3060 if (scr->dtext_pixel == scr->mtext_pixel) {
3061 gcv.foreground = scr->white_pixel;
3062 gcv.background = scr->black_pixel;
3063 gcv.fill_style = FillStippled;
3064 } else {
3065 gcv.foreground = scr->dtext_pixel;
3066 gcv.fill_style = FillSolid;
3068 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3070 return REFRESH_MENU_COLOR;
3071 #undef gcm
3074 static int
3075 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3077 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3079 return REFRESH_ICON_TITLE_COLOR;
3083 static int
3084 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3086 if (scr->icon_title_texture) {
3087 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3089 XQueryColor (dpy, scr->w_colormap, color);
3090 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3092 return REFRESH_ICON_TITLE_BACK;
3096 static void
3097 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3099 close(scr->helper_fd);
3100 scr->helper_fd = 0;
3101 scr->helper_pid = 0;
3102 scr->flags.backimage_helper_launched = 0;
3106 static int
3107 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3108 void *bar)
3110 int i;
3111 proplist_t val;
3112 char *str;
3114 if (scr->flags.backimage_helper_launched) {
3115 if (PLGetNumberOfElements(value)==0) {
3116 SendHelperMessage(scr, 'C', 0, NULL);
3117 SendHelperMessage(scr, 'K', 0, NULL);
3119 PLRelease(value);
3120 return 0;
3122 } else {
3123 pid_t pid;
3124 int filedes[2];
3126 if (PLGetNumberOfElements(value) == 0)
3127 return 0;
3129 if (pipe(filedes) < 0) {
3130 wsyserror("pipe() failed:can't set workspace specific background image");
3132 PLRelease(value);
3133 return 0;
3136 pid = fork();
3137 if (pid < 0) {
3138 wsyserror("fork() failed:can't set workspace specific background image");
3139 if (close(filedes[0]) < 0)
3140 wsyserror("could not close pipe");
3141 if (close(filedes[1]) < 0)
3142 wsyserror("could not close pipe");
3144 } else if (pid == 0) {
3145 SetupEnvironment(scr);
3147 if (close(0) < 0)
3148 wsyserror("could not close pipe");
3149 if (dup(filedes[0]) < 0) {
3150 wsyserror("dup() failed:can't set workspace specific background image");
3152 if (wPreferences.smooth_workspace_back)
3153 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
3154 else
3155 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
3156 wsyserror("could not execute wmsetbg");
3157 exit(1);
3158 } else {
3160 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3161 wsyserror("error setting close-on-exec flag");
3163 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3164 wsyserror("error setting close-on-exec flag");
3167 scr->helper_fd = filedes[1];
3168 scr->helper_pid = pid;
3169 scr->flags.backimage_helper_launched = 1;
3171 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3173 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3178 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3179 val = PLGetArrayElement(value, i);
3180 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3181 str = PLGetDescription(val);
3183 SendHelperMessage(scr, 'S', i+1, str);
3185 free(str);
3186 } else {
3187 SendHelperMessage(scr, 'U', i+1, NULL);
3190 sleep(1);
3192 PLRelease(value);
3193 return 0;
3197 static int
3198 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3199 void *bar)
3201 if (scr->flags.backimage_helper_launched) {
3202 char *str;
3204 if (PLGetNumberOfElements(value)==0) {
3205 SendHelperMessage(scr, 'U', 0, NULL);
3206 } else {
3207 /* set the default workspace background to this one */
3208 str = PLGetDescription(value);
3209 if (str) {
3210 SendHelperMessage(scr, 'S', 0, str);
3211 free(str);
3212 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3213 } else {
3214 SendHelperMessage(scr, 'U', 0, NULL);
3217 } else {
3218 char *command;
3219 char *text;
3221 SetupEnvironment(scr);
3222 text = PLGetDescription(value);
3223 command = wmalloc(strlen(text)+40);
3224 if (wPreferences.smooth_workspace_back)
3225 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
3226 else
3227 sprintf(command, "wmsetbg -d -p '%s' &", text);
3228 free(text);
3229 system(command);
3230 free(command);
3232 PLRelease(value);
3234 return 0;
3238 static int
3239 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3241 if (scr->widget_texture) {
3242 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3244 scr->widget_texture = *(WTexSolid**)texture;
3246 return 0;
3250 static int
3251 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3253 if (scr->window_title_texture[WS_FOCUSED]) {
3254 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3256 scr->window_title_texture[WS_FOCUSED] = *texture;
3258 return REFRESH_WINDOW_TEXTURES;
3262 static int
3263 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3265 if (scr->window_title_texture[WS_PFOCUSED]) {
3266 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3268 scr->window_title_texture[WS_PFOCUSED] = *texture;
3270 return REFRESH_WINDOW_TEXTURES;
3274 static int
3275 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3277 if (scr->window_title_texture[WS_UNFOCUSED]) {
3278 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3280 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3282 return REFRESH_WINDOW_TEXTURES;
3286 static int
3287 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3289 if (scr->resizebar_texture[0]) {
3290 wTextureDestroy(scr, scr->resizebar_texture[0]);
3292 scr->resizebar_texture[0] = *texture;
3294 return REFRESH_WINDOW_TEXTURES;
3298 static int
3299 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3301 if (scr->menu_title_texture[0]) {
3302 wTextureDestroy(scr, scr->menu_title_texture[0]);
3304 scr->menu_title_texture[0] = *texture;
3306 return REFRESH_MENU_TITLE_TEXTURE;
3310 static int
3311 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3313 if (scr->menu_item_texture) {
3314 wTextureDestroy(scr, scr->menu_item_texture);
3315 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3317 scr->menu_item_texture = *texture;
3319 scr->menu_item_auxtexture
3320 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3322 return REFRESH_MENU_TEXTURE;
3326 static int
3327 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3329 WWindow *wwin;
3330 wKeyBindings[index] = *shortcut;
3332 wwin = scr->focused_window;
3334 while (wwin!=NULL) {
3335 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3337 if (!WFLAGP(wwin, no_bind_keys)) {
3338 wWindowSetKeyGrabs(wwin);
3340 wwin = wwin->prev;
3343 return 0;
3347 static int
3348 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3350 wArrangeIcons(scr, True);
3352 return 0;
3356 static int
3357 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3359 wScreenUpdateUsableArea(scr);
3361 return 0;
3365 static int
3366 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3368 return REFRESH_MENU_TEXTURE;
3373 static int
3374 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3376 return REFRESH_BUTTON_IMAGES;
3381 * Very ugly kluge.
3382 * Need access to the double click variables, so that all widgets in
3383 * wmaker panels will have the same dbl-click values.
3384 * TODO: figure a better way of dealing with it.
3386 #include "WINGsP.h"
3388 static int
3389 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3391 extern _WINGsConfiguration WINGsConfiguration;
3393 if (*value <= 0)
3394 *(int*)foo = 1;
3396 WINGsConfiguration.doubleClickDelay = *value;
3398 return 0;
3403 static int
3404 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3406 extern _WINGsConfiguration WINGsConfiguration;
3408 WINGsConfiguration.useMultiByte = *value;
3410 return 0;
3414 #ifdef DEFINABLE_CURSOR
3415 static int
3416 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3418 if (None != wCursor[index])
3420 XFreeCursor(dpy, wCursor[index]);
3423 wCursor[index] = *cursor;
3425 if ((WCUR_ROOT == index) && (None != *cursor))
3427 XDefineCursor(dpy, scr->root_win, *cursor);
3430 return 0;
3432 #endif /* DEFINABLE_CURSOR*/