Added select while scrolling the list, when the mouse pointer leaves
[wmaker-crm.git] / src / defaults.c
blob1719e497d9381078adb56aa5bffe04d3dfb863ac
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},
323 {NULL, 0, 0}
326 static WOptionEnumeration seWorkspaceBorder[] = {
327 {"None", WB_NONE, 0},
328 {"LeftRight", WB_LEFTRIGHT, 0},
329 {"TopBottom", WB_TOPBOTTOM, 0},
330 {"AllDirections", WB_ALLDIRS, 0},
331 {NULL, 0, 0}
336 * ALL entries in the tables bellow, NEED to have a default value
337 * defined, and this value needs to be correct.
340 /* these options will only affect the window manager on startup
342 * static defaults can't access the screen data, because it is
343 * created after these defaults are read
345 WDefaultEntry staticOptionList[] = {
347 {"ColormapSize", "4", NULL,
348 &wPreferences.cmap_size, getInt, NULL
350 {"DisableDithering", "NO", NULL,
351 &wPreferences.no_dithering, getBool, NULL
353 /* static by laziness */
354 {"IconSize", "64", NULL,
355 &wPreferences.icon_size, getInt, NULL
357 {"ModifierKey", "Mod1", NULL,
358 &wPreferences.modifier_mask, getModMask, NULL
360 {"DisableWSMouseActions", "NO", NULL,
361 &wPreferences.disable_root_mouse, getBool, NULL
363 {"FocusMode", "manual", seFocusModes,
364 &wPreferences.focus_mode, getEnum, NULL
365 }, /* have a problem when switching from manual to sloppy without restart */
366 {"NewStyle", "NO", NULL,
367 &wPreferences.new_style, getBool, NULL
369 {"DisableDock", "NO", (void*) WM_DOCK,
370 NULL, getBool, setIfDockPresent
372 {"DisableClip", "NO", (void*) WM_CLIP,
373 NULL, getBool, setIfDockPresent
375 {"DisableMiniwindows", "NO", NULL,
376 &wPreferences.disable_miniwindows, getBool, NULL
378 {"MultiByteText", "NO", NULL,
379 &wPreferences.multi_byte_text, getBool, setMultiByte
385 WDefaultEntry optionList[] = {
386 /* dynamic options */
387 {"IconPosition", "blh", seIconPositions,
388 &wPreferences.icon_yard, getEnum, setIconPosition
390 {"IconificationStyle", "Zoom", seIconificationStyles,
391 &wPreferences.iconification_style, getEnum, NULL
393 {"SelectWindowsMouseButton", "Left", seMouseButtons,
394 &wPreferences.select_button, getEnum, NULL
396 {"WindowListMouseButton", "Middle", seMouseButtons,
397 &wPreferences.windowl_button, getEnum, NULL
399 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
400 &wPreferences.menu_button, getEnum, NULL
402 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
403 &wPreferences.pixmap_path, getPathList, NULL
405 {"IconPath", DEF_ICON_PATHS, NULL,
406 &wPreferences.icon_path, getPathList, NULL
408 {"ColormapMode", "auto", seColormapModes,
409 &wPreferences.colormap_mode, getEnum, NULL
411 {"AutoFocus", "NO", NULL,
412 &wPreferences.auto_focus, getBool, NULL
414 {"RaiseDelay", "0", NULL,
415 &wPreferences.raise_delay, getInt, NULL
417 {"WindozeCycling", "YES", NULL,
418 &wPreferences.windows_cycling,getBool, NULL
420 {"CirculateRaise", "NO", NULL,
421 &wPreferences.circ_raise, getBool, NULL
423 {"Superfluous", "NO", NULL,
424 &wPreferences.superfluous, getBool, NULL
426 {"AdvanceToNewWorkspace", "NO", NULL,
427 &wPreferences.ws_advance, getBool, NULL
429 {"CycleWorkspaces", "NO", NULL,
430 &wPreferences.ws_cycle, getBool, NULL
432 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
433 &wPreferences.workspace_name_display_position, getEnum, NULL
435 {"WorkspaceBorder", "None", seWorkspaceBorder,
436 &wPreferences.workspace_border_position, getEnum, updateUsableArea
438 {"WorkspaceBorderSize", "0", NULL,
439 &wPreferences.workspace_border_size, getInt, updateUsableArea
441 #ifdef VIRTUAL_DESKTOP
442 {"VirtualEdgeThickness", "1", NULL,
443 &wPreferences.vedge_thickness, getInt, NULL
445 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
446 &wPreferences.vedge_hscrollspeed, getInt, NULL
448 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
449 &wPreferences.vedge_vscrollspeed, getInt, NULL
451 {"VirtualEdgeWidth", "2000", NULL,
452 &wPreferences.vedge_width, getInt, NULL
454 {"VirtualEdgeHeight", "2000", NULL,
455 &wPreferences.vedge_height, getInt, NULL
457 #endif
458 {"StickyIcons", "NO", NULL,
459 &wPreferences.sticky_icons, getBool, setStickyIcons
461 {"SaveSessionOnExit", "NO", NULL,
462 &wPreferences.save_session_on_exit, getBool, NULL
464 {"WrapMenus", "NO", NULL,
465 &wPreferences.wrap_menus, getBool, NULL
467 {"ScrollableMenus", "NO", NULL,
468 &wPreferences.scrollable_menus, getBool, NULL
470 {"MenuScrollSpeed", "medium", seSpeeds,
471 &wPreferences.menu_scroll_speed, getEnum, NULL
473 {"IconSlideSpeed", "medium", seSpeeds,
474 &wPreferences.icon_slide_speed, getEnum, NULL
476 {"ShadeSpeed", "medium", seSpeeds,
477 &wPreferences.shade_speed, getEnum, NULL
479 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
480 &wPreferences.dblclick_time, getInt, setDoubleClick,
482 {"AlignSubmenus", "NO", NULL,
483 &wPreferences.align_menus, getBool, NULL
485 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
486 &wPreferences.open_transients_with_parent, getBool, NULL
488 {"WindowPlacement", "auto", sePlacements,
489 &wPreferences.window_placement, getEnum, NULL
491 {"IgnoreFocusClick","NO", NULL,
492 &wPreferences.ignore_focus_click, getBool, NULL
494 {"UseSaveUnders", "NO", NULL,
495 &wPreferences.use_saveunders, getBool, NULL
497 {"OpaqueMove", "NO", NULL,
498 &wPreferences.opaque_move, getBool, NULL
500 {"DisableSound", "NO", NULL,
501 &wPreferences.no_sound, getBool, NULL
503 {"DisableAnimations", "NO", NULL,
504 &wPreferences.no_animations, getBool, NULL
506 {"DontLinkWorkspaces","NO", NULL,
507 &wPreferences.no_autowrap, getBool, NULL
509 {"AutoArrangeIcons", "NO", NULL,
510 &wPreferences.auto_arrange_icons, getBool, NULL
512 {"NoWindowOverDock", "NO", NULL,
513 &wPreferences.no_window_over_dock, getBool, updateUsableArea
515 {"NoWindowOverIcons", "NO", NULL,
516 &wPreferences.no_window_over_icons, getBool, updateUsableArea
518 {"WindowPlaceOrigin", "(0, 0)", NULL,
519 &wPreferences.window_place_origin, getCoord, NULL
521 {"ResizeDisplay", "corner", seGeomDisplays,
522 &wPreferences.size_display, getEnum, NULL
524 {"MoveDisplay", "corner", seGeomDisplays,
525 &wPreferences.move_display, getEnum, NULL
527 {"DontConfirmKill", "NO", NULL,
528 &wPreferences.dont_confirm_kill, getBool,NULL
530 {"WindowTitleBalloons", "NO", NULL,
531 &wPreferences.window_balloon, getBool, NULL
533 {"MiniwindowTitleBalloons", "NO", NULL,
534 &wPreferences.miniwin_balloon,getBool, NULL
536 {"AppIconBalloons", "NO", NULL,
537 &wPreferences.appicon_balloon,getBool, NULL
539 {"HelpBalloons", "NO", NULL,
540 &wPreferences.help_balloon, getBool, NULL
542 {"EdgeResistance", "30", NULL,
543 &wPreferences.edge_resistance,getInt, NULL
545 {"Attraction", "NO", NULL,
546 &wPreferences.attract, getBool, NULL
548 {"DisableBlinking", "NO", NULL,
549 &wPreferences.dont_blink, getBool, NULL
551 /* style options */
552 {"MenuStyle", "normal", seMenuStyles,
553 &wPreferences.menu_style, getEnum, setMenuStyle
555 {"WidgetColor", "(solid, gray)", NULL,
556 NULL, getTexture, setWidgetColor,
558 {"WorkspaceSpecificBack","()", NULL,
559 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
561 /* WorkspaceBack must come after WorkspaceSpecificBack or
562 * WorkspaceBack wont know WorkspaceSpecificBack was also
563 * specified and 2 copies of wmsetbg will be launched */
564 {"WorkspaceBack", "(solid, black)", NULL,
565 NULL, getWSBackground,setWorkspaceBack
567 {"SmoothWorkspaceBack", "NO", NULL,
568 NULL, getBool, NULL
570 {"IconBack", "(solid, gray)", NULL,
571 NULL, getTexture, setIconTile
573 {"TitleJustify", "center", seJustifications,
574 &wPreferences.title_justification, getEnum, setJustify
576 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
577 NULL, getFont, setWinTitleFont,
579 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
580 &wPreferences.window_title_clearance, getInt, setClearance
582 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
583 &wPreferences.menu_title_clearance, getInt, setClearance
585 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
586 &wPreferences.menu_text_clearance, getInt, setClearance
588 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
589 NULL, getFont, setMenuTitleFont
591 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
592 NULL, getFont, setMenuTextFont
594 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
595 NULL, getFont, setIconTitleFont
597 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
598 NULL, getFont, setClipTitleFont
600 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
601 NULL, getFont, setLargeDisplayFont
603 {"HighlightColor", "white", NULL,
604 NULL, getColor, setHightlight
606 {"HighlightTextColor", "black", NULL,
607 NULL, getColor, setHightlightText
609 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
610 NULL, getColor, setClipTitleColor
612 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
613 NULL, getColor, setClipTitleColor
615 #ifdef DRAWSTRING_PLUGIN
616 {"FTitleColor", "white", (void*)WS_FOCUSED,
617 NULL, getTextRenderer, setWTitleColor
619 {"PTitleColor", "white", (void*)WS_PFOCUSED,
620 NULL, getTextRenderer, setWTitleColor
622 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
623 NULL, getTextRenderer, setWTitleColor
625 #else
626 {"FTitleColor", "white", (void*)WS_FOCUSED,
627 NULL, getColor, setWTitleColor
629 {"PTitleColor", "white", (void*)WS_PFOCUSED,
630 NULL, getColor, setWTitleColor
632 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
633 NULL, getColor, setWTitleColor
635 #endif
636 {"FTitleBack", "(solid, black)", NULL,
637 NULL, getTexture, setFTitleBack
639 {"PTitleBack", "(solid, \"#616161\")", NULL,
640 NULL, getTexture, setPTitleBack
642 {"UTitleBack", "(solid, gray)", NULL,
643 NULL, getTexture, setUTitleBack
645 {"ResizebarBack", "(solid, gray)", NULL,
646 NULL, getTexture, setResizebarBack
648 #ifdef DRAWSTRING_PLUGIN
649 {"MenuTitleColor", "white", NULL,
650 NULL, getTextRenderer, setMenuTitleColor
652 #else
653 {"MenuTitleColor", "white", NULL,
654 NULL, getColor, setMenuTitleColor
656 #endif
657 {"MenuTextColor", "black", NULL,
658 NULL, getColor, setMenuTextColor
660 {"MenuDisabledColor", "\"#616161\"", NULL,
661 NULL, getColor, setMenuDisabledColor
663 {"MenuTitleBack", "(solid, black)", NULL,
664 NULL, getTexture, setMenuTitleBack
666 {"MenuTextBack", "(solid, gray)", NULL,
667 NULL, getTexture, setMenuTextBack
669 {"IconTitleColor", "white", NULL,
670 NULL, getColor, setIconTitleColor
672 {"IconTitleBack", "black", NULL,
673 NULL, getColor, setIconTitleBack
675 /* keybindings */
676 #ifndef LITE
677 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
678 NULL, getKeybind, setKeyGrab
680 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
681 NULL, getKeybind, setKeyGrab
683 #endif /* LITE */
684 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
685 NULL, getKeybind, setKeyGrab
687 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
688 NULL, getKeybind, setKeyGrab
690 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
691 NULL, getKeybind, setKeyGrab
693 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
694 NULL, getKeybind, setKeyGrab
696 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
697 NULL, getKeybind, setKeyGrab
699 {"HideKey", "None", (void*)WKBD_HIDE,
700 NULL, getKeybind, setKeyGrab
702 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
703 NULL, getKeybind, setKeyGrab
705 {"CloseKey", "None", (void*)WKBD_CLOSE,
706 NULL, getKeybind, setKeyGrab
708 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
709 NULL, getKeybind, setKeyGrab
711 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
712 NULL, getKeybind, setKeyGrab
714 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
715 NULL, getKeybind, setKeyGrab
717 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
718 NULL, getKeybind, setKeyGrab
720 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
721 NULL, getKeybind, setKeyGrab
723 {"ShadeKey", "None", (void*)WKBD_SHADE,
724 NULL, getKeybind, setKeyGrab
726 {"SelectKey", "None", (void*)WKBD_SELECT,
727 NULL, getKeybind, setKeyGrab
729 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
730 NULL, getKeybind, setKeyGrab
732 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
733 NULL, getKeybind, setKeyGrab
735 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
736 NULL, getKeybind, setKeyGrab
738 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
739 NULL, getKeybind, setKeyGrab
741 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
742 NULL, getKeybind, setKeyGrab
744 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
745 NULL, getKeybind, setKeyGrab
747 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
760 NULL, getKeybind, setKeyGrab
762 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
763 NULL, getKeybind, setKeyGrab
765 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
766 NULL, getKeybind, setKeyGrab
768 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
769 NULL, getKeybind, setKeyGrab
771 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
772 NULL, getKeybind, setKeyGrab
774 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
775 NULL, getKeybind, setKeyGrab
777 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
778 NULL, getKeybind, setKeyGrab
780 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
781 NULL, getKeybind, setKeyGrab
783 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
784 NULL, getKeybind, setKeyGrab
786 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
787 NULL, getKeybind, setKeyGrab
789 #ifdef EXTEND_WINDOWSHORTCUT
790 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
791 NULL, getKeybind, setKeyGrab
793 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
794 NULL, getKeybind, setKeyGrab
796 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
797 NULL, getKeybind, setKeyGrab
799 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
800 NULL, getKeybind, setKeyGrab
802 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
803 NULL, getKeybind, setKeyGrab
805 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
806 NULL, getKeybind, setKeyGrab
808 #endif /* EXTEND_WINDOWSHORTCUT */
810 #ifdef KEEP_XKB_LOCK_STATUS
811 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
812 NULL, getKeybind, setKeyGrab
814 {"KbdModeLock", "NO", NULL,
815 &wPreferences.modelock, getBool, NULL
817 #endif /* KEEP_XKB_LOCK_STATUS */
818 #ifdef DEFINABLE_CURSOR
819 ,{"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
820 NULL, getCursor, setCursor
822 ,{"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
823 NULL, getCursor, setCursor
825 #if 0
826 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
827 NULL, getCursor, setCursor
829 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
830 NULL, getCursor, setCursor
832 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
833 NULL, getCursor, setCursor
835 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
836 NULL, getCursor, setCursor
838 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
839 NULL, getCursor, setCursor
841 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
842 NULL, getCursor, setCursor
844 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
845 NULL, getCursor, setCursor
847 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
848 NULL, getCursor, setCursor
850 #endif
851 #endif /* DEFINABLE_CURSOR */
855 #if 0
856 static void rereadDefaults(void);
857 #endif
859 #if 0
860 static void
861 rereadDefaults(void)
863 /* must defer the update because accessing X data from a
864 * signal handler can mess up Xlib */
867 #endif
869 static void
870 initDefaults()
872 int i;
873 WDefaultEntry *entry;
875 PLSetStringCmpHook(StringCompareHook);
877 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
878 entry = &optionList[i];
880 entry->plkey = PLMakeString(entry->key);
881 if (entry->default_value)
882 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
883 else
884 entry->plvalue = NULL;
887 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
888 entry = &staticOptionList[i];
890 entry->plkey = PLMakeString(entry->key);
891 if (entry->default_value)
892 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
893 else
894 entry->plvalue = NULL;
898 wDomainName = PLMakeString(WMDOMAIN_NAME);
899 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
901 PLRegister(wDomainName, rereadDefaults);
902 PLRegister(wAttributeDomainName, rereadDefaults);
909 #if 0
910 proplist_t
911 wDefaultsInit(int screen_number)
913 static int defaults_inited = 0;
914 proplist_t dict;
916 if (!defaults_inited) {
917 initDefaults();
920 dict = PLGetDomain(wDomainName);
921 if (!dict) {
922 wwarning(_("could not read domain \"%s\" from defaults database"),
923 PLGetString(wDomainName));
926 return dict;
928 #endif
931 void
932 wDefaultsDestroyDomain(WDDomain *domain)
934 if (domain->dictionary)
935 PLRelease(domain->dictionary);
936 free(domain->path);
937 free(domain);
941 WDDomain*
942 wDefaultsInitDomain(char *domain, Bool requireDictionary)
944 WDDomain *db;
945 struct stat stbuf;
946 static int inited = 0;
947 char path[PATH_MAX];
948 char *the_path;
949 proplist_t shared_dict=NULL;
951 if (!inited) {
952 inited = 1;
953 initDefaults();
956 db = wmalloc(sizeof(WDDomain));
957 memset(db, 0, sizeof(WDDomain));
958 db->domain_name = domain;
959 db->path = wdefaultspathfordomain(domain);
960 the_path = db->path;
962 if (the_path && stat(the_path, &stbuf)>=0) {
963 db->dictionary = ReadProplistFromFile(the_path);
964 if (db->dictionary) {
965 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
966 PLRelease(db->dictionary);
967 db->dictionary = NULL;
968 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
969 domain, the_path);
971 db->timestamp = stbuf.st_mtime;
972 } else {
973 wwarning(_("could not load domain %s from user defaults database"),
974 domain);
978 /* global system dictionary */
979 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
980 if (stat(path, &stbuf)>=0) {
981 shared_dict = ReadProplistFromFile(path);
982 if (shared_dict) {
983 if (requireDictionary && !PLIsDictionary(shared_dict)) {
984 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
985 domain, path);
986 PLRelease(shared_dict);
987 shared_dict = NULL;
988 } else {
989 if (db->dictionary && PLIsDictionary(shared_dict) &&
990 PLIsDictionary(db->dictionary)) {
991 PLMergeDictionaries(shared_dict, db->dictionary);
992 PLRelease(db->dictionary);
993 db->dictionary = shared_dict;
994 if (stbuf.st_mtime > db->timestamp)
995 db->timestamp = stbuf.st_mtime;
996 } else if (!db->dictionary) {
997 db->dictionary = shared_dict;
998 if (stbuf.st_mtime > db->timestamp)
999 db->timestamp = stbuf.st_mtime;
1002 } else {
1003 wwarning(_("could not load domain %s from global defaults database (%s)"),
1004 domain, path);
1008 /* set to save it in user's directory, no matter from where it was read */
1009 if (db->dictionary) {
1010 proplist_t tmp = PLMakeString(db->path);
1012 PLSetFilename(db->dictionary, tmp);
1013 PLRelease(tmp);
1016 return db;
1020 void
1021 wReadStaticDefaults(proplist_t dict)
1023 proplist_t plvalue;
1024 WDefaultEntry *entry;
1025 int i;
1026 void *tdata;
1029 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1030 entry = &staticOptionList[i];
1032 if (dict)
1033 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1034 else
1035 plvalue = NULL;
1037 if (!plvalue) {
1038 /* no default in the DB. Use builtin default */
1039 plvalue = entry->plvalue;
1042 if (plvalue) {
1043 /* convert data */
1044 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1045 if (entry->update) {
1046 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1053 void
1054 wDefaultsCheckDomains(void *foo)
1056 WScreen *scr;
1057 struct stat stbuf;
1058 proplist_t dict;
1059 int i;
1060 char path[PATH_MAX];
1062 #ifdef HEARTBEAT
1063 puts("Checking domains...");
1064 #endif
1065 if (stat(WDWindowMaker->path, &stbuf)>=0
1066 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1067 proplist_t shared_dict = NULL;
1068 #ifdef HEARTBEAT
1069 puts("Checking WindowMaker domain");
1070 #endif
1071 WDWindowMaker->timestamp = stbuf.st_mtime;
1073 /* global dictionary */
1074 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1075 if (stat(path, &stbuf)>=0) {
1076 shared_dict = ReadProplistFromFile(path);
1077 if (shared_dict && !PLIsDictionary(shared_dict)) {
1078 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1079 "WindowMaker", path);
1080 PLRelease(shared_dict);
1081 shared_dict = NULL;
1082 } else if (!shared_dict) {
1083 wwarning(_("could not load domain %s from global defaults database"),
1084 "WindowMaker");
1087 /* user dictionary */
1088 dict = ReadProplistFromFile(WDWindowMaker->path);
1089 if (dict) {
1090 if (!PLIsDictionary(dict)) {
1091 PLRelease(dict);
1092 dict = NULL;
1093 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1094 "WindowMaker", WDWindowMaker->path);
1095 } else {
1096 if (shared_dict) {
1097 PLSetFilename(shared_dict, PLGetFilename(dict));
1098 PLMergeDictionaries(shared_dict, dict);
1099 PLRelease(dict);
1100 dict = shared_dict;
1101 shared_dict = NULL;
1103 for (i=0; i<wScreenCount; i++) {
1104 scr = wScreenWithNumber(i);
1105 if (scr)
1106 wReadDefaults(scr, dict);
1108 if (WDWindowMaker->dictionary) {
1109 PLRelease(WDWindowMaker->dictionary);
1111 WDWindowMaker->dictionary = dict;
1113 } else {
1114 wwarning(_("could not load domain %s from user defaults database"),
1115 "WindowMaker");
1117 if (shared_dict) {
1118 PLRelease(shared_dict);
1122 if (stat(WDWindowAttributes->path, &stbuf)>=0
1123 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1124 #ifdef HEARTBEAT
1125 puts("Checking WMWindowAttributes domain");
1126 #endif
1127 dict = ReadProplistFromFile(WDWindowAttributes->path);
1128 if (dict) {
1129 if (!PLIsDictionary(dict)) {
1130 PLRelease(dict);
1131 dict = NULL;
1132 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1133 "WMWindowAttributes", WDWindowAttributes->path);
1134 } else {
1135 if (WDWindowAttributes->dictionary)
1136 PLRelease(WDWindowAttributes->dictionary);
1137 WDWindowAttributes->dictionary = dict;
1138 for (i=0; i<wScreenCount; i++) {
1139 scr = wScreenWithNumber(i);
1140 if (scr)
1141 wDefaultUpdateIcons(scr);
1144 } else {
1145 wwarning(_("could not load domain %s from user defaults database"),
1146 "WMWindowAttributes");
1148 WDWindowAttributes->timestamp = stbuf.st_mtime;
1151 #ifndef LITE
1152 if (stat(WDRootMenu->path, &stbuf)>=0
1153 && WDRootMenu->timestamp < stbuf.st_mtime) {
1154 dict = ReadProplistFromFile(WDRootMenu->path);
1155 #ifdef HEARTBEAT
1156 puts("Checking WMRootMenu domain");
1157 #endif
1158 if (dict) {
1159 if (!PLIsArray(dict) && !PLIsString(dict)) {
1160 PLRelease(dict);
1161 dict = NULL;
1162 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1163 "WMRootMenu", WDRootMenu->path);
1164 } else {
1165 if (WDRootMenu->dictionary) {
1166 PLRelease(WDRootMenu->dictionary);
1168 WDRootMenu->dictionary = dict;
1170 } else {
1171 wwarning(_("could not load domain %s from user defaults database"),
1172 "WMRootMenu");
1174 WDRootMenu->timestamp = stbuf.st_mtime;
1176 #endif /* !LITE */
1178 if (!foo)
1179 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1183 void
1184 wReadDefaults(WScreen *scr, proplist_t new_dict)
1186 proplist_t plvalue, old_value;
1187 WDefaultEntry *entry;
1188 int i, must_update;
1189 int update_workspace_back = 0; /* kluge :/ */
1190 int needs_refresh;
1191 void *tdata;
1192 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1193 ? WDWindowMaker->dictionary : NULL);
1195 must_update = 0;
1197 needs_refresh = 0;
1199 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1200 entry = &optionList[i];
1202 if (new_dict)
1203 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1204 else
1205 plvalue = NULL;
1207 if (!old_dict)
1208 old_value = NULL;
1209 else
1210 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1213 if (!plvalue && !old_value) {
1214 /* no default in the DB. Use builtin default */
1215 plvalue = entry->plvalue;
1216 if (plvalue && new_dict) {
1217 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1218 must_update = 1;
1220 } else if (!plvalue) {
1221 /* value was deleted from DB. Keep current value */
1222 continue;
1223 } else if (!old_value) {
1224 /* set value for the 1st time */
1225 } else if (!PLIsEqual(plvalue, old_value)) {
1226 /* value has changed */
1227 } else {
1229 if (strcmp(entry->key, "WorkspaceBack") == 0
1230 && update_workspace_back
1231 && scr->flags.backimage_helper_launched) {
1232 } else {
1233 /* value was not changed since last time */
1234 continue;
1238 if (plvalue) {
1239 #ifdef DEBUG
1240 printf("Updating %s to %s\n", entry->key,
1241 PLGetDescription(plvalue));
1242 #endif
1243 /* convert data */
1244 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1246 * If the WorkspaceSpecificBack data has been changed
1247 * so that the helper will be launched now, we must be
1248 * sure to send the default background texture config
1249 * to the helper.
1251 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1252 && !scr->flags.backimage_helper_launched) {
1253 update_workspace_back = 1;
1255 if (entry->update) {
1256 needs_refresh |=
1257 (*entry->update)(scr, entry, tdata, entry->extra_data);
1263 if (needs_refresh!=0 && !scr->flags.startup) {
1264 int foo;
1266 foo = 0;
1267 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1268 foo |= WTextureSettings;
1269 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1270 foo |= WFontSettings;
1271 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1272 foo |= WColorSettings;
1273 if (foo)
1274 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1275 (void*)foo);
1277 foo = 0;
1278 if (needs_refresh & REFRESH_MENU_TEXTURE)
1279 foo |= WTextureSettings;
1280 if (needs_refresh & REFRESH_MENU_FONT)
1281 foo |= WFontSettings;
1282 if (needs_refresh & REFRESH_MENU_COLOR)
1283 foo |= WColorSettings;
1284 if (foo)
1285 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1286 (void*)foo);
1288 foo = 0;
1289 if (needs_refresh & REFRESH_WINDOW_FONT) {
1290 foo |= WFontSettings;
1292 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1293 foo |= WTextureSettings;
1295 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1296 foo |= WColorSettings;
1298 if (foo)
1299 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1300 (void*)foo);
1302 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1303 foo = 0;
1304 if (needs_refresh & REFRESH_ICON_FONT) {
1305 foo |= WFontSettings;
1307 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1308 foo |= WTextureSettings;
1310 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1311 foo |= WTextureSettings;
1313 if (foo)
1314 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1315 (void*)foo);
1317 if (needs_refresh & REFRESH_ICON_TILE)
1318 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1323 void
1324 wDefaultUpdateIcons(WScreen *scr)
1326 WAppIcon *aicon = scr->app_icon_list;
1327 WWindow *wwin = scr->focused_window;
1328 char *file;
1330 while(aicon) {
1331 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1332 False);
1333 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1334 || (file && !aicon->icon->file)) {
1335 RImage *new_image;
1337 if (aicon->icon->file)
1338 free(aicon->icon->file);
1339 aicon->icon->file = wstrdup(file);
1341 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1342 aicon->wm_class);
1343 if (new_image) {
1344 wIconChangeImage(aicon->icon, new_image);
1345 wAppIconPaint(aicon);
1348 aicon = aicon->next;
1351 if (!wPreferences.flags.noclip)
1352 wClipIconPaint(scr->clip_icon);
1354 while (wwin) {
1355 if (wwin->icon && wwin->flags.miniaturized) {
1356 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1357 False);
1358 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1359 || (file && !wwin->icon->file)) {
1360 RImage *new_image;
1362 if (wwin->icon->file)
1363 free(wwin->icon->file);
1364 wwin->icon->file = wstrdup(file);
1366 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1367 wwin->wm_class);
1368 if (new_image)
1369 wIconChangeImage(wwin->icon, new_image);
1372 wwin = wwin->prev;
1377 /* --------------------------- Local ----------------------- */
1379 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1380 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1381 entry->key, x); \
1382 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1383 var = entry->default_value;\
1384 } else var = PLGetString(value)\
1390 static int
1391 string2index(proplist_t key, proplist_t val, proplist_t def,
1392 WOptionEnumeration *values)
1394 char *str;
1395 WOptionEnumeration *v;
1396 char buffer[TOTAL_VALUES_LENGTH];
1398 if (PLIsString(val) && (str = PLGetString(val))) {
1399 for (v=values; v->string!=NULL; v++) {
1400 if (strcasecmp(v->string, str)==0)
1401 return v->value;
1405 buffer[0] = 0;
1406 for (v=values; v->string!=NULL; v++) {
1407 if (!v->is_alias) {
1408 if (buffer[0]!=0)
1409 strcat(buffer, ", ");
1410 strcat(buffer, v->string);
1413 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1414 PLGetString(key), buffer);
1416 if (def) {
1417 return string2index(key, val, NULL, values);
1420 return -1;
1427 * value - is the value in the defaults DB
1428 * addr - is the address to store the data
1429 * ret - is the address to store a pointer to a temporary buffer. ret
1430 * must not be freed and is used by the set functions
1432 static int
1433 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1434 void **ret)
1436 static char data;
1437 char *val;
1438 int second_pass=0;
1440 GET_STRING_OR_DEFAULT("Boolean", val);
1442 again:
1443 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1444 || strcasecmp(val, "YES")==0) {
1446 data = 1;
1447 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1448 || strcasecmp(val, "NO")==0) {
1449 data = 0;
1450 } else {
1451 int i;
1452 if (sscanf(val, "%i", &i)==1) {
1453 if (i!=0)
1454 data = 1;
1455 else
1456 data = 0;
1457 } else {
1458 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1459 val, entry->key);
1460 if (second_pass==0) {
1461 val = PLGetString(entry->plvalue);
1462 second_pass = 1;
1463 wwarning(_("using default \"%s\" instead"), val);
1464 goto again;
1466 return False;
1470 if (ret)
1471 *ret = &data;
1473 if (addr) {
1474 *(char*)addr = data;
1477 return True;
1481 static int
1482 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1483 void **ret)
1485 static int data;
1486 char *val;
1489 GET_STRING_OR_DEFAULT("Integer", val);
1491 if (sscanf(val, "%i", &data)!=1) {
1492 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1493 val, entry->key);
1494 val = PLGetString(entry->plvalue);
1495 wwarning(_("using default \"%s\" instead"), val);
1496 if (sscanf(val, "%i", &data)!=1) {
1497 return False;
1501 if (ret)
1502 *ret = &data;
1504 if (addr) {
1505 *(int*)addr = data;
1507 return True;
1511 static int
1512 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1513 void **ret)
1515 static WCoord data;
1516 char *val_x, *val_y;
1517 int nelem, changed=0;
1518 proplist_t elem_x, elem_y;
1520 again:
1521 if (!PLIsArray(value)) {
1522 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1523 entry->key, "Coordinate");
1524 if (changed==0) {
1525 value = entry->plvalue;
1526 changed = 1;
1527 wwarning(_("using default \"%s\" instead"), entry->default_value);
1528 goto again;
1530 return False;
1533 nelem = PLGetNumberOfElements(value);
1534 if (nelem != 2) {
1535 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1536 entry->key);
1537 if (changed==0) {
1538 value = entry->plvalue;
1539 changed = 1;
1540 wwarning(_("using default \"%s\" instead"), entry->default_value);
1541 goto again;
1543 return False;
1546 elem_x = PLGetArrayElement(value, 0);
1547 elem_y = PLGetArrayElement(value, 1);
1549 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1550 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1551 entry->key);
1552 if (changed==0) {
1553 value = entry->plvalue;
1554 changed = 1;
1555 wwarning(_("using default \"%s\" instead"), entry->default_value);
1556 goto again;
1558 return False;
1561 val_x = PLGetString(elem_x);
1562 val_y = PLGetString(elem_y);
1564 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1565 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1566 if (changed==0) {
1567 value = entry->plvalue;
1568 changed = 1;
1569 wwarning(_("using default \"%s\" instead"), entry->default_value);
1570 goto again;
1572 return False;
1575 if (data.x < 0)
1576 data.x = 0;
1577 else if (data.x > scr->scr_width/3)
1578 data.x = scr->scr_width/3;
1579 if (data.y < 0)
1580 data.y = 0;
1581 else if (data.y > scr->scr_height/3)
1582 data.y = scr->scr_height/3;
1584 if (ret)
1585 *ret = &data;
1587 if (addr) {
1588 *(WCoord*)addr = data;
1591 return True;
1595 #if 0
1596 /* This function is not used at the moment. */
1597 static int
1598 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1599 void **ret)
1601 static char *data;
1603 GET_STRING_OR_DEFAULT("String", data);
1605 if (!data) {
1606 data = PLGetString(entry->plvalue);
1607 if (!data)
1608 return False;
1611 if (ret)
1612 *ret = &data;
1614 if (addr)
1615 *(char**)addr = wstrdup(data);
1617 return True;
1619 #endif
1622 static int
1623 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1624 void **ret)
1626 static char *data;
1627 int i, count, len;
1628 char *ptr;
1629 proplist_t d;
1630 int changed=0;
1632 again:
1633 if (!PLIsArray(value)) {
1634 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1635 entry->key, "an array of paths");
1636 if (changed==0) {
1637 value = entry->plvalue;
1638 changed = 1;
1639 wwarning(_("using default \"%s\" instead"), entry->default_value);
1640 goto again;
1642 return False;
1645 i = 0;
1646 count = PLGetNumberOfElements(value);
1647 if (count < 1) {
1648 if (changed==0) {
1649 value = entry->plvalue;
1650 changed = 1;
1651 wwarning(_("using default \"%s\" instead"), entry->default_value);
1652 goto again;
1654 return False;
1657 len = 0;
1658 for (i=0; i<count; i++) {
1659 d = PLGetArrayElement(value, i);
1660 if (!d || !PLIsString(d)) {
1661 count = i;
1662 break;
1664 len += strlen(PLGetString(d))+1;
1667 ptr = data = wmalloc(len+1);
1669 for (i=0; i<count; i++) {
1670 d = PLGetArrayElement(value, i);
1671 if (!d || !PLIsString(d)) {
1672 break;
1674 strcpy(ptr, PLGetString(d));
1675 ptr += strlen(PLGetString(d));
1676 *ptr = ':';
1677 ptr++;
1679 ptr--; *(ptr--) = 0;
1681 if (*(char**)addr!=NULL) {
1682 free(*(char**)addr);
1684 *(char**)addr = data;
1686 return True;
1690 static int
1691 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1692 void **ret)
1694 static signed char data;
1696 data = string2index(entry->plkey, value, entry->default_value,
1697 (WOptionEnumeration*)entry->extra_data);
1698 if (data < 0)
1699 return False;
1701 if (ret)
1702 *ret = &data;
1704 if (addr)
1705 *(signed char*)addr = data;
1707 return True;
1713 * (solid <color>)
1714 * (hgradient <color> <color>)
1715 * (vgradient <color> <color>)
1716 * (dgradient <color> <color>)
1717 * (mhgradient <color> <color> ...)
1718 * (mvgradient <color> <color> ...)
1719 * (mdgradient <color> <color> ...)
1720 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1721 * (tpixmap <file> <color>)
1722 * (spixmap <file> <color>)
1723 * (cpixmap <file> <color>)
1724 * (thgradient <file> <opaqueness> <color> <color>)
1725 * (tvgradient <file> <opaqueness> <color> <color>)
1726 * (tdgradient <file> <opaqueness> <color> <color>)
1727 * (function <lib> <function> ...)
1730 static WTexture*
1731 parse_texture(WScreen *scr, proplist_t pl)
1733 proplist_t elem;
1734 char *val;
1735 int nelem;
1736 WTexture *texture=NULL;
1738 nelem = PLGetNumberOfElements(pl);
1739 if (nelem < 1)
1740 return NULL;
1743 elem = PLGetArrayElement(pl, 0);
1744 if (!elem || !PLIsString(elem))
1745 return NULL;
1746 val = PLGetString(elem);
1749 if (strcasecmp(val, "solid")==0) {
1750 XColor color;
1752 if (nelem != 2)
1753 return NULL;
1755 /* get color */
1757 elem = PLGetArrayElement(pl, 1);
1758 if (!elem || !PLIsString(elem))
1759 return NULL;
1760 val = PLGetString(elem);
1762 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1763 wwarning(_("\"%s\" is not a valid color name"), val);
1764 return NULL;
1767 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1768 } else if (strcasecmp(val, "dgradient")==0
1769 || strcasecmp(val, "vgradient")==0
1770 || strcasecmp(val, "hgradient")==0) {
1771 RColor color1, color2;
1772 XColor xcolor;
1773 int type;
1775 if (nelem != 3) {
1776 wwarning(_("bad number of arguments in gradient specification"));
1777 return NULL;
1780 if (val[0]=='d' || val[0]=='D')
1781 type = WTEX_DGRADIENT;
1782 else if (val[0]=='h' || val[0]=='H')
1783 type = WTEX_HGRADIENT;
1784 else
1785 type = WTEX_VGRADIENT;
1788 /* get from color */
1789 elem = PLGetArrayElement(pl, 1);
1790 if (!elem || !PLIsString(elem))
1791 return NULL;
1792 val = PLGetString(elem);
1794 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1795 wwarning(_("\"%s\" is not a valid color name"), val);
1796 return NULL;
1798 color1.alpha = 255;
1799 color1.red = xcolor.red >> 8;
1800 color1.green = xcolor.green >> 8;
1801 color1.blue = xcolor.blue >> 8;
1803 /* get to color */
1804 elem = PLGetArrayElement(pl, 2);
1805 if (!elem || !PLIsString(elem)) {
1806 return NULL;
1808 val = PLGetString(elem);
1810 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1811 wwarning(_("\"%s\" is not a valid color name"), val);
1812 return NULL;
1814 color2.alpha = 255;
1815 color2.red = xcolor.red >> 8;
1816 color2.green = xcolor.green >> 8;
1817 color2.blue = xcolor.blue >> 8;
1819 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1821 } else if (strcasecmp(val, "igradient")==0) {
1822 RColor colors1[2], colors2[2];
1823 int th1, th2;
1824 XColor xcolor;
1825 int i;
1827 if (nelem != 7) {
1828 wwarning(_("bad number of arguments in gradient specification"));
1829 return NULL;
1832 /* get from color */
1833 for (i = 0; i < 2; i++) {
1834 elem = PLGetArrayElement(pl, 1+i);
1835 if (!elem || !PLIsString(elem))
1836 return NULL;
1837 val = PLGetString(elem);
1839 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1840 wwarning(_("\"%s\" is not a valid color name"), val);
1841 return NULL;
1843 colors1[i].alpha = 255;
1844 colors1[i].red = xcolor.red >> 8;
1845 colors1[i].green = xcolor.green >> 8;
1846 colors1[i].blue = xcolor.blue >> 8;
1848 elem = PLGetArrayElement(pl, 3);
1849 if (!elem || !PLIsString(elem))
1850 return NULL;
1851 val = PLGetString(elem);
1852 th1 = atoi(val);
1855 /* get from color */
1856 for (i = 0; i < 2; i++) {
1857 elem = PLGetArrayElement(pl, 4+i);
1858 if (!elem || !PLIsString(elem))
1859 return NULL;
1860 val = PLGetString(elem);
1862 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1863 wwarning(_("\"%s\" is not a valid color name"), val);
1864 return NULL;
1866 colors2[i].alpha = 255;
1867 colors2[i].red = xcolor.red >> 8;
1868 colors2[i].green = xcolor.green >> 8;
1869 colors2[i].blue = xcolor.blue >> 8;
1871 elem = PLGetArrayElement(pl, 6);
1872 if (!elem || !PLIsString(elem))
1873 return NULL;
1874 val = PLGetString(elem);
1875 th2 = atoi(val);
1877 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1878 th2, colors2);
1880 } else if (strcasecmp(val, "mhgradient")==0
1881 || strcasecmp(val, "mvgradient")==0
1882 || strcasecmp(val, "mdgradient")==0) {
1883 XColor color;
1884 RColor **colors;
1885 int i, count;
1886 int type;
1888 if (nelem < 3) {
1889 wwarning(_("too few arguments in multicolor gradient specification"));
1890 return NULL;
1893 if (val[1]=='h' || val[1]=='H')
1894 type = WTEX_MHGRADIENT;
1895 else if (val[1]=='v' || val[1]=='V')
1896 type = WTEX_MVGRADIENT;
1897 else
1898 type = WTEX_MDGRADIENT;
1900 count = nelem-1;
1902 colors = wmalloc(sizeof(RColor*)*(count+1));
1904 for (i=0; i<count; i++) {
1905 elem = PLGetArrayElement(pl, i+1);
1906 if (!elem || !PLIsString(elem)) {
1907 for (--i; i>=0; --i) {
1908 free(colors[i]);
1910 free(colors);
1911 return NULL;
1913 val = PLGetString(elem);
1915 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1916 wwarning(_("\"%s\" is not a valid color name"), val);
1917 for (--i; i>=0; --i) {
1918 free(colors[i]);
1920 free(colors);
1921 return NULL;
1922 } else {
1923 colors[i] = wmalloc(sizeof(RColor));
1924 colors[i]->red = color.red >> 8;
1925 colors[i]->green = color.green >> 8;
1926 colors[i]->blue = color.blue >> 8;
1929 colors[i] = NULL;
1931 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1932 } else if (strcasecmp(val, "spixmap")==0 ||
1933 strcasecmp(val, "cpixmap")==0 ||
1934 strcasecmp(val, "tpixmap")==0) {
1935 XColor color;
1936 int type;
1938 if (nelem != 3)
1939 return NULL;
1941 if (val[0] == 's' || val[0] == 'S')
1942 type = WTP_SCALE;
1943 else if (val[0] == 'c' || val[0] == 'C')
1944 type = WTP_CENTER;
1945 else
1946 type = WTP_TILE;
1948 /* get color */
1949 elem = PLGetArrayElement(pl, 2);
1950 if (!elem || !PLIsString(elem)) {
1951 return NULL;
1953 val = PLGetString(elem);
1955 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1956 wwarning(_("\"%s\" is not a valid color name"), val);
1957 return NULL;
1960 /* file name */
1961 elem = PLGetArrayElement(pl, 1);
1962 if (!elem || !PLIsString(elem))
1963 return NULL;
1964 val = PLGetString(elem);
1966 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1967 } else if (strcasecmp(val, "thgradient")==0
1968 || strcasecmp(val, "tvgradient")==0
1969 || strcasecmp(val, "tdgradient")==0) {
1970 RColor color1, color2;
1971 XColor xcolor;
1972 int opacity;
1973 int style;
1975 if (val[1]=='h' || val[1]=='H')
1976 style = WTEX_THGRADIENT;
1977 else if (val[1]=='v' || val[1]=='V')
1978 style = WTEX_TVGRADIENT;
1979 else
1980 style = WTEX_TDGRADIENT;
1982 if (nelem != 5) {
1983 wwarning(_("bad number of arguments in textured gradient specification"));
1984 return NULL;
1987 /* get from color */
1988 elem = PLGetArrayElement(pl, 3);
1989 if (!elem || !PLIsString(elem))
1990 return NULL;
1991 val = PLGetString(elem);
1993 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1994 wwarning(_("\"%s\" is not a valid color name"), val);
1995 return NULL;
1997 color1.alpha = 255;
1998 color1.red = xcolor.red >> 8;
1999 color1.green = xcolor.green >> 8;
2000 color1.blue = xcolor.blue >> 8;
2002 /* get to color */
2003 elem = PLGetArrayElement(pl, 4);
2004 if (!elem || !PLIsString(elem)) {
2005 return NULL;
2007 val = PLGetString(elem);
2009 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2010 wwarning(_("\"%s\" is not a valid color name"), val);
2011 return NULL;
2013 color2.alpha = 255;
2014 color2.red = xcolor.red >> 8;
2015 color2.green = xcolor.green >> 8;
2016 color2.blue = xcolor.blue >> 8;
2018 /* get opacity */
2019 elem = PLGetArrayElement(pl, 2);
2020 if (!elem || !PLIsString(elem))
2021 opacity = 128;
2022 else
2023 val = PLGetString(elem);
2025 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2026 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2027 opacity = 128;
2030 /* get file name */
2031 elem = PLGetArrayElement(pl, 1);
2032 if (!elem || !PLIsString(elem))
2033 return NULL;
2034 val = PLGetString(elem);
2036 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2037 val, opacity);
2039 #ifdef TEXTURE_PLUGIN
2040 else if (strcasecmp(val, "function")==0) {
2041 WTexFunction *function;
2042 void (*initFunc) (Display *, Colormap);
2043 char *lib, *func, **argv;
2044 int i, argc;
2046 if (nelem < 3)
2047 return NULL;
2049 /* get the library name */
2050 elem = PLGetArrayElement(pl, 1);
2051 if (!elem || !PLIsString(elem)) {
2052 return NULL;
2054 lib = PLGetString(elem);
2056 /* get the function name */
2057 elem = PLGetArrayElement(pl, 2);
2058 if (!elem || !PLIsString(elem)) {
2059 return NULL;
2061 func = PLGetString(elem);
2063 argc = nelem - 2;
2064 argv = (char **)wmalloc(argc * sizeof(char *));
2066 /* get the parameters */
2067 argv[0] = wstrdup(func);
2068 for (i = 0; i < argc - 1; i++) {
2069 elem = PLGetArrayElement(pl, 3 + i);
2070 if (!elem || !PLIsString(elem)) {
2071 free(argv);
2073 return NULL;
2075 argv[i+1] = wstrdup(PLGetString(elem));
2078 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2080 #ifdef HAVE_DLFCN_H
2081 if (function) {
2082 initFunc = dlsym(function->handle, "initWindowMaker");
2083 if (initFunc) {
2084 initFunc(dpy, scr->w_colormap);
2085 } else {
2086 wwarning(_("could not initialize library %s"), lib);
2088 } else {
2089 wwarning(_("could not find function %s::%s"), lib, func);
2091 #endif /* HAVE_DLFCN_H */
2092 texture = (WTexture*)function;
2094 #endif /* TEXTURE_PLUGIN */
2095 else {
2096 wwarning(_("invalid texture type %s"), val);
2097 return NULL;
2099 return texture;
2104 static int
2105 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2106 void **ret)
2108 static WTexture *texture;
2109 int changed=0;
2111 again:
2112 if (!PLIsArray(value)) {
2113 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2114 entry->key, "Texture");
2115 if (changed==0) {
2116 value = entry->plvalue;
2117 changed = 1;
2118 wwarning(_("using default \"%s\" instead"), entry->default_value);
2119 goto again;
2121 return False;
2124 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2125 proplist_t pl;
2127 pl = PLGetArrayElement(value, 0);
2128 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2129 || strcasecmp(PLGetString(pl), "solid")!=0) {
2130 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2131 entry->key, "Solid Texture");
2133 value = entry->plvalue;
2134 changed = 1;
2135 wwarning(_("using default \"%s\" instead"), entry->default_value);
2136 goto again;
2140 texture = parse_texture(scr, value);
2142 if (!texture) {
2143 wwarning(_("Error in texture specification for key \"%s\""),
2144 entry->key);
2145 if (changed==0) {
2146 value = entry->plvalue;
2147 changed = 1;
2148 wwarning(_("using default \"%s\" instead"), entry->default_value);
2149 goto again;
2151 return False;
2154 if (ret)
2155 *ret = &texture;
2157 if (addr)
2158 *(WTexture**)addr = texture;
2160 return True;
2165 #ifdef DRAWSTRING_PLUGIN
2166 static int
2167 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2168 void *addr, void **ret)
2170 proplist_t elem;
2171 char *val, *lib, *func, **argv;
2172 int argc, changed;
2174 if (strcmp(entry->key, "FTitleColor")==0) {
2175 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2176 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2177 } else if (strcmp(entry->key, "UTitleColor")==0) {
2178 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2179 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2180 } else if (strcmp(entry->key, "PTitleColor")==0) {
2181 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2182 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2183 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2184 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2185 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2186 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2187 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2188 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2191 if (PLIsArray(value)) {
2192 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2193 argc -= 2;
2194 argv = (char **)wmalloc(argc * sizeof(char *));
2196 elem = PLGetArrayElement(value,0);
2197 if (!elem || !PLIsString(elem)) return False;
2198 val = PLGetString(elem);
2199 if (strcasecmp(val, "function")==0) {
2200 elem = PLGetArrayElement(value, 1); /* library name */
2201 if (!elem || !PLIsString(elem)) return False;
2202 lib = PLGetString(elem);
2203 elem = PLGetArrayElement(value, 2); /* function name */
2204 if (!elem || !PLIsString(elem)) return False;
2205 func = PLGetString(elem);
2206 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2207 lib, "initDrawString", func, NULL, value,
2208 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2211 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2212 } else if (PLIsString(value)) {
2213 return getColor(scr, entry, value, addr, ret);
2216 return False;
2218 #endif /* DRAWSTRING_PLUGIN */
2222 static int
2223 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2224 void *addr, void **ret)
2226 proplist_t elem;
2227 int changed = 0;
2228 char *val;
2229 int nelem;
2231 again:
2232 if (!PLIsArray(value)) {
2233 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2234 "WorkspaceBack", "Texture or None");
2235 if (changed==0) {
2236 value = entry->plvalue;
2237 changed = 1;
2238 wwarning(_("using default \"%s\" instead"), entry->default_value);
2239 goto again;
2241 return False;
2244 /* only do basic error checking and verify for None texture */
2246 nelem = PLGetNumberOfElements(value);
2247 if (nelem > 0) {
2248 elem = PLGetArrayElement(value, 0);
2249 if (!elem || !PLIsString(elem)) {
2250 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2251 if (changed==0) {
2252 value = entry->plvalue;
2253 changed = 1;
2254 wwarning(_("using default \"%s\" instead"), entry->default_value);
2255 goto again;
2257 return False;
2259 val = PLGetString(elem);
2261 if (strcasecmp(val, "None")==0)
2262 return True;
2264 *ret = PLRetain(value);
2266 return True;
2270 static int
2271 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2272 void *addr, void **ret)
2274 proplist_t elem;
2275 int nelem;
2276 int changed = 0;
2278 again:
2279 if (!PLIsArray(value)) {
2280 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2281 "WorkspaceSpecificBack", "an array of textures");
2282 if (changed==0) {
2283 value = entry->plvalue;
2284 changed = 1;
2285 wwarning(_("using default \"%s\" instead"), entry->default_value);
2286 goto again;
2288 return False;
2291 /* only do basic error checking and verify for None texture */
2293 nelem = PLGetNumberOfElements(value);
2294 if (nelem > 0) {
2295 while (nelem--) {
2296 elem = PLGetArrayElement(value, nelem);
2297 if (!elem || !PLIsArray(elem)) {
2298 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2299 nelem);
2304 *ret = PLRetain(value);
2306 #ifdef notworking
2308 * Kluge to force wmsetbg helper to set the default background.
2309 * If the WorkspaceSpecificBack is changed once wmaker has started,
2310 * the WorkspaceBack won't be sent to the helper, unless the user
2311 * changes it's value too. So, we must force this by removing the
2312 * value from the defaults DB.
2314 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2315 proplist_t key = PLMakeString("WorkspaceBack");
2317 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2319 PLRelease(key);
2321 #endif
2322 return True;
2326 static int
2327 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2328 void **ret)
2330 static WMFont *font;
2331 char *val;
2333 GET_STRING_OR_DEFAULT("Font", val);
2335 font = WMCreateFont(scr->wmscreen, val);
2336 if (!font)
2337 font = WMCreateFont(scr->wmscreen, "fixed");
2339 if (!font) {
2340 wfatal(_("could not load any usable font!!!"));
2341 exit(1);
2344 if (ret)
2345 *ret = font;
2347 /* can't assign font value outside update function */
2348 wassertrv(addr == NULL, True);
2350 return True;
2354 static int
2355 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2356 void **ret)
2358 static XColor color;
2359 char *val;
2360 int second_pass=0;
2362 GET_STRING_OR_DEFAULT("Color", val);
2365 again:
2366 if (!wGetColor(scr, val, &color)) {
2367 wwarning(_("could not get color for key \"%s\""),
2368 entry->key);
2369 if (second_pass==0) {
2370 val = PLGetString(entry->plvalue);
2371 second_pass = 1;
2372 wwarning(_("using default \"%s\" instead"), val);
2373 goto again;
2375 return False;
2378 if (ret)
2379 *ret = &color;
2381 assert(addr==NULL);
2383 if (addr)
2384 *(unsigned long*)addr = pixel;
2387 return True;
2392 static int
2393 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2394 void **ret)
2396 static WShortKey shortcut;
2397 KeySym ksym;
2398 char *val;
2399 char *k;
2400 char buf[128], *b;
2403 GET_STRING_OR_DEFAULT("Key spec", val);
2405 if (!val || strcasecmp(val, "NONE")==0) {
2406 shortcut.keycode = 0;
2407 shortcut.modifier = 0;
2408 if (ret)
2409 *ret = &shortcut;
2410 return True;
2413 strcpy(buf, val);
2415 b = (char*)buf;
2417 /* get modifiers */
2418 shortcut.modifier = 0;
2419 while ((k = strchr(b, '+'))!=NULL) {
2420 int mod;
2422 *k = 0;
2423 mod = wXModifierFromKey(b);
2424 if (mod<0) {
2425 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2426 return False;
2428 shortcut.modifier |= mod;
2430 b = k+1;
2433 /* get key */
2434 ksym = XStringToKeysym(b);
2436 if (ksym==NoSymbol) {
2437 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2438 val);
2439 return False;
2442 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2443 if (shortcut.keycode==0) {
2444 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2445 return False;
2448 if (ret)
2449 *ret = &shortcut;
2451 return True;
2455 static int
2456 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2457 void **ret)
2459 static unsigned int mask;
2460 char *str;
2462 GET_STRING_OR_DEFAULT("Modifier Key", str);
2464 if (!str)
2465 return False;
2467 mask = wXModifierFromKey(str);
2468 if (mask < 0) {
2469 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2470 mask = 0;
2471 return False;
2474 if (addr)
2475 *(unsigned int*)addr = mask;
2477 if (ret)
2478 *ret = &mask;
2480 return True;
2484 #ifdef NEWSTUFF
2485 static int
2486 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2487 void *addr, void **ret)
2489 unsigned int mask;
2490 char *str;
2491 RImage *image;
2492 int i, n;
2493 int w, h;
2495 GET_STRING_OR_DEFAULT("Image File Path", str);
2496 if (!str)
2497 return False;
2499 image = RLoadImage(scr->rcontext, str, 0);
2500 if (!image) {
2501 wwarning(_("could not load image in option %s: %s"), entry->key,
2502 RMessageForError(RErrorCode));
2503 return False;
2506 if (*(RImage**)addr) {
2507 RDestroyImage(*(RImage**)addr);
2509 if (addr)
2510 *(RImage**)addr = image;
2512 assert(ret == NULL);
2514 if (ret)
2515 *(RImage**)ret = image;
2518 return True;
2520 #endif
2522 #ifdef DEFINABLE_CURSOR
2524 # include <X11/cursorfont.h>
2525 typedef struct
2527 char *name;
2528 int id;
2529 } WCursorLookup;
2531 #define CURSOR_ID_NONE (XC_num_glyphs)
2533 static WCursorLookup cursor_table[] =
2535 { "X_cursor", XC_X_cursor },
2536 { "arrow", XC_arrow },
2537 { "based_arrow_down", XC_based_arrow_down },
2538 { "based_arrow_up", XC_based_arrow_up },
2539 { "boat", XC_boat },
2540 { "bogosity", XC_bogosity },
2541 { "bottom_left_corner", XC_bottom_left_corner },
2542 { "bottom_right_corner", XC_bottom_right_corner },
2543 { "bottom_side", XC_bottom_side },
2544 { "bottom_tee", XC_bottom_tee },
2545 { "box_spiral", XC_box_spiral },
2546 { "center_ptr", XC_center_ptr },
2547 { "circle", XC_circle },
2548 { "clock", XC_clock },
2549 { "coffee_mug", XC_coffee_mug },
2550 { "cross", XC_cross },
2551 { "cross_reverse", XC_cross_reverse },
2552 { "crosshair", XC_crosshair },
2553 { "diamond_cross", XC_diamond_cross },
2554 { "dot", XC_dot },
2555 { "dotbox", XC_dotbox },
2556 { "double_arrow", XC_double_arrow },
2557 { "draft_large", XC_draft_large },
2558 { "draft_small", XC_draft_small },
2559 { "draped_box", XC_draped_box },
2560 { "exchange", XC_exchange },
2561 { "fleur", XC_fleur },
2562 { "gobbler", XC_gobbler },
2563 { "gumby", XC_gumby },
2564 { "hand1", XC_hand1 },
2565 { "hand2", XC_hand2 },
2566 { "heart", XC_heart },
2567 { "icon", XC_icon },
2568 { "iron_cross", XC_iron_cross },
2569 { "left_ptr", XC_left_ptr },
2570 { "left_side", XC_left_side },
2571 { "left_tee", XC_left_tee },
2572 { "leftbutton", XC_leftbutton },
2573 { "ll_angle", XC_ll_angle },
2574 { "lr_angle", XC_lr_angle },
2575 { "man", XC_man },
2576 { "middlebutton", XC_middlebutton },
2577 { "mouse", XC_mouse },
2578 { "pencil", XC_pencil },
2579 { "pirate", XC_pirate },
2580 { "plus", XC_plus },
2581 { "question_arrow", XC_question_arrow },
2582 { "right_ptr", XC_right_ptr },
2583 { "right_side", XC_right_side },
2584 { "right_tee", XC_right_tee },
2585 { "rightbutton", XC_rightbutton },
2586 { "rtl_logo", XC_rtl_logo },
2587 { "sailboat", XC_sailboat },
2588 { "sb_down_arrow", XC_sb_down_arrow },
2589 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2590 { "sb_left_arrow", XC_sb_left_arrow },
2591 { "sb_right_arrow", XC_sb_right_arrow },
2592 { "sb_up_arrow", XC_sb_up_arrow },
2593 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2594 { "shuttle", XC_shuttle },
2595 { "sizing", XC_sizing },
2596 { "spider", XC_spider },
2597 { "spraycan", XC_spraycan },
2598 { "star", XC_star },
2599 { "target", XC_target },
2600 { "tcross", XC_tcross },
2601 { "top_left_arrow", XC_top_left_arrow },
2602 { "top_left_corner", XC_top_left_corner },
2603 { "top_right_corner", XC_top_right_corner },
2604 { "top_side", XC_top_side },
2605 { "top_tee", XC_top_tee },
2606 { "trek", XC_trek },
2607 { "ul_angle", XC_ul_angle },
2608 { "umbrella", XC_umbrella },
2609 { "ur_angle", XC_ur_angle },
2610 { "watch", XC_watch },
2611 { "xterm", XC_xterm },
2612 { NULL, CURSOR_ID_NONE }
2615 static void
2616 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2618 switch(status) {
2619 case BitmapOpenFailed:
2620 wwarning(_("failed to open bitmap file \"%s\""), filename);
2621 break;
2622 case BitmapFileInvalid:
2623 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2624 break;
2625 case BitmapNoMemory:
2626 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2627 break;
2628 case BitmapSuccess:
2629 XFreePixmap(dpy, bitmap);
2630 break;
2635 * (none)
2636 * (builtin, <cursor_name>)
2637 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2639 static int
2640 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2642 proplist_t elem;
2643 char *val;
2644 int nelem;
2645 int status = 0;
2647 nelem = PLGetNumberOfElements(pl);
2648 if (nelem < 1) {
2649 return(status);
2651 elem = PLGetArrayElement(pl, 0);
2652 if (!elem || !PLIsString(elem)) {
2653 return(status);
2655 val = PLGetString(elem);
2657 if (0 == strcasecmp(val, "none")) {
2658 status = 1;
2659 *cursor = None;
2660 } else if (0 == strcasecmp(val, "builtin")) {
2661 int i;
2662 int cursor_id = CURSOR_ID_NONE;
2664 if (2 != nelem) {
2665 wwarning(_("bad number of arguments in cursor specification"));
2666 return(status);
2668 elem = PLGetArrayElement(pl, 1);
2669 if (!elem || !PLIsString(elem)) {
2670 return(status);
2672 val = PLGetString(elem);
2674 for (i = 0; NULL != cursor_table[i].name; i++) {
2675 if (0 == strcasecmp(val, cursor_table[i].name)) {
2676 cursor_id = cursor_table[i].id;
2677 break;
2680 if (CURSOR_ID_NONE == cursor_id) {
2681 wwarning(_("unknown builtin cursor name \"%s\""), val);
2682 } else {
2683 *cursor = XCreateFontCursor(dpy, cursor_id);
2684 status = 1;
2686 } else if (0 == strcasecmp(val, "bitmap")) {
2687 char *bitmap_name;
2688 char *mask_name;
2689 int bitmap_status;
2690 int mask_status;
2691 Pixmap bitmap;
2692 Pixmap mask;
2693 unsigned int w, h;
2694 int x, y;
2695 XColor fg, bg;
2697 if (3 != nelem) {
2698 wwarning(_("bad number of arguments in cursor specification"));
2699 return(status);
2701 elem = PLGetArrayElement(pl, 1);
2702 if (!elem || !PLIsString(elem)) {
2703 return(status);
2705 val = PLGetString(elem);
2706 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2707 if (!bitmap_name) {
2708 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2709 return(status);
2711 elem = PLGetArrayElement(pl, 2);
2712 if (!elem || !PLIsString(elem)) {
2713 free(bitmap_name);
2714 return(status);
2716 val = PLGetString(elem);
2717 mask_name = FindImage(wPreferences.pixmap_path, val);
2718 if (!mask_name) {
2719 free(bitmap_name);
2720 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2721 return(status);
2723 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2724 &mask, &x, &y);
2725 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2726 &bitmap, &x, &y);
2727 if ((BitmapSuccess == bitmap_status) &&
2728 (BitmapSuccess == mask_status)) {
2729 fg.pixel = scr->black_pixel;
2730 bg.pixel = scr->white_pixel;
2731 XQueryColor(dpy, scr->w_colormap, &fg);
2732 XQueryColor(dpy, scr->w_colormap, &bg);
2733 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2734 status = 1;
2736 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2737 check_bitmap_status(mask_status, mask_name, mask);
2738 free(bitmap_name);
2739 free(mask_name);
2741 return(status);
2745 static int
2746 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2747 void **ret)
2749 static Cursor cursor;
2750 int status;
2751 int changed = 0;
2753 again:
2754 if (!PLIsArray(value)) {
2755 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2756 entry->key, "cursor specification");
2757 if (!changed) {
2758 value = entry->plvalue;
2759 changed = 1;
2760 wwarning(_("using default \"%s\" instead"), entry->default_value);
2761 goto again;
2763 return(False);
2765 status = parse_cursor(scr, value, &cursor);
2766 if (!status) {
2767 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
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 if (ret) {
2777 *ret = &cursor;
2779 if (addr) {
2780 *(Cursor *)addr = cursor;
2782 return(True);
2784 #undef CURSOR_ID_NONE
2786 #endif /* DEFINABLE_CURSOR */
2789 /* ---------------- value setting functions --------------- */
2790 static int
2791 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2793 return REFRESH_WINDOW_TITLE_COLOR;
2796 static int
2797 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2799 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2802 static int
2803 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2805 switch (which) {
2806 case WM_DOCK:
2807 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2808 break;
2809 case WM_CLIP:
2810 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2811 break;
2812 default:
2813 break;
2815 return 0;
2819 static int
2820 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2822 if (scr->workspaces) {
2823 wWorkspaceForceChange(scr, scr->current_workspace);
2824 wArrangeIcons(scr, False);
2826 return 0;
2829 #if not_used
2830 static int
2831 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2833 if (*value <= 0)
2834 *(int*)foo = 1;
2836 return 0;
2838 #endif
2842 static int
2843 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2845 Pixmap pixmap;
2846 RImage *img;
2847 int reset = 0;
2849 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2850 wPreferences.icon_size,
2851 ((*texture)->any.type & WREL_BORDER_MASK)
2852 ? WREL_ICON : WREL_FLAT);
2853 if (!img) {
2854 wwarning(_("could not render texture for icon background"));
2855 if (!entry->addr)
2856 wTextureDestroy(scr, *texture);
2857 return 0;
2859 RConvertImage(scr->rcontext, img, &pixmap);
2861 if (scr->icon_tile) {
2862 reset = 1;
2863 RDestroyImage(scr->icon_tile);
2864 XFreePixmap(dpy, scr->icon_tile_pixmap);
2867 scr->icon_tile = img;
2870 /* put the icon in the noticeboard hint */
2871 PropSetIconTileHint(scr, img);
2874 if (!wPreferences.flags.noclip) {
2875 if (scr->clip_tile) {
2876 RDestroyImage(scr->clip_tile);
2878 scr->clip_tile = wClipMakeTile(scr, img);
2881 scr->icon_tile_pixmap = pixmap;
2883 if (scr->def_icon_pixmap) {
2884 XFreePixmap(dpy, scr->def_icon_pixmap);
2885 scr->def_icon_pixmap = None;
2887 if (scr->def_ticon_pixmap) {
2888 XFreePixmap(dpy, scr->def_ticon_pixmap);
2889 scr->def_ticon_pixmap = None;
2892 if (scr->icon_back_texture) {
2893 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2895 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2897 if (scr->clip_balloon)
2898 XSetWindowBackground(dpy, scr->clip_balloon,
2899 (*texture)->any.color.pixel);
2902 * Free the texture as nobody else will use it, nor refer to it.
2904 if (!entry->addr)
2905 wTextureDestroy(scr, *texture);
2907 return (reset ? REFRESH_ICON_TILE : 0);
2912 static int
2913 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2915 if (scr->title_font) {
2916 WMReleaseFont(scr->title_font);
2918 scr->title_font = font;
2920 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2924 static int
2925 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2927 if (scr->menu_title_font) {
2928 WMReleaseFont(scr->menu_title_font);
2931 scr->menu_title_font = font;
2933 return REFRESH_MENU_TITLE_FONT;
2937 static int
2938 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2940 if (scr->menu_entry_font) {
2941 WMReleaseFont(scr->menu_entry_font);
2943 scr->menu_entry_font = font;
2945 return REFRESH_MENU_FONT;
2950 static int
2951 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2953 if (scr->icon_title_font) {
2954 WMReleaseFont(scr->icon_title_font);
2957 scr->icon_title_font = font;
2959 return REFRESH_ICON_FONT;
2963 static int
2964 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2966 if (scr->clip_title_font) {
2967 WMReleaseFont(scr->clip_title_font);
2970 scr->clip_title_font = font;
2972 return REFRESH_ICON_FONT;
2976 static int
2977 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2979 if (scr->workspace_name_font) {
2980 WMReleaseFont(scr->workspace_name_font);
2983 scr->workspace_name_font = font;
2985 return 0;
2989 static int
2990 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2992 if (scr->select_pixel!=scr->white_pixel &&
2993 scr->select_pixel!=scr->black_pixel) {
2994 wFreeColor(scr, scr->select_pixel);
2997 scr->select_pixel = color->pixel;
2999 return REFRESH_MENU_COLOR;
3003 static int
3004 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3006 if (scr->select_text_pixel!=scr->white_pixel &&
3007 scr->select_text_pixel!=scr->black_pixel) {
3008 wFreeColor(scr, scr->select_text_pixel);
3011 scr->select_text_pixel = color->pixel;
3013 return REFRESH_MENU_COLOR;
3017 static int
3018 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3020 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
3021 scr->clip_title_pixel[index]!=scr->black_pixel) {
3022 wFreeColor(scr, scr->clip_title_pixel[index]);
3024 scr->clip_title_pixel[index] = color->pixel;
3026 #ifdef GRADIENT_CLIP_ARROW
3027 if (index == CLIP_NORMAL) {
3028 RImage *image;
3029 RColor color1, color2;
3030 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3031 int as = pt - 15; /* 15 = 5+5+5 */
3033 FREE_PIXMAP(scr->clip_arrow_gradient);
3035 color1.red = (color->red >> 8)*6/10;
3036 color1.green = (color->green >> 8)*6/10;
3037 color1.blue = (color->blue >> 8)*6/10;
3039 color2.red = WMIN((color->red >> 8)*20/10, 255);
3040 color2.green = WMIN((color->green >> 8)*20/10, 255);
3041 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3043 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3044 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3045 RDestroyImage(image);
3047 #endif /* GRADIENT_CLIP_ARROW */
3049 return REFRESH_ICON_TITLE_COLOR;
3053 static int
3054 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3056 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3057 scr->window_title_pixel[index]!=scr->black_pixel) {
3058 wFreeColor(scr, scr->window_title_pixel[index]);
3061 scr->window_title_pixel[index] = color->pixel;
3063 if (index == WS_UNFOCUSED)
3064 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3066 return REFRESH_WINDOW_TITLE_COLOR;
3070 static int
3071 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3073 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3074 scr->menu_title_pixel[0]!=scr->black_pixel) {
3075 #ifdef DRAWSTRING_PLUGIN
3076 if(!scr->drawstring_func[W_STRING_MTITLE])
3077 #endif
3078 wFreeColor(scr, scr->menu_title_pixel[0]);
3081 scr->menu_title_pixel[0] = color->pixel;
3082 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3084 return REFRESH_MENU_TITLE_COLOR;
3088 static int
3089 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3091 XGCValues gcv;
3092 #define gcm (GCForeground|GCBackground|GCFillStyle)
3094 if (scr->mtext_pixel!=scr->white_pixel &&
3095 scr->mtext_pixel!=scr->black_pixel) {
3096 wFreeColor(scr, scr->mtext_pixel);
3099 scr->mtext_pixel = color->pixel;
3101 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3104 if (scr->dtext_pixel == scr->mtext_pixel) {
3105 gcv.foreground = scr->white_pixel;
3106 gcv.background = scr->black_pixel;
3107 gcv.fill_style = FillStippled;
3108 } else {
3109 gcv.foreground = scr->dtext_pixel;
3110 gcv.fill_style = FillSolid;
3112 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3114 return REFRESH_MENU_COLOR;
3115 #undef gcm
3119 static int
3120 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3122 XGCValues gcv;
3123 #define gcm (GCForeground|GCBackground|GCFillStyle)
3125 if (scr->dtext_pixel!=scr->white_pixel &&
3126 scr->dtext_pixel!=scr->black_pixel) {
3127 wFreeColor(scr, scr->dtext_pixel);
3130 scr->dtext_pixel = color->pixel;
3132 if (scr->dtext_pixel == scr->mtext_pixel) {
3133 gcv.foreground = scr->white_pixel;
3134 gcv.background = scr->black_pixel;
3135 gcv.fill_style = FillStippled;
3136 } else {
3137 gcv.foreground = scr->dtext_pixel;
3138 gcv.fill_style = FillSolid;
3140 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3142 return REFRESH_MENU_COLOR;
3143 #undef gcm
3146 static int
3147 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3149 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3151 return REFRESH_ICON_TITLE_COLOR;
3155 static int
3156 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3158 if (scr->icon_title_texture) {
3159 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3161 XQueryColor (dpy, scr->w_colormap, color);
3162 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3164 return REFRESH_ICON_TITLE_BACK;
3168 static void
3169 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3171 close(scr->helper_fd);
3172 scr->helper_fd = 0;
3173 scr->helper_pid = 0;
3174 scr->flags.backimage_helper_launched = 0;
3178 static int
3179 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3180 void *bar)
3182 int i;
3183 proplist_t val;
3184 char *str;
3186 if (scr->flags.backimage_helper_launched) {
3187 if (PLGetNumberOfElements(value)==0) {
3188 SendHelperMessage(scr, 'C', 0, NULL);
3189 SendHelperMessage(scr, 'K', 0, NULL);
3191 PLRelease(value);
3192 return 0;
3194 } else {
3195 pid_t pid;
3196 int filedes[2];
3198 if (PLGetNumberOfElements(value) == 0)
3199 return 0;
3201 if (pipe(filedes) < 0) {
3202 wsyserror("pipe() failed:can't set workspace specific background image");
3204 PLRelease(value);
3205 return 0;
3208 pid = fork();
3209 if (pid < 0) {
3210 wsyserror("fork() failed:can't set workspace specific background image");
3211 if (close(filedes[0]) < 0)
3212 wsyserror("could not close pipe");
3213 if (close(filedes[1]) < 0)
3214 wsyserror("could not close pipe");
3216 } else if (pid == 0) {
3217 SetupEnvironment(scr);
3219 if (close(0) < 0)
3220 wsyserror("could not close pipe");
3221 if (dup(filedes[0]) < 0) {
3222 wsyserror("dup() failed:can't set workspace specific background image");
3224 if (wPreferences.smooth_workspace_back)
3225 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
3226 else
3227 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
3228 wsyserror("could not execute wmsetbg");
3229 exit(1);
3230 } else {
3232 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3233 wsyserror("error setting close-on-exec flag");
3235 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3236 wsyserror("error setting close-on-exec flag");
3239 scr->helper_fd = filedes[1];
3240 scr->helper_pid = pid;
3241 scr->flags.backimage_helper_launched = 1;
3243 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3245 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3250 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3251 val = PLGetArrayElement(value, i);
3252 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3253 str = PLGetDescription(val);
3255 SendHelperMessage(scr, 'S', i+1, str);
3257 free(str);
3258 } else {
3259 SendHelperMessage(scr, 'U', i+1, NULL);
3262 sleep(1);
3264 PLRelease(value);
3265 return 0;
3269 static int
3270 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3271 void *bar)
3273 if (scr->flags.backimage_helper_launched) {
3274 char *str;
3276 if (PLGetNumberOfElements(value)==0) {
3277 SendHelperMessage(scr, 'U', 0, NULL);
3278 } else {
3279 /* set the default workspace background to this one */
3280 str = PLGetDescription(value);
3281 if (str) {
3282 SendHelperMessage(scr, 'S', 0, str);
3283 free(str);
3284 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3285 } else {
3286 SendHelperMessage(scr, 'U', 0, NULL);
3289 } else if (PLGetNumberOfElements(value) > 0) {
3290 char *command;
3291 char *text;
3293 SetupEnvironment(scr);
3294 text = PLGetDescription(value);
3295 command = wmalloc(strlen(text)+40);
3296 if (wPreferences.smooth_workspace_back)
3297 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
3298 else
3299 sprintf(command, "wmsetbg -d -p '%s' &", text);
3300 free(text);
3301 system(command);
3302 free(command);
3304 PLRelease(value);
3306 return 0;
3310 static int
3311 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3313 if (scr->widget_texture) {
3314 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3316 scr->widget_texture = *(WTexSolid**)texture;
3318 return 0;
3322 static int
3323 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3325 if (scr->window_title_texture[WS_FOCUSED]) {
3326 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3328 scr->window_title_texture[WS_FOCUSED] = *texture;
3330 return REFRESH_WINDOW_TEXTURES;
3334 static int
3335 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3337 if (scr->window_title_texture[WS_PFOCUSED]) {
3338 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3340 scr->window_title_texture[WS_PFOCUSED] = *texture;
3342 return REFRESH_WINDOW_TEXTURES;
3346 static int
3347 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3349 if (scr->window_title_texture[WS_UNFOCUSED]) {
3350 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3352 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3354 return REFRESH_WINDOW_TEXTURES;
3358 static int
3359 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3361 if (scr->resizebar_texture[0]) {
3362 wTextureDestroy(scr, scr->resizebar_texture[0]);
3364 scr->resizebar_texture[0] = *texture;
3366 return REFRESH_WINDOW_TEXTURES;
3370 static int
3371 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3373 if (scr->menu_title_texture[0]) {
3374 wTextureDestroy(scr, scr->menu_title_texture[0]);
3376 scr->menu_title_texture[0] = *texture;
3378 return REFRESH_MENU_TITLE_TEXTURE;
3382 static int
3383 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3385 if (scr->menu_item_texture) {
3386 wTextureDestroy(scr, scr->menu_item_texture);
3387 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3389 scr->menu_item_texture = *texture;
3391 scr->menu_item_auxtexture
3392 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3394 return REFRESH_MENU_TEXTURE;
3398 static int
3399 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3401 WWindow *wwin;
3402 wKeyBindings[index] = *shortcut;
3404 wwin = scr->focused_window;
3406 while (wwin!=NULL) {
3407 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3409 if (!WFLAGP(wwin, no_bind_keys)) {
3410 wWindowSetKeyGrabs(wwin);
3412 wwin = wwin->prev;
3415 return 0;
3419 static int
3420 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3422 wArrangeIcons(scr, True);
3424 return 0;
3428 static int
3429 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3431 wScreenUpdateUsableArea(scr);
3433 return 0;
3437 static int
3438 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3440 return REFRESH_MENU_TEXTURE;
3445 static int
3446 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3448 return REFRESH_BUTTON_IMAGES;
3453 * Very ugly kluge.
3454 * Need access to the double click variables, so that all widgets in
3455 * wmaker panels will have the same dbl-click values.
3456 * TODO: figure a better way of dealing with it.
3458 #include "WINGsP.h"
3460 static int
3461 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3463 extern _WINGsConfiguration WINGsConfiguration;
3465 if (*value <= 0)
3466 *(int*)foo = 1;
3468 WINGsConfiguration.doubleClickDelay = *value;
3470 return 0;
3475 static int
3476 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3478 extern _WINGsConfiguration WINGsConfiguration;
3480 WINGsConfiguration.useMultiByte = *value;
3482 return 0;
3486 #ifdef DEFINABLE_CURSOR
3487 static int
3488 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3490 if (None != wCursor[index])
3492 XFreeCursor(dpy, wCursor[index]);
3495 wCursor[index] = *cursor;
3497 if ((WCUR_ROOT == index) && (None != *cursor))
3499 XDefineCursor(dpy, scr->root_win, *cursor);
3502 return 0;
3504 #endif /* DEFINABLE_CURSOR*/