fix a typo.
[wmaker-crm.git] / src / defaults.c
blobe76a361ea1f955069baa06ccebc53b5a69253285
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 {"VirtualEdgeWidth", "2000", NULL,
455 &wPreferences.vedge_width, getInt, NULL
457 {"VirtualEdgeHeight", "2000", NULL,
458 &wPreferences.vedge_height, 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 #else
656 {"MenuTitleColor", "white", NULL,
657 NULL, getColor, setMenuTitleColor
659 #endif
660 {"MenuTextColor", "black", NULL,
661 NULL, getColor, setMenuTextColor
663 {"MenuDisabledColor", "\"#616161\"", NULL,
664 NULL, getColor, setMenuDisabledColor
666 {"MenuTitleBack", "(solid, black)", NULL,
667 NULL, getTexture, setMenuTitleBack
669 {"MenuTextBack", "(solid, gray)", NULL,
670 NULL, getTexture, setMenuTextBack
672 {"IconTitleColor", "white", NULL,
673 NULL, getColor, setIconTitleColor
675 {"IconTitleBack", "black", NULL,
676 NULL, getColor, setIconTitleBack
678 /* keybindings */
679 #ifndef LITE
680 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
681 NULL, getKeybind, setKeyGrab
683 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
684 NULL, getKeybind, setKeyGrab
686 #endif /* LITE */
687 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
688 NULL, getKeybind, setKeyGrab
690 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
691 NULL, getKeybind, setKeyGrab
693 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
694 NULL, getKeybind, setKeyGrab
696 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
697 NULL, getKeybind, setKeyGrab
699 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
700 NULL, getKeybind, setKeyGrab
702 {"HideKey", "None", (void*)WKBD_HIDE,
703 NULL, getKeybind, setKeyGrab
705 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
706 NULL, getKeybind, setKeyGrab
708 {"CloseKey", "None", (void*)WKBD_CLOSE,
709 NULL, getKeybind, setKeyGrab
711 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
712 NULL, getKeybind, setKeyGrab
714 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
715 NULL, getKeybind, setKeyGrab
717 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
718 NULL, getKeybind, setKeyGrab
720 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
721 NULL, getKeybind, setKeyGrab
723 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
724 NULL, getKeybind, setKeyGrab
726 {"ShadeKey", "None", (void*)WKBD_SHADE,
727 NULL, getKeybind, setKeyGrab
729 {"SelectKey", "None", (void*)WKBD_SELECT,
730 NULL, getKeybind, setKeyGrab
732 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
733 NULL, getKeybind, setKeyGrab
735 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
736 NULL, getKeybind, setKeyGrab
738 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
739 NULL, getKeybind, setKeyGrab
741 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
742 NULL, getKeybind, setKeyGrab
744 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
745 NULL, getKeybind, setKeyGrab
747 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
760 NULL, getKeybind, setKeyGrab
762 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
763 NULL, getKeybind, setKeyGrab
765 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
766 NULL, getKeybind, setKeyGrab
768 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
769 NULL, getKeybind, setKeyGrab
771 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
772 NULL, getKeybind, setKeyGrab
774 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
775 NULL, getKeybind, setKeyGrab
777 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
778 NULL, getKeybind, setKeyGrab
780 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
781 NULL, getKeybind, setKeyGrab
783 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
784 NULL, getKeybind, setKeyGrab
786 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
787 NULL, getKeybind, setKeyGrab
789 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
790 NULL, getKeybind, setKeyGrab
792 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
793 NULL, getKeybind, setKeyGrab
795 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
796 NULL, getKeybind, setKeyGrab
798 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
799 NULL, getKeybind, setKeyGrab
801 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
802 NULL, getKeybind, setKeyGrab
804 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
805 NULL, getKeybind, setKeyGrab
807 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
808 NULL, getKeybind, setKeyGrab
810 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
811 NULL, getKeybind, setKeyGrab
814 #ifdef KEEP_XKB_LOCK_STATUS
815 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
816 NULL, getKeybind, setKeyGrab
818 {"KbdModeLock", "NO", NULL,
819 &wPreferences.modelock, getBool, NULL
821 #endif /* KEEP_XKB_LOCK_STATUS */
822 #ifdef DEFINABLE_CURSOR
823 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
824 NULL, getCursor, setCursor
826 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
827 NULL, getCursor, setCursor
829 #if 0
830 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
831 NULL, getCursor, setCursor
833 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
834 NULL, getCursor, setCursor
836 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
837 NULL, getCursor, setCursor
839 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
840 NULL, getCursor, setCursor
842 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
843 NULL, getCursor, setCursor
845 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
846 NULL, getCursor, setCursor
848 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
849 NULL, getCursor, setCursor
851 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
852 NULL, getCursor, setCursor
854 #endif
855 #endif /* DEFINABLE_CURSOR */
859 #if 0
860 static void rereadDefaults(void);
861 #endif
863 #if 0
864 static void
865 rereadDefaults(void)
867 /* must defer the update because accessing X data from a
868 * signal handler can mess up Xlib */
871 #endif
873 static void
874 initDefaults()
876 int i;
877 WDefaultEntry *entry;
879 PLSetStringCmpHook(StringCompareHook);
881 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
882 entry = &optionList[i];
884 entry->plkey = PLMakeString(entry->key);
885 if (entry->default_value)
886 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
887 else
888 entry->plvalue = NULL;
891 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
892 entry = &staticOptionList[i];
894 entry->plkey = PLMakeString(entry->key);
895 if (entry->default_value)
896 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
897 else
898 entry->plvalue = NULL;
902 wDomainName = PLMakeString(WMDOMAIN_NAME);
903 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
905 PLRegister(wDomainName, rereadDefaults);
906 PLRegister(wAttributeDomainName, rereadDefaults);
913 #if 0
914 proplist_t
915 wDefaultsInit(int screen_number)
917 static int defaults_inited = 0;
918 proplist_t dict;
920 if (!defaults_inited) {
921 initDefaults();
924 dict = PLGetDomain(wDomainName);
925 if (!dict) {
926 wwarning(_("could not read domain \"%s\" from defaults database"),
927 PLGetString(wDomainName));
930 return dict;
932 #endif
935 void
936 wDefaultsDestroyDomain(WDDomain *domain)
938 if (domain->dictionary)
939 PLRelease(domain->dictionary);
940 wfree(domain->path);
941 wfree(domain);
945 WDDomain*
946 wDefaultsInitDomain(char *domain, Bool requireDictionary)
948 WDDomain *db;
949 struct stat stbuf;
950 static int inited = 0;
951 char path[PATH_MAX];
952 char *the_path;
953 proplist_t shared_dict=NULL;
955 if (!inited) {
956 inited = 1;
957 initDefaults();
960 db = wmalloc(sizeof(WDDomain));
961 memset(db, 0, sizeof(WDDomain));
962 db->domain_name = domain;
963 db->path = wdefaultspathfordomain(domain);
964 the_path = db->path;
966 if (the_path && stat(the_path, &stbuf)>=0) {
967 db->dictionary = ReadProplistFromFile(the_path);
968 if (db->dictionary) {
969 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
970 PLRelease(db->dictionary);
971 db->dictionary = NULL;
972 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
973 domain, the_path);
975 db->timestamp = stbuf.st_mtime;
976 } else {
977 wwarning(_("could not load domain %s from user defaults database"),
978 domain);
982 /* global system dictionary */
983 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
984 if (stat(path, &stbuf)>=0) {
985 shared_dict = ReadProplistFromFile(path);
986 if (shared_dict) {
987 if (requireDictionary && !PLIsDictionary(shared_dict)) {
988 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
989 domain, path);
990 PLRelease(shared_dict);
991 shared_dict = NULL;
992 } else {
993 if (db->dictionary && PLIsDictionary(shared_dict) &&
994 PLIsDictionary(db->dictionary)) {
995 PLMergeDictionaries(shared_dict, db->dictionary);
996 PLRelease(db->dictionary);
997 db->dictionary = shared_dict;
998 if (stbuf.st_mtime > db->timestamp)
999 db->timestamp = stbuf.st_mtime;
1000 } else if (!db->dictionary) {
1001 db->dictionary = shared_dict;
1002 if (stbuf.st_mtime > db->timestamp)
1003 db->timestamp = stbuf.st_mtime;
1006 } else {
1007 wwarning(_("could not load domain %s from global defaults database (%s)"),
1008 domain, path);
1012 /* set to save it in user's directory, no matter from where it was read */
1013 if (db->dictionary) {
1014 proplist_t tmp = PLMakeString(db->path);
1016 PLSetFilename(db->dictionary, tmp);
1017 PLRelease(tmp);
1020 return db;
1024 void
1025 wReadStaticDefaults(proplist_t dict)
1027 proplist_t plvalue;
1028 WDefaultEntry *entry;
1029 int i;
1030 void *tdata;
1033 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1034 entry = &staticOptionList[i];
1036 if (dict)
1037 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1038 else
1039 plvalue = NULL;
1041 if (!plvalue) {
1042 /* no default in the DB. Use builtin default */
1043 plvalue = entry->plvalue;
1046 if (plvalue) {
1047 /* convert data */
1048 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1049 if (entry->update) {
1050 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1057 void
1058 wDefaultsCheckDomains(void *foo)
1060 WScreen *scr;
1061 struct stat stbuf;
1062 proplist_t dict;
1063 int i;
1064 char path[PATH_MAX];
1066 #ifdef HEARTBEAT
1067 puts("Checking domains...");
1068 #endif
1069 if (stat(WDWindowMaker->path, &stbuf)>=0
1070 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1071 proplist_t shared_dict = NULL;
1072 #ifdef HEARTBEAT
1073 puts("Checking WindowMaker domain");
1074 #endif
1075 WDWindowMaker->timestamp = stbuf.st_mtime;
1077 /* global dictionary */
1078 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1079 if (stat(path, &stbuf)>=0) {
1080 shared_dict = ReadProplistFromFile(path);
1081 if (shared_dict && !PLIsDictionary(shared_dict)) {
1082 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1083 "WindowMaker", path);
1084 PLRelease(shared_dict);
1085 shared_dict = NULL;
1086 } else if (!shared_dict) {
1087 wwarning(_("could not load domain %s from global defaults database"),
1088 "WindowMaker");
1091 /* user dictionary */
1092 dict = ReadProplistFromFile(WDWindowMaker->path);
1093 if (dict) {
1094 if (!PLIsDictionary(dict)) {
1095 PLRelease(dict);
1096 dict = NULL;
1097 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1098 "WindowMaker", WDWindowMaker->path);
1099 } else {
1100 if (shared_dict) {
1101 PLSetFilename(shared_dict, PLGetFilename(dict));
1102 PLMergeDictionaries(shared_dict, dict);
1103 PLRelease(dict);
1104 dict = shared_dict;
1105 shared_dict = NULL;
1107 for (i=0; i<wScreenCount; i++) {
1108 scr = wScreenWithNumber(i);
1109 if (scr)
1110 wReadDefaults(scr, dict);
1112 if (WDWindowMaker->dictionary) {
1113 PLRelease(WDWindowMaker->dictionary);
1115 WDWindowMaker->dictionary = dict;
1117 } else {
1118 wwarning(_("could not load domain %s from user defaults database"),
1119 "WindowMaker");
1121 if (shared_dict) {
1122 PLRelease(shared_dict);
1126 if (stat(WDWindowAttributes->path, &stbuf)>=0
1127 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1128 #ifdef HEARTBEAT
1129 puts("Checking WMWindowAttributes domain");
1130 #endif
1131 dict = ReadProplistFromFile(WDWindowAttributes->path);
1132 if (dict) {
1133 if (!PLIsDictionary(dict)) {
1134 PLRelease(dict);
1135 dict = NULL;
1136 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1137 "WMWindowAttributes", WDWindowAttributes->path);
1138 } else {
1139 if (WDWindowAttributes->dictionary)
1140 PLRelease(WDWindowAttributes->dictionary);
1141 WDWindowAttributes->dictionary = dict;
1142 for (i=0; i<wScreenCount; i++) {
1143 scr = wScreenWithNumber(i);
1144 if (scr)
1145 wDefaultUpdateIcons(scr);
1148 } else {
1149 wwarning(_("could not load domain %s from user defaults database"),
1150 "WMWindowAttributes");
1152 WDWindowAttributes->timestamp = stbuf.st_mtime;
1155 #ifndef LITE
1156 if (stat(WDRootMenu->path, &stbuf)>=0
1157 && WDRootMenu->timestamp < stbuf.st_mtime) {
1158 dict = ReadProplistFromFile(WDRootMenu->path);
1159 #ifdef HEARTBEAT
1160 puts("Checking WMRootMenu domain");
1161 #endif
1162 if (dict) {
1163 if (!PLIsArray(dict) && !PLIsString(dict)) {
1164 PLRelease(dict);
1165 dict = NULL;
1166 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1167 "WMRootMenu", WDRootMenu->path);
1168 } else {
1169 if (WDRootMenu->dictionary) {
1170 PLRelease(WDRootMenu->dictionary);
1172 WDRootMenu->dictionary = dict;
1174 } else {
1175 wwarning(_("could not load domain %s from user defaults database"),
1176 "WMRootMenu");
1178 WDRootMenu->timestamp = stbuf.st_mtime;
1180 #endif /* !LITE */
1182 if (!foo)
1183 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1187 void
1188 wReadDefaults(WScreen *scr, proplist_t new_dict)
1190 proplist_t plvalue, old_value;
1191 WDefaultEntry *entry;
1192 int i, must_update;
1193 int update_workspace_back = 0; /* kluge :/ */
1194 int needs_refresh;
1195 void *tdata;
1196 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1197 ? WDWindowMaker->dictionary : NULL);
1199 must_update = 0;
1201 needs_refresh = 0;
1203 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1204 entry = &optionList[i];
1206 if (new_dict)
1207 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1208 else
1209 plvalue = NULL;
1211 if (!old_dict)
1212 old_value = NULL;
1213 else
1214 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1217 if (!plvalue && !old_value) {
1218 /* no default in the DB. Use builtin default */
1219 plvalue = entry->plvalue;
1220 if (plvalue && new_dict) {
1221 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1222 must_update = 1;
1224 } else if (!plvalue) {
1225 /* value was deleted from DB. Keep current value */
1226 continue;
1227 } else if (!old_value) {
1228 /* set value for the 1st time */
1229 } else if (!PLIsEqual(plvalue, old_value)) {
1230 /* value has changed */
1231 } else {
1233 if (strcmp(entry->key, "WorkspaceBack") == 0
1234 && update_workspace_back
1235 && scr->flags.backimage_helper_launched) {
1236 } else {
1237 /* value was not changed since last time */
1238 continue;
1242 if (plvalue) {
1243 #ifdef DEBUG
1244 printf("Updating %s to %s\n", entry->key,
1245 PLGetDescription(plvalue));
1246 #endif
1247 /* convert data */
1248 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1250 * If the WorkspaceSpecificBack data has been changed
1251 * so that the helper will be launched now, we must be
1252 * sure to send the default background texture config
1253 * to the helper.
1255 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1256 && !scr->flags.backimage_helper_launched) {
1257 update_workspace_back = 1;
1259 if (entry->update) {
1260 needs_refresh |=
1261 (*entry->update)(scr, entry, tdata, entry->extra_data);
1267 if (needs_refresh!=0 && !scr->flags.startup) {
1268 int foo;
1270 foo = 0;
1271 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1272 foo |= WTextureSettings;
1273 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1274 foo |= WFontSettings;
1275 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1276 foo |= WColorSettings;
1277 if (foo)
1278 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1279 (void*)foo);
1281 foo = 0;
1282 if (needs_refresh & REFRESH_MENU_TEXTURE)
1283 foo |= WTextureSettings;
1284 if (needs_refresh & REFRESH_MENU_FONT)
1285 foo |= WFontSettings;
1286 if (needs_refresh & REFRESH_MENU_COLOR)
1287 foo |= WColorSettings;
1288 if (foo)
1289 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1290 (void*)foo);
1292 foo = 0;
1293 if (needs_refresh & REFRESH_WINDOW_FONT) {
1294 foo |= WFontSettings;
1296 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1297 foo |= WTextureSettings;
1299 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1300 foo |= WColorSettings;
1302 if (foo)
1303 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1304 (void*)foo);
1306 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1307 foo = 0;
1308 if (needs_refresh & REFRESH_ICON_FONT) {
1309 foo |= WFontSettings;
1311 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1312 foo |= WTextureSettings;
1314 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1315 foo |= WTextureSettings;
1317 if (foo)
1318 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1319 (void*)foo);
1321 if (needs_refresh & REFRESH_ICON_TILE)
1322 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1327 void
1328 wDefaultUpdateIcons(WScreen *scr)
1330 WAppIcon *aicon = scr->app_icon_list;
1331 WWindow *wwin = scr->focused_window;
1332 char *file;
1334 while(aicon) {
1335 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1336 False);
1337 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1338 || (file && !aicon->icon->file)) {
1339 RImage *new_image;
1341 if (aicon->icon->file)
1342 wfree(aicon->icon->file);
1343 aicon->icon->file = wstrdup(file);
1345 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1346 aicon->wm_class);
1347 if (new_image) {
1348 wIconChangeImage(aicon->icon, new_image);
1349 wAppIconPaint(aicon);
1352 aicon = aicon->next;
1355 if (!wPreferences.flags.noclip)
1356 wClipIconPaint(scr->clip_icon);
1358 while (wwin) {
1359 if (wwin->icon && wwin->flags.miniaturized) {
1360 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1361 False);
1362 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1363 || (file && !wwin->icon->file)) {
1364 RImage *new_image;
1366 if (wwin->icon->file)
1367 wfree(wwin->icon->file);
1368 wwin->icon->file = wstrdup(file);
1370 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1371 wwin->wm_class);
1372 if (new_image)
1373 wIconChangeImage(wwin->icon, new_image);
1376 wwin = wwin->prev;
1381 /* --------------------------- Local ----------------------- */
1383 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1384 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1385 entry->key, x); \
1386 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1387 var = entry->default_value;\
1388 } else var = PLGetString(value)\
1394 static int
1395 string2index(proplist_t key, proplist_t val, proplist_t def,
1396 WOptionEnumeration *values)
1398 char *str;
1399 WOptionEnumeration *v;
1400 char buffer[TOTAL_VALUES_LENGTH];
1402 if (PLIsString(val) && (str = PLGetString(val))) {
1403 for (v=values; v->string!=NULL; v++) {
1404 if (strcasecmp(v->string, str)==0)
1405 return v->value;
1409 buffer[0] = 0;
1410 for (v=values; v->string!=NULL; v++) {
1411 if (!v->is_alias) {
1412 if (buffer[0]!=0)
1413 strcat(buffer, ", ");
1414 strcat(buffer, v->string);
1417 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1418 PLGetString(key), buffer);
1420 if (def) {
1421 return string2index(key, val, NULL, values);
1424 return -1;
1431 * value - is the value in the defaults DB
1432 * addr - is the address to store the data
1433 * ret - is the address to store a pointer to a temporary buffer. ret
1434 * must not be freed and is used by the set functions
1436 static int
1437 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1438 void **ret)
1440 static char data;
1441 char *val;
1442 int second_pass=0;
1444 GET_STRING_OR_DEFAULT("Boolean", val);
1446 again:
1447 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1448 || strcasecmp(val, "YES")==0) {
1450 data = 1;
1451 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1452 || strcasecmp(val, "NO")==0) {
1453 data = 0;
1454 } else {
1455 int i;
1456 if (sscanf(val, "%i", &i)==1) {
1457 if (i!=0)
1458 data = 1;
1459 else
1460 data = 0;
1461 } else {
1462 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1463 val, entry->key);
1464 if (second_pass==0) {
1465 val = PLGetString(entry->plvalue);
1466 second_pass = 1;
1467 wwarning(_("using default \"%s\" instead"), val);
1468 goto again;
1470 return False;
1474 if (ret)
1475 *ret = &data;
1477 if (addr) {
1478 *(char*)addr = data;
1481 return True;
1485 static int
1486 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1487 void **ret)
1489 static int data;
1490 char *val;
1493 GET_STRING_OR_DEFAULT("Integer", val);
1495 if (sscanf(val, "%i", &data)!=1) {
1496 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1497 val, entry->key);
1498 val = PLGetString(entry->plvalue);
1499 wwarning(_("using default \"%s\" instead"), val);
1500 if (sscanf(val, "%i", &data)!=1) {
1501 return False;
1505 if (ret)
1506 *ret = &data;
1508 if (addr) {
1509 *(int*)addr = data;
1511 return True;
1515 static int
1516 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1517 void **ret)
1519 static WCoord data;
1520 char *val_x, *val_y;
1521 int nelem, changed=0;
1522 proplist_t elem_x, elem_y;
1524 again:
1525 if (!PLIsArray(value)) {
1526 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1527 entry->key, "Coordinate");
1528 if (changed==0) {
1529 value = entry->plvalue;
1530 changed = 1;
1531 wwarning(_("using default \"%s\" instead"), entry->default_value);
1532 goto again;
1534 return False;
1537 nelem = PLGetNumberOfElements(value);
1538 if (nelem != 2) {
1539 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1540 entry->key);
1541 if (changed==0) {
1542 value = entry->plvalue;
1543 changed = 1;
1544 wwarning(_("using default \"%s\" instead"), entry->default_value);
1545 goto again;
1547 return False;
1550 elem_x = PLGetArrayElement(value, 0);
1551 elem_y = PLGetArrayElement(value, 1);
1553 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1554 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1555 entry->key);
1556 if (changed==0) {
1557 value = entry->plvalue;
1558 changed = 1;
1559 wwarning(_("using default \"%s\" instead"), entry->default_value);
1560 goto again;
1562 return False;
1565 val_x = PLGetString(elem_x);
1566 val_y = PLGetString(elem_y);
1568 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1569 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1570 if (changed==0) {
1571 value = entry->plvalue;
1572 changed = 1;
1573 wwarning(_("using default \"%s\" instead"), entry->default_value);
1574 goto again;
1576 return False;
1579 if (data.x < 0)
1580 data.x = 0;
1581 else if (data.x > scr->scr_width/3)
1582 data.x = scr->scr_width/3;
1583 if (data.y < 0)
1584 data.y = 0;
1585 else if (data.y > scr->scr_height/3)
1586 data.y = scr->scr_height/3;
1588 if (ret)
1589 *ret = &data;
1591 if (addr) {
1592 *(WCoord*)addr = data;
1595 return True;
1599 #if 0
1600 /* This function is not used at the moment. */
1601 static int
1602 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1603 void **ret)
1605 static char *data;
1607 GET_STRING_OR_DEFAULT("String", data);
1609 if (!data) {
1610 data = PLGetString(entry->plvalue);
1611 if (!data)
1612 return False;
1615 if (ret)
1616 *ret = &data;
1618 if (addr)
1619 *(char**)addr = wstrdup(data);
1621 return True;
1623 #endif
1626 static int
1627 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1628 void **ret)
1630 static char *data;
1631 int i, count, len;
1632 char *ptr;
1633 proplist_t d;
1634 int changed=0;
1636 again:
1637 if (!PLIsArray(value)) {
1638 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1639 entry->key, "an array of paths");
1640 if (changed==0) {
1641 value = entry->plvalue;
1642 changed = 1;
1643 wwarning(_("using default \"%s\" instead"), entry->default_value);
1644 goto again;
1646 return False;
1649 i = 0;
1650 count = PLGetNumberOfElements(value);
1651 if (count < 1) {
1652 if (changed==0) {
1653 value = entry->plvalue;
1654 changed = 1;
1655 wwarning(_("using default \"%s\" instead"), entry->default_value);
1656 goto again;
1658 return False;
1661 len = 0;
1662 for (i=0; i<count; i++) {
1663 d = PLGetArrayElement(value, i);
1664 if (!d || !PLIsString(d)) {
1665 count = i;
1666 break;
1668 len += strlen(PLGetString(d))+1;
1671 ptr = data = wmalloc(len+1);
1673 for (i=0; i<count; i++) {
1674 d = PLGetArrayElement(value, i);
1675 if (!d || !PLIsString(d)) {
1676 break;
1678 strcpy(ptr, PLGetString(d));
1679 ptr += strlen(PLGetString(d));
1680 *ptr = ':';
1681 ptr++;
1683 ptr--; *(ptr--) = 0;
1685 if (*(char**)addr!=NULL) {
1686 wfree(*(char**)addr);
1688 *(char**)addr = data;
1690 return True;
1694 static int
1695 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1696 void **ret)
1698 static signed char data;
1700 data = string2index(entry->plkey, value, entry->default_value,
1701 (WOptionEnumeration*)entry->extra_data);
1702 if (data < 0)
1703 return False;
1705 if (ret)
1706 *ret = &data;
1708 if (addr)
1709 *(signed char*)addr = data;
1711 return True;
1717 * (solid <color>)
1718 * (hgradient <color> <color>)
1719 * (vgradient <color> <color>)
1720 * (dgradient <color> <color>)
1721 * (mhgradient <color> <color> ...)
1722 * (mvgradient <color> <color> ...)
1723 * (mdgradient <color> <color> ...)
1724 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1725 * (tpixmap <file> <color>)
1726 * (spixmap <file> <color>)
1727 * (cpixmap <file> <color>)
1728 * (thgradient <file> <opaqueness> <color> <color>)
1729 * (tvgradient <file> <opaqueness> <color> <color>)
1730 * (tdgradient <file> <opaqueness> <color> <color>)
1731 * (function <lib> <function> ...)
1734 static WTexture*
1735 parse_texture(WScreen *scr, proplist_t pl)
1737 proplist_t elem;
1738 char *val;
1739 int nelem;
1740 WTexture *texture=NULL;
1742 nelem = PLGetNumberOfElements(pl);
1743 if (nelem < 1)
1744 return NULL;
1747 elem = PLGetArrayElement(pl, 0);
1748 if (!elem || !PLIsString(elem))
1749 return NULL;
1750 val = PLGetString(elem);
1753 if (strcasecmp(val, "solid")==0) {
1754 XColor color;
1756 if (nelem != 2)
1757 return NULL;
1759 /* get color */
1761 elem = PLGetArrayElement(pl, 1);
1762 if (!elem || !PLIsString(elem))
1763 return NULL;
1764 val = PLGetString(elem);
1766 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1767 wwarning(_("\"%s\" is not a valid color name"), val);
1768 return NULL;
1771 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1772 } else if (strcasecmp(val, "dgradient")==0
1773 || strcasecmp(val, "vgradient")==0
1774 || strcasecmp(val, "hgradient")==0) {
1775 RColor color1, color2;
1776 XColor xcolor;
1777 int type;
1779 if (nelem != 3) {
1780 wwarning(_("bad number of arguments in gradient specification"));
1781 return NULL;
1784 if (val[0]=='d' || val[0]=='D')
1785 type = WTEX_DGRADIENT;
1786 else if (val[0]=='h' || val[0]=='H')
1787 type = WTEX_HGRADIENT;
1788 else
1789 type = WTEX_VGRADIENT;
1792 /* get from color */
1793 elem = PLGetArrayElement(pl, 1);
1794 if (!elem || !PLIsString(elem))
1795 return NULL;
1796 val = PLGetString(elem);
1798 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1799 wwarning(_("\"%s\" is not a valid color name"), val);
1800 return NULL;
1802 color1.alpha = 255;
1803 color1.red = xcolor.red >> 8;
1804 color1.green = xcolor.green >> 8;
1805 color1.blue = xcolor.blue >> 8;
1807 /* get to color */
1808 elem = PLGetArrayElement(pl, 2);
1809 if (!elem || !PLIsString(elem)) {
1810 return NULL;
1812 val = PLGetString(elem);
1814 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1815 wwarning(_("\"%s\" is not a valid color name"), val);
1816 return NULL;
1818 color2.alpha = 255;
1819 color2.red = xcolor.red >> 8;
1820 color2.green = xcolor.green >> 8;
1821 color2.blue = xcolor.blue >> 8;
1823 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1825 } else if (strcasecmp(val, "igradient")==0) {
1826 RColor colors1[2], colors2[2];
1827 int th1, th2;
1828 XColor xcolor;
1829 int i;
1831 if (nelem != 7) {
1832 wwarning(_("bad number of arguments in gradient specification"));
1833 return NULL;
1836 /* get from color */
1837 for (i = 0; i < 2; i++) {
1838 elem = PLGetArrayElement(pl, 1+i);
1839 if (!elem || !PLIsString(elem))
1840 return NULL;
1841 val = PLGetString(elem);
1843 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1844 wwarning(_("\"%s\" is not a valid color name"), val);
1845 return NULL;
1847 colors1[i].alpha = 255;
1848 colors1[i].red = xcolor.red >> 8;
1849 colors1[i].green = xcolor.green >> 8;
1850 colors1[i].blue = xcolor.blue >> 8;
1852 elem = PLGetArrayElement(pl, 3);
1853 if (!elem || !PLIsString(elem))
1854 return NULL;
1855 val = PLGetString(elem);
1856 th1 = atoi(val);
1859 /* get from color */
1860 for (i = 0; i < 2; i++) {
1861 elem = PLGetArrayElement(pl, 4+i);
1862 if (!elem || !PLIsString(elem))
1863 return NULL;
1864 val = PLGetString(elem);
1866 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1867 wwarning(_("\"%s\" is not a valid color name"), val);
1868 return NULL;
1870 colors2[i].alpha = 255;
1871 colors2[i].red = xcolor.red >> 8;
1872 colors2[i].green = xcolor.green >> 8;
1873 colors2[i].blue = xcolor.blue >> 8;
1875 elem = PLGetArrayElement(pl, 6);
1876 if (!elem || !PLIsString(elem))
1877 return NULL;
1878 val = PLGetString(elem);
1879 th2 = atoi(val);
1881 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1882 th2, colors2);
1884 } else if (strcasecmp(val, "mhgradient")==0
1885 || strcasecmp(val, "mvgradient")==0
1886 || strcasecmp(val, "mdgradient")==0) {
1887 XColor color;
1888 RColor **colors;
1889 int i, count;
1890 int type;
1892 if (nelem < 3) {
1893 wwarning(_("too few arguments in multicolor gradient specification"));
1894 return NULL;
1897 if (val[1]=='h' || val[1]=='H')
1898 type = WTEX_MHGRADIENT;
1899 else if (val[1]=='v' || val[1]=='V')
1900 type = WTEX_MVGRADIENT;
1901 else
1902 type = WTEX_MDGRADIENT;
1904 count = nelem-1;
1906 colors = wmalloc(sizeof(RColor*)*(count+1));
1908 for (i=0; i<count; i++) {
1909 elem = PLGetArrayElement(pl, i+1);
1910 if (!elem || !PLIsString(elem)) {
1911 for (--i; i>=0; --i) {
1912 wfree(colors[i]);
1914 wfree(colors);
1915 return NULL;
1917 val = PLGetString(elem);
1919 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1920 wwarning(_("\"%s\" is not a valid color name"), val);
1921 for (--i; i>=0; --i) {
1922 wfree(colors[i]);
1924 wfree(colors);
1925 return NULL;
1926 } else {
1927 colors[i] = wmalloc(sizeof(RColor));
1928 colors[i]->red = color.red >> 8;
1929 colors[i]->green = color.green >> 8;
1930 colors[i]->blue = color.blue >> 8;
1933 colors[i] = NULL;
1935 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1936 } else if (strcasecmp(val, "spixmap")==0 ||
1937 strcasecmp(val, "cpixmap")==0 ||
1938 strcasecmp(val, "tpixmap")==0) {
1939 XColor color;
1940 int type;
1942 if (nelem != 3)
1943 return NULL;
1945 if (val[0] == 's' || val[0] == 'S')
1946 type = WTP_SCALE;
1947 else if (val[0] == 'c' || val[0] == 'C')
1948 type = WTP_CENTER;
1949 else
1950 type = WTP_TILE;
1952 /* get color */
1953 elem = PLGetArrayElement(pl, 2);
1954 if (!elem || !PLIsString(elem)) {
1955 return NULL;
1957 val = PLGetString(elem);
1959 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1960 wwarning(_("\"%s\" is not a valid color name"), val);
1961 return NULL;
1964 /* file name */
1965 elem = PLGetArrayElement(pl, 1);
1966 if (!elem || !PLIsString(elem))
1967 return NULL;
1968 val = PLGetString(elem);
1970 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1971 } else if (strcasecmp(val, "thgradient")==0
1972 || strcasecmp(val, "tvgradient")==0
1973 || strcasecmp(val, "tdgradient")==0) {
1974 RColor color1, color2;
1975 XColor xcolor;
1976 int opacity;
1977 int style;
1979 if (val[1]=='h' || val[1]=='H')
1980 style = WTEX_THGRADIENT;
1981 else if (val[1]=='v' || val[1]=='V')
1982 style = WTEX_TVGRADIENT;
1983 else
1984 style = WTEX_TDGRADIENT;
1986 if (nelem != 5) {
1987 wwarning(_("bad number of arguments in textured gradient specification"));
1988 return NULL;
1991 /* get from color */
1992 elem = PLGetArrayElement(pl, 3);
1993 if (!elem || !PLIsString(elem))
1994 return NULL;
1995 val = PLGetString(elem);
1997 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1998 wwarning(_("\"%s\" is not a valid color name"), val);
1999 return NULL;
2001 color1.alpha = 255;
2002 color1.red = xcolor.red >> 8;
2003 color1.green = xcolor.green >> 8;
2004 color1.blue = xcolor.blue >> 8;
2006 /* get to color */
2007 elem = PLGetArrayElement(pl, 4);
2008 if (!elem || !PLIsString(elem)) {
2009 return NULL;
2011 val = PLGetString(elem);
2013 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2014 wwarning(_("\"%s\" is not a valid color name"), val);
2015 return NULL;
2017 color2.alpha = 255;
2018 color2.red = xcolor.red >> 8;
2019 color2.green = xcolor.green >> 8;
2020 color2.blue = xcolor.blue >> 8;
2022 /* get opacity */
2023 elem = PLGetArrayElement(pl, 2);
2024 if (!elem || !PLIsString(elem))
2025 opacity = 128;
2026 else
2027 val = PLGetString(elem);
2029 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2030 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2031 opacity = 128;
2034 /* get file name */
2035 elem = PLGetArrayElement(pl, 1);
2036 if (!elem || !PLIsString(elem))
2037 return NULL;
2038 val = PLGetString(elem);
2040 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2041 val, opacity);
2043 #ifdef TEXTURE_PLUGIN
2044 else if (strcasecmp(val, "function")==0) {
2045 WTexFunction *function;
2046 void (*initFunc) (Display *, Colormap);
2047 char *lib, *func, **argv;
2048 int i, argc;
2050 if (nelem < 3)
2051 return NULL;
2053 /* get the library name */
2054 elem = PLGetArrayElement(pl, 1);
2055 if (!elem || !PLIsString(elem)) {
2056 return NULL;
2058 lib = PLGetString(elem);
2060 /* get the function name */
2061 elem = PLGetArrayElement(pl, 2);
2062 if (!elem || !PLIsString(elem)) {
2063 return NULL;
2065 func = PLGetString(elem);
2067 argc = nelem - 2;
2068 argv = (char **)wmalloc(argc * sizeof(char *));
2070 /* get the parameters */
2071 argv[0] = wstrdup(func);
2072 for (i = 0; i < argc - 1; i++) {
2073 elem = PLGetArrayElement(pl, 3 + i);
2074 if (!elem || !PLIsString(elem)) {
2075 wfree(argv);
2077 return NULL;
2079 argv[i+1] = wstrdup(PLGetString(elem));
2082 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2084 #ifdef HAVE_DLFCN_H
2085 if (function) {
2086 initFunc = dlsym(function->handle, "initWindowMaker");
2087 if (initFunc) {
2088 initFunc(dpy, scr->w_colormap);
2089 } else {
2090 wwarning(_("could not initialize library %s"), lib);
2092 } else {
2093 wwarning(_("could not find function %s::%s"), lib, func);
2095 #endif /* HAVE_DLFCN_H */
2096 texture = (WTexture*)function;
2098 #endif /* TEXTURE_PLUGIN */
2099 else {
2100 wwarning(_("invalid texture type %s"), val);
2101 return NULL;
2103 return texture;
2108 static int
2109 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2110 void **ret)
2112 static WTexture *texture;
2113 int changed=0;
2115 again:
2116 if (!PLIsArray(value)) {
2117 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2118 entry->key, "Texture");
2119 if (changed==0) {
2120 value = entry->plvalue;
2121 changed = 1;
2122 wwarning(_("using default \"%s\" instead"), entry->default_value);
2123 goto again;
2125 return False;
2128 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2129 proplist_t pl;
2131 pl = PLGetArrayElement(value, 0);
2132 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2133 || strcasecmp(PLGetString(pl), "solid")!=0) {
2134 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2135 entry->key, "Solid Texture");
2137 value = entry->plvalue;
2138 changed = 1;
2139 wwarning(_("using default \"%s\" instead"), entry->default_value);
2140 goto again;
2144 texture = parse_texture(scr, value);
2146 if (!texture) {
2147 wwarning(_("Error in texture specification for key \"%s\""),
2148 entry->key);
2149 if (changed==0) {
2150 value = entry->plvalue;
2151 changed = 1;
2152 wwarning(_("using default \"%s\" instead"), entry->default_value);
2153 goto again;
2155 return False;
2158 if (ret)
2159 *ret = &texture;
2161 if (addr)
2162 *(WTexture**)addr = texture;
2164 return True;
2169 #ifdef DRAWSTRING_PLUGIN
2170 static int
2171 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2172 void *addr, void **ret)
2174 proplist_t elem;
2175 char *val, *lib, *func, **argv;
2176 int argc, changed;
2178 if (strcmp(entry->key, "FTitleColor")==0) {
2179 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2180 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2181 } else if (strcmp(entry->key, "UTitleColor")==0) {
2182 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2183 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2184 } else if (strcmp(entry->key, "PTitleColor")==0) {
2185 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2186 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2187 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2188 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2189 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2190 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2191 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2192 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2195 if (PLIsArray(value)) {
2196 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2197 argc -= 2;
2198 argv = (char **)wmalloc(argc * sizeof(char *));
2200 elem = PLGetArrayElement(value,0);
2201 if (!elem || !PLIsString(elem)) return False;
2202 val = PLGetString(elem);
2203 if (strcasecmp(val, "function")==0) {
2204 elem = PLGetArrayElement(value, 1); /* library name */
2205 if (!elem || !PLIsString(elem)) return False;
2206 lib = PLGetString(elem);
2207 elem = PLGetArrayElement(value, 2); /* function name */
2208 if (!elem || !PLIsString(elem)) return False;
2209 func = PLGetString(elem);
2210 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2211 lib, "initDrawString", func, NULL, value,
2212 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2215 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2216 } else if (PLIsString(value)) {
2217 return getColor(scr, entry, value, addr, ret);
2220 return False;
2222 #endif /* DRAWSTRING_PLUGIN */
2226 static int
2227 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2228 void *addr, void **ret)
2230 proplist_t elem;
2231 int changed = 0;
2232 char *val;
2233 int nelem;
2235 again:
2236 if (!PLIsArray(value)) {
2237 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2238 "WorkspaceBack", "Texture or None");
2239 if (changed==0) {
2240 value = entry->plvalue;
2241 changed = 1;
2242 wwarning(_("using default \"%s\" instead"), entry->default_value);
2243 goto again;
2245 return False;
2248 /* only do basic error checking and verify for None texture */
2250 nelem = PLGetNumberOfElements(value);
2251 if (nelem > 0) {
2252 elem = PLGetArrayElement(value, 0);
2253 if (!elem || !PLIsString(elem)) {
2254 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2255 if (changed==0) {
2256 value = entry->plvalue;
2257 changed = 1;
2258 wwarning(_("using default \"%s\" instead"), entry->default_value);
2259 goto again;
2261 return False;
2263 val = PLGetString(elem);
2265 if (strcasecmp(val, "None")==0)
2266 return True;
2268 *ret = PLRetain(value);
2270 return True;
2274 static int
2275 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2276 void *addr, void **ret)
2278 proplist_t elem;
2279 int nelem;
2280 int changed = 0;
2282 again:
2283 if (!PLIsArray(value)) {
2284 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2285 "WorkspaceSpecificBack", "an array of textures");
2286 if (changed==0) {
2287 value = entry->plvalue;
2288 changed = 1;
2289 wwarning(_("using default \"%s\" instead"), entry->default_value);
2290 goto again;
2292 return False;
2295 /* only do basic error checking and verify for None texture */
2297 nelem = PLGetNumberOfElements(value);
2298 if (nelem > 0) {
2299 while (nelem--) {
2300 elem = PLGetArrayElement(value, nelem);
2301 if (!elem || !PLIsArray(elem)) {
2302 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2303 nelem);
2308 *ret = PLRetain(value);
2310 #ifdef notworking
2312 * Kluge to force wmsetbg helper to set the default background.
2313 * If the WorkspaceSpecificBack is changed once wmaker has started,
2314 * the WorkspaceBack won't be sent to the helper, unless the user
2315 * changes it's value too. So, we must force this by removing the
2316 * value from the defaults DB.
2318 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2319 proplist_t key = PLMakeString("WorkspaceBack");
2321 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2323 PLRelease(key);
2325 #endif
2326 return True;
2330 static int
2331 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2332 void **ret)
2334 static WMFont *font;
2335 char *val;
2337 GET_STRING_OR_DEFAULT("Font", val);
2339 font = WMCreateFont(scr->wmscreen, val);
2340 if (!font)
2341 font = WMCreateFont(scr->wmscreen, "fixed");
2343 if (!font) {
2344 wfatal(_("could not load any usable font!!!"));
2345 exit(1);
2348 if (ret)
2349 *ret = font;
2351 /* can't assign font value outside update function */
2352 wassertrv(addr == NULL, True);
2354 return True;
2358 static int
2359 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2360 void **ret)
2362 static XColor color;
2363 char *val;
2364 int second_pass=0;
2366 GET_STRING_OR_DEFAULT("Color", val);
2369 again:
2370 if (!wGetColor(scr, val, &color)) {
2371 wwarning(_("could not get color for key \"%s\""),
2372 entry->key);
2373 if (second_pass==0) {
2374 val = PLGetString(entry->plvalue);
2375 second_pass = 1;
2376 wwarning(_("using default \"%s\" instead"), val);
2377 goto again;
2379 return False;
2382 if (ret)
2383 *ret = &color;
2385 assert(addr==NULL);
2387 if (addr)
2388 *(unsigned long*)addr = pixel;
2391 return True;
2396 static int
2397 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2398 void **ret)
2400 static WShortKey shortcut;
2401 KeySym ksym;
2402 char *val;
2403 char *k;
2404 char buf[128], *b;
2407 GET_STRING_OR_DEFAULT("Key spec", val);
2409 if (!val || strcasecmp(val, "NONE")==0) {
2410 shortcut.keycode = 0;
2411 shortcut.modifier = 0;
2412 if (ret)
2413 *ret = &shortcut;
2414 return True;
2417 strcpy(buf, val);
2419 b = (char*)buf;
2421 /* get modifiers */
2422 shortcut.modifier = 0;
2423 while ((k = strchr(b, '+'))!=NULL) {
2424 int mod;
2426 *k = 0;
2427 mod = wXModifierFromKey(b);
2428 if (mod<0) {
2429 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2430 return False;
2432 shortcut.modifier |= mod;
2434 b = k+1;
2437 /* get key */
2438 ksym = XStringToKeysym(b);
2440 if (ksym==NoSymbol) {
2441 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2442 val);
2443 return False;
2446 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2447 if (shortcut.keycode==0) {
2448 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2449 return False;
2452 if (ret)
2453 *ret = &shortcut;
2455 return True;
2459 static int
2460 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2461 void **ret)
2463 static unsigned int mask;
2464 char *str;
2466 GET_STRING_OR_DEFAULT("Modifier Key", str);
2468 if (!str)
2469 return False;
2471 mask = wXModifierFromKey(str);
2472 if (mask < 0) {
2473 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2474 mask = 0;
2475 return False;
2478 if (addr)
2479 *(unsigned int*)addr = mask;
2481 if (ret)
2482 *ret = &mask;
2484 return True;
2488 #ifdef NEWSTUFF
2489 static int
2490 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2491 void *addr, void **ret)
2493 unsigned int mask;
2494 char *str;
2495 RImage *image;
2496 int i, n;
2497 int w, h;
2499 GET_STRING_OR_DEFAULT("Image File Path", str);
2500 if (!str)
2501 return False;
2503 image = RLoadImage(scr->rcontext, str, 0);
2504 if (!image) {
2505 wwarning(_("could not load image in option %s: %s"), entry->key,
2506 RMessageForError(RErrorCode));
2507 return False;
2510 if (*(RImage**)addr) {
2511 RDestroyImage(*(RImage**)addr);
2513 if (addr)
2514 *(RImage**)addr = image;
2516 assert(ret == NULL);
2518 if (ret)
2519 *(RImage**)ret = image;
2522 return True;
2524 #endif
2526 #ifdef DEFINABLE_CURSOR
2528 # include <X11/cursorfont.h>
2529 typedef struct
2531 char *name;
2532 int id;
2533 } WCursorLookup;
2535 #define CURSOR_ID_NONE (XC_num_glyphs)
2537 static WCursorLookup cursor_table[] =
2539 { "X_cursor", XC_X_cursor },
2540 { "arrow", XC_arrow },
2541 { "based_arrow_down", XC_based_arrow_down },
2542 { "based_arrow_up", XC_based_arrow_up },
2543 { "boat", XC_boat },
2544 { "bogosity", XC_bogosity },
2545 { "bottom_left_corner", XC_bottom_left_corner },
2546 { "bottom_right_corner", XC_bottom_right_corner },
2547 { "bottom_side", XC_bottom_side },
2548 { "bottom_tee", XC_bottom_tee },
2549 { "box_spiral", XC_box_spiral },
2550 { "center_ptr", XC_center_ptr },
2551 { "circle", XC_circle },
2552 { "clock", XC_clock },
2553 { "coffee_mug", XC_coffee_mug },
2554 { "cross", XC_cross },
2555 { "cross_reverse", XC_cross_reverse },
2556 { "crosshair", XC_crosshair },
2557 { "diamond_cross", XC_diamond_cross },
2558 { "dot", XC_dot },
2559 { "dotbox", XC_dotbox },
2560 { "double_arrow", XC_double_arrow },
2561 { "draft_large", XC_draft_large },
2562 { "draft_small", XC_draft_small },
2563 { "draped_box", XC_draped_box },
2564 { "exchange", XC_exchange },
2565 { "fleur", XC_fleur },
2566 { "gobbler", XC_gobbler },
2567 { "gumby", XC_gumby },
2568 { "hand1", XC_hand1 },
2569 { "hand2", XC_hand2 },
2570 { "heart", XC_heart },
2571 { "icon", XC_icon },
2572 { "iron_cross", XC_iron_cross },
2573 { "left_ptr", XC_left_ptr },
2574 { "left_side", XC_left_side },
2575 { "left_tee", XC_left_tee },
2576 { "leftbutton", XC_leftbutton },
2577 { "ll_angle", XC_ll_angle },
2578 { "lr_angle", XC_lr_angle },
2579 { "man", XC_man },
2580 { "middlebutton", XC_middlebutton },
2581 { "mouse", XC_mouse },
2582 { "pencil", XC_pencil },
2583 { "pirate", XC_pirate },
2584 { "plus", XC_plus },
2585 { "question_arrow", XC_question_arrow },
2586 { "right_ptr", XC_right_ptr },
2587 { "right_side", XC_right_side },
2588 { "right_tee", XC_right_tee },
2589 { "rightbutton", XC_rightbutton },
2590 { "rtl_logo", XC_rtl_logo },
2591 { "sailboat", XC_sailboat },
2592 { "sb_down_arrow", XC_sb_down_arrow },
2593 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2594 { "sb_left_arrow", XC_sb_left_arrow },
2595 { "sb_right_arrow", XC_sb_right_arrow },
2596 { "sb_up_arrow", XC_sb_up_arrow },
2597 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2598 { "shuttle", XC_shuttle },
2599 { "sizing", XC_sizing },
2600 { "spider", XC_spider },
2601 { "spraycan", XC_spraycan },
2602 { "star", XC_star },
2603 { "target", XC_target },
2604 { "tcross", XC_tcross },
2605 { "top_left_arrow", XC_top_left_arrow },
2606 { "top_left_corner", XC_top_left_corner },
2607 { "top_right_corner", XC_top_right_corner },
2608 { "top_side", XC_top_side },
2609 { "top_tee", XC_top_tee },
2610 { "trek", XC_trek },
2611 { "ul_angle", XC_ul_angle },
2612 { "umbrella", XC_umbrella },
2613 { "ur_angle", XC_ur_angle },
2614 { "watch", XC_watch },
2615 { "xterm", XC_xterm },
2616 { NULL, CURSOR_ID_NONE }
2619 static void
2620 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2622 switch(status) {
2623 case BitmapOpenFailed:
2624 wwarning(_("failed to open bitmap file \"%s\""), filename);
2625 break;
2626 case BitmapFileInvalid:
2627 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2628 break;
2629 case BitmapNoMemory:
2630 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2631 break;
2632 case BitmapSuccess:
2633 XFreePixmap(dpy, bitmap);
2634 break;
2639 * (none)
2640 * (builtin, <cursor_name>)
2641 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2643 static int
2644 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2646 proplist_t elem;
2647 char *val;
2648 int nelem;
2649 int status = 0;
2651 nelem = PLGetNumberOfElements(pl);
2652 if (nelem < 1) {
2653 return(status);
2655 elem = PLGetArrayElement(pl, 0);
2656 if (!elem || !PLIsString(elem)) {
2657 return(status);
2659 val = PLGetString(elem);
2661 if (0 == strcasecmp(val, "none")) {
2662 status = 1;
2663 *cursor = None;
2664 } else if (0 == strcasecmp(val, "builtin")) {
2665 int i;
2666 int cursor_id = CURSOR_ID_NONE;
2668 if (2 != nelem) {
2669 wwarning(_("bad number of arguments in cursor specification"));
2670 return(status);
2672 elem = PLGetArrayElement(pl, 1);
2673 if (!elem || !PLIsString(elem)) {
2674 return(status);
2676 val = PLGetString(elem);
2678 for (i = 0; NULL != cursor_table[i].name; i++) {
2679 if (0 == strcasecmp(val, cursor_table[i].name)) {
2680 cursor_id = cursor_table[i].id;
2681 break;
2684 if (CURSOR_ID_NONE == cursor_id) {
2685 wwarning(_("unknown builtin cursor name \"%s\""), val);
2686 } else {
2687 *cursor = XCreateFontCursor(dpy, cursor_id);
2688 status = 1;
2690 } else if (0 == strcasecmp(val, "bitmap")) {
2691 char *bitmap_name;
2692 char *mask_name;
2693 int bitmap_status;
2694 int mask_status;
2695 Pixmap bitmap;
2696 Pixmap mask;
2697 unsigned int w, h;
2698 int x, y;
2699 XColor fg, bg;
2701 if (3 != nelem) {
2702 wwarning(_("bad number of arguments in cursor specification"));
2703 return(status);
2705 elem = PLGetArrayElement(pl, 1);
2706 if (!elem || !PLIsString(elem)) {
2707 return(status);
2709 val = PLGetString(elem);
2710 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2711 if (!bitmap_name) {
2712 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2713 return(status);
2715 elem = PLGetArrayElement(pl, 2);
2716 if (!elem || !PLIsString(elem)) {
2717 wfree(bitmap_name);
2718 return(status);
2720 val = PLGetString(elem);
2721 mask_name = FindImage(wPreferences.pixmap_path, val);
2722 if (!mask_name) {
2723 wfree(bitmap_name);
2724 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2725 return(status);
2727 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2728 &mask, &x, &y);
2729 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2730 &bitmap, &x, &y);
2731 if ((BitmapSuccess == bitmap_status) &&
2732 (BitmapSuccess == mask_status)) {
2733 fg.pixel = scr->black_pixel;
2734 bg.pixel = scr->white_pixel;
2735 XQueryColor(dpy, scr->w_colormap, &fg);
2736 XQueryColor(dpy, scr->w_colormap, &bg);
2737 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2738 status = 1;
2740 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2741 check_bitmap_status(mask_status, mask_name, mask);
2742 wfree(bitmap_name);
2743 wfree(mask_name);
2745 return(status);
2749 static int
2750 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2751 void **ret)
2753 static Cursor cursor;
2754 int status;
2755 int changed = 0;
2757 again:
2758 if (!PLIsArray(value)) {
2759 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2760 entry->key, "cursor specification");
2761 if (!changed) {
2762 value = entry->plvalue;
2763 changed = 1;
2764 wwarning(_("using default \"%s\" instead"), entry->default_value);
2765 goto again;
2767 return(False);
2769 status = parse_cursor(scr, value, &cursor);
2770 if (!status) {
2771 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2772 if (!changed) {
2773 value = entry->plvalue;
2774 changed = 1;
2775 wwarning(_("using default \"%s\" instead"), entry->default_value);
2776 goto again;
2778 return(False);
2780 if (ret) {
2781 *ret = &cursor;
2783 if (addr) {
2784 *(Cursor *)addr = cursor;
2786 return(True);
2788 #undef CURSOR_ID_NONE
2790 #endif /* DEFINABLE_CURSOR */
2793 /* ---------------- value setting functions --------------- */
2794 static int
2795 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2797 return REFRESH_WINDOW_TITLE_COLOR;
2800 static int
2801 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2803 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2806 static int
2807 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2809 switch (which) {
2810 case WM_DOCK:
2811 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2812 break;
2813 case WM_CLIP:
2814 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2815 break;
2816 default:
2817 break;
2819 return 0;
2823 static int
2824 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2826 if (scr->workspaces) {
2827 wWorkspaceForceChange(scr, scr->current_workspace);
2828 wArrangeIcons(scr, False);
2830 return 0;
2833 #if not_used
2834 static int
2835 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2837 if (*value <= 0)
2838 *(int*)foo = 1;
2840 return 0;
2842 #endif
2846 static int
2847 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2849 Pixmap pixmap;
2850 RImage *img;
2851 int reset = 0;
2853 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2854 wPreferences.icon_size,
2855 ((*texture)->any.type & WREL_BORDER_MASK)
2856 ? WREL_ICON : WREL_FLAT);
2857 if (!img) {
2858 wwarning(_("could not render texture for icon background"));
2859 if (!entry->addr)
2860 wTextureDestroy(scr, *texture);
2861 return 0;
2863 RConvertImage(scr->rcontext, img, &pixmap);
2865 if (scr->icon_tile) {
2866 reset = 1;
2867 RDestroyImage(scr->icon_tile);
2868 XFreePixmap(dpy, scr->icon_tile_pixmap);
2871 scr->icon_tile = img;
2874 /* put the icon in the noticeboard hint */
2875 PropSetIconTileHint(scr, img);
2878 if (!wPreferences.flags.noclip) {
2879 if (scr->clip_tile) {
2880 RDestroyImage(scr->clip_tile);
2882 scr->clip_tile = wClipMakeTile(scr, img);
2885 scr->icon_tile_pixmap = pixmap;
2887 if (scr->def_icon_pixmap) {
2888 XFreePixmap(dpy, scr->def_icon_pixmap);
2889 scr->def_icon_pixmap = None;
2891 if (scr->def_ticon_pixmap) {
2892 XFreePixmap(dpy, scr->def_ticon_pixmap);
2893 scr->def_ticon_pixmap = None;
2896 if (scr->icon_back_texture) {
2897 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2899 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2901 if (scr->clip_balloon)
2902 XSetWindowBackground(dpy, scr->clip_balloon,
2903 (*texture)->any.color.pixel);
2906 * Free the texture as nobody else will use it, nor refer to it.
2908 if (!entry->addr)
2909 wTextureDestroy(scr, *texture);
2911 return (reset ? REFRESH_ICON_TILE : 0);
2916 static int
2917 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2919 if (scr->title_font) {
2920 WMReleaseFont(scr->title_font);
2922 scr->title_font = font;
2924 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2928 static int
2929 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2931 if (scr->menu_title_font) {
2932 WMReleaseFont(scr->menu_title_font);
2935 scr->menu_title_font = font;
2937 return REFRESH_MENU_TITLE_FONT;
2941 static int
2942 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2944 if (scr->menu_entry_font) {
2945 WMReleaseFont(scr->menu_entry_font);
2947 scr->menu_entry_font = font;
2949 return REFRESH_MENU_FONT;
2954 static int
2955 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2957 if (scr->icon_title_font) {
2958 WMReleaseFont(scr->icon_title_font);
2961 scr->icon_title_font = font;
2963 return REFRESH_ICON_FONT;
2967 static int
2968 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2970 if (scr->clip_title_font) {
2971 WMReleaseFont(scr->clip_title_font);
2974 scr->clip_title_font = font;
2976 return REFRESH_ICON_FONT;
2980 static int
2981 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2983 if (scr->workspace_name_font) {
2984 WMReleaseFont(scr->workspace_name_font);
2987 scr->workspace_name_font = font;
2989 return 0;
2993 static int
2994 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2996 if (scr->select_pixel!=scr->white_pixel &&
2997 scr->select_pixel!=scr->black_pixel) {
2998 wFreeColor(scr, scr->select_pixel);
3001 scr->select_pixel = color->pixel;
3003 return REFRESH_MENU_COLOR;
3007 static int
3008 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3010 if (scr->select_text_pixel!=scr->white_pixel &&
3011 scr->select_text_pixel!=scr->black_pixel) {
3012 wFreeColor(scr, scr->select_text_pixel);
3015 scr->select_text_pixel = color->pixel;
3017 return REFRESH_MENU_COLOR;
3021 static int
3022 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3024 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
3025 scr->clip_title_pixel[index]!=scr->black_pixel) {
3026 wFreeColor(scr, scr->clip_title_pixel[index]);
3028 scr->clip_title_pixel[index] = color->pixel;
3030 #ifdef GRADIENT_CLIP_ARROW
3031 if (index == CLIP_NORMAL) {
3032 RImage *image;
3033 RColor color1, color2;
3034 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3035 int as = pt - 15; /* 15 = 5+5+5 */
3037 FREE_PIXMAP(scr->clip_arrow_gradient);
3039 color1.red = (color->red >> 8)*6/10;
3040 color1.green = (color->green >> 8)*6/10;
3041 color1.blue = (color->blue >> 8)*6/10;
3043 color2.red = WMIN((color->red >> 8)*20/10, 255);
3044 color2.green = WMIN((color->green >> 8)*20/10, 255);
3045 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3047 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3048 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3049 RDestroyImage(image);
3051 #endif /* GRADIENT_CLIP_ARROW */
3053 return REFRESH_ICON_TITLE_COLOR;
3057 static int
3058 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3060 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3061 scr->window_title_pixel[index]!=scr->black_pixel) {
3062 wFreeColor(scr, scr->window_title_pixel[index]);
3065 scr->window_title_pixel[index] = color->pixel;
3067 if (index == WS_UNFOCUSED)
3068 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3070 return REFRESH_WINDOW_TITLE_COLOR;
3074 static int
3075 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3077 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3078 scr->menu_title_pixel[0]!=scr->black_pixel) {
3079 #ifdef DRAWSTRING_PLUGIN
3080 if(!scr->drawstring_func[W_STRING_MTITLE])
3081 #endif
3082 wFreeColor(scr, scr->menu_title_pixel[0]);
3085 scr->menu_title_pixel[0] = color->pixel;
3086 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3088 return REFRESH_MENU_TITLE_COLOR;
3092 static int
3093 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3095 XGCValues gcv;
3096 #define gcm (GCForeground|GCBackground|GCFillStyle)
3098 if (scr->mtext_pixel!=scr->white_pixel &&
3099 scr->mtext_pixel!=scr->black_pixel) {
3100 wFreeColor(scr, scr->mtext_pixel);
3103 scr->mtext_pixel = color->pixel;
3105 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3108 if (scr->dtext_pixel == scr->mtext_pixel) {
3109 gcv.foreground = scr->white_pixel;
3110 gcv.background = scr->black_pixel;
3111 gcv.fill_style = FillStippled;
3112 } else {
3113 gcv.foreground = scr->dtext_pixel;
3114 gcv.fill_style = FillSolid;
3116 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3118 return REFRESH_MENU_COLOR;
3119 #undef gcm
3123 static int
3124 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3126 XGCValues gcv;
3127 #define gcm (GCForeground|GCBackground|GCFillStyle)
3129 if (scr->dtext_pixel!=scr->white_pixel &&
3130 scr->dtext_pixel!=scr->black_pixel) {
3131 wFreeColor(scr, scr->dtext_pixel);
3134 scr->dtext_pixel = color->pixel;
3136 if (scr->dtext_pixel == scr->mtext_pixel) {
3137 gcv.foreground = scr->white_pixel;
3138 gcv.background = scr->black_pixel;
3139 gcv.fill_style = FillStippled;
3140 } else {
3141 gcv.foreground = scr->dtext_pixel;
3142 gcv.fill_style = FillSolid;
3144 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3146 return REFRESH_MENU_COLOR;
3147 #undef gcm
3150 static int
3151 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3153 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3155 return REFRESH_ICON_TITLE_COLOR;
3159 static int
3160 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3162 if (scr->icon_title_texture) {
3163 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3165 XQueryColor (dpy, scr->w_colormap, color);
3166 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3168 return REFRESH_ICON_TITLE_BACK;
3172 static void
3173 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3175 close(scr->helper_fd);
3176 scr->helper_fd = 0;
3177 scr->helper_pid = 0;
3178 scr->flags.backimage_helper_launched = 0;
3182 static int
3183 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3184 void *bar)
3186 int i;
3187 proplist_t val;
3188 char *str;
3190 if (scr->flags.backimage_helper_launched) {
3191 if (PLGetNumberOfElements(value)==0) {
3192 SendHelperMessage(scr, 'C', 0, NULL);
3193 SendHelperMessage(scr, 'K', 0, NULL);
3195 PLRelease(value);
3196 return 0;
3198 } else {
3199 pid_t pid;
3200 int filedes[2];
3202 if (PLGetNumberOfElements(value) == 0)
3203 return 0;
3205 if (pipe(filedes) < 0) {
3206 wsyserror("pipe() failed:can't set workspace specific background image");
3208 PLRelease(value);
3209 return 0;
3212 pid = fork();
3213 if (pid < 0) {
3214 wsyserror("fork() failed:can't set workspace specific background image");
3215 if (close(filedes[0]) < 0)
3216 wsyserror("could not close pipe");
3217 if (close(filedes[1]) < 0)
3218 wsyserror("could not close pipe");
3220 } else if (pid == 0) {
3221 SetupEnvironment(scr);
3223 if (close(0) < 0)
3224 wsyserror("could not close pipe");
3225 if (dup(filedes[0]) < 0) {
3226 wsyserror("dup() failed:can't set workspace specific background image");
3228 if (wPreferences.smooth_workspace_back)
3229 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
3230 else
3231 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
3232 wsyserror("could not execute wmsetbg");
3233 exit(1);
3234 } else {
3236 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3237 wsyserror("error setting close-on-exec flag");
3239 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3240 wsyserror("error setting close-on-exec flag");
3243 scr->helper_fd = filedes[1];
3244 scr->helper_pid = pid;
3245 scr->flags.backimage_helper_launched = 1;
3247 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3249 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3254 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3255 val = PLGetArrayElement(value, i);
3256 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3257 str = PLGetDescription(val);
3259 SendHelperMessage(scr, 'S', i+1, str);
3261 wfree(str);
3262 } else {
3263 SendHelperMessage(scr, 'U', i+1, NULL);
3266 sleep(1);
3268 PLRelease(value);
3269 return 0;
3273 static int
3274 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3275 void *bar)
3277 if (scr->flags.backimage_helper_launched) {
3278 char *str;
3280 if (PLGetNumberOfElements(value)==0) {
3281 SendHelperMessage(scr, 'U', 0, NULL);
3282 } else {
3283 /* set the default workspace background to this one */
3284 str = PLGetDescription(value);
3285 if (str) {
3286 SendHelperMessage(scr, 'S', 0, str);
3287 wfree(str);
3288 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3289 } else {
3290 SendHelperMessage(scr, 'U', 0, NULL);
3293 } else if (PLGetNumberOfElements(value) > 0) {
3294 char *command;
3295 char *text;
3297 SetupEnvironment(scr);
3298 text = PLGetDescription(value);
3299 command = wmalloc(strlen(text)+40);
3300 if (wPreferences.smooth_workspace_back)
3301 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
3302 else
3303 sprintf(command, "wmsetbg -d -p '%s' &", text);
3304 wfree(text);
3305 system(command);
3306 wfree(command);
3308 PLRelease(value);
3310 return 0;
3314 static int
3315 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3317 if (scr->widget_texture) {
3318 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3320 scr->widget_texture = *(WTexSolid**)texture;
3322 return 0;
3326 static int
3327 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3329 if (scr->window_title_texture[WS_FOCUSED]) {
3330 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3332 scr->window_title_texture[WS_FOCUSED] = *texture;
3334 return REFRESH_WINDOW_TEXTURES;
3338 static int
3339 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3341 if (scr->window_title_texture[WS_PFOCUSED]) {
3342 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3344 scr->window_title_texture[WS_PFOCUSED] = *texture;
3346 return REFRESH_WINDOW_TEXTURES;
3350 static int
3351 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3353 if (scr->window_title_texture[WS_UNFOCUSED]) {
3354 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3356 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3358 return REFRESH_WINDOW_TEXTURES;
3362 static int
3363 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3365 if (scr->resizebar_texture[0]) {
3366 wTextureDestroy(scr, scr->resizebar_texture[0]);
3368 scr->resizebar_texture[0] = *texture;
3370 return REFRESH_WINDOW_TEXTURES;
3374 static int
3375 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3377 if (scr->menu_title_texture[0]) {
3378 wTextureDestroy(scr, scr->menu_title_texture[0]);
3380 scr->menu_title_texture[0] = *texture;
3382 return REFRESH_MENU_TITLE_TEXTURE;
3386 static int
3387 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3389 if (scr->menu_item_texture) {
3390 wTextureDestroy(scr, scr->menu_item_texture);
3391 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3393 scr->menu_item_texture = *texture;
3395 scr->menu_item_auxtexture
3396 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3398 return REFRESH_MENU_TEXTURE;
3402 static int
3403 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3405 WWindow *wwin;
3406 wKeyBindings[index] = *shortcut;
3408 wwin = scr->focused_window;
3410 while (wwin!=NULL) {
3411 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3413 if (!WFLAGP(wwin, no_bind_keys)) {
3414 wWindowSetKeyGrabs(wwin);
3416 wwin = wwin->prev;
3419 return 0;
3423 static int
3424 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3426 wArrangeIcons(scr, True);
3428 return 0;
3432 static int
3433 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3435 wScreenUpdateUsableArea(scr);
3437 return 0;
3441 static int
3442 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3444 return REFRESH_MENU_TEXTURE;
3449 static int
3450 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3452 return REFRESH_BUTTON_IMAGES;
3457 * Very ugly kluge.
3458 * Need access to the double click variables, so that all widgets in
3459 * wmaker panels will have the same dbl-click values.
3460 * TODO: figure a better way of dealing with it.
3462 #include "WINGsP.h"
3464 static int
3465 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3467 extern _WINGsConfiguration WINGsConfiguration;
3469 if (*value <= 0)
3470 *(int*)foo = 1;
3472 WINGsConfiguration.doubleClickDelay = *value;
3474 return 0;
3478 #if 0
3479 static int
3480 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3482 extern _WINGsConfiguration WINGsConfiguration;
3484 WINGsConfiguration.useMultiByte = *value;
3486 return 0;
3488 #endif
3490 #ifdef DEFINABLE_CURSOR
3491 static int
3492 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3494 if (None != wCursor[index])
3496 XFreeCursor(dpy, wCursor[index]);
3499 wCursor[index] = *cursor;
3501 if ((WCUR_ROOT == index) && (None != *cursor))
3503 XDefineCursor(dpy, scr->root_win, *cursor);
3506 return 0;
3508 #endif /* DEFINABLE_CURSOR*/