fixed bugs in configure.in, removed
[wmaker-crm.git] / src / defaults.c
blob45f887490787c8878e0951698a7fd4b9585c9c8c
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 #if 0
186 static int setMultiByte();
187 #endif
188 static int updateUsableArea();
190 #ifdef DEFINABLE_CURSOR
191 extern Cursor wCursor[WCUR_LAST];
192 static int getCursor();
193 static int setCursor();
194 #endif
198 * Tables to convert strings to enumeration values.
199 * Values stored are char
203 /* WARNING: sum of length of all value strings must not exceed
204 * this value */
205 #define TOTAL_VALUES_LENGTH 80
210 #define REFRESH_WINDOW_TEXTURES (1<<0)
211 #define REFRESH_MENU_TEXTURE (1<<1)
212 #define REFRESH_MENU_FONT (1<<2)
213 #define REFRESH_MENU_COLOR (1<<3)
214 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
215 #define REFRESH_MENU_TITLE_FONT (1<<5)
216 #define REFRESH_MENU_TITLE_COLOR (1<<6)
217 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
218 #define REFRESH_WINDOW_FONT (1<<8)
219 #define REFRESH_ICON_TILE (1<<9)
220 #define REFRESH_ICON_FONT (1<<10)
221 #define REFRESH_WORKSPACE_BACK (1<<11)
223 #define REFRESH_BUTTON_IMAGES (1<<12)
225 #define REFRESH_ICON_TITLE_COLOR (1<<13)
226 #define REFRESH_ICON_TITLE_BACK (1<<14)
230 static WOptionEnumeration seFocusModes[] = {
231 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
232 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
233 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
234 {NULL, 0, 0}
237 static WOptionEnumeration seColormapModes[] = {
238 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
239 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
240 {NULL, 0, 0}
243 static WOptionEnumeration sePlacements[] = {
244 {"Auto", WPM_AUTO, 0},
245 {"Smart", WPM_SMART, 0},
246 {"Cascade", WPM_CASCADE, 0},
247 {"Random", WPM_RANDOM, 0},
248 {"Manual", WPM_MANUAL, 0},
249 {NULL, 0, 0}
252 static WOptionEnumeration seGeomDisplays[] = {
253 {"Center", WDIS_CENTER, 0},
254 {"Corner", WDIS_TOPLEFT, 0},
255 {"Floating", WDIS_FRAME_CENTER, 0},
256 {"Line", WDIS_NEW, 0},
257 {NULL, 0, 0}
260 static WOptionEnumeration seSpeeds[] = {
261 {"UltraFast", SPEED_ULTRAFAST, 0},
262 {"Fast", SPEED_FAST, 0},
263 {"Medium", SPEED_MEDIUM, 0},
264 {"Slow", SPEED_SLOW, 0},
265 {"UltraSlow", SPEED_ULTRASLOW, 0},
266 {NULL, 0, 0}
269 static WOptionEnumeration seMouseButtons[] = {
270 {"None", -1, 0},
271 {"Left", Button1, 0}, {"Button1", Button1, 1},
272 {"Middle", Button2, 0}, {"Button2", Button2, 1},
273 {"Right", Button3, 0}, {"Button3", Button3, 1},
274 {"Button4", Button4, 0},
275 {"Button5", Button5, 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 {"SelectWindowsMouseButton", "Left", seMouseButtons,
397 &wPreferences.select_button, getEnum, NULL
399 {"WindowListMouseButton", "Middle", seMouseButtons,
400 &wPreferences.windowl_button, getEnum, NULL
402 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
403 &wPreferences.menu_button, getEnum, NULL
405 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
406 &wPreferences.pixmap_path, getPathList, NULL
408 {"IconPath", DEF_ICON_PATHS, NULL,
409 &wPreferences.icon_path, getPathList, NULL
411 {"ColormapMode", "auto", seColormapModes,
412 &wPreferences.colormap_mode, getEnum, NULL
414 {"AutoFocus", "NO", NULL,
415 &wPreferences.auto_focus, getBool, NULL
417 {"RaiseDelay", "0", NULL,
418 &wPreferences.raise_delay, getInt, NULL
420 {"WindozeCycling", "YES", NULL,
421 &wPreferences.windows_cycling,getBool, NULL
423 {"CirculateRaise", "NO", NULL,
424 &wPreferences.circ_raise, getBool, NULL
426 {"Superfluous", "NO", NULL,
427 &wPreferences.superfluous, getBool, NULL
429 {"AdvanceToNewWorkspace", "NO", NULL,
430 &wPreferences.ws_advance, getBool, NULL
432 {"CycleWorkspaces", "NO", NULL,
433 &wPreferences.ws_cycle, getBool, NULL
435 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
436 &wPreferences.workspace_name_display_position, getEnum, NULL
438 {"WorkspaceBorder", "None", seWorkspaceBorder,
439 &wPreferences.workspace_border_position, getEnum, updateUsableArea
441 {"WorkspaceBorderSize", "0", NULL,
442 &wPreferences.workspace_border_size, getInt, updateUsableArea
444 #ifdef VIRTUAL_DESKTOP
445 {"VirtualEdgeThickness", "1", NULL,
446 &wPreferences.vedge_thickness, getInt, NULL
448 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
449 &wPreferences.vedge_hscrollspeed, getInt, NULL
451 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
452 &wPreferences.vedge_vscrollspeed, getInt, NULL
454 {"VirtualEdgeMaximumWidth", "3000", NULL,
455 &wPreferences.vedge_maxwidth, getInt, NULL
457 {"VirtualEdgeMaximumHeight", "3000", NULL,
458 &wPreferences.vedge_maxheight, getInt, NULL
460 #endif
461 {"StickyIcons", "NO", NULL,
462 &wPreferences.sticky_icons, getBool, setStickyIcons
464 {"SaveSessionOnExit", "NO", NULL,
465 &wPreferences.save_session_on_exit, getBool, NULL
467 {"WrapMenus", "NO", NULL,
468 &wPreferences.wrap_menus, getBool, NULL
470 {"ScrollableMenus", "NO", NULL,
471 &wPreferences.scrollable_menus, getBool, NULL
473 {"MenuScrollSpeed", "medium", seSpeeds,
474 &wPreferences.menu_scroll_speed, getEnum, NULL
476 {"IconSlideSpeed", "medium", seSpeeds,
477 &wPreferences.icon_slide_speed, getEnum, NULL
479 {"ShadeSpeed", "medium", seSpeeds,
480 &wPreferences.shade_speed, getEnum, NULL
482 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
483 &wPreferences.dblclick_time, getInt, setDoubleClick,
485 {"AlignSubmenus", "NO", NULL,
486 &wPreferences.align_menus, getBool, NULL
488 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
489 &wPreferences.open_transients_with_parent, getBool, NULL
491 {"WindowPlacement", "auto", sePlacements,
492 &wPreferences.window_placement, getEnum, NULL
494 {"IgnoreFocusClick","NO", NULL,
495 &wPreferences.ignore_focus_click, getBool, NULL
497 {"UseSaveUnders", "NO", NULL,
498 &wPreferences.use_saveunders, getBool, NULL
500 {"OpaqueMove", "NO", NULL,
501 &wPreferences.opaque_move, getBool, NULL
503 {"DisableSound", "NO", NULL,
504 &wPreferences.no_sound, getBool, NULL
506 {"DisableAnimations", "NO", NULL,
507 &wPreferences.no_animations, getBool, NULL
509 {"DontLinkWorkspaces","NO", NULL,
510 &wPreferences.no_autowrap, getBool, NULL
512 {"AutoArrangeIcons", "NO", NULL,
513 &wPreferences.auto_arrange_icons, getBool, NULL
515 {"NoWindowOverDock", "NO", NULL,
516 &wPreferences.no_window_over_dock, getBool, updateUsableArea
518 {"NoWindowOverIcons", "NO", NULL,
519 &wPreferences.no_window_over_icons, getBool, updateUsableArea
521 {"WindowPlaceOrigin", "(0, 0)", NULL,
522 &wPreferences.window_place_origin, getCoord, NULL
524 {"ResizeDisplay", "corner", seGeomDisplays,
525 &wPreferences.size_display, getEnum, NULL
527 {"MoveDisplay", "corner", seGeomDisplays,
528 &wPreferences.move_display, getEnum, NULL
530 {"DontConfirmKill", "NO", NULL,
531 &wPreferences.dont_confirm_kill, getBool,NULL
533 {"WindowTitleBalloons", "NO", NULL,
534 &wPreferences.window_balloon, getBool, NULL
536 {"MiniwindowTitleBalloons", "NO", NULL,
537 &wPreferences.miniwin_balloon,getBool, NULL
539 {"AppIconBalloons", "NO", NULL,
540 &wPreferences.appicon_balloon,getBool, NULL
542 {"HelpBalloons", "NO", NULL,
543 &wPreferences.help_balloon, getBool, NULL
545 {"EdgeResistance", "30", NULL,
546 &wPreferences.edge_resistance,getInt, NULL
548 {"Attraction", "NO", NULL,
549 &wPreferences.attract, getBool, NULL
551 {"DisableBlinking", "NO", NULL,
552 &wPreferences.dont_blink, getBool, NULL
554 /* style options */
555 {"MenuStyle", "normal", seMenuStyles,
556 &wPreferences.menu_style, getEnum, setMenuStyle
558 {"WidgetColor", "(solid, gray)", NULL,
559 NULL, getTexture, setWidgetColor,
561 {"WorkspaceSpecificBack","()", NULL,
562 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
564 /* WorkspaceBack must come after WorkspaceSpecificBack or
565 * WorkspaceBack wont know WorkspaceSpecificBack was also
566 * specified and 2 copies of wmsetbg will be launched */
567 {"WorkspaceBack", "(solid, black)", NULL,
568 NULL, getWSBackground,setWorkspaceBack
570 {"SmoothWorkspaceBack", "NO", NULL,
571 NULL, getBool, NULL
573 {"IconBack", "(solid, gray)", NULL,
574 NULL, getTexture, setIconTile
576 {"TitleJustify", "center", seJustifications,
577 &wPreferences.title_justification, getEnum, setJustify
579 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
580 NULL, getFont, setWinTitleFont,
582 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
583 &wPreferences.window_title_clearance, getInt, setClearance
585 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
586 &wPreferences.menu_title_clearance, getInt, setClearance
588 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
589 &wPreferences.menu_text_clearance, getInt, setClearance
591 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
592 NULL, getFont, setMenuTitleFont
594 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
595 NULL, getFont, setMenuTextFont
597 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
598 NULL, getFont, setIconTitleFont
600 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
601 NULL, getFont, setClipTitleFont
603 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
604 NULL, getFont, setLargeDisplayFont
606 {"HighlightColor", "white", NULL,
607 NULL, getColor, setHightlight
609 {"HighlightTextColor", "black", NULL,
610 NULL, getColor, setHightlightText
612 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
613 NULL, getColor, setClipTitleColor
615 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
616 NULL, getColor, setClipTitleColor
618 #ifdef DRAWSTRING_PLUGIN
619 {"FTitleColor", "white", (void*)WS_FOCUSED,
620 NULL, getTextRenderer, setWTitleColor
622 {"PTitleColor", "white", (void*)WS_PFOCUSED,
623 NULL, getTextRenderer, setWTitleColor
625 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
626 NULL, getTextRenderer, setWTitleColor
628 #else
629 {"FTitleColor", "white", (void*)WS_FOCUSED,
630 NULL, getColor, setWTitleColor
632 {"PTitleColor", "white", (void*)WS_PFOCUSED,
633 NULL, getColor, setWTitleColor
635 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
636 NULL, getColor, setWTitleColor
638 #endif
639 {"FTitleBack", "(solid, black)", NULL,
640 NULL, getTexture, setFTitleBack
642 {"PTitleBack", "(solid, \"#616161\")", NULL,
643 NULL, getTexture, setPTitleBack
645 {"UTitleBack", "(solid, gray)", NULL,
646 NULL, getTexture, setUTitleBack
648 {"ResizebarBack", "(solid, gray)", NULL,
649 NULL, getTexture, setResizebarBack
651 #ifdef DRAWSTRING_PLUGIN
652 {"MenuTitleColor", "white", NULL,
653 NULL, getTextRenderer, setMenuTitleColor
655 {"MenuTextColor", "black", NULL,
656 NULL, getTextRenderer, setMenuTextColor
658 #else
659 {"MenuTitleColor", "white", NULL,
660 NULL, getColor, setMenuTitleColor
662 {"MenuTextColor", "black", NULL,
663 NULL, getColor, setMenuTextColor
665 #endif
666 {"MenuDisabledColor", "\"#616161\"", NULL,
667 NULL, getColor, setMenuDisabledColor
669 {"MenuTitleBack", "(solid, black)", NULL,
670 NULL, getTexture, setMenuTitleBack
672 {"MenuTextBack", "(solid, gray)", NULL,
673 NULL, getTexture, setMenuTextBack
675 {"IconTitleColor", "white", NULL,
676 NULL, getColor, setIconTitleColor
678 {"IconTitleBack", "black", NULL,
679 NULL, getColor, setIconTitleBack
681 /* keybindings */
682 #ifndef LITE
683 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
684 NULL, getKeybind, setKeyGrab
686 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
687 NULL, getKeybind, setKeyGrab
689 #endif /* LITE */
690 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
691 NULL, getKeybind, setKeyGrab
693 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
694 NULL, getKeybind, setKeyGrab
696 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
697 NULL, getKeybind, setKeyGrab
699 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
700 NULL, getKeybind, setKeyGrab
702 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
703 NULL, getKeybind, setKeyGrab
705 {"HideKey", "None", (void*)WKBD_HIDE,
706 NULL, getKeybind, setKeyGrab
708 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
709 NULL, getKeybind, setKeyGrab
711 {"CloseKey", "None", (void*)WKBD_CLOSE,
712 NULL, getKeybind, setKeyGrab
714 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
715 NULL, getKeybind, setKeyGrab
717 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
718 NULL, getKeybind, setKeyGrab
720 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
721 NULL, getKeybind, setKeyGrab
723 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
724 NULL, getKeybind, setKeyGrab
726 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
727 NULL, getKeybind, setKeyGrab
729 {"ShadeKey", "None", (void*)WKBD_SHADE,
730 NULL, getKeybind, setKeyGrab
732 {"SelectKey", "None", (void*)WKBD_SELECT,
733 NULL, getKeybind, setKeyGrab
735 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
736 NULL, getKeybind, setKeyGrab
738 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
739 NULL, getKeybind, setKeyGrab
741 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
742 NULL, getKeybind, setKeyGrab
744 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
745 NULL, getKeybind, setKeyGrab
747 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
748 NULL, getKeybind, setKeyGrab
750 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
760 NULL, getKeybind, setKeyGrab
762 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
763 NULL, getKeybind, setKeyGrab
765 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
766 NULL, getKeybind, setKeyGrab
768 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
769 NULL, getKeybind, setKeyGrab
771 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
772 NULL, getKeybind, setKeyGrab
774 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
775 NULL, getKeybind, setKeyGrab
777 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
778 NULL, getKeybind, setKeyGrab
780 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
781 NULL, getKeybind, setKeyGrab
783 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
784 NULL, getKeybind, setKeyGrab
786 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
787 NULL, getKeybind, setKeyGrab
789 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
790 NULL, getKeybind, setKeyGrab
792 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
793 NULL, getKeybind, setKeyGrab
795 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
796 NULL, getKeybind, setKeyGrab
798 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
799 NULL, getKeybind, setKeyGrab
801 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
802 NULL, getKeybind, setKeyGrab
804 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
805 NULL, getKeybind, setKeyGrab
807 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
808 NULL, getKeybind, setKeyGrab
810 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
811 NULL, getKeybind, setKeyGrab
813 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
814 NULL, getKeybind, setKeyGrab
817 #ifdef KEEP_XKB_LOCK_STATUS
818 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
819 NULL, getKeybind, setKeyGrab
821 {"KbdModeLock", "NO", NULL,
822 &wPreferences.modelock, getBool, NULL
824 #endif /* KEEP_XKB_LOCK_STATUS */
825 #ifdef DEFINABLE_CURSOR
826 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
827 NULL, getCursor, setCursor
829 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
830 NULL, getCursor, setCursor
832 #if 0
833 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
834 NULL, getCursor, setCursor
836 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
837 NULL, getCursor, setCursor
839 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
840 NULL, getCursor, setCursor
842 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
843 NULL, getCursor, setCursor
845 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
846 NULL, getCursor, setCursor
848 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
849 NULL, getCursor, setCursor
851 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
852 NULL, getCursor, setCursor
854 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
855 NULL, getCursor, setCursor
857 #endif
858 #endif /* DEFINABLE_CURSOR */
862 #if 0
863 static void rereadDefaults(void);
864 #endif
866 #if 0
867 static void
868 rereadDefaults(void)
870 /* must defer the update because accessing X data from a
871 * signal handler can mess up Xlib */
874 #endif
876 static void
877 initDefaults()
879 int i;
880 WDefaultEntry *entry;
882 PLSetStringCmpHook(StringCompareHook);
884 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
885 entry = &optionList[i];
887 entry->plkey = PLMakeString(entry->key);
888 if (entry->default_value)
889 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
890 else
891 entry->plvalue = NULL;
894 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
895 entry = &staticOptionList[i];
897 entry->plkey = PLMakeString(entry->key);
898 if (entry->default_value)
899 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
900 else
901 entry->plvalue = NULL;
905 wDomainName = PLMakeString(WMDOMAIN_NAME);
906 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
908 PLRegister(wDomainName, rereadDefaults);
909 PLRegister(wAttributeDomainName, rereadDefaults);
916 #if 0
917 proplist_t
918 wDefaultsInit(int screen_number)
920 static int defaults_inited = 0;
921 proplist_t dict;
923 if (!defaults_inited) {
924 initDefaults();
927 dict = PLGetDomain(wDomainName);
928 if (!dict) {
929 wwarning(_("could not read domain \"%s\" from defaults database"),
930 PLGetString(wDomainName));
933 return dict;
935 #endif
938 void
939 wDefaultsDestroyDomain(WDDomain *domain)
941 if (domain->dictionary)
942 PLRelease(domain->dictionary);
943 wfree(domain->path);
944 wfree(domain);
948 WDDomain*
949 wDefaultsInitDomain(char *domain, Bool requireDictionary)
951 WDDomain *db;
952 struct stat stbuf;
953 static int inited = 0;
954 char path[PATH_MAX];
955 char *the_path;
956 proplist_t shared_dict=NULL;
958 if (!inited) {
959 inited = 1;
960 initDefaults();
963 db = wmalloc(sizeof(WDDomain));
964 memset(db, 0, sizeof(WDDomain));
965 db->domain_name = domain;
966 db->path = wdefaultspathfordomain(domain);
967 the_path = db->path;
969 if (the_path && stat(the_path, &stbuf)>=0) {
970 db->dictionary = ReadProplistFromFile(the_path);
971 if (db->dictionary) {
972 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
973 PLRelease(db->dictionary);
974 db->dictionary = NULL;
975 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
976 domain, the_path);
978 db->timestamp = stbuf.st_mtime;
979 } else {
980 wwarning(_("could not load domain %s from user defaults database"),
981 domain);
985 /* global system dictionary */
986 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
987 if (stat(path, &stbuf)>=0) {
988 shared_dict = ReadProplistFromFile(path);
989 if (shared_dict) {
990 if (requireDictionary && !PLIsDictionary(shared_dict)) {
991 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
992 domain, path);
993 PLRelease(shared_dict);
994 shared_dict = NULL;
995 } else {
996 if (db->dictionary && PLIsDictionary(shared_dict) &&
997 PLIsDictionary(db->dictionary)) {
998 PLMergeDictionaries(shared_dict, db->dictionary);
999 PLRelease(db->dictionary);
1000 db->dictionary = shared_dict;
1001 if (stbuf.st_mtime > db->timestamp)
1002 db->timestamp = stbuf.st_mtime;
1003 } else if (!db->dictionary) {
1004 db->dictionary = shared_dict;
1005 if (stbuf.st_mtime > db->timestamp)
1006 db->timestamp = stbuf.st_mtime;
1009 } else {
1010 wwarning(_("could not load domain %s from global defaults database (%s)"),
1011 domain, path);
1015 /* set to save it in user's directory, no matter from where it was read */
1016 if (db->dictionary) {
1017 proplist_t tmp = PLMakeString(db->path);
1019 PLSetFilename(db->dictionary, tmp);
1020 PLRelease(tmp);
1023 return db;
1027 void
1028 wReadStaticDefaults(proplist_t dict)
1030 proplist_t plvalue;
1031 WDefaultEntry *entry;
1032 int i;
1033 void *tdata;
1036 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1037 entry = &staticOptionList[i];
1039 if (dict)
1040 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1041 else
1042 plvalue = NULL;
1044 if (!plvalue) {
1045 /* no default in the DB. Use builtin default */
1046 plvalue = entry->plvalue;
1049 if (plvalue) {
1050 /* convert data */
1051 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1052 if (entry->update) {
1053 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1060 void
1061 wDefaultsCheckDomains(void *foo)
1063 WScreen *scr;
1064 struct stat stbuf;
1065 proplist_t dict;
1066 int i;
1067 char path[PATH_MAX];
1069 #ifdef HEARTBEAT
1070 puts("Checking domains...");
1071 #endif
1072 if (stat(WDWindowMaker->path, &stbuf)>=0
1073 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1074 proplist_t shared_dict = NULL;
1075 #ifdef HEARTBEAT
1076 puts("Checking WindowMaker domain");
1077 #endif
1078 WDWindowMaker->timestamp = stbuf.st_mtime;
1080 /* global dictionary */
1081 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1082 if (stat(path, &stbuf)>=0) {
1083 shared_dict = ReadProplistFromFile(path);
1084 if (shared_dict && !PLIsDictionary(shared_dict)) {
1085 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1086 "WindowMaker", path);
1087 PLRelease(shared_dict);
1088 shared_dict = NULL;
1089 } else if (!shared_dict) {
1090 wwarning(_("could not load domain %s from global defaults database"),
1091 "WindowMaker");
1094 /* user dictionary */
1095 dict = ReadProplistFromFile(WDWindowMaker->path);
1096 if (dict) {
1097 if (!PLIsDictionary(dict)) {
1098 PLRelease(dict);
1099 dict = NULL;
1100 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1101 "WindowMaker", WDWindowMaker->path);
1102 } else {
1103 if (shared_dict) {
1104 PLSetFilename(shared_dict, PLGetFilename(dict));
1105 PLMergeDictionaries(shared_dict, dict);
1106 PLRelease(dict);
1107 dict = shared_dict;
1108 shared_dict = NULL;
1110 for (i=0; i<wScreenCount; i++) {
1111 scr = wScreenWithNumber(i);
1112 if (scr)
1113 wReadDefaults(scr, dict);
1115 if (WDWindowMaker->dictionary) {
1116 PLRelease(WDWindowMaker->dictionary);
1118 WDWindowMaker->dictionary = dict;
1120 } else {
1121 wwarning(_("could not load domain %s from user defaults database"),
1122 "WindowMaker");
1124 if (shared_dict) {
1125 PLRelease(shared_dict);
1129 if (stat(WDWindowAttributes->path, &stbuf)>=0
1130 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1131 #ifdef HEARTBEAT
1132 puts("Checking WMWindowAttributes domain");
1133 #endif
1134 dict = ReadProplistFromFile(WDWindowAttributes->path);
1135 if (dict) {
1136 if (!PLIsDictionary(dict)) {
1137 PLRelease(dict);
1138 dict = NULL;
1139 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1140 "WMWindowAttributes", WDWindowAttributes->path);
1141 } else {
1142 if (WDWindowAttributes->dictionary)
1143 PLRelease(WDWindowAttributes->dictionary);
1144 WDWindowAttributes->dictionary = dict;
1145 for (i=0; i<wScreenCount; i++) {
1146 scr = wScreenWithNumber(i);
1147 if (scr)
1148 wDefaultUpdateIcons(scr);
1151 } else {
1152 wwarning(_("could not load domain %s from user defaults database"),
1153 "WMWindowAttributes");
1155 WDWindowAttributes->timestamp = stbuf.st_mtime;
1158 #ifndef LITE
1159 if (stat(WDRootMenu->path, &stbuf)>=0
1160 && WDRootMenu->timestamp < stbuf.st_mtime) {
1161 dict = ReadProplistFromFile(WDRootMenu->path);
1162 #ifdef HEARTBEAT
1163 puts("Checking WMRootMenu domain");
1164 #endif
1165 if (dict) {
1166 if (!PLIsArray(dict) && !PLIsString(dict)) {
1167 PLRelease(dict);
1168 dict = NULL;
1169 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1170 "WMRootMenu", WDRootMenu->path);
1171 } else {
1172 if (WDRootMenu->dictionary) {
1173 PLRelease(WDRootMenu->dictionary);
1175 WDRootMenu->dictionary = dict;
1177 } else {
1178 wwarning(_("could not load domain %s from user defaults database"),
1179 "WMRootMenu");
1181 WDRootMenu->timestamp = stbuf.st_mtime;
1183 #endif /* !LITE */
1185 if (!foo)
1186 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1190 void
1191 wReadDefaults(WScreen *scr, proplist_t new_dict)
1193 proplist_t plvalue, old_value;
1194 WDefaultEntry *entry;
1195 int i, must_update;
1196 int update_workspace_back = 0; /* kluge :/ */
1197 int needs_refresh;
1198 void *tdata;
1199 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1200 ? WDWindowMaker->dictionary : NULL);
1202 must_update = 0;
1204 needs_refresh = 0;
1206 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1207 entry = &optionList[i];
1209 if (new_dict)
1210 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1211 else
1212 plvalue = NULL;
1214 if (!old_dict)
1215 old_value = NULL;
1216 else
1217 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1220 if (!plvalue && !old_value) {
1221 /* no default in the DB. Use builtin default */
1222 plvalue = entry->plvalue;
1223 if (plvalue && new_dict) {
1224 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1225 must_update = 1;
1227 } else if (!plvalue) {
1228 /* value was deleted from DB. Keep current value */
1229 continue;
1230 } else if (!old_value) {
1231 /* set value for the 1st time */
1232 } else if (!PLIsEqual(plvalue, old_value)) {
1233 /* value has changed */
1234 } else {
1236 if (strcmp(entry->key, "WorkspaceBack") == 0
1237 && update_workspace_back
1238 && scr->flags.backimage_helper_launched) {
1239 } else {
1240 /* value was not changed since last time */
1241 continue;
1245 if (plvalue) {
1246 #ifdef DEBUG
1247 printf("Updating %s to %s\n", entry->key,
1248 PLGetDescription(plvalue));
1249 #endif
1250 /* convert data */
1251 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1253 * If the WorkspaceSpecificBack data has been changed
1254 * so that the helper will be launched now, we must be
1255 * sure to send the default background texture config
1256 * to the helper.
1258 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1259 && !scr->flags.backimage_helper_launched) {
1260 update_workspace_back = 1;
1262 if (entry->update) {
1263 needs_refresh |=
1264 (*entry->update)(scr, entry, tdata, entry->extra_data);
1270 if (needs_refresh!=0 && !scr->flags.startup) {
1271 int foo;
1273 foo = 0;
1274 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1275 foo |= WTextureSettings;
1276 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1277 foo |= WFontSettings;
1278 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1279 foo |= WColorSettings;
1280 if (foo)
1281 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1282 (void*)foo);
1284 foo = 0;
1285 if (needs_refresh & REFRESH_MENU_TEXTURE)
1286 foo |= WTextureSettings;
1287 if (needs_refresh & REFRESH_MENU_FONT)
1288 foo |= WFontSettings;
1289 if (needs_refresh & REFRESH_MENU_COLOR)
1290 foo |= WColorSettings;
1291 if (foo)
1292 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1293 (void*)foo);
1295 foo = 0;
1296 if (needs_refresh & REFRESH_WINDOW_FONT) {
1297 foo |= WFontSettings;
1299 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1300 foo |= WTextureSettings;
1302 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1303 foo |= WColorSettings;
1305 if (foo)
1306 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1307 (void*)foo);
1309 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1310 foo = 0;
1311 if (needs_refresh & REFRESH_ICON_FONT) {
1312 foo |= WFontSettings;
1314 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1315 foo |= WTextureSettings;
1317 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1318 foo |= WTextureSettings;
1320 if (foo)
1321 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1322 (void*)foo);
1324 if (needs_refresh & REFRESH_ICON_TILE)
1325 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1330 void
1331 wDefaultUpdateIcons(WScreen *scr)
1333 WAppIcon *aicon = scr->app_icon_list;
1334 WWindow *wwin = scr->focused_window;
1335 char *file;
1337 while(aicon) {
1338 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1339 False);
1340 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1341 || (file && !aicon->icon->file)) {
1342 RImage *new_image;
1344 if (aicon->icon->file)
1345 wfree(aicon->icon->file);
1346 aicon->icon->file = wstrdup(file);
1348 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1349 aicon->wm_class);
1350 if (new_image) {
1351 wIconChangeImage(aicon->icon, new_image);
1352 wAppIconPaint(aicon);
1355 aicon = aicon->next;
1358 if (!wPreferences.flags.noclip)
1359 wClipIconPaint(scr->clip_icon);
1361 while (wwin) {
1362 if (wwin->icon && wwin->flags.miniaturized) {
1363 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1364 False);
1365 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1366 || (file && !wwin->icon->file)) {
1367 RImage *new_image;
1369 if (wwin->icon->file)
1370 wfree(wwin->icon->file);
1371 wwin->icon->file = wstrdup(file);
1373 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1374 wwin->wm_class);
1375 if (new_image)
1376 wIconChangeImage(wwin->icon, new_image);
1379 wwin = wwin->prev;
1384 /* --------------------------- Local ----------------------- */
1386 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1387 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1388 entry->key, x); \
1389 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1390 var = entry->default_value;\
1391 } else var = PLGetString(value)\
1397 static int
1398 string2index(proplist_t key, proplist_t val, proplist_t def,
1399 WOptionEnumeration *values)
1401 char *str;
1402 WOptionEnumeration *v;
1403 char buffer[TOTAL_VALUES_LENGTH];
1405 if (PLIsString(val) && (str = PLGetString(val))) {
1406 for (v=values; v->string!=NULL; v++) {
1407 if (strcasecmp(v->string, str)==0)
1408 return v->value;
1412 buffer[0] = 0;
1413 for (v=values; v->string!=NULL; v++) {
1414 if (!v->is_alias) {
1415 if (buffer[0]!=0)
1416 strcat(buffer, ", ");
1417 strcat(buffer, v->string);
1420 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1421 PLGetString(key), buffer);
1423 if (def) {
1424 return string2index(key, val, NULL, values);
1427 return -1;
1434 * value - is the value in the defaults DB
1435 * addr - is the address to store the data
1436 * ret - is the address to store a pointer to a temporary buffer. ret
1437 * must not be freed and is used by the set functions
1439 static int
1440 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1441 void **ret)
1443 static char data;
1444 char *val;
1445 int second_pass=0;
1447 GET_STRING_OR_DEFAULT("Boolean", val);
1449 again:
1450 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1451 || strcasecmp(val, "YES")==0) {
1453 data = 1;
1454 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1455 || strcasecmp(val, "NO")==0) {
1456 data = 0;
1457 } else {
1458 int i;
1459 if (sscanf(val, "%i", &i)==1) {
1460 if (i!=0)
1461 data = 1;
1462 else
1463 data = 0;
1464 } else {
1465 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1466 val, entry->key);
1467 if (second_pass==0) {
1468 val = PLGetString(entry->plvalue);
1469 second_pass = 1;
1470 wwarning(_("using default \"%s\" instead"), val);
1471 goto again;
1473 return False;
1477 if (ret)
1478 *ret = &data;
1480 if (addr) {
1481 *(char*)addr = data;
1484 return True;
1488 static int
1489 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1490 void **ret)
1492 static int data;
1493 char *val;
1496 GET_STRING_OR_DEFAULT("Integer", val);
1498 if (sscanf(val, "%i", &data)!=1) {
1499 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1500 val, entry->key);
1501 val = PLGetString(entry->plvalue);
1502 wwarning(_("using default \"%s\" instead"), val);
1503 if (sscanf(val, "%i", &data)!=1) {
1504 return False;
1508 if (ret)
1509 *ret = &data;
1511 if (addr) {
1512 *(int*)addr = data;
1514 return True;
1518 static int
1519 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1520 void **ret)
1522 static WCoord data;
1523 char *val_x, *val_y;
1524 int nelem, changed=0;
1525 proplist_t elem_x, elem_y;
1527 again:
1528 if (!PLIsArray(value)) {
1529 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1530 entry->key, "Coordinate");
1531 if (changed==0) {
1532 value = entry->plvalue;
1533 changed = 1;
1534 wwarning(_("using default \"%s\" instead"), entry->default_value);
1535 goto again;
1537 return False;
1540 nelem = PLGetNumberOfElements(value);
1541 if (nelem != 2) {
1542 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1543 entry->key);
1544 if (changed==0) {
1545 value = entry->plvalue;
1546 changed = 1;
1547 wwarning(_("using default \"%s\" instead"), entry->default_value);
1548 goto again;
1550 return False;
1553 elem_x = PLGetArrayElement(value, 0);
1554 elem_y = PLGetArrayElement(value, 1);
1556 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1557 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1558 entry->key);
1559 if (changed==0) {
1560 value = entry->plvalue;
1561 changed = 1;
1562 wwarning(_("using default \"%s\" instead"), entry->default_value);
1563 goto again;
1565 return False;
1568 val_x = PLGetString(elem_x);
1569 val_y = PLGetString(elem_y);
1571 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1572 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1573 if (changed==0) {
1574 value = entry->plvalue;
1575 changed = 1;
1576 wwarning(_("using default \"%s\" instead"), entry->default_value);
1577 goto again;
1579 return False;
1582 if (data.x < 0)
1583 data.x = 0;
1584 else if (data.x > scr->scr_width/3)
1585 data.x = scr->scr_width/3;
1586 if (data.y < 0)
1587 data.y = 0;
1588 else if (data.y > scr->scr_height/3)
1589 data.y = scr->scr_height/3;
1591 if (ret)
1592 *ret = &data;
1594 if (addr) {
1595 *(WCoord*)addr = data;
1598 return True;
1602 #if 0
1603 /* This function is not used at the moment. */
1604 static int
1605 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1606 void **ret)
1608 static char *data;
1610 GET_STRING_OR_DEFAULT("String", data);
1612 if (!data) {
1613 data = PLGetString(entry->plvalue);
1614 if (!data)
1615 return False;
1618 if (ret)
1619 *ret = &data;
1621 if (addr)
1622 *(char**)addr = wstrdup(data);
1624 return True;
1626 #endif
1629 static int
1630 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1631 void **ret)
1633 static char *data;
1634 int i, count, len;
1635 char *ptr;
1636 proplist_t d;
1637 int changed=0;
1639 again:
1640 if (!PLIsArray(value)) {
1641 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1642 entry->key, "an array of paths");
1643 if (changed==0) {
1644 value = entry->plvalue;
1645 changed = 1;
1646 wwarning(_("using default \"%s\" instead"), entry->default_value);
1647 goto again;
1649 return False;
1652 i = 0;
1653 count = PLGetNumberOfElements(value);
1654 if (count < 1) {
1655 if (changed==0) {
1656 value = entry->plvalue;
1657 changed = 1;
1658 wwarning(_("using default \"%s\" instead"), entry->default_value);
1659 goto again;
1661 return False;
1664 len = 0;
1665 for (i=0; i<count; i++) {
1666 d = PLGetArrayElement(value, i);
1667 if (!d || !PLIsString(d)) {
1668 count = i;
1669 break;
1671 len += strlen(PLGetString(d))+1;
1674 ptr = data = wmalloc(len+1);
1676 for (i=0; i<count; i++) {
1677 d = PLGetArrayElement(value, i);
1678 if (!d || !PLIsString(d)) {
1679 break;
1681 strcpy(ptr, PLGetString(d));
1682 ptr += strlen(PLGetString(d));
1683 *ptr = ':';
1684 ptr++;
1686 ptr--; *(ptr--) = 0;
1688 if (*(char**)addr!=NULL) {
1689 wfree(*(char**)addr);
1691 *(char**)addr = data;
1693 return True;
1697 static int
1698 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1699 void **ret)
1701 static signed char data;
1703 data = string2index(entry->plkey, value, entry->default_value,
1704 (WOptionEnumeration*)entry->extra_data);
1705 if (data < 0)
1706 return False;
1708 if (ret)
1709 *ret = &data;
1711 if (addr)
1712 *(signed char*)addr = data;
1714 return True;
1720 * (solid <color>)
1721 * (hgradient <color> <color>)
1722 * (vgradient <color> <color>)
1723 * (dgradient <color> <color>)
1724 * (mhgradient <color> <color> ...)
1725 * (mvgradient <color> <color> ...)
1726 * (mdgradient <color> <color> ...)
1727 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1728 * (tpixmap <file> <color>)
1729 * (spixmap <file> <color>)
1730 * (cpixmap <file> <color>)
1731 * (thgradient <file> <opaqueness> <color> <color>)
1732 * (tvgradient <file> <opaqueness> <color> <color>)
1733 * (tdgradient <file> <opaqueness> <color> <color>)
1734 * (function <lib> <function> ...)
1737 static WTexture*
1738 parse_texture(WScreen *scr, proplist_t pl)
1740 proplist_t elem;
1741 char *val;
1742 int nelem;
1743 WTexture *texture=NULL;
1745 nelem = PLGetNumberOfElements(pl);
1746 if (nelem < 1)
1747 return NULL;
1750 elem = PLGetArrayElement(pl, 0);
1751 if (!elem || !PLIsString(elem))
1752 return NULL;
1753 val = PLGetString(elem);
1756 if (strcasecmp(val, "solid")==0) {
1757 XColor color;
1759 if (nelem != 2)
1760 return NULL;
1762 /* get color */
1764 elem = PLGetArrayElement(pl, 1);
1765 if (!elem || !PLIsString(elem))
1766 return NULL;
1767 val = PLGetString(elem);
1769 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1770 wwarning(_("\"%s\" is not a valid color name"), val);
1771 return NULL;
1774 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1775 } else if (strcasecmp(val, "dgradient")==0
1776 || strcasecmp(val, "vgradient")==0
1777 || strcasecmp(val, "hgradient")==0) {
1778 RColor color1, color2;
1779 XColor xcolor;
1780 int type;
1782 if (nelem != 3) {
1783 wwarning(_("bad number of arguments in gradient specification"));
1784 return NULL;
1787 if (val[0]=='d' || val[0]=='D')
1788 type = WTEX_DGRADIENT;
1789 else if (val[0]=='h' || val[0]=='H')
1790 type = WTEX_HGRADIENT;
1791 else
1792 type = WTEX_VGRADIENT;
1795 /* get from color */
1796 elem = PLGetArrayElement(pl, 1);
1797 if (!elem || !PLIsString(elem))
1798 return NULL;
1799 val = PLGetString(elem);
1801 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1802 wwarning(_("\"%s\" is not a valid color name"), val);
1803 return NULL;
1805 color1.alpha = 255;
1806 color1.red = xcolor.red >> 8;
1807 color1.green = xcolor.green >> 8;
1808 color1.blue = xcolor.blue >> 8;
1810 /* get to color */
1811 elem = PLGetArrayElement(pl, 2);
1812 if (!elem || !PLIsString(elem)) {
1813 return NULL;
1815 val = PLGetString(elem);
1817 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1818 wwarning(_("\"%s\" is not a valid color name"), val);
1819 return NULL;
1821 color2.alpha = 255;
1822 color2.red = xcolor.red >> 8;
1823 color2.green = xcolor.green >> 8;
1824 color2.blue = xcolor.blue >> 8;
1826 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1828 } else if (strcasecmp(val, "igradient")==0) {
1829 RColor colors1[2], colors2[2];
1830 int th1, th2;
1831 XColor xcolor;
1832 int i;
1834 if (nelem != 7) {
1835 wwarning(_("bad number of arguments in gradient specification"));
1836 return NULL;
1839 /* get from color */
1840 for (i = 0; i < 2; i++) {
1841 elem = PLGetArrayElement(pl, 1+i);
1842 if (!elem || !PLIsString(elem))
1843 return NULL;
1844 val = PLGetString(elem);
1846 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1847 wwarning(_("\"%s\" is not a valid color name"), val);
1848 return NULL;
1850 colors1[i].alpha = 255;
1851 colors1[i].red = xcolor.red >> 8;
1852 colors1[i].green = xcolor.green >> 8;
1853 colors1[i].blue = xcolor.blue >> 8;
1855 elem = PLGetArrayElement(pl, 3);
1856 if (!elem || !PLIsString(elem))
1857 return NULL;
1858 val = PLGetString(elem);
1859 th1 = atoi(val);
1862 /* get from color */
1863 for (i = 0; i < 2; i++) {
1864 elem = PLGetArrayElement(pl, 4+i);
1865 if (!elem || !PLIsString(elem))
1866 return NULL;
1867 val = PLGetString(elem);
1869 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1870 wwarning(_("\"%s\" is not a valid color name"), val);
1871 return NULL;
1873 colors2[i].alpha = 255;
1874 colors2[i].red = xcolor.red >> 8;
1875 colors2[i].green = xcolor.green >> 8;
1876 colors2[i].blue = xcolor.blue >> 8;
1878 elem = PLGetArrayElement(pl, 6);
1879 if (!elem || !PLIsString(elem))
1880 return NULL;
1881 val = PLGetString(elem);
1882 th2 = atoi(val);
1884 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1885 th2, colors2);
1887 } else if (strcasecmp(val, "mhgradient")==0
1888 || strcasecmp(val, "mvgradient")==0
1889 || strcasecmp(val, "mdgradient")==0) {
1890 XColor color;
1891 RColor **colors;
1892 int i, count;
1893 int type;
1895 if (nelem < 3) {
1896 wwarning(_("too few arguments in multicolor gradient specification"));
1897 return NULL;
1900 if (val[1]=='h' || val[1]=='H')
1901 type = WTEX_MHGRADIENT;
1902 else if (val[1]=='v' || val[1]=='V')
1903 type = WTEX_MVGRADIENT;
1904 else
1905 type = WTEX_MDGRADIENT;
1907 count = nelem-1;
1909 colors = wmalloc(sizeof(RColor*)*(count+1));
1911 for (i=0; i<count; i++) {
1912 elem = PLGetArrayElement(pl, i+1);
1913 if (!elem || !PLIsString(elem)) {
1914 for (--i; i>=0; --i) {
1915 wfree(colors[i]);
1917 wfree(colors);
1918 return NULL;
1920 val = PLGetString(elem);
1922 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1923 wwarning(_("\"%s\" is not a valid color name"), val);
1924 for (--i; i>=0; --i) {
1925 wfree(colors[i]);
1927 wfree(colors);
1928 return NULL;
1929 } else {
1930 colors[i] = wmalloc(sizeof(RColor));
1931 colors[i]->red = color.red >> 8;
1932 colors[i]->green = color.green >> 8;
1933 colors[i]->blue = color.blue >> 8;
1936 colors[i] = NULL;
1938 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1939 } else if (strcasecmp(val, "spixmap")==0 ||
1940 strcasecmp(val, "cpixmap")==0 ||
1941 strcasecmp(val, "tpixmap")==0) {
1942 XColor color;
1943 int type;
1945 if (nelem != 3)
1946 return NULL;
1948 if (val[0] == 's' || val[0] == 'S')
1949 type = WTP_SCALE;
1950 else if (val[0] == 'c' || val[0] == 'C')
1951 type = WTP_CENTER;
1952 else
1953 type = WTP_TILE;
1955 /* get color */
1956 elem = PLGetArrayElement(pl, 2);
1957 if (!elem || !PLIsString(elem)) {
1958 return NULL;
1960 val = PLGetString(elem);
1962 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1963 wwarning(_("\"%s\" is not a valid color name"), val);
1964 return NULL;
1967 /* file name */
1968 elem = PLGetArrayElement(pl, 1);
1969 if (!elem || !PLIsString(elem))
1970 return NULL;
1971 val = PLGetString(elem);
1973 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1974 } else if (strcasecmp(val, "thgradient")==0
1975 || strcasecmp(val, "tvgradient")==0
1976 || strcasecmp(val, "tdgradient")==0) {
1977 RColor color1, color2;
1978 XColor xcolor;
1979 int opacity;
1980 int style;
1982 if (val[1]=='h' || val[1]=='H')
1983 style = WTEX_THGRADIENT;
1984 else if (val[1]=='v' || val[1]=='V')
1985 style = WTEX_TVGRADIENT;
1986 else
1987 style = WTEX_TDGRADIENT;
1989 if (nelem != 5) {
1990 wwarning(_("bad number of arguments in textured gradient specification"));
1991 return NULL;
1994 /* get from color */
1995 elem = PLGetArrayElement(pl, 3);
1996 if (!elem || !PLIsString(elem))
1997 return NULL;
1998 val = PLGetString(elem);
2000 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2001 wwarning(_("\"%s\" is not a valid color name"), val);
2002 return NULL;
2004 color1.alpha = 255;
2005 color1.red = xcolor.red >> 8;
2006 color1.green = xcolor.green >> 8;
2007 color1.blue = xcolor.blue >> 8;
2009 /* get to color */
2010 elem = PLGetArrayElement(pl, 4);
2011 if (!elem || !PLIsString(elem)) {
2012 return NULL;
2014 val = PLGetString(elem);
2016 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2017 wwarning(_("\"%s\" is not a valid color name"), val);
2018 return NULL;
2020 color2.alpha = 255;
2021 color2.red = xcolor.red >> 8;
2022 color2.green = xcolor.green >> 8;
2023 color2.blue = xcolor.blue >> 8;
2025 /* get opacity */
2026 elem = PLGetArrayElement(pl, 2);
2027 if (!elem || !PLIsString(elem))
2028 opacity = 128;
2029 else
2030 val = PLGetString(elem);
2032 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2033 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2034 opacity = 128;
2037 /* get file name */
2038 elem = PLGetArrayElement(pl, 1);
2039 if (!elem || !PLIsString(elem))
2040 return NULL;
2041 val = PLGetString(elem);
2043 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2044 val, opacity);
2046 #ifdef TEXTURE_PLUGIN
2047 else if (strcasecmp(val, "function")==0) {
2048 WTexFunction *function;
2049 void (*initFunc) (Display *, Colormap);
2050 char *lib, *func, **argv;
2051 int i, argc;
2053 if (nelem < 3)
2054 return NULL;
2056 /* get the library name */
2057 elem = PLGetArrayElement(pl, 1);
2058 if (!elem || !PLIsString(elem)) {
2059 return NULL;
2061 lib = PLGetString(elem);
2063 /* get the function name */
2064 elem = PLGetArrayElement(pl, 2);
2065 if (!elem || !PLIsString(elem)) {
2066 return NULL;
2068 func = PLGetString(elem);
2070 argc = nelem - 2;
2071 argv = (char **)wmalloc(argc * sizeof(char *));
2073 /* get the parameters */
2074 argv[0] = wstrdup(func);
2075 for (i = 0; i < argc - 1; i++) {
2076 elem = PLGetArrayElement(pl, 3 + i);
2077 if (!elem || !PLIsString(elem)) {
2078 wfree(argv);
2080 return NULL;
2082 argv[i+1] = wstrdup(PLGetString(elem));
2085 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2087 #ifdef HAVE_DLFCN_H
2088 if (function) {
2089 initFunc = dlsym(function->handle, "initWindowMaker");
2090 if (initFunc) {
2091 initFunc(dpy, scr->w_colormap);
2092 } else {
2093 wwarning(_("could not initialize library %s"), lib);
2095 } else {
2096 wwarning(_("could not find function %s::%s"), lib, func);
2098 #endif /* HAVE_DLFCN_H */
2099 texture = (WTexture*)function;
2101 #endif /* TEXTURE_PLUGIN */
2102 else {
2103 wwarning(_("invalid texture type %s"), val);
2104 return NULL;
2106 return texture;
2111 static int
2112 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2113 void **ret)
2115 static WTexture *texture;
2116 int changed=0;
2118 again:
2119 if (!PLIsArray(value)) {
2120 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2121 entry->key, "Texture");
2122 if (changed==0) {
2123 value = entry->plvalue;
2124 changed = 1;
2125 wwarning(_("using default \"%s\" instead"), entry->default_value);
2126 goto again;
2128 return False;
2131 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2132 proplist_t pl;
2134 pl = PLGetArrayElement(value, 0);
2135 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2136 || strcasecmp(PLGetString(pl), "solid")!=0) {
2137 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2138 entry->key, "Solid Texture");
2140 value = entry->plvalue;
2141 changed = 1;
2142 wwarning(_("using default \"%s\" instead"), entry->default_value);
2143 goto again;
2147 texture = parse_texture(scr, value);
2149 if (!texture) {
2150 wwarning(_("Error in texture specification for key \"%s\""),
2151 entry->key);
2152 if (changed==0) {
2153 value = entry->plvalue;
2154 changed = 1;
2155 wwarning(_("using default \"%s\" instead"), entry->default_value);
2156 goto again;
2158 return False;
2161 if (ret)
2162 *ret = &texture;
2164 if (addr)
2165 *(WTexture**)addr = texture;
2167 return True;
2172 #ifdef DRAWSTRING_PLUGIN
2173 static int
2174 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2175 void *addr, void **ret)
2177 proplist_t elem;
2178 char *val, *lib, *func, **argv;
2179 int argc, changed;
2181 /* Destroying functions if they are already loaded. */
2182 /* The function will auto-check NULL, does this break any ethic? */
2183 if (strcmp(entry->key, "FTitleColor")==0) {
2184 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2185 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2186 } else if (strcmp(entry->key, "UTitleColor")==0) {
2187 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2188 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2189 } else if (strcmp(entry->key, "PTitleColor")==0) {
2190 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2191 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2192 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2193 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2194 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2195 } else if (strcmp(entry->key, "MenuTextColor")==0) { /* problemssss */
2196 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2197 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2200 if (PLIsArray(value)) {
2201 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2202 argc -= 2;
2203 argv = (char **)wmalloc(argc * sizeof(char *));
2205 elem = PLGetArrayElement(value,0);
2206 if (!elem || !PLIsString(elem)) return False;
2207 val = PLGetString(elem);
2208 if (strcasecmp(val, "function")==0) {
2209 elem = PLGetArrayElement(value, 1); /* library name */
2210 if (!elem || !PLIsString(elem)) return False;
2211 lib = PLGetString(elem);
2212 elem = PLGetArrayElement(value, 2); /* function name */
2213 if (!elem || !PLIsString(elem)) return False;
2214 func = PLGetString(elem);
2215 scr->drawstring_func[changed] = wPluginCreateFunction(W_FUNCTION_DRAWSTRING,
2216 lib, "initDrawString",
2217 wPluginPackData(2, func, "widthOfString"),
2218 "destroyDrawString", value,
2219 wPluginPackData(3, dpy, &scr->w_colormap, "dummy"));
2222 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2223 } else if (PLIsString(value)) {
2224 return getColor(scr, entry, value, addr, ret);
2227 return False;
2229 #endif /* DRAWSTRING_PLUGIN */
2233 static int
2234 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2235 void *addr, void **ret)
2237 proplist_t elem;
2238 int changed = 0;
2239 char *val;
2240 int nelem;
2242 again:
2243 if (!PLIsArray(value)) {
2244 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2245 "WorkspaceBack", "Texture or None");
2246 if (changed==0) {
2247 value = entry->plvalue;
2248 changed = 1;
2249 wwarning(_("using default \"%s\" instead"), entry->default_value);
2250 goto again;
2252 return False;
2255 /* only do basic error checking and verify for None texture */
2257 nelem = PLGetNumberOfElements(value);
2258 if (nelem > 0) {
2259 elem = PLGetArrayElement(value, 0);
2260 if (!elem || !PLIsString(elem)) {
2261 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2262 if (changed==0) {
2263 value = entry->plvalue;
2264 changed = 1;
2265 wwarning(_("using default \"%s\" instead"), entry->default_value);
2266 goto again;
2268 return False;
2270 val = PLGetString(elem);
2272 if (strcasecmp(val, "None")==0)
2273 return True;
2275 *ret = PLRetain(value);
2277 return True;
2281 static int
2282 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2283 void *addr, void **ret)
2285 proplist_t elem;
2286 int nelem;
2287 int changed = 0;
2289 again:
2290 if (!PLIsArray(value)) {
2291 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2292 "WorkspaceSpecificBack", "an array of textures");
2293 if (changed==0) {
2294 value = entry->plvalue;
2295 changed = 1;
2296 wwarning(_("using default \"%s\" instead"), entry->default_value);
2297 goto again;
2299 return False;
2302 /* only do basic error checking and verify for None texture */
2304 nelem = PLGetNumberOfElements(value);
2305 if (nelem > 0) {
2306 while (nelem--) {
2307 elem = PLGetArrayElement(value, nelem);
2308 if (!elem || !PLIsArray(elem)) {
2309 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2310 nelem);
2315 *ret = PLRetain(value);
2317 #ifdef notworking
2319 * Kluge to force wmsetbg helper to set the default background.
2320 * If the WorkspaceSpecificBack is changed once wmaker has started,
2321 * the WorkspaceBack won't be sent to the helper, unless the user
2322 * changes it's value too. So, we must force this by removing the
2323 * value from the defaults DB.
2325 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2326 proplist_t key = PLMakeString("WorkspaceBack");
2328 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2330 PLRelease(key);
2332 #endif
2333 return True;
2337 static int
2338 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2339 void **ret)
2341 static WMFont *font;
2342 char *val;
2344 GET_STRING_OR_DEFAULT("Font", val);
2346 font = WMCreateFont(scr->wmscreen, val);
2347 if (!font)
2348 font = WMCreateFont(scr->wmscreen, "fixed");
2350 if (!font) {
2351 wfatal(_("could not load any usable font!!!"));
2352 exit(1);
2355 if (ret)
2356 *ret = font;
2358 /* can't assign font value outside update function */
2359 wassertrv(addr == NULL, True);
2361 return True;
2365 static int
2366 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2367 void **ret)
2369 static XColor color;
2370 char *val;
2371 int second_pass=0;
2373 GET_STRING_OR_DEFAULT("Color", val);
2376 again:
2377 if (!wGetColor(scr, val, &color)) {
2378 wwarning(_("could not get color for key \"%s\""),
2379 entry->key);
2380 if (second_pass==0) {
2381 val = PLGetString(entry->plvalue);
2382 second_pass = 1;
2383 wwarning(_("using default \"%s\" instead"), val);
2384 goto again;
2386 return False;
2389 if (ret)
2390 *ret = &color;
2392 assert(addr==NULL);
2394 if (addr)
2395 *(unsigned long*)addr = pixel;
2398 return True;
2403 static int
2404 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2405 void **ret)
2407 static WShortKey shortcut;
2408 KeySym ksym;
2409 char *val;
2410 char *k;
2411 char buf[128], *b;
2414 GET_STRING_OR_DEFAULT("Key spec", val);
2416 if (!val || strcasecmp(val, "NONE")==0) {
2417 shortcut.keycode = 0;
2418 shortcut.modifier = 0;
2419 if (ret)
2420 *ret = &shortcut;
2421 return True;
2424 strcpy(buf, val);
2426 b = (char*)buf;
2428 /* get modifiers */
2429 shortcut.modifier = 0;
2430 while ((k = strchr(b, '+'))!=NULL) {
2431 int mod;
2433 *k = 0;
2434 mod = wXModifierFromKey(b);
2435 if (mod<0) {
2436 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2437 return False;
2439 shortcut.modifier |= mod;
2441 b = k+1;
2444 /* get key */
2445 ksym = XStringToKeysym(b);
2447 if (ksym==NoSymbol) {
2448 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2449 val);
2450 return False;
2453 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2454 if (shortcut.keycode==0) {
2455 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2456 return False;
2459 if (ret)
2460 *ret = &shortcut;
2462 return True;
2466 static int
2467 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2468 void **ret)
2470 static unsigned int mask;
2471 char *str;
2473 GET_STRING_OR_DEFAULT("Modifier Key", str);
2475 if (!str)
2476 return False;
2478 mask = wXModifierFromKey(str);
2479 if (mask < 0) {
2480 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2481 mask = 0;
2482 return False;
2485 if (addr)
2486 *(unsigned int*)addr = mask;
2488 if (ret)
2489 *ret = &mask;
2491 return True;
2495 #ifdef NEWSTUFF
2496 static int
2497 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2498 void *addr, void **ret)
2500 unsigned int mask;
2501 char *str;
2502 RImage *image;
2503 int i, n;
2504 int w, h;
2506 GET_STRING_OR_DEFAULT("Image File Path", str);
2507 if (!str)
2508 return False;
2510 image = RLoadImage(scr->rcontext, str, 0);
2511 if (!image) {
2512 wwarning(_("could not load image in option %s: %s"), entry->key,
2513 RMessageForError(RErrorCode));
2514 return False;
2517 if (*(RImage**)addr) {
2518 RDestroyImage(*(RImage**)addr);
2520 if (addr)
2521 *(RImage**)addr = image;
2523 assert(ret == NULL);
2525 if (ret)
2526 *(RImage**)ret = image;
2529 return True;
2531 #endif
2533 #ifdef DEFINABLE_CURSOR
2535 # include <X11/cursorfont.h>
2536 typedef struct
2538 char *name;
2539 int id;
2540 } WCursorLookup;
2542 #define CURSOR_ID_NONE (XC_num_glyphs)
2544 static WCursorLookup cursor_table[] =
2546 { "X_cursor", XC_X_cursor },
2547 { "arrow", XC_arrow },
2548 { "based_arrow_down", XC_based_arrow_down },
2549 { "based_arrow_up", XC_based_arrow_up },
2550 { "boat", XC_boat },
2551 { "bogosity", XC_bogosity },
2552 { "bottom_left_corner", XC_bottom_left_corner },
2553 { "bottom_right_corner", XC_bottom_right_corner },
2554 { "bottom_side", XC_bottom_side },
2555 { "bottom_tee", XC_bottom_tee },
2556 { "box_spiral", XC_box_spiral },
2557 { "center_ptr", XC_center_ptr },
2558 { "circle", XC_circle },
2559 { "clock", XC_clock },
2560 { "coffee_mug", XC_coffee_mug },
2561 { "cross", XC_cross },
2562 { "cross_reverse", XC_cross_reverse },
2563 { "crosshair", XC_crosshair },
2564 { "diamond_cross", XC_diamond_cross },
2565 { "dot", XC_dot },
2566 { "dotbox", XC_dotbox },
2567 { "double_arrow", XC_double_arrow },
2568 { "draft_large", XC_draft_large },
2569 { "draft_small", XC_draft_small },
2570 { "draped_box", XC_draped_box },
2571 { "exchange", XC_exchange },
2572 { "fleur", XC_fleur },
2573 { "gobbler", XC_gobbler },
2574 { "gumby", XC_gumby },
2575 { "hand1", XC_hand1 },
2576 { "hand2", XC_hand2 },
2577 { "heart", XC_heart },
2578 { "icon", XC_icon },
2579 { "iron_cross", XC_iron_cross },
2580 { "left_ptr", XC_left_ptr },
2581 { "left_side", XC_left_side },
2582 { "left_tee", XC_left_tee },
2583 { "leftbutton", XC_leftbutton },
2584 { "ll_angle", XC_ll_angle },
2585 { "lr_angle", XC_lr_angle },
2586 { "man", XC_man },
2587 { "middlebutton", XC_middlebutton },
2588 { "mouse", XC_mouse },
2589 { "pencil", XC_pencil },
2590 { "pirate", XC_pirate },
2591 { "plus", XC_plus },
2592 { "question_arrow", XC_question_arrow },
2593 { "right_ptr", XC_right_ptr },
2594 { "right_side", XC_right_side },
2595 { "right_tee", XC_right_tee },
2596 { "rightbutton", XC_rightbutton },
2597 { "rtl_logo", XC_rtl_logo },
2598 { "sailboat", XC_sailboat },
2599 { "sb_down_arrow", XC_sb_down_arrow },
2600 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2601 { "sb_left_arrow", XC_sb_left_arrow },
2602 { "sb_right_arrow", XC_sb_right_arrow },
2603 { "sb_up_arrow", XC_sb_up_arrow },
2604 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2605 { "shuttle", XC_shuttle },
2606 { "sizing", XC_sizing },
2607 { "spider", XC_spider },
2608 { "spraycan", XC_spraycan },
2609 { "star", XC_star },
2610 { "target", XC_target },
2611 { "tcross", XC_tcross },
2612 { "top_left_arrow", XC_top_left_arrow },
2613 { "top_left_corner", XC_top_left_corner },
2614 { "top_right_corner", XC_top_right_corner },
2615 { "top_side", XC_top_side },
2616 { "top_tee", XC_top_tee },
2617 { "trek", XC_trek },
2618 { "ul_angle", XC_ul_angle },
2619 { "umbrella", XC_umbrella },
2620 { "ur_angle", XC_ur_angle },
2621 { "watch", XC_watch },
2622 { "xterm", XC_xterm },
2623 { NULL, CURSOR_ID_NONE }
2626 static void
2627 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2629 switch(status) {
2630 case BitmapOpenFailed:
2631 wwarning(_("failed to open bitmap file \"%s\""), filename);
2632 break;
2633 case BitmapFileInvalid:
2634 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2635 break;
2636 case BitmapNoMemory:
2637 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2638 break;
2639 case BitmapSuccess:
2640 XFreePixmap(dpy, bitmap);
2641 break;
2646 * (none)
2647 * (builtin, <cursor_name>)
2648 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2650 static int
2651 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2653 proplist_t elem;
2654 char *val;
2655 int nelem;
2656 int status = 0;
2658 nelem = PLGetNumberOfElements(pl);
2659 if (nelem < 1) {
2660 return(status);
2662 elem = PLGetArrayElement(pl, 0);
2663 if (!elem || !PLIsString(elem)) {
2664 return(status);
2666 val = PLGetString(elem);
2668 if (0 == strcasecmp(val, "none")) {
2669 status = 1;
2670 *cursor = None;
2671 } else if (0 == strcasecmp(val, "builtin")) {
2672 int i;
2673 int cursor_id = CURSOR_ID_NONE;
2675 if (2 != nelem) {
2676 wwarning(_("bad number of arguments in cursor specification"));
2677 return(status);
2679 elem = PLGetArrayElement(pl, 1);
2680 if (!elem || !PLIsString(elem)) {
2681 return(status);
2683 val = PLGetString(elem);
2685 for (i = 0; NULL != cursor_table[i].name; i++) {
2686 if (0 == strcasecmp(val, cursor_table[i].name)) {
2687 cursor_id = cursor_table[i].id;
2688 break;
2691 if (CURSOR_ID_NONE == cursor_id) {
2692 wwarning(_("unknown builtin cursor name \"%s\""), val);
2693 } else {
2694 *cursor = XCreateFontCursor(dpy, cursor_id);
2695 status = 1;
2697 } else if (0 == strcasecmp(val, "bitmap")) {
2698 char *bitmap_name;
2699 char *mask_name;
2700 int bitmap_status;
2701 int mask_status;
2702 Pixmap bitmap;
2703 Pixmap mask;
2704 unsigned int w, h;
2705 int x, y;
2706 XColor fg, bg;
2708 if (3 != nelem) {
2709 wwarning(_("bad number of arguments in cursor specification"));
2710 return(status);
2712 elem = PLGetArrayElement(pl, 1);
2713 if (!elem || !PLIsString(elem)) {
2714 return(status);
2716 val = PLGetString(elem);
2717 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2718 if (!bitmap_name) {
2719 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2720 return(status);
2722 elem = PLGetArrayElement(pl, 2);
2723 if (!elem || !PLIsString(elem)) {
2724 wfree(bitmap_name);
2725 return(status);
2727 val = PLGetString(elem);
2728 mask_name = FindImage(wPreferences.pixmap_path, val);
2729 if (!mask_name) {
2730 wfree(bitmap_name);
2731 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2732 return(status);
2734 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2735 &mask, &x, &y);
2736 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2737 &bitmap, &x, &y);
2738 if ((BitmapSuccess == bitmap_status) &&
2739 (BitmapSuccess == mask_status)) {
2740 fg.pixel = scr->black_pixel;
2741 bg.pixel = scr->white_pixel;
2742 XQueryColor(dpy, scr->w_colormap, &fg);
2743 XQueryColor(dpy, scr->w_colormap, &bg);
2744 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2745 status = 1;
2747 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2748 check_bitmap_status(mask_status, mask_name, mask);
2749 wfree(bitmap_name);
2750 wfree(mask_name);
2752 return(status);
2756 static int
2757 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2758 void **ret)
2760 static Cursor cursor;
2761 int status;
2762 int changed = 0;
2764 again:
2765 if (!PLIsArray(value)) {
2766 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2767 entry->key, "cursor specification");
2768 if (!changed) {
2769 value = entry->plvalue;
2770 changed = 1;
2771 wwarning(_("using default \"%s\" instead"), entry->default_value);
2772 goto again;
2774 return(False);
2776 status = parse_cursor(scr, value, &cursor);
2777 if (!status) {
2778 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2779 if (!changed) {
2780 value = entry->plvalue;
2781 changed = 1;
2782 wwarning(_("using default \"%s\" instead"), entry->default_value);
2783 goto again;
2785 return(False);
2787 if (ret) {
2788 *ret = &cursor;
2790 if (addr) {
2791 *(Cursor *)addr = cursor;
2793 return(True);
2795 #undef CURSOR_ID_NONE
2797 #endif /* DEFINABLE_CURSOR */
2800 /* ---------------- value setting functions --------------- */
2801 static int
2802 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2804 return REFRESH_WINDOW_TITLE_COLOR;
2807 static int
2808 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2810 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2813 static int
2814 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2816 switch (which) {
2817 case WM_DOCK:
2818 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2819 break;
2820 case WM_CLIP:
2821 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2822 break;
2823 default:
2824 break;
2826 return 0;
2830 static int
2831 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2833 if (scr->workspaces) {
2834 wWorkspaceForceChange(scr, scr->current_workspace);
2835 wArrangeIcons(scr, False);
2837 return 0;
2840 #if not_used
2841 static int
2842 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2844 if (*value <= 0)
2845 *(int*)foo = 1;
2847 return 0;
2849 #endif
2853 static int
2854 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2856 Pixmap pixmap;
2857 RImage *img;
2858 int reset = 0;
2860 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2861 wPreferences.icon_size,
2862 ((*texture)->any.type & WREL_BORDER_MASK)
2863 ? WREL_ICON : WREL_FLAT);
2864 if (!img) {
2865 wwarning(_("could not render texture for icon background"));
2866 if (!entry->addr)
2867 wTextureDestroy(scr, *texture);
2868 return 0;
2870 RConvertImage(scr->rcontext, img, &pixmap);
2872 if (scr->icon_tile) {
2873 reset = 1;
2874 RDestroyImage(scr->icon_tile);
2875 XFreePixmap(dpy, scr->icon_tile_pixmap);
2878 scr->icon_tile = img;
2881 /* put the icon in the noticeboard hint */
2882 PropSetIconTileHint(scr, img);
2885 if (!wPreferences.flags.noclip) {
2886 if (scr->clip_tile) {
2887 RDestroyImage(scr->clip_tile);
2889 scr->clip_tile = wClipMakeTile(scr, img);
2892 scr->icon_tile_pixmap = pixmap;
2894 if (scr->def_icon_pixmap) {
2895 XFreePixmap(dpy, scr->def_icon_pixmap);
2896 scr->def_icon_pixmap = None;
2898 if (scr->def_ticon_pixmap) {
2899 XFreePixmap(dpy, scr->def_ticon_pixmap);
2900 scr->def_ticon_pixmap = None;
2903 if (scr->icon_back_texture) {
2904 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2906 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2908 if (scr->clip_balloon)
2909 XSetWindowBackground(dpy, scr->clip_balloon,
2910 (*texture)->any.color.pixel);
2913 * Free the texture as nobody else will use it, nor refer to it.
2915 if (!entry->addr)
2916 wTextureDestroy(scr, *texture);
2918 return (reset ? REFRESH_ICON_TILE : 0);
2923 static int
2924 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2926 if (scr->title_font) {
2927 WMReleaseFont(scr->title_font);
2929 scr->title_font = font;
2931 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2935 static int
2936 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2938 if (scr->menu_title_font) {
2939 WMReleaseFont(scr->menu_title_font);
2942 scr->menu_title_font = font;
2944 return REFRESH_MENU_TITLE_FONT;
2948 static int
2949 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2951 if (scr->menu_entry_font) {
2952 WMReleaseFont(scr->menu_entry_font);
2954 scr->menu_entry_font = font;
2956 return REFRESH_MENU_FONT;
2961 static int
2962 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2964 if (scr->icon_title_font) {
2965 WMReleaseFont(scr->icon_title_font);
2968 scr->icon_title_font = font;
2970 return REFRESH_ICON_FONT;
2974 static int
2975 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2977 if (scr->clip_title_font) {
2978 WMReleaseFont(scr->clip_title_font);
2981 scr->clip_title_font = font;
2983 return REFRESH_ICON_FONT;
2987 static int
2988 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2990 if (scr->workspace_name_font) {
2991 WMReleaseFont(scr->workspace_name_font);
2994 scr->workspace_name_font = font;
2996 return 0;
3000 static int
3001 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3003 if (scr->select_pixel!=scr->white_pixel &&
3004 scr->select_pixel!=scr->black_pixel) {
3005 wFreeColor(scr, scr->select_pixel);
3008 scr->select_pixel = color->pixel;
3010 return REFRESH_MENU_COLOR;
3014 static int
3015 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3017 if (scr->select_text_pixel!=scr->white_pixel &&
3018 scr->select_text_pixel!=scr->black_pixel) {
3019 wFreeColor(scr, scr->select_text_pixel);
3022 scr->select_text_pixel = color->pixel;
3024 return REFRESH_MENU_COLOR;
3028 static int
3029 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3031 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
3032 scr->clip_title_pixel[index]!=scr->black_pixel) {
3033 wFreeColor(scr, scr->clip_title_pixel[index]);
3035 scr->clip_title_pixel[index] = color->pixel;
3037 #ifdef GRADIENT_CLIP_ARROW
3038 if (index == CLIP_NORMAL) {
3039 RImage *image;
3040 RColor color1, color2;
3041 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3042 int as = pt - 15; /* 15 = 5+5+5 */
3044 FREE_PIXMAP(scr->clip_arrow_gradient);
3046 color1.red = (color->red >> 8)*6/10;
3047 color1.green = (color->green >> 8)*6/10;
3048 color1.blue = (color->blue >> 8)*6/10;
3050 color2.red = WMIN((color->red >> 8)*20/10, 255);
3051 color2.green = WMIN((color->green >> 8)*20/10, 255);
3052 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3054 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3055 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3056 RDestroyImage(image);
3058 #endif /* GRADIENT_CLIP_ARROW */
3060 return REFRESH_ICON_TITLE_COLOR;
3064 static int
3065 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3067 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3068 scr->window_title_pixel[index]!=scr->black_pixel) {
3069 wFreeColor(scr, scr->window_title_pixel[index]);
3072 scr->window_title_pixel[index] = color->pixel;
3074 if (index == WS_UNFOCUSED)
3075 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3077 return REFRESH_WINDOW_TITLE_COLOR;
3081 static int
3082 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3084 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3085 scr->menu_title_pixel[0]!=scr->black_pixel) {
3086 #ifdef DRAWSTRING_PLUGIN
3087 if(!scr->drawstring_func[W_STRING_MTITLE])
3088 #endif
3089 wFreeColor(scr, scr->menu_title_pixel[0]);
3092 scr->menu_title_pixel[0] = color->pixel;
3093 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3095 return REFRESH_MENU_TITLE_COLOR;
3099 static int
3100 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3102 XGCValues gcv;
3103 #define gcm (GCForeground|GCBackground|GCFillStyle)
3105 if (scr->mtext_pixel!=scr->white_pixel &&
3106 scr->mtext_pixel!=scr->black_pixel) {
3107 wFreeColor(scr, scr->mtext_pixel);
3110 scr->mtext_pixel = color->pixel;
3112 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3115 if (scr->dtext_pixel == scr->mtext_pixel) {
3116 gcv.foreground = scr->white_pixel;
3117 gcv.background = scr->black_pixel;
3118 gcv.fill_style = FillStippled;
3119 } else {
3120 gcv.foreground = scr->dtext_pixel;
3121 gcv.fill_style = FillSolid;
3123 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3125 return REFRESH_MENU_COLOR;
3126 #undef gcm
3130 static int
3131 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3133 XGCValues gcv;
3134 #define gcm (GCForeground|GCBackground|GCFillStyle)
3136 if (scr->dtext_pixel!=scr->white_pixel &&
3137 scr->dtext_pixel!=scr->black_pixel) {
3138 wFreeColor(scr, scr->dtext_pixel);
3141 scr->dtext_pixel = color->pixel;
3143 if (scr->dtext_pixel == scr->mtext_pixel) {
3144 gcv.foreground = scr->white_pixel;
3145 gcv.background = scr->black_pixel;
3146 gcv.fill_style = FillStippled;
3147 } else {
3148 gcv.foreground = scr->dtext_pixel;
3149 gcv.fill_style = FillSolid;
3151 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3153 return REFRESH_MENU_COLOR;
3154 #undef gcm
3157 static int
3158 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3160 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3162 return REFRESH_ICON_TITLE_COLOR;
3166 static int
3167 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3169 if (scr->icon_title_texture) {
3170 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3172 XQueryColor (dpy, scr->w_colormap, color);
3173 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3175 return REFRESH_ICON_TITLE_BACK;
3179 static void
3180 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3182 close(scr->helper_fd);
3183 scr->helper_fd = 0;
3184 scr->helper_pid = 0;
3185 scr->flags.backimage_helper_launched = 0;
3189 static int
3190 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3191 void *bar)
3193 int i;
3194 proplist_t val;
3195 char *str;
3197 if (scr->flags.backimage_helper_launched) {
3198 if (PLGetNumberOfElements(value)==0) {
3199 SendHelperMessage(scr, 'C', 0, NULL);
3200 SendHelperMessage(scr, 'K', 0, NULL);
3202 PLRelease(value);
3203 return 0;
3205 } else {
3206 pid_t pid;
3207 int filedes[2];
3209 if (PLGetNumberOfElements(value) == 0)
3210 return 0;
3212 if (pipe(filedes) < 0) {
3213 wsyserror("pipe() failed:can't set workspace specific background image");
3215 PLRelease(value);
3216 return 0;
3219 pid = fork();
3220 if (pid < 0) {
3221 wsyserror("fork() failed:can't set workspace specific background image");
3222 if (close(filedes[0]) < 0)
3223 wsyserror("could not close pipe");
3224 if (close(filedes[1]) < 0)
3225 wsyserror("could not close pipe");
3227 } else if (pid == 0) {
3228 SetupEnvironment(scr);
3230 if (close(0) < 0)
3231 wsyserror("could not close pipe");
3232 if (dup(filedes[0]) < 0) {
3233 wsyserror("dup() failed:can't set workspace specific background image");
3235 if (wPreferences.smooth_workspace_back)
3236 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
3237 else
3238 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
3239 wsyserror("could not execute wmsetbg");
3240 exit(1);
3241 } else {
3243 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3244 wsyserror("error setting close-on-exec flag");
3246 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3247 wsyserror("error setting close-on-exec flag");
3250 scr->helper_fd = filedes[1];
3251 scr->helper_pid = pid;
3252 scr->flags.backimage_helper_launched = 1;
3254 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3256 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3261 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3262 val = PLGetArrayElement(value, i);
3263 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3264 str = PLGetDescription(val);
3266 SendHelperMessage(scr, 'S', i+1, str);
3268 wfree(str);
3269 } else {
3270 SendHelperMessage(scr, 'U', i+1, NULL);
3273 sleep(1);
3275 PLRelease(value);
3276 return 0;
3280 static int
3281 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3282 void *bar)
3284 if (scr->flags.backimage_helper_launched) {
3285 char *str;
3287 if (PLGetNumberOfElements(value)==0) {
3288 SendHelperMessage(scr, 'U', 0, NULL);
3289 } else {
3290 /* set the default workspace background to this one */
3291 str = PLGetDescription(value);
3292 if (str) {
3293 SendHelperMessage(scr, 'S', 0, str);
3294 wfree(str);
3295 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3296 } else {
3297 SendHelperMessage(scr, 'U', 0, NULL);
3300 } else if (PLGetNumberOfElements(value) > 0) {
3301 char *command;
3302 char *text;
3304 SetupEnvironment(scr);
3305 text = PLGetDescription(value);
3306 command = wmalloc(strlen(text)+40);
3307 if (wPreferences.smooth_workspace_back)
3308 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
3309 else
3310 sprintf(command, "wmsetbg -d -p '%s' &", text);
3311 wfree(text);
3312 system(command);
3313 wfree(command);
3315 PLRelease(value);
3317 return 0;
3321 static int
3322 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3324 if (scr->widget_texture) {
3325 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3327 scr->widget_texture = *(WTexSolid**)texture;
3329 return 0;
3333 static int
3334 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3336 if (scr->window_title_texture[WS_FOCUSED]) {
3337 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3339 scr->window_title_texture[WS_FOCUSED] = *texture;
3341 return REFRESH_WINDOW_TEXTURES;
3345 static int
3346 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3348 if (scr->window_title_texture[WS_PFOCUSED]) {
3349 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3351 scr->window_title_texture[WS_PFOCUSED] = *texture;
3353 return REFRESH_WINDOW_TEXTURES;
3357 static int
3358 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3360 if (scr->window_title_texture[WS_UNFOCUSED]) {
3361 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3363 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3365 return REFRESH_WINDOW_TEXTURES;
3369 static int
3370 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3372 if (scr->resizebar_texture[0]) {
3373 wTextureDestroy(scr, scr->resizebar_texture[0]);
3375 scr->resizebar_texture[0] = *texture;
3377 return REFRESH_WINDOW_TEXTURES;
3381 static int
3382 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3384 if (scr->menu_title_texture[0]) {
3385 wTextureDestroy(scr, scr->menu_title_texture[0]);
3387 scr->menu_title_texture[0] = *texture;
3389 return REFRESH_MENU_TITLE_TEXTURE;
3393 static int
3394 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3396 if (scr->menu_item_texture) {
3397 wTextureDestroy(scr, scr->menu_item_texture);
3398 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3400 scr->menu_item_texture = *texture;
3402 scr->menu_item_auxtexture
3403 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3405 return REFRESH_MENU_TEXTURE;
3409 static int
3410 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3412 WWindow *wwin;
3413 wKeyBindings[index] = *shortcut;
3415 wwin = scr->focused_window;
3417 while (wwin!=NULL) {
3418 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3420 if (!WFLAGP(wwin, no_bind_keys)) {
3421 wWindowSetKeyGrabs(wwin);
3423 wwin = wwin->prev;
3426 return 0;
3430 static int
3431 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3433 wArrangeIcons(scr, True);
3435 return 0;
3439 static int
3440 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3442 wScreenUpdateUsableArea(scr);
3444 return 0;
3448 static int
3449 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3451 return REFRESH_MENU_TEXTURE;
3456 static int
3457 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3459 return REFRESH_BUTTON_IMAGES;
3464 * Very ugly kluge.
3465 * Need access to the double click variables, so that all widgets in
3466 * wmaker panels will have the same dbl-click values.
3467 * TODO: figure a better way of dealing with it.
3469 #include "WINGsP.h"
3471 static int
3472 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3474 extern _WINGsConfiguration WINGsConfiguration;
3476 if (*value <= 0)
3477 *(int*)foo = 1;
3479 WINGsConfiguration.doubleClickDelay = *value;
3481 return 0;
3485 #if 0
3486 static int
3487 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3489 extern _WINGsConfiguration WINGsConfiguration;
3491 WINGsConfiguration.useMultiByte = *value;
3493 return 0;
3495 #endif
3497 #ifdef DEFINABLE_CURSOR
3498 static int
3499 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3501 if (None != wCursor[index])
3503 XFreeCursor(dpy, wCursor[index]);
3506 wCursor[index] = *cursor;
3508 if ((WCUR_ROOT == index) && (None != *cursor))
3510 XDefineCursor(dpy, scr->root_win, *cursor);
3513 return 0;
3515 #endif /* DEFINABLE_CURSOR*/